Class Item3D

java.lang.Object
edu.cnu.mdi.mdi3D.item3D.Item3D
Direct Known Subclasses:
Axes3D, Cube, Cylinder, GlobeCountryLines3D, LabelSet3D, Line3D, PointSet3D, PolyLine3D, Quad3D, ScatterPlot3D, Sphere, Triangle3D

public abstract class Item3D extends Object
Base class for every drawable object hosted on a Panel3D.

Item3D is the 3D analogue of MDI's 2D AItem: a self-contained drawable that owns its own appearance properties and can be organized into a parent/child tree so a group of items (e.g. the axes of a coordinate frame, or the components of a composite shape) can be shown, hidden, or disposed as a unit.

Properties

Appearance is stored as a small Properties-backed key/value bag (LINE_WIDTH, FILLCOLOR, FILLALPHA, LINECOLOR, LINEALPHA, TEXT_COLOR, FONT), accessed through the typed get*/set* convenience methods. Any property that has not been explicitly set falls back to a class-wide default.

Drawing and disposal

Subclasses implement draw(GLAutoDrawable) for their own custom rendering, and only that GL-thread-bound method should touch the GL context. drawItem(GLAutoDrawable) and disposeItem(GLAutoDrawable) are called by Panel3D and are final: they invoke draw(GLAutoDrawable)/dispose(GLAutoDrawable) on this item and then recurse into every visible child, so a subtree draws or releases its GL resources with a single call from the panel.

Thread safety

