Difference between revisions of "VTK/Examples/Cxx/IO/GenericDataObjectReader"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(Missing vtkPolyData.h and style.)
(3 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
int main ( int argc, char *argv[] )
 
int main ( int argc, char *argv[] )
 
{
 
{
   //ensure a filename was specified
+
   // Ensure a filename was specified
   if ( argc != 2 )
+
   if(argc != 2)
 
     {
 
     {
 
     std::cerr << "Usage: " << argv[0] << " InputFilename" << endl;
 
     std::cerr << "Usage: " << argv[0] << " InputFilename" << endl;
Line 16: Line 16:
 
     }
 
     }
  
   //get the filename from the command line
+
   // Get the filename from the command line
 
   std::string inputFilename = argv[1];
 
   std::string inputFilename = argv[1];
  
   //get all data from the file
+
   // Get all data from the file
 
   vtkSmartPointer<vtkGenericDataObjectReader> reader =  
 
   vtkSmartPointer<vtkGenericDataObjectReader> reader =  
 
       vtkSmartPointer<vtkGenericDataObjectReader>::New();
 
       vtkSmartPointer<vtkGenericDataObjectReader>::New();
   reader->SetFileName ( inputFilename.c_str() );
+
   reader->SetFileName(inputFilename.c_str());
 
   reader->Update();
 
   reader->Update();
 
    
 
    
   //all of the standard data types can be checked and obtained like this:
+
   // All of the standard data types can be checked and obtained like this:
 
   if(reader->IsFilePolyData())
 
   if(reader->IsFilePolyData())
 
     {
 
     {
Line 38: Line 38:
 
</source>
 
</source>
  
==CMakeLists.txt==
+
{{VTKCMakeLists|GenericDataObjectReader}}
<source lang="cmake">
+
cmake_minimum_required(VERSION 2.6)
+
 
+
PROJECT(GenericDataObjectReader)
+
 
+
FIND_PACKAGE(VTK REQUIRED)
+
INCLUDE(${VTK_USE_FILE})
+
 
+
ADD_EXECUTABLE(GenericDataObjectReader GenericDataObjectReader.cxx)
+
TARGET_LINK_LIBRARIES(GenericDataObjectReader vtkHybrid)
+
 
+
</source>
+

Revision as of 17:12, 8 September 2011

GenericDataObjectReader.cxx

#include <vtkGenericDataObjectReader.h>
#include <vtkStructuredGrid.h>
#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <string>
 
int main ( int argc, char *argv[] )
{
  // Ensure a filename was specified
  if(argc != 2)
    {
    std::cerr << "Usage: " << argv[0] << " InputFilename" << endl;
    return EXIT_FAILURE;
    }
 
  // Get the filename from the command line
  std::string inputFilename = argv[1];
 
  // Get all data from the file
  vtkSmartPointer<vtkGenericDataObjectReader> reader = 
      vtkSmartPointer<vtkGenericDataObjectReader>::New();
  reader->SetFileName(inputFilename.c_str());
  reader->Update();
 
  // All of the standard data types can be checked and obtained like this:
  if(reader->IsFilePolyData())
    {
    std::cout << "output is a polydata" << std::endl;
    vtkPolyData* output = reader->GetPolyDataOutput();
    std::cout << "output has " << output->GetNumberOfPoints() << " points." << std::endl;
    }
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
 
PROJECT(GenericDataObjectReader)
 
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
 
add_executable(GenericDataObjectReader MACOSX_BUNDLE GenericDataObjectReader.cxx)
 
if(VTK_LIBRARIES)
  target_link_libraries(GenericDataObjectReader ${VTK_LIBRARIES})
else()
  target_link_libraries(GenericDataObjectReader vtkHybrid vtkWidgets)
endif()

Download and Build GenericDataObjectReader

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

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

cd GenericDataObjectReader/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:

./GenericDataObjectReader

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.