VTK/Tutorials/TriangleGeometryOnly: Difference between revisions

From KitwarePublic
< VTK‎ | Tutorials
Jump to navigationJump to search
No edit summary
Line 1: Line 1:
<source lang="cpp">
<source lang="cpp">
void TestWritePointSquare(const string &OutputFile, const char FileType)
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));
//setup model
 
ModelClass Model;
vtkSmartPointer<vtkPoints> points3D = vtkSmartPointer<vtkPoints>::New();
Model.Points = 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);
//write model
vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
writer->SetFileName(OutputFile.c_str());
if(FileType == 'u')
writer->SetInput(polydata);
VtuWrite(Model, OutputFile);
writer->Write();
else if(FileType == 'p')
VtpWrite(Model, OutputFile);
 
}
}
</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>