[vtkusers] Voxelization
Daniel Soares
adaptchart.info at gmail.com
Wed Mar 10 20:16:09 EST 2010
Here's the code of my experiment. You can easily change it to switch between
vtkContourFilter and vtkMarchingCubes. As I said, vtkContourFilter displays
holes on the voxelized sphere and vtkMarchingCubes doesn't display anything.
#include "vtkActor.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyData.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkImageData.h"
#include "vtkVoxelModeller.h"
#include "vtkMarchingCubes.h"
#include "vtkContourFilter.h"
#include "vtkSphereSource.h"
int main(int argc, char *argv[]) {
vtkRenderer* ren1 = vtkRenderer::New();
ren1->SetBackground(1, 1, 1); // Background color white
vtkRenderWindow* renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
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());
vtkContourFilter* surface = vtkContourFilter::New();
//vtkMarchingCubes* surface = vtkMarchingCubes::New();
surface->SetInputConnection(voxeller->GetOutputPort());
surface->SetNumberOfContours(1);
surface->ComputeScalarsOn();
surface->ComputeGradientsOn();
surface->ComputeNormalsOn();
surface->SetValue(0, 0.5);
vtkPolyDataMapper* voxelMapper = vtkPolyDataMapper::New();
voxelMapper->SetInputConnection(surface->GetOutputPort());
vtkActor* voxelActor = vtkActor::New();
voxelActor->SetMapper(voxelMapper);
vtkPolyDataMapper* sphereMapper = vtkPolyDataMapper::New();
sphereMapper->SetInputConnection(sphereModel->GetOutputPort());
vtkActor* sphereActor = vtkActor::New();
sphereActor->SetMapper(sphereMapper);
//ren1->AddActor(sphereActor);
ren1->AddActor(voxelActor);
renWin->Render();
iren->Start();
}
2010/3/10 David Doria <daviddoria+vtk at gmail.com <daviddoria%2Bvtk at gmail.com>
>
> On Wed, Mar 10, 2010 at 6:12 PM, Daniel Soares <adaptchart.info at gmail.com>wrote:
>
>> I suppose you are saying that I use the following pipeline:
>>
>> vtkSphereSource -> vtkVoxelModeller -> vtkDelaunay3D
>>
>> The problem is that the input of vtkDelaunay3D is a vtkPointSet and the
>> output of vtkVoxelModeller is a vtkImageData. How could I convert a
>> vtkImageData to a vtkPointSet?
>>
>> Anyway, it looks like the solution involves vtkMarchingCubes, as it's
>> input is a vtkImageData. The problem is that vtkMarchingCubes is not
>> displaying any result when used in my source code.
>>
>> Any ideas?
>>
>> Daniel Soares
>>
>>
> To convert an ImageData to a PointSet, I don't think there is a better way
> than to do:
>
> vtkPolyData* pd = vtkPolyData::New();
> for(unsigned int i = 0; i < image->GetNumberOfPoints(); i++
> {
> double p[3];
> image->GetPoint(i, p);
> pd->InsertNextPoint(p);
> }
>
> As for why marching cubes doesn't display anything - maybe you can make the
> simplest example that will compile - make a sphere source, convert it to an
> ImageData, then run MarchingCubes. Post this compilable code to the list and
> we'll check it out.
>
> Thanks,
>
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100310/52df1841/attachment.htm>
More information about the vtkusers
mailing list