VTK/Tutorials/TriangleGeometryLines: Difference between revisions

From KitwarePublic
< VTK‎ | Tutorials
Jump to navigationJump to search
(New page: ==TriangleLines.cxx== <source lang="cpp"> #include <vtkPoints.h> #include <vtkLine.h> #include <vtkCellArray.h> #include <vtkSmartPointer.h> #include <vtkXMLPolyDataWriter.h> #include <vtk...)
 
No edit summary
Line 11: Line 11:
{
{
   //Setup point coordinates
   //Setup point coordinates
   vtkSmartPointer<vtkPoints> Points = vtkSmartPointer<vtkPoints>::New();
   vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
   Points->InsertNextPoint ( 1.0, 0.0, 0.0 );
   points->InsertNextPoint ( 1.0, 0.0, 0.0 );
   Points->InsertNextPoint ( 0.0, 0.0, 1.0 );
   points->InsertNextPoint ( 0.0, 0.0, 1.0 );
   Points->InsertNextPoint ( 0.0, 0.0, 0.0 );
   points->InsertNextPoint ( 0.0, 0.0, 0.0 );


   //create a line between each pair of points
   //create a line between each pair of points
Line 39: Line 39:


   //add the points and lines to the polydata
   //add the points and lines to the polydata
   polydata->SetPoints ( Points );
   polydata->SetPoints ( points );
   polydata->SetLines ( lines );
   polydata->SetLines ( lines );



Revision as of 21:50, 12 December 2009

TriangleLines.cxx

<source lang="cpp">

  1. include <vtkPoints.h>
  2. include <vtkLine.h>
  3. include <vtkCellArray.h>
  4. include <vtkSmartPointer.h>
  5. include <vtkXMLPolyDataWriter.h>
  6. include <vtkPolyData.h>

int main() {

 //Setup point coordinates
 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
 points->InsertNextPoint ( 1.0, 0.0, 0.0 );
 points->InsertNextPoint ( 0.0, 0.0, 1.0 );
 points->InsertNextPoint ( 0.0, 0.0, 0.0 );
 //create a line between each pair of points
 vtkSmartPointer<vtkLine> line0 = vtkSmartPointer<vtkLine>::New();
 line0->GetPointIds()->SetId ( 0,0 );
 line0->GetPointIds()->SetId ( 1,1 );
 vtkSmartPointer<vtkLine> line1 = vtkSmartPointer<vtkLine>::New();
 line1->GetPointIds()->SetId ( 0,1 );
 line1->GetPointIds()->SetId ( 1,2 );
 vtkSmartPointer<vtkLine> line2 = vtkSmartPointer<vtkLine>::New();
 line2->GetPointIds()->SetId ( 0,2 );
 line2->GetPointIds()->SetId ( 1,0 );
 //create a cell array to store the line in
 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
 lines->InsertNextCell ( line0 );
 lines->InsertNextCell ( line1 );
 lines->InsertNextCell ( line2 );
 //create a polydata to store everything in
 vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
 //add the points and lines to the polydata
 polydata->SetPoints ( points );
 polydata->SetLines ( lines );
 //write the polydata to a file
 vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
 writer->SetFileName ( "TriangleLines.vtp" );
 writer->SetInput ( polydata );
 writer->Write();

}

</source>

CMakeLists.txt

<source lang="text"> cmake_minimum_required(VERSION 2.6)

PROJECT(TriangleLines)

FIND_PACKAGE(VTK REQUIRED) INCLUDE(${VTK_USE_FILE})

ADD_EXECUTABLE(TriangleLines TriangleLines.cxx) TARGET_LINK_LIBRARIES(TriangleLines vtkHybrid)

</source>