[vtkusers] question ? [txt writer]
Agata Krasoń
agatakrason at gmail.com
Mon Sep 3 02:57:20 EDT 2012
Hi ;)
I am trying to make writer to txt file to format like this :
number_of_points
number_of_triangles
point[0]X point[0]Y point[0]Z
point[1]X point[1]Y point[1]Z
...
point[N]X point[N]Y point[N]Z
triangle[0]A triangle[0]B triangle[0]C
triangle[1]A triangle[1]B triangle[1]C
...
triangle[M]A triangle[M]B triangle[M]C
I have written correctly numer of points, triangles and points ..
I have problem with writing triangle :
triangle[0]A triangle[0]B triangle[0]C
Here this is my code :
Could You look at this code please ?
I don't have any idea ?
What I could extract polys->GetCell ().. ?
#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <vtkDelimitedTextWriter.h>
#include <vtkPolyDataReader.h>
#include <vtkSphereSource.h>
#include <vtkVariantArray.h>
#include <vtkPolyData.h>
#include <vtkTable.h>
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 = "plik4.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;
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;
}
*// HERE ?? *
* for (vtkIdType i = 0; i < number_of_triangles; i++)*
* *
* {*
* *
* vtkIdType a, b, c;*
* *
* infile << a << b << c <<std::endl;*
* *
*
*
* *
* double t[3];*
* *
*
*
* *
* points->GetPoint(i,t);*
* *
* infile <<t[0]<<" "<< t[1]<<" "<<t[2];*
* *
* infile<<" "<<std::endl;*
* *
*
*
* *
*
*
* *
* // polys->Ge*
* *
* // polys->InsertCellPoint(a-1);*
* *
* // polys->InsertCellPoint(b-1);*
* *
* // polys->InsertCellPoint(c-1);*
* *
*
*
* *
* // double t[3];*
* *
* // points->GetPoint(i,t);*
* *
* // infile<<t[0]<<t[1]<<t[2]<<std::endl;*
* *
*
*
* *
* }*
* *
*
*
* *
*
*
* *
*
*
infile.close();
return EXIT_SUCCESS;
}
I would appreciate for any help please.
agatte
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120903/ddde19b7/attachment.htm>
More information about the vtkusers
mailing list