Gamp v0.0.7-36-g24b1eb6
Gamp: Graphics, Audio, Multimedia and Processing
|
A Generic shape objects which is defined by a list of Outlines. More...
#include <OutlineShape.hpp>
Public Types | |
enum class | DirtyBits : uint16_t { none = 0 , bounds = 1 << 0 , vertices = 1 << 1 , triangles = 1 << 2 , convex = 1 << 3 , convexOverride = 1 << 4 } |
typedef uint32_t | size_type |
enum class | VertexState : uint16_t { undefined = 0 , quadratic_nurbs = 1 } |
Public Member Functions | |
OutlineShape () | |
OutlineShape (size_type capacity, size_type outlineVertCapacity) | |
constexpr size_type | addedVertexCount () const noexcept |
Return the number of newly added vertices during getTriangles(VerticesState) while transforming the outlines to VerticesState::QUADRATIC_NURBS and triangulation. | |
void | addEmptyOutline () |
Add a new empty Outline to the end of this shape's outline list. | |
void | addOutline (const Outline &outline) |
Appends the Outline element to the end, ensuring a clean tail. | |
void | addOutline (size_type position, const Outline &outline) |
Insert the Outline element at the given position . | |
void | addOutlineShape (const OutlineShape &outlineShape) |
Insert the OutlineShape elements of type Outline , . | |
void | addVertex (const Vec2f &v, bool onCurve) |
Add a 2D Vertex to the last open outline to the shape's tail. | |
void | addVertex (const Vec3f &v, bool onCurve) |
Add a 3D Vertex to the last open outline to the shape's tail. | |
void | addVertex (const Vertex &v) |
Adds a vertex to the last open outline to the shape's tail. | |
void | addVertex (float x, float y, bool onCurve) |
Add a 2D Vertex to the last open outline to the shape's tail. | |
void | addVertex (float x, float y, float z, bool onCurve) |
Add a 3D Vertex to the last open outline to the shape's tail. | |
void | addVertex (size_type position, const Vertex &v) |
Adds a vertex to the last open outline to the shape at position @endiliteral. | |
void | addVertex (size_type position, float x, float y, float z, bool onCurve) |
Add a 3D Vertex to the last open outline to the shape at position . | |
const AABBox3f & | bounds () const noexcept |
void | clear () |
Clears all data and reset all states as if this instance was newly created. | |
void | clearCache () noexcept |
Clears cached triangulated data, i.e. | |
void | clearOverrideConvex () noexcept |
Clears the isComplex() override done by setOverrideConvex(boolean) . | |
void | closeLastOutline (bool 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 (const OutlineShape &other) const noexcept |
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). | |
constexpr DirtyBits | dirtyBits () const noexcept |
bool | empty () const noexcept |
OutlineShape | flipFace (float zoffset=0) const |
Returns a copy of this instance with normal() and all outlines() vertices()'s z-axis sign-flipped, used to generate a back-face from a front-face shape. | |
const TriangleRefList & | getTriangles (VertexState destinationType=VertexState::quadratic_nurbs) |
Triangulate the OutlineShape generating a list of triangles, while transformOutlines(VerticesState) beforehand. | |
const VertexList & | getVertices () |
Return list of concatenated vertices associated with all Outline s of this object. | |
bool | isComplex () const noexcept |
Returns cached or computed result if at least one polyline outline(size_type) is a complex shape, see Outline::isComplex(). | |
JAU_MAKE_BITFIELD_ENUM_STRING_MEMBER (DirtyBits, bounds, vertices, triangles, convex, convexOverride) | |
JAU_MAKE_ENUM_STRING_MEMBER (VertexState, quadratic_nurbs) | |
const Outline & | lastOutline () const noexcept |
Get the last added outline to the list of outlines that define the shape. | |
Outline & | lastOutline () noexcept |
Get the last added outline to the list of outlines that define the shape. | |
void | lineTo (float x, float y, float z) |
Add a line segment, intersecting the last point and the given point x/y (P1). | |
void | markClean (DirtyBits flags) noexcept |
void | moveTo (float x, float y, float z) |
Start a new position for the next line segment at given point x/y (P1). | |
constexpr const Vec3f & | normal () const noexcept |
Normal vector, optionally used by tesselator to add (interleaved) normals. | |
constexpr Vec3f & | normal () noexcept |
Writing the normal vector, optionally used by tesselator to add (interleaved) normals. | |
constexpr bool | operator== (const OutlineShape &o) const noexcept |
const Outline & | outline (size_type i) const noexcept |
Outline & | outline (size_type i) noexcept |
size_type | outlineCount () const noexcept |
Returns the number of Outline s. | |
const OutlineList & | outlines () const noexcept |
OutlineList & | outlines () noexcept |
VertexState | outlineState () const noexcept |
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). | |
void | removeOutline (size_type position) |
Removes the Outline element at the given position . | |
constexpr void | reserve (size_type newCapacity) |
void | setIsQuadraticNurbs () noexcept |
Claim this outline's vertices are all VertexState::quadratic_nurbs, hence no cubic transformations will be performed. | |
void | setOutline (size_type position, const Outline &outline) |
Replaces the Outline element at the given position . | |
void | setOverrideConvex (bool convex) noexcept |
Overrides isComplex() using the given value instead of computing via Outline#isComplex() . | |
void | setSharpness (float s) noexcept |
Sets sharpness, defaults to DEFAULT_SHARPNESS. | |
void | setWindingOfLastOutline (Winding enforced) |
Sets the enforced Winding of the getLastOutline() . | |
constexpr float | sharpness () const noexcept |
Sharpness value, defaults to DEFAULT_SHARPNESS. | |
std::string | toString () const noexcept |
OutlineShape | transform (const AffineTransform &t) const |
Return a transformed instance with all Outline s are copied and transformed. | |
constexpr bool | trianglesDirty () const noexcept |
size_type | vertexCount () const noexcept |
Returns the total vertex number of all Outline s. | |
constexpr bool | verticesDirty () const noexcept |
Winding | windingOfLastOutline () const noexcept |
Compute the Winding of the getLastOutline() using the VectorUtil#area(ArrayList) function over all of its vertices. | |
Static Public Attributes | |
static constexpr float | DEFAULT_SHARPNESS = 0.5f |
Initial sharpness() value, which can be modified via setSharpness(float). | |
static constexpr size_type | max_elements = std::numeric_limits<uint32_t>::max() / sizeof(uint32_t) |
byte-size int32_t limit: 536'870'911 (FIXME: Adjust to actual type, i.e. Vertex = 2x Vec3f?) | |
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
closeLastOutline(boolean)
or closePath()
} to enforce Winding::CCW, orExample 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.
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:
Definition at line 100 of file OutlineShape.hpp.
typedef uint32_t gamp::graph::OutlineShape::size_type |
Definition at line 102 of file OutlineShape.hpp.
|
strong |
Definition at line 110 of file OutlineShape.hpp.
|
strong |
Enumerator | |
---|---|
undefined | |
quadratic_nurbs |
Definition at line 120 of file OutlineShape.hpp.
|
inline |
|
inline |
Definition at line 139 of file OutlineShape.hpp.
gamp::graph::OutlineShape::JAU_MAKE_BITFIELD_ENUM_STRING_MEMBER | ( | DirtyBits | , |
bounds | , | ||
vertices | , | ||
triangles | , | ||
convex | , | ||
convexOverride | ) |
gamp::graph::OutlineShape::JAU_MAKE_ENUM_STRING_MEMBER | ( | VertexState | , |
quadratic_nurbs | ) |
|
inlineconstexprnoexcept |
Normal vector, optionally used by tesselator to add (interleaved) normals.
Definition at line 155 of file OutlineShape.hpp.
|
inlineconstexprnoexcept |
Writing the normal vector, optionally used by tesselator to add (interleaved) normals.
Definition at line 157 of file OutlineShape.hpp.
|
inlineconstexprnoexcept |
Return the number of newly added vertices during getTriangles(VerticesState) while transforming the outlines to VerticesState::QUADRATIC_NURBS and triangulation.
Definition at line 164 of file OutlineShape.hpp.
|
inlineconstexprnoexcept |
Sharpness value, defaults to DEFAULT_SHARPNESS.
Definition at line 167 of file OutlineShape.hpp.
|
inlinenoexcept |
Sets sharpness, defaults to DEFAULT_SHARPNESS.
Definition at line 170 of file OutlineShape.hpp.
|
inline |
Clears all data and reset all states as if this instance was newly created.
Definition at line 178 of file OutlineShape.hpp.
|
inlinenoexcept |
Clears cached triangulated data, i.e.
getTriangles(VerticesState)
and getVertices()
.
Definition at line 191 of file OutlineShape.hpp.
|
inlineconstexpr |
Definition at line 197 of file OutlineShape.hpp.
|
inlineconstexprnoexcept |
Definition at line 199 of file OutlineShape.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlinenoexcept |
Definition at line 202 of file OutlineShape.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Returns the number of Outline
s.
Definition at line 224 of file OutlineShape.hpp.
|
inlinenoexcept |
Returns the total vertex number
of all Outline
s.
Definition at line 229 of file OutlineShape.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 238 of file OutlineShape.hpp.
Definition at line 241 of file OutlineShape.hpp.
|
inlinenoexcept |
Get the last added outline to the list of outlines that define the shape.
Definition at line 248 of file OutlineShape.hpp.
|
inlinenoexcept |
Get the last added outline to the list of outlines that define the shape.
Definition at line 256 of file OutlineShape.hpp.
|
inlinenoexcept |
Compute the Winding
of the getLastOutline()
using the VectorUtil#area(ArrayList)
function over all of its vertices.
Winding#CCW
or Winding#CW
Definition at line 264 of file OutlineShape.hpp.
|
inline |
Sets the enforced Winding
of the getLastOutline()
.
Definition at line 271 of file OutlineShape.hpp.
|
inlinenoexcept |
Returns cached or computed result if at least one polyline
outline(size_type) is a complex shape, see Outline::isComplex().
A polyline with less than 3 elements is marked a simple shape for simplicity.
The result is cached.
Definition at line 286 of file OutlineShape.hpp.
|
inlinenoexcept |
Overrides isComplex()
using the given value instead of computing via Outline#isComplex()
.
Definition at line 304 of file OutlineShape.hpp.
|
inlinenoexcept |
Clears the isComplex()
override done by setOverrideConvex(boolean)
.
Definition at line 314 of file OutlineShape.hpp.
|
inline |
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
Definition at line 327 of file OutlineShape.hpp.
|
inline |
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.
outline | Outline object to be added |
NullPointerException | if the Outline element is null |
Definition at line 343 of file OutlineShape.hpp.
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.
NullPointerException | if the Outline element is null |
IndexOutOfBoundsException | if position is out of range (position < 0 || position > getOutlineNumber()) |
Definition at line 359 of file OutlineShape.hpp.
|
inline |
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.
outlineShape | OutlineShape elements to be added. |
NullPointerException | if the OutlineShape is null |
IndexOutOfBoundsException | if position is out of range (position < 0 || position > getOutlineNumber()) |
Definition at line 390 of file OutlineShape.hpp.
Replaces the Outline
element at the given position
.
Sets the bounding box dirty, hence a next call to getBounds()
will validate it.
NullPointerException | if the Outline element is null |
IndexOutOfBoundsException | if position is out of range (position < 0 || position >= getOutlineNumber()) |
Definition at line 406 of file OutlineShape.hpp.
|
inline |
Removes the Outline
element at the given position
.
Sets the bounding box dirty, hence a next call to getBounds()
will validate it.
position | of the to be removed Outline |
IndexOutOfBoundsException | if position is out of range (position < 0 || position >= getOutlineNumber()) |
Definition at line 418 of file OutlineShape.hpp.
|
inline |
Adds a vertex to the last open outline to the shape's tail.
v | the vertex to be added to the OutlineShape |
Definition at line 432 of file OutlineShape.hpp.
Adds a vertex to the last open outline to the shape at position @endiliteral.
position | index within the last open outline, at which the vertex will be added |
v | the vertex to be added to the OutlineShape |
Definition at line 449 of file OutlineShape.hpp.
|
inline |
Add a 3D Vertex
to the last open outline to the shape's tail.
x | the x coordinate |
y | the y coordinate |
z | the z coordinate |
onCurve | flag if this vertex is on the curve or defines a curved region of the shape around this vertex. |
Definition at line 468 of file OutlineShape.hpp.
|
inline |
Add a 3D Vertex
to the last open outline to the shape's tail.
v | the Vec3f coordinates |
onCurve | flag if this vertex is on the curve or defines a curved region of the shape around this vertex. |
Definition at line 479 of file OutlineShape.hpp.
|
inline |
Add a 2D Vertex
to the last open outline to the shape's tail.
x | the x coordinate |
y | the y coordinate |
onCurve | flag if this vertex is on the curve or defines a curved region of the shape around this vertex. |
Definition at line 491 of file OutlineShape.hpp.
|
inline |
Add a 2D Vertex
to the last open outline to the shape's tail.
v | the Vec2f coordinates |
onCurve | flag if this vertex is on the curve or defines a curved region of the shape around this vertex. |
Definition at line 502 of file OutlineShape.hpp.
|
inline |
Add a 3D Vertex
to the last open outline to the shape at position
.
position | index within the last open outline, at which the vertex will be added |
x | the x coordinate |
y | the y coordniate |
z | the z coordinate |
onCurve | flag if this vertex is on the curve or defines a curved region of the shape around this vertex. |
Definition at line 516 of file OutlineShape.hpp.
|
inline |
Start a new position for the next line segment at given point x/y (P1).
x | point (P1) |
y | point (P1) |
z | point (P1) |
Definition at line 530 of file OutlineShape.hpp.
|
inline |
Add a line segment, intersecting the last point and the given point x/y (P1).
x | final point (P1) |
y | final point (P1) |
z | final point (P1) |
Definition at line 550 of file OutlineShape.hpp.
|
inline |
Add a quadratic curve segment, intersecting the last point and the second given point x2/y2 (P2).
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) |
Definition at line 567 of file OutlineShape.hpp.
|
inline |
Add a cubic Bézier curve segment, intersecting the last point and the second given point x3/y3 (P3).
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) |
Definition at line 588 of file OutlineShape.hpp.
|
inline |
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
.
closeTail | if true, a copy of the first vertex will be appended, otherwise a copy of the last vertex will be prepended. |
Definition at line 604 of file OutlineShape.hpp.
|
inline |
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.
Definition at line 615 of file OutlineShape.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
Claim this outline's vertices are all VertexState::quadratic_nurbs, hence no cubic transformations will be performed.
Definition at line 628 of file OutlineShape.hpp.
|
inline |
Return a transformed instance with all Outline
s are copied and transformed.
Note: Triangulated data is lost in returned instance!
Definition at line 639 of file OutlineShape.hpp.
|
inline |
Returns a copy of this instance with normal() and all outlines() vertices()'s z-axis sign-flipped, used to generate a back-face from a front-face shape.
Definition at line 650 of file OutlineShape.hpp.
|
inlinenoexcept |
Compare two outline shape's Bounding Box size.
Definition at line 666 of file OutlineShape.hpp.
|
inlineconstexprnoexcept |
o
equals bounds and vertices in the same order Definition at line 681 of file OutlineShape.hpp.
|
inline |
Return list of concatenated vertices associated with all Outline
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!
Definition at line 871 of file OutlineShape.hpp.
|
inline |
Triangulate the OutlineShape
generating a list of triangles, while transformOutlines(VerticesState)
beforehand.
Triangles are cached until marked dirty.
Definition at line 936 of file OutlineShape.hpp.
|
inlinenoexcept |
Definition at line 964 of file OutlineShape.hpp.
|
staticconstexpr |
byte-size int32_t limit: 536'870'911 (FIXME: Adjust to actual type, i.e. Vertex = 2x Vec3f?)
Definition at line 105 of file OutlineShape.hpp.
|
staticconstexpr |
Initial sharpness() value, which can be modified via setSharpness(float).
Definition at line 108 of file OutlineShape.hpp.