VTK/Tutorials/TriangleGeometryOnly: Difference between revisions

From KitwarePublic
< VTK‎ | Tutorials
Jump to navigationJump to search
No edit summary
No edit summary
Line 3: Line 3:
{
{
//setup points
//setup points
vector<Point> 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));
Line 13: Line 13:
vtkSmartPointer<vtkCellArray> Vertices = vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkCellArray> Vertices = vtkSmartPointer<vtkCellArray>::New();


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

Revision as of 14:28, 18 June 2009

<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>