[prev in list] [next in list] [prev in thread] [next in thread]
List: vtk-developers
Subject: Re: [vtk-developers] SafeDownCast returns NULL for derived data type
From: David Gobbi <david.gobbi () gmail ! com>
Date: 2012-09-27 14:48:10
Message-ID: CANwS1=EfcVwAKQs1a0Nv6fq-9zx-u-WBE+ZPeuSXAcMoBoXFkw () mail ! gmail ! com
[Download RAW message or body]
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@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
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtk-developers
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic