[vtkusers] Fill closed surface with voxels.

Hendrik Belitz hbelitz at darkon.info
Sat Aug 25 09:02:01 EDT 2007


Hi Vladimir,

maybe the following code fragment will suffice:
	
	// Stencil is created from PolyData and empty ImageData
	vtkImageData* vi = vtkImageData::New();
        vi->SetOrigin( 0,0,0 ); // adjust these to your needs
        vi->SetSpacing( 1,1,1 ); // adjust these to your needs
        vi->SetDimensions( 181,217,181 ); // adjust these to your needs
        vi->SetScalarTypeToUnsignedChar ();
        vi->AllocateScalars(); 
	// outputMesh is of vtkPolyData* type and contains your mesh data
	vtkPolyDataToImageStencil* pti = vtkPolyDataToImageStencil::New();
        pti->SetInput( outputMesh );
        pti->Update();
        vtkImageStencil* is = vtkImageStencil::New();
        is->SetInput( vi );
        is->SetStencil( pti->GetOutput() );
        is->ReverseStencilOff();
        is->SetBackgroundValue(1);
        is->Update();
	// is->GetOutput() returns your image data as vtkImageData*

Regards
 Hendrik

-------------------------------------------------------------------
Brilliance is typically the act of an individual, but incredible
stupidity can usually be traced to an organization. - Jon Bentley

Hendrik Belitz, Computer Scientist
email: hbelitz at computer.org or hbelitz at ieee.org


On Saturday 25 August 2007 07:24:51 Vladimir Lazunin wrote:
> Thank you, Hendrik. From the description of vtkPolyDataToImageStencil it
> looks like what I need. Hope I won't be too annoying by asking if you
> have any code example?
> Now I'm trying to figure it out from the only example I found in VTK
> "Examples" folder, but it does something too different.
>
> Vladimir.
>
> Hendrik Belitz wrote:
> > Hi Vladimir,
> >
> > since I guess that this is essentially the same problem Achim Poll
> > required a solution for a day before, I'll give you the same answer:
> >
> > With high probability, this answer is still valid:
> > http://public.kitware.com/pipermail/vtkusers/2002-April/060535.html
> >
> > I use vtkPolyDataToImageStencil for myself with good results to
> > "voxelize" polydata meshes. Even more decent results could be obtained
> > by using an external library, like object voxelization by filterung
> > for example( http://www.viskom.oeaw.ac.at/~milos/
> > <http://www.viskom.oeaw.ac.at/%7Emilos/> ), with the only drawback
> > that you need to convert your data by yourself into the appropiate
> > formats.
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070825/772061ca/attachment.pgp>


More information about the vtkusers mailing list