[vtkusers] Java: imageData example

rkemp rkemp at few.vu.nl
Tue Feb 6 07:12:56 EST 2007


Hi all,

Below you can find a code snippet in Java. The code is supposed to show a 2D (10x10) image. For each 
point a scalar is added. I want to see a 10x10 image with each cell a different color (according to 
its scalar value), however the only thing I see is a little grey square in the lower left corner. 
Does anybody know what I do wrong? Or some essential code missing? Please let me know!

Roelof

code snippet
		double[] G = new double[100]; /* 10 x 10 */
		for (int i = 0; i < 100; i++) {
			G[i] = (double) i;
		}

		vtkDoubleArray array = new vtkDoubleArray();
		array.SetJavaArray(G);

		vtkImageData imageData = new vtkImageData();
		imageData.SetDimensions(10, 10, 1);
		imageData.SetScalarTypeToDouble();
		imageData.SetSpacing(1.0, 1.0, 1.0);
		imageData.SetOrigin(0.0, 0.0, 0.0);
		imageData.GetPointData().SetScalars(array);

		vtkImageViewer viewer = new vtkImageViewer();
		viewer.SetInput(imageData);
		viewer.SetColorWindow(100.0);
		viewer.SetColorLevel(1.0);
		viewer.GetRenderWindow().SetSize(300, 300);

		viewer.Render();

		try {
			Thread.sleep(3000);
		} catch (Exception e) {}



More information about the vtkusers mailing list