[vtkusers] Voxelization
Daniel Soares
adaptchart.info at gmail.com
Thu Mar 11 18:29:25 EST 2010
I'm sorry, but there is no method called GetPolyData in vtkSphereSource.
Also there's no class named GetPolyData. So I don't understand what you are
suggesting. Plus, if I subdivide a polydata I will have a polydata with more
polygons, and that's not what I want.
Any other suggestions?
2010/3/11 KS Jothybasu <jothybasu at gmail.com>
> SphereSource--GetPolydata--CreateMesh--Subdivide should work I think. Let
> me know, if you find any solution as I too need to do this at some point of
> time.
>
> Thanks
>
> Jothy
>
> On Thu, Mar 11, 2010 at 1:16 AM, Daniel Soares <adaptchart.info at gmail.com>wrote:
>
>> 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
>>>
>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100311/de84de33/attachment.htm>
More information about the vtkusers
mailing list