# How to know if specific point in world coordinates is visible within current render?

**URL:** <https://discourse.vtk.org/t/how-to-know-if-specific-point-in-world-coordinates-is-visible-within-current-render/13766>\
**Category:** Development\
**Tags:** python\
**Created:** [April 22, 2024, 7:52am UTC](https://discourse.vtk.org/t/how-to-know-if-specific-point-in-world-coordinates-is-visible-within-current-render/13766 "2024-04-22T07:52:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinzileo](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/v/f6c823/32.png) [@vinzileo](https://discourse.vtk.org/u/vinzileo)\
**Post date:** [April 22, 2024, 7:52am UTC](https://discourse.vtk.org/t/how-to-know-if-specific-point-in-world-coordinates-is-visible-within-current-render/13766/1 "2024-04-22T07:52:17Z")

</div>

Hi all,

How to know if specific point in world coordinates is visible within current render?  
I know vtkSelectVisiblePoints could handle that using z-buffer, however I cannot find source code of that part, and any examples related.  
Any suggestions would be appreciated, thanks.

I tried following code to test if point on object’s surface is occluded(rotating camera 360 degrees and check if point is visible), but the returned value is always false.

```auto
    step = 10
    for i in range(36):
        renderer.GetActiveCamera().Azimuth(step)
        visPts = vtk.vtkSelectVisiblePoints()
        visPts.SetRenderer(renderer)
        visible = visPts.IsPointOccluded(pos, 0.0)
        print(f"visible {visible}")

```

---

<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:** [April 22, 2024, 10:20pm UTC](https://discourse.vtk.org/t/how-to-know-if-specific-point-in-world-coordinates-is-visible-within-current-render/13766/2 "2024-04-22T22:20:41Z")

</div>

Hello,

`vtkSelectVisiblePoints`’s `IsPointOccluded()` expects, as its second parameter, an array of `foat`s that is the Z-Buffer data. You passed a `0.0` scalar instead. Hence the unexpected result.

Following the rationale in [vtk render window GetZbufferData method - Stack Overflow](https://stackoverflow.com/questions/47854808/vtk-render-window-getzbufferdata-method), here’s a possible solution ⚠ Untested C++ → Python translation:

```python
    step = 10

    x1 = renderer.GetViewport()[0] * (renWin.GetSize()[0] - 1)
    y1 = renderer.GetViewport()[1] * (renWin.GetSize()[1] - 1)
    x2 = renderer.GetViewport()[2] * (renWin.GetSize()[0] - 1)
    y2 = renderer.GetViewport()[3] * (renWin.GetSize()[1] - 1)
    renZ = renWin.GetZbufferData(x1,y1,x2,y2)

    for i in range(36):
        renderer.GetActiveCamera().Azimuth(step)
        visPts = vtk.vtkSelectVisiblePoints()
        visPts.SetRenderer(renderer)
        visible = visPts.IsPointOccluded(pos, renZ)
        print(f"visible {visible}")

```

`renWin` is the `vtkRenderWindow` object of your program. Replace that with whatever name you gave to it. I hope this helps.

best,

PC

---

<div class="post-metadata">

**Author:** ![LucasGandel](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lucasgandel/32/1831_2.png) [@LucasGandel](https://discourse.vtk.org/u/LucasGandel)\
**Post date:** [April 23, 2024, 7:26am UTC](https://discourse.vtk.org/t/how-to-know-if-specific-point-in-world-coordinates-is-visible-within-current-render/13766/3 "2024-04-23T07:26:32Z")

</div>

While the detailed solution provided by @Paulo_Carvalho will work, accessing the Z buffer is an expensive operation. Maybe you can achieve better performances by creating an implicit function from the camera frustum. Something similar is done here: [https://examples.vtk.org/site/Cxx/Meshes/ClipFrustum/](https://examples.vtk.org/site/Cxx/Meshes/ClipFrustum/)
