# WorldPointPicker: get the right value if you zoom in

**URL:** https://discourse.vtk.org/t/worldpointpicker-get-the-right-value-if-you-zoom-in/4096
**Category:** Support
**Created:** [August 29, 2020, 9:00am UTC](https://discourse.vtk.org/t/worldpointpicker-get-the-right-value-if-you-zoom-in/4096 "2020-08-29T09:00:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tommi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@tommi](https://discourse.vtk.org/u/tommi)
#### Post date: [August 29, 2020, 9:00am UTC](https://discourse.vtk.org/t/worldpointpicker-get-the-right-value-if-you-zoom-in/4096/1 "2020-08-29T09:00:22Z")

</div>

I use [this](https://vtk.org/Wiki/VTK/Examples/Cxx/Interaction/WorldPointPicker) example for a WorldPointPicker. It works fine, but if i zoom in, it doesn’t give the correct coordinates. How can i correct this?

---

<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: [September 1, 2020, 2:48pm UTC](https://discourse.vtk.org/t/worldpointpicker-get-the-right-value-if-you-zoom-in/4096/2 "2020-09-01T14:48:21Z")

</div>

Hi, Thomas,

I perform picking with this (simplified from [https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/v3dmouseinteractor.cpp](https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/v3dmouseinteractor.cpp)):

```cpp
void v3dMouseInteractor::OnLeftButtonUp()
{
    // Don't pick during dragging.
    if( ! m_isDragging ){

        // Get pick position in 2D screen coordinates.
        int* clickPos = this->GetInteractor()->GetEventPosition();

        // Get the 3D object under the 2D screen coordinates (ray casting).
        vtkSmartPointer<vtkPropPicker> picker = vtkSmartPointer<vtkPropPicker>::New();
        picker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());

        // Get the cell of a 3D object under the 2D screen coordinates (ray casting).
        vtkSmartPointer<vtkCellPicker> cellPicker = vtkSmartPointer<vtkCellPicker>::New();
        cellPicker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());

        //if something was picked
        if( picker->GetActor() && cellPicker->GetCellId() != -1 ) {

            // Get the picked location in world coordinates.
            double* pos = picker->GetPickPosition();

            // Output the picked location.
            Application::instance()->logInfo( "Picked location (world coordinates): X="
                      + QString::number(pos[0]) + " Y=" + QString::number(pos[1])
                      + " Z=" + QString::number(pos[2]) );

        }
    }

    m_isLBdown = false;
    m_isDragging = false;

    // Forward the event to the superclass.
    vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
}

```

I hope this helps.

regards,

Paulo

---

<div class="post-metadata">

### Author: ![tommi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@tommi](https://discourse.vtk.org/u/tommi)
#### Post date: [September 2, 2020, 11:21am UTC](https://discourse.vtk.org/t/worldpointpicker-get-the-right-value-if-you-zoom-in/4096/3 "2020-09-02T11:21:14Z")

</div>

Hi Paulo,  
thank you for your help, but your code doesn’t work, because “this-\>GetDefaultRenderer()” crashes. But now, i found the solution. In the example, I substitutet "this-\>Interactor-\>GetRenderWindow()-\>GetRenderers()-\>GetFirstRenderer() " and passed the Renderer as a parameter. Now it works.
