Class OutlineShape
- java.lang.Object
-
- com.jogamp.graph.curve.OutlineShape
-
- All Implemented Interfaces:
Comparable<OutlineShape>
public final 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.
Outline shape general
Winding
rules- Outer boundary shapes are required as
Winding.CCW
, if unsure- You may check
Winding
viagetWindingOfLastOutline()
orOutline.getWinding()
(optional) - Use
setWindingOfLastOutline(Winding)
beforecloseLastOutline(boolean)
orclosePath()
} to enforceWinding.CCW
, or - use
Outline.setWinding(Winding)
on a specificOutline
to enforceWinding.CCW
. - If e.g. the
Winding
has changed for anOutline
by above operations, its vertices have been reversed.
- You may check
- Inner shapes or holes are adjusted to be
Winding.CW
, no user consideration is required here. - Safe path: Simply create all shapes with
Winding.CCW
or applyOutline.setWinding(Winding)
.
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()
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
addPath(Path2F.Iterator pathI, boolean connect)
Add the givenPath2F.Iterator
to this outline shape.void
addPath(Path2F path, boolean connect)
Append the given path geometry to this outline shape.void
addPathRev(Path2F.Iterator pathI, boolean connect)
Add the givenPath2F.Iterator
to this outline shape in reverse order.void
addPathRev(Path2F path, boolean connect)
Append the given path geometry to this outline shape in reverse order.void
addVertex(float[] coordsBuffer, int offset, int length, boolean onCurve)
Add a vertex to the last open outline to the shape's tail.void
addVertex(float x, float y, boolean onCurve)
Add a 2DVertex
to the last open outline to the shape's tail.void
addVertex(float x, float y, float z, boolean onCurve)
Add a 3DVertex
to the last open outline to the shape's tail.void
addVertex(int position, float[] coordsBuffer, int offset, int length, boolean onCurve)
Add a vertex to the last open outline to the shape atposition
.void
addVertex(int position, float x, float y, boolean onCurve)
Add a 2DVertex
to the last open outline to the shape atposition
.void
addVertex(int position, float x, float y, float z, boolean onCurve)
Add a 3DVertex
to the last open outline to the shape atposition
.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.void
closePath()
Closes the current sub-path segment by drawing a straight line back to the coordinates of the last moveTo.int
compareTo(OutlineShape other)
Compare two outline shape's Bounding Box size.void
cubicTo(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
Add a cubic Bézier curve segment, intersecting the last point and the second given point x3/y3 (P3).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
getOutlineCount()
Returns the number ofOutline
s.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.int
getVertexCount()
Returns the totalvertex number
of allOutline
s.ArrayList<Vertex>
getVertices()
Return list of concatenated vertices associated with allOutline
s of this object.Winding
getWindingOfLastOutline()
Compute theWinding
of thegetLastOutline()
using the#area(ArrayList)
function over all of its vertices.int
hashCode()
void
lineTo(float x, float y, float z)
Add a line segment, intersecting the last point and the given point x/y (P1).void
moveTo(float x, float y, float z)
Start a new position for the next line segment at given point x/y (P1).void
quadTo(float x1, float y1, float z1, float x2, float y2, float z2)
Add a quadratic curve segment, intersecting the last point and the second given point x2/y2 (P2).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
.void
setWindingOfLastOutline(Winding enforced)
Sets the enforcedWinding
of thegetLastOutline()
.String
toString()
OutlineShape
transform(AffineTransform t)
Return a transformed instance with allOutline
s are copied and transformed.
-
-
-
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
-
-
Method Detail
-
getAddedVerticeCount
public final 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 final float getSharpness()
Sharpness value, defaults toDEFAULT_SHARPNESS
.
-
setSharpness
public final void setSharpness(float s)
Sets sharpness, defaults toDEFAULT_SHARPNESS
.
-
clear
public final void clear()
Clears all data and reset all states as if this instance was newly created
-
clearCache
public final void clearCache()
Clears cached triangulated data, i.e.getTriangles(VerticesState)
andgetVertices()
.
-
getOutlineCount
public final int getOutlineCount()
Returns the number ofOutline
s.
-
getVertexCount
public final int getVertexCount()
Returns the totalvertex number
of allOutline
s.
-
getWindingOfLastOutline
public final Winding getWindingOfLastOutline()
Compute theWinding
of thegetLastOutline()
using the#area(ArrayList)
function over all of its vertices.- Returns:
Winding.CCW
orWinding.CW
-
setWindingOfLastOutline
public final void setWindingOfLastOutline(Winding enforced)
Sets the enforcedWinding
of thegetLastOutline()
.
-
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- See Also:
- see winding rules
-
addVertex
public final void addVertex(int position, Vertex v)
Adds a vertex to the last open outline to the shape atposition
- Parameters:
position
- index within the last open outline, at which the vertex will be addedv
- the vertex to be added to the OutlineShape- See Also:
- see winding rules
-
addVertex
public final void addVertex(float x, float y, boolean onCurve)
Add a 2DVertex
to the last open outline to the shape's tail. 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.- See Also:
- see winding rules
-
addVertex
public final void addVertex(int position, float x, float y, boolean onCurve)
Add a 2DVertex
to the last open outline to the shape atposition
. The 2D vertex will be represented as Z=0.- Parameters:
position
- index within the last open outline, at which the vertex will be addedx
- 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.- See Also:
- see winding rules
-
addVertex
public final void addVertex(float x, float y, float z, boolean onCurve)
Add a 3DVertex
to the last open outline to the shape's tail.- 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.- See Also:
- see winding rules
-
addVertex
public final void addVertex(int position, float x, float y, float z, boolean onCurve)
Add a 3DVertex
to the last open outline to the shape atposition
.- Parameters:
position
- index within the last open outline, at which the vertex will be addedx
- the x coordinatey
- the y coordniatez
- the z coordinateonCurve
- flag if this vertex is on the final curve or defines a curved region of the shape around this vertex.- See Also:
- see winding rules
-
addVertex
public final void addVertex(float[] coordsBuffer, int offset, int length, boolean onCurve)
Add a vertex to the last open outline to the shape's tail. The vertex is passed as a float array and its offset where its attributes 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.- See Also:
- see winding rules
-
addVertex
public final void addVertex(int position, float[] coordsBuffer, int offset, int length, boolean onCurve)
Add a vertex to the last open outline to the shape atposition
. The vertex is passed as a float array and its offset where its attributes 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:
position
- index within the last open outline, at which the vertex will be addedcoordsBuffer
- 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.- See Also:
- see winding rules
-
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.
-
addPath
public void addPath(Path2F path, boolean connect)
Append the given path geometry to this outline shape. The given path geometry should beWinding.CCW
. If the given path geometry isWinding.CW
, useaddPathRev(Path2F, boolean)
.- Parameters:
path
- thePath2F
to append to this outline shape, should beWinding.CCW
.connect
- pass true to turn an initial moveTo segment into a lineTo segment to connect the new geometry to the existing path, otherwise pass false.- See Also:
Path2F.getWinding()
-
addPath
public final void addPath(Path2F.Iterator pathI, boolean connect)
Add the givenPath2F.Iterator
to this outline shape. The given path geometry should beWinding.CCW
. If the given path geometry isWinding.CW
, use {@link #addPathRev(Path2F.Iterator, boolean).- Parameters:
pathI
- thePath2F.Iterator
to append to this outline shape, should beWinding.CCW
.connect
- pass true to turn an initial moveTo segment into a lineTo segment to connect the new geometry to the existing path, otherwise pass false.- See Also:
Path2F.Iterator.getWinding()
-
addPathRev
public void addPathRev(Path2F path, boolean connect)
Append the given path geometry to this outline shape in reverse order. The given path geometry should beWinding.CW
. If the given path geometry isWinding.CCW
, useaddPath(Path2F, boolean)
.- Parameters:
path
- thePath2F
to append to this outline shape, should beWinding.CW
.connect
- pass true to turn an initial moveTo segment into a lineTo segment to connect the new geometry to the existing path, otherwise pass false.
-
addPathRev
public final void addPathRev(Path2F.Iterator pathI, boolean connect)
Add the givenPath2F.Iterator
to this outline shape in reverse order. The given path geometry should beWinding.CW
. If the given path geometry isWinding.CCW
, use {@link #addPath(Path2F.Iterator, boolean).- Parameters:
pathI
- thePath2F.Iterator
to append to this outline shape, should beWinding.CW
.connect
- pass true to turn an initial moveTo segment into a lineTo segment to connect the new geometry to the existing path, otherwise pass false.
-
moveTo
public final void moveTo(float x, float y, float z)
Start a new position for the next line segment at given point x/y (P1).- Parameters:
x
- point (P1)y
- point (P1)z
- point (P1)- See Also:
Path2F.moveTo(float, float)
,addPath(com.jogamp.graph.geom.plane.Path2F.Iterator, boolean)
, see winding rules
-
lineTo
public final void lineTo(float x, float y, float z)
Add a line segment, intersecting the last point and the given point x/y (P1).- Parameters:
x
- final point (P1)y
- final point (P1)z
- final point (P1)- See Also:
Path2F.lineTo(float, float)
,addPath(com.jogamp.graph.geom.plane.Path2F.Iterator, boolean)
, see winding rules
-
quadTo
public final void quadTo(float x1, float y1, float z1, float x2, float y2, float z2)
Add a quadratic curve segment, intersecting the last point and the second given point x2/y2 (P2).- Parameters:
x1
- quadratic parametric control point (P1)y1
- quadratic parametric control point (P1)z1
- quadratic parametric control point (P1)x2
- final interpolated control point (P2)y2
- final interpolated control point (P2)z2
- quadratic parametric control point (P2)- See Also:
Path2F.quadTo(float, float, float, float)
,addPath(com.jogamp.graph.geom.plane.Path2F.Iterator, boolean)
, see winding rules
-
cubicTo
public final void cubicTo(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
Add a cubic Bézier curve segment, intersecting the last point and the second given point x3/y3 (P3).- Parameters:
x1
- Bézier control point (P1)y1
- Bézier control point (P1)z1
- Bézier control point (P1)x2
- Bézier control point (P2)y2
- Bézier control point (P2)z2
- Bézier control point (P2)x3
- final interpolated control point (P3)y3
- final interpolated control point (P3)z3
- final interpolated control point (P3)- See Also:
Path2F.cubicTo(float, float, float, float, float, float)
,addPath(com.jogamp.graph.geom.plane.Path2F.Iterator, boolean)
, see winding rules
-
closePath
public final void closePath()
Closes the current sub-path segment by drawing a straight line back to the coordinates of the last moveTo. If the path is already closed then this method has no effect.
-
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 final 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(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 final boolean equals(Object obj)
-
-