[vtkusers] Saving a vtp file from vtkPolyData

Sam Raby rabysam28 at gmail.com
Sat May 10 16:27:49 EDT 2014


What I mean is that when I save the vtp file and then read it, the file
does not render anything (blank window). I think the source of problem is
that the vtkPolyData that is taken from surfaceMapper has 0 number of Ploy,
meaning that, in the ContoursToSurface example [1], if I add the following
lines:

vtkPolyData *myvtkPolyData = vtkPolyData::SafeDownCast(
surfaceMapper->GetInputAsDataSet() );

std:cerr << myvtkPolyData->GetNumberOfPolys();

it will print zero.

I resolved the issue, as it follows:

In the example [1], there is an instance of vtkTransformPolyDataFilter
which rescales the output from IJK coordinate system back into the world
coordinates. I just needed to add "UpdateWholeExtent()" method to it, and
this will update the pipeline:

transformFilter->UpdateWholeExtent();

This example [1] works fine, as long as someone wants to visualize the
results, however if someone wants to "use" the polyData (e.g. to save a vtp
file out of it), then, I think, it is necessary to either add the above
line or perform any alternative solution.

-S




[1] http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ContoursToSurface




On Sat, May 10, 2014 at 6:09 AM, David Doria <daviddoria at gmail.com> wrote:

> On Fri, May 9, 2014 at 4:55 PM, Sam Raby <rabysam28 at gmail.com> wrote:
>
>> In the following VTK example:
>>
>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ContoursToSurface
>>
>> after the surface of sphere is generated, I am trying to simply save the
>> surface as a vtp file using the following code, but I can not, that is, the
>> saved file does not show anything. Can anyone help why this happens?
>> Thanks.
>>
>>
>>     vtkPolyData *myvtkPolyData = vtkPolyData::SafeDownCast(
>> surfaceMapper->GetInputAsDataSet() );
>>     vtkSmartPointer<vtkXMLPolyDataWriter> writer =
>> vtkSmartPointer<vtkXMLPolyDataWriter>::New();
>>     writer->SetFileName("/home/surface.vtp");
>>     writer->SetInputData( myvtkPolyData );
>>     writer->SetDataModeToBinary();
>>     writer->Write();
>>
>
> What do you mean it does not show anything? How are you trying to view it?
> I would suggest using Paraview.
>
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140510/8538b0c6/attachment.html>


More information about the vtkusers mailing list