How to visualize 4D data.

prev toc next
You can download example source code for this HowTo here. Sometimes, 3D data are recorded over time, and it is desirable to visualize those data, i.e. show it in a time line, being able to animate it, etc. This is possible with the viewer. The following lines of code show how to do it programmatically:
// Open a hyperstack
ImagePlus imp = IJ.openImage(
      Prefs.getImagesURL() + "Spindly-GFP.zip");

// Create a universe and show it
Image3DUniverse univ = new Image3DUniverse();
univ.show();

// load the stack in the viewer
univ.addVoltex(imp);

// get the Timeline object
Timeline tl = univ.getTimeline();

// start playback
tl.play();

// wait a bit
try {
        Thread.sleep(5000);
} catch(InterruptedException e) {}


// Stop animation
tl.pause();
The 3D viewer automatically recognizes hyperstacks and shows a control panel on demand, providing buttons for playback, pause, etc. Image3DUniverse allows to retrieve a Timeline object, which allows to call the corresponding functions programmatically.

Important methods of Viewer4D

Next to play() and pause(), the Timeline class provides several methods for stepping through the time frames of the 4D data:
/** Set bounce-back or repeat */
public void setBounceBack(boolean bounce);
public boolean getBounceBack();

/** Speed up the animation. */
public void faster();

/** Slows the animation down. */
public void slower();

/** Record the whole timeline */
public ImagePlus record();

/** Start animation.  */
public synchronized void play();

/** Stop/pause animation */
public synchronized void pause();

/** Display next timepoint. */
public void next();

/** Display previous timepoint. */
public void previous();

/** Display first timepoint. */
public void first();

/** Display last timepoint. */
public void last();