20 #define GTE_CDT_REQUIRE(c) { if (!(c)) { Trap(); return false; } } 21 #define GTE_CDT_FAILURE { Trap(); return false; } 22 #define GTE_CDT_REQUIRE_RET(c, r) { if (!(c)) { Trap(); return r; } } 23 #define GTE_CDT_FAILURE_RET(r) { Trap(); return r; } 28 template <
typename InputType,
typename ComputeType>
56 bool Insert(std::array<int, 2>
const& edge, std::vector<int>& outEdge);
60 bool Insert(std::array<int, 2>
const& edge,
int v0Triangle,
61 std::vector<int>& outEdge);
65 std::vector<int>& outEdge);
70 std::vector<int>& outEdge);
75 std::vector<std::array<int, 2>>
const& lBoundary,
76 std::vector<std::array<int, 2>>
const& rBoundary);
79 std::vector<std::array<int, 2>>
const& lBoundary,
80 int i0,
int i1,
int a0, std::vector<int>& polygon);
83 std::vector<std::array<int, 2>>
const& rBoundary,
84 int i0,
int i1,
int a0, std::vector<int>& polygon);
86 int SelectSplit(std::vector<std::array<int, 2>>
const& boundary,
int i0,
116 int needAdjVIndex)
const;
121 bool Connect(
int tri,
int adj,
int v0,
int v1);
129 bool BuildLink(
int v,
int vTriangle, std::list<std::pair<int,int>>& link,
139 template <
typename InputType,
typename ComputeType>
144 template <
typename InputType,
typename ComputeType>
151 template <
typename InputType,
typename ComputeType>
159 template <
typename InputType,
typename ComputeType>
161 std::array<int, 2>
const& edge, std::vector<int>& outEdge)
163 int v0 = edge[0],
v1 = edge[1];
176 return Insert(edge, v0Triangle, outEdge);
182 template <
typename InputType,
typename ComputeType>
184 std::array<int, 2>
const& edge,
int v0Triangle, std::vector<int>& outEdge)
188 int v0 = edge[0],
v1 = edge[1];
189 std::list<std::pair<int, int>> link;
196 auto item = link.begin();
199 int vNext = indices[(item->second + 1) % 3];
201 while (item != link.end())
211 if (
Dot(ctv1 - ctv0, ctvnext - ctv0) > (ComputeType)0)
226 if (++item == link.end())
231 vNext = indices[(item->second + 1) % 3];
236 int vPrev = indices[(item->second + 2) % 3];
238 while (item != link.end())
248 if (
Dot(ctv1 - ctv0, ctvprev - ctv0) > (ComputeType)0)
263 if (++item == link.end())
269 vPrev = indices[(item->second + 2) % 3];
285 template <
typename InputType,
typename ComputeType>
287 int v0,
int v1,
int vOther, std::vector<int>& outEdge)
289 outEdge.push_back(v0);
293 return Insert({ vOther, v1 }, tri, outEdge);
298 outEdge.push_back(v1);
303 template <
typename InputType,
typename ComputeType>
305 int v0,
int v1,
int vNext,
int vPrev, std::vector<int>& outEdge)
311 std::vector<int> polygon;
321 std::vector<std::array<int, 2>> lBoundary, rBoundary;
322 std::array<int, 2> binfo;
324 polygon.push_back(tri);
326 lBoundary.push_back({
v0, -1 });
329 lBoundary.push_back(binfo);
331 rBoundary.push_back({
v0, -1 });
334 rBoundary.push_back(binfo);
342 int adj = iinfo[0], vOpposite = iinfo[1];
347 polygon.push_back(tri);
358 lBoundary.push_back(binfo);
362 rBoundary.push_back(binfo);
367 outEdge.push_back(v0);
368 return Insert({ vOpposite, v1 }, tri, outEdge);
380 lBoundary.push_back(binfo);
387 rBoundary.push_back(binfo);
396 template <
typename InputType,
typename ComputeType>
398 std::vector<int>& polygon,
399 std::vector<std::array<int, 2>>
const& lBoundary,
400 std::vector<std::array<int, 2>>
const& rBoundary)
403 static_cast<int>(lBoundary.size()) - 1, -1, polygon);
406 static_cast<int>(rBoundary.size()) - 1, -1, polygon);
408 int v0 = lBoundary.front()[0];
409 int v1 = lBoundary.back()[0];
414 template <
typename InputType,
typename ComputeType>
416 std::vector<std::array<int, 2>>
const& lBoundary,
int i0,
int i1,
int a0,
417 std::vector<int>& polygon)
422 int v0 = lBoundary[i0][0];
423 int v1 = lBoundary[i1][0];
434 int v2 = lBoundary[i2][0];
437 int tri = polygon.back();
455 template <
typename InputType,
typename ComputeType>
457 std::vector<std::array<int, 2>>
const& rBoundary,
int i0,
int i1,
int a0,
458 std::vector<int>& polygon)
463 int v0 = rBoundary[i0][0];
464 int v1 = rBoundary[i1][0];
475 int v2 = rBoundary[i2][0];
478 int tri = polygon.back();
496 template <
typename InputType,
typename ComputeType>
498 std::vector<std::array<int, 2>>
const& boundary,
int i0,
int i1)
const 513 int v0 = boundary[i0][0];
514 int v1 = boundary[i1][0];
515 int v2 = boundary[i2][0];
517 for (
int i = i2 + 1; i < i1; ++i)
531 template <
typename InputType,
typename ComputeType>
533 int v1,
int v2)
const 543 ComputeType sqrlen10 =
Dot(V1mV0, V1mV0);
544 ComputeType dot =
Dot(V1mV0, V2mV0);
549 ComputeType sqrlen20 =
Dot(V2mV0, V2mV0);
550 psd = sqrlen10 * sqrlen20;
555 dot =
Dot(V1mV0, V2mV1);
558 ComputeType sqrlen21 =
Dot(V2mV1, V2mV1);
559 psd = sqrlen10 * sqrlen21;
564 psd = sqrlen10 * dot * dot;
571 template <
typename InputType,
typename ComputeType>
583 for (
int j = 0; j < 3; ++j)
592 for (
int j0 = 2, j1 = 0; j1 < 3; j0 = j1++)
594 if (this->
mQuery.
ToLine(v, indices[j0], indices[j1]) > 0)
598 std::array<int, 3> adjacencies;
600 int adj = adjacencies[j0];
612 template <
typename InputType,
typename ComputeType>
619 for (indexOfV = 0; indexOfV < 3; ++indexOfV)
621 if (v == indices[indexOfV])
631 template <
typename InputType,
typename ComputeType>
635 std::array<int, 2> error = { -2, -2 };
641 for (
int v2Index = 0; v2Index < 3; ++v2Index)
644 if (v2 != v0 && v2 != v1)
658 template <
typename InputType,
typename ComputeType>
662 std::array<int, 2> error = { -2, -2 };
666 return{ needBndVertex, adj };
669 template <
typename InputType,
typename ComputeType>
690 template <
typename InputType,
typename ComputeType>
692 int vTriangle, std::list<std::pair<int, int>>& link,
bool& isOpen)
const 697 link.push_front(std::make_pair(vTriangle, vStartIndex));
701 int tri = vTriangle, vIndex = vStartIndex;
702 std::array<int, 3> adjacencies;
706 int adjPrev = adjacencies[(vIndex + 2) % 3];
709 if (adjPrev != vTriangle)
714 link.push_back(std::make_pair(tri, vIndex));
731 vIndex = vStartIndex;
735 int adjNext = adjacencies[vIndex];
741 link.push_front(std::make_pair(tri, vIndex));
757 template <
typename InputType,
typename ComputeType>
#define GTE_CDT_REQUIRE(c)
bool ProcessInterior(int tri, int v0, int v1, int vNext, int vPrev, std::vector< int > &outEdge)
std::vector< int > const & GetAdjacencies() const
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
#define GTE_CDT_FAILURE_RET(r)
int RetriangulateRRecurse(std::vector< std::array< int, 2 >> const &rBoundary, int i0, int i1, int a0, std::vector< int > &polygon)
bool Connect(int tri, int adj, int v0, int v1)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
PrimalQuery2< ComputeType > mQuery
std::array< int, 2 > GetAdjBoundary(int tri, int needBndVertex, int needAdjVIndex) const
virtual ~ConstrainedDelaunay2()
ComputeType ComputePSD(int v0, int v1, int v2) const
bool Insert(std::array< int, 2 > const &edge, std::vector< int > &outEdge)
int GetIndexOfVertex(int tri, int v) const
bool operator()(int numVertices, Vector2< InputType > const *vertices, InputType epsilon)
std::vector< int > mIndices
std::vector< int > mDuplicates
bool Retriangulate(std::vector< int > &polygon, std::vector< std::array< int, 2 >> const &lBoundary, std::vector< std::array< int, 2 >> const &rBoundary)
bool ProcessCoincident(int tri, int v0, int v1, int vOther, std::vector< int > &outEdge)
int ToLine(int i, int v0, int v1) const
GLsizei GLenum const void * indices
int RetriangulateLRecurse(std::vector< std::array< int, 2 >> const &lBoundary, int i0, int i1, int a0, std::vector< int > &polygon)
int GetLinkTriangle(int v) const
#define LogError(message)
Real DotPerp(Vector2< Real > const &v0, Vector2< Real > const &v1)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLfloat GLfloat GLfloat v2
std::vector< Vector2< ComputeType > > mComputeVertices
#define GTE_CDT_REQUIRE_RET(c, r)
std::vector< int > mAdjacencies
bool BuildLink(int v, int vTriangle, std::list< std::pair< int, int >> &link, bool &isOpen) const
bool operator()(int numVertices, Vector2< InputType > const *vertices, InputType epsilon)
std::array< int, 2 > GetAdjInterior(int tri, int v0, int v1) const
int SelectSplit(std::vector< std::array< int, 2 >> const &boundary, int i0, int i1) const
std::vector< int > const & GetIndices() const