BRL-CAD
intersect.h
Go to the documentation of this file.
1/* I N T E R S E C T . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2007-2023 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20/** @addtogroup brep_intersect
21 * @brief
22 * Intersection routines for Non-Uniform Rational
23 * B-Spline (NURBS) curves and surfaces.
24 */
25#ifndef BREP_INTERSECT_H
26#define BREP_INTERSECT_H
27
28#include "common.h"
29#include "brep/defines.h"
30
31/** @{ */
32/** @file brep/intersect.h */
33
34#ifdef __cplusplus
35
36extern "C++" {
37
38/**
39 * Dump the information of an ON_SSX_EVENT.
40 */
41extern BREP_EXPORT void
42DumpSSXEvent(ON_SSX_EVENT &x, ON_TextLog &text_log);
43
44/* Sub-division support for a curve.
45 * It's similar to generating the bounding box tree, when the Split()
46 * method is called, the curve is split into two parts, whose bounding
47 * boxes become the children of the original curve's bbox.
48 */
49class Subcurve {
50 friend class Subsurface;
51private:
52 ON_BoundingBox m_node;
53public:
54 ON_Curve *m_curve;
55 ON_Interval m_t;
58
60 Subcurve(ON_Curve *curve);
61 Subcurve(const Subcurve &_scurve);
63 int Split();
64 void GetBBox(ON_3dPoint &min, ON_3dPoint &max);
65 void SetBBox(const ON_BoundingBox &bbox);
66 bool IsPointIn(const ON_3dPoint &pt, double tolerance = 0.0);
67 bool Intersect(const Subcurve &other, double tolerance = 0.0, ON_BoundingBox *intersection = NULL) const;
68};
69
70/* Sub-division support for a surface.
71 * It's similar to generating the bounding box tree, when the Split()
72 * method is called, the surface is split into two parts, whose bounding
73 * boxes become the children of the original surface's bbox.
74 */
76private:
77 ON_BoundingBox m_node;
78public:
79 ON_Surface *m_surf;
80 ON_Interval m_u, m_v;
83
85 Subsurface(ON_Surface *surf);
86 Subsurface(const Subsurface &_ssurf);
88
89 int Split();
90 void GetBBox(ON_3dPoint &min, ON_3dPoint &max);
91 void SetBBox(const ON_BoundingBox &bbox);
92 bool IsPointIn(const ON_3dPoint &pt, double tolerance = 0.0);
93 bool Intersect(const Subcurve &curve, double tolerance = 0.0, ON_BoundingBox *intersection = NULL) const;
94 bool Intersect(const Subsurface &surf, double tolerance = 0.0, ON_BoundingBox *intersection = NULL) const;
95};
96
97/** The ON_PX_EVENT class is used to report point-point, point-curve
98 * and point-surface intersection events.
99 */
100class BREP_EXPORT ON_PX_EVENT
101{
102public:
103 /** Default construction sets everything to zero. */
105
106 /**
107 * Compares point intersection events and sorts them in the
108 * canonical order.
109 *
110 * @retval -1 this < other
111 * @retval 0 this == other
112 * @retval +1 this > other
113 *
114 * @remarks ON_PX_EVENT::Compare is used to sort intersection
115 * events into canonical order.
116 */
117 static
118 int Compare(const ON_PX_EVENT *a, const ON_PX_EVENT *b);
119
120 /**
121 * Check point intersection event values to make sure they are
122 * valid.
123 *
124 * @param text_log [in] If not null and an error is found, then
125 * a description of the error is printed to text_log.
126 * @param intersection_tolerance [in] 0.0 or value used in
127 * intersection calculation.
128 * @param pointA [in] NULL or pointA passed to intersection
129 * calculation.
130 * @param pointB [in] NULL or pointB passed to intersection
131 * calculation.
132 * @param curveB [in] NULL or curveB passed to intersection
133 * calculation.
134 * @param curveB_domain [in] NULL or curveB domain used in
135 * intersection calculation.
136 * @param surfaceB [in] NULL or surfaceB passed to intersection
137 * calculation.
138 * @param surfaceB_domain0 [in] NULL or surfaceB "u" domain used
139 * in intersection calculation.
140 * @param surfaceB_domain1 [in] NULL or surfaceB "v" domain used
141 * in intersection calculation.
142 *
143 * @return True if event is valid.
144 */
145 bool IsValid(ON_TextLog *text_log,
146 double intersection_tolerance,
147 const class ON_3dPoint *pointA,
148 const class ON_3dPoint *pointB,
149 const class ON_Curve *curveB,
150 const class ON_Interval *curveB_domain,
151 const class ON_Surface *surfaceB,
152 const class ON_Interval *surfaceB_domain0,
153 const class ON_Interval *surfaceB_domain1) const;
154
155 void Dump(ON_TextLog &text_log) const;
156
157 enum TYPE {
158 no_px_event = 0,
159 ppx_point = 1, /**< point-point intersection */
160 pcx_point = 2, /**< point-curve intersection */
161 psx_point = 3 /**< point-surface intersection */
162 };
163
165
166 ON_3dPoint m_A; /**< Point A in 3D space */
167 ON_3dPoint m_B; /**< Point B in 3D space */
168
169 ON_2dPoint m_b; /**< Point B in 2D space for the curve/surface
170 * For a curve, m_b[1] == 0
171 * For a point, m_b[0] == m_b[1] == 0
172 */
173
174 ON_3dPoint m_Mid; /**< The mid-point of Point A and Point B */
175 double m_radius; /**< To trace the uncertainty area */
176};
177
178/**
179 * An overload of ON_Intersect for point-point intersection.
180 * Intersect pointA with pointB.
181 *
182 * @param pointA [in]
183 * @param pointB [in]
184 * @param x [out] Intersection events are appended to this array.
185 * @param tolerance [in] If the input intersection_tolerance <= 0.0,
186 * then 0.001 is used.
187 *
188 * @return True for an intersection. False for no intersection.
189 */
190extern BREP_EXPORT bool
191ON_Intersect(const ON_3dPoint &pointA,
192 const ON_3dPoint &pointB,
193 ON_ClassArray<ON_PX_EVENT> &x,
194 double tolerance = 0.0);
195
196/**
197 * An overload of ON_Intersect for point-curve intersection.
198 * Intersect pointA with curveB.
199 *
200 * @param pointA [in] pointA
201 * @param curveB [in] curveB
202 * @param x [out] Intersection events are appended to this array.
203 * @param tolerance [in] If the input intersection_tolerance <= 0.0,
204 * then 0.001 is used.
205 * @param curveB_domain [in] optional restriction on curveB t domain
206 * @param treeB [in] optional curve tree for curveB, to avoid re-computation
207 *
208 * @return True for an intersection. False for no intersection.
209 */
210extern BREP_EXPORT bool
211ON_Intersect(const ON_3dPoint &pointA,
212 const ON_Curve &curveB,
213 ON_ClassArray<ON_PX_EVENT> &x,
214 double tolerance = 0.0,
215 const ON_Interval *curveB_domain = 0,
216 Subcurve *treeB = 0);
217
218/**
219 * An overload of ON_Intersect for point-surface intersection.
220 * Intersect pointA with surfaceB.
221 *
222 * @param pointA [in]
223 * @param surfaceB [in]
224 * @param x [out] Intersection events are appended to this array.
225 * @param tolerance [in] If the input intersection_tolerance <= 0.0,
226 * then 0.001 is used.
227 * @param surfaceB_udomain [in] optional restriction on surfaceB u
228 * domain
229 * @param surfaceB_vdomain [in] optional restriction on surfaceB v
230 * domain
231 * @param treeB [in] optional surface tree for surfaceB, to avoid
232 * re-computation
233 *
234 * @return True for an intersection. False for no intersection.
235 */
236extern BREP_EXPORT bool
237ON_Intersect(const ON_3dPoint &pointA,
238 const ON_Surface &surfaceB,
239 ON_ClassArray<ON_PX_EVENT> &x,
240 double tolerance = 0.0,
241 const ON_Interval *surfaceB_udomain = 0,
242 const ON_Interval *surfaceB_vdomain = 0,
243 Subsurface *treeB = 0);
244
245/**
246 * An overload of ON_Intersect for curve-curve intersection.
247 * Intersect curveA with curveB.
248 *
249 * Parameters:
250 * @param curveA [in]
251 * @param curveB [in]
252 * @param x [out] Intersection events are appended to this array.
253 * @param intersection_tolerance [in] If the distance from a point
254 * on curveA to curveB is <= intersection tolerance, then the
255 * point will be part of an intersection event. If the input
256 * intersection_tolerance <= 0.0, then 0.001 is used.
257 * @param overlap_tolerance [in] If t1 and t2 are parameters of
258 * curveA's intersection events and the distance from curveA(t)
259 * to curveB is <= overlap_tolerance for every t1 <= t <= t2,
260 * then the event will be returned as an overlap event. If the
261 * input overlap_tolerance <= 0.0, then
262 * intersection_tolerance * 2.0 is used.
263 * @param curveA_domain [in] optional restriction on curveA domain
264 * @param curveB_domain [in] optional restriction on curveB domain
265 * @param treeA [in] optional curve tree for curveA, to avoid re
266 * computation
267 * @param treeB [in] optional curve tree for curveB, to avoid re
268 * computation
269 *
270 * @return Number of intersection events appended to x.
271 */
272extern BREP_EXPORT int
273ON_Intersect(const ON_Curve *curveA,
274 const ON_Curve *curveB,
275 ON_SimpleArray<ON_X_EVENT> &x,
276 double intersection_tolerance = 0.0,
277 double overlap_tolerance = 0.0,
278 const ON_Interval *curveA_domain = 0,
279 const ON_Interval *curveB_domain = 0,
280 Subcurve *treeA = 0,
281 Subcurve *treeB = 0);
282
283/**
284 * An overload of ON_Intersect for curve-surface intersection.
285 * Intersect curveA with surfaceB.
286 *
287 * @param curveA [in]
288 * @param surfaceB [in]
289 * @param x [out] Intersection events are appended to this array.
290 * @param intersection_tolerance [in] If the distance from a
291 * point on curveA to the surface is <= intersection tolerance,
292 * then the point will be part of an intersection event, or
293 * there is an intersection event the point leads to. If the
294 * input intersection_tolerance <= 0.0, then 0.001 is used.
295 * @param overlap_tolerance [in] If the input overlap_tolerance
296 * <= 0.0, then 2.0*intersection_tolerance is used. Otherwise,
297 * overlap tolerance must be >= intersection_tolerance. In all
298 * cases, the intersection calculation is performed with an
299 * overlap_tolerance that is >= intersection_tolerance. If t1
300 * and t2 are curve parameters of intersection events and the
301 * distance from curve(t) to the surface is <=
302 * overlap_tolerance for every t1 <= t <= t2, then the event
303 * will be returned as an overlap event.
304 * @param curveA_domain [in] optional restriction on curveA domain
305 * @param surfaceB_udomain [in] optional restriction on surfaceB
306 * u domain
307 * @param surfaceB_vdomain [in] optional restriction on surfaceB
308 * v domain
309 * @param overlap2d [out] return the 2D overlap curves on surfaceB.
310 * overlap2d[i] is the curve for event x[i].
311 * @param treeA [in] optional curve tree for curveA, to avoid
312 * re-computation
313 * @param treeB [in] optional surface tree for surfaceB, to avoid
314 * re-computation
315 *
316 * @return Number of intersection events appended to x.
317 */
318extern BREP_EXPORT int
319ON_Intersect(const ON_Curve *curveA,
320 const ON_Surface *surfaceB,
321 ON_SimpleArray<ON_X_EVENT> &x,
322 double intersection_tolerance = 0.0,
323 double overlap_tolerance = 0.0,
324 const ON_Interval *curveA_domain = 0,
325 const ON_Interval *surfaceB_udomain = 0,
326 const ON_Interval *surfaceB_vdomain = 0,
327 ON_CurveArray *overlap2d = 0,
328 Subcurve *treeA = 0,
329 Subsurface *treeB = 0);
330
331/**
332 * An overload of ON_Intersect for surface-surface intersection.
333 * Intersect surfaceA with surfaceB.
334 *
335 * @param surfA [in]
336 * @param surfB [in]
337 * @param x [out] Intersection events are appended to this array.
338 * @param intersection_tolerance [in] If the input
339 * intersection_tolerance <= 0.0, then 0.001 is used.
340 * @param overlap_tolerance [in] If positive, then overlap_tolerance
341 * must be >= intersection_tolerance and is used to test for
342 * overlapping regions. If the input overlap_tolerance <= 0.0,
343 * then 2*intersection_tolerance is used.
344 * @param fitting_tolerance [in] If fitting_tolerance is > 0 and
345 * >= intersection_tolerance, then the intersection curves are
346 * fit to this tolerance. If input fitting_tolerance <= 0.0 or
347 * < intersection_tolerance, then intersection_tolerance is used.
348 * @param surfaceA_udomain [in] optional restriction on surfaceA
349 * u domain
350 * @param surfaceA_vdomain [in] optional restriction on surfaceA
351 * v domain
352 * @param surfaceB_udomain [in] optional restriction on surfaceB
353 * u domain
354 * @param surfaceB_vdomain [in] optional restriction on surfaceB
355 * v domain
356 * @param treeA [in] optional surface tree for surfaceA, to avoid
357 * re-computation
358 * @param treeB [in] optional surface tree for surfaceB, to avoid
359 * re-computation
360 *
361 * @return Number of intersection events appended to x.
362 */
363extern BREP_EXPORT int
364ON_Intersect(const ON_Surface *surfA,
365 const ON_Surface *surfB,
366 ON_ClassArray<ON_SSX_EVENT> &x,
367 double intersection_tolerance = 0.0,
368 double overlap_tolerance = 0.0,
369 double fitting_tolerance = 0.0,
370 const ON_Interval *surfaceA_udomain = 0,
371 const ON_Interval *surfaceA_vdomain = 0,
372 const ON_Interval *surfaceB_udomain = 0,
373 const ON_Interval *surfaceB_vdomain = 0,
374 Subsurface *treeA = 0,
375 Subsurface *treeB = 0);
376
377
378} /* extern C++ */
379#endif
380
381#endif /* BREP_INTERSECT_H */
382/** @} */
383/*
384 * Local Variables:
385 * mode: C
386 * tab-width: 8
387 * indent-tabs-mode: t
388 * c-file-style: "stroustrup"
389 * End:
390 * ex: shiftwidth=4 tabstop=8
391 */
ON_3dPoint m_B
Definition: intersect.h:167
ON_3dPoint m_A
Definition: intersect.h:166
double m_radius
Definition: intersect.h:175
static int Compare(const ON_PX_EVENT *a, const ON_PX_EVENT *b)
void Dump(ON_TextLog &text_log) const
bool IsValid(ON_TextLog *text_log, double intersection_tolerance, const class ON_3dPoint *pointA, const class ON_3dPoint *pointB, const class ON_Curve *curveB, const class ON_Interval *curveB_domain, const class ON_Surface *surfaceB, const class ON_Interval *surfaceB_domain0, const class ON_Interval *surfaceB_domain1) const
ON_3dPoint m_Mid
Definition: intersect.h:174
TYPE m_type
Definition: intersect.h:164
ON_2dPoint m_b
Definition: intersect.h:169
bool m_islinear
Definition: intersect.h:57
ON_Interval m_t
Definition: intersect.h:55
void SetBBox(const ON_BoundingBox &bbox)
bool IsPointIn(const ON_3dPoint &pt, double tolerance=0.0)
Subcurve * m_children[2]
Definition: intersect.h:56
void GetBBox(ON_3dPoint &min, ON_3dPoint &max)
Subcurve(const Subcurve &_scurve)
bool Intersect(const Subcurve &other, double tolerance=0.0, ON_BoundingBox *intersection=NULL) const
ON_Curve * m_curve
Definition: intersect.h:54
int Split()
Subcurve(ON_Curve *curve)
bool Intersect(const Subsurface &surf, double tolerance=0.0, ON_BoundingBox *intersection=NULL) const
bool m_isplanar
Definition: intersect.h:82
Subsurface * m_children[4]
Definition: intersect.h:81
ON_Interval m_u
Definition: intersect.h:80
Subsurface(const Subsurface &_ssurf)
void SetBBox(const ON_BoundingBox &bbox)
bool IsPointIn(const ON_3dPoint &pt, double tolerance=0.0)
ON_Interval m_v
Definition: intersect.h:80
ON_Surface * m_surf
Definition: intersect.h:79
void GetBBox(ON_3dPoint &min, ON_3dPoint &max)
Subsurface(ON_Surface *surf)
bool Intersect(const Subcurve &curve, double tolerance=0.0, ON_BoundingBox *intersection=NULL) const
Header file for the BRL-CAD common definitions.
bool ON_Intersect(const ON_3dPoint &pointA, const ON_3dPoint &pointB, ON_ClassArray< ON_PX_EVENT > &x, double tolerance=0.0)
void DumpSSXEvent(ON_SSX_EVENT &x, ON_TextLog &text_log)
void int char int int double * min
Definition: tig.h:182
void float * x
Definition: tig.h:72