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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OutlineShape.VerticesState
Outline's vertices have undefined state until transformed.
-
Field Summary
Fields Modifier and Type Field Description static float
DEFAULT_SHARPNESS
InitialgetSharpness()
value, which can be modified viasetSharpness(float)
.static int
DIRTY_BOUNDS
static int
DIRTY_TRIANGLES
Modified shape, requires to update the vertices and triangles, here: triangulation.static int
DIRTY_VERTICES
Modified shape, requires to update the vertices and triangles, here: vertices.
-
Constructor Summary
Constructors Constructor Description OutlineShape(Vertex.Factory<? extends Vertex> factory)
Create a new Outline based Shape
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEmptyOutline()
Add a new emptyOutline
to the end of this shape's outline list.void
addOutline(int position, Outline outline)
Insert theOutline
element at the givenposition
.void
addOutline(Outline outline)
Appends theOutline
element to the end, ensuring a clean tail.void
addOutlineShape(OutlineShape outlineShape)
Insert theOutlineShape
elements of typeOutline
, ..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.void
addVertex(float x, float y, boolean onCurve)
Add a 2DVertex
to the last outline by defining the coordinate attribute of the vertex.void
addVertex(float x, float y, float z, boolean onCurve)
Add a 3DVertex
to the last outline by defining the coordniate attribute of the vertex.void
addVertex(int position, Vertex v)
Adds a vertex to the last open outline to the shape atposition
void
addVertex(Vertex v)
Adds a vertex to the last open outline to the shape's tail.void
clear()
Clears all data and reset all states as if this instance was newly createdvoid
clearCache()
Clears cached triangulated data, i.e.void
closeLastOutline(boolean closeTail)
Closes the last outline in the shape.int
compareTo(OutlineShape other)
Compare two outline shape's Bounding Box size.boolean
equals(Object obj)
int
getAddedVerticeCount()
Return the number of newly added vertices duringgetTriangles(VerticesState)
while transforming the outlines toOutlineShape.VerticesState.QUADRATIC_NURBS
and triangulation.AABBox
getBounds()
Outline
getLastOutline()
Get the last added outline to the list of outlines that define the shapeOutline
getOutline(int position)
Returns theOutline
atposition
int
getOutlineNumber()
OutlineShape.VerticesState
getOutlineState()
Return the outline's vertices state,OutlineShape.VerticesState
float
getSharpness()
Sharpness value, defaults toDEFAULT_SHARPNESS
.ArrayList<Triangle>
getTriangles(OutlineShape.VerticesState destinationType)
Triangulate theOutlineShape
generating a list of triangles, while#transformOutlines(VerticesState)
beforehand.ArrayList<Vertex>
getVertices()
Return list of concatenated vertices associated with allOutline
s of this object.int
hashCode()
Outline
removeOutline(int position)
Removes theOutline
element at the givenposition
.void
setIsQuadraticNurbs()
Claim this outline's vertices are allOutlineShape.VerticesState.QUADRATIC_NURBS
, hence no cubic transformations will be performed.void
setOutline(int position, Outline outline)
Replaces theOutline
element at the givenposition
.void
setSharpness(float s)
Sets sharpness, defaults toDEFAULT_SHARPNESS
.String
toString()
OutlineShape
transform(jogamp.graph.geom.plane.AffineTransform t)
Return a transformed instance with allOutline
s are copied and transformed.Vertex.Factory<? extends Vertex>
vertexFactory()
Returns the associated vertex factory of this outline shape
-
-
-
Field Detail
-
DEFAULT_SHARPNESS
public static final float DEFAULT_SHARPNESS
InitialgetSharpness()
value, which can be modified viasetSharpness(float)
.- See Also:
- Constant Field Values
-
DIRTY_BOUNDS
public static final int DIRTY_BOUNDS
- See Also:
- Constant Field Values
-
DIRTY_VERTICES
public static final int DIRTY_VERTICES
Modified shape, requires to update the vertices and triangles, here: vertices.- See Also:
- Constant Field Values
-
DIRTY_TRIANGLES
public static final int DIRTY_TRIANGLES
Modified shape, requires to update the vertices and triangles, here: triangulation.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OutlineShape
public OutlineShape(Vertex.Factory<? extends Vertex> factory)
Create a new Outline based Shape
-
-
Method Detail
-
getAddedVerticeCount
public int getAddedVerticeCount()
Return the number of newly added vertices duringgetTriangles(VerticesState)
while transforming the outlines toOutlineShape.VerticesState.QUADRATIC_NURBS
and triangulation.- See Also:
setIsQuadraticNurbs()
-
getSharpness
public float getSharpness()
Sharpness value, defaults toDEFAULT_SHARPNESS
.
-
setSharpness
public void setSharpness(float s)
Sets sharpness, defaults toDEFAULT_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)
andgetVertices()
.
-
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 emptyOutline
to the end of this shape's outline list.If the
After a call to this function all new vertices added will belong to the new outlinegetLastOutline()
is empty already, no new one will be added.
-
addOutline
public final void addOutline(Outline outline) throws NullPointerException
Appends theOutline
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 theOutline
element is null
-
addOutline
public final void addOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException
Insert theOutline
element at the givenposition
.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 Outlineoutline
- Outline object to be added- Throws:
NullPointerException
- if theOutline
element is nullIndexOutOfBoundsException
- if position is out of range (position < 0 || position > getOutlineNumber())
-
addOutlineShape
public final void addOutlineShape(OutlineShape outlineShape) throws NullPointerException
Insert theOutlineShape
elements of typeOutline
, .. at the end of this shape, usingaddOutline(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 theOutlineShape
is nullIndexOutOfBoundsException
- if position is out of range (position < 0 || position > getOutlineNumber())
-
setOutline
public final void setOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException
Replaces theOutline
element at the givenposition
.Sets the bounding box dirty, hence a next call to
getBounds()
will validate it.- Parameters:
position
- of the replaced Outlineoutline
- replacement Outline object- Throws:
NullPointerException
- if theOutline
element is nullIndexOutOfBoundsException
- if position is out of range (position < 0 || position >= getOutlineNumber())
-
removeOutline
public final Outline removeOutline(int position) throws IndexOutOfBoundsException
Removes theOutline
element at the givenposition
.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 theOutline
atposition
- 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 atposition
- Parameters:
position
- indx at which the vertex will be addedv
- the vertex to be added to the OutlineShape
-
addVertex
public final void addVertex(float x, float y, boolean onCurve)
Add a 2DVertex
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 coordinatey
- the y coordniateonCurve
- 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 3DVertex
to the last outline by defining the coordniate attribute of the vertex.- Parameters:
x
- the x coordinatey
- the y coordinatez
- the z coordinateonCurve
- 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 fromoffset
- the offset in the buffer to the x coordinatelength
- 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 allOutlineShape.VerticesState.QUADRATIC_NURBS
, hence no cubic transformations will be performed.
-
getVertices
public final ArrayList<Vertex> getVertices()
Return list of concatenated vertices associated with allOutline
s 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 theOutlineShape
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 allOutline
s 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 interfaceComparable<OutlineShape>
- See Also:
AABBox.getSize()
,Comparable.compareTo(java.lang.Object)
-
getBounds
public final AABBox getBounds()
-
equals
public boolean equals(Object obj)
-
-