This wiki has been deprecated. You can find updated information from the main VTK website.

VTK/Java Code Samples

From KitwarePublic
Jump to navigationJump to search

Building VTK Programmable filter in Java

This example change the point location by multiplying by 2 the z coordinate. Be aware, that the filter has one output port by DataSet type so you will have to figure out which port should be used depending on the processing you are doing.

import vtk.vtkFloatArray;
import vtk.vtkPoints;
import vtk.vtkPolyData;
import vtk.vtkProgrammableFilter;

public class MyFilter extends vtkProgrammableFilter {
	vtkPoints outputPoints;

	public MyFilter() {
		SetExecuteMethod(this, "compute");

	public void compute() {
		vtkPolyData polyDataInput = GetPolyDataInput();
		vtkPolyData polyDataOutput = GetPolyDataOutput();
		vtkPoints inputPoints = polyDataInput.GetPoints();

	        outputPoints = new vtkPoints();
		for (int i = 0; i < inputPoints.GetNumberOfPoints(); i++) {
			outputPoints.SetPoint(i, inputPoints.GetPoint(i)[0], inputPoints.GetPoint(i)[1], inputPoints.GetPoint(i)[2] * 2);