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
Example to creating an Outline Shape:Windingrules- Outer boundary-shapes are required as
Winding.CCW - Inner hole-shapes should be
Winding.CW - If unsure
- You may check
WindingviagetWindingOfLastOutline()orOutline.getWinding()(optional, might be incorrect) - Use
setWindingOfLastOutline(Winding)beforecloseLastOutline(boolean)orclosePath()} to enforceWinding.CCW, or - use
Outline.setWinding(Winding)on a specificOutlineto enforceWinding.CCW. - If e.g. the
Windinghas changed for anOutlineby above operations, its vertices have been reversed.
- You may check
- Safe path: Simply create all outer boundary-shapes with
Winding.CCWand inner hole-shapes withWinding.CW.
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 classOutlineShape.VerticesStateOutline's vertices have undefined state until transformed.
-
Field Summary
Fields Modifier and Type Field Description static floatDEFAULT_SHARPNESSInitialgetSharpness()value, which can be modified viasetSharpness(float).
-
Constructor Summary
Constructors Constructor Description OutlineShape()Create a new Outline based Shape
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEmptyOutline()Add a new emptyOutlineto the end of this shape's outline list.voidaddOutline(int position, Outline outline)Insert theOutlineelement at the givenposition.voidaddOutline(Outline outline)Appends theOutlineelement to the end, ensuring a clean tail.voidaddOutlineShape(OutlineShape outlineShape)Insert theOutlineShapeelements of typeOutline, ..voidaddPath(com.jogamp.math.geom.plane.Path2F.Iterator pathI, boolean connect)Add the givenPath2F.Iteratorto this outline shape.voidaddPath(com.jogamp.math.geom.plane.Path2F path, boolean connect)Append the given path geometry to this outline shape.voidaddPathRev(com.jogamp.math.geom.plane.Path2F.Iterator pathI, boolean connect)Add the givenPath2F.Iteratorto this outline shape in reverse order.voidaddPathRev(com.jogamp.math.geom.plane.Path2F path, boolean connect)Append the given path geometry to this outline shape in reverse order.voidaddVertex(float[] coordsBuffer, int offset, int length, boolean onCurve)Add a vertex to the last open outline to the shape's tail.voidaddVertex(float x, float y, boolean onCurve)Add a 2DVertexto the last open outline to the shape's tail.voidaddVertex(float x, float y, float z, boolean onCurve)Add a 3DVertexto the last open outline to the shape's tail.voidaddVertex(int position, float[] coordsBuffer, int offset, int length, boolean onCurve)Add a vertex to the last open outline to the shape atposition.voidaddVertex(int position, float x, float y, boolean onCurve)Add a 2DVertexto the last open outline to the shape atposition.voidaddVertex(int position, float x, float y, float z, boolean onCurve)Add a 3DVertexto the last open outline to the shape atposition.voidaddVertex(int position, Vertex v)Adds a vertex to the last open outline to the shape atpositionvoidaddVertex(Vertex v)Adds 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 createdvoidclearCache()Clears cached triangulated data, i.e.voidclearOverrideConvex()Clears theisComplex()override done bysetOverrideConvex(boolean)voidcloseLastOutline(boolean closeTail)Closes the last outline in the shape.voidclosePath()Closes the current sub-path segment by drawing a straight line back to the coordinates of the last moveTo.intcompareTo(OutlineShape other)Compare two outline shape's Bounding Box size.voidcubicTo(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).booleanequals(Object obj)intgetAddedVerticeCount()Return the number of newly added vertices duringgetTriangles(VerticesState)while transforming the outlines toOutlineShape.VerticesState.QUADRATIC_NURBSand triangulation.com.jogamp.math.geom.AABBoxgetBounds()OutlinegetLastOutline()Get the last added outline to the list of outlines that define the shapeOutlinegetOutline(int position)Returns theOutlineatpositionintgetOutlineCount()Returns the number ofOutlines.OutlineShape.VerticesStategetOutlineState()Return the outline's vertices state,OutlineShape.VerticesStatefloatgetSharpness()Sharpness value, defaults toDEFAULT_SHARPNESS.ArrayList<Triangle>getTriangles(OutlineShape.VerticesState destinationType)Triangulate theOutlineShapegenerating a list of triangles, while#transformOutlines(VerticesState)beforehand.intgetVertexCount()Returns the totalvertex numberof allOutlines.ArrayList<Vertex>getVertices()Return list of concatenated vertices associated with allOutlines of this object.com.jogamp.math.geom.plane.WindinggetWindingOfLastOutline()Compute theWindingof thegetLastOutline()using theVectorUtil#area(ArrayList)function over all of its vertices.inthashCode()booleanisComplex()Returns cached or computed result if at least onepolylineofgetOutline(int)is a complex shape, seeOutline.isComplex().voidlineTo(float x, float y, float z)Add a line segment, intersecting the last point and the given point x/y (P1).voidmoveTo(float x, float y, float z)Start a new position for the next line segment at given point x/y (P1).voidprint(PrintStream out)static voidprintPerf(PrintStream out)voidquadTo(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).OutlineremoveOutline(int position)Removes theOutlineelement at the givenposition.voidsetIsQuadraticNurbs()Claim this outline's vertices are allOutlineShape.VerticesState.QUADRATIC_NURBS, hence no cubic transformations will be performed.voidsetOutline(int position, Outline outline)Replaces theOutlineelement at the givenposition.voidsetOverrideConvex(boolean convex)OverridesisComplex()using the given value instead of computing viaOutline.isComplex().voidsetSharpness(float s)Sets sharpness, defaults toDEFAULT_SHARPNESS.voidsetWindingOfLastOutline(com.jogamp.math.geom.plane.Winding enforced)Sets the enforcedWindingof thegetLastOutline().StringtoString()OutlineShapetransform(com.jogamp.math.geom.plane.AffineTransform t)Return a transformed instance with allOutlines 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
-
-
Method Detail
-
getAddedVerticeCount
public final int getAddedVerticeCount()
Return the number of newly added vertices duringgetTriangles(VerticesState)while transforming the outlines toOutlineShape.VerticesState.QUADRATIC_NURBSand 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 ofOutlines.
-
getVertexCount
public final int getVertexCount()
Returns the totalvertex numberof allOutlines.
-
getWindingOfLastOutline
public final com.jogamp.math.geom.plane.Winding getWindingOfLastOutline()
Compute theWindingof thegetLastOutline()using theVectorUtil#area(ArrayList)function over all of its vertices.- Returns:
Winding.CCWorWinding.CW
-
setWindingOfLastOutline
public final void setWindingOfLastOutline(com.jogamp.math.geom.plane.Winding enforced)
Sets the enforcedWindingof thegetLastOutline().
-
isComplex
public boolean isComplex()
Returns cached or computed result if at least onepolylineofgetOutline(int)is a complex shape, seeOutline.isComplex().A polyline with less than 3 elements is marked a simple shape for simplicity.
The result is cached.
- See Also:
setOverrideConvex(boolean),clearOverrideConvex()
-
setOverrideConvex
public void setOverrideConvex(boolean convex)
OverridesisComplex()using the given value instead of computing viaOutline.isComplex().- See Also:
clearOverrideConvex(),isComplex()
-
clearOverrideConvex
public void clearOverrideConvex()
Clears theisComplex()override done bysetOverrideConvex(boolean)- See Also:
setOverrideConvex(boolean),isComplex()
-
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
public final void addOutline(Outline outline) throws NullPointerException
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, IndexOutOfBoundsExceptionInsert 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
public final void addOutlineShape(OutlineShape outlineShape) throws NullPointerException
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, IndexOutOfBoundsExceptionReplaces 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
public final Outline removeOutline(int position) throws IndexOutOfBoundsException
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
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 theOutlineatposition- 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 2DVertexto 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 2DVertexto 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 3DVertexto 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 3DVertexto 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 copy of the first vertex or prepends a copy of the last vertex, depending on
closeTail.- Parameters:
closeTail- if true, a copy of the first vertex will be appended, otherwise a copy of the last vertex will be prepended.
-
addPath
public void addPath(com.jogamp.math.geom.plane.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- thePath2Fto 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(com.jogamp.math.geom.plane.Path2F.Iterator pathI, boolean connect)Add the givenPath2F.Iteratorto 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.Iteratorto 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(com.jogamp.math.geom.plane.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- thePath2Fto 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(com.jogamp.math.geom.plane.Path2F.Iterator pathI, boolean connect)Add the givenPath2F.Iteratorto 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.Iteratorto 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.math.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.math.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.math.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.math.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.- See Also:
Path2F.closePath(),addPath(com.jogamp.math.geom.plane.Path2F.Iterator, boolean)
-
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 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!
-
printPerf
public static void printPerf(PrintStream out)
-
getTriangles
public final ArrayList<Triangle> getTriangles(OutlineShape.VerticesState destinationType)
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
public final OutlineShape transform(com.jogamp.math.geom.plane.AffineTransform t)
Return a transformed instance with allOutlines 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:
compareToin interfaceComparable<OutlineShape>- See Also:
AABBox.getSize(),Comparable.compareTo(java.lang.Object)
-
getBounds
public final com.jogamp.math.geom.AABBox getBounds()
-
equals
public final boolean equals(Object obj)
-
print
public void print(PrintStream out)
-
-