VTK/Tutorials/TriangleGeometryOnly: Difference between revisions
Daviddoria (talk | contribs) |
Daviddoria (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<source lang="cpp"> | <source lang="cpp"> | ||
void TestWritePointSquare(const string &OutputFile | void TestWritePointSquare(const std::string &OutputFile) | ||
{ | { | ||
//setup points | //setup points | ||
Line 9: | Line 9: | ||
Points.push_back(Point(-1, -1, 0)); | Points.push_back(Point(-1, -1, 0)); | ||
vtkSmartPointer<vtkPoints> points3D = vtkSmartPointer<vtkPoints>::New(); | |||
Model.Points = | vtkSmartPointer<vtkCellArray> Vertices = vtkSmartPointer<vtkCellArray>::New(); | ||
for ( unsigned int i = 0; i < Model.Points.size(); ++i ) | |||
{ | |||
vtkIdType pid[1]; | |||
Point P = Model.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> | </source> |
Revision as of 10:39, 30 April 2009
<source lang="cpp"> void TestWritePointSquare(const std::string &OutputFile) { //setup points 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 < Model.Points.size(); ++i ) { vtkIdType pid[1]; Point P = Model.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>