KnownLengthArray
vtk-examples/Java/Utilities/KnownLengthArray
Description¶
This example creates a VTK style float array. This can be easily interchanged with vtkIntArray, vtkDoubleArray, etc.
The terminology is as follows:
-
SetNumberOfComponents()
: sets the number of elements that a tuple in the array will have. See VectorArrayKnownLength for an example with tuples with more than one element. -
SetNumberOfValues()
: sets the number of tuples the array will have. See UnknownLengthArray for an example where the number of values is not known in advance.
Other languages
See (Cxx)
Question
If you have a question about this example, please use the VTK Discourse Forum
Code¶
KnownLengthArray.java
import vtk.vtkNativeLibrary;
import vtk.vtkFloatArray;
public class KnownLengthArray
{
//-----------------------------------------------------------------
// Load VTK library and print which library was not properly loaded
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 s[])
{
vtkFloatArray Distances = new vtkFloatArray();
Distances.SetName("Distances");
Distances.SetNumberOfComponents(1);
Distances.SetNumberOfValues(5);
//set values
for(int i = 0; i < Distances.GetNumberOfTuples(); i++)
{
double f = i + 0.1;
Distances.SetValue(i, f);
}
//get values
for(int i = 0; i < Distances.GetNumberOfTuples(); i++)
{
double f = Distances.GetValue(i);
System.out.println(f);
}
}
}