VTK/Examples/Broken/DataObjectToTable

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

How to get point coordinates into the table?

DataObjectToTable.cxx

#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkPolyData.h>
#include <vtkDataObjectToTable.h>
#include <vtkTable.h>

int main(int argc, char *argv[])
{
  
  //Create a sphere
  vtkSmartPointer<vtkSphereSource> sphereSource = 
      vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->Update();

  vtkSmartPointer<vtkDataObjectToTable> dataObjectToTable = 
      vtkSmartPointer<vtkDataObjectToTable>::New();
  dataObjectToTable->SetInputConnection(sphereSource->GetOutputPort());
  //dataObjectToTable->SetFieldType(vtkDataObjectToTable::POINT_DATA);
  //dataObjectToTable->SetFieldType(vtkDataObjectToTable::CELL_DATA);
  dataObjectToTable->Update();
  
  vtkSmartPointer<vtkTable> table = dataObjectToTable->GetOutput();
  table->Dump();
  
  return EXIT_SUCCESS;
}

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(DataObjectToTable)

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

add_executable(DataObjectToTable MACOSX_BUNDLE DataObjectToTable.cxx)

if(VTK_LIBRARIES)
  target_link_libraries(DataObjectToTable ${VTK_LIBRARIES})
else()
  target_link_libraries(DataObjectToTable vtkHybrid vtkWidgets)
endif()

Download and Build DataObjectToTable

Click here to download DataObjectToTable. and its CMakeLists.txt file.

Once the tarball DataObjectToTable.tar has been downloaded and extracted,

cd DataObjectToTable/build 
  • If VTK is installed:
cmake ..
  • If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

Build the project:

make

and run it:

./DataObjectToTable

WINDOWS USERS PLEASE NOTE: Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.