[vtkusers] Re: A question

Luke Hua luke_qz at yahoo.com
Mon Mar 22 17:02:39 EST 2004


Just so let you know. I finally derived my own actor class with your method. 
 
However, I made some changes to your class to make it compile in my application(VC6.0&MFC)
 
1) I have to change the super class from vtkActor to vtkOpenGLActor. Otherwise, the render window won't render. I don't know why.
 
2) I change the new method to
vtkMyActor* vtkMyActor::New() {
 vtkObject* ret = vtkObjectFactory::CreateInstance("vtkActor");
 if(ret)
  {
  return (vtkMyActor*)ret;
  }
 return (vtkMyActor*) new vtkMyActor;
}
 
Thank for your help!
 
                                                         Luke
 
 
 
 
On 08.03.2004, at 21:19, Luke Hua wrote:

> Is there any way to retrieve actor by ID or properties? My renderer 
> has various kind of actors and I need to delete and add them 
> dynamically. It's very difficult to track the position of actors using 
> Initialtraversal().
> 
> There is no return values for addActor(). Could vtk make some changes 
> so that the addActor() can return a ID for each actor therefore easier 
> to retrieve actors?
> 
> Or there is any other way to retrieve actors?

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.


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;
}


Hope that helps...

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

Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040322/05d9fe68/attachment.htm>


More information about the vtkusers mailing list