# How to listen zoom event to to keep a fixed ratio of axises\_length/window\_width?

**URL:** https://discourse.vtk.org/t/how-to-listen-zoom-event-to-to-keep-a-fixed-ratio-of-axises-length-window-width/7486
**Category:** Support
**Created:** [December 23, 2021, 10:46am UTC](https://discourse.vtk.org/t/how-to-listen-zoom-event-to-to-keep-a-fixed-ratio-of-axises-length-window-width/7486 "2021-12-23T10:46:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![AlexLuya](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alexluya/32/4036_2.png) [@AlexLuya](https://discourse.vtk.org/u/AlexLuya)
#### Post date: [December 23, 2021, 10:46am UTC](https://discourse.vtk.org/t/how-to-listen-zoom-event-to-to-keep-a-fixed-ratio-of-axises-length-window-width/7486/1 "2021-12-23T10:46:03Z")

</div>

Hello,  
I have put an vtkAxesActor in the centor of window,if putting a big object or zoom out too much,this actor will become tiny.Any way to keep a fixed ratio of axis\_length/window\_width?I want to listen to zoom event,but can’t find out how to

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [December 26, 2021, 2:48pm UTC](https://discourse.vtk.org/t/how-to-listen-zoom-event-to-to-keep-a-fixed-ratio-of-axises-length-window-width/7486/2 "2021-12-26T14:48:35Z")

</div>

Hi, Alex,

I also had a problem similar to yours. In my case, I have a small sphere that serves as a pick marker that must appear with the same size with respect to the screen regardless of zoom or vertical exaggeration applied by the user. I had to subclass `vtkInteractorStyleTrackballCamera` which interprets the user’s gestures (including those to perform zoom): [gammaray/v3dmouseinteractor.h at master · PauloCarvalhoRJ/gammaray · GitHub](https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/v3dmouseinteractor.h) . Then I had to add a call to:

```cpp
void v3dMouseInteractor::rescalePickMarkerActor()
{
    double cameraFocalPoint[3], cameraPosition[3];
    double objectPosition[3];
    double newScale = 0;
    double totalSquared = 0;

    if( ! m_vtkMathObj )
        m_vtkMathObj = vtkSmartPointer<vtkMath>::New();

    // Keeping the pick marker actor
    // the same size relative to the viewport. This is done by
    // changing the scale of the object to be proportional to
    // the distance between the current camera and the object.
    if( m_pickMarkerActor ){
        // Get a pointer to the current camera according to the main renderer.
        vtkCamera *currentCamera = static_cast<vtkCamera *>( this->GetDefaultRenderer()->GetActiveCamera() );
        currentCamera->GetPosition( cameraPosition );
        currentCamera->GetFocalPoint( cameraFocalPoint );
        m_pickMarkerActor->GetPosition( objectPosition );

        totalSquared = std::sqrt(m_vtkMathObj->Distance2BetweenPoints( objectPosition, cameraPosition ));
        newScale = totalSquared / 20000; // The denominator value is an abitary number that gives the desired size of the objects on screen.
        Application::instance()->logInfo( "Distance to picked location: " + QString::number(totalSquared) );
        m_pickMarkerActor->SetScale( newScale,
                                     newScale,
                                     newScale / m_ParentView3DWidget->getVerticalExaggeration() );

        this->GetDefaultRenderer()->Render();
    }
}

```

in all events associated with zooming to rescale the pick marker actor accordingly.

I hope this helps,

Paulo
