Repository: pyvista/pyvista

Issue #5179: `renderer.bounds` includes invisible actors
Created: 2023-11-06T18:21:16Z
Describe the bug, what's wrong, and what you expected.
The renderer bounds are currently calculated for all actors regardless of their visibility. This means that actors with VisibilityOff() or UseBoundsOff() will have their bounds included in the renderer's bounds when they should not be. The expected behaviour is that the bounds should match the output from vtkRenderer.ComputeVisiblePropBounds(), which is what vtkRenderer.ResetCamera() calls internally.
I think PyVista's docs, e.g. for Plotter.bounds and Camera.tight could be more explicit as well and use the term "visible actors" where possible to make it clear that actor visibility is taken into consideration.
If there is a need for getting all bounds regardless of visibility, maybe this should be parameterized, e.g. include_invisible=True?
Steps to reproduce the bug.
import pyvista as pv
a=pv.Actor(mapper=pv.DataSetMapper(pv.Sphere()))
a.VisibilityOff()
p=pv.Plotter(off_screen=True)
p.add_actor(a)
p.show()

# Actual bounds:
print(p.renderer.bounds)
# (-0.49926671385765076, 0.49926671385765076, -0.4965316653251648, 0.4965316653251648, -0.5, 0.5)

# Expected bounds:
print(p.renderer.ComputeVisiblePropBounds())
# (1.0, -1.0, 1.0, -1.0, 1.0, -1.0)
System Information
.
Screenshots
No response

Duplicate issue #7108: issue with polydata using 'render_points_as_spheres', along with frozen camera clipping range
Created: 2025-01-21T15:35:06Z
Describe the bug, what's wrong, and what you expected.
I display a polydata mesh of points on a sphere, with the option 'render_points_as_spheres' set to True.
I also freeze the clipping range of the camera (setting the clipping range to (1e-9, 1000) to see everything (otherwise, some shapes are clipped) + calling pl.iren.style.AutoAdjustCameraClippingRangeOff() to keep that clipping range.
result: the points that should normaly be not visible by camera (because on the opposite side of the sphere), are visible.
when not forcing camera clipping, everything is OK.
I would have expected that in any cases, the sphere masks points that are behind
Steps to reproduce the bug.
# -*- coding: utf-8 -*-

import pyvista as pv
import numpy as np

pl = pv.Plotter()
np.random.seed(0)

# create and display sphere
red_sphere = pv.Sphere(radius = 1.)
pl.add_mesh(red_sphere, color='red', lighting=False)

# create and display random points on its surface
points = np.random.rand(40,3)-0.5
points = points / np.linalg.norm(points, axis=-1, keepdims=True)
pts_inertial = pv.PolyData(points)

pts_actor = pl.add_mesh(
    pts_inertial,
    render_points_as_spheres=True,  # Render points as spheres
    point_size=7
)

# now force camera position: set flag below to True/False to see the difference !
force_camera_clipping = True

if force_camera_clipping:
    
    pl.camera.position = (3., 3., 3.)
    pl.camera.focal_point = (0., 0., 0.)
    pl.iren.style.AutoAdjustCameraClippingRangeOff()
    pl.camera.clipping_range = (1e-9, 1000.)
    
pl.show()
System Information
--------------------------------------------------------------------------------
  Date: Tue Jan 21 16:34:54 2025 Paris, Madrid

                OS : Windows (10 10.0.19045 SP0 Multiprocessor Free)
            CPU(s) : 8
           Machine : AMD64
      Architecture : 64bit
               RAM : 15.7 GiB
       Environment : IPython
        GPU Vendor : Intel
      GPU Renderer : Intel(R) Iris(R) Xe Graphics
       GPU Version : 4.5.0 - Build 31.0.101.4887
  MathText Support : False

  Python 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:27:10) [MSC
  v.1938 64 bit (AMD64)]

           pyvista : 0.44.0
               vtk : 9.3.0
             numpy : 1.26.4
        matplotlib : 3.9.1
            scooby : 0.10.0
             pooch : 1.8.2
            pillow : 10.3.0
           imageio : 2.34.2
         pyvistaqt : 0.11.1
             PyQt5 : 5.15.9
           IPython : 8.26.0
             scipy : 1.14.0
              tqdm : 4.66.4
            meshio : 5.3.5
             trame : 3.6.3
      trame_client : 3.2.1
      trame_server : 3.0.3
         trame_vtk : 2.8.9
     trame_vuetify : 2.6.1
      nest_asyncio : 1.6.0
--------------------------------------------------------------------------------
Screenshots
No response

Closing comment (2025-02-07T14:46:12Z): Haven't looked into this but it might be related to #5179
We have a few issues related to how bounds are computed. Maybe this extends to clipped actors