[vtkusers] VTK file data precision

Nico Schlömer nico.schloemer at gmail.com
Tue Feb 16 14:07:43 EST 2010


Hi,

this issue may have come up before:

I'm using VTK to store some numerical data for me, specifically

I do so by

1.) Filling the scalar field; notice vtkDOUBLEArray.
=============================== *snip* ===============================
    vtkSmartPointer<vtkDoubleArray> scalars =
        vtkSmartPointer<vtkDoubleArray>::New();
   [ fill with data ]
=============================== *snap* ===============================

2.) Plugging the field into imageData:
=============================== *snip* ===============================
    const vtkSmartPointer<vtkImageData>   imageData;
    imageData->GetPointData()->AddArray ( scalars );
=============================== *snap* ===============================

and (3.) Printing the image data to a file:
=============================== *snip* ===============================
    vtkSmartPointer<vtkStructuredPointsWriter> writer =
vtkSmartPointer<vtkStructuredPointsWriter>::New();
    writer->SetFileName ( "myfile.vtk" );
    writer->SetInput ( imageData );
    writer->Write();
=============================== *snap* ===============================

What I eventually get is a nice standards-compliant VTK file; an
extract from its contents would be
=============================== *snip* ===============================
[...]
DIMENSIONS 61 61 1
SPACING 0.0833333 0.0833333 0
ORIGIN 0 0 0
POINT_DATA 3721
FIELD FieldData 1
psi 2 3721 double
0.590845 -2.3876e-13 0.587619 0.0616976 0.57869 0.112716 0.565679
0.156785 0.549682
[...]
=============================== *snip* ===============================

Wow -- were have all the 15 digits of my machines double-precision
gone? They seem like lousy floats!
-- Any explanation for this? How would I be able to store all digits?

Cheers,
Nico



More information about the vtkusers mailing list