2008-04-23 07:29:19 +00:00
|
|
|
|
|
|
|
#ifndef __POLYGON_H
|
|
|
|
#define __POLYGON_H
|
|
|
|
|
2008-04-25 07:04:09 +00:00
|
|
|
class SPolygon;
|
2008-06-21 10:18:20 +00:00
|
|
|
class SContour;
|
2008-05-22 10:28:28 +00:00
|
|
|
class SMesh;
|
2008-05-24 10:34:06 +00:00
|
|
|
class SBsp3;
|
2008-04-25 07:04:09 +00:00
|
|
|
|
2008-04-24 06:22:16 +00:00
|
|
|
class SEdge {
|
2008-04-23 07:29:19 +00:00
|
|
|
public:
|
2008-04-25 07:04:09 +00:00
|
|
|
int tag;
|
2008-04-24 06:22:16 +00:00
|
|
|
Vector a, b;
|
2008-05-30 08:01:19 +00:00
|
|
|
|
|
|
|
static SEdge From(Vector a, Vector b);
|
2008-04-24 06:22:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SEdgeList {
|
|
|
|
public:
|
2009-01-13 06:56:05 +00:00
|
|
|
List<SEdge> l;
|
2008-04-24 06:22:16 +00:00
|
|
|
|
2008-05-22 10:28:28 +00:00
|
|
|
void Clear(void);
|
|
|
|
void AddEdge(Vector a, Vector b);
|
2008-04-25 07:04:09 +00:00
|
|
|
bool AssemblePolygon(SPolygon *dest, SEdge *errorAt);
|
2008-06-21 10:18:20 +00:00
|
|
|
bool AssembleContour(Vector first, Vector last, SContour *dest,
|
|
|
|
SEdge *errorAt);
|
2009-01-23 03:30:30 +00:00
|
|
|
int AnyEdgeCrossings(Vector a, Vector b, Vector *pi=NULL);
|
2008-04-25 07:04:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SPoint {
|
|
|
|
public:
|
|
|
|
int tag;
|
2009-01-21 05:04:38 +00:00
|
|
|
|
|
|
|
static const int UNKNOWN = 0;
|
|
|
|
static const int NOT_EAR = 1;
|
|
|
|
static const int EAR = 2;
|
|
|
|
int ear;
|
|
|
|
|
2008-04-25 07:04:09 +00:00
|
|
|
Vector p;
|
2008-04-23 07:29:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SContour {
|
|
|
|
public:
|
2009-01-19 03:33:15 +00:00
|
|
|
int tag;
|
2009-01-21 05:04:38 +00:00
|
|
|
int timesEnclosed;
|
2009-01-22 10:02:46 +00:00
|
|
|
Vector xminPt;
|
2009-01-13 06:56:05 +00:00
|
|
|
List<SPoint> l;
|
2008-05-02 10:54:22 +00:00
|
|
|
|
2008-06-21 10:18:20 +00:00
|
|
|
void AddPoint(Vector p);
|
2008-05-02 10:54:22 +00:00
|
|
|
void MakeEdgesInto(SEdgeList *el);
|
2008-05-05 09:47:23 +00:00
|
|
|
void Reverse(void);
|
|
|
|
Vector ComputeNormal(void);
|
|
|
|
bool IsClockwiseProjdToNormal(Vector n);
|
|
|
|
bool ContainsPointProjdToNormal(Vector n, Vector p);
|
2008-06-12 04:36:33 +00:00
|
|
|
bool AllPointsInPlane(Vector n, double d, Vector *notCoplanarAt);
|
2008-08-14 08:28:25 +00:00
|
|
|
void OffsetInto(SContour *dest, double r);
|
2009-01-21 05:04:38 +00:00
|
|
|
void CopyInto(SContour *dest);
|
2009-01-22 10:02:46 +00:00
|
|
|
void FindPointWithMinX(void);
|
2009-01-21 05:04:38 +00:00
|
|
|
|
|
|
|
bool IsEar(int bp);
|
|
|
|
bool BridgeToContour(SContour *sc, SEdgeList *el, List<Vector> *vl);
|
|
|
|
void ClipEarInto(SMesh *m, int bp);
|
|
|
|
void UvTriangulateInto(SMesh *m);
|
2008-04-23 07:29:19 +00:00
|
|
|
};
|
|
|
|
|
2008-06-26 07:28:29 +00:00
|
|
|
typedef struct {
|
|
|
|
DWORD face;
|
|
|
|
int color;
|
|
|
|
} STriMeta;
|
|
|
|
|
2008-04-24 06:22:16 +00:00
|
|
|
class SPolygon {
|
|
|
|
public:
|
2009-01-13 06:56:05 +00:00
|
|
|
List<SContour> l;
|
2008-05-05 09:47:23 +00:00
|
|
|
Vector normal;
|
2008-04-25 07:04:09 +00:00
|
|
|
|
2008-05-05 09:47:23 +00:00
|
|
|
Vector ComputeNormal(void);
|
2008-04-25 07:04:09 +00:00
|
|
|
void AddEmptyContour(void);
|
2008-06-21 10:18:20 +00:00
|
|
|
int WindingNumberForPoint(Vector p);
|
2008-05-19 09:23:49 +00:00
|
|
|
bool ContainsPoint(Vector p);
|
2008-05-02 10:54:22 +00:00
|
|
|
void MakeEdgesInto(SEdgeList *el);
|
2008-05-05 09:47:23 +00:00
|
|
|
void FixContourDirections(void);
|
2008-05-22 10:28:28 +00:00
|
|
|
void TriangulateInto(SMesh *m);
|
2008-06-21 10:18:20 +00:00
|
|
|
void TriangulateInto(SMesh *m, STriMeta meta);
|
2008-04-25 07:04:09 +00:00
|
|
|
void Clear(void);
|
2008-06-12 04:36:33 +00:00
|
|
|
bool AllPointsInPlane(Vector *notCoplanarAt);
|
2009-01-23 03:30:30 +00:00
|
|
|
bool SelfIntersecting(Vector *intersectsAt);
|
2008-06-21 10:18:20 +00:00
|
|
|
bool IsEmpty(void);
|
|
|
|
Vector AnyPoint(void);
|
2008-08-14 08:28:25 +00:00
|
|
|
void OffsetInto(SPolygon *dest, double r);
|
2009-01-21 05:04:38 +00:00
|
|
|
void UvTriangulateInto(SMesh *m);
|
2008-05-21 03:58:14 +00:00
|
|
|
};
|
2008-05-19 09:23:49 +00:00
|
|
|
|
2008-05-21 03:58:14 +00:00
|
|
|
class STriangle {
|
|
|
|
public:
|
2008-05-30 06:09:41 +00:00
|
|
|
int tag;
|
|
|
|
STriMeta meta;
|
|
|
|
Vector a, b, c;
|
2009-01-19 10:37:10 +00:00
|
|
|
Vector an, bn, cn;
|
2008-05-23 10:05:07 +00:00
|
|
|
|
2008-05-30 06:09:41 +00:00
|
|
|
static STriangle From(STriMeta meta, Vector a, Vector b, Vector c);
|
2008-05-23 10:05:07 +00:00
|
|
|
Vector Normal(void);
|
2008-06-06 11:35:28 +00:00
|
|
|
void FlipNormal(void);
|
2008-07-02 04:32:24 +00:00
|
|
|
double MinAltitude(void);
|
2008-06-21 10:18:20 +00:00
|
|
|
int WindingNumberForPoint(Vector p);
|
2008-05-24 10:34:06 +00:00
|
|
|
bool ContainsPoint(Vector p);
|
2008-06-02 03:31:37 +00:00
|
|
|
bool ContainsPointProjd(Vector n, Vector p);
|
2008-05-21 03:58:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SBsp2 {
|
2008-05-22 10:28:28 +00:00
|
|
|
public:
|
2008-05-24 10:34:06 +00:00
|
|
|
Vector np; // normal to the plane
|
|
|
|
|
|
|
|
Vector no; // outer normal to the edge
|
|
|
|
double d;
|
2008-05-21 03:58:14 +00:00
|
|
|
SEdge edge;
|
2008-05-19 09:23:49 +00:00
|
|
|
|
2008-05-22 10:28:28 +00:00
|
|
|
SBsp2 *pos;
|
|
|
|
SBsp2 *neg;
|
|
|
|
|
|
|
|
SBsp2 *more;
|
2008-05-23 10:05:07 +00:00
|
|
|
|
2008-05-24 10:34:06 +00:00
|
|
|
static const int POS = 100, NEG = 101, COPLANAR = 200;
|
2008-05-24 23:10:00 +00:00
|
|
|
void InsertTriangleHow(int how, STriangle *tr, SMesh *m, SBsp3 *bsp3);
|
|
|
|
void InsertTriangle(STriangle *tr, SMesh *m, SBsp3 *bsp3);
|
2008-05-24 10:34:06 +00:00
|
|
|
Vector IntersectionWith(Vector a, Vector b);
|
|
|
|
SBsp2 *InsertEdge(SEdge *nedge, Vector nnp, Vector out);
|
2008-05-23 10:05:07 +00:00
|
|
|
static SBsp2 *Alloc(void);
|
2008-05-24 10:34:06 +00:00
|
|
|
|
|
|
|
void DebugDraw(Vector n, double d);
|
2008-04-24 06:22:16 +00:00
|
|
|
};
|
|
|
|
|
2008-05-21 03:58:14 +00:00
|
|
|
class SBsp3 {
|
2008-04-23 07:29:19 +00:00
|
|
|
public:
|
2008-05-23 10:05:07 +00:00
|
|
|
Vector n;
|
|
|
|
double d;
|
|
|
|
|
2008-05-21 03:58:14 +00:00
|
|
|
STriangle tri;
|
|
|
|
SBsp3 *pos;
|
|
|
|
SBsp3 *neg;
|
2008-05-19 09:23:49 +00:00
|
|
|
|
2008-05-21 03:58:14 +00:00
|
|
|
SBsp3 *more;
|
|
|
|
|
|
|
|
SBsp2 *edges;
|
2008-05-23 10:05:07 +00:00
|
|
|
|
|
|
|
static SBsp3 *Alloc(void);
|
|
|
|
static SBsp3 *FromMesh(SMesh *m);
|
|
|
|
|
|
|
|
Vector IntersectionWith(Vector a, Vector b);
|
|
|
|
|
|
|
|
static const int POS = 100, NEG = 101, COPLANAR = 200;
|
2008-05-24 23:10:00 +00:00
|
|
|
void InsertHow(int how, STriangle *str, SMesh *instead);
|
|
|
|
SBsp3 *Insert(STriangle *str, SMesh *instead);
|
2008-05-23 10:05:07 +00:00
|
|
|
|
2008-05-30 06:09:41 +00:00
|
|
|
void InsertConvexHow(int how, STriMeta meta, Vector *vertex, int n,
|
|
|
|
SMesh *instead);
|
|
|
|
SBsp3 *InsertConvex(STriMeta meta, Vector *vertex, int n, SMesh *instead);
|
2008-05-24 23:10:00 +00:00
|
|
|
|
|
|
|
void InsertInPlane(bool pos2, STriangle *tr, SMesh *m);
|
2008-05-24 10:34:06 +00:00
|
|
|
|
2008-05-23 10:05:07 +00:00
|
|
|
void DebugDraw(void);
|
2008-05-21 03:58:14 +00:00
|
|
|
};
|
2008-05-19 09:23:49 +00:00
|
|
|
|
2008-05-21 03:58:14 +00:00
|
|
|
class SMesh {
|
|
|
|
public:
|
2009-01-13 06:56:05 +00:00
|
|
|
List<STriangle> l;
|
2008-05-22 10:28:28 +00:00
|
|
|
|
2008-05-24 23:10:00 +00:00
|
|
|
bool flipNormal;
|
|
|
|
bool keepCoplanar;
|
|
|
|
bool atLeastOneDiscarded;
|
|
|
|
|
2008-05-22 10:28:28 +00:00
|
|
|
void Clear(void);
|
2008-05-24 12:23:25 +00:00
|
|
|
void AddTriangle(STriangle *st);
|
2008-05-30 06:09:41 +00:00
|
|
|
void AddTriangle(STriMeta meta, Vector a, Vector b, Vector c);
|
2008-06-21 10:18:20 +00:00
|
|
|
void AddTriangle(STriMeta meta, Vector n, Vector a, Vector b, Vector c);
|
2008-05-24 12:23:25 +00:00
|
|
|
void DoBounding(Vector v, Vector *vmax, Vector *vmin);
|
|
|
|
void GetBounding(Vector *vmax, Vector *vmin);
|
2008-05-24 23:10:00 +00:00
|
|
|
|
2008-05-26 03:39:45 +00:00
|
|
|
void Simplify(int start);
|
|
|
|
|
2008-05-24 23:10:00 +00:00
|
|
|
void AddAgainstBsp(SMesh *srcm, SBsp3 *bsp3);
|
2008-05-25 13:11:44 +00:00
|
|
|
void MakeFromUnion(SMesh *a, SMesh *b);
|
|
|
|
void MakeFromDifference(SMesh *a, SMesh *b);
|
2008-06-04 06:39:32 +00:00
|
|
|
bool MakeFromInterferenceCheck(SMesh *srca, SMesh *srcb, SMesh *errorAt);
|
2008-06-21 22:49:57 +00:00
|
|
|
void MakeFromCopy(SMesh *a);
|
2008-06-02 03:31:37 +00:00
|
|
|
|
|
|
|
DWORD FirstIntersectionWith(Point2d mp);
|
2008-04-23 07:29:19 +00:00
|
|
|
};
|
|
|
|
|
2008-05-27 09:52:36 +00:00
|
|
|
// A linked list of triangles
|
|
|
|
class STriangleLl {
|
|
|
|
public:
|
|
|
|
int tag;
|
2008-06-30 09:34:03 +00:00
|
|
|
STriangle *tri;
|
2008-05-27 09:52:36 +00:00
|
|
|
|
|
|
|
STriangleLl *next;
|
2008-07-06 07:56:24 +00:00
|
|
|
|
|
|
|
static STriangleLl *Alloc(void);
|
2008-05-27 09:52:36 +00:00
|
|
|
};
|
|
|
|
|
2008-07-06 07:56:24 +00:00
|
|
|
class SKdNode {
|
2008-05-27 09:52:36 +00:00
|
|
|
public:
|
2008-06-16 08:35:05 +00:00
|
|
|
static const int BY_X = 0;
|
|
|
|
static const int BY_Y = 1;
|
|
|
|
static const int BY_Z = 2;
|
2008-05-27 09:52:36 +00:00
|
|
|
int which;
|
|
|
|
double c;
|
|
|
|
|
2008-07-06 07:56:24 +00:00
|
|
|
SKdNode *gt;
|
|
|
|
SKdNode *lt;
|
2008-05-27 09:52:36 +00:00
|
|
|
|
2008-06-30 09:34:03 +00:00
|
|
|
STriangleLl *tris;
|
2008-07-06 07:56:24 +00:00
|
|
|
|
|
|
|
static SKdNode *Alloc(void);
|
|
|
|
static SKdNode *From(SMesh *m);
|
|
|
|
static SKdNode *From(STriangleLl *tll, int which);
|
|
|
|
|
|
|
|
void AddTriangle(STriangle *tr);
|
|
|
|
void MakeMeshInto(SMesh *m);
|
|
|
|
void ClearTags(void);
|
|
|
|
|
|
|
|
void FindEdgeOn(Vector a, Vector b, int *n, int *nOther,
|
|
|
|
STriMeta m, int cnt);
|
2008-07-08 06:30:13 +00:00
|
|
|
void MakeCertainEdgesInto(SEdgeList *sel, bool emphasized);
|
2008-05-27 09:52:36 +00:00
|
|
|
};
|
|
|
|
|
2008-04-23 07:29:19 +00:00
|
|
|
#endif
|
2008-04-24 06:22:16 +00:00
|
|
|
|