[vtkusers] question ? [txt writer]
agatte
agatakrason at gmail.com
Tue Sep 4 07:26:02 EDT 2012
Hi ;)
Yes, I am trying but I didn't received it ;/
I have always problem with saving correctly triangle in txt file.
Could anyone help me please ?
int main(int argc, char *argv[])
{
// Polydata reader
vtkPolyDataReader* reader = vtkPolyDataReader::New();
reader->SetFileName("SimpleMesh.vtk");
reader->Update();
vtkPolyData*polydata = reader->GetOutput();
vtkPoints* points = polydata->GetPoints();
vtkCellArray* polys = polydata->GetPolys();
polydata->SetPoints(points);
polydata->SetPolys(polys);
// Write to txt file
const char* filename = "test1.txt";
std::fstream infile;
infile.open(filename);
vtkIdType number_of_points, number_of_triangles;
number_of_points = polydata->GetNumberOfPoints();
infile<<number_of_points<<std::endl;
number_of_triangles = polydata->GetNumberOfCells();
infile<<number_of_triangles<<std::endl;
// Read points
for (vtkIdType i = 0; i < number_of_points; i++)
{
double p[3];
points->GetPoint(i,p);
infile <<p[0]<<" "<< p[1]<<"
"<<p[2];
infile<<" "<<std::endl;
}
<b> // HERE : problem get polys/ cells
for (vtkIdType i = 0; i < number_of_triangles; i++)
{
// double p[3];
// points->GetPoint(i,p);
// infile <<p[0]<<" "<< p[1]<<"
"<<p[2];
// infile<<" "<<std::endl;
unsigned int ids[3];
// infile << ids[0]<<" "<<
ids[1]<<" "<< ids[2];
// infile<<" "<<std::endl;
vtkIdList* idlist = vtkIdList::New();
idlist->InsertNextId (ids[0]-1);
idlist->InsertNextId (ids[1]-1);
idlist->InsertNextId (ids[2]-1);
polys->GetCell(idlist);
idlist->Delete();
//polys->InsertNextCell(idlist);
infile << ids[0]<<" "<< ids[1]<<" "<< ids[2];
infile<<" "<<std::endl;
}
</b>
infile.close();
return EXIT_SUCCESS;
}
I would appreciate for any help please .
---------------------------------
agatte
--
View this message in context: http://vtk.1045678.n5.nabble.com/question-txt-writer-tp5715788p5715817.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list