[vtkusers] precision of points

Gopalakrishnan, Gowri Gowri.Gopalakrishnan at inteq.com
Tue Oct 16 05:41:45 EDT 2001


Thanks for your tip Karin. I just tried it.

Yes when you access
double xOut =
((vtkDoubleArray)(coordinates[0].GetData())).GetValue(0);

xOut value is the right doube value but when I write to the *.vtk file the 
values after the decimal point is still missing.......

Any comments?.

Gowri


-----Original Message-----
From: Karin Faulhaber [mailto:faulhaber at ipf.uni-karlsruhe.de]
Sent: Tuesday, October 16, 2001 10:18 AM
To: Gopalakrishnan, Gowri
Cc: 'vtkusers at public.kitware.com'
Subject: Re: [vtkusers] precision of points


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