[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&lt;&lt;std::endl;
    number_of_triangles = polydata->GetNumberOfCells();
    infile<<number_of_triangles&lt;&lt;std::endl;

    // Read points
    for (vtkIdType i = 0; i &lt; number_of_points; i++)
    {
        double p[3];
        points->GetPoint(i,p);
        infile <<p[0]&lt;&lt;&quot; &quot;&lt;&lt; p[1]&lt;&lt;&quot;
&quot;&lt;&lt;p[2];
        infile&lt;&lt;&quot; &quot;&lt;&lt;std::endl;

    }


&lt;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]&lt;&lt;&quot; &quot;&lt;&lt; p[1]&lt;&lt;&quot;
&quot;&lt;&lt;p[2];
//      infile&lt;&lt;&quot; &quot;&lt;&lt;std::endl;

        unsigned int ids[3];
//        infile &lt;&lt; ids[0]&lt;&lt;&quot; &quot;&lt;&lt;
ids[1]&lt;&lt;&quot; &quot;&lt;&lt; ids[2];
//        infile&lt;&lt;&quot; &quot;&lt;&lt;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;

     }
&lt;/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