QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
opennurbs_x.h
Go to the documentation of this file.
1/* $NoKeywords: $ */
2/*
3//
4// Copyright (c) 1993-2007 Robert McNeel & Associates. All rights reserved.
5// Rhinoceros is a registered trademark of Robert McNeel & Assoicates.
6//
7// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
8// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
9// MERCHANTABILITY ARE HEREBY DISCLAIMED.
10//
11// For complete openNURBS copyright information see <http://www.opennurbs.org>.
12//
14*/
15
16#if !defined(OPENNURBS_X_INC_)
17#define OPENNURBS_X_INC_
18
19// The ON_X_EVENT class is used to report curve-curve and curve-surface
20// intersection events.
22{
23 // NO VIRTUAL FUNCTIONS IN THIS CLASS
24public:
25
26 // Default construction sets everything to zero.
27 ON_X_EVENT();
28
29 // This class must use default copy constructor, operator=, and destructor.
30
31 /*
32 Description:
33 Compares intersection events and sorts them in the
34 canonical order.
35 Returns:
36 @untitled table
37 -1 this < other
38 0 this == other
39 +1 this > other
40 Remarks:
41 ON_CX_EVENT::Compare is used to sort intersection events into canonical
42 order.
43 */
44 static
45 int Compare( const ON_X_EVENT* a, const ON_X_EVENT* b );
46
47 void Dump(ON_TextLog& text_log) const;
48
49 /*
50 Description:
51 Check intersection event values to make sure they are valid.
52 Parameters:
53 text_log - [in] If not null and an error is found, then a description
54 of the error is printed to text_log.
55 intersection_tolerance - [in]
56 0.0 or value used in intersection calculation.
57 overlap_tolerance - [in]
58 0.0 or value used in intersection calculation.
59 curveA - [in]
60 NULL or curveA passed to intersection calculation.
61 curveA_domain - [in]
62 NULL or curveA domain used in intersection calculation.
63 curveB - [in]
64 NULL or curveB passed to intersection calculation.
65 curveB_domain - [in]
66 NULL or curveB domain used in intersection calculation.
67 surfaceB - [in]
68 NULL or surfaceB passed to intersection calculation.
69 surfaceB_domain0 - [in]
70 NULL or surfaceB "u" domain used in intersection calculation.
71 surfaceB_domain1 - [in]
72 NULL or surfaceB "v" domain used in intersection calculation.
73 Returns:
74 True if event is valid.
75 */
76 bool IsValid(
77 ON_TextLog* text_log,
78 double intersection_tolerance,
79 double overlap_tolerance,
80 const class ON_Curve* curveA,
81 const class ON_Interval* curveA_domain,
82 const class ON_Curve* curveB,
83 const class ON_Interval* curveB_domain,
84 const class ON_Surface* surfaceB,
85 const class ON_Interval* surfaceB_domain0,
86 const class ON_Interval* surfaceB_domain1
87 ) const;
88
89
90 /*
91 Description:
92 Expert user tool to copy portions of the itersection
93 event information from one event to another.
94 If src.m_type is ON_X_EVENT::csx_*, then the
95 m_b[] and m_nodeB_t[] values are treated as
96 surface parameters, otherwise the values are
97 treated as curve parameters. The m_type field
98 is not copied.
99 Parameters:
100 src - [in]
101 src_end - [in] 0 or 1 (m_A[] source index)
102 dst - [out]
103 dst_end - [in] 0 or 1 (m_A[] destination index)
104 */
105 static
106 void CopyEventPart(
107 const ON_X_EVENT& src,
108 int src_end,
109 ON_X_EVENT& dst,
110 int dst_end
111 );
112
113 /*
114 Description:
115 Expert user tool to cleanup a list of intersection
116 events.
117 Parameters:
118 event_tolerance - [in] If the distance between
119 events is <= event_tolerance, they will
120 be considered to be the same event. Typically,
121 event_tolerance is "small" and
122 event_tolerance <= intersection_tolerance.
123
124 overlap_tolerance - [in] minimum length for an
125 intersection overlap segment. Typically,
126 overlap_tolerance is "large" and
127 overlap_tolerance > intersection_tolerance
128
129 xevent_count - [in]
130 xevent - [in/out]
131 Returns:
132 Length of cleaned list.
133 */
134 static
135 int CleanList(
136 double event_tolerance,
137 double overlap_tolerance,
138 int xevent_count,
139 ON_X_EVENT* xevent
140 );
141
142 /*
143 Description:
144 Expert user tool to check a list of intersection events.
145 Parameters:
146 xevent_count - [in]
147 xevent - [in]
148 text_log - [in] NULL or place to describe errors.
149 intersection_tolerance - [in]
150 overlap_tolerance - [in]
151 curveA - [in]
152 curveA_domain - [in] (can be NULL)
153 curveB - [in] (NULL for curve-surface intersection events)
154 curveB_domain - [in] (can be NULL)
155 surfaceB - [in] (NULL for curve-curve intersection events)
156 surfaceB_domain0 - [in] (can be NULL)
157 surfaceB_domain1 - [in] (can be NULL)
158 Returns:
159 True if list is valid.
160 */
161 static
162 bool IsValidList(
163 int xevent_count,
164 const ON_X_EVENT* xevent,
165 ON_TextLog* text_log,
166 double intersection_tolerance,
167 double overlap_tolerance,
168 const class ON_Curve* curveA,
169 const class ON_Interval* curveA_domain,
170 const class ON_Curve* curveB,
171 const class ON_Interval* curveB_domain,
172 const class ON_Surface* surfaceB,
173 const class ON_Interval* surfaceB_domain0,
174 const class ON_Interval* surfaceB_domain1
175 );
176
177 /*
178 Description:
179 Do a quick and simple test to see if this curve
180 lies on some portion of curveB.
181 Parameters:
182 curveA_domain - [in] non empty interval
183 sample_count - [in] minimum number of test points
184 overlap_tolerance - [in]
185 cnodeA - [in]
186 cnodeB - [in]
187 curveB_domain - [in] optional domain restriction
188 Returns:
189 True if sections overlap.
190 */
191 static
192 bool IsValidCurveCurveOverlap(
193 ON_Interval curveA_domain,
194 int sample_count,
195 double overlap_tolerance,
196 const class ON_CurveTreeNode* cnodeA,
197 const class ON_CurveTreeNode* cnodeB,
198 const ON_Interval* curveB_domain = 0
199 );
200
201 /*
202 Description:
203 Do a quick and simple test to see if this curve
204 lies on the plane.
205 Parameters:
206 curveA_domain - [in] non empty interval
207 sample_count - [in] minimum number of test points
208 endpont_tolerance - [in] tolerance to use when checking ends
209 overlap_tolerance - [in] tolerance to use when checking interior
210 cnodeA - [in]
211 plane_equation - [in]
212 Returns:
213 True if curve lies on the plane
214 */
215 static
216 bool IsValidCurvePlaneOverlap(
217 ON_Interval curveA_domain,
218 int sample_count,
219 double endpoint_tolerance,
220 double overlap_tolerance,
221 const class ON_CurveTreeNode* cnodeA,
222 const ON_PlaneEquation* plane_equation
223 );
224
225 /*
226 Description:
227 Do a quick and simple test to see if this curve
228 lies on the surface.
229 Parameters:
230 curveA_domain - [in] non empty interval
231 sample_count - [in] minimum number of test points
232 overlap_tolerance - [in]
233 cnodeA - [in]
234 snodeB - [in]
235 surfaceB_udomain - [in] optional domain restriction
236 surfaceB_vdomain - [in] optional domain restriction
237 Returns:
238 True if sections overlap.
239 */
240 static
241 bool IsValidCurveSurfaceOverlap(
242 ON_Interval curveA_domain,
243 int sample_count,
244 double overlap_tolerance,
245 const class ON_CurveTreeNode* cnodeA,
246 const class ON_SurfaceTreeNode* snodeB,
247 const ON_Interval* surfaceB_udomain = 0,
248 const ON_Interval* surfaceB_vdomain = 0
249 );
250
251 /*
252 Description:
253 Convert input intersection tolerance to value used
254 in calculations.
255 Parameters:
256 intersection_tolerance - [in]
257 Returns:
258 Value use in intersection calculations.
259 */
260 static
261 double IntersectionTolerance( double intersection_tolerance );
262
263 /*
264 Description:
265 Convert input intersection tolerance to value used
266 in calculations.
267 Parameters:
268 intersection_tolerance - [in]
269 Returns:
270 Value use in intersection calculations.
271 */
272 static
273 double OverlapTolerance( double intersection_tolerance, double overlap_tolerance );
274
275 /*
276 Returns:
277 True if m_type is ccx_point or csx_point.
278 */
279 bool IsPointEvent() const;
280
281 /*
282 Returns:
283 True if m_type is ccx_overlap or csx_overlap.
284 */
285 bool IsOverlapEvent() const;
286
287 /*
288 Returns:
289 True if m_type is ccx_point or ccx_overlap
290 */
291 bool IsCCXEvent() const;
292
293 /*
294 Returns:
295 True if m_type is csx_point or csx_overlap
296 */
297 bool IsCSXEvent() const;
298
299
300 enum TYPE
301 {
302 no_x_event = 0,
303
304 // Two valid event types for curve-curve intersections
305 ccx_point = 1, // curve-curve transverse intersection point
306 ccx_overlap = 2, // curve-curve intersection overlap
307
308 // Two valid event types for curve-surface intersections
309 csx_point = 3, // curve-surface transverse intersection point
310 csx_overlap = 4 // curve-surface intersection overlap
311 };
312
313 // Event directions for use in the m_dirA[] and m_dirB[]
314 // fields. The "x_from_*" values are used to report the
315 // behavior of the curve as it enters the intersection
316 // event. The "x_to_*" values are used to report the
317 // behavior of the curve as it leaves the intersection
318 // event.
320 {
321 no_x_dir = 0,
322
323 at_end_dir = 1, // event is at the start/end/side of object's
324 // parameter space
325
326 from_above_dir = 2, // curve enters x-event from above surface/other curve
327 from_below_dir = 3, // curve enters x-event from below surface/other curve
328 from_on_dir = 4, // curve enters x-event tangent surface/other curve
329
330 to_above_dir = 5, // curve leaves x-event above surface/other curve
331 to_below_dir = 6, // curve leaves x-event below surface/other curve
332 to_on_dir = 7 // curve leaves x-event tangent to surface/other curve
333 };
334
335 // This field is a scratch field for users.
336 // The constructor sets it to zero and the
337 // intersectors never use it.
339
340 // The m_type field determines how the values in the other
341 // fields are interpreted. See the detailed comment below
342 // for complete informtion
344
345 ON_3dPoint m_A[2]; // intersection points on first curve
346 ON_3dPoint m_B[2]; // intersection points on second curve or surface
347 double m_a[2]; // intersection parameters on first curve
348 double m_b[4]; // intersection parameters on second curve or surface
349
350 // There are cases when it is valuable to have direction
351 // flags on intersection events. The m_dirA[] and m_dirB[]
352 // fields provide a place to store these flags. Because this
353 // information is rarely used, it is not computed by the
354 // intersection routines. You can use
355 // ON_SetCurveCurveIntersectionDir
356 // or
357 // ON_SetCurveSurfaceIntersectionDir
358 // to fill in these fields.
359 DIRECTION m_dirA[2];
360 DIRECTION m_dirB[2];
361
362 // tree nodes where the intersection events occured.
363 const class ON_CurveTreeNode* m_cnodeA[2];
364 double m_nodeA_t[2]; // nodeA bezier paramters corresponding to a[] values
365 const class ON_CurveTreeNode* m_cnodeB[2];
366 const class ON_SurfaceTreeNode* m_snodeB[2];
367 double m_nodeB_t[4]; // nodeB bezier paramters corresponding to b[] values.
368
369 // Each intersection event is assigned a runtime serial number.
370 unsigned int m_x_eventsn;
371
372 /*
373 The m_type field determines how the values in the other
374 fields are interpreted.
375
376 ccx_point events:
377 a[0] = a[1] = first curve parameter
378 A[0] = A[1] = intersection point on first curve
379 b[0] = b[1] = second curve parmeter
380 B[0] = B[1] = intersection point on second curve
381 b[2] = b[3] = not used
382 cnodeA[0] = cnodeA[1] = pointer to first curve's tree node
383 cnodeB[0] = cnodeB[1] = pointer to second curve's tree node
384 snodeB[0] = snodeB[1] = 0
385
386 ccx_overlap events:
387 (a[0],a[1]) = first curve parameter range (a[0] < a[1])
388 A[0] = intersection start point on first curve
389 A[1] = intersection end point on first curve
390 (b[0],b[1]) = second curve parameter range (b[0] != b[1])
391 B[0] = intersection start point on second curve
392 B[1] = intersection end point on second curve
393 b[2] = b[3] = not used
394 cnodeA[0] = pointer to first curve's tree node for start point
395 cnodeA[1] = pointer to first curve's tree node for end point
396 cnodeB[0] = pointer to second curve's tree node for start point
397 cnodeB[1] = pointer to second curve's tree node for end point
398 snodeB[0] = snodeB[1] = 0
399
400 csx_point events:
401 a[0] = a[1] = curve parameter
402 A[0] = A[1] = intersection point on curve
403 (b[0],b[1]) = (b[2],b[3]) = surface parameter
404 B[0] = B[1] intersection point on surface
405 cnodeA[0] = cnodeA[1] = pointer to curve's tree node
406 cnodeB[0] = cnodeB[1] = 0;
407 snodeB[0] = snodeB[1] = pointer to surface's tree node
408
409 csx_overlap events:
410 (a[0],a[1]) = curve parmamter range (a[0] < a[1])
411 A[0] = intersection start point on first curve
412 A[1] = intersection end point on first curve
413 (b[0],b[1]) = surface parameter for curve(a[0]).
414 B[0] = intersection start point on surface
415 (b[2],b[3]) = surface parameter for curve(a[1]).
416 B[1] = intersection end point on surface
417 cnodeA[0] = pointer to curve's tree node for start point
418 cnodeA[1] = pointer to curve's tree node for end point
419 snodeB[0] = pointer to surface's tree node for start point
420 snodeB[1] = pointer to surface's tree node for end point
421 */
422};
423
424
425
426/*
427Description:
428 Sets ON_X_EVENT m_dirA[] and m_dirB[] flags for in intersection
429 of coplanar curves. For each m_dirA[]/m_dirB[] flag that is
430 set to ON_X_EVENT, the curve geometry at the itersection is
431 examined to set the flags.
432Parameters:
433 N [in] normal to the plane
434 xcount - [in] number of intersection events
435 xevent - [in] array of xcount intersection events
436 a0 - [in]
437 a1 - [in] (a0,a1) = curveA intersection domain
438 b0 - [in]
439 b1 - [in] (b0,b1) = curveB intersection domain
440See Also:
441 ON_Curve::IntersectCurve
442 ON_SetCurveSurfaceIntersectionDir
443*/
447 int xcount,
448 ON_X_EVENT* xevent,
449 double a0,
450 double a1,
451 double b0,
452 double b1
453 );
454
455
456/*
457Description:
458 Sets ON_X_EVENT m_dirA[] and m_dirB[] flags for a curve surface
459 intersection. For each m_dirA[]/m_dirB[] flag that is
460 set to ON_X_EVENT, the curve and surface geometry at the
461 itersection is examined to set the flags.
462Parameters:
463 xcount - [in] number of intersection events
464 xevent - [in] array of xcount intersection events
465 t0 - [in]
466 t1 - [in] (t0,t1) = curveA intersection domain
467 u0 - [in]
468 u1 - [in] (u0,u1) = surfaceB u interesection domain
469 v0 - [in]
470 v1 - [in] (v0,v1) = surfaceB v interesection domain
471Returns:
472 << TODO: Add return codes here >>
473See Also:
474 ON_Curve::IntersectSurface
475 ON_SetCurveCurveIntersectionDir
476*/
479 int xcount,
480 ON_X_EVENT* xevent,
481 double t0,
482 double t1,
483 double u0,
484 double u1,
485 double v0,
486 double v1
487 );
488
489// The ON_SSX_EVENT class is used to report surface-surface
490// intersection events.
492{
493 // NO VIRTUAL FUNCTIONS IN THIS CLASS
494public:
495 ON_SSX_EVENT();
496 ~ON_SSX_EVENT(); // deletes m_curveA, m_curveB, m_curve3d
497
498 void Dump(ON_TextLog& text_log) const;
499
500 /*
501 Description:
502 Check intersection event values to make sure they are valid.
503 Parameters:
504 text_log - [in] If not null and an error is found, then a description
505 of the error is printed to text_log.
506 intersection_tolerance - [in]
507 0.0 or value used in intersection calculation.
508 overlap_tolerance - [in]
509 0.0 or value used in intersection calculation.
510 fitting_tolerance - [in]
511 0.0 or value used in intersection calculation.
512 surfaceA - [in]
513 NULL or surfaceA passed to intersection calculation.
514 surfaceA_domain0 - [in]
515 NULL or surfaceA "u" domain used in intersection calculation.
516 surfaceA_domain1 - [in]
517 NULL or surfaceA "v" domain used in intersection calculation.
518 surfaceB - [in]
519 NULL or surfaceB passed to intersection calculation.
520 surfaceB_domain0 - [in]
521 NULL or surfaceB "u" domain used in intersection calculation.
522 surfaceB_domain1 - [in]
523 NULL or surfaceB "v" domain used in intersection calculation.
524 Returns:
525 True if event is valid.
526 */
527 bool IsValid(
528 ON_TextLog* text_log,
529 double intersection_tolerance,
530 double overlap_tolerance,
531 double fitting_tolerance,
532 const class ON_Surface* surfaceA,
533 const class ON_Interval* surfaceA_domain0,
534 const class ON_Interval* surfaceA_domain1,
535 const class ON_Surface* surfaceB,
536 const class ON_Interval* surfaceB_domain0,
537 const class ON_Interval* surfaceB_domain1
538 ) const;
539
540 /*
541 Returns:
542 True if m_type is ssx_transverse_point or ssx_tangent_point.
543 See Also:
544 ON_SSX_EVENT::IsCurveEvent
545 ON_SSX_EVENT::IsTinyEvent
546 */
547 bool IsPointEvent() const;
548
549 /*
550 Returns:
551 True if m_type is ssx_transverse or ssx_tangent.
552 See Also:
553 ON_SSX_EVENT::IsPointEvent
554 ON_SSX_EVENT::IsTinyEvent
555 */
556 bool IsCurveEvent() const;
557
558 /*
559 Description:
560 This function can be used to detect intersection events
561 that are "nearly" points.
562 Parameters:
563 tiny_tolerance - [in]
564 Returns:
565 True if
566 m_type is ssx_transverse_point or ssx_tangent_point,
567 or,
568 m_type is ssx_transverse, ssx_tangent or ssx_overlap
569 and length of the longest side of m_curve3d's
570 bounding box is <= tiny_tolerance.
571 See Also:
572 ON_SSX_EVENT::IsPointEvent
573 ON_SSX_EVENT::IsCurveEvent
574 */
575 bool IsTinyEvent(double tiny_tolerance) const;
576
577 /*
578 Returns:
579 True if m_type is ssx_tangent, or ssx_tangent_point.
580 */
581 bool IsTangentEvent() const;
582
583 /*
584 Returns:
585 True if m_type is ssx_overlap.
586 */
587 bool IsOverlapEvent() const;
588
589 // This field is a scratch field for users.
590 // The constructor sets it to zero and the
591 // intersectors never use it.
593
594 enum TYPE
595 {
596 no_ssx_event = 0,
597 ssx_transverse = 1, // transverse surface-surface intersection curve
598 ssx_tangent = 2, // tangent surface-surface intersection curve
599 ssx_overlap = 3, // overlap surface-surface intersection curve
600 ssx_transverse_point = 4, // transverse surface-surface intersection point
601 ssx_tangent_point = 5, // tangent surface-surface intersection point
602 ssx_32bit_enum = 0xFFFFFFFF
603 };
604
606
607 // If m_type = ssx_transverse, ssx_tangent, or ssx_overlap,
608 // then the intersection curves are returned here.
609 // In all cases the 3 curves are compatibly oriented.
610 // For ssx_transverse events, the 3d curve direction
611 // agrees with SurfaceNormalB x SurfaceNormalA
612 // For ssx_tangent events, the orientation is random.
613 // For ssx_overlap events, the overlap is to the left of
614 // m_curveA. These curves are deleted by ~ON_SSX_EVENT().
615 // If you want to harvest a curve for long term use, set
616 // the pointer to NULL.
617 ON_Curve* m_curveA; // 2d surface A parameter space curve
618 ON_Curve* m_curveB; // 2d surface B parameter space curve
619 ON_Curve* m_curve3d; // 3d surface B parameter space curve
620
621 // If m_type = ssx_transverse_point or ssx_tangent_point,
622 // the the points are returned here
623 ON_3dPoint m_pointA; // 2d surfaceA parameter space point with z = 0
624 ON_3dPoint m_pointB; // 2d surfaceB parameter space point with z = 0
625 ON_3dPoint m_point3d; // 3d intersection point
626};
627
628#endif
Definition opennurbs_point.h:403
Definition opennurbs_point.h:931
Definition opennurbs_curve.h:88
Definition opennurbs_point.h:46
Definition opennurbs_point.h:1169
Definition opennurbs_x.h:492
ON_3dPoint m_pointA
Definition opennurbs_x.h:623
ON_3dPoint m_pointB
Definition opennurbs_x.h:624
TYPE
Definition opennurbs_x.h:595
ON_U m_user
Definition opennurbs_x.h:592
ON_Curve * m_curveA
Definition opennurbs_x.h:617
ON_3dPoint m_point3d
Definition opennurbs_x.h:625
ON_Curve * m_curve3d
Definition opennurbs_x.h:619
TYPE m_type
Definition opennurbs_x.h:605
ON_Curve * m_curveB
Definition opennurbs_x.h:618
Definition opennurbs_surface.h:58
Definition opennurbs_textlog.h:20
Definition opennurbs_x.h:22
DIRECTION
Definition opennurbs_x.h:320
TYPE
Definition opennurbs_x.h:301
ON_U m_user
Definition opennurbs_x.h:338
TYPE m_type
Definition opennurbs_x.h:343
unsigned int m_x_eventsn
Definition opennurbs_x.h:370
#define ON_DECL
Definition opennurbs_defines.h:92
#define ON_CLASS
Definition opennurbs_defines.h:91
#define N
Definition opennurbs_rand.cpp:70
ON_DECL bool ON_SetCurveCurveIntersectionDir(ON_3dVector N, int xcount, ON_X_EVENT *xevent, double a0, double a1, double b0, double b1)
ON_DECL bool ON_SetCurveSurfaceIntersectionDir(int xcount, ON_X_EVENT *xevent, double t0, double t1, double u0, double u1, double v0, double v1)
Definition opennurbs_defines.h:270