Repository navigation
cvcGL + ariadne: clip planes on scene nodes, in the node's own coordinates (stacked on #561) - #564
Merged
Merged
Conversation
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).
…setClipPlanes) cvcGL could clip only a node's children, and only to that node's own box (setClipChildren). A scene that wants to cut a mesh or a volume with a plane, or carve a region out of a subtree, had no way to say so. Now: - GraphicsNode::setClipPlanes(planes): half-spaces in the node's LOCAL frame (the frame its geometry or volume is defined in, before its transform), each keeping the side its normal points into (n . (x - origin) >= 0, VTK's and cvc::volren::cut_plane's convention). They clip the node AND everything below it. boxClipPlanes(box) gives the six of a box. Mirrored in a "clip_planes" state key (px,py,pz,nx,ny,nz per plane, both ways). - A node is clipped by its own planes and every ancestor's (their setClipPlanes, and the box of a setClipChildren ancestor), nearest first, capped by the new virtual maxClipPlanes(): 6 for VTK's poly-data mapper, 8 for its GPU volume mapper and for VolRenNode, 0 for the low-memory mapper (it has no clip code) and for nodes that draw nothing. Over the cap, the farthest planes are dropped and that is logged once. - The world-space vtkPlane objects are SHARED down the tree, so moving a plane (a slider dragging it, or its owner moving -- every transform path, the pose path included, goes through updateTransform) updates every renderer in place: no re-hand, no shader rebuild. Only a change in the SET of planes (count, setClipChildren, a child added or removed) re-hands the nodes below, through one propagateClip(). getAppliedClipPlanes() / clipPlaneCount() report it. - setClipChildren's box now reaches every level below, not just direct children, which also makes #561's LodGraphicsNode forwarding unnecessary: a LOD's rungs are its children and are clipped as such. Its accessor is renamed getClipBoxPlanes(); applyClipPlanesToChildren() and applyClipPlanesTo() go. - VolRenNode turns its planes into the raycaster's cut planes (world space, on top of its own) and re-raycasts when they move. It never hands them to its billboard quad, which would cut the picture, not the volume. VolumeNode passes them to its VTK volume mapper; VolSliceNode's slice polygons and every GeometryNode take them through the poly-data mapper. - pycvc_gl: set_clip_planes(flat list) / get_clip_planes() / set_clip_box(...) / applied_clip_plane_count(), plus maxClipPlanes() and clipPlaneCount().
cvcgl_clip_planes: - wiring, without GL: own planes first and then the parent's, through three levels, as the same plane objects; the cap (8 planes on a poly-data mapper -> its own 6; 9 on a volume -> 8); the parent rotated and moved: its plane moves in place (the same collection, nothing re-handed); a plane added: everything below re-handed; removed / added back / a LOD child's rung; setClipChildren reaching a grandchild; the "clip_planes" state key both ways, a malformed write ignored; a VolRenNode's quad mapper never clipped, a VolumeNode's mapper clipped. - local frame: for 30+ points given in the declaring node's coordinates, the local side and the world plane's side agree under rotation, non-uniform scale and translation, nested, after setPoseMatrix and after the parent re-scales; an inherited plane stays in its owner's frame. - the low-memory mapper (forced): clipped by 1 plane, hands its mapper none. - rendered, x >= 0: a geometry quad, a VolumeNode (VTK GPU raycast), a VolSliceNode and a VolRenNode each draw nothing left of the cut and are drawn right of it, after drawing both sides unclipped; on the quad, the plane moved in place, the node moved, and the node rotated 90 deg and squashed -- the cut follows each. Passes on NVIDIA and llvmpipe. cvcgl_clip_children follows the model: a child's mapper holds its own collection of the parent's six box planes (the same objects), and the accessor is getClipBoxPlanes(). pycvc_gl_clip: set_clip_planes / get_clip_planes / set_clip_box / applied_clip_plane_count, a parent's box reaching a child behind its own plane (7 planes, 6 applied), and a node's own plane cutting it about in half.
…n coordinates
A scene node may now declare clip planes with its description:
- node: region
type: group # a clip REGION for everything below it
clip:
box: [-1, -1, -1, 1, 1, 1] # keep the inside (or { min: [..], max: [..] })
planes:
- { origin: [0, 0, 0.5], normal: [0, 0, -1] }
- { normal: [1, 0, 0], offset: sim.cut_x } # a live cut, bound like visible:
children: true # also clip everything below to this node's own bounds
- Coordinates are the declaring node's OWN frame: where its geometry or volume
is defined, before its `transform:`. The clip moves, turns and scales with the
node, and a plane inherited from an ancestor stays in that ancestor's frame
(cvc::gl::GraphicsNode::setClipPlanes).
- A plane keeps the side its normal points into: it passes through
origin + offset·n̂ and keeps n̂·(x − origin) ≥ offset. `box:` adds its six
inward faces first. `clip:` clips the node and its whole subtree, on top of
every ancestor's; `children: true` maps to setClipChildren.
- `offset:` is a number, a state path, or { bind, default }. It resolves with
the widget-bind rule, is read without seeding (a follower, like `visible:`),
and is recorded as a cvc::ariadne::SceneClipBinding (state paths only). It is
re-read each frame by tick_scene, before the volren/volslice tickers, through
sync_scene_clip, which writes the node's `clip_planes` key only when the
planes changed; the node moves them in place. So every host already
servicing tick_scene gets live cuts with no change.
- Geometry, volume, volren and volslice nodes are all clipped (volren through
its cut planes). The realizer warns, never throws: a zero normal or an
inverted box (dropped), more planes than a renderer honours (the nearest
apply), and a node under VTK's low-memory mapper (the WebGL/GLES default), which
has no clip-plane support and draws unclipped.
Roadmap §9.10 specifies it (coordinates, keep side, live cuts, accumulation,
per-renderer caps, the low-memory caveat, coexistence with `shader:`). §9.2's
example, the §9.3 group row and §11's node keys (clip_planes, clip_children) are
updated. examples/clip_planes.ari is a runnable demo for ariadne_hello: a
cut-away bunny in a group region with a slider-bound section and a fixed cap,
and a second bunny cut by a box in its own coordinates. It is desktop-only, so
it is not in the wasm gallery.
- ariadne_loader_test: box in list and {min,max} form; planes with a literal,
bare-path and {bind, default} offset; children; `clip` parsed as a known key,
not swept into a custom node's props; a node without one has clip.present
false; malformed values (a short box, a non-number component, a scalar plane
entry) default instead of failing the load.
- ariadne_bind_test: sync_scene_clip slides a bound plane along its normal;
an unset source uses the default and is not seeded; a non-number counts as
unset; an unchanged frame writes nothing; clip_planes_csv round-trips doubles.
- cvcgl_ariadne_realize: a group moved to x = 10 with a plane in its frame,
and inside it a quad at local x = 0.5 with its own (non-unit) bound plane.
The quad is clipped by both, nearest first, with world origins 10 + 0.5 +
0.25 and 10. Writing the bound key and calling tick_scene slides the cut to
11.5 in place. children: true clips the child, not the host. A zero normal
and an inverted box are warned about and dropped; 7 planes on a mesh warn
that the nearest 6 apply; the low-memory mapper warns that the node draws
unclipped. On screen, nothing of the quad shows left of its cut or below the
region's plane.
…p-planes # Conflicts: # src/cvcGL/ariadne/scene_realize.cpp
…sh-merge; tree unchanged)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scene nodes in a
.arican now declare clip planes as part of the node, and cvcGL gains the per-node clip planes that need.Semantics (roadmap §9.10)
transform:. The clip moves, turns and scales with the node, under any rotation, non-uniform scale, nesting and the per-frame pose path. A plane inherited from an ancestor stays in that ancestor's frame.cvc::volren::cut_plane.box:adds its six inward faces.groupwithclip:is a clip region for its subtree.children: trueclips everything below the node to the node's own bounds.offset:can be live. It takes a number, a state path, or{ bind, default }, using the same resolve rule as widget binds. It is read without seeding the key, and re-read each frame bytick_scene. Every existing host gets live cuts with no change.Per renderer
cvc::volrencut planes (the volume, never its billboard quad)Over the cap, the nearest planes apply and the realizer warns. VTK 9.5's low-memory mapper honours no clip planes at all, and it is the WebGL/GLES default. A clipped node there draws unclipped, and the realizer warns about that as well.
cvcGL:
GraphicsNode::setClipPlanessetClipPlanes(local planes)andboxClipPlanes(box);maxClipPlanes(),clipPlaneCount()andgetAppliedClipPlanes()report what applies. A newclip_planesstate key holdspx,py,pz,nx,ny,nzper plane.vtkPlaneobjects are shared down the tree. Moving a plane (a dragged slider, or its owner moving) updates every renderer in place, with no re-hand and no shader rebuild. Only a change in the set of planes re-hands the nodes below.setClipChildrennow reaches every level below, not just direct children. That makes cvcGL: setClipChildren follows children coming and going, and the parent's box (stacked on #559) #561's LOD forwarding unnecessary, so it's removed. Its accessor is renamedgetClipBoxPlanes().set_clip_planes,get_clip_planes,set_clip_box,applied_clip_plane_count.Tests
cvcgl_clip_planes(new, 40 checks):setPoseMatrix;cvcgl_clip_children(cvcGL: setClipChildren clipped everything (outward planes) and could not be re-enabled #559/cvcGL: setClipChildren follows children coming and going, and the parent's box (stacked on #559) #561): adapted to the new model, 212/212.cvcgl_ariadne_realize: a nested group and quad, checking world planes from both frames, a bound offset slid throughtick_scene,children:, each warning, and an on-screen cut.ariadne_loader_test: every form of theclip:block, and malformed values.ariadne_bind_test:sync_scene_clip.pycvc_gl_clip: the new Python surface.Verification
cvcgl_*suite: 57/57 on NVIDIA and on llvmpipe, withCVC_REQUIRE_RENDER=1.ariadne_loader_test174/174,ariadne_runtime_test119/119,ariadne_bind_test19/19.ci.ymldoesn't build pycvc, so these ran locally only).examples/clip_planes.arirenders headlessly throughariadne_hello. With the section slider seeded at −70, −5 and 35, the cut moves as expected, and the box clip is visible.git clang-format --diffis clean.