[vtkusers] Geometry Voxelization

TomPritchard t.j.pritchard at limitstate.com
Tue May 10 11:07:34 EDT 2011


I know this thread is *very* old now, but just in case it helps somebody in
the future:

==========================================================

#include <vtkSmartPointer.h>
#include <vtkContourFilter.h>
#include <vtkVoxelModeller.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkDataSetMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>

vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(ren1);
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);

vtkSmartPointer<vtkSphereSource> sphereModel =
vtkSmartPointer<vtkSphereSource>::New();
sphereModel->SetThetaResolution(10);
sphereModel->SetPhiResolution(10);
 
vtkSmartPointer<vtkVoxelModeller> voxelModel =
vtkSmartPointer<vtkVoxelModeller>::New();
voxelModel->SetInputConnection(sphereModel->GetOutputPort());
voxelModel->SetSampleDimensions(21, 21, 21);
voxelModel->SetModelBounds(-1.5, 1.5, -1.5 , 1.5, -1.5, 1.5);
voxelModel->SetScalarTypeToBit();
voxelModel->SetForegroundValue(1);
voxelModel->SetBackgroundValue(0);

// some stuff about writing /reading .vtk here in tcl, ignoring this for now
 
vtkSmartPointer<vtkContourFilter> voxelSurface =
vtkSmartPointer<vtkContourFilter>::New();
voxelSurface->SetInputConnection(voxelModel->GetOutputPort());
voxelSurface->SetValue(0, 0.999);
  
vtkSmartPointer<vtkPolyDataMapper> voxelMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
voxelMapper->SetInputConnection(voxelSurface->GetOutputPort());

vtkSmartPointer<vtkActor> voxelActor = vtkSmartPointer<vtkActor>::New();
voxelActor->SetMapper(voxelMapper);

vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper->SetInputConnection(sphereModel->GetOutputPort());

vtkSmartPointer<vtkActor> sphereActor = vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper(sphereMapper);

ren1->AddActor(sphereActor);
ren1->AddActor(voxelActor);

ren1->SetBackground(.1, .2, .4); // Background color blue
renWin->SetSize(256,256);
ren1->ResetCamera();
ren1->ResetCameraClippingRange();

renWin->Render();
iren->Start();

==========================================================


--
View this message in context: http://vtk.1045678.n5.nabble.com/Geometry-Voxelization-tp1230981p4384725.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list