FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
solvespace/src/srf/surface.h at python · realthunder/solvespace · GitHub
realthunder
/
solvespace
Public
forked from
solvespace/solvespace
Notifications
You must be signed in to change notification settings
Fork
4
Star
16
Code
Issues
3
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
solvespace
/
src
/
srf
/
surface.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
423 lines (355 loc) · 14.9 KB
Breadcrumbs
solvespace
/
src
/
srf
/
surface.h
Copy path
File metadata and controls
423 lines (355 loc) · 14.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
//
-----------------------------------------------------------------------------
//
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.
//
-----------------------------------------------------------------------------
#
ifndef
__SURFACE_H
#
define
__SURFACE_H
//
Utility functions, Bernstein polynomials of order 1-3 and their derivatives.
double
Bernstein
(
int
k,
int
deg,
double
t);
double
BernsteinDerivative
(
int
k,
int
deg,
double
t);
class
SSurface
;
class
SCurvePt
;
//
Utility data structure, a two-dimensional BSP to accelerate polygon
//
operations.
class
SBspUv
{
public:
Point2d a, b;
SBspUv *pos;
SBspUv *neg;
SBspUv *more;
enum
{
INSIDE
=
100
,
OUTSIDE
=
200
,
EDGE_PARALLEL
=
300
,
EDGE_ANTIPARALLEL
=
400
,
EDGE_OTHER
=
500
};
static
SBspUv *
Alloc
(
void
);
static
SBspUv *
From
(SEdgeList *el, SSurface *srf);
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);
void
InsertEdge
(Point2d a, Point2d b, SSurface *srf);
static
SBspUv *
InsertOrCreateEdge
(SBspUv *where,
const
Point2d &ea,
const
Point2d &eb, SSurface *srf);
int
ClassifyPoint
(Point2d p, Point2d eb, SSurface *srf);
int
ClassifyEdge
(Point2d ea, Point2d eb, SSurface *srf);
double
MinimumDistanceToEdge
(Point2d p, SSurface *srf);
};
//
Now the data structures to represent a shell of trimmed rational polynomial
//
surfaces.
class
SShell
;
class
hSSurface
{
public:
uint32_t
v;
};
class
hSCurve
{
public:
uint32_t
v;
};
//
Stuff for rational polynomial curves, of degree one to three. These are
//
our inputs, and are also calculated for certain exact surface-surface
//
intersections.
class
SBezier
{
public:
int
tag;
int
auxA, auxB;
int
deg;
Vector ctrl[
4
];
double
weight[
4
];
uint32_t
entity;
Vector
PointAt
(
double
t);
Vector
TangentAt
(
double
t);
void
ClosestPointTo
(Vector p,
double
*t,
bool
converge=
true
);
void
SplitAt
(
double
t, SBezier *bef, SBezier *aft);
bool
PointOnThisAndCurve
(SBezier *sbb, Vector *p);
Vector
Start
(
void
);
Vector
Finish
(
void
);
bool
Equals
(SBezier *b);
void
MakePwlInto
(SEdgeList *sel,
double
chordTol=
0
);
void
MakePwlInto
(List<SCurvePt> *l,
double
chordTol=
0
);
void
MakePwlInto
(SContour *sc,
double
chordTol=
0
);
void
MakePwlInto
(List<Vector> *l,
double
chordTol=
0
);
void
MakePwlWorker
(List<Vector> *l,
double
ta,
double
tb,
double
chordTol);
void
MakePwlInitialWorker
(List<Vector> *l,
double
ta,
double
tb,
double
chordTol);
void
AllIntersectionsWith
(SBezier *sbb, SPointList *spl);
void
GetBoundingProjd
(Vector u, Vector orig,
double
*umin,
double
*umax);
void
Reverse
(
void
);
bool
IsInPlane
(Vector n,
double
d);
bool
IsCircle
(Vector axis, Vector *center,
double
*r);
bool
IsRational
(
void
);
SBezier
TransformedBy
(Vector t, Quaternion q,
double
scale);
SBezier
InPerspective
(Vector u, Vector v, Vector n,
Vector origin,
double
cameraTan);
void
ScaleSelfBy
(
double
s);
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);
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);
};
class
SBezierList
{
public:
List<SBezier> l;
void
Clear
(
void
);
void
ScaleSelfBy
(
double
s);
void
CullIdenticalBeziers
(
void
);
void
AllIntersectionsWith
(SBezierList *sblb, SPointList *spl);
bool
GetPlaneContainingBeziers
(Vector *p, Vector *u, Vector *v,
Vector *notCoplanarAt);
};
class
SBezierLoop
{
public:
int
tag;
List<SBezier> l;
inline
void
Clear
(
void
) { l.
Clear
(); }
bool
IsClosed
(
void
);
void
Reverse
(
void
);
void
MakePwlInto
(SContour *sc,
double
chordTol=
0
);
void
GetBoundingProjd
(Vector u, Vector orig,
double
*umin,
double
*umax);
static
SBezierLoop
FromCurves
(SBezierList *spcl,
bool
*allClosed, SEdge *errorAt);
};
class
SBezierLoopSet
{
public:
List<SBezierLoop> l;
Vector normal;
Vector point;
static
SBezierLoopSet
From
(SBezierList *spcl, SPolygon *poly,
double
chordTol,
bool
*allClosed, SEdge *errorAt,
SBezierList *openContours);
void
GetBoundingProjd
(Vector u, Vector orig,
double
*umin,
double
*umax);
void
MakePwlInto
(SPolygon *sp);
void
Clear
(
void
);
};
class
SBezierLoopSetSet
{
public:
List<SBezierLoopSet> l;
void
FindOuterFacesFrom
(SBezierList *sbl, SPolygon *spxyz, SSurface *srfuv,
double
chordTol,
bool
*allClosed, SEdge *notClosedAt,
bool
*allCoplanar, Vector *notCoplanarAt,
SBezierList *openContours);
void
AddOpenPath
(SBezier *sb);
void
Clear
(
void
);
};
//
Stuff for the surface trim curves: piecewise linear
class
SCurvePt
{
public:
int
tag;
Vector p;
bool
vertex;
};
class
SCurve
{
public:
hSCurve h;
//
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;
enum
{
FROM_A
=
100
,
FROM_B
=
200
,
FROM_INTERSECTION
=
300
};
int
source;
bool
isExact;
SBezier exact;
List<SCurvePt> pts;
hSSurface surfA;
hSSurface surfB;
static
SCurve
FromTransformationOf
(SCurve *a, Vector t, Quaternion q,
double
scale);
SCurve
MakeCopySplitAgainst
(SShell *agnstA, SShell *agnstB,
SSurface *srfA, SSurface *srfB);
void
RemoveShortSegments
(SSurface *srfA, SSurface *srfB);
SSurface *
GetSurfaceA
(SShell *a, SShell *b);
SSurface *
GetSurfaceB
(SShell *a, SShell *b);
void
Clear
(
void
);
};
//
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.
class
STrimBy
{
public:
hSCurve curve;
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.
Vector start;
Vector finish;
static
STrimBy
EntireCurve
(SShell *shell, hSCurve hsc,
bool
bkwds);
};
//
An intersection point between a line and a surface
class
SInter
{
public:
int
tag;
Vector p;
SSurface *srf;
Point2d pinter;
Vector surfNormal;
//
of the intersecting surface, at pinter
bool
onEdge;
//
pinter is on edge of trim poly
};
//
A rational polynomial surface in Bezier form.
class
SSurface
{
public:
int
tag;
hSSurface h;
//
Same as newH for the curves; record what a surface gets renamed to
//
when I copy things over.
hSSurface newH;
RgbaColor color;
uint32_t
face;
int
degm, degn;
Vector ctrl[
4
][
4
];
double
weight[
4
][
4
];
List<STrimBy> trim;
//
For testing whether a point (u, v) on the surface lies inside the trim
SBspUv *bsp;
SEdgeList edges;
//
For caching our initial (u, v) when doing Newton iterations to project
//
a point into our surface.
Point2d cached;
static
SSurface
FromExtrusionOf
(SBezier *spc, Vector t0, Vector t1);
static
SSurface
FromRevolutionOf
(SBezier *sb, Vector pt, Vector axis,
double
thetas,
double
thetaf);
static
SSurface
FromPlane
(Vector pt, Vector u, Vector v);
static
SSurface
FromTransformationOf
(SSurface *a, Vector t, Quaternion q,
double
scale,
bool
includingTrims);
void
ScaleSelfBy
(
double
s);
void
EdgeNormalsWithinSurface
(Point2d auv, Point2d buv,
Vector *pt, Vector *enin, Vector *enout,
Vector *surfn,
uint32_t
auxA,
SShell *shell, SShell *sha, SShell *shb);
void
FindChainAvoiding
(SEdgeList *src, SEdgeList *dest, SPointList *avoid);
SSurface
MakeCopyTrimAgainst
(SShell *parent, SShell *a, SShell *b,
SShell *into,
int
type);
void
TrimFromEdgeList
(SEdgeList *el,
bool
asUv);
void
IntersectAgainst
(SSurface *b, SShell *agnstA, SShell *agnstB,
SShell *into);
void
AddExactIntersectionCurve
(SBezier *sb, SSurface *srfB,
SShell *agnstA, SShell *agnstB, SShell *into);
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);
double
DepartureFromCoplanar
(
void
);
void
SplitInHalf
(
bool
byU, SSurface *sa, SSurface *sb);
void
AllPointsIntersecting
(Vector a, Vector b,
List<SInter> *l,
bool
seg,
bool
trimmed,
bool
inclTangent);
void
AllPointsIntersectingUntrimmed
(Vector a, Vector b,
int
*cnt,
int
*level,
List<Inter> *l,
bool
segment,
SSurface *sorig);
void
ClosestPointTo
(Vector p, Point2d *puv,
bool
converge=
true
);
void
ClosestPointTo
(Vector p,
double
*u,
double
*v,
bool
converge=
true
);
bool
ClosestPointNewton
(Vector p,
double
*u,
double
*v,
bool
converge=
true
);
bool
PointIntersectingLine
(Vector p0, Vector p1,
double
*u,
double
*v);
Vector
ClosestPointOnThisAndSurface
(SSurface *srf2, Vector p);
void
PointOnSurfaces
(SSurface *s1, SSurface *s2,
double
*u,
double
*v);
Vector
PointAt
(
double
u,
double
v);
Vector
PointAt
(Point2d puv);
void
TangentsAt
(
double
u,
double
v, Vector *tu, Vector *tv);
Vector
NormalAt
(Point2d puv);
Vector
NormalAt
(
double
u,
double
v);
bool
LineEntirelyOutsideBbox
(Vector a, Vector b,
bool
segment);
void
GetAxisAlignedBounding
(Vector *ptMax, Vector *ptMin);
bool
CoincidentWithPlane
(Vector n,
double
d);
bool
CoincidentWith
(SSurface *ss,
bool
sameNormal);
bool
IsExtrusion
(SBezier *of, Vector *along);
bool
IsCylinder
(Vector *axis, Vector *center,
double
*r,
Vector *start, Vector *finish);
void
TriangulateInto
(SShell *shell, SMesh *sm);
//
these are intended as bitmasks, even though there's just one now
enum
{
AS_UV
=
0x01
,
AS_XYZ
=
0x00
};
void
MakeTrimEdgesInto
(SEdgeList *sel,
int
flags, SCurve *sc, STrimBy *stb);
void
MakeEdgesInto
(SShell *shell, SEdgeList *sel,
int
flags,
SShell *useCurvesFrom=
NULL
);
Vector
ExactSurfaceTangentAt
(Vector p, SSurface *srfA, SSurface *srfB,
Vector dir);
void
MakeSectionEdgesInto
(SShell *shell, SEdgeList *sel, SBezierList *sbl);
void
MakeClassifyingBsp
(SShell *shell, SShell *useCurvesFrom);
double
ChordToleranceForEdge
(Vector a, Vector b);
void
MakeTriangulationGridInto
(List<
double
> *l,
double
vs,
double
vf,
bool
swapped);
Vector
PointAtMaybeSwapped
(
double
u,
double
v,
bool
swapped);
void
Reverse
(
void
);
void
Clear
(
void
);
};
class
SShell
{
public:
IdList<SCurve,hSCurve> curve;
IdList<SSurface,hSSurface> surface;
bool
booleanFailed;
void
MakeFromExtrusionOf
(SBezierLoopSet *sbls, Vector t0, Vector t1,
RgbaColor color);
void
MakeFromRevolutionOf
(SBezierLoopSet *sbls, Vector pt, Vector axis,
RgbaColor color, Group *group);
void
MakeFromUnionOf
(SShell *a, SShell *b);
void
MakeFromDifferenceOf
(SShell *a, SShell *b);
enum
{
AS_UNION
=
10
,
AS_DIFFERENCE
=
11
,
AS_INTERSECT
=
12
};
void
MakeFromBoolean
(SShell *a, SShell *b,
int
type);
void
CopyCurvesSplitAgainst
(
bool
opA, SShell *agnst, SShell *into);
void
CopySurfacesTrimAgainst
(SShell *sha, SShell *shb, SShell *into,
int
type);
void
MakeIntersectionCurvesAgainst
(SShell *against, SShell *into);
void
MakeClassifyingBsps
(SShell *useCurvesFrom);
void
AllPointsIntersecting
(Vector a, Vector b, List<SInter> *il,
bool
seg,
bool
trimmed,
bool
inclTangent);
void
MakeCoincidentEdgesInto
(SSurface *proto,
bool
sameNormal,
SEdgeList *el, SShell *useCurvesFrom);
void
RewriteSurfaceHandlesForCurves
(SShell *a, SShell *b);
void
CleanupAfterBoolean
(
void
);
//
Definitions when classifying regions of a surface; it is either inside,
//
outside, or coincident (with parallel or antiparallel normal) with a
//
shell.
enum
{
INSIDE
=
100
,
OUTSIDE
=
200
,
COINC_SAME
=
300
,
COINC_OPP
=
400
};
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);
void
MakeFromCopyOf
(SShell *a);
void
MakeFromTransformationOf
(SShell *a,
Vector trans, Quaternion q,
double
scale);
void
MakeFromAssemblyOf
(SShell *a, SShell *b);
void
MergeCoincidentSurfaces
(
void
);
void
TriangulateInto
(SMesh *sm);
void
MakeEdgesInto
(SEdgeList *sel);
void
MakeSectionEdgesInto
(Vector n,
double
d,
SEdgeList *sel, SBezierList *sbl);
bool
IsEmpty
(
void
);
void
RemapFaces
(Group *g,
int
remap);
void
Clear
(
void
);
};
#
endif
Back
|
FazBrowse Home
|
New Git URL