[vtkusers] Save a vtkContourTriangulator output inside a PNG

Cory Quammen cory.quammen at kitware.com
Fri Nov 6 09:41:39 EST 2015


Romain,

Let's pop up a level and discuss what you are trying to do. It sounds like
you are trying to voxelize a geometry into a 3D image. Is that right?

You don't have to use the vtkCutter at all but rather set your geometry as
the input for vtkPolyDataToImageStencil. I have used this class for
voxelization in the past and it works very well.

HTH,
Cory

On Fri, Nov 6, 2015 at 9:32 AM, Romain LEGUAY <romain.leguay at gmail.com>
wrote:

> Thanks David for your answer!
>
> I just saw on the vtkPolyDataToImageStencil documentation that the contour
> must be align throw the Z planes.
>
> I use vtkCutter to cut my mesh along Z-axis but all the pictures saved are
> black. I attached my code and the CMakeLists.txt.
>
> Is there another way to "project" my filled contour on an image?
>
> Thanks again.
>
> Romain
>
>
>
> 2015-11-06 14:15 GMT+01:00 David Gobbi <david.gobbi at gmail.com>:
>
>> Hi Romain,
>>
>> The vtkPolyDataToImageStencil class needs a "hollow" shape as input,
>> either a 3D surface or a 2D contour.  If you fill the contour, then it
>> can't
>> be used by vtkPolyDataToImageStencil.
>>
>>  - David
>>
>>
>> On Fri, Nov 6, 2015 at 2:22 AM, Romain LEGUAY <romain.leguay at gmail.com>
>> wrote:
>>
>>> Hello everyone,
>>>
>>> In purpose to create a series of pictures (with the same size 512*512
>>> for example), I cut a mesh along an axis (X, Y or Z) with vtkCutter, then I
>>> triangulate those contours with vtkContourTriangulator. I obtain some
>>> "flat" vtkPolydata*s* (one per cut). Now, I want to save all those
>>> "flat" meshes to 2D images with fixed size.
>>> I saw on the wiki (
>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData)
>>> how to convert a vtkPolydata in vtkImageData, but in this case, my
>>> vtkPolydata is in a plane (the output of vtkContourTriangulator) so the
>>> dimension of the white image is 0 or negative because of this part of code:
>>>
>>> vtkSmartPointer<vtkImageData> whiteImage =
>>> vtkSmartPointer<vtkImageData>::New();
>>> double bounds[6];
>>> polydata->GetBounds(bounds);
>>> double spacing[3]; // desired volume spacing
>>> spacing[0] = 0.5;
>>> spacing[1] = 0.5;
>>> spacing[2] = 0.5;
>>> whiteImage->SetSpacing(spacing);
>>>
>>> // compute dimensions
>>> int dim[3];
>>> for (int i = 0; i < 3; i++)
>>> {
>>>   dim[i] = static_cast<int>(ceil((bounds[i * 2 + 1] - bounds[i * 2]) /
>>> spacing[i])); // One of the dimension is 0
>>> }
>>> whiteImage->SetDimensions(dim);
>>> whiteImage->SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, dim[2] - 1); //
>>> Here
>>>
>>>
>>> I don't know if there is other choice to convert a polydata to an image
>>> but this code always give some black pictures.
>>> I'm not sure if I use the good filter to convert my polydata to a 2D
>>> image but I don't find anything.
>>>
>>> Do you have any clues?
>>>
>>> Thanks,
>>>
>>> Romain
>>>
>>
>
> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151106/e0a5374d/attachment.html>


More information about the vtkusers mailing list