isVisible()/setVisible(boolean) and the child list are safe to touch from threads other than the GL rendering thread: visibility is volatile, and addChild(Item3D)/removeChild(Item3D) synchronize on this, the same monitor used to snapshot the child list before iterating it during draw/dispose. Actual GL calls inside draw(GLAutoDrawable) still must only happen on the GL thread.

  • Field Details

  • Constructor Details

    • Item3D

      public Item3D(Panel3D panel3D)
      Create a 3D item for use on a Panel3D.
      Parameters:
      panel3D - the owner panel 3D object
  • Method Details

    • defaultProperties

      protected void defaultProperties()
      Set the default properties
    • put

      public void put(Object key, Object value)
      set a property
      Parameters:
      key - the key
      value - the value
    • drawItem

      public final void drawItem(com.jogamp.opengl.GLAutoDrawable drawable)
      Called by the panel3D. Do not overrwrite.
      Parameters:
      drawable - the OpenGL drawable
    • draw

      public abstract void draw(com.jogamp.opengl.GLAutoDrawable drawable)
      The custom drawing method
      Parameters:
      drawable - the OpenGL drawable
    • disposeItem

      public final void disposeItem(com.jogamp.opengl.GLAutoDrawable drawable)
      Called by the panel3D when its GL context is being torn down. Do not overwrite.

      Releases this item's own GL resources via dispose(GLAutoDrawable), then recurses into children so a subtree is fully released with one call.

      Parameters:
      drawable - the OpenGL drawable being disposed
    • dispose

      protected void dispose(com.jogamp.opengl.GLAutoDrawable drawable)
      Override to release any GL resources this item owns (textures, display lists, text renderers, etc.).

      The default implementation does nothing. Items that lazily allocate GL-backed resources — for example a JOGL TextRenderer — should override this to release them and null out the field so a subsequent draw call (if any) lazily recreates it.

      Parameters:
      drawable - the OpenGL drawable being disposed
    • get

      public Object get(String key) throws Bad3DPropertyException
      Get a 3D property
      Parameters:
      key - the name of the property
      Returns:
      the object corresponding to that key, or null
      Throws:
      Bad3DPropertyException - if the property is missing or not of the expected type
    • getString

      public String getString(String key) throws Bad3DPropertyException
      Get a String 3D property
      Parameters:
      key - the name of the property
      Returns:
      the String corresponding to that key, or null
      Throws:
      Bad3DPropertyException - if the property is missing or not of the expected type
    • getColor

      public Color getColor(String key) throws Bad3DPropertyException
      Get an AWT color 3D property
      Parameters:
      key - the name of the property
      Returns:
      the (AWT) Color corresponding to that key, or null
      Throws:
      Bad3DPropertyException - if the property is missing or not of the expected type
    • getFont

      public Font getFont(String key) throws Bad3DPropertyException
      Get an a Font 3D property
      Parameters:
      key - the name of the property
      Returns:
      the Font corresponding to that key, or null
      Throws:
      Bad3DPropertyException - if the property is missing or not of the expected type
    • getInt

      public int getInt(String key) throws Bad3DPropertyException
      Get a integer 3D property
      Parameters:
      key - the name of the property
      Returns:
      the Integer corresponding to that key, or null
      Throws:
      Bad3DPropertyException - if the property is missing or not of the expected type
    • getFloat

      public float getFloat(String key) throws Bad3DPropertyException
      Get a float 3D property
      Parameters:
      key - the name of the property
      Returns:
      the Float corresponding to that key, or null
      Throws:
      Bad3DPropertyException - if the property is missing or not of the expected type
    • getLineWidth

      public float getLineWidth()
      Convenience method to get the line width for this item
      Returns:
      the line width. (Default is 1f)
    • setLineWidth

      public void setLineWidth(float lineWidth)
      Convenience method to set the line width
      Parameters:
      lineWidth - the line width.
    • getFillColor

      public Color getFillColor()
      Convenience method to get the fill color for this item
      Returns:
      the fill color.
    • getFillAlpha

      public int getFillAlpha()
      Convenience method to get the fill alpha for this item
      Returns:
      the fill alpha.
    • getLineAlpha

      public int getLineAlpha()
      Convenience method to get the line (frame) alpha for this item
      Returns:
      the line (frame) alpha.
    • getLineColor

      public Color getLineColor()
      Convenience method to get the line (and frame)color for this item
      Returns:
      the line (frame) color.
    • getTextColor

      public Color getTextColor()
      Convenience method to get the text color for this item
      Returns:
      the text color.
    • getFont

      public Font getFont()
      Convenience method to get the fontr for this item
      Returns:
      the font.
    • setFillColor

      public void setFillColor(Color color)
      Convenience method to set the fill color
      Parameters:
      color - the fill color.
    • setLineColor

      public void setLineColor(Color color)
      Convenience method to set the line (frame) color
      Parameters:
      color - the line (frame) color.
    • setFillAlpha

      public void setFillAlpha(int alpha)
      Convenience method to set the fill alpha
      Parameters:
      alpha - the fill alpha [0..255].
    • setLineAlpha

      public void setLineAlpha(int alpha)
      Convenience method to set the line (frame) alpha
      Parameters:
      alpha - the line (frame) alpha [0..255].
    • setTextColor

      public void setTextColor(Color textColor)
      Convenience method to set the text color
      Parameters:
      textColor - the text color.
    • setFont

      public void setFont(Font font)
      Convenience method to set the font
      Parameters:
      font - the text font.
    • setVisible

      public void setVisible(boolean visible)
      Controls whether we want the item to be drawn. That is, drawing is skipped if this is false. Whether or not the item is actually visible when drawn is not controlled by this flag. This does NOT initiate a redraw,
      Parameters:
      visible - the visibility flag.
    • isVisible

      public boolean isVisible()
      Checks whether we want the item to be drawn. That is, drawing is skipped if this is false. Whether or not the item is actually visible when drawn is not controlled by this flag.
      Returns:
      the visibility flag.
    • getChildren

      public List<Item3D> getChildren()
      Get a list of the item's children, can be null
      Returns:
      a list of the item's children
    • getParent

      public Item3D getParent()
      Get the parent item (might be null)
      Returns:
      the parent
    • addChild

      public void addChild(Item3D item)
      Add a child item.

      The remove-then-add (to move an existing child to the end) is performed under synchronized(this) so it is atomic with respect to childrenSnapshot() — a concurrent drawer/disposer can never observe the child transiently missing.

      Parameters:
      item - the child item
    • removeChild

      public void removeChild(Item3D item)
      Remove a child item
      Parameters:
      item - the chold item
    • getPanel3D

      public Panel3D getPanel3D()
      Get the parent Panel3D object
      Returns:
      the parent Panel3D object
    • setAlphaOfColor

      protected Color setAlphaOfColor(Color color, int alpha)
      Set the alpha of a color. If it already has the given alpha it just returns the color. If not, it makes a new color with the same RGB components and the new alpha
      Parameters:
      color - the color to change
      alpha - the alpha [0..255] 0 is transparent, 255 is opaque
      Returns:
      the color
    • getSortPoint

      public float[] getSortPoint()
      A representative point for transparent sorting, in world coordinates. Default is origin. Override in items with a natural center (Sphere, Cube, Cylinder, etc.).
      Returns:
      the sort point as [x, y, z]