VTK/Tutorials/TriangleGeometryOnly

From KitwarePublic
< VTK‎ | Tutorials
Revision as of 14:28, 18 June 2009 by Daviddoria (talk | contribs)
Jump to navigationJump to search

<source lang="cpp"> void TestWritePointSquare(const std::string &OutputFile) { //setup points std::vector<Point> Points; Points.push_back(Point(-1, 1, 0)); Points.push_back(Point(1, 1, 0)); Points.push_back(Point(1, -1, 0)); Points.push_back(Point(-1, -1, 0));


vtkSmartPointer<vtkPoints> points3D = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkCellArray> Vertices = vtkSmartPointer<vtkCellArray>::New();

for ( unsigned int i = 0; i < Points.size(); ++i ) { vtkIdType pid[1]; Point P = Points[i]; pid[0] = points3D->InsertNextPoint(P.x, P.y, P.z); Vertices->InsertNextCell(1,pid); }

vtkSmartPointer<vtkPolyData> polydata = vtkPolyData::New();

polydata->SetPoints(points3D); polydata->SetVerts(Vertices);

vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); writer->SetFileName(OutputFile.c_str()); writer->SetInput(polydata); writer->Write(); } </source>