[vtkusers] Voxelization

Daniel Soares adaptchart.info at gmail.com
Tue Mar 9 20:30:29 EST 2010


Hi!

I have a problem with voxelization in VTK. My purpose is to create a sphere
using vtkSphereSource, then voxelize it using vtkVoxelModeller, then draw a
surface that is similar to the original sphere. The only way I managed to
draw a surface, was using vtkContourFilter. The problem is that some
artifacts are produced, looking like holes in the voxelized sphere.
I saw at this site ( http://www.evl.uic.edu/aspale/cs526/final/3-5-2-0.htm ),
that the results with vtkMarchingCubes are much better than the ones with
vtkContourFilter. So I tryied to use it, but I couldn't obtain any result at
all (blank screen). The same happened when I used vtkDiscreteMarchingCubes
and vtkImageMarchingCubes.

Does anyone have any idea why the marching cubes are not producing results
or why the contour filter produces holes on the surface? Is there other way
to achive what I want?

Here's the source code of my experiment:

//===============================================

vtkSphereSource* sphereModel = vtkSphereSource::New();
sphereModel->SetThetaResolution(10);
sphereModel->SetPhiResolution(10);

vtkVoxelModeller* voxeller = vtkVoxelModeller::New();
voxeller->SetSampleDimensions(17, 17, 17);
voxeller->SetModelBounds(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5);
voxeller->SetInputConnection(sphereModel->GetOutputPort());
voxeller->Update();
vtkImageData* imageData = voxeller->GetOutput();
imageData->SetScalarTypeToFloat();

vtkLookupTable* lut = vtkLookupTable::New();
lut->SetNumberOfColors(3);
lut->SetTableRange(0, 1);
lut->SetScaleToLinear();
lut->Build();
lut->SetTableValue(0, 0, 0, 0, 1);
lut->SetTableValue(0.5, 1, 0, 0, 1);
lut->SetTableValue(1, 1, 1, 1, 1);

//vtkContourFilter* surface = vtkContourFilter::New();
vtkMarchingCubes* surface = vtkMarchingCubes::New();
surface->SetInput(imageData);
surface->ComputeScalarsOn();
surface->ComputeGradientsOn();
surface->ComputeNormalsOn();
surface->SetValue(0, 0.5);

vtkPolyDataMapper* voxelMapper = vtkPolyDataMapper::New();
voxelMapper->SetInputConnection(discrete->GetOutputPort());
voxelMapper->SetLookupTable(lut);
voxelMapper->SetScalarRange(0, lut->GetNumberOfColors());

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

ren1->AddActor(voxelActor);

//==============================================

Thanks in advance.

Daniel Soares
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100309/74dd15df/attachment.htm>


More information about the vtkusers mailing list