This wiki has been deprecated. You can find updated information from the main VTK website.

VTK/Tutorials/TriangleGeometryOnly

From KitwarePublic
< VTK‎ | Tutorials
Jump to navigationJump to search

This example writes the coordinates of the corners of a triangle to a vtp file. There is geometry (points), but there is no topology (vertices), so if you open this file in Paraview, you will not see anything. You can "glyph" the points to see them, but generally some type of topology exists. We will see topology in the next example.

TrianglePoints.cxx

#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkXMLPolyDataWriter.h>
#include <vtkPolyData.h>

int main(int argc, char *argv[])
{
  //create a set of points
  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 );

  //create a polydata
  vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();

  //add the points to the polydata
  polydata->SetPoints ( points );

  //write the polydata to a file
  vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
  writer->SetFileName ( "TrianglePoints.vtp" );
#if VTK_MAJOR_VERSION <= 5
  writer->SetInput( polydata );
#else
  writer->SetInputData( polydata );
#endif
  writer->Write();

  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

project(TrianglePoints)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

add_executable(TrianglePoints TrianglePoints.cxx)
if(VTK_LIBRARIES)
  target_link_libraries(TrianglePoints ${VTK_LIBRARIES})
else()
  target_link_libraries(TrianglePoints vtkHybrid)
endif()