Class OutlineShape

java.lang.Object
com.jogamp.graph.curve.OutlineShape
All Implemented Interfaces:
Comparable<OutlineShape>

public class OutlineShape extends Object implements Comparable<OutlineShape>
A Generic shape objects which is defined by a list of Outlines. This Shape can be transformed to triangulations. The list of triangles generated are render-able by a Region object. The triangulation produced by this Shape will define the closed region defined by the outlines. One or more OutlineShape Object can be associated to a region this is left as a high-level representation of the Objects. For optimizations, flexibility requirements for future features.

Example to creating an Outline Shape:
      addVertex(...)
      addVertex(...)
      addVertex(...)
      addEmptyOutline()
      addVertex(...)
      addVertex(...)
      addVertex(...)
 
The above will create two outlines each with three vertices. By adding these two outlines to the OutlineShape, we are stating that the combination of the two outlines represent the shape.
To specify that the shape is curved at a region, the on-curve flag should be set to false for the vertex that is in the middle of the curved region (if the curved region is defined by 3 vertices (quadratic curve).
In case the curved region is defined by 4 or more vertices the middle vertices should both have the on-curve flag set to false.
Example:
      addVertex(0,0, true);
      addVertex(0,1, false);
      addVertex(1,1, false);
      addVertex(1,0, true);
 
The above snippet defines a cubic nurbs curve where (0,1 and 1,1) do not belong to the final rendered shape. Implementation Notes:
  • The first vertex of any outline belonging to the shape should be on-curve
  • Intersections between off-curved parts of the outline is not handled
See Also:
  • Field Details

    • DEFAULT_SHARPNESS

      public static final float DEFAULT_SHARPNESS
      Initial getSharpness() value, which can be modified via setSharpness(float).
      See Also:
    • DIRTY_BOUNDS

      public static final int DIRTY_BOUNDS
      See Also:
    • DIRTY_VERTICES

      public static final int DIRTY_VERTICES
      Modified shape, requires to update the vertices and triangles, here: vertices.
      See Also:
    • DIRTY_TRIANGLES

      public static final int DIRTY_TRIANGLES
      Modified shape, requires to update the vertices and triangles, here: triangulation.
      See Also:
  • Constructor Details

    • OutlineShape

      public OutlineShape(Vertex.Factory<? extends Vertex> factory)
      Create a new Outline based Shape
  • Method Details

    • getAddedVerticeCount

      public int getAddedVerticeCount()
      Return the number of newly added vertices during getTriangles(VerticesState) while transforming the outlines to OutlineShape.VerticesState.QUADRATIC_NURBS and triangulation.
      See Also:
    • getSharpness

      public float getSharpness()
      Sharpness value, defaults to DEFAULT_SHARPNESS.
    • setSharpness

      public void setSharpness(float s)
      Sets sharpness, defaults to DEFAULT_SHARPNESS.
    • clear

      public void clear()
      Clears all data and reset all states as if this instance was newly created
    • clearCache

      public void clearCache()
      Clears cached triangulated data, i.e. getTriangles(VerticesState) and getVertices().
    • vertexFactory

      public final Vertex.Factory<? extends Vertex> vertexFactory()
      Returns the associated vertex factory of this outline shape
      Returns:
      Vertex.Factory object
    • getOutlineNumber

      public final int getOutlineNumber()
    • addEmptyOutline

      public final void addEmptyOutline()
      Add a new empty Outline to the end of this shape's outline list.

      If the getLastOutline() is empty already, no new one will be added.

      After a call to this function all new vertices added will belong to the new outline
    • addOutline

      public final void addOutline(Outline outline) throws NullPointerException
      Appends the Outline element to the end, ensuring a clean tail.

      A clean tail is ensured, no double empty Outlines are produced and a pre-existing empty outline will be replaced with the given one.

      Parameters:
      outline - Outline object to be added
      Throws:
      NullPointerException - if the Outline element is null
    • addOutline

      public final void addOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException
      Insert the Outline element at the given position.

      If the position indicates the end of this list, a clean tail is ensured, no double empty Outlines are produced and a pre-existing empty outline will be replaced with the given one.

      Parameters:
      position - of the added Outline
      outline - Outline object to be added
      Throws:
      NullPointerException - if the Outline element is null
      IndexOutOfBoundsException - if position is out of range (position < 0 || position > getOutlineNumber())
    • addOutlineShape

      public final void addOutlineShape(OutlineShape outlineShape) throws NullPointerException
      Insert the OutlineShape elements of type Outline, .. at the end of this shape, using addOutline(Outline) for each element.

      Closes the current last outline via closeLastOutline(boolean) before adding the new ones.

      Parameters:
      outlineShape - OutlineShape elements to be added.
      Throws:
      NullPointerException - if the OutlineShape is null
      IndexOutOfBoundsException - if position is out of range (position < 0 || position > getOutlineNumber())
    • setOutline

      public final void setOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException
      Replaces the Outline element at the given position.

      Sets the bounding box dirty, hence a next call to getBounds() will validate it.

      Parameters:
      position - of the replaced Outline
      outline - replacement Outline object
      Throws:
      NullPointerException - if the Outline element is null
      IndexOutOfBoundsException - if position is out of range (position < 0 || position >= getOutlineNumber())
    • removeOutline

      public final Outline removeOutline(int position) throws IndexOutOfBoundsException
      Removes the Outline element at the given position.

      Sets the bounding box dirty, hence a next call to getBounds() will validate it.

      Parameters:
      position - of the to be removed Outline
      Throws:
      IndexOutOfBoundsException - if position is out of range (position < 0 || position >= getOutlineNumber())
    • getLastOutline

      public final Outline getLastOutline()
      Get the last added outline to the list of outlines that define the shape
      Returns:
      the last outline
    • getOutline

      public final Outline getOutline(int position) throws IndexOutOfBoundsException
      Returns the Outline at position
      Throws:
      IndexOutOfBoundsException - if position is out of range (position < 0 || position >= getOutlineNumber())
    • addVertex

      public final void addVertex(Vertex v)
      Adds a vertex to the last open outline to the shape's tail.
      Parameters:
      v - the vertex to be added to the OutlineShape
    • addVertex

      public final void addVertex(int position, Vertex v)
      Adds a vertex to the last open outline to the shape at position
      Parameters:
      position - indx at which the vertex will be added
      v - the vertex to be added to the OutlineShape
    • addVertex

      public final void addVertex(float x, float y, boolean onCurve)
      Add a 2D Vertex to the last outline by defining the coordinate attribute of the vertex. The 2D vertex will be represented as Z=0.
      Parameters:
      x - the x coordinate
      y - the y coordniate
      onCurve - flag if this vertex is on the final curve or defines a curved region of the shape around this vertex.
    • addVertex

      public final void addVertex(float x, float y, float z, boolean onCurve)
      Add a 3D Vertex to the last outline by defining the coordniate attribute of the vertex.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      onCurve - flag if this vertex is on the final curve or defines a curved region of the shape around this vertex.
    • addVertex

      public final void addVertex(float[] coordsBuffer, int offset, int length, boolean onCurve)
      Add a vertex to the last outline by passing a float array and specifying the offset and length in which. The attributes of the vertex are located. The attributes should be continuous (stride = 0). Attributes which value are not set (when length less than 3) are set implicitly to zero.
      Parameters:
      coordsBuffer - the coordinate array where the vertex attributes are to be picked from
      offset - the offset in the buffer to the x coordinate
      length - the number of attributes to pick from the buffer (maximum 3)
      onCurve - flag if this vertex is on the final curve or defines a curved region of the shape around this vertex.
    • closeLastOutline

      public final void closeLastOutline(boolean closeTail)
      Closes the last outline in the shape.

      Checks whether the last vertex equals to the first of the last outline. If not equal, it either appends a clone of the first vertex or prepends a clone of the last vertex, depending on closeTail.

      Parameters:
      closeTail - if true, a clone of the first vertex will be appended, otherwise a clone of the last vertex will be prepended.
    • getOutlineState

      public final OutlineShape.VerticesState getOutlineState()
      Return the outline's vertices state, OutlineShape.VerticesState
    • setIsQuadraticNurbs

      public final void setIsQuadraticNurbs()
      Claim this outline's vertices are all OutlineShape.VerticesState.QUADRATIC_NURBS, hence no cubic transformations will be performed.
    • getVertices

      public final ArrayList<Vertex> getVertices()
      Return list of concatenated vertices associated with all Outlines of this object.

      Vertices are cached until marked dirty.

      Should always be called after getTriangles(VerticesState), since the latter will mark all cached vertices dirty!

    • getTriangles

      public ArrayList<Triangle> getTriangles(OutlineShape.VerticesState destinationType)
      Triangulate the OutlineShape generating a list of triangles, while #transformOutlines(VerticesState) beforehand.

      Triangles are cached until marked dirty.

      Returns:
      an arraylist of triangles representing the filled region which is produced by the combination of the outlines
    • transform

      public final OutlineShape transform(jogamp.graph.geom.plane.AffineTransform t)
      Return a transformed instance with all Outlines are copied and transformed.

      Note: Triangulated data is lost in returned instance!

    • compareTo

      public final int compareTo(OutlineShape other)
      Compare two outline shape's Bounding Box size.
      Specified by:
      compareTo in interface Comparable<OutlineShape>
      See Also:
    • getBounds

      public final AABBox getBounds()
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      Parameters:
      obj - the Object to compare this OutlineShape with
      Returns:
      true if obj is an OutlineShape, not null, same outlineState, equal bounds and equal outlines in the same order
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object