Skip to content

#14441 Keep annotation labels inside the view frustum - #14442

Draft
magnesj wants to merge 1 commit into
OPM:devfrom
magnesj:fix-14441-annotation-label-frustum
Draft

#14441 Keep annotation labels inside the view frustum#14442
magnesj wants to merge 1 commit into
OPM:devfrom
magnesj:fix-14441-annotation-label-frustum

Conversation

@magnesj

@magnesj magnesj commented Aug 2, 2026

Copy link
Copy Markdown
Member

Fixes #14441

The label for a surface intersection curve or band is moved from the anchor point towards the camera, to be drawn in front of other geometry. The offset was computed by computeScalingFactorFromZoom() as 10 times the near plane diagonal, a zoom dependent length that is not related to the distance between the camera and the anchor point. In a 3D view the offset is usually several times larger than this distance, and the label ends up behind the camera.

cvf::DrawableText::renderText() maps the projected depth to 1 - 2 * z and clips anything outside [-1, 1], so a label outside the view frustum is silently discarded. As the relation between the offset and the camera distance differs per curve and changes when the camera is moved, labels appear and disappear.

The flat 2D intersection view calls addAnnotationLabels() with computeScalingFactor = false, giving a fixed offset of 1.0. This is why the labels are displayed as expected in that view.

Changes

  • Limit the offset to the smaller of half the distance to the anchor point and the distance to the near plane. The limit is derived from the anchor point and not from the near plane, as the label parts are part of the scene and are used by caf::Viewer::calculateNearFarPlanes(). A limit derived from the near plane would create a feedback loop between the label positions and the clipping planes.
  • Reject anchor point candidates behind the camera. cvf::Camera::project() divides by the homogeneous w-coordinate, which is negative behind the camera, mirroring these coordinates into the viewport. Such a coordinate could be selected as the coordinate closest to the label position at 90% of the viewport width, placing the label behind the camera. The same check is added to the COUNT_HINT and ALL strategies, and to the multiple label path used for measured depth labels along a well path.
  • Prefer anchor points inside the viewport, as a label attached to a coordinate outside the viewport can be positioned outside the visible area.
  • Move the file local helpers into an anonymous namespace. Declared as auto at namespace scope, they had external linkage.

Verification

RivAnnotationTools-Test.cpp adds two tests. Both fail without the fix:

  • LabelIsInsideViewFrustum: the label projects to window z = 3.31, the frustum is 0 to 1
  • AnchorPointsBehindCameraAreIgnored: the selected anchor point is 306 units behind the camera

The complete unit test suite passes, 961 tests.

The change has not yet been verified visually in a 3D view.

The label is moved from the anchor point towards the camera to be drawn in front of other geometry. The offset was derived from the zoom level, and was not related to the distance between the camera and the anchor point. In a 3D view the offset is usually larger than this distance, moving the label behind the camera. Labels outside the view frustum are silently discarded by the text renderer.

Limit the offset to the smaller of half the distance to the anchor point and the distance to the near plane. The limit is derived from the anchor point and not from the near plane, as the label parts are part of the scene and are used to compute the clipping planes.

Reject anchor point candidates behind the camera. Coordinates behind the camera are mirrored into the viewport by the perspective divide in cvf::Camera::project(), and could be selected as the coordinate closest to the label position.
@magnesj magnesj self-assigned this Aug 3, 2026
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.

Surface intersection curve labels are not displayed in 3D view

1 participant