Hi, in my long journey to build a swept surface with VTK (How to build a swept surface ?), I begun by the begining: creating the enveloppe curve defined by a dot product. Thus I tried to port the VectorDot example (https://examples.vtk.org/site/Cxx/Math/VectorDot/) to Java.
Here is the code:
import vtk.vtkFloatArray;
import vtk.vtkNativeLibrary;
import vtk.vtkPoints;
import vtk.vtkPolyData;
import vtk.vtkVectorDot;
public class VtkVectorDot {
static {
if (!vtkNativeLibrary.LoadAllNativeLibraries()) {
for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
if (!lib.IsLoaded()) {
System.out.println(lib.GetLibraryName() + " not loaded");
}
}
}
vtkNativeLibrary.DisableOutputWindow(null);
}
public static void main(String[] args) {
// Generate data
vtkPoints points = new vtkPoints();
points.InsertNextPoint(0, 0, 0);
points.InsertNextPoint(1, 0, 0);
points.InsertNextPoint(2, 0, 0);
vtkPolyData polydata = new vtkPolyData();
polydata.SetPoints(points);
// Add normals
vtkFloatArray normals = new vtkFloatArray();
normals.SetNumberOfComponents(3);
normals.SetName("Normals");
normals.InsertNextTuple3(1, 0, 0);
normals.InsertNextTuple3(1, 0, 0);
normals.InsertNextTuple3(3, 0, 0);
polydata.GetPointData().SetNormals(normals);
// Add vectors.
vtkFloatArray vectors = new vtkFloatArray();
vectors.SetNumberOfComponents(3);
vectors.SetName("Vectors");
vectors.InsertNextTuple3(1, 1, 1);
vectors.InsertNextTuple3(.707, .707, 0);
vectors.InsertNextTuple3(0, 1, 0);
polydata.GetPointData().SetVectors(vectors);
// Compute the dot products between normals and vectors.
vtkVectorDot vectorDot = new vtkVectorDot();
vectorDot.SetInputData(polydata);
vectorDot.Update();
// Get the results.
vtkFloatArray data = (vtkFloatArray) vectorDot.GetOutput().GetPointData().GetScalars();
// Output the results.
for (int i = 0; i < data.GetNumberOfTuples(); i++) {
System.out.println("Value " + i + " : " + data.GetValue(i));
}
}
}
My problem is this code, which IMHO is a line for line translation of the cxx version, doesn’t work :-(.
The output is:
Value 0 : NaN
Value 1 : Infinity
Value 2 : Infinity
I checked it and checked it again, I can’t figure out where the problem is coming from.
Any help would be gratefully appreciated.
Thanks in advance.
jMaxR
PS: Once the code fixed, feel free to add it to VTK examples java pages.