VTK/Tutorials/TriangleGeometryOnly

From KitwarePublic
< VTK‎ | Tutorials
Revision as of 05:39, 30 April 2009 by Daviddoria (talk | contribs)
Jump to navigationJump to search
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();
}