[vtkusers] Re: deriving from vtkActor to add an ID (was: A question)

John Biddiscombe jbiddiscombe at skippingmouse.co.uk
Fri Apr 30 04:30:50 EDT 2004


As you have noticed, creating a vtkActor actually returns a vtkOpenGlActor
etc, so subclassing vtkActor doesn't help you. subclass vtkOpenGlActor, add
the ID, then edit vtkGraphicsFactory so that it returns a vtkMyOpenGlActor
instead of the vtkOpenGlActor

JB


----- Original Message ----- 
From: "Wiebke Timm" <wiebke.timm at uni-bielefeld.de>
To: <vtkusers at vtk.org>
Cc: "Luke Hua" <luke_qz at yahoo.com>
Sent: Friday, April 30, 2004 9:05 AM
Subject: [vtkusers] Re: deriving from vtkActor to add an ID (was: A
question)


> Hi again!
>
> Replying to my own post because just now I found out my answer was kind
> of wrong although in the first place the solution might have worked. I
> hope Luke Hua is still reading...
>
> The question was how to extend a vtkActor to have an int more to hold
> an ID. Maybe some more experienced users could have a look because I'm
> still not sure how to extend a vtkSomething in an orderly manner.
>
> My answer to that question was the following:
>
> On 09.03.2004, at 10:31, Wiebke Timm wrote:
>
> > You can extend vtkActor to have an ID. Did that and it works
> > flawlessly. Just use the extended vtkActor instead of the original.
> > When your picker/renderer returns an actor you can get the ID easily.
> > If you don't want to set that ID yourself you can add a static
> > variable that "counts" actors, i.e. it has to be incremented inside
> > the New() method, then set the ID accordingly.
>
> This is still true. But the way _how_ this has to be done was wrong - I
> wonder why nobody spoke up... :
>
> > vtkMyActor.h looks like this:
> >
> > #ifndef MYACT_H
> > #define MYACT_H
> >
> > #include <vtkActor.h>
> >
> > class vtkMyActor : public vtkActor {
> >    public:
> >       int GetID();
> >       void SetID(int id);
> >       static vtkMyActor* New();
> >       void Delete();
> >
> >    private:
> >       int id;         // id of this glyph's actor
> >
> > };
> > #endif
> >
> >
> >
> > vtkMyActor.cc looks like this:
> >
> > #include "vtkMyActor.h"
> >
> > vtkMyActor* vtkMyActor::New() {
> >    vtkActor::New();
> > }
> >
> > void vtkMyActor::Delete() {
> >    vtkActor::Delete();
> > }
> >
> > int vtkMyActor::GetID() {
> >    return this->id;
> > }
> >
> > void vtkMyActor::SetID(int id) {
> >    this->id = id;
> > }
>
> Got a few seg faults at the end of my vtkqt program, valgrind reported
> memory leaks of 4 byte size (that's an int...) when I used the GetID()
> and SetID(int id) methods. That's because above
>
> vtkActor::New();
>
> inside the overwritten New() method doesn't allocate memory for that
> int!
>
> Luke, did your version you posted have that leaks (should have if I
> read it correctly)?
>
>
> Also I read in the vtk Users Guide that I have to derive a new factory
> from vtkObjectFactory, register the override of vtkActor with
> vtkMyActor and use some macros to get a create method to work. Isn't
> there an easier and shorter way to just add an int to a class... ??? I
> don't need any dynmically loaded classes during runtime.
> I also thought about writing a wrapper class that holds the int ID
> _and_ the vtkActor without extending vtkActor. That would be shorter
> but kind of dirty in my understanding.
>
> The book also says you have to implement the copy constructor, the
> operator=, and some other methods when deriving from a vtk class, but
> in the "own factory" example these methods aren't implemented. So now
> I'm confused _which_ methods really _have to_ be implemented and which
> are optional. (In general the book is a little cursory IMO.)
>
> There have to be people who already derived from vtk classes, I'm sure.
> So does any of you have any recommendations...?
>
> Ciao!
>     Wiebke
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list