VTK/Java Code Samples: Difference between revisions
(Created page with '== 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 Data…') |
|||
Line 24: | Line 24: | ||
polyDataOutput.GetCellData().PassData(polyDataInput.GetCellData()); | polyDataOutput.GetCellData().PassData(polyDataInput.GetCellData()); | ||
vtkPoints inputPoints = polyDataInput.GetPoints(); | vtkPoints inputPoints = polyDataInput.GetPoints(); | ||
outputPoints = new vtkPoints(); | outputPoints = new vtkPoints(); |
Latest revision as of 14:41, 2 June 2010
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>