[vtkusers] Save a vtkContourTriangulator output inside a PNG

Romain LEGUAY romain.leguay at gmail.com
Fri Nov 6 09:32:18 EST 2015


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
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151106/4694e8c8/attachment.html>


More information about the vtkusers mailing list