[vtkusers] precision of points

Karin Faulhaber faulhaber at ipf.uni-karlsruhe.de
Tue Oct 16 05:18:19 EDT 2001


Hi Gowri,

> Is there anyway in vtk to specify the precision you want on vtkpoints?.

I had the same problem in writing data like this to a file. What I did:
working directly on the arrays (vtkDoubleArrays!) instead of vtkPoints
(which are floating point).

Hope this helps
Karin


-----
1. Create a vtkDoubleArray with three components and the correct number
of tuples:

       vtkDoubleArray da = new vtkDoubleArray();
       da.SetNumberOfComponents(3);
       da.SetNumberOfTuples(numberOfPoints);


2. Fill this array with values:

        double x1, y1, z1, x2, y2, z2 
        ...
        da.SetValue(0, x1);
        da.SetValue(1, y1);
        da.SetValue(2, z1);     
        da.SetValue(3, x2);
        da.SetValue(4, y2);
        da.SetValue(5, z2);
        ...


3. Create a vtkPoints object, set the number of components to 3 and fill
it with the array:

        vtkPoints coordinates = new vtkPoints();
        coordinates.GetData().SetNumberOfComponents(3);
        coordinates.SetData(da);


4. You can get the correct double precision numbers from the vtkPoints
object with the following line:

        double xOut =
((vtkDoubleArray)(coordinates[0].GetData())).GetValue(0);
        etc.


The following line doesn`t seem to be necessary:

        coordinates.SetDataTypeToDouble();



More information about the vtkusers mailing list