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-27 13:04:36 +00:00
|
|
|
class SSurface;
|
|
|
|
|
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);
|
2009-03-15 23:04:45 +00:00
|
|
|
bool Equals(SBezier *b);
|
2009-01-15 03:55:42 +00:00
|
|
|
void MakePwlInto(List<Vector> *l);
|
2009-03-15 23:04:45 +00:00
|
|
|
void MakePwlWorker(List<Vector> *l, double ta, double tb);
|
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-02-27 13:04:36 +00:00
|
|
|
// In a Boolean, C = A op B. The curves in A and B get copied into C, and
|
|
|
|
// therefore must get new hSCurves assigned. For the curves in A and B,
|
|
|
|
// we use newH to record their new handle in C.
|
|
|
|
hSCurve newH;
|
|
|
|
static const int FROM_A = 100;
|
|
|
|
static const int FROM_B = 200;
|
|
|
|
static const int FROM_INTERSECTION = 300;
|
|
|
|
int source;
|
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-27 13:04:36 +00:00
|
|
|
SCurve MakeCopySplitAgainst(SShell *agnstA, SShell *agnstB,
|
|
|
|
SSurface *srfA, SSurface *srfB);
|
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:
|
2009-02-27 13:04:36 +00:00
|
|
|
int tag;
|
2009-02-01 13:01:28 +00:00
|
|
|
Vector p;
|
2009-02-27 13:04:36 +00:00
|
|
|
SSurface *srf;
|
|
|
|
hSSurface hsrf;
|
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-03-15 23:04:45 +00:00
|
|
|
// Same as newH for the curves; record what a surface gets renamed to
|
|
|
|
// when I copy things over.
|
|
|
|
hSSurface newH;
|
|
|
|
|
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-27 13:04:36 +00:00
|
|
|
void AddExactIntersectionCurve(SBezier *sb, SSurface *srfB,
|
2009-02-23 10:06:02 +00:00
|
|
|
SShell *agnstA, SShell *agnstB, SShell *into);
|
2009-03-19 17:40:11 +00:00
|
|
|
|
2009-03-08 10:59:57 +00:00
|
|
|
typedef struct {
|
|
|
|
int tag;
|
|
|
|
Point2d p;
|
|
|
|
} Inter;
|
|
|
|
void WeightControlPoints(void);
|
|
|
|
void UnWeightControlPoints(void);
|
|
|
|
void CopyRowOrCol(bool row, int this_ij, SSurface *src, int src_ij);
|
|
|
|
void BlendRowOrCol(bool row, int this_ij, SSurface *a, int a_ij,
|
|
|
|
SSurface *b, int b_ij);
|
2009-03-14 20:01:20 +00:00
|
|
|
double DepartureFromCoplanar(void);
|
2009-03-08 10:59:57 +00:00
|
|
|
void SplitInHalf(bool byU, SSurface *sa, SSurface *sb);
|
2009-02-23 10:06:02 +00:00
|
|
|
void AllPointsIntersecting(Vector a, Vector b,
|
2009-03-19 17:40:11 +00:00
|
|
|
List<SInter> *l,
|
|
|
|
bool seg, bool trimmed, bool inclTangent);
|
2009-03-08 10:59:57 +00:00
|
|
|
void AllPointsIntersectingUntrimmed(Vector a, Vector b,
|
|
|
|
int *cnt, int *level,
|
|
|
|
List<Inter> *l, bool segment,
|
|
|
|
SSurface *sorig);
|
2009-01-25 11:52:29 +00:00
|
|
|
|
2009-02-27 13:04:36 +00:00
|
|
|
void ClosestPointTo(Vector p, double *u, double *v, bool converge=true);
|
|
|
|
bool PointIntersectingLine(Vector p0, Vector p1, double *u, double *v);
|
|
|
|
void PointOnSurfaces(SSurface *s1, SSurface *s2, double *u, double *v);
|
2009-01-19 03:33:15 +00:00
|
|
|
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-03-19 17:40:11 +00:00
|
|
|
bool LineEntirelyOutsideBbox(Vector a, Vector b, bool segment);
|
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-02-23 10:06:02 +00:00
|
|
|
bool IsExtrusion(SBezier *of, Vector *along);
|
2009-03-15 23:04:45 +00:00
|
|
|
bool IsCylinder(Vector *center, Vector *axis, double *r,
|
|
|
|
Vector *start, Vector *finish);
|
2009-01-19 03:33:15 +00:00
|
|
|
|
2009-01-19 10:37:10 +00:00
|
|
|
void TriangulateInto(SShell *shell, SMesh *sm);
|
2009-03-15 23:04:45 +00:00
|
|
|
void MakeEdgesInto(SShell *shell, SEdgeList *sel, bool asUv,
|
|
|
|
SShell *useCurvesFrom=NULL);
|
2009-02-01 05:13:43 +00:00
|
|
|
void MakeClassifyingBsp(SShell *shell);
|
2009-02-27 14:05:08 +00:00
|
|
|
double ChordToleranceForEdge(Vector a, Vector b);
|
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-27 13:04:36 +00:00
|
|
|
void CopyCurvesSplitAgainst(bool opA, SShell *agnst, 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-23 10:06:02 +00:00
|
|
|
void AllPointsIntersecting(Vector a, Vector b, List<SInter> *il,
|
2009-03-19 17:40:11 +00:00
|
|
|
bool seg, bool trimmed, bool inclTangent);
|
2009-02-09 12:40:48 +00:00
|
|
|
void MakeCoincidentEdgesInto(SSurface *proto, bool sameNormal,
|
2009-03-15 23:04:45 +00:00
|
|
|
SEdgeList *el, SShell *useCurvesFrom);
|
2009-01-27 07:59:58 +00:00
|
|
|
void CleanupAfterBoolean(void);
|
2009-01-25 11:52:29 +00:00
|
|
|
|
2009-03-19 17:40:11 +00:00
|
|
|
static const int INSIDE = 100;
|
|
|
|
static const int OUTSIDE = 200;
|
|
|
|
static const int SURF_PARALLEL = 300;
|
|
|
|
static const int SURF_ANTIPARALLEL = 400;
|
|
|
|
static const int EDGE_PARALLEL = 500;
|
|
|
|
static const int EDGE_ANTIPARALLEL = 600;
|
|
|
|
static const int EDGE_TANGENT = 700;
|
2009-02-17 11:17:12 +00:00
|
|
|
|
2009-03-19 17:40:11 +00:00
|
|
|
int ClassifyPoint(Vector p, Vector edge_n, Vector surf_n);
|
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
|
|
|
|
|