VTK/Tutorials/TriangleGeometryPolygon: Difference between revisions
Daviddoria (talk | contribs) No edit summary |
Daviddoria (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<source lang="cpp"> | <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 | //setup points | ||
vector<Point> | 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 ) | |||
for ( unsigned int i = 0; i < | |||
{ | { | ||
Point P = Coords[i]; | |||
Point P = | Points->InsertNextPoint(P.x, P.y, P.z); | ||
} | } | ||
std::vector<int> VertexList; | |||
vtkCellArray* triangles = vtkCellArray::New(); | 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( | polydata->SetPoints(Points); | ||
polydata->SetPolys(triangles); | polydata->SetPolys(triangles); | ||
vtkXMLPolyDataWriter* writer = vtkXMLPolyDataWriter::New(); | |||
writer->SetFileName("Triangle.vtp"); | |||
writer->SetFileName( | |||
writer->SetInput(polydata); | writer->SetInput(polydata); | ||
writer->Write(); | writer->Write(); |
Revision as of 15:11, 18 June 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>