2009-01-10 08:18:54 +00:00
|
|
|
|
|
|
|
#ifndef __SURFACE_H
|
|
|
|
#define __SURFACE_H
|
|
|
|
|
2009-01-19 03:33:15 +00:00
|
|
|
// Utility functions, Bernstein polynomials of order 1-3 and their derivatives.
|
2009-01-15 03:55:42 +00:00
|
|
|
double Bernstein(int k, int deg, double t);
|
2009-01-19 03:33:15 +00:00
|
|
|
double BernsteinDerivative(int k, int deg, double t);
|
2009-01-15 03:55:42 +00:00
|
|
|
|
2009-02-01 05:13:43 +00:00
|
|
|
// Utility data structure, a two-dimensional BSP to accelerate polygon
|
|
|
|
// operations.
|
|
|
|
class SBspUv {
|
|
|
|
public:
|
|
|
|
Point2d a, b;
|
|
|
|
|
|
|
|
SBspUv *pos;
|
|
|
|
SBspUv *neg;
|
|
|
|
|
|
|
|
SBspUv *more;
|
|
|
|
|
|
|
|
static const int INSIDE = 100;
|
|
|
|
static const int OUTSIDE = 200;
|
|
|
|
static const int EDGE_PARALLEL = 300;
|
|
|
|
static const int EDGE_ANTIPARALLEL = 400;
|
|
|
|
static const int EDGE_OTHER = 500;
|
|
|
|
|
|
|
|
static SBspUv *Alloc(void);
|
|
|
|
static SBspUv *From(SEdgeList *el);
|
|
|
|
|
|
|
|
Point2d IntersectionWith(Point2d a, Point2d b);
|
|
|
|
SBspUv *InsertEdge(Point2d a, Point2d b);
|
|
|
|
int ClassifyPoint(Point2d p, Point2d eb);
|
|
|
|
int ClassifyEdge(Point2d ea, Point2d eb);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Now the data structures to represent a shell of trimmed rational polynomial
|
|
|
|
// surfaces.
|
|
|
|
|
2009-01-19 10:37:10 +00:00
|
|
|
class SShell;
|
|
|
|
|
2009-01-15 03:55:42 +00:00
|
|
|
class hSSurface {
|
|
|
|
public:
|
|
|
|
DWORD v;
|
|
|
|
};
|
|
|
|
|
|
|
|
class hSCurve {
|
|
|
|
public:
|
|
|
|
DWORD v;
|
|
|
|
};
|
2009-01-10 08:18:54 +00:00
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
// Stuff for rational polynomial curves, of degree one to three. These are
|
|
|
|
// our inputs.
|
2009-01-19 03:51:00 +00:00
|
|
|
class SBezier {
|
2009-01-14 05:10:42 +00:00
|
|
|
public:
|
2009-01-17 05:28:49 +00:00
|
|
|
int tag;
|
2009-01-14 05:10:42 +00:00
|
|
|
int deg;
|
|
|
|
Vector ctrl[4];
|
|
|
|
double weight[4];
|
|
|
|
|
2009-01-19 03:33:15 +00:00
|
|
|
Vector PointAt(double t);
|
2009-01-15 03:55:42 +00:00
|
|
|
Vector Start(void);
|
|
|
|
Vector Finish(void);
|
|
|
|
void MakePwlInto(List<Vector> *l);
|
2009-01-19 10:37:10 +00:00
|
|
|
void MakePwlInto(List<Vector> *l, Vector offset);
|
|
|
|
void MakePwlWorker(List<Vector> *l, double ta, double tb, Vector offset);
|
2009-01-14 05:10:42 +00:00
|
|
|
|
2009-01-25 11:52:29 +00:00
|
|
|
void GetBoundingProjd(Vector u, Vector orig, double *umin, double *umax);
|
2009-01-17 05:28:49 +00:00
|
|
|
void Reverse(void);
|
|
|
|
|
2009-01-23 03:30:30 +00:00
|
|
|
SBezier TransformedBy(Vector t, Quaternion q);
|
|
|
|
|
2009-01-19 03:51:00 +00:00
|
|
|
static SBezier From(Vector p0, Vector p1, Vector p2, Vector p3);
|
|
|
|
static SBezier From(Vector p0, Vector p1, Vector p2);
|
|
|
|
static SBezier From(Vector p0, Vector p1);
|
2009-01-14 05:10:42 +00:00
|
|
|
};
|
|
|
|
|
2009-01-19 03:51:00 +00:00
|
|
|
class SBezierList {
|
2009-01-14 05:10:42 +00:00
|
|
|
public:
|
2009-01-19 03:51:00 +00:00
|
|
|
List<SBezier> l;
|
2009-01-15 03:55:42 +00:00
|
|
|
|
|
|
|
void Clear(void);
|
2009-01-14 05:10:42 +00:00
|
|
|
};
|
|
|
|
|
2009-01-19 03:51:00 +00:00
|
|
|
class SBezierLoop {
|
2009-01-17 05:28:49 +00:00
|
|
|
public:
|
2009-01-19 03:51:00 +00:00
|
|
|
List<SBezier> l;
|
2009-01-17 05:28:49 +00:00
|
|
|
|
2009-01-19 03:33:15 +00:00
|
|
|
inline void Clear(void) { l.Clear(); }
|
|
|
|
void Reverse(void);
|
|
|
|
void MakePwlInto(SContour *sc);
|
2009-01-25 11:52:29 +00:00
|
|
|
void GetBoundingProjd(Vector u, Vector orig, double *umin, double *umax);
|
2009-01-17 05:28:49 +00:00
|
|
|
|
2009-01-19 03:51:00 +00:00
|
|
|
static SBezierLoop FromCurves(SBezierList *spcl,
|
|
|
|
bool *allClosed, SEdge *errorAt);
|
2009-01-17 05:28:49 +00:00
|
|
|
};
|
|
|
|
|
2009-01-19 03:51:00 +00:00
|
|
|
class SBezierLoopSet {
|
2009-01-19 03:33:15 +00:00
|
|
|
public:
|
2009-01-19 03:51:00 +00:00
|
|
|
List<SBezierLoop> l;
|
2009-01-19 03:33:15 +00:00
|
|
|
Vector normal;
|
2009-01-19 10:37:10 +00:00
|
|
|
Vector point;
|
2009-01-19 03:33:15 +00:00
|
|
|
|
2009-01-19 03:51:00 +00:00
|
|
|
static SBezierLoopSet From(SBezierList *spcl, SPolygon *poly,
|
|
|
|
bool *allClosed, SEdge *errorAt);
|
2009-01-19 03:33:15 +00:00
|
|
|
|
2009-01-25 11:52:29 +00:00
|
|
|
void GetBoundingProjd(Vector u, Vector orig, double *umin, double *umax);
|
2009-01-19 03:33:15 +00:00
|
|
|
void Clear(void);
|
|
|
|
};
|
2009-01-14 05:10:42 +00:00
|
|
|
|
|
|
|
// Stuff for the surface trim curves: piecewise linear
|
2009-01-10 08:18:54 +00:00
|
|
|
class SCurve {
|
|
|
|
public:
|
|
|
|
hSCurve h;
|
|
|
|
|
2009-01-27 07:59:58 +00:00
|
|
|
hSCurve newH; // when merging with booleans
|
|
|
|
bool interCurve; // it's a newly-calculated intersection
|
2009-01-25 11:52:29 +00:00
|
|
|
|
2009-01-19 10:37:10 +00:00
|
|
|
bool isExact;
|
|
|
|
SBezier exact;
|
|
|
|
|
2009-01-17 05:28:49 +00:00
|
|
|
List<Vector> pts;
|
2009-01-19 10:37:10 +00:00
|
|
|
|
2009-01-27 07:59:58 +00:00
|
|
|
hSSurface surfA;
|
|
|
|
hSSurface surfB;
|
|
|
|
|
2009-01-25 11:52:29 +00:00
|
|
|
static SCurve FromTransformationOf(SCurve *a, Vector t, Quaternion q);
|
2009-02-01 05:13:43 +00:00
|
|
|
SCurve MakeCopySplitAgainst(SShell *agnstA, SShell *agnstB);
|
2009-01-23 03:30:30 +00:00
|
|
|
|
2009-01-19 10:37:10 +00:00
|
|
|
void Clear(void);
|
2009-01-10 08:18:54 +00:00
|
|
|
};
|
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
// A segment of a curve by which a surface is trimmed: indicates which curve,
|
|
|
|
// by its handle, and the starting and ending points of our segment of it.
|
|
|
|
// The vector out points out of the surface; it, the surface outer normal,
|
|
|
|
// and a tangent to the beginning of the curve are all orthogonal.
|
2009-01-10 08:18:54 +00:00
|
|
|
class STrimBy {
|
|
|
|
public:
|
|
|
|
hSCurve curve;
|
2009-01-25 09:19:59 +00:00
|
|
|
bool backwards;
|
|
|
|
// If a trim runs backwards, then start and finish still correspond to
|
|
|
|
// the actual start and finish, but they appear in reverse order in
|
|
|
|
// the referenced curve.
|
2009-01-10 08:18:54 +00:00
|
|
|
Vector start;
|
|
|
|
Vector finish;
|
2009-01-19 10:37:10 +00:00
|
|
|
|
2009-01-25 09:19:59 +00:00
|
|
|
static STrimBy STrimBy::EntireCurve(SShell *shell, hSCurve hsc, bool bkwds);
|
2009-01-10 08:18:54 +00:00
|
|
|
};
|
|
|
|
|
2009-02-01 13:01:28 +00:00
|
|
|
// An intersection point between a line and a surface
|
|
|
|
class SInter {
|
|
|
|
public:
|
|
|
|
Vector p;
|
|
|
|
hSSurface surface;
|
2009-02-09 12:40:48 +00:00
|
|
|
Vector surfNormal; // of the intersecting surface, at pinter
|
|
|
|
bool onEdge; // pinter is on edge of trim poly
|
2009-02-01 13:01:28 +00:00
|
|
|
};
|
|
|
|
|
2009-01-19 10:37:10 +00:00
|
|
|
// A rational polynomial surface in Bezier form.
|
2009-01-10 08:18:54 +00:00
|
|
|
class SSurface {
|
|
|
|
public:
|
|
|
|
hSSurface h;
|
|
|
|
|
2009-01-25 09:19:59 +00:00
|
|
|
int color;
|
|
|
|
DWORD face;
|
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
int degm, degn;
|
2009-01-10 08:18:54 +00:00
|
|
|
Vector ctrl[4][4];
|
2009-01-14 05:10:42 +00:00
|
|
|
double weight[4][4];
|
2009-01-10 08:18:54 +00:00
|
|
|
|
2009-01-15 03:55:42 +00:00
|
|
|
List<STrimBy> trim;
|
2009-01-17 05:28:49 +00:00
|
|
|
|
2009-02-01 05:13:43 +00:00
|
|
|
// For testing whether a point (u, v) on the surface lies inside the trim
|
|
|
|
SBspUv *bsp;
|
2009-01-27 07:59:58 +00:00
|
|
|
|
2009-01-19 03:51:00 +00:00
|
|
|
static SSurface FromExtrusionOf(SBezier *spc, Vector t0, Vector t1);
|
2009-01-25 11:52:29 +00:00
|
|
|
static SSurface FromPlane(Vector pt, Vector u, Vector v);
|
2009-01-23 03:30:30 +00:00
|
|
|
static SSurface FromTransformationOf(SSurface *a, Vector t, Quaternion q,
|
|
|
|
bool includingTrims);
|
2009-01-17 05:28:49 +00:00
|
|
|
|
2009-02-01 05:13:43 +00:00
|
|
|
SSurface MakeCopyTrimAgainst(SShell *against, SShell *parent, SShell *into,
|
2009-01-25 11:52:29 +00:00
|
|
|
int type, bool opA);
|
|
|
|
void TrimFromEdgeList(SEdgeList *el);
|
2009-02-01 05:13:43 +00:00
|
|
|
void IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
|
|
|
|
SShell *into);
|
2009-02-01 13:01:28 +00:00
|
|
|
void AllPointsIntersecting(Vector a, Vector b, List<SInter> *l);
|
2009-01-25 11:52:29 +00:00
|
|
|
|
2009-01-19 03:33:15 +00:00
|
|
|
void ClosestPointTo(Vector p, double *u, double *v);
|
|
|
|
Vector PointAt(double u, double v);
|
2009-01-19 10:37:10 +00:00
|
|
|
void TangentsAt(double u, double v, Vector *tu, Vector *tv);
|
2009-01-19 03:33:15 +00:00
|
|
|
Vector NormalAt(double u, double v);
|
2009-01-27 07:59:58 +00:00
|
|
|
void GetAxisAlignedBounding(Vector *ptMax, Vector *ptMin);
|
2009-02-09 12:40:48 +00:00
|
|
|
bool CoincidentWithPlane(Vector n, double d);
|
|
|
|
bool CoincidentWith(SSurface *ss, bool sameNormal);
|
2009-01-19 03:33:15 +00:00
|
|
|
|
2009-01-19 10:37:10 +00:00
|
|
|
void TriangulateInto(SShell *shell, SMesh *sm);
|
2009-01-23 03:30:30 +00:00
|
|
|
void MakeEdgesInto(SShell *shell, SEdgeList *sel, bool asUv);
|
2009-02-01 05:13:43 +00:00
|
|
|
void MakeClassifyingBsp(SShell *shell);
|
2009-01-19 10:37:10 +00:00
|
|
|
|
2009-02-16 12:05:08 +00:00
|
|
|
void Reverse(void);
|
2009-01-19 10:37:10 +00:00
|
|
|
void Clear(void);
|
2009-01-10 08:18:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SShell {
|
|
|
|
public:
|
2009-01-14 05:10:42 +00:00
|
|
|
IdList<SCurve,hSCurve> curve;
|
2009-01-10 08:18:54 +00:00
|
|
|
IdList<SSurface,hSSurface> surface;
|
2009-01-17 05:28:49 +00:00
|
|
|
|
2009-01-25 09:19:59 +00:00
|
|
|
void MakeFromExtrusionOf(SBezierLoopSet *sbls, Vector t0, Vector t1,
|
|
|
|
int color);
|
2009-01-25 11:52:29 +00:00
|
|
|
|
2009-01-23 03:30:30 +00:00
|
|
|
void MakeFromUnionOf(SShell *a, SShell *b);
|
|
|
|
void MakeFromDifferenceOf(SShell *a, SShell *b);
|
2009-01-25 11:52:29 +00:00
|
|
|
static const int AS_UNION = 10;
|
|
|
|
static const int AS_DIFFERENCE = 11;
|
|
|
|
static const int AS_INTERSECT = 12;
|
|
|
|
void MakeFromBoolean(SShell *a, SShell *b, int type);
|
2009-02-01 05:13:43 +00:00
|
|
|
void CopyCurvesSplitAgainst(SShell *agnstA, SShell *agnstB, SShell *into);
|
2009-01-25 11:52:29 +00:00
|
|
|
void CopySurfacesTrimAgainst(SShell *against, SShell *into, int t, bool a);
|
2009-01-27 07:59:58 +00:00
|
|
|
void MakeIntersectionCurvesAgainst(SShell *against, SShell *into);
|
2009-02-01 05:13:43 +00:00
|
|
|
void MakeClassifyingBsps(void);
|
2009-02-01 13:01:28 +00:00
|
|
|
void AllPointsIntersecting(Vector a, Vector b, List<SInter> *il);
|
2009-02-09 12:40:48 +00:00
|
|
|
void MakeCoincidentEdgesInto(SSurface *proto, bool sameNormal,
|
|
|
|
SEdgeList *el);
|
2009-01-27 07:59:58 +00:00
|
|
|
void CleanupAfterBoolean(void);
|
2009-01-25 11:52:29 +00:00
|
|
|
|
2009-02-01 13:01:28 +00:00
|
|
|
static const int INSIDE = 100;
|
|
|
|
static const int OUTSIDE = 200;
|
2009-02-09 12:40:48 +00:00
|
|
|
static const int ON_PARALLEL = 300;
|
|
|
|
static const int ON_ANTIPARALLEL = 400;
|
|
|
|
int ClassifyPoint(Vector p, Vector out);
|
2009-02-01 13:01:28 +00:00
|
|
|
|
|
|
|
|
2009-01-23 03:30:30 +00:00
|
|
|
void MakeFromCopyOf(SShell *a);
|
|
|
|
void MakeFromTransformationOf(SShell *a, Vector trans, Quaternion q);
|
2009-01-19 10:37:10 +00:00
|
|
|
|
|
|
|
void TriangulateInto(SMesh *sm);
|
2009-01-23 03:30:30 +00:00
|
|
|
void MakeEdgesInto(SEdgeList *sel);
|
2009-01-19 10:37:10 +00:00
|
|
|
void Clear(void);
|
2009-01-10 08:18:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|