123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- #ifndef TRIANGULATOR_H
- #define TRIANGULATOR_H
- #include "core/list.h"
- #include "core/math/vector2.h"
- #include "core/set.h"
- #define TRIANGULATOR_CCW 1
- #define TRIANGULATOR_CW -1
- class TriangulatorPoly {
- protected:
- Vector2 *points;
- long numpoints;
- bool hole;
- public:
-
- TriangulatorPoly();
- ~TriangulatorPoly();
- TriangulatorPoly(const TriangulatorPoly &src);
- TriangulatorPoly& operator=(const TriangulatorPoly &src);
-
- long GetNumPoints() {
- return numpoints;
- }
- bool IsHole() {
- return hole;
- }
- void SetHole(bool hole) {
- this->hole = hole;
- }
- Vector2 &GetPoint(long i) {
- return points[i];
- }
- Vector2 *GetPoints() {
- return points;
- }
- Vector2& operator[] (int i) {
- return points[i];
- }
-
- void Clear();
-
- void Init(long numpoints);
-
- void Triangle(Vector2 &p1, Vector2 &p2, Vector2 &p3);
-
- void Invert();
-
-
-
-
-
- int GetOrientation();
-
-
-
-
- void SetOrientation(int orientation);
- };
- class TriangulatorPartition {
- protected:
- struct PartitionVertex {
- bool isActive;
- bool isConvex;
- bool isEar;
- Vector2 p;
- real_t angle;
- PartitionVertex *previous;
- PartitionVertex *next;
- };
- struct MonotoneVertex {
- Vector2 p;
- long previous;
- long next;
- };
- struct VertexSorter{
- mutable MonotoneVertex *vertices;
- bool operator() (long index1, long index2) const;
- };
- struct Diagonal {
- long index1;
- long index2;
- };
-
- struct DPState {
- bool visible;
- real_t weight;
- long bestvertex;
- };
-
- struct DPState2 {
- bool visible;
- long weight;
- List<Diagonal> pairs;
- };
-
- struct ScanLineEdge {
- mutable long index;
- Vector2 p1;
- Vector2 p2;
-
- bool operator< (const ScanLineEdge & other) const;
- bool IsConvex(const Vector2& p1, const Vector2& p2, const Vector2& p3) const;
- };
-
- bool IsConvex(Vector2& p1, Vector2& p2, Vector2& p3);
- bool IsReflex(Vector2& p1, Vector2& p2, Vector2& p3);
- bool IsInside(Vector2& p1, Vector2& p2, Vector2& p3, Vector2 &p);
- bool InCone(Vector2 &p1, Vector2 &p2, Vector2 &p3, Vector2 &p);
- bool InCone(PartitionVertex *v, Vector2 &p);
- int Intersects(Vector2 &p11, Vector2 &p12, Vector2 &p21, Vector2 &p22);
- Vector2 Normalize(const Vector2 &p);
- real_t Distance(const Vector2 &p1, const Vector2 &p2);
-
- void UpdateVertexReflexity(PartitionVertex *v);
- void UpdateVertex(PartitionVertex *v,PartitionVertex *vertices, long numvertices);
-
- void UpdateState(long a, long b, long w, long i, long j, DPState2 **dpstates);
- void TypeA(long i, long j, long k, PartitionVertex *vertices, DPState2 **dpstates);
- void TypeB(long i, long j, long k, PartitionVertex *vertices, DPState2 **dpstates);
-
- bool Below(Vector2 &p1, Vector2 &p2);
- void AddDiagonal(MonotoneVertex *vertices, long *numvertices, long index1, long index2,
- char *vertextypes, Set<ScanLineEdge>::Element **edgeTreeIterators,
- Set<ScanLineEdge> *edgeTree, long *helpers);
-
- int TriangulateMonotone(TriangulatorPoly *inPoly, List<TriangulatorPoly> *triangles);
- public:
-
-
-
-
-
-
-
-
-
-
- int RemoveHoles(List<TriangulatorPoly> *inpolys, List<TriangulatorPoly> *outpolys);
-
-
-
-
-
-
-
-
- int Triangulate_EC(TriangulatorPoly *poly, List<TriangulatorPoly> *triangles);
-
-
-
-
-
-
-
-
-
-
- int Triangulate_EC(List<TriangulatorPoly> *inpolys, List<TriangulatorPoly> *triangles);
-
-
-
-
-
-
-
-
- int Triangulate_OPT(TriangulatorPoly *poly, List<TriangulatorPoly> *triangles);
-
-
-
-
-
-
-
-
- int Triangulate_MONO(TriangulatorPoly *poly, List<TriangulatorPoly> *triangles);
-
-
-
-
-
-
-
-
-
- int Triangulate_MONO(List<TriangulatorPoly> *inpolys, List<TriangulatorPoly> *triangles);
-
-
-
-
-
-
-
-
-
- int MonotonePartition(List<TriangulatorPoly> *inpolys, List<TriangulatorPoly> *monotonePolys);
-
-
-
-
-
-
-
-
-
-
-
- int ConvexPartition_HM(TriangulatorPoly *poly, List<TriangulatorPoly> *parts);
-
-
-
-
-
-
-
-
-
-
-
-
- int ConvexPartition_HM(List<TriangulatorPoly> *inpolys, List<TriangulatorPoly> *parts);
-
-
-
-
-
-
-
-
-
- int ConvexPartition_OPT(TriangulatorPoly *poly, List<TriangulatorPoly> *parts);
- };
- #endif
|