[vtkusers] doubt in conversion from VRML to VTK

Alex Malyushytskyy alexmalvtk at gmail.com
Mon Aug 29 16:18:02 EDT 2011


Try to compile what you suggested and you will quickly find why.
Mapper will return you pointer to vtkDataSet *:
vtkDataSet * vtkMapper::GetInput();

       vtkPolyData* pDataset::vtkPolyData::New();
...
       pDataset = actors -> GetNextActor()->GetMapper()->GetInput();

// Line will not compile ,

       vtkPolyData pointer is also pointer to vtkDataset .
      vtkDataset  pointer might point to instance of the class which
has noting to do with vtkPolyData,


Since you know that you should deal with  vtkPolyData you need to cast pointer,
which has nothing to do with data conversion.

Regards,
  Alex



On Mon, Aug 29, 2011 at 9:10 AM, nuno.jf <nunofernandes7 at gmail.com> wrote:
> Dear Users,
>
> I have a doubt regarding a piece of code that converts a VRML file,
> containing geometric data, into a VTK (polydata) file. (link to the code:
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/VRML)
> The code is similar to this:
>
>        imp = vtkVRMLImporter::New();
>        imp -> SetFileName( fileName );
>        imp -> Read();
>        imp -> Update();
>
>        vtkDataSet *pDataset;
>        vtkActorCollection *actors = imp -> GetRenderer()->GetActors();
>        actors -> InitTraversal();
>        pDataset = actors -> GetNextActor()->GetMapper()->GetInput();
>
>        vtkPolyData *polyData = vtkPolyData::SafeDownCast( pDataset );
>        polyData -> Update();
>
> My question is: Why do we need to first convert to vtkDataSet, instead of
> directly converting to vtkPolyData, since vtkPolyData is a derived classe of
> vtkDataSet? I don't know If I am being totally clear, but why not doing
> this:
>
>        imp = vtkVRMLImporter::New();
>        imp -> SetFileName( fileName );
>        imp -> Read();
>        imp -> Update();
>
>        vtkPolyData *pDataset::vtkPolyData::New();
>        vtkActorCollection *actors = imp -> GetRenderer()->GetActors();
>        actors -> InitTraversal();
>        pDataset = actors -> GetNextActor()->GetMapper()->GetInput();
>        pDataset->update();
>
> Is this because there needs to be some specific way to convert the data to
> vtkPolyData? If so, is this done by SafeDownCast()? I know that
> SafeDownCast() converts a base-class pointer to a derive-class pointer and
> verifies the inheritance.
> I am a little confused, so any help would be greatly appreciated.
> Thank you,
>
> Nuno
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/doubt-in-conversion-from-VRML-to-VTK-tp4746682p4746682.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
>



More information about the vtkusers mailing list