# Transform an actor but keep it visible within the view

**URL:** <https://discourse.vtk.org/t/transform-an-actor-but-keep-it-visible-within-the-view/7243>\
**Category:** Development\
**Created:** [November 22, 2021, 12:50pm UTC](https://discourse.vtk.org/t/transform-an-actor-but-keep-it-visible-within-the-view/7243 "2021-11-22T12:50:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lwh0328](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/9fc29f/32.png) [@lwh0328](https://discourse.vtk.org/u/lwh0328)\
**Post date:** [November 22, 2021, 12:50pm UTC](https://discourse.vtk.org/t/transform-an-actor-but-keep-it-visible-within-the-view/7243/1 "2021-11-22T12:50:34Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Flagada](https://discourse.vtk.org/user_avatar/discourse.vtk.org/flagada/32/273_2.png) [@Flagada](https://discourse.vtk.org/u/Flagada)\
**Post date:** [November 23, 2021, 10:37am UTC](https://discourse.vtk.org/t/transform-an-actor-but-keep-it-visible-within-the-view/7243/2 "2021-11-23T10:37:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [November 29, 2021, 6:43pm UTC](https://discourse.vtk.org/t/transform-an-actor-but-keep-it-visible-within-the-view/7243/3 "2021-11-29T18:43:31Z")

</div>

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:

> <https://github.com/SlicerIGT/SlicerIGT/blob/5e996c52a5ea6802b804cc3add2dd8f026f257ac/Viewpoint/Viewpoint.py#L1191>

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

[/uploads/default/original/2X/e/e39a56cd12a66c345c2147e928e30d2702655abc.mp4](https://discourse.vtk.org/uploads/default/original/2X/e/e39a56cd12a66c345c2147e928e30d2702655abc.mp4)
