Difference between revisions of "VTK/Examples/Cxx/Meshes/AddCell"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
 
Line 1: Line 1:
==AddCell.cxx==
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Meshes/AddCell AddCell] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
<source lang="cpp">
 
#include <vtkSmartPointer.h>
 
#include <vtkTriangle.h>
 
#include <vtkCellArray.h>
 
#include <vtkPolyData.h>
 
 
 
int main(int , char *[])
 
{
 
  // Create a triangle
 
  vtkSmartPointer<vtkPoints> points =
 
    vtkSmartPointer<vtkPoints>::New();
 
  points->InsertNextPoint ( 1.0, 0.0, 0.0 );
 
  points->InsertNextPoint ( 0.0, 0.0, 0.0 );
 
  points->InsertNextPoint ( 0.0, 1.0, 0.0 );
 
 
 
  vtkSmartPointer<vtkTriangle> triangle =
 
    vtkSmartPointer<vtkTriangle>::New();
 
  triangle->GetPointIds()->SetId ( 0, 0 );
 
  triangle->GetPointIds()->SetId ( 1, 1 );
 
  triangle->GetPointIds()->SetId ( 2, 2 );
 
 
 
  vtkSmartPointer<vtkCellArray> triangles =
 
    vtkSmartPointer<vtkCellArray>::New();
 
  triangles->InsertNextCell ( triangle );
 
 
 
  // Create a polydata object
 
  vtkSmartPointer<vtkPolyData> polyData =
 
    vtkSmartPointer<vtkPolyData>::New();
 
 
 
  // Add the geometry and topology to the polydata
 
  polyData->SetPoints ( points );
 
  polyData->SetPolys ( triangles );
 
 
 
  std::cout << "There are " << polyData->GetNumberOfCells() << " cells." << std::endl;
 
 
 
  polyData->GetPolys()->InsertNextCell(triangle);
 
 
 
  std::cout << "There are " << polyData->GetNumberOfCells() << " cells." << std::endl;
 
 
 
  return EXIT_SUCCESS;
 
}
 
 
 
</source>
 
 
 
 
 
{{VTKCMakeLists|{{SUBPAGENAME}}}}
 

Latest revision as of 19:46, 19 February 2019

See AddCell on the new VTKExamples website.