11#ifndef JAU_GAMP_GRAPH_OUTLINESHAPE_HPP_
12#define JAU_GAMP_GRAPH_OUTLINESHAPE_HPP_
28 using namespace jau::math;
29 using namespace jau::math::geom;
30 using namespace jau::enums;
31 using jau::math::geom::plane::AffineTransform;
129 mutable bool m_complexShape;
139 : m_outlineVertCapacity(capacity),
141 m_outlines(m_outlineVertCapacity),
144 m_addedVertexCount(0),
145 m_complexShape(false),
149 m_outlines.emplace_back(outlineVertCapacity);
154 constexpr const Vec3f&
normal() const noexcept {
return m_normal; }
159 m_normal.cross((p1 - p0), (p2 - p0)).normalize();
163 if(m_outlines.size() > 0){
164 const VertexList& v = m_outlines[0].vertices();
166 setNormal(v[0].coord(), v[1].coord(), v[2].coord());
178 constexpr float sharpness() const noexcept {
return m_sharpness; }
182 if( m_sharpness != s ) {
191 m_outlines.emplace_back(m_outlineVertCapacity);
196 m_addedVertexCount = 0;
197 m_complexShape =
false;
216 void validateBoundingBox() const noexcept {
219 for (
const auto & m_outline : m_outlines) {
220 m_bbox.
resize(m_outline.bounds());
227 validateBoundingBox();
232 bool empty() const noexcept {
return m_outlines.empty(); }
236 return m_outlines.size();
242 for(
const Outline& o : m_outlines) {
243 res += o.vertexCount();
260 return m_outlines[m_outlines.size()-1];
268 return m_outlines[m_outlines.size()-1];
301 m_complexShape =
false;
303 for(
size_type i=0; i<sz && !m_complexShape; ++i) {
308 return m_complexShape;
340 m_outlines.emplace_back(m_outlineVertCapacity);
371 if( m_outlines.size() == position ) {
377 m_outlines[position-1] =
outline;
379 m_bbox.resize(
outline.bounds());
386 m_outlines.insert(position,
outline);
388 m_bbox.resize(
outline.bounds());
418 m_outlines.insert(position,
outline);
431 m_outlines.erase(position);
447 m_bbox.resize(v.
coord());
464 m_bbox.resize(v.
coord());
479 void addVertex(
float x,
float y,
float z,
bool onCurve) {
578 void quadTo(
float x1,
float y1,
float z1,
float x2,
float y2,
float z2) {
599 void cubicTo(
float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float x3,
float y3,
float z3) {
661 return newOutlineShape;
670 for(
Vertex& v : o.vertices()) {
671 v.coord().z = ( v.coord().z * -1.0f ) + zoffset;
684 const float otherSize = other.bounds().size();
687 }
else if(thisSize < otherSize){
707 if(
bounds() != o.bounds() ) {
711 if(
outline(i) != o.outline(i) ) {
734 void checkOverlaps();
736 void cleanupOutlines();
737 uint32_t generateVertexIds();
745 void triangulateImpl();
775 std::string r(
"OutlineShape[");
776 r.append(
"dirty ").append(
to_string(m_dirtyBits))
777 .append(
", outlines ").append(std::to_string(
outlineCount()))
778 .append(
", vertices ").append(std::to_string(
vertexCount()))
constexpr size_type addedVertexCount() const noexcept
Return the number of newly added vertices during getTriangles(VerticesState) while transforming the o...
const VertexList & getVertices()
Return list of concatenated vertices associated with all Outlines of this object.
size_type outlineCount() const noexcept
Returns the number of Outlines.
JAU_MAKE_BITFIELD_ENUM_STRING_MEMBER(DirtyBits, bounds, vertices, triangles, convex, convexOverride)
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.
void addVertex(float x, float y, float z, bool onCurve)
Add a 3D Vertex to the last open outline to the shape's tail.
const AABBox3f & bounds() const noexcept
void setSharpness(float s) noexcept
Sets sharpness, defaults to DEFAULT_SHARPNESS.
void clearCache() noexcept
Clears cached triangulated data, i.e.
static constexpr size_type max_elements
byte-size uint32_t limit: 1'073'741'823 (FIXME: Adjust to actual type, i.e. Vertex = 2x Vec3f?...
VertexState outlineState() const noexcept
void setOverrideConvex(bool convex) noexcept
Overrides isComplex() using the given value instead of computing via Outline#isComplex().
bool isComplex() const noexcept
Returns cached or computed result if at least one polyline outline(size_type) is a complex shape,...
int compareTo(const OutlineShape &other) const noexcept
Compare two outline shape's Bounding Box size.
OutlineList & outlines() noexcept
Winding windingOfLastOutline() const noexcept
Compute the Winding of the getLastOutline() using the VectorUtil#area(ArrayList) function over all of...
@ triangles
<Modified shape, requires to update the vertices and triangles, here: vertices
@ convexOverride
<Modified shape, requires to update the convex determination
@ convex
<Modified shape, requires to update the vertices and triangles, here: triangulation.
void setNormal(Point3f p0, Point3f p1, Point3f p2) noexcept
Set the normal using given 3 points.
JAU_MAKE_ENUM_STRING_MEMBER(VertexState, quadratic_nurbs)
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).
void removeOutline(size_type position)
Removes the Outline element at the given position.
void addVertex(float x, float y, bool onCurve)
Add a 2D Vertex to the last open outline to the shape's tail.
const Outline & lastOutline() const noexcept
Get the last added outline to the list of outlines that define the shape.
const OutlineList & outlines() const noexcept
void addVertex(const Vec2f &v, bool onCurve)
Add a 2D Vertex to the last open outline to the shape's tail.
size_type vertexCount() const noexcept
Returns the total vertex number of all Outlines.
const Outline & outline(size_type i) const noexcept
std::string toString() const noexcept
void addVertex(const Vec3f &v, bool onCurve)
Add a 3D Vertex to the last open outline to the shape's tail.
void setNormal() noexcept
Set the normal using first outline's 3 points.
constexpr Vec3f & normal() noexcept
Writing the normal vector, optionally used by tesselator to add (interleaved) normals.
void closeLastOutline(bool closeTail)
Closes the last outline in the shape.
OutlineShape(size_type capacity, size_type outlineVertCapacity)
constexpr bool verticesDirty() const noexcept
void addOutline(size_type position, const Outline &outline)
Insert the Outline element at the given position.
void setWindingOfLastOutline(Winding enforced)
Sets the enforced Winding of the getLastOutline().
constexpr void reserve(size_type newCapacity)
void setIsQuadraticNurbs() noexcept
Claim this outline's vertices are all VertexState::quadratic_nurbs, hence no cubic transformations wi...
constexpr bool operator==(const OutlineShape &o) const noexcept
void clear()
Clears all data and reset all states as if this instance was newly created.
bool empty() 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 markClean(DirtyBits flags) noexcept
void addOutlineShape(const OutlineShape &outlineShape)
Insert the OutlineShape elements of type Outline, .
constexpr const Vec3f & normal() const noexcept
Normal vector, optionally used by tesselator to add (interleaved) normals.
void moveTo(float x, float y, float z)
Start a new position for the next line segment at given point x/y (P1).
void clearOverrideConvex() noexcept
Clears the isComplex() override done by setOverrideConvex(boolean).
void closePath()
Closes the current sub-path segment by drawing a straight line back to the coordinates of the last mo...
void addVertex(size_type position, const Vertex &v)
Adds a vertex to the last open outline to the shape at position @endiliteral.
static constexpr float DEFAULT_SHARPNESS
Initial sharpness() value, which can be modified via setSharpness(float).
const TriangleRefList & getTriangles(VertexState destinationType=VertexState::quadratic_nurbs)
Triangulate the OutlineShape generating a list of triangles, while transformOutlines(VerticesState) b...
constexpr float sharpness() const noexcept
Sharpness value, defaults to DEFAULT_SHARPNESS.
constexpr bool trianglesDirty() const noexcept
Outline & lastOutline() noexcept
Get the last added outline to the list of outlines that define the shape.
OutlineShape transform(const AffineTransform &t) const
Return a transformed instance with all Outlines are copied and transformed.
Outline & outline(size_type i) noexcept
OutlineShape flipFace(float zoffset=0) const
Returns a copy of this instance with normal() pointing to the opposite direction and all outlines() v...
void lineTo(float x, float y, float z)
Add a line segment, intersecting the last point and the given point x/y (P1).
void addEmptyOutline()
Add a new empty Outline to the end of this shape's outline list.
void setOutline(size_type position, const Outline &outline)
Replaces the Outline element at the given position.
void addOutline(const Outline &outline)
Appends the Outline element to the end, ensuring a clean tail.
void addVertex(const Vertex &v)
Adds a vertex to the last open outline to the shape's tail.
constexpr DirtyBits dirtyBits() const noexcept
Define a single continuous stroke by control vertices.
void addVertex(const Vertex &vertex)
Appends a vertex to the outline loop/strip.
bool isComplex() const noexcept
Returns cached or computed result if whether this Outlines polyline is a complex shape.
constexpr bool empty() const noexcept
void setWinding(Winding enforce)
Sets Winding to this outline.
Winding getWinding() const noexcept
Returns the cached or computed winding of this Outlines polyline using VectorUtil#area(ArrayList).
constexpr const Vec3f & coord() const noexcept
constexpr size_type size() const noexcept
Like std::vector::size().
Axis Aligned Bounding Box.
constexpr AABBox3f & reset() noexcept
Reset this box to the inverse low/high, allowing the next resize(float, float, float) command to hit.
constexpr float size() const noexcept
Get the size of this aabbox3f where the size is represented by the length of the vector between low a...
AABBox3f & resize(const AABBox3f &o) noexcept
Resize the aabbox3f to encapsulate another AABox.
constexpr bool is_set(const E mask, const E bits) noexcept
constexpr bool equals2(const T &a, const T &b, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
Returns true if both values are equal, i.e.
jau::darray< Vertex, uint32_t > VertexList
jau::darray< Outline, uint32_t > OutlineList
jau::darray< TriangleRef, uint32_t > TriangleRefList
std::string_view to_string(const math_error_t v) noexcept
Returns std::string_view representation of math_error_t.