VTK/Java Code Samples

From KitwarePublic
< VTK
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.


<source lang="java"> 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(); polyDataOutput.CopyStructure(polyDataInput); polyDataOutput.GetPointData().PassData(polyDataInput.GetPointData()); polyDataOutput.GetCellData().PassData(polyDataInput.GetCellData()); vtkPoints inputPoints = polyDataInput.GetPoints();

outputPoints = new vtkPoints(); outputPoints.SetNumberOfPoints(inputPoints.GetNumberOfPoints()); polyDataOutput.SetPoints(outputPoints); // for (int i = 0; i < inputPoints.GetNumberOfPoints(); i++) { outputPoints.SetPoint(i, inputPoints.GetPoint(i)[0], inputPoints.GetPoint(i)[1], inputPoints.GetPoint(i)[2] * 2); } } } </source>