[vtkusers] using a custom Callback

Dean Inglis dean.inglis at on.aibn.com
Mon Jun 24 15:17:21 EDT 2002


Hi,

the effect I'm trying to generate is to show a vtkAxes, usually aligned with
the origin and axes of a (3D) vtkImageData, but offset and scaled so that
the axes appears in a corner of a render window.  When the outline of the
image bounding box is rotated interactively, the axes in the corner rotates
(but does not scale or translate).  I'm trying to do this with the following
code snippet:


// Callback for the interaction
class vtkAxesCallback : public vtkCommand
{
public:

  static vtkAxesCallback *New()
    { return new vtkAxesCallback; }

  vtkAxesCallback():transform(0),axes(0),renderer(0){};
  vtkRenderer  *renderer;
  vtkTransform *transform;
  vtkAxes      *axes;

  virtual void Execute(vtkObject *caller, unsigned long, void* )
    {
    vtkInteractorStyle *self = reinterpret_cast<vtkInteractorStyle
*>(caller);
    vtkRenderWindowInteractor *iren = self->GetInteractor();
    vtkRenderWindow *renwin = iren->GetRenderWindow();
    vtkRendererCollection *collection = renwin->GetRenderers();
    if ( collection->IsItemPresent((vtkObject*)renderer) )
      {
      renderer->NormalizedViewportToViewport(0.1,0.1);
      renderer->GetViewPoint(vp);
      renderer->ViewToWorld(vp[0],vp[1],vp[2]);
      renderer->GetWorldPoint(wp);
      axes->GetOrigin(ao);
      transform->Identity();
      transform->Translate(ao[0]-wp[0],ao[1]-wp[1],ao[2]-wp[2]);
      transform->Modified();
      cout << vp[0] << vp [1] << vp[2] <<endl ;
      }
     else
     {
     cout << "not present..." << endl;
     }
    }

protected:
  float vp[3];
  float wp[4];
  float ao[3];
};


and when adding the axes to the renderer:

void vtkMyClass::AddToRenderer(vtkRenderer* aren)
{
  if ( ! aren )
    {
    return;
    }

  aren->AddActor(this->AxesActor);

  this->AxesCB->renderer = aren;

  vtkInteractorStyle *style = (vtkInteractorStyle
*)(aren->GetRenderWindow()->GetInteractor()->GetInteractorStyle());
  if(style)
    {
  style->AddObserver(vtkCommand::InteractionEvent,this->AxesCB);
  vtkGenericWarningMacro(<<"style found...");
    }
  else
   {
   vtkGenericWarningMacro(<<"no style...");
   }
}

the style is found but the callback doesn't work.  What is the correct
object in the rendering pipeline to add this particular callback to?  Is
there another way that
would avoid the callback altogether?


Dean





More information about the vtkusers mailing list