Center of rotation in VTK - ParaView style

Hi All,

I am currently using VTK 9 in Python, and in my application I am taking advantage of th wxPython wrapper of vtkRenderWindowInteractor using vtkInteractorStyleTrackballCamera as interactor style.

This is all nice and well, although I would like to be able to change the center of rotation for the camera, especially when the user is zooming in a lot close to an actor. For high level of zooms on an object that is not in the center of the window the rotation is almost unusable as the camera rotates around a point that is very far away from the actor I am interested in.

I can see that ParaView has this super cool feature of picking a center of rotation, resetting it and also showing it with some sort of axes (?).

I have tried to dig into the ParaView code but it’s a bit overwhelming to me… does anyone know if there is a way to set another center of rotation for the camera using VTK? Do I have to implement my own interactor style somehow to do something like that?

Thank you in advance for any suggestion.

Andrea.

Camera rotation is implemented in the interaction style, which delegates the computation to vtkPVTrackballRotate.cxx. The computation is very simple: translate to center of rotation, rotate, then translate back.

vtkInteractorStyleUnicam style in VTK can already rotate around a custom point and I think you can implement custom interaction styles in Python. So vtkInteractorStyleUnicam is not good enough then you can create your custom style, using the computation that you take from vtkPVTrackballRotate.

@lassoan Thank you so much, that is most helpful. I think I can mange to wade through that (maybe), although there is an unclear step in the code, and specifically this:

//-------------------------------------------------------------------------
void vtkPVTrackballRotate::OnButtonDown(int, int, vtkRenderer* ren, vtkRenderWindowInteractor*)
{
  this->ComputeDisplayCenter(ren);
}

Looking at ComputeDisplayCenter in vtkCameraManipulator.cxx, I can see that it does this:

//-------------------------------------------------------------------------
void vtkCameraManipulator::ComputeDisplayCenter(vtkRenderer* ren)
{
  double* pt;

  // save the center of rotation in screen coordinates
  ren->SetWorldPoint(this->Center[0], this->Center[1], this->Center[2], 1.0);
  ren->WorldToDisplay();
  pt = ren->GetDisplayPoint();
  this->DisplayCenter[0] = pt[0];
  this->DisplayCenter[1] = pt[1];
}

And the attribute “Center” is initialized as the vector (0, 0, 0) at the very beginning, but I can’t find anywhere if and when that attribute is changed and what it refers to. Is it the screen center? Is it the center of mass of the scene with all the bounding boxes for all actors considered? Or is it the center that the user can pick with the mouse in ParaView and, if not done, it stays by default at (0, 0, 0) (??) ?

The reason I ask is because later on, in vtkPVTrackballRotate::OnMouseMove, this very important “Center” attribute is used like this:

// translate to center
transform->Identity();
transform->Translate(this->Center[0] / scale, this->Center[1] / scale, this->Center[2] / scale);

And I am a bit unclear what it actually refers to and how to set/retrieve this famous “Center” attribute.

Thank you in advance for any suggestion.

Andrea.