Skip to content

cvcGL: setClipChildren clipped everything (outward planes) and could not be re-enabled - #559

Merged
transfix merged 3 commits into
masterfrom
fix/cvcgl-clip-children-inward-normals
Oct 7, 2026
Merged

transfix merged 3 commits into
masterfrom
fix/cvcgl-clip-children-inward-normals

Conversation

@transfix

@transfix transfix commented Oct 4, 2026

Copy link
Copy Markdown
Owner

GraphicsNode::setClipChildren(true) made every child completely invisible. Found while reviewing #512, and reproduced there with a plain triangle child and with a DrapedLinkNode. Nothing in the repo calls setClipChildren yet, and nothing tested it. pycvc_gl wraps it (setClipChildren / getClipChildren; only getClipPlanes is %ignored).

1. The planes faced out of the box

updateClipPlanes built the six face planes with outward normals ({1,0,0} at max-x, and so on), although its comments said they point inward. VTK 9.5 keeps the side a clipping plane's normal points into:

  • vtkAbstractMapper3D::GetClippingPlaneInDataCoords builds the plane equation (n, -n·origin).
  • vtkOpenGLPolyDataMapper::ReplaceShaderClip computes dot(clipPlanes[i], vertexMC) and discards the fragment when it is < 0.0. So a point is kept where n·(x − origin) ≥ 0.
  • The GPU volume ray caster clips the same side: vtkVolumeShaderComposer treats a sample as clipped where dot(n, origin − p) > 0.

Six outward planes keep only points outside all six faces at once, which is nothing. Fix: negate the six normals and correct the comments.

2. Turning clipping off emptied the parent's planes

This turned up while writing the test. A clipping parent gives every child's mapper the same vtkPlaneCollection: its own m_clipPlanes. setClipChildren(false) then called RemoveAllClippingPlanes() on each child's mapper, and VTK implements that as ClippingPlanes->RemoveAllItems(). That emptied the parent's collection. After that, updateClipPlanes moved planes that were no longer in it, and the next setClipChildren(true) handed every child an empty collection, which applyClipPlanes treats as "remove". So after one off/on cycle, that parent could never clip again.

Fix: GeometryNode, GridNode and VolumeNode::applyClipPlanes now detach with SetClippingPlanes(nullptr) instead of emptying.

Tests

cvcgl_clip_children (src/cvcGL/test, offscreen, llvmpipe-friendly, shares streaming_test_util.h). A NullGraphicNode box centred at x = y = 500 (away from the origin), with five flat-coloured children: fully inside, straddling an x/y corner, a tilted quad cut by the ±z faces, beside the box, and above it.

  • Planes, no GL needed. The box centre evaluates to +half-extent against every plane. A point just past a face is negative against that face's plane only. Both hold axis-aligned and with the parent rotated 30° about z and 20° about x and moved. Every child's mapper holds the planes while clipping is on and none after it goes off. The parent keeps its six planes through an off/on cycle.
  • Rendered, classic mapper. Pixel samples 4 units either side of each face, plus the lit area per hue. The scene is checked unclipped first (so the checks can fail), then clipped, off again, on again, and with the parent rotated and moved while clipping is on. Clipped areas are exactly r 400 / g 900 / b 800, against 1300 / 4000 / 1600 unclipped.
  • Rendered, low-memory mapper (forced). VTK 9.5's vtkOpenGLLowMemoryPolyDataMapper has no clipping-plane code at all, so only "not wrongly clipped" is checked; a note prints what it drew. The header now says so.

pycvc_gl_clip (bindings/pycvc). The wrapped getter and setter. With offscreen GL, a box-outline parent with children inside, straddling +x and above +z, measured by lit area per hue through an off/on cycle: inside 1.000, straddling 0.514, above 0.000.

Verification

  • cvcgl_clip_children: 141/141 pass on NVIDIA (GTX 1650, 595.91) and on Mesa llvmpipe (25.2.8). With master's cvcGL sources it fails 30 of 139: everything is invisible under clipping, and the off/on cycle loses the planes.
  • pycvc_gl_clip passes. Against master's libcvcGL it fails 3.
  • The whole cvcgl_* suite passes 56/56 on NVIDIA and 56/56 on llvmpipe with CVC_REQUIRE_RENDER=1, including cvcgl_streaming_overlays.
  • git clang-format --diff origin/master is clean.
  • ci.yml doesn't build pycvc, so in CI only cvcgl_clip_children runs. pycvc_gl_clip was run locally against the deps-vr3 prefix.

