Skip to content

cvcGL: setClipChildren follows children coming and going, and the parent's box (stacked on #559) - #561

Merged
transfix merged 6 commits into
masterfrom
fix/cvcgl-clip-children-lifecycle
Oct 7, 2026
Merged

transfix merged 6 commits into
masterfrom
fix/cvcgl-clip-children-lifecycle

Conversation

@transfix

@transfix transfix commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Stacked on #559. This branch contains #559's three commits. Review only the last two: 324de4e55 (library) and 0aeee9923 (tests). It targets master so CI runs; I'll rebase it onto master once #559 squash-merges.

#559 made setClipChildren clip correctly, but only for the children present when clipping was switched on, and only while the parent's box stayed the same. This PR closes the gaps #559 listed, and two more.

What changes

  • A child added after setClipChildren(true) is clipped. addGraphicsChild hands it the parent's planes.

  • A removed child is no longer clipped. removeGraphicsChild detaches the planes, so a child reparented elsewhere draws whole.

  • The planes follow the parent's box. New protected GraphicsNode::ownBoundsChanged() re-fits both the bbox outline and the clip planes. Every node whose box can change now reports through it:

    Node Where its box changes
    GeometryNode setGeometry
    NullGraphicNode setBounds (both overloads; also reached from its bounds state key), syncBoundsToChildren
    VolumeNode setVolume
    VolSliceNode setVolume
    VolRenNode addVolume, clearVolumes, setVolumeConfig, and its state-settings apply (a volumes.<i>.matrix written to the tree)
    LodGraphicsNode when rung 0 is added, or the rungs are cleared
    StreamingGeometryNode reserved bounds (apply path) and derived bounds (setDerivedBoundsNow, used by DrapedLinkNode)

    VolSlice, VolRen, LOD and the derived-bounds path did not refit their bbox outline either; they do now. Light, Axis and Grid nodes have constant boxes.

    ownBoundsChanged() runs on the owner thread, because VolSlice and VolRen setters can come from loader threads. It returns at once when the outline is hidden and the node clips nothing. That is the common case, and a draped link reports a new box from VTK's bounds pass. The VolRen apply callback calls it after releasing m_configMutex, since getBoundingBox() takes that lock.

  • A LodGraphicsNode child is clipped. It draws nothing itself, and its rungs are its own children, so before this they were never clipped. It now passes the planes it is given to its rungs, including rungs added later. This goes through a protected static GraphicsNode::applyClipPlanesTo, because applyClipPlanes is protected.

Tests

cvcgl_clip_children goes from 141 to 212 checks.

  • Without GL:
    • add-after-enable
    • remove and re-add, with the parent keeping its six planes
    • the planes tracking every box change in the table above
    • an LOD child's rungs, including a rung added later, and off/on with the parent
  • Rendered (classic mapper):
    • a late child and an LOD child, both cut at the face
    • a child moved to the root, drawn whole
    • the box grown with setBounds, every cut moving out with it

On #559's code it fails 28 of 212. With this PR it passes 212/212 on NVIDIA and on llvmpipe.

pycvc_gl_clip: a child added with sg.add_child_geometry while clipping is on is cut at the −x face (0.514 of its area drawn).

Verification

Still not clipped

Children drawn by VTK 9.5's low-memory mapper (the WebGL/GLES default). It has no clipping-plane support at all; the header documents this.

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.
…ent's box

The planes a clipping parent hands its children were set once, on the children
present at setClipChildren(true), and re-fitted only when the parent moved:

- A child added afterwards was never clipped: addGraphicsChild did not hand it
  the planes. It does now.
- A child removed (reparented, say) kept clipping to its old parent's box.
  removeGraphicsChild now detaches them.
- A parent whose own box changed left the planes on the old box: only
  updateTransform and setClipChildren re-fitted them. New protected
  GraphicsNode::ownBoundsChanged() re-fits the bbox outline and the planes, and
  every node whose box can change reports through it: GeometryNode::setGeometry,
  NullGraphicNode::setBounds (and its "bounds" state key) and
  syncBoundsToChildren, VolumeNode / VolSliceNode::setVolume, VolRenNode
  addVolume / clearVolumes / setVolumeConfig and its state-settings apply (a
  model_transform written to the tree), LodGraphicsNode when rung 0 comes or
  goes, and a StreamingGeometryNode's reserved or derived bounds. VolSlice,
  VolRen, LOD and the derived-bounds path did not refit their bbox outline
  either; they do now. ownBoundsChanged() runs on the owner thread (VolSlice and
  VolRen setters come from loader threads), and returns at once when the
  outline is hidden and the node clips nothing -- a draped link reports a new
  box from VTK's bounds pass.
- A LodGraphicsNode child was never clipped: it draws nothing itself, and its
  rungs are its children, not the clipping parent's. It now passes the planes
  it is given to its rungs, including rungs added later (protected static
  GraphicsNode::applyClipPlanesTo, as applyClipPlanes is protected).
cvcgl_clip_children, without GL: a child added after setClipChildren(true)
holds the parent's planes; one clipped from the start is detached when removed
(the parent keeping its six) and clipped again when added back; the planes
follow NullGraphicNode::setBounds, its "bounds" state key and a group syncing
to its children, GeometryNode::setGeometry, VolumeNode and VolSliceNode
setVolume, VolRenNode addVolume / setVolumeConfig / a matrix written to its
state tree / clearVolumes, and LodGraphicsNode::setBase; a LodGraphicsNode
child hands the planes to its rung, to a rung added later, and takes them off
and back on with the parent. Rendered on the classic mapper: a child and an
LOD child added while clipping is on are cut at the face, a child moved to the
root is drawn whole, and growing the box with setBounds moves every cut out
with it. checkPlanes takes the expected box. On #559's code it fails 28 of
212 checks; passes on NVIDIA and llvmpipe.

pycvc_gl_clip: a child added with sg.add_child_geometry while clipping is on
is cut at the -x face (about half drawn).
@transfix
transfix merged commit b52efcb 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
…nates (stacked on #561) (#564)

* cvcGL: per-node clip planes in the node's local frame (GraphicsNode::setClipPlanes)
* test(cvcGL): cvcgl_clip_planes; per-node planes in pycvc_gl_clip
* ariadne(scene): `clip:` on scene nodes — half-spaces in the node's own coordinates
* test(ariadne): the `clip:` block — loader, bound-offset sync, realize
@transfix
transfix deleted the fix/cvcgl-clip-children-lifecycle 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