Transform an actor but keep it visible within the view

Hi folks,

I’m currently trying to translate an actor, but I was wondering how I can control the translation so as to avoid the actor outside the render view? In another way to describe my question, I would like to get the translation limits in order to keep the actor still visible within the view.

I have figured some ways, for example, convert the actor’s bounds in world coordinate to the view coordinate, then check whether they are outside. Or convert the view coordinate back to the world coordinate. However, those methods seemed a bit of complicated… Could anybody give any suggestion please? Thank you so much!

Hi,
I’m not a specialist so maybe there is another solution. But what I have in mind is to determine a kind of intersection between your translation vector and the boundary planes of the viewport (left, right, bottom, top).
It seems that the vtkAreaPicker can gives you the planes and it surely exists a function to determine the intersection. The idea should be to determine the intersection for the 6 nodes of the actor’s bound and the view planes in your direction of translation and keep the shortest distance as your translation value.
What do you think?

Wet have implemented automatic centering of a selected object in the renderer for keeping position-tracked objects (tumor, surgical tools, etc.) in the field of view in 3D Slicer’s SlicerIGT extension:

If the object approaches the boundary of the view then the camera is automatically smoothly shifted so that the object gets into the center: