This is an archive of the old MediaWiki-based ImageJ wiki. The current website can be found at imagej.net.

3D Viewer: Two Canvasses

(Return to the Developer Documentation page)
(Return to the main 3D_Viewer page)


How to create two canvasses displaying the same universe

You can download example source code for this HowTo here.


This howto shows how to create two windows showing the same universe:

	// Open a hyperstack
	String path = "/home/bene/PhD/brains/template.tif";
	ImagePlus imp = IJ.openImage(path);

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

	// retrieve some info about the 1st canvas
	int w = univ.getCanvas().getWidth();
	int h = univ.getCanvas().getHeight();

	// Create a new canvas and add it
	ImageCanvas3D canvas2 = new ImageCanvas3D(w, h);
	univ.getViewer().getView().addCanvas3D(canvas2);

	// create a new window, add the canvas and show it
	Frame f = new Frame();
	f.add(canvas2);
	f.pack();
	f.show();

After creating the universe as usual, a new ImageCanvas3D is created. To make it display the existing universe, it has to be registered with it. This is done with univ.getViewer().getView().addCanvas3D(...).

All what is left to do is to create a new frame, add the canvas to it and finally show it.