VTK/Examples/Cxx/PolyData/GetMiscCellData
From KitwarePublic
This demo reads the file Test.vtp that was created in this example http://www.vtk.org/Wiki/Add_Miscellaneous_Data_to_Cells_in_a_Polydata and retrieves the double that we attached to the triangle.
GetMiscCellData.cxx
#include <vtkSmartPointer.h> #include <vtkCellData.h> #include <vtkCellArray.h> #include <vtkDoubleArray.h> #include <vtkTriangle.h> #include <vtkPoints.h> #include <vtkPolyData.h> #include <vtkXMLPolyDataReader.h> int main(int argc, char *argv[]) { if (argc < 2) { std::cerr << "Usage: " << argv[0] << " InputFileName(.vtp)" << std::endl; return EXIT_FAILURE; } //we will read Test.vtp std::string inputFilename = argv[1]; //read the file vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New(); reader->SetFileName(inputFilename.c_str()); reader->Update(); vtkPolyData* polydata = reader->GetOutput(); vtkDoubleArray* triangleArea = vtkDoubleArray::SafeDownCast(polydata->GetCellData()->GetArray("TriangleArea")); std::cout << "Triangle area: " << triangleArea->GetValue(0) << std::endl; return EXIT_SUCCESS; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.8) PROJECT(GetMiscCellData) find_package(VTK REQUIRED) include(${VTK_USE_FILE}) if (APPLE) add_executable(GetMiscCellData MACOSX_BUNDLE GetMiscCellData.cxx) else() add_executable(GetMiscCellData GetMiscCellData.cxx) endif() if(VTK_LIBRARIES) target_link_libraries(GetMiscCellData ${VTK_LIBRARIES}) else() target_link_libraries(GetMiscCellData vtkHybrid ) endif()