[vtkusers] Problem: can't write down double precision data to .vtp file using vtkXMLPolyDataWriter !
M.Salman at surrey.ac.uk
M.Salman at surrey.ac.uk
Thu Feb 14 11:01:10 EST 2008
Hi All,
I am trying to write double precison data to a .vtp file using vtkXMLPolyDataWriter but it writes down only 5 digits after the point decimal.During debugging, I found cout behaving the same way and only a few digits after the decimal point were displayed on the screen which was sorted out by setting the precision of cout explicitly using cout.setprecision() function.This suggests, we probably need to set the precision of the vtkPolyDataWriter too.
Any suggestion plese, I am really stuck badly just at the end of my job !
The code which I am using is as follows:
#include <vld.h>
#include "vtkXMLPolyDataWriter.h"
#include "vtkXMLWriter.h"
#include "vtkPolyData.h"
#include "vtkPointData.h"
#include "vtkIdType.h"
#include <iostream>
#include <cmath>
using namespace std;
int main( int argc, char *argv[] )
{
vtkXMLPolyDataReader *reader1 = vtkXMLPolyDataReader::New();
reader1->SetFileName("C:\\VtkProjects\\normal\\conemodel.vtp");
vtkPolyData *data1 =reader1->GetOutput();
data1->BuildLinks();
data1->Update();
vtkPoints * pointSet = vtkPoints::New();
pointSet->SetDataTypeToDouble();
double point1 [3];
//Load pointSet from polydata
for (int i =0; i< (data1->GetNumberOfPoints());i++)
{
data1->GetPoint(i,point1);
pointSet->InsertPoint(i,point1);
}
double * buffer1 = new double[3];
vtkIdType pointId = 0;
buffer1[0]=1.809017843;
buffer1[1]=1.809017490;
buffer1[2]=1.809017840;
//To confirm the data type of pointSet
cout.setprecision(10);
cout<<"data type of pointSet"<<pointSet->GetDataType()<<endl;
// change the first element of pointSet
double* aikPoint1 = new double[3];
pointSet->SetPoint(pointId, buffer1);
aikPoint1= pointSet->GetPoint(0);
// Display the contents of changed value
cout<<aikPoint1[0]<<endl;
cout<<aikPoint1[1]<<endl;
cout<<aikPoint1[2]<<endl<<endl;
//linkNew pointSet with the data
data1->SetPoints(pointSet);
// check if we see the updted value directly within the polydata
data1->GetPoint(0,aikPoint);
cout<<aikPoint[0]<<endl;
cout<<aikPoint[1]<<endl;
cout<<aikPoint[2]<<endl;
//**************************************** SO FAR SO GOOD *************************************************
vtkPolyData * test = vtkPolyData::New();
test->Allocate(data1,1000,1000);
test->SetPoints(pointSet);
test->SetPolys(data1->GetPolys());
test->Update();
vtkXMLPolyDataWriter *writer1 = vtkXMLPolyDataWriter::New();
writer1->SetInput(test);
writer1->SetDataModeToAscii();
writer1->SetFileName("testDoubleFloatCone.vtp");
writer1->Write();
return(0);
}
Best Regards,
Salman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080214/4b43ec04/attachment.htm>
More information about the vtkusers
mailing list