Class OutlineShape
- All Implemented Interfaces:
Comparable<OutlineShape>
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 ClassesModifier and TypeClassDescriptionstatic enumOutline's vertices have undefined state until transformed. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatInitialgetSharpness()value, which can be modified viasetSharpness(float).static final intstatic final intModified shape, requires to update the vertices and triangles, here: triangulation.static final intModified shape, requires to update the vertices and triangles, here: vertices. -
Constructor Summary
ConstructorsConstructorDescriptionOutlineShape(Vertex.Factory<? extends Vertex> factory) Create a new Outline based Shape -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdd a new emptyOutlineto the end of this shape's outline list.final voidaddOutline(int position, Outline outline) Insert theOutlineelement at the givenposition.final voidaddOutline(Outline outline) Appends theOutlineelement to the end, ensuring a clean tail.final voidaddOutlineShape(OutlineShape outlineShape) Insert theOutlineShapeelements of typeOutline, ..final voidaddVertex(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.final voidaddVertex(float x, float y, boolean onCurve) Add a 2DVertexto the last outline by defining the coordinate attribute of the vertex.final voidaddVertex(float x, float y, float z, boolean onCurve) Add a 3DVertexto the last outline by defining the coordniate attribute of the vertex.final voidAdds a vertex to the last open outline to the shape atpositionfinal voidAdds a vertex to the last open outline to the shape's tail.voidclear()Clears all data and reset all states as if this instance was newly createdvoidClears cached triangulated data, i.e.final voidcloseLastOutline(boolean closeTail) Closes the last outline in the shape.final intcompareTo(OutlineShape other) Compare two outline shape's Bounding Box size.booleanintReturn the number of newly added vertices duringgetTriangles(VerticesState)while transforming the outlines toOutlineShape.VerticesState.QUADRATIC_NURBSand triangulation.final AABBoxfinal OutlineGet the last added outline to the list of outlines that define the shapefinal OutlinegetOutline(int position) Returns theOutlineatpositionfinal intReturn the outline's vertices state,OutlineShape.VerticesStatefloatSharpness value, defaults toDEFAULT_SHARPNESS.getTriangles(OutlineShape.VerticesState destinationType) Triangulate theOutlineShapegenerating a list of triangles, while#transformOutlines(VerticesState)beforehand.Return list of concatenated vertices associated with allOutlines of this object.final inthashCode()final OutlineremoveOutline(int position) Removes theOutlineelement at the givenposition.final voidClaim this outline's vertices are allOutlineShape.VerticesState.QUADRATIC_NURBS, hence no cubic transformations will be performed.final voidsetOutline(int position, Outline outline) Replaces theOutlineelement at the givenposition.voidsetSharpness(float s) Sets sharpness, defaults toDEFAULT_SHARPNESS.toString()final OutlineShapetransform(jogamp.graph.geom.plane.AffineTransform t) Return a transformed instance with allOutlines are copied and transformed.final Vertex.Factory<? extends Vertex>Returns the associated vertex factory of this outline shape
-
Field Details
-
DEFAULT_SHARPNESS
public static final float DEFAULT_SHARPNESSInitialgetSharpness()value, which can be modified viasetSharpness(float).- See Also:
-
DIRTY_BOUNDS
public static final int DIRTY_BOUNDS- See Also:
-
DIRTY_VERTICES
public static final int DIRTY_VERTICESModified shape, requires to update the vertices and triangles, here: vertices.- See Also:
-
DIRTY_TRIANGLES
public static final int DIRTY_TRIANGLESModified shape, requires to update the vertices and triangles, here: triangulation.- See Also:
-
-
Constructor Details
-
OutlineShape
Create a new Outline based Shape
-
-
Method Details
-
getAddedVerticeCount
public int getAddedVerticeCount()Return the number of newly added vertices duringgetTriangles(VerticesState)while transforming the outlines toOutlineShape.VerticesState.QUADRATIC_NURBSand triangulation.- See Also:
-
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
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 emptyOutlineto 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
Appends theOutlineelement 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 theOutlineelement is null
-
addOutline
public final void addOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException Insert theOutlineelement at the givenposition.If the
positionindicates 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 theOutlineelement is nullIndexOutOfBoundsException- if position is out of range (position < 0 || position > getOutlineNumber())
-
addOutlineShape
Insert theOutlineShapeelements 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 theOutlineShapeis nullIndexOutOfBoundsException- if position is out of range (position < 0 || position > getOutlineNumber())
-
setOutline
public final void setOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException Replaces theOutlineelement 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 theOutlineelement is nullIndexOutOfBoundsException- if position is out of range (position < 0 || position >= getOutlineNumber())
-
removeOutline
Removes theOutlineelement 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
Get the last added outline to the list of outlines that define the shape- Returns:
- the last outline
-
getOutline
Returns theOutlineatposition- Throws:
IndexOutOfBoundsException- if position is out of range (position < 0 || position >= getOutlineNumber())
-
addVertex
Adds a vertex to the last open outline to the shape's tail.- Parameters:
v- the vertex to be added to the OutlineShape
-
addVertex
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 2DVertexto 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 3DVertexto 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
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
Return list of concatenated vertices associated with allOutlines 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
Triangulate theOutlineShapegenerating 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
Return a transformed instance with allOutlines are copied and transformed.Note: Triangulated data is lost in returned instance!
-
compareTo
Compare two outline shape's Bounding Box size.- Specified by:
compareToin interfaceComparable<OutlineShape>- See Also:
-
getBounds
-
equals
-
hashCode
public final int hashCode() -
toString
-