[vtkusers] How to convert native array to VTK array efficiently in Java?

Alan alan at vuesonix.com
Thu Mar 20 17:58:17 EST 2003


Hi,
I've seen this question posted, but no answers, so I will repost.  How 
do I efficiently convert data from a native java array (eg, byte) to a 
VTK array (eg, vtkUnsignedCharArray) without explicitly iterating 
through each point with the SetValue() method?


For example, I currently load VTK with my voxel data with a loop like:

    static vtkShortArray convertToVTKShortArray(short arrIn[])
    {
      vtkShortArray dataArr = new vtkShortArray();
      dataArr.SetNumberOfComponents(1);
      dataArr.SetNumberOfTuples(arrIn.length);

      for (int i = 0; i < arrIn.length; i++)
      {
        dataArr.SetValue(i, arrIn[i]);
      }
      return(dataArr);
    }

Unfortunately, the Java wrappers have no SetValue(short[]) methods which 
could load an array of values, hence the need iterate and load each one 
explicitly using the SetValue(index, val) method.

Thanks in advance for any help.
   --Alan




More information about the vtkusers mailing list