[vtkusers] VTK5.6.1: One  render window, multiple renders and auto interactor style solution

Andre Souza a.souz36 at gmail.com
Fri May 6 14:29:22 EDT 2011


Hi everyone,

I'm answering myself here with a solution for my question. I solved my
problem by adding an observer to the interactor object that whatches for a
MouseMoveEvent to call my callback function. - Andre

-------
vtkVolumeInteractionCallback* callback =
vtkVolumeInteractionCallback::New();
  callback->SetInteractor(iren);
  callback->SetImageInteractorStyle(imageStyle);
  callback->SetImageRenderer(rendererImage);
  callback->SetVolumeInteractorStyle(volumeStyle);

  iren->AddObserver(vtkCommand::MouseMoveEvent, callback);
  callback->Delete();
---------

//Callback for automatic change of interaction styles
class vtkVolumeInteractionCallback : public vtkCommand
{
public:

  static vtkVolumeInteractionCallback *New() {
    return new vtkVolumeInteractionCallback; };
 
  vtkVolumeInteractionCallback() {
    this->Interactor = 0;
    this->VolumeIren = 0;
    this->ImageIren = 0;
    this->ImageRenderer = 0;};


  void SetInteractor(vtkRenderWindowInteractor *interactor) {
    this->Interactor = interactor; };

  vtkRenderWindowInteractor *GetInteractor() {
    return this->Interactor; };

  void SetVolumeInteractorStyle(vtkInteractorStyleSwitch* m) { this->
VolumeIren = m; };
  void SetImageInteractorStyle(vtkInteractorStyleImage* m) { this->ImageIren
= m; };
  void SetImageRenderer(vtkRenderer* imageRenderer){ this->ImageRenderer =
imageRenderer; };
  
  virtual void Execute(vtkObject *, unsigned long event, void *)
    {
     vtkRenderWindowInteractor *interactor = this->GetInteractor();

     int lastPos[2];
     interactor->GetLastEventPosition(lastPos);
     int currPos[2];
     interactor->GetEventPosition(currPos);
     double port[4];

       
     if (event == vtkCommand::MouseMoveEvent) {
        vtkRenderer *renderer = interactor->FindPokedRenderer(currPos[0],
currPos[1]);
        if (renderer == ImageRenderer) {
            interactor->SetInteractorStyle(this->ImageIren);        
        }else {
            interactor->SetInteractorStyle(this->VolumeIren);           
        }
        vtkInteractorStyle *style = vtkInteractorStyle::SafeDownCast(
          interactor->GetInteractorStyle());
        if (style)
          {
          style->OnMouseMove();
          }      
   }
  };
 
private: 

  // Pointer to the interactor
  vtkRenderWindowInteractor *Interactor;

  //pointer to interactor volume style
  vtkInteractorStyleSwitch *VolumeIren;

  //pointer to interactor image style
  vtkInteractorStyleImage *ImageIren;

 //pointer to image renderer
  vtkRenderer *ImageRenderer;

};




--
View this message in context: http://vtk.1045678.n5.nabble.com/VTK5-6-1-One-render-window-multiple-renders-and-auto-interactor-style-solution-tp4358940p4376754.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list