VTK/Tutorials/TriangleGeometryVertices: Difference between revisions

From KitwarePublic
< VTK‎ | Tutorials
Jump to navigationJump to search
(New page: This example writes the coordinates of the corners of a triangle to a vtp file. There is now geometry (points) as well as topology (vertices). If you open this file in Paraview, you will n...)
 
m (Write a file of triangle corners (+vertices) moved to Triangle - Geometry + Vertices: Changed structure of polydata examples)
(No difference)

Revision as of 18:11, 22 October 2009

This example writes the coordinates of the corners of a triangle to a vtp file. There is now geometry (points) as well as topology (vertices). If you open this file in Paraview, you will now see the points immediately.

<source lang="cpp">

  1. include <iostream>
  2. include <vector>
  1. include "vtkCellArray.h"
  2. include "vtkPoints.h"
  3. include "vtkXMLPolyDataWriter.h"
  4. include "vtkPolyData.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, 1.0, 0.0)); Coords.push_back(Point(1.0, 1.0, 0.0)); Coords.push_back(Point(1.0, -1.0, 0.0));

vtkPoints* Points = vtkPoints::New(); vtkCellArray* Vertices = vtkCellArray::New();

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

vtkPolyData* polydata = vtkPolyData::New();

polydata->SetPoints(Points); polydata->SetVerts(Vertices);

vtkXMLPolyDataWriter* writer = vtkXMLPolyDataWriter::New(); writer->SetFileName("TriangleVerts.vtp"); writer->SetInput(polydata); writer->Write();

} </source>