[vtkusers] Geometry Voxelization

Bill Lorensen bill.lorensen at gmail.com
Tue May 10 16:25:44 EDT 2011


I would not use
voxelModel->SetScalarTypeToBit();

I believe that ContourFilter will not work with this type.

Here is an example:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Modelling/MarchingCubes

Bill
On Tue, May 10, 2011 at 11:07 AM, TomPritchard <t.j.pritchard at limitstate.com
> wrote:

> 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.
> _______________________________________________
> 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/20110510/08b2c14b/attachment.htm>


More information about the vtkusers mailing list