I tried to build an c# example of vtk-examples: src\CSharp\PolyData\NullPoint.cs using Activiz.NET 9, but get a compile error for SetValue:
vtkFloatArray floatArray = vtkFloatArray.New();
floatArray.SetNumberOfValues(3);
floatArray.SetNumberOfComponents(1);
floatArray.SetName("FloatArray");
for(int i = 0; i < 3; i++) {
floatArray.SetValue(i, 2);
}
Program.cs(27, 24): [CS1061] ‘vtkFloatArray’ does not contain a definition for ‘SetValue’ and no accessible extension method ‘SetValue’ accepting a first argument of type ‘vtkFloatArray’ could be found (are you missing a using directive or an assembly reference?)
Am I wrong?
I can change the code to SetTuple1 to make the code compile, but the parameter of SetTurple1 is always double, Will this lose precision? For example, for a vtkIntArray
vtkIntArray intArray = vtkIntArray.New();
intArray.SetNumberOfValues(3);
intArray.SetNumberOfComponents(1);
for(int i = 0; i < 3; i++) {
intArray.SetTuple1(i, 2); // the value is convert to double
}
There are different ways to populate data arrays. This is due to historical, convenience, and wrapping (e.g., Python) reasons. Using variations of SetTuple* is convenient and simple, but may have performance and precision effects as you point out. As a result, there are more complex, performance oriented ways to populate VTK data arrays. For example, using templated dispatch. Take a look at https://docs.vtk.org/en/latest/design_documents/array_dispatch.html. I would also suggest looking at source code (such as vtkWarpVector). Note that templated dispatch is often used in conjunction with vtkSMPTools to implement threaded processing. (There are other ways to do the same thing such as GetPointer(), but this typically is discouraged as you need to know the type and organizational structure of the data array i.e., SOA or AOS).