11#ifndef JAU_GAMP_GRAPH_TESS_IMPL_CDTesselator2D_HPP_
12#define JAU_GAMP_GRAPH_TESS_IMPL_CDTesselator2D_HPP_
29namespace gamp::graph::tess::impl {
31 using namespace jau::math;
32 using namespace jau::math::geom;
33 using namespace gamp::graph;
45 class CDTriangulator2D {
47 impl::LoopRefList loops;
50 size_t m_addedVerticeCount;
56 constexpr CDTriangulator2D() noexcept
57 : complexShape(false) { reset(); }
59 constexpr void setComplexShape(
bool complex)
noexcept { complexShape = complex; }
61 constexpr void reset() noexcept {
63 m_addedVerticeCount = 0;
67 constexpr size_t getAddedVerticeCount() const noexcept {
return m_addedVerticeCount; }
69 constexpr static bool FixedWindingRule = impl::Loop::FixedWindingRule;
71 void addCurve(
TriangleRefList& sink, Outline& polyline,
float sharpness) {
72 impl::LoopRef loop = getContainerLoop(polyline);
76 if constexpr (!FixedWindingRule) {
84 impl::GraphOutlineRef outline = impl::GraphOutline::create(polyline);
85 impl::GraphOutlineRef innerPoly = extractBoundaryTriangles(sink, outline,
false , sharpness);
87 if (innerPoly->graphPoints().size() >= 3) {
88 loop = impl::Loop::createBoundary(innerPoly, complexShape);
90 loops.push_back(loop);
122 impl::GraphOutlineRef outline = impl::GraphOutline::create(polyline);
123 impl::GraphOutlineRef innerPoly = extractBoundaryTriangles(sink, outline,
true , sharpness);
125 loop->addConstraintCurveHole(innerPoly);
130 size_t loopsSize = loops.size();
133 for (
size_t i = 0; i < loopsSize; i++) {
134 impl::LoopRef &loop = loops[i];
136 size = loop->computeLoopSize();
138 while (!loop->isSimplex()) {
141 if (numTries > size) {
142 tri = loop->cut(
false);
145 tri = loop->cut(
true);
151 tri->id() = m_maxTriID++;
159 if (numTries > size * 2) {
169 tri->id() = m_maxTriID++;
179 impl::GraphOutlineRef extractBoundaryTriangles(
TriangleRefList& sink,
const impl::GraphOutlineRef& outline,
bool hole,
float sharpness) {
180 impl::GraphOutlineRef innerOutline = impl::GraphOutline::create();
181 const impl::GraphVertexRefList& outVertices = outline->graphPoints();
182 size_t size = outVertices.size();
184 for (
size_t i = 0; i < size; i++) {
185 const impl::GraphVertexRef &gv1 = outVertices[i];
186 const impl::GraphVertexRef& gv0 = outVertices[(i + size - 1) % size];
187 const impl::GraphVertexRef& gv2 = outVertices[(i + 1) % size];
189 if (!gv1->vertex().onCurve()) {
190 Vertex v0 = gv0->vertex().clone();
191 Vertex v2 = gv2->vertex().clone();
192 Vertex v1 = gv1->vertex().clone();
193 m_addedVerticeCount += 3;
195 boundaryVertices.
put(0,
true);
196 boundaryVertices.
put(1,
true);
197 boundaryVertices.
put(2,
true);
199 gv0->setBoundaryContained(
true);
200 gv1->setBoundaryContained(
true);
201 gv2->setBoundaryContained(
true);
204 if (hole || holeLike) {
208 innerOutline->addVertex(gv1);
220 t->id() = m_maxTriID++;
226 if( !gv2->vertex().onCurve() || !gv0->vertex().onCurve() ) {
227 gv1->setBoundaryContained(
true);
229 innerOutline->addVertex(gv1);
238 impl::LoopRef getContainerLoop(
const Outline& polyline)
const noexcept {
239 size_t count = loops.size();
242 for (
const impl::LoopRef &loop : loops) {
243 for (
size_t j = 0;
j < vertices.
size(); ++
j) {
244 if (loop->checkInside(vertices[j])) {
constexpr const VertexList & vertices() 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).
static TriangleRef create(const Vertex &v1, const Vertex &v2, const Vertex &v3, const tribit_t &boundaryVertices) noexcept
jau::bitfield_t< uint8_t, 3 > tribit_t
constexpr const Vec3f & texCoord() const noexcept
constexpr const Vec3f & coord() const noexcept
constexpr bool put(size_type bitpos, bool v) noexcept
Writes the bit value v to position bitpos into this storage.
constexpr size_type size() const noexcept
Like std::vector::size().
constexpr void push_back(const value_type &x)
Like std::vector::push_back(), copy.
#define jau_WARN_PRINT(...)
Use for unconditional warning messages, prefix '[elapsed_time] Warning @ FILE:LINE FUNC: '.
#define jau_PLAIN_PRINT(printPrefix, fmt,...)
Use for unconditional plain messages, prefix '[elapsed_time] ' if printPrefix == true.
jau::darray< Vertex, uint32_t > VertexList
std::shared_ptr< Triangle > TriangleRef
jau::darray< TriangleRef, uint32_t > TriangleRefList
constexpr bool is2DCCW(const Vec3f &a, const Vec3f &b, const Vec3f &c) noexcept
Check if points are in ccw order.
std::string_view to_string(const math_error_t v) noexcept
Returns std::string_view representation of math_error_t.
@ j
intmax_t or uintmax_t integer
void print_backtrace(const bool skip_anon_frames, const jau::snsize_t max_frames=-1, const jau::snsize_t skip_frames=2) noexcept
Prints the de-mangled backtrace string separated by newline excluding this function to stderr,...