VTK/Tutorials/TriangleGeometryLines: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
Daviddoria (talk | contribs) |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 45: | Line 45: | ||
vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); | vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); | ||
writer->SetFileName ( "TriangleLines.vtp" ); | writer->SetFileName ( "TriangleLines.vtp" ); | ||
#if VTK_MAJOR_VERSION <= 5 | |||
writer->SetInput ( polydata ); | writer->SetInput ( polydata ); | ||
#else | |||
writer->SetInputData ( polydata ); | |||
#endif | |||
writer->Write(); | writer->Write(); | ||
return EXIT_SUCCESS; | |||
} | } | ||
Line 53: | Line 58: | ||
==CMakeLists.txt== | ==CMakeLists.txt== | ||
<source lang=" | <source lang="cmake"> | ||
cmake_minimum_required(VERSION 2.6) | cmake_minimum_required(VERSION 2.6) | ||
project(TriangleLines) | |||
find_package(VTK REQUIRED) | |||
include(${VTK_USE_FILE}) | |||
add_executable(TriangleLines TriangleLines.cxx) | |||
if(VTK_LIBRARIES) | |||
target_link_libarries(TriangleLines ${VTK_LIBRARIES}) | |||
else() | |||
target_link_libraries(TriangleLines vtkHybrid) | |||
endif() | |||
</source> | </source> |
Latest revision as of 19:21, 25 April 2014
TriangleLines.cxx
<source lang="cpp">
- include <vtkPoints.h>
- include <vtkLine.h>
- include <vtkCellArray.h>
- include <vtkSmartPointer.h>
- include <vtkXMLPolyDataWriter.h>
- include <vtkPolyData.h>
int main(int argc, char *argv[]) {
//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" );
- if VTK_MAJOR_VERSION <= 5
writer->SetInput ( polydata );
- else
writer->SetInputData ( polydata );
- endif
writer->Write();
return EXIT_SUCCESS;
}
</source>
CMakeLists.txt
<source lang="cmake"> cmake_minimum_required(VERSION 2.6)
project(TriangleLines)
find_package(VTK REQUIRED) include(${VTK_USE_FILE})
add_executable(TriangleLines TriangleLines.cxx) if(VTK_LIBRARIES)
target_link_libarries(TriangleLines ${VTK_LIBRARIES})
else()
target_link_libraries(TriangleLines vtkHybrid)
endif() </source>