VTK/Tutorials/TriangleGeometryPolygon: Difference between revisions
Daviddoria (talk | contribs) |
Daviddoria (talk | contribs) m (Write a file of a triangle moved to Triangle - Geometry + Polygon: Changed structure of polydata examples) |
(No difference)
|
Revision as of 18:11, 22 October 2009
<source lang="cpp">
- include <iostream>
- include <vector>
- include "vtkCellArray.h"
- include "vtkPoints.h"
- include "vtkXMLPolyDataWriter.h"
- include "vtkPolyData.h"
- include "vtkTriangle.h"
struct Point { double x,y,z; Point(const double xin, const double yin, const double zin) : x(xin), y(yin), z(zin) {} };
int main() {
//setup points std::vector<Point> Coords; Coords.push_back(Point(1.0, 0.0, 0.0)); Coords.push_back(Point(0.0, 0.0, 0.0)); Coords.push_back(Point(0.0, 1.0, 0.0));
vtkPoints* Points = vtkPoints::New();
for ( unsigned int i = 0; i < Coords.size(); ++i ) { Point P = Coords[i]; Points->InsertNextPoint(P.x, P.y, P.z); }
std::vector<int> VertexList;
vtkCellArray* triangles = vtkCellArray::New(); vtkTriangle* triangle = vtkTriangle::New(); triangle->GetPointIds()->SetId(0, 0); triangle->GetPointIds()->SetId(1, 1); triangle->GetPointIds()->SetId(2, 2); triangles->InsertNextCell(triangle);
vtkPolyData* polydata = vtkPolyData::New();
polydata->SetPoints(Points); polydata->SetPolys(triangles);
vtkXMLPolyDataWriter* writer = vtkXMLPolyDataWriter::New(); writer->SetFileName("Triangle.vtp"); writer->SetInput(polydata); writer->Write();
} </source>