[vtkusers] Re: [Fwd: callback to manipulate actors?]

Goodwin Lawlor goodwin.lawlor at ucd.ie
Thu Nov 1 11:24:13 EDT 2007


John

Create a public method "SetActor" in your class callback which will set 
  a protected pointer to the actor you want to translate.

  class vtkMyCallback : public vtkCommand
  {
  public:
  static vtkMyCallback *New()
    { return new vtkMyCallback; }
   virtual void Execute(vtkObject *caller1, unsigned long, void*)
    {
      vtkRenderWindowInteractor *interact =
  reinterpret_cast<vtkRenderWindowInteractor*>(caller1);
       char* key = interact->GetKeySym();
       if (*key=='n')
          { // How to change the position of the actor
          this->Actor->SetPosition(pos);
          }
    }

   void SetActor(vtkActor *actor)
     {
     this->Actor = actor;
     }

   protected:
     vtkActor *Actor;
  }


vtkMyCallback *cb = vtkMyCallback::New();
   cb->SetActor(actor);



// You could set the cylinder pointer instead and alter is center.

hth

Goodwin

Joby John wrote:
> Hello VTK users,
> I am new to VTK and I am trying to use "callback" to change the position 
> of one of the actors in my renderWindow.
> How do I pass the actor (say for example an instance of 
> vtkCylinderSource) to the callback and use SetCenter to move its position.
> My callback code looks as follows,
> %%%%%%%%%%%%%%%%%%%%
> class vtkMyCallback : public vtkCommand
> {
> public:
> static vtkMyCallback *New()
>   { return new vtkMyCallback; }
> virtual void Execute(vtkObject *caller1, unsigned long, void*)
>   {
>     vtkRenderWindowInteractor *interact = 
> reinterpret_cast<vtkRenderWindowInteractor*>(caller1);
>      char* key = interact->GetKeySym();
>      if (*key=='n')
>         {              // How to change the position of the actor 
> described below. Say using SetCenter();
>          }
> }
> %%%%%%%%%%%%%%%%%%%%%%%%%%
> The actor is defined in the main code as such
> 
> vtkCylinderSource *C1 = vtkCylinderSource::New();       
> C1->SetCenter(5,1.5,0);
>   C1->SetRadius(2);
>   C1->SetHeight(1);
>   C1->SetResolution(24);   %%%%%%%%%%%%%%%%%%%%%%%%%%     Thanks in 
> advance,
> Joby.
> _______________________________________________
> This is the private VTK discussion list. Please keep messages on-topic. 
> Check the 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