2013-07-28 22:08:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Functions relating to rational polynomial surfaces, which are trimmed by
|
|
|
|
// curves (either rational polynomial curves, or piecewise linear
|
|
|
|
// approximations to curves of intersection that can't be represented
|
|
|
|
// exactly in ratpoly form), and assembled into watertight shells.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
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-05-18 07:26:51 +00:00
|
|
|
class SCurvePt;
|
2009-02-27 13:04:36 +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;
|
|
|
|
|
2013-09-09 19:50:32 +00:00
|
|
|
enum {
|
|
|
|
INSIDE = 100,
|
|
|
|
OUTSIDE = 200,
|
|
|
|
EDGE_PARALLEL = 300,
|
|
|
|
EDGE_ANTIPARALLEL = 400,
|
|
|
|
EDGE_OTHER = 500
|
|
|
|
};
|
2009-02-01 05:13:43 +00:00
|
|
|
|
|
|
|
static SBspUv *Alloc(void);
|
2009-07-02 03:32:17 +00:00
|
|
|
static SBspUv *From(SEdgeList *el, SSurface *srf);
|
2009-02-01 05:13:43 +00:00
|
|
|
|
2009-07-02 03:32:17 +00:00
|
|
|
void ScalePoints(Point2d *pt, Point2d *a, Point2d *b, SSurface *srf);
|
|
|
|
double ScaledSignedDistanceToLine(Point2d pt, Point2d a, Point2d b,
|
|
|
|
SSurface *srf);
|
|
|
|
double ScaledDistanceToLine(Point2d pt, Point2d a, Point2d b, bool seg,
|
|
|
|
SSurface *srf);
|
|
|
|
|
|
|
|
SBspUv *InsertEdge(Point2d a, Point2d b, SSurface *srf);
|
|
|
|
int ClassifyPoint(Point2d p, Point2d eb, SSurface *srf);
|
|
|
|
int ClassifyEdge(Point2d ea, Point2d eb, SSurface *srf);
|
2009-08-21 04:58:28 +00:00
|
|
|
double MinimumDistanceToEdge(Point2d p, SSurface *srf);
|
2009-02-01 05:13:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 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:
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
uint32_t v;
|
2009-01-15 03:55:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class hSCurve {
|
|
|
|
public:
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
uint32_t v;
|
2009-01-15 03:55:42 +00:00
|
|
|
};
|
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
|
2009-04-14 04:19:23 +00:00
|
|
|
// our inputs, and are also calculated for certain exact surface-surface
|
|
|
|
// intersections.
|
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-09-22 05:46:30 +00:00
|
|
|
int auxA, auxB;
|
|
|
|
|
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-04-14 04:19:23 +00:00
|
|
|
Vector TangentAt(double t);
|
2009-06-04 03:59:40 +00:00
|
|
|
void ClosestPointTo(Vector p, double *t, bool converge=true);
|
2009-04-14 04:19:23 +00:00
|
|
|
void SplitAt(double t, SBezier *bef, SBezier *aft);
|
2009-07-07 08:21:59 +00:00
|
|
|
bool PointOnThisAndCurve(SBezier *sbb, Vector *p);
|
2009-04-14 04:19:23 +00:00
|
|
|
|
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-10-12 10:40:48 +00:00
|
|
|
void MakePwlInto(SEdgeList *sel, double chordTol=0);
|
|
|
|
void MakePwlInto(List<SCurvePt> *l, double chordTol=0);
|
2009-10-29 07:16:28 +00:00
|
|
|
void MakePwlInto(SContour *sc, double chordTol=0);
|
2009-10-12 10:40:48 +00:00
|
|
|
void MakePwlInto(List<Vector> *l, double chordTol=0);
|
|
|
|
void MakePwlWorker(List<Vector> *l, double ta, double tb, double chordTol);
|
2009-01-14 05:10:42 +00:00
|
|
|
|
2009-07-07 08:21:59 +00:00
|
|
|
void AllIntersectionsWith(SBezier *sbb, SPointList *spl);
|
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-10-12 10:40:48 +00:00
|
|
|
bool IsInPlane(Vector n, double d);
|
2009-04-15 02:55:18 +00:00
|
|
|
bool IsCircle(Vector axis, Vector *center, double *r);
|
|
|
|
bool IsRational(void);
|
|
|
|
|
2009-12-15 12:26:22 +00:00
|
|
|
SBezier TransformedBy(Vector t, Quaternion q, double scale);
|
2009-04-14 04:19:23 +00:00
|
|
|
SBezier InPerspective(Vector u, Vector v, Vector n,
|
|
|
|
Vector origin, double cameraTan);
|
2009-10-12 09:28:34 +00:00
|
|
|
void ScaleSelfBy(double s);
|
2009-01-23 03:30:30 +00:00
|
|
|
|
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-04-14 04:19:23 +00:00
|
|
|
static SBezier From(Vector4 p0, Vector4 p1, Vector4 p2, Vector4 p3);
|
|
|
|
static SBezier From(Vector4 p0, Vector4 p1, Vector4 p2);
|
|
|
|
static SBezier From(Vector4 p0, Vector4 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-10-12 09:28:34 +00:00
|
|
|
void ScaleSelfBy(double s);
|
2009-04-15 02:55:18 +00:00
|
|
|
void CullIdenticalBeziers(void);
|
2009-07-07 08:21:59 +00:00
|
|
|
void AllIntersectionsWith(SBezierList *sblb, SPointList *spl);
|
2009-10-29 07:16:28 +00:00
|
|
|
bool GetPlaneContainingBeziers(Vector *p, Vector *u, Vector *v,
|
|
|
|
Vector *notCoplanarAt);
|
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-06-08 16:21:33 +00:00
|
|
|
int tag;
|
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(); }
|
2009-10-22 17:16:20 +00:00
|
|
|
bool IsClosed(void);
|
2009-01-19 03:33:15 +00:00
|
|
|
void Reverse(void);
|
2009-10-29 07:16:28 +00:00
|
|
|
void MakePwlInto(SContour *sc, double chordTol=0);
|
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,
|
2009-10-29 07:16:28 +00:00
|
|
|
double chordTol,
|
|
|
|
bool *allClosed, SEdge *errorAt,
|
|
|
|
SBezierList *openContours);
|
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-10-29 07:16:28 +00:00
|
|
|
void MakePwlInto(SPolygon *sp);
|
2009-01-19 03:33:15 +00:00
|
|
|
void Clear(void);
|
|
|
|
};
|
2009-01-14 05:10:42 +00:00
|
|
|
|
2009-10-22 17:16:20 +00:00
|
|
|
class SBezierLoopSetSet {
|
|
|
|
public:
|
|
|
|
List<SBezierLoopSet> l;
|
|
|
|
|
2009-10-29 07:16:28 +00:00
|
|
|
void FindOuterFacesFrom(SBezierList *sbl, SPolygon *spxyz, SSurface *srfuv,
|
|
|
|
double chordTol,
|
|
|
|
bool *allClosed, SEdge *notClosedAt,
|
|
|
|
bool *allCoplanar, Vector *notCoplanarAt,
|
|
|
|
SBezierList *openContours);
|
2009-10-30 10:38:34 +00:00
|
|
|
void AddOpenPath(SBezier *sb);
|
2009-10-22 17:16:20 +00:00
|
|
|
void Clear(void);
|
|
|
|
};
|
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
// Stuff for the surface trim curves: piecewise linear
|
2009-05-18 07:26:51 +00:00
|
|
|
class SCurvePt {
|
|
|
|
public:
|
|
|
|
int tag;
|
|
|
|
Vector p;
|
|
|
|
bool vertex;
|
|
|
|
};
|
|
|
|
|
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;
|
2013-09-09 19:50:32 +00:00
|
|
|
enum {
|
|
|
|
FROM_A = 100,
|
|
|
|
FROM_B = 200,
|
|
|
|
FROM_INTERSECTION = 300
|
|
|
|
};
|
2009-02-27 13:04:36 +00:00
|
|
|
int source;
|
2009-01-25 11:52:29 +00:00
|
|
|
|
2009-01-19 10:37:10 +00:00
|
|
|
bool isExact;
|
|
|
|
SBezier exact;
|
|
|
|
|
2009-05-18 07:26:51 +00:00
|
|
|
List<SCurvePt> pts;
|
2009-01-19 10:37:10 +00:00
|
|
|
|
2009-01-27 07:59:58 +00:00
|
|
|
hSSurface surfA;
|
|
|
|
hSSurface surfB;
|
|
|
|
|
2009-10-09 12:57:10 +00:00
|
|
|
static SCurve FromTransformationOf(SCurve *a, Vector t, Quaternion q,
|
2009-12-15 12:26:22 +00:00
|
|
|
double scale);
|
2009-02-27 13:04:36 +00:00
|
|
|
SCurve MakeCopySplitAgainst(SShell *agnstA, SShell *agnstB,
|
|
|
|
SSurface *srfA, SSurface *srfB);
|
2009-05-18 07:26:51 +00:00
|
|
|
void RemoveShortSegments(SSurface *srfA, SSurface *srfB);
|
2009-06-19 07:56:33 +00:00
|
|
|
SSurface *GetSurfaceA(SShell *a, SShell *b);
|
|
|
|
SSurface *GetSurfaceB(SShell *a, SShell *b);
|
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
|
|
|
|
2013-08-26 20:54:04 +00:00
|
|
|
static 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;
|
2009-06-04 03:59:40 +00:00
|
|
|
Point2d pinter;
|
|
|
|
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:
|
2009-06-05 05:38:41 +00:00
|
|
|
int tag;
|
2009-01-10 08:18:54 +00:00
|
|
|
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;
|
|
|
|
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
RgbColor color;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
uint32_t face;
|
2009-01-25 09:19:59 +00:00
|
|
|
|
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-06-04 03:59:40 +00:00
|
|
|
SEdgeList edges;
|
2009-01-27 07:59:58 +00:00
|
|
|
|
2009-08-21 04:58:28 +00:00
|
|
|
// For caching our initial (u, v) when doing Newton iterations to project
|
|
|
|
// a point into our surface.
|
|
|
|
Point2d cached;
|
|
|
|
|
2009-01-19 03:51:00 +00:00
|
|
|
static SSurface FromExtrusionOf(SBezier *spc, Vector t0, Vector t1);
|
2009-04-29 02:42:44 +00:00
|
|
|
static SSurface FromRevolutionOf(SBezier *sb, Vector pt, Vector axis,
|
|
|
|
double thetas, double thetaf);
|
2009-01-25 11:52:29 +00:00
|
|
|
static SSurface FromPlane(Vector pt, Vector u, Vector v);
|
2009-10-09 12:57:10 +00:00
|
|
|
static SSurface FromTransformationOf(SSurface *a, Vector t, Quaternion q,
|
2009-12-15 12:26:22 +00:00
|
|
|
double scale,
|
2009-01-23 03:30:30 +00:00
|
|
|
bool includingTrims);
|
2009-10-12 09:28:34 +00:00
|
|
|
void ScaleSelfBy(double s);
|
2009-01-17 05:28:49 +00:00
|
|
|
|
2009-06-04 03:59:40 +00:00
|
|
|
void EdgeNormalsWithinSurface(Point2d auv, Point2d buv,
|
|
|
|
Vector *pt, Vector *enin, Vector *enout,
|
|
|
|
Vector *surfn,
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
uint32_t auxA,
|
2009-06-19 07:56:33 +00:00
|
|
|
SShell *shell, SShell *sha, SShell *shb);
|
2009-06-27 05:53:56 +00:00
|
|
|
void FindChainAvoiding(SEdgeList *src, SEdgeList *dest, SPointList *avoid);
|
2009-06-19 07:56:33 +00:00
|
|
|
SSurface MakeCopyTrimAgainst(SShell *parent, SShell *a, SShell *b,
|
|
|
|
SShell *into, int type);
|
2009-06-05 05:38:41 +00:00
|
|
|
void TrimFromEdgeList(SEdgeList *el, bool asUv);
|
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-06-04 03:59:40 +00:00
|
|
|
void ClosestPointTo(Vector p, Point2d *puv, bool converge=true);
|
2009-02-27 13:04:36 +00:00
|
|
|
void ClosestPointTo(Vector p, double *u, double *v, bool converge=true);
|
2009-08-21 04:58:28 +00:00
|
|
|
bool ClosestPointNewton(Vector p, double *u, double *v, bool converge=true);
|
|
|
|
|
2009-02-27 13:04:36 +00:00
|
|
|
bool PointIntersectingLine(Vector p0, Vector p1, double *u, double *v);
|
2009-06-04 03:59:40 +00:00
|
|
|
Vector ClosestPointOnThisAndSurface(SSurface *srf2, Vector p);
|
2009-02-27 13:04:36 +00:00
|
|
|
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-06-04 03:59:40 +00:00
|
|
|
Vector PointAt(Point2d puv);
|
2009-01-19 10:37:10 +00:00
|
|
|
void TangentsAt(double u, double v, Vector *tu, Vector *tv);
|
2009-06-04 03:59:40 +00:00
|
|
|
Vector NormalAt(Point2d puv);
|
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-04-15 02:55:18 +00:00
|
|
|
bool IsCylinder(Vector *axis, Vector *center, 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-08-21 04:58:28 +00:00
|
|
|
|
|
|
|
// these are intended as bitmasks, even though there's just one now
|
2013-09-09 19:50:32 +00:00
|
|
|
enum {
|
|
|
|
AS_UV = 0x01,
|
|
|
|
AS_XYZ = 0x00
|
|
|
|
};
|
2009-08-21 04:58:28 +00:00
|
|
|
void MakeTrimEdgesInto(SEdgeList *sel, int flags, SCurve *sc, STrimBy *stb);
|
|
|
|
void MakeEdgesInto(SShell *shell, SEdgeList *sel, int flags,
|
2009-03-15 23:04:45 +00:00
|
|
|
SShell *useCurvesFrom=NULL);
|
2009-08-21 04:58:28 +00:00
|
|
|
|
2009-06-22 02:54:09 +00:00
|
|
|
Vector ExactSurfaceTangentAt(Vector p, SSurface *srfA, SSurface *srfB,
|
|
|
|
Vector dir);
|
2009-04-14 04:19:23 +00:00
|
|
|
void MakeSectionEdgesInto(SShell *shell, SEdgeList *sel, SBezierList *sbl);
|
2009-06-04 03:59:40 +00:00
|
|
|
void MakeClassifyingBsp(SShell *shell, SShell *useCurvesFrom);
|
2009-02-27 14:05:08 +00:00
|
|
|
double ChordToleranceForEdge(Vector a, Vector b);
|
2009-05-08 08:33:04 +00:00
|
|
|
void MakeTriangulationGridInto(List<double> *l, double vs, double vf,
|
|
|
|
bool swapped);
|
|
|
|
Vector PointAtMaybeSwapped(double u, double v, bool swapped);
|
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-05-30 08:49:09 +00:00
|
|
|
bool booleanFailed;
|
|
|
|
|
2009-01-25 09:19:59 +00:00
|
|
|
void MakeFromExtrusionOf(SBezierLoopSet *sbls, Vector t0, Vector t1,
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
RgbColor color);
|
2009-04-29 02:42:44 +00:00
|
|
|
void MakeFromRevolutionOf(SBezierLoopSet *sbls, Vector pt, Vector axis,
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
RgbColor 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);
|
2013-09-09 19:50:32 +00:00
|
|
|
enum {
|
|
|
|
AS_UNION = 10,
|
|
|
|
AS_DIFFERENCE = 11,
|
|
|
|
AS_INTERSECT = 12
|
|
|
|
};
|
2009-01-25 11:52:29 +00:00
|
|
|
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-06-19 07:56:33 +00:00
|
|
|
void CopySurfacesTrimAgainst(SShell *sha, SShell *shb, SShell *into,
|
|
|
|
int type);
|
2009-01-27 07:59:58 +00:00
|
|
|
void MakeIntersectionCurvesAgainst(SShell *against, SShell *into);
|
2009-06-04 03:59:40 +00:00
|
|
|
void MakeClassifyingBsps(SShell *useCurvesFrom);
|
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-05-20 03:04:36 +00:00
|
|
|
void RewriteSurfaceHandlesForCurves(SShell *a, SShell *b);
|
2009-01-27 07:59:58 +00:00
|
|
|
void CleanupAfterBoolean(void);
|
2009-01-25 11:52:29 +00:00
|
|
|
|
2009-06-04 03:59:40 +00:00
|
|
|
// Definitions when classifying regions of a surface; it is either inside,
|
|
|
|
// outside, or coincident (with parallel or antiparallel normal) with a
|
|
|
|
// shell.
|
2013-09-09 19:50:32 +00:00
|
|
|
enum {
|
|
|
|
INSIDE = 100,
|
|
|
|
OUTSIDE = 200,
|
|
|
|
COINC_SAME = 300,
|
|
|
|
COINC_OPP = 400
|
|
|
|
};
|
2009-06-04 03:59:40 +00:00
|
|
|
static const double DOTP_TOL;
|
|
|
|
int ClassifyRegion(Vector edge_n, Vector inter_surf_n, Vector edge_surf_n);
|
|
|
|
bool ClassifyEdge(int *indir, int *outdir,
|
|
|
|
Vector ea, Vector eb,
|
|
|
|
Vector p,
|
|
|
|
Vector edge_n_in, Vector edge_n_out, Vector surf_n);
|
2009-02-01 13:01:28 +00:00
|
|
|
|
2009-01-23 03:30:30 +00:00
|
|
|
void MakeFromCopyOf(SShell *a);
|
2009-12-15 12:26:22 +00:00
|
|
|
void MakeFromTransformationOf(SShell *a,
|
|
|
|
Vector trans, Quaternion q, double scale);
|
2009-05-20 03:04:36 +00:00
|
|
|
void MakeFromAssemblyOf(SShell *a, SShell *b);
|
2009-06-05 05:38:41 +00:00
|
|
|
void MergeCoincidentSurfaces(void);
|
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-04-14 04:19:23 +00:00
|
|
|
void MakeSectionEdgesInto(Vector n, double d,
|
|
|
|
SEdgeList *sel, SBezierList *sbl);
|
2009-05-24 11:37:07 +00:00
|
|
|
bool IsEmpty(void);
|
|
|
|
void RemapFaces(Group *g, int remap);
|
2009-01-19 10:37:10 +00:00
|
|
|
void Clear(void);
|
2009-01-10 08:18:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|