VTK/Examples/Broken/VoxelModeller

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

VTK_BIT is no longer supported.

VoxelModeller.cxx

#include <vtkSmartPointer.h>
#include <vtkVoxelModeller.h>
#include <vtkSphereSource.h>
#include <vtkPolyData.h>
#include <vtkImageCast.h>
#include <vtkXMLImageDataWriter.h>

int main(int argc, char *argv[])
{
  vtkSmartPointer<vtkSphereSource> sphereSource = 
      vtkSmartPointer<vtkSphereSource>::New();
  
  double bounds[6];
  sphereSource->GetOutput()->GetBounds(bounds);
  
  vtkSmartPointer<vtkVoxelModeller> voxelModeller = 
      vtkSmartPointer<vtkVoxelModeller>::New();
  voxelModeller->SetSampleDimensions(20,20,20);
  //voxelModeller->SetSampleDimensions(100,100,100);
  voxelModeller->SetModelBounds(bounds);
  voxelModeller->SetOutputScalarTypeToUnsignedChar();
      
  voxelModeller->SetInputConnection(sphereSource->GetOutputPort());
  voxelModeller->Update();
  
  vtkSmartPointer<vtkImageCast> imageCastFilter = 
      vtkSmartPointer<vtkImageCast>::New();
  imageCastFilter->SetInputConnection(voxelModeller->GetOutputPort());
  imageCastFilter->SetOutputScalarTypeToUnsignedChar();
  imageCastFilter->Update();
  
  vtkSmartPointer<vtkXMLImageDataWriter> writer = 
      vtkSmartPointer<vtkXMLImageDataWriter>::New();
  writer->SetInputConnection(imageCastFilter->GetOutputPort());
  writer->SetFileName("voxel.vti");
  writer->Write();
  
  return EXIT_SUCCESS;
}

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(VoxelModeller)

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

add_executable(VoxelModeller MACOSX_BUNDLE VoxelModeller.cxx)

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

Download and Build VoxelModeller

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

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

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

./VoxelModeller

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.