Class LabelSet3D

java.lang.Object
edu.cnu.mdi.mdi3D.item3D.Item3D
edu.cnu.mdi.mdi3D.item3D.LabelSet3D

public class LabelSet3D extends Item3D
Draws screen-space text labels for a set of 3D points.

This item projects each 3D point into window coordinates using Panel3D.project(GL2, float, float, float, float[]) and then renders the corresponding label in pixel coordinates via JOGL's TextRenderer.

This keeps label size constant regardless of zoom and avoids any need for 3D text geometry. Label visibility policy (e.g., globe front-hemisphere) is optional and controlled by a pluggable LabelSet3D.LabelCull.

  • Constructor Details

    • LabelSet3D

      public LabelSet3D(Panel3D panel3D, float[] coords, String[] labels)
      Create a label set for 3D points.
      Parameters:
      panel3D - owner panel
      coords - point coords as [x1,y1,z1,...]
      labels - per-point labels (same count as points)
  • Method Details

    • setCull

      public void setCull(LabelSet3D.LabelCull cull)
      Install (or clear) an optional culling strategy.
      Parameters:
      cull - strategy, or null to disable extra culling
    • setPixelOffset

      public void setPixelOffset(int dx, int dy)
      Set pixel offsets applied to each label after projecting.
      Parameters:
      dx - pixels right
      dy - pixels up
    • setClipToViewport

      public void setClipToViewport(boolean clip)
      If enabled, labels must project into the viewport and have depth in [0,1].
      Parameters:
      clip - true to clip labels to viewport
    • setCoords

      public void setCoords(float[] coords)
      Update coordinates (e.g., if points move).
      Parameters:
      coords - [x1,y1,z1,...]
    • setLabels

      public void setLabels(String[] labels)
      Update labels.
      Parameters:
      labels - per-point labels
    • dispose

      protected void dispose(com.jogamp.opengl.GLAutoDrawable drawable)
      Releases the lazily-created TextRenderer and its GPU texture atlas.
      Overrides:
      dispose in class Item3D
      Parameters:
      drawable - the OpenGL drawable being disposed
    • draw

      public void draw(com.jogamp.opengl.GLAutoDrawable drawable)
      Description copied from class: Item3D
      The custom drawing method
      Specified by:
      draw in class Item3D
      Parameters:
      drawable - the OpenGL drawable
    • frontHemisphereCull

      public static LabelSet3D.LabelCull frontHemisphereCull(float cx, float cy, float cz)
      Returns a culling policy that keeps labels on the visible hemisphere of a sphere.

      This is a geometric hemisphere test for a sphere whose center is given in world coordinates. It does not require the sphere to be centered at (0,0,0).

      Implementation details:

      • Transforms the sphere center C and the point P into eye space using the provided modelview.
      • Computes N = P - C (outward normal direction).
      • Computes V = -C (vector from center to camera at origin in eye space).
      • Accepts if N ยท V > 0.
      Parameters:
      cx - sphere center world x
      cy - sphere center world y
      cz - sphere center world z
      Returns:
      a culling strategy for the front hemisphere of that sphere