[vtk-developers] SafeDownCast returns NULL for derived data type

David Gobbi david.gobbi at gmail.com
Thu Sep 27 10:48:10 EDT 2012


Hi Roy,

If you subclass a VTK data object, then subclass members like
the PhaseCount that you have added will not be passed through
the pipeline, because the pipeline is not aware of them.

I suggest that, instead of subclassing, you just use vtkImageData
and add FieldData arrays that contain extra values.  Here's an
example in python, but it should be easy to translate into C++:

  data = vtk.vtkImageData()

  v = vtk.vtkIntArray()
  v.SetName("PhaseCount")
  v.InsertNextValue(1)

  data.GetFieldData().AddArray(v)

You can retrieve the array like this:

  data.GetFieldData().GetArray("PhaseCount")

The FieldData is passed through the VTK pipeline,
and if you write your own VTK filters then you can
modify the FieldData.

 - David


On Thu, Sep 27, 2012 at 3:29 AM, Pelt, R.F.P. van <R.F.P.v.Pelt at tue.nl> wrote:
> Dear all,
>
> Recently, I’m working on a reader derived from vtkMedicalImageReader2.
> I’ve also declared my own data type:
>
> #include "vtkImageData.h"
>
> class qfeVTIImageData : public vtkImageData
> {
> public:
>   static qfeVTIImageData *New();
>
>   vtkTypeMacro(qfeVTIImageData,vtkImageData);
>
>   vtkSetMacro(PhaseCount, int);
>   vtkGetMacro(PhaseCount, int);
>
>
>
>   ...
>
>
>
> When I attempt a SafeDownCast to vtkImageData, the macro returns NULL.
>
> It seems like the IsTypeOf does not traverse up the hierarchy to
> vtkObjectBase.
>
> Anyone know what could be the issue here?
>
> When using a static_cast, I can get the data object.
> However, the added variables in the derived data type  (e.g., phasecount in
> the example above),
> give an error upon assignment. I guess this memory is not allocated.
> What am I doing wrong here?
>
> Thanks.
>
> Roy



More information about the vtk-developers mailing list