[java] cannot work using vtkImageReslice

(george2008) #1

any help about vtk with java ?
below java code is from C++/C#, but cannot work.

           vtkDICOMImageReader reader = new vtkDICOMImageReader();
	reader.SetDirectoryName("/home/dicom/series1");
	reader.SetDataByteOrderToLittleEndian();
	reader.Update();

	// vtkImageChangeInformation change = new vtkImageChangeInformation();
	// change.SetInputConnection(reader.GetOutputPort());
	// change.SetOutputSpacing(spacing[0], spacing[1], spacing[2]);
	// change.Update();

	vtkImageData img = reader.GetOutput();
	int[] extent = img.GetExtent();
	double[] spacing = img.GetSpacing();
	double[] origin = img.GetOrigin();

	double[] center = new double[3];
	center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);
	center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);
	center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);

	/* @formatter:off */
	double[] axialElements = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0,
			1 };
	/* @formatter:on */

	vtkMatrix4x4 resliceAxes = new vtkMatrix4x4();
	resliceAxes.DeepCopy(axialElements);
	// for (int i = 0; i < 4; i++) {
	//	for (int j = 0; j < 4; j++) {
	//		resliceAxes.SetElement(i, j, axialElements[i * 4 + j]);
	//	}
	// }

	resliceAxes.SetElement(0, 3, center[0]);
	resliceAxes.SetElement(1, 3, center[1]);
	resliceAxes.SetElement(2, 3, center[2]);

	vtkImageReslice reslice = new vtkImageReslice();
	reslice.SetInputConnection(reader.GetOutputPort());
	// reslice.SetInputData(img);
	reslice.SetOutputDimensionality(2);
	reslice.SetResliceAxes(resliceAxes);
	reslice.SetInterpolationModeToLinear();

	vtkLookupTable colorTable = new vtkLookupTable();
	colorTable.SetRange(0, 1000);
	colorTable.SetValueRange(0.0, 1.0);
	colorTable.SetSaturationRange(0.0, 0.0);
	colorTable.SetRampToLinear();
	colorTable.Build();

	vtkImageMapToColors colorMap = new vtkImageMapToColors();
	colorMap.SetLookupTable(colorTable);
	colorMap.SetInputConnection(reslice.GetOutputPort());
	// colorMap.SetInputData(reslice.GetOutput());

	vtkImageActor imgActor = new vtkImageActor();
	imgActor.SetInputData(colorMap.GetOutput());

	vtkRenderer renderer = new vtkRenderer();
	renderer.AddActor(imgActor);
	renderer.SetBackground(0.4, 0.5, 0.6);

	vtkRenderWindow renderWindow = new vtkRenderWindow();
	renderWindow.SetSize(500, 500);
	renderWindow.AddRenderer(renderer);

	vtkRenderWindowInteractor renderWindowInteractor = new vtkRenderWindowInteractor();
	vtkInteractorStyleImage imagestyle = new vtkInteractorStyleImage();
	renderWindowInteractor.SetInteractorStyle(imagestyle);
	renderWindowInteractor.SetRenderWindow(renderWindow);
	renderWindowInteractor.Initialize();
	renderWindowInteractor.Start();
(Sebastien Jourdain) #2

What is the error? Do you load the native library? You can look at some Java example here.