Notes

  • cvcGL: streaming overlay geometry with partial uploads (StreamingGeometryNode, RibbonNode, terrain-hugging links) #512's DrapedLinkNode clip test (testLinkClip in cvcgl_streaming_overlays.cpp) sets correctly oriented planes directly on the mapper (inwardBox()) because of this bug. Once this lands it could switch to a clipping parent with setClipChildren(true).
  • Gaps left alone (found by reading the code; this PR doesn't change them):
    • A child added after setClipChildren(true) is not clipped. addGraphicsChild never applies the planes.
    • Changing the parent's box (NullGraphicNode::setBounds, GeometryNode::setGeometry) does not refresh the planes. Only updateTransform and setClipChildren call updateClipPlanes.
    • A child removed from a clipping parent keeps the planes.

GraphicsNode::updateClipPlanes built the six face planes with OUTWARD normals
({1,0,0} at max-x, ...), though its own comments said they point inward. VTK
keeps the half-space a clipping plane's normal points into: it builds the plane
equation (n, -n.origin) (vtkAbstractMapper3D::GetClippingPlaneInDataCoords) and
vtkOpenGLPolyDataMapper discards a fragment whose clip distance is negative, so
a point survives where n . (x - origin) >= 0. The GPU volume ray caster clips the
same side (vtkVolumeShaderComposer: clipped where n . (origin - p) > 0). Six
outward planes keep only points outside every face at once -- none -- so
setClipChildren(true) made every child completely invisible.

Negate the six normals and say why in the comment. Document on the declaration
what setClipChildren clips to, and that VTK 9.5's low-memory poly-data mapper
(the GLES3/WebGL2 default) has no clipping-plane support at all, so children
drawn by it are not clipped.
A clipping parent hands every child's mapper its own vtkPlaneCollection
(m_clipPlanes), shared. setClipChildren(false) then called
RemoveAllClippingPlanes() on each child's mapper, and VTK implements that as
ClippingPlanes->RemoveAllItems(): it emptied the parent's collection. From then
on updateClipPlanes moved planes that were no longer in it, the next
setClipChildren(true) handed every child an empty collection (which
applyClipPlanes treats as "remove"), and that parent could never clip again.

GeometryNode, GridNode and VolumeNode::applyClipPlanes now detach the
collection with SetClippingPlanes(nullptr) instead.
cvcgl_clip_children: a NullGraphicNode box (centred at x = y = 500, away from
the origin) with five flat-coloured children -- fully inside, straddling an
x/y corner, a tilted quad cut by the z faces, beside the box and above it.
- Without GL: the box centre is +half-extent against every plane and a point
  just past a face is negative against that face's plane only (axis-aligned,
  and with the parent rotated and moved); every child's mapper holds the
  planes while clipping is on and none after it goes off; the parent keeps its
  six planes through an off/on cycle.
- Rendered, classic mapper: pixel samples 4 units either side of each face plus
  the lit area per hue (inside drawn, outside clipped, straddling cut at the
  face) -- unclipped first so the checks can fail, after clipping goes off, on
  again, and with the parent rotated and moved while clipping is on.
- Rendered, low-memory mapper (forced): VTK's has no clipping planes, so only
  "not wrongly clipped" is checked; a note prints what it drew.
On master it fails 30 of 139 checks (everything invisible under clipping, and
the off/on cycle loses the planes). Passes on NVIDIA and llvmpipe.

pycvc_gl_clip: the wrapped setClipChildren/getClipChildren, and -- with
offscreen GL -- children inside / straddling +x / above +z of a box-outline
parent drawn whole / about half / not at all, through an off-and-on cycle,
measured by lit area per hue. On master it fails 3 checks.
@transfix
transfix merged commit 7837bd8 into master Oct 7, 2026
14 checks passed
transfix pushed a commit that referenced this pull request Oct 7, 2026
transfix added a commit that referenced this pull request Oct 7, 2026
…ent's box (stacked on #559) (#561)

* cvcGL: setClipChildren follows children coming and going, and the parent's box
* test(cvcGL): clip planes follow children and every kind of parent box
@transfix
transfix deleted the fix/cvcgl-clip-children-inward-normals branch October 29, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant