QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
opennurbs_bezier.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_BEZIER_INC_)
17#define OPENNURBS_BEZIER_INC_
18
21class ON_BezierCurve;
23class ON_TextLog;
24class ON_NurbsCurve;
25class ON_NurbsSurface;
26class ON_X_EVENT;
27
29{
30public:
32
33 // Description:
34 // See ON_PolynomialCurve::Create.
35 // Parameters:
36 // dim - [in] dimension of the curve
37 // bIsRational - [in] true if rational
38 // order - [in] (>=2) order = degree+1
40 int dim,
41 ON_BOOL32 bIsRational,
42 int order
43 );
44
46
48
50
51 ON_PolynomialCurve& operator=(const ON_PolynomialCurve&);
52
53 ON_PolynomialCurve& operator=(const ON_BezierCurve&);
54
55 // Description:
56 // Initializes fields and allocates the m_cv array.
57 // Parameters:
58 // dim - [in] dimension of the curve
59 // bIsRational - [in] true if rational
60 // order - [in] (>=2) order = degree+1
61 ON_BOOL32 Create(
62 int dim,
63 ON_BOOL32 bIsRational,
64 int order
65 );
66
67 // Description:
68 // Deallocates the m_cv array and sets fields to zero.
69 void Destroy();
70
71 // Description:
72 // Evaluate a polynomial curve.
73 // Parameters:
74 // t - [in] evaluation parameter ( usually in Domain() ).
75 // der_count - [in] (>=0) number of derivatives to evaluate
76 // v_stride - [in] (>=Dimension()) stride to use for the v[] array
77 // v - [out] array of length (der_count+1)*v_stride
78 // curve(t) is returned in (v[0],...,v[m_dim-1]),
79 // curve'(t) is retuned in (v[v_stride],...,v[v_stride+m_dim-1]),
80 // curve"(t) is retuned in (v[2*v_stride],...,v[2*v_stride+m_dim-1]),
81 // etc.
82 // Returns:
83 // false if unable to evaluate.
84 ON_BOOL32 Evaluate(
85 double t,
86 int der_count,
87 int v_stride,
88 double* v
89 ) const;
90
91 // dimension of polynomial curve (1,2, or 3)
92 int m_dim;
93
94 // 1 if polynomial curve is rational, 0 if polynomial curve is not rational
96
97 // order (=degree+1) of polynomial
99
100 // coefficients ( m_cv.Count() = order of monomial )
102
103 // domain of polynomial
105};
106
108{
109public:
112 int, // dim,
113 ON_BOOL32, // true if rational
114 int, // "u" order
115 int // "v" order
116 );
121 ON_PolynomialSurface& operator=(const ON_BezierSurface&);
122
123 ON_BOOL32 Create(
124 int, // dim,
125 ON_BOOL32, // true if rational
126 int, // "u" order
127 int // "v" order
128 );
129 void Destroy();
130
131 ON_BOOL32 Evaluate( // returns false if unable to evaluate
132 double s,
133 double t, // evaluation parameter
134 int der_count, // number of derivatives (>=0)
135 int v_stride, // array stride (>=Dimension())
136 double* v // array of length stride*(ndir+1)*(ndir+2)/2
137 ) const;
138
139 int m_dim; // 1,2, or 3
140 int m_is_rat; // 1 if rational, 0 if not rational
141 int m_order[2];
142 ON_4dPointArray m_cv; // coefficients ( m_C.Length() = m_order[0]*m_order[1]
143 // coefficient of s^m*t^n = m_cv[m_order[1]*m+n]
144 ON_Interval m_domain[2];
145};
146
148{
149public:
150
152
153 // Description:
154 // Creates a bezier with cv memory allocated.
155 // Parameters:
156 // dim - [in] (>0) dimension of bezier curve
157 // bIsRational - [in] true for a rational bezier
158 // order - [in] (>=2) order (=degree+1) of bezier curve
160 int dim,
161 ON_BOOL32 bIsRational,
162 int order
163 );
164
168 ON_BezierCurve(const ON_2dPointArray&); // sets control points
169 ON_BezierCurve(const ON_3dPointArray&); // sets control points
170 ON_BezierCurve(const ON_4dPointArray&); // sets control points
171 ON_BezierCurve& operator=(const ON_BezierCurve&);
172 ON_BezierCurve& operator=(const ON_PolynomialCurve&);
173
174
175 ON_BezierCurve& operator=(const ON_2dPointArray&); // sets control points
176 ON_BezierCurve& operator=(const ON_3dPointArray&); // sets control points
177 ON_BezierCurve& operator=(const ON_4dPointArray&); // sets control points
178
179 bool IsValid() const;
180
181 void Dump( ON_TextLog& ) const; // for debugging
182
183 // Returns:
184 // Dimension of bezier.
185 int Dimension() const;
186
187 // Description:
188 // Creates a bezier with cv memory allocated.
189 // Parameters:
190 // dim - [in] (>0) dimension of bezier curve
191 // bIsRational - [in] true for a rational bezier
192 // order - [in] (>=2) order (=degree+1) of bezier curve
193 // Returns:
194 // true if successful.
195 bool Create(
196 int dim,
197 ON_BOOL32 bIsRational,
198 int order
199 );
200
201 // Description:
202 // Deallocates m_cv memory.
203 void Destroy();
204
205 void EmergencyDestroy(); // call if memory used by ON_NurbsCurve becomes invalid
206
207 // Description:
208 // Loft a bezier curve through a list of points.
209 // Parameters:
210 // points - [in] an array of 2 or more points to interpolate
211 // Returns:
212 // true if successful
213 // Remarks:
214 // The result has order = points.Count() and the loft uses the
215 // uniform parameterizaton curve( i/(points.Count()-1) ) = points[i].
216 bool Loft(
217 const ON_3dPointArray& points
218 );
219
220 // Description:
221 // Loft a bezier curve through a list of points.
222 // Parameters:
223 // pt_dim - [in] dimension of points to interpolate
224 // pt_count - [in] number of points (>=2)
225 // pt_stride - [in] (>=pt_dim) pt[] array stride
226 // pt - [in] array of points
227 // t_stride - [in] (>=1) t[] array stride
228 // t - [in] strictly increasing array of interpolation parameters
229 // Returns:
230 // true if successful
231 // Remarks:
232 // The result has order = points.Count() and the loft uses the
233 // parameterizaton curve( t[i] ) = points[i].
234 bool Loft(
235 int pt_dim,
236 int pt_count,
237 int pt_stride,
238 const double* pt,
239 int t_stride,
240 const double* t
241 );
242
243 // Description:
244 // Gets bounding box.
245 // Parameters:
246 // box_min - [out] minimum corner of axis aligned bounding box
247 // The box_min[] array must have size m_dim.
248 // box_max - [out] maximum corner of axis aligned bounding box
249 // The box_max[] array must have size m_dim.
250 // bGrowBox - [in] if true, input box_min/box_max must be set
251 // to valid bounding box corners and this box is enlarged to
252 // be the union of the input box and the bezier's bounding
253 // box.
254 // Returns:
255 // true if successful.
256 bool GetBBox( // returns true if successful
257 double* box_min,
258 double* box_max,
259 int bGrowBox = false
260 ) const;
261
262 // Description:
263 // Gets bounding box.
264 // Parameters:
265 // bbox - [out] axis aligned bounding box returned here.
266 // bGrowBox - [in] if true, input bbox must be a valid
267 // bounding box and this box is enlarged to
268 // be the union of the input box and the
269 // bezier's bounding box.
270 // Returns:
271 // true if successful.
272 bool GetBoundingBox(
273 ON_BoundingBox& bbox,
274 int bGrowBox = false
275 ) const;
276
277 // Description:
278 // Gets bounding box.
279 // Returns:
280 // Axis aligned bounding box.
281 ON_BoundingBox BoundingBox() const;
282
283 /*
284 Description:
285 Get tight bounding box of the bezier.
286 Parameters:
287 tight_bbox - [in/out] tight bounding box
288 bGrowBox -[in] (default=false)
289 If true and the input tight_bbox is valid, then returned
290 tight_bbox is the union of the input tight_bbox and the
291 tight bounding box of the bezier curve.
292 xform -[in] (default=NULL)
293 If not NULL, the tight bounding box of the transformed
294 bezier is calculated. The bezier curve is not modified.
295 Returns:
296 True if the returned tight_bbox is set to a valid
297 bounding box.
298 */
299 bool GetTightBoundingBox(
300 ON_BoundingBox& tight_bbox,
301 int bGrowBox = false,
302 const ON_Xform* xform = 0
303 ) const;
304
305 // Description:
306 // Transform the bezier.
307 // Parameters:
308 // xform - [in] transformation to apply to bezier
309 // Returns:
310 // true if successful. false if bezier is invalid
311 // and cannot be transformed.
312 bool Transform(
313 const ON_Xform& xform
314 );
315
316 bool Morph( const ON_SpaceMorph& morph );
317
318 // Description:
319 // Rotates the bezier curve about the specified axis. A positive
320 // rotation angle results in a counter-clockwise rotation
321 // about the axis (right hand rule).
322 // Parameters:
323 // sin_angle - [in] sine of rotation angle
324 // cos_angle - [in] sine of rotation angle
325 // rotation_axis - [in] direction of the axis of rotation
326 // rotation_center - [in] point on the axis of rotation
327 // Returns:
328 // true if bezier curve successfully rotated
329 // Remarks:
330 // Uses ON_BezierCurve::Transform() function to calculate the result.
331 bool Rotate(
332 double sin_angle,
333 double cos_angle,
334 const ON_3dVector& rotation_axis,
335 const ON_3dPoint& rotation_center
336 );
337
338 // Description:
339 // Rotates the bezier curve about the specified axis. A positive
340 // rotation angle results in a counter-clockwise rotation
341 // about the axis (right hand rule).
342 // Parameters:
343 // rotation_angle - [in] angle of rotation in radians
344 // rotation_axis - [in] direction of the axis of rotation
345 // rotation_center - [in] point on the axis of rotation
346 // Returns:
347 // true if bezier curve successfully rotated
348 // Remarks:
349 // Uses ON_BezierCurve::Transform() function to calculate the result.
350 bool Rotate(
351 double rotation_angle,
352 const ON_3dVector& rotation_axis,
353 const ON_3dPoint& rotation_center
354 );
355
356 // Description:
357 // Translates the bezier curve along the specified vector.
358 // Parameters:
359 // translation_vector - [in] translation vector
360 // Returns:
361 // true if bezier curve successfully translated
362 // Remarks:
363 // Uses ON_BezierCurve::Transform() function to calculate the result.
364 bool Translate(
365 const ON_3dVector& translation_vector
366 );
367
368 // Description:
369 // Scales the bezier curve by the specified facotor. The scale is
370 // centered at the origin.
371 // Parameters:
372 // scale_factor - [in] scale factor
373 // Returns:
374 // true if bezier curve successfully scaled
375 // Remarks:
376 // Uses ON_BezierCurve::Transform() function to calculate the result.
377 bool Scale(
378 double scale_factor
379 );
380
381 // Returns:
382 // Domain of bezier (always [0,1]).
383 ON_Interval Domain() const;
384
385 // Description:
386 // Reverses bezier by reversing the order
387 // of the control points.
388 bool Reverse();
389
390 // Description:
391 // Evaluate point at a parameter.
392 // Parameters:
393 // t - [in] evaluation parameter
394 // Returns:
395 // Point (location of curve at the parameter t).
396 ON_3dPoint PointAt(
397 double t
398 ) const;
399
400 // Description:
401 // Evaluate first derivative at a parameter.
402 // Parameters:
403 // t - [in] evaluation parameter
404 // Returns:
405 // First derivative of the curve at the parameter t.
406 // Remarks:
407 // No error handling.
408 // See Also:
409 // ON_Curve::Ev1Der
410 ON_3dVector DerivativeAt(
411 double t
412 ) const;
413
414 // Description:
415 // Evaluate unit tangent vector at a parameter.
416 // Parameters:
417 // t - [in] evaluation parameter
418 // Returns:
419 // Unit tangent vector of the curve at the parameter t.
420 // Remarks:
421 // No error handling.
422 // See Also:
423 // ON_Curve::EvTangent
424 ON_3dVector TangentAt(
425 double t
426 ) const;
427
428 // Description:
429 // Evaluate the curvature vector at a parameter.
430 // Parameters:
431 // t - [in] evaluation parameter
432 // Returns:
433 // curvature vector of the curve at the parameter t.
434 // Remarks:
435 // No error handling.
436 // See Also:
437 // ON_Curve::EvCurvature
438 ON_3dVector CurvatureAt(
439 double t
440 ) const;
441
442 // Description:
443 // Evaluate point at a parameter with error checking.
444 // Parameters:
445 // t - [in] evaluation parameter
446 // point - [out] value of curve at t
447 // Returns:
448 // false if unable to evaluate.
449 bool EvPoint(
450 double t,
451 ON_3dPoint& point
452 ) const;
453
454 // Description:
455 // Evaluate first derivative at a parameter with error checking.
456 // Parameters:
457 // t - [in] evaluation parameter
458 // point - [out] value of curve at t
459 // first_derivative - [out] value of first derivative at t
460 // Returns:
461 // false if unable to evaluate.
462 bool Ev1Der(
463 double t,
464 ON_3dPoint& point,
465 ON_3dVector& first_derivative
466 ) const;
467
468 // Description:
469 // Evaluate second derivative at a parameter with error checking.
470 // Parameters:
471 // t - [in] evaluation parameter
472 // point - [out] value of curve at t
473 // first_derivative - [out] value of first derivative at t
474 // second_derivative - [out] value of second derivative at t
475 // Returns:
476 // false if unable to evaluate.
477 bool Ev2Der(
478 double t,
479 ON_3dPoint& point,
480 ON_3dVector& first_derivative,
481 ON_3dVector& second_derivative
482 ) const;
483
484 /*
485 Description:
486 Evaluate unit tangent at a parameter with error checking.
487 Parameters:
488 t - [in] evaluation parameter
489 point - [out] value of curve at t
490 tangent - [out] value of unit tangent
491 Returns:
492 false if unable to evaluate.
493 See Also:
494 ON_Curve::TangentAt
495 ON_Curve::Ev1Der
496 */
497 bool EvTangent(
498 double t,
499 ON_3dPoint& point,
500 ON_3dVector& tangent
501 ) const;
502
503 /*
504 Description:
505 Evaluate unit tangent and curvature at a parameter with error checking.
506 Parameters:
507 t - [in] evaluation parameter
508 point - [out] value of curve at t
509 tangent - [out] value of unit tangent
510 kappa - [out] value of curvature vector
511 Returns:
512 false if unable to evaluate.
513 */
514 bool EvCurvature(
515 double t,
516 ON_3dPoint& point,
517 ON_3dVector& tangent,
518 ON_3dVector& kappa
519 ) const;
520
521 // Description:
522 // Evaluate a bezier.
523 // Parameters:
524 // t - [in] evaluation parameter (usually 0 <= t <= 1)
525 // der_count - [in] (>=0) number of derivatives to evaluate
526 // v_stride - [in] (>=m_dim) stride to use for the v[] array
527 // v - [out] array of length (der_count+1)*v_stride
528 // bez(t) is returned in (v[0],...,v[m_dim-1]),
529 // bez'(t) is retuned in (v[v_stride],...,v[v_stride+m_dim-1]),
530 // bez"(t) is retuned in (v[2*v_stride],...,v[2*v_stride+m_dim-1]),
531 // etc.
532 // Returns:
533 // true if successful
534 bool Evaluate(
535 double t,
536 int der_count,
537 int v_stride,
538 double* v
539 ) const;
540
541 // Description:
542 // Get ON_NurbsCurve form of a bezier.
543 // Parameters:
544 // nurbs_curve - [out] NURBS curve form of a bezier.
545 // The domain is [0,1].
546 // Returns:
547 // true if successful
548 bool GetNurbForm(
549 ON_NurbsCurve& nurbs_curve
550 ) const;
551
552 // Returns:
553 // true if bezier is rational.
554 bool IsRational() const;
555
556 // Returns:
557 // Number of doubles per control vertex.
558 // (= IsRational() ? Dim()+1 : Dim())
559 int CVSize() const;
560
561 // Returns:
562 // Number of control vertices in the bezier.
563 // This is always the same as the order of the bezier.
564 int CVCount() const;
565
566 // Returns:
567 // Order of the bezier. (order=degree+1)
568 int Order() const; // order = degree + 1
569
570 // Returns:
571 // Degree of the bezier. (degree=order-1)
572 int Degree() const;
573
574 /*
575 Description:
576 Expert user function to get a pointer to control vertex
577 memory. If you are not an expert user, please use
578 ON_BezierCurve::GetCV( ON_3dPoint& ) or
579 ON_BezierCurve::GetCV( ON_4dPoint& ).
580 Parameters:
581 cv_index - [in] (0 <= cv_index < m_order)
582 Returns:
583 Pointer to control vertex.
584 Remarks:
585 If the Bezier curve is rational, the format of the
586 returned array is a homogeneos rational point with
587 length m_dim+1. If the Bezier curve is not rational,
588 the format of the returned array is a nonrational
589 euclidean point with length m_dim.
590 See Also
591 ON_BezierCurve::CVStyle
592 ON_BezierCurve::GetCV
593 ON_BezierCurve::Weight
594 */
595 double* CV(
596 int cv_index
597 ) const;
598
599 /*
600 Description:
601 Returns the style of control vertices in the m_cv array.
602 Returns:
603 @untitled table
604 ON::not_rational m_is_rat is false
605 ON::homogeneous_rational m_is_rat is true
606 */
607 ON::point_style CVStyle() const;
608
609 // Parameters:
610 // cv_index - [in] control vertex index (0<=i<m_order)
611 // Returns:
612 // Weight of the i-th control vertex.
613 double Weight(
614 int cv_index
615 ) const;
616
617 // Description:
618 // Set weight of a control vertex.
619 // Parameters:
620 // cv_index - [in] control vertex index (0 <= cv_index < m_order)
621 // weight - [in] weight
622 // Returns:
623 // true if the weight can be set. If weight is not 1 and
624 // the bezier is not rational, then false is returned.
625 // Use ON_BezierCurve::MakeRational to make a bezier curve
626 // rational.
627 // See Also:
628 // ON_BezierCurve::SetCV, ON_BezierCurve::MakeRational,
629 // ON_BezierCurve::IsRational, ON_BezierCurve::Weight
630 bool SetWeight(
631 int cv_index,
632 double weight
633 );
634
635 // Description:
636 // Set control vertex
637 // Parameters:
638 // cv_index - [in] control vertex index (0 <= cv_index < m_order)
639 // pointstyle - [in] specifes what kind of values are passed
640 // in the cv array.
641 // ON::not_rational
642 // cv[] is an array of length m_dim that defines
643 // a euclidean (world coordinate) point
644 // ON::homogeneous_rational
645 // cv[] is an array of length (m_dim+1) that defines
646 // a rational homogeneous point.
647 // ON::euclidean_rational
648 // cv[] is an array of length (m_dim+1). The first
649 // m_dim values define the euclidean (world coordinate)
650 // location of the point. cv[m_dim] is the weight
651 // ON::intrinsic_point_style
652 // If m_is_rat is true, cv[] has ON::homogeneous_rational
653 // point style. If m_is_rat is false, cv[] has
654 // ON::not_rational point style.
655 // cv - [in] array with control vertex value.
656 // Returns:
657 // true if the point can be set.
658 bool SetCV(
659 int cv_index,
660 ON::point_style pointstyle,
661 const double* cv
662 );
663
664 // Description:
665 // Set location of a control vertex.
666 // Parameters:
667 // cv_index - [in] control vertex index (0 <= cv_index < m_order)
668 // point - [in] control vertex location. If the bezier
669 // is rational, the weight will be set to 1.
670 // Returns:
671 // true if successful.
672 // See Also:
673 // ON_BezierCurve::CV, ON_BezierCurve::SetCV,
674 // ON_BezierCurve::SetWeight, ON_BezierCurve::Weight
675 bool SetCV(
676 int cv_index,
677 const ON_3dPoint& point
678 );
679
680 // Description:
681 // Set value of a control vertex.
682 // Parameters:
683 // cv_index - [in] control vertex index (0 <= cv_index < m_order)
684 // point - [in] control vertex value. If the bezier
685 // is not rational, the euclidean location of
686 // homogenoeous point will be used.
687 // Returns:
688 // true if successful.
689 // See Also:
690 // ON_BezierCurve::CV, ON_BezierCurve::SetCV,
691 // ON_BezierCurve::SetWeight, ON_BezierCurve::Weight
692 bool SetCV(
693 int cv_index,
694 const ON_4dPoint& point
695 );
696
697 // Description:
698 // Get location of a control vertex.
699 // Parameters:
700 // cv_index - [in] control vertex index (0 <= cv_index < m_order)
701 // pointstyle - [in] specifes what kind of values to get
702 // ON::not_rational
703 // cv[] is an array of length m_dim that defines
704 // a euclidean (world coordinate) point
705 // ON::homogeneous_rational
706 // cv[] is an array of length (m_dim+1) that defines
707 // a rational homogeneous point.
708 // ON::euclidean_rational
709 // cv[] is an array of length (m_dim+1). The first
710 // m_dim values define the euclidean (world coordinate)
711 // location of the point. cv[m_dim] is the weight
712 // ON::intrinsic_point_style
713 // If m_is_rat is true, cv[] has ON::homogeneous_rational
714 // point style. If m_is_rat is false, cv[] has
715 // ON::not_rational point style.
716 // cv - [out] array with control vertex value.
717 // Returns:
718 // true if successful. false if cv_index is invalid.
719 bool GetCV(
720 int cv_index,
721 ON::point_style pointstyle,
722 double* cv
723 ) const;
724
725 // Description:
726 // Get location of a control vertex.
727 // Parameters:
728 // cv_index - [in] control vertex index (0 <= cv_index < m_order)
729 // point - [out] Location of control vertex. If the bezier
730 // is rational, the euclidean location is returned.
731 // Returns:
732 // true if successful.
733 bool GetCV(
734 int cv_index,
735 ON_3dPoint& point
736 ) const;
737
738 // Description:
739 // Get value of a control vertex.
740 // Parameters:
741 // cv_index - [in] control vertex index (0 <= cv_index < m_order)
742 // point - [out] Homogenous value of control vertex.
743 // If the bezier is not rational, the weight is 1.
744 // Returns:
745 // true if successful.
746 bool GetCV(
747 int cv_index,
748 ON_4dPoint& point
749 ) const;
750
751 // Description:
752 // Zeros control vertices and, if rational, sets weights to 1.
753 bool ZeroCVs();
754
755 // Description:
756 // Make beizer rational.
757 // Returns:
758 // true if successful.
759 // See Also:
760 // ON_Bezier::MakeNonRational
761 bool MakeRational();
762
763 // Description:
764 // Make beizer not rational by setting all control
765 // vertices to their euclidean locations and setting
766 // m_is_rat to false.
767 // See Also:
768 // ON_Bezier::MakeRational
769 bool MakeNonRational();
770
771 // Description:
772 // Increase degree of bezier.
773 // Parameters:
774 // desired_degree - [in]
775 // Returns:
776 // true if successful. false if desired_degree < current degree.
777 bool IncreaseDegree(
778 int desired_degree
779 );
780
781 // Description:
782 // Change dimension of bezier.
783 // Parameters:
784 // desired_dimension - [in]
785 // Returns:
786 // true if successful. false if desired_dimension < 1
787 bool ChangeDimension(
788 int desired_dimension
789 );
790
792 // Tools for managing CV and knot memory
793
794 // Description:
795 // Make sure m_cv array has a certain length.
796 // Parameters:
797 // desired_cv_capacity - [in] minimum length of m_cv array.
798 // Returns:
799 // true if successful.
800 bool ReserveCVCapacity(
801 int desired_cv_capacity
802 );
803
804 // Description:
805 // Trims (or extends) the bezier so the bezier so that the
806 // result starts bezier(interval[0]) and ends at
807 // bezier(interval[1]) (Evaluation performed on input bezier.)
808 // Parameters:
809 // interval -[in]
810 // Example:
811 // An interval of [0,1] leaves the bezier unchanged. An
812 // interval of [0.5,1] would trim away the left half. An
813 // interval of [0.0,2.0] would extend the right end.
814 bool Trim(
815 const ON_Interval& interval
816 );
817
818 // Description:
819 // Split() divides the Bezier curve at the specified parameter.
820 // The parameter must satisfy 0 < t < 1. You may pass *this as
821 // one of the curves to be returned.
822 // Parameters:
823 // t - [in] (0 < t < 1 ) parameter to split at
824 // left_side - [out]
825 // right_side - [out]
826 // Example:
827 // ON_BezierCurve crv = ...;
828 // ON_BezierCurve right_side;
829 // crv.Split( 0.5, crv, right_side );
830 // would split crv at the 1/2, put the left side in crv,
831 // and return the right side in right_side.
832 bool Split(
833 double t,
834 ON_BezierCurve& left_side,
835 ON_BezierCurve& right_side
836 ) const;
837
838 // Description:
839 // returns the length of the control polygon
840 double ControlPolygonLength() const;
841
842 /*
843 Description:
844 Use a linear fractional tranformation for [0,1] to reparameterize
845 the bezier. The locus of the curve is not changed, but the
846 parameterization is changed.
847 Parameters:
848 c - [in]
849 reparameterization constant (generally speaking, c should be > 0).
850 If c != 1, then the returned bezier will be rational.
851 Returns:
852 true if successful.
853 Remarks:
854 The reparameterization is performed by composing the input Bezier with
855 the function lambda: [0,1] -> [0,1] given by
856
857 t -> c*t / ( (c-1)*t + 1 )
858
859 Note that lambda(0) = 0, lambda(1) = 1, lambda'(t) > 0,
860 lambda'(0) = c and lambda'(1) = 1/c.
861
862 If the input Bezier has control vertices {B_0, ..., B_d}, then the
863 output Bezier has control vertices
864
865 (B_0, ... c^i * B_i, ..., c^d * B_d).
866
867 To derive this formula, simply compute the i-th Bernstein polynomial
868 composed with lambda().
869
870 The inverse parameterization is given by 1/c. That is, the
871 cumulative effect of the two calls
872
873 Reparameterize(c)
874 Reparameterize(1.0/c)
875
876 is to leave the bezier unchanged.
877 See Also:
878 ON_Bezier::ScaleConrolPoints
879 */
880 bool Reparameterize(
881 double c
882 );
883
884 // misspelled function name is obsolete
885 ON_DEPRECATED bool Reparametrize(double);
886
887 /*
888 Description:
889 Scale a rational Bezier's control vertices to set a weight to a
890 specified value.
891 Parameters:
892 i - [in] (0 <= i < order)
893 w - [in] w != 0.0
894 Returns:
895 True if successful. The i-th control vertex will have weight w.
896 Remarks:
897 Each control point is multiplied by w/w0, where w0 is the
898 input value of Weight(i).
899 See Also:
900 ON_Bezier::Reparameterize
901 ON_Bezier::ChangeWeights
902 */
903 bool ScaleConrolPoints(
904 int i,
905 double w
906 );
907
908 /*
909 Description:
910 Use a combination of scaling and reparameterization to set two
911 rational Bezier weights to specified values.
912 Parameters:
913 i0 - [in] control point index (0 <= i0 < order, i0 != i1)
914 w0 - [in] Desired weight for i0-th control point
915 i1 - [in] control point index (0 <= i1 < order, i0 != i1)
916 w1 - [in] Desired weight for i1-th control point
917 Returns:
918 True if successful. The returned bezier has the same locus but
919 probably has a different parameterization.
920 Remarks:
921 The i0-th cv will have weight w0 and the i1-rst cv will have
922 weight w1. If v0 and v1 are the cv's input weights,
923 then v0, v1, w0 and w1 must all be nonzero, and w0*v0
924 and w1*v1 must have the same sign.
925
926 The equations
927
928 s * r^i0 = w0/v0
929 s * r^i1 = w1/v1
930
931 determine the scaling and reparameterization necessary to
932 change v0,v1 to w0,w1.
933
934 If the input Bezier has control vertices
935
936 (B_0, ..., B_d),
937
938 then the output Bezier has control vertices
939
940 (s*B_0, ... s*r^i * B_i, ..., s*r^d * B_d).
941 See Also:
942 ON_Bezier::Reparameterize
943 ON_Bezier::ScaleConrolPoints
944 */
945 bool ChangeWeights(
946 int i0,
947 double w0,
948 int i1,
949 double w1
950 );
951
952 /*
953 Description:
954 Get the parameter of the point on the bezier curve
955 that is closest to the point P.
956 Parameters:
957 P - [in]
958 t - [out]
959 Closest point parameter.
960 maximum_distance - [in]
961 If maximum_distance > 0.0, then an answer is returned
962 only if the distance from the bezier curve to P
963 is <= maximum_distance. If maximum_distance <= 0.0,
964 then maximum_distance is ignored.
965 sub_domain - [in]
966 If not NULL, the search is confined to the intersection
967 of the sub_domain interval and (0,1).
968 Returns:
969 True if a point is found.
970 See Also:
971 ON_CurveTreeNode::GetClosestPoint
972 Remarks:
973 This function is not efficient if you will be finding
974 multiple closest points to the same bezier. To efficiently
975 find multiple closest points, make a curve tree and use it.
976 See the ON_BezierCurve::GetClosestPoint code for an example.
977 */
978 bool GetClosestPoint(
979 ON_3dPoint P,
980 double* t,
981 double maximum_distance = 0.0,
982 const ON_Interval* sub_domain = 0
983 ) const;
984
985
986 /*
987 Description:
988 Get the parameter of the point on the bezier curve
989 that is locally closest to the point P when the search
990 begins at seed_parameter.
991 Parameters:
992 P - [in]
993 seed_parameter - [in]
994 Parameter where the search begins.
995 t - [out]
996 Closest point parameter.
997 sub_domain - [in]
998 If not NULL, the search is confined to the intersection
999 of the sub_domain interval and (0,1).
1000 Returns:
1001 True if a point is found.
1002 */
1003 bool GetLocalClosestPoint(
1004 ON_3dPoint P,
1005 double seed_parameter,
1006 double* t,
1007 const ON_Interval* sub_domain = 0
1008 ) const;
1009
1010
1011 /*
1012 Description:
1013 Get a local curve-curve intersection point.
1014 Parameters:
1015 other_bezcrv - [in] other curve
1016 this_seed_t - [in] this curve seed paramter
1017 other_seed_t - [in] other curve seed paramter
1018 this_t - [out] this curve paramter
1019 other_t - [out] other curve paramter
1020 this_domain - [in] optional this curve domain restriction
1021 other_domain - [in] optional other curve domain restriction
1022 Returns:
1023 True if something is returned in (t,u,v). Check
1024 answer.
1025 */
1026 bool GetLocalCurveIntersection(
1027 const ON_BezierCurve* other_bezcrv,
1028 double this_seed_t,
1029 double other_seed_t,
1030 double* this_t,
1031 double* other_t,
1032 const ON_Interval* this_domain = 0,
1033 const ON_Interval* other_domain = 0
1034 ) const;
1035
1036 /*
1037 Description:
1038 Find bezier self intersection points.
1039 Parameters:
1040 x - [out]
1041 Intersection events are appended to this array.
1042 intersection_tolerance - [in]
1043 Returns:
1044 Number of intersection events appended to x.
1045 */
1046 int IntersectSelf(
1048 double intersection_tolerance = 0.0
1049 ) const;
1050
1051 /*
1052 Description:
1053 Intersect this bezier with bezierB.
1054 Parameters:
1055 curveB - [in]
1056 x - [out] Intersection events are appended to this array.
1057 intersection_tolerance - [in] If the distance from a point
1058 on this curve to curveB is <= intersection tolerance,
1059 then the point will be part of an intersection event.
1060 If the input intersection_tolerance <= 0.0, then 0.001 is used.
1061 overlap_tolerance - [in] If t1 and t2 are parameters of this
1062 curve's intersection events and the distance from curve(t) to
1063 curveB is <= overlap_tolerance for every t1 <= t <= t2,
1064 then the event will be returened as an overlap event.
1065 If the input overlap_tolerance <= 0.0, then
1066 intersection_tolerance*2.0 is used.
1067 curveA_domain - [in] optional restriction on this bezier's domain
1068 curveB_domain - [in] optional restriction on bezierB domain
1069 Returns:
1070 Number of intersection events appended to x.
1071 Remarks:
1072 If you are performing more than one intersection,
1073 you should create curve trees and intersect them.
1074 See the IntersectBezierCurve code for an example.
1075 */
1076 int IntersectCurve(
1077 const ON_BezierCurve* bezierB,
1079 double intersection_tolerance = 0.0,
1080 double overlap_tolerance = 0.0,
1081 const ON_Interval* bezierA_domain = 0,
1082 const ON_Interval* bezierB_domain = 0
1083 ) const;
1084
1085 /*
1086 Description:
1087 Get a local curve-surface intersection point.
1088 Parameters:
1089 bezsrf - [in]
1090 seed_t - [in] curve paramter
1091 seed_u - [in] surface parameter
1092 seed_v - [in] surface parameter
1093 t - [out] curve paramter
1094 u - [out] surface parameter
1095 v - [out] surface parameter
1096 tdomain - [in] optional curve domain restriction
1097 udomain - [in] optional surface domain restriction
1098 vdomain - [in] optional surface domain restriction
1099 Returns:
1100 True if something is returned in (t,u,v). Check
1101 answer.
1102 */
1103 bool GetLocalSurfaceIntersection(
1104 const ON_BezierSurface* bezsrf,
1105 double seed_t,
1106 double seed_u,
1107 double seed_v,
1108 double* t,
1109 double* u,
1110 double* v,
1111 const ON_Interval* tdomain = 0,
1112 const ON_Interval* udomain = 0,
1113 const ON_Interval* vdomain = 0
1114 ) const;
1115
1116
1117 /*
1118 Description:
1119 Intersect this bezier curve with bezsrfB.
1120 Parameters:
1121 bezsrfB - [in]
1122 x - [out] Intersection events are appended to this array.
1123 intersection_tolerance - [in] If the distance from a point
1124 on this curve to the surface is <= intersection tolerance,
1125 then the point will be part of an intersection event.
1126 If the input intersection_tolerance <= 0.0, then 0.001 is used.
1127 overlap_tolerance - [in] If t1 and t2 are curve parameters of
1128 intersection events and the distance from curve(t) to the
1129 surface is <= overlap_tolerance for every t1 <= t <= t2,
1130 then the event will be returened as an overlap event.
1131 If the input overlap_tolerance <= 0.0, then
1132 intersection_tolerance*2.0 is used.
1133 curveA_domain - [in] optional restriction on this curve's domain
1134 surfaceB_udomain - [in] optional restriction on surfaceB u domain
1135 surfaceB_vdomain - [in] optional restriction on surfaceB v domain
1136 Returns:
1137 Number of intersection events appended to x.
1138 Remarks:
1139 If you are performing more than one intersection,
1140 you should create curve and surface trees and
1141 intersect them. See the IntersectBezierSurface code
1142 for an example.
1143 */
1144 int IntersectSurface(
1145 const ON_BezierSurface* bezsrfB,
1147 double intersection_tolerance = 0.0,
1148 double overlap_tolerance = 0.0,
1149 const ON_Interval* bezierA_domain = 0,
1150 const ON_Interval* bezsrfB_udomain = 0,
1151 const ON_Interval* bezsrfB_vdomain = 0
1152 ) const;
1153
1154
1156 // Implementation
1157public:
1158 // NOTE: These members are left "public" so that expert users may efficiently
1159 // create bezier curves using the default constructor and borrow the
1160 // knot and CV arrays from their native NURBS representation.
1161 // No technical support will be provided for users who access these
1162 // members directly. If you can't get your stuff to work, then use
1163 // the constructor with the arguments and the SetKnot() and SetCV()
1164 // functions to fill in the arrays.
1165
1166
1167 // dimension of bezier (>=1)
1169
1170 // 1 if bezier is rational, 0 if bezier is not rational
1172
1173 // order = degree+1
1175
1176 // Number of doubles per cv ( >= ((m_is_rat)?m_dim+1:m_dim) )
1178
1179 // The i-th cv begins at cv[i*m_cv_stride].
1180 double* m_cv;
1181
1182 // Number of doubles in m_cv array. If m_cv_capacity is zero
1183 // and m_cv is not NULL, an expert user is managing the m_cv
1184 // memory. ~ON_BezierCurve will not deallocate m_cv unless
1185 // m_cv_capacity is greater than zero.
1187
1188#if 8 == ON_SIZEOF_POINTER
1189 // pad to a multiple of 8 bytes so custom allocators
1190 // will keep m_cv aligned and tail-padding reuse will
1191 // not be an issue.
1192 int m_reserved_ON_BezierCurve;
1193#endif
1194};
1195
1196
1198{
1199public:
1202 int dim,
1203 int is_rat,
1204 int order0,
1205 int order1
1206 );
1207
1211 ON_BezierSurface& operator=(const ON_BezierSurface&);
1212 ON_BezierSurface& operator=(const ON_PolynomialSurface&);
1213
1214 bool IsValid() const;
1215 void Dump( ON_TextLog& ) const; // for debugging
1216 int Dimension() const;
1217
1218 bool Create(
1219 int dim,
1220 int is_rat,
1221 int order0,
1222 int order1
1223 );
1224
1225 void Destroy();
1226 void EmergencyDestroy(); // call if memory used by ON_NurbsCurve becomes invalid
1227
1228 /*
1229 Description:
1230 Loft a bezier surface through a list of bezier curves.
1231 Parameters:
1232 curve_list - [in] list of curves that have the same degree.
1233 Returns:
1234 True if successful.
1235 */
1236 bool Loft( const ON_ClassArray<ON_BezierCurve>& curve_list );
1237
1238 /*
1239 Description:
1240 Loft a bezier surface through a list of bezier curves.
1241 Parameters:
1242 curve_count - [in] number of curves in curve_list
1243 curve_list - [in] array of pointers to curves that have the same degree.
1244 Returns:
1245 True if successful.
1246 */
1247 bool Loft(
1248 int count,
1249 const ON_BezierCurve* const* curve_list
1250 );
1251
1252 bool GetBBox( // returns true if successful
1253 double*, // minimum
1254 double*, // maximum
1255 int bGrowBox = false // true means grow box
1256 ) const;
1257
1258 bool GetBoundingBox(
1259 ON_BoundingBox& bbox,
1260 int bGrowBox
1261 ) const;
1262
1263 ON_BoundingBox BoundingBox() const;
1264
1265 bool Transform(
1266 const ON_Xform&
1267 );
1268
1269 bool Morph( const ON_SpaceMorph& morph );
1270
1271 // Description:
1272 // Rotates the bezier surface about the specified axis. A positive
1273 // rotation angle results in a counter-clockwise rotation
1274 // about the axis (right hand rule).
1275 // Parameters:
1276 // sin_angle - [in] sine of rotation angle
1277 // cos_angle - [in] sine of rotation angle
1278 // rotation_axis - [in] direction of the axis of rotation
1279 // rotation_center - [in] point on the axis of rotation
1280 // Returns:
1281 // true if bezier surface successfully rotated
1282 // Remarks:
1283 // Uses ON_BezierSurface::Transform() function to calculate the result.
1284 bool Rotate(
1285 double sin_angle,
1286 double cos_angle,
1287 const ON_3dVector& rotation_axis,
1288 const ON_3dPoint& rotation_center
1289 );
1290
1291 // Description:
1292 // Rotates the bezier surface about the specified axis. A positive
1293 // rotation angle results in a counter-clockwise rotation
1294 // about the axis (right hand rule).
1295 // Parameters:
1296 // rotation_angle - [in] angle of rotation in radians
1297 // rotation_axis - [in] direction of the axis of rotation
1298 // rotation_center - [in] point on the axis of rotation
1299 // Returns:
1300 // true if bezier surface successfully rotated
1301 // Remarks:
1302 // Uses ON_BezierSurface::Transform() function to calculate the result.
1303 bool Rotate(
1304 double rotation_angle,
1305 const ON_3dVector& rotation_axis,
1306 const ON_3dPoint& rotation_center
1307 );
1308
1309 // Description:
1310 // Translates the bezier surface along the specified vector.
1311 // Parameters:
1312 // translation_vector - [in] translation vector
1313 // Returns:
1314 // true if bezier surface successfully translated
1315 // Remarks:
1316 // Uses ON_BezierSurface::Transform() function to calculate the result.
1317 bool Translate(
1318 const ON_3dVector& translation_vector
1319 );
1320
1321 // Description:
1322 // Scales the bezier surface by the specified facotor. The scale is
1323 // centered at the origin.
1324 // Parameters:
1325 // scale_factor - [in] scale factor
1326 // Returns:
1327 // true if bezier surface successfully scaled
1328 // Remarks:
1329 // Uses ON_BezierSurface::Transform() function to calculate the result.
1330 bool Scale(
1331 double scale_factor
1332 );
1333
1334 ON_Interval Domain(
1335 int // 0 = "u" domain, 1 = "v" domain
1336 ) const;
1337
1338 bool Reverse( int ); // reverse parameterizatrion
1339 // Domain changes from [a,b] to [-b,-a]
1340
1341 bool Transpose(); // transpose surface parameterization (swap "s" and "t")
1342
1343 bool Evaluate( // returns false if unable to evaluate
1344 double, double, // evaluation parameter
1345 int, // number of derivatives (>=0)
1346 int, // array stride (>=Dimension())
1347 double* // array of length stride*(ndir+1)*(ndir+2)/2
1348 ) const;
1349
1350 ON_3dPoint PointAt(double s, double t) const;
1351
1352 bool GetNurbForm( ON_NurbsSurface& ) const;
1353
1354 bool IsRational() const; // true if NURBS curve is rational
1355
1356 int CVSize() const; // number of doubles per control vertex
1357 // = IsRational() ? Dim()+1 : Dim()
1358
1359 int Order( // order = degree + 1
1360 int // dir
1361 ) const;
1362
1363 int Degree( // degree = order - 1
1364 int // dir
1365 ) const;
1366
1367 /*
1368 Description:
1369 Expert user function to get a pointer to control vertex
1370 memory. If you are not an expert user, please use
1371 ON_BezierSurface::GetCV( ON_3dPoint& ) or
1372 ON_BezierSurface::GetCV( ON_4dPoint& ).
1373 Parameters:
1374 cv_index0 - [in] (0 <= cv_index0 < m_order[0])
1375 cv_index1 - [in] (0 <= cv_index1 < m_order[1])
1376 Returns:
1377 Pointer to control vertex.
1378 Remarks:
1379 If the Bezier surface is rational, the format of the
1380 returned array is a homogeneos rational point with
1381 length m_dim+1. If the Bezier surface is not rational,
1382 the format of the returned array is a nonrational
1383 euclidean point with length m_dim.
1384 See Also
1385 ON_BezierSurface::CVStyle
1386 ON_BezierSurface::GetCV
1387 ON_BezierSurface::Weight
1388 */
1389 double* CV(
1390 int cv_index0,
1391 int cv_index1
1392 ) const;
1393
1394 /*
1395 Description:
1396 Returns the style of control vertices in the m_cv array.
1397 Returns:
1398 @untitled table
1399 ON::not_rational m_is_rat is false
1400 ON::homogeneous_rational m_is_rat is true
1401 */
1402 ON::point_style CVStyle() const;
1403
1404 double Weight( // get value of control vertex weight
1405 int,int // CV index ( >= 0 and < CVCount() )
1406 ) const;
1407
1408 bool SetWeight( // set value of control vertex weight
1409 int,int, // CV index ( >= 0 and < CVCount() )
1410 double
1411 );
1412
1413 bool SetCV( // set a single control vertex
1414 int,int, // CV index ( >= 0 and < CVCount() )
1415 ON::point_style, // style of input point
1416 const double* // value of control vertex
1417 );
1418
1419 bool SetCV( // set a single control vertex
1420 int,int, // CV index ( >= 0 and < CVCount() )
1421 const ON_3dPoint& // value of control vertex
1422 // If NURBS is rational, weight
1423 // will be set to 1.
1424 );
1425
1426 bool SetCV( // set a single control vertex
1427 int,int, // CV index ( >= 0 and < CVCount() )
1428 const ON_4dPoint& // value of control vertex
1429 // If NURBS is not rational, euclidean
1430 // location of homogeneous point will
1431 // be used.
1432 );
1433
1434 bool GetCV( // get a single control vertex
1435 int,int, // CV index ( >= 0 and < CVCount() )
1436 ON::point_style, // style to use for output point
1437 double* // array of length >= CVSize()
1438 ) const;
1439
1440 bool GetCV( // get a single control vertex
1441 int,int, // CV index ( >= 0 and < CVCount() )
1442 ON_3dPoint& // gets euclidean cv when NURBS is rational
1443 ) const;
1444
1445 bool GetCV( // get a single control vertex
1446 int,int, // CV index ( >= 0 and < CVCount() )
1447 ON_4dPoint& // gets homogeneous cv
1448 ) const;
1449
1450 bool ZeroCVs(); // zeros control vertices and, if rational, sets weights to 1
1451
1452 bool MakeRational();
1453
1454 bool MakeNonRational();
1455
1456 bool Split(
1457 int, // 0 split at "u"=t, 1= split at "v"=t
1458 double, // t = splitting parameter must 0 < t < 1
1459 ON_BezierSurface&, // west/south side returned here (can pass *this)
1460 ON_BezierSurface& // east/north side returned here (can pass *this)
1461 ) const;
1462
1463 bool Trim(
1464 int dir,
1465 const ON_Interval& domain
1466 );
1467
1468 // returns the isocurve.
1469 ON_BezierCurve* IsoCurve(
1470 int dir, // 0 first parameter varies and second parameter is constant
1471 // e.g., point on IsoCurve(0,c) at t is srf(t,c)
1472 // 1 first parameter is constant and second parameter varies
1473 // e.g., point on IsoCurve(1,c) at t is srf(c,t)
1474 double c, // value of constant parameter
1475 ON_BezierCurve* iso=NULL // When NULL result is constructed on the heap.
1476 ) const;
1477
1478 bool IsSingular( // true if surface side is collapsed to a point
1479 int // side of parameter space to test
1480 // 0 = south, 1 = east, 2 = north, 3 = west
1481 ) const;
1482
1483
1485 // Tools for managing CV and knot memory
1486 bool ReserveCVCapacity(
1487 int // number of doubles to reserve
1488 );
1489
1490
1491 /*
1492 Description:
1493 Get the parameters of the point on the bezier surface
1494 that is closest to the point P.
1495 Parameters:
1496 P - [in]
1497 s - [out]
1498 t - [out]
1499 Closest point parameters.
1500 maximum_distance - [in]
1501 If maximum_distance > 0.0, then an answer is returned
1502 only if the distance from the bezier surface to P
1503 is <= maximum_distance. If maximum_distance <= 0.0,
1504 then maximum_distance is ignored.
1505 sub_domain0 - [in]
1506 If not NULL, the search is confined to "s" parameters
1507 in the intersection of the sub_domain0 interval and (0,1).
1508 sub_domain1 - [in]
1509 If not NULL, the search is confined to "t" parameters
1510 in the intersection of the sub_domain1 interval and (0,1).
1511 Returns:
1512 True if a point is found.
1513 See Also:
1514 ON_SurfaceTreeNode::GetClosestPoint
1515 Remarks:
1516 This function is not efficient if you will be finding
1517 multiple closest points to the same bezier. To efficiently
1518 find multiple closest points, make a surface tree and use it.
1519 See the ON_BezierSurface::GetClosestPoint code for an example.
1520 */
1521 bool GetClosestPoint(
1522 ON_3dPoint P,
1523 double* s,
1524 double* t,
1525 double maximum_distance = 0.0,
1526 const ON_Interval* sub_domain0 = 0,
1527 const ON_Interval* sub_domain1 = 0
1528 ) const;
1529
1530 /*
1531 Description:
1532 Get the parameter of the point on the bezier surface
1533 that is locally closest to the point P when the search
1534 begins at (s_seed,t_seed).
1535 Parameters:
1536 P - [in]
1537 s_seed - [in]
1538 t_seed - [in]
1539 Parameters where the search begins.
1540 s - [out]
1541 t - [out]
1542 Closest point parameter.
1543 sub_domain0 - [in]
1544 If not NULL, the search is confined to "s" parameters
1545 in the intersection of the sub_domain0 interval and (0,1).
1546 sub_domain1 - [in]
1547 If not NULL, the search is confined to "t" parameters
1548 in the intersection of the sub_domain1 interval and (0,1).
1549 Returns:
1550 True if a point is found.
1551 */
1552 bool GetLocalClosestPoint(
1553 ON_3dPoint P,
1554 double s_seed,
1555 double t_seed,
1556 double* s,
1557 double* t,
1558 const ON_Interval* sub_domain0 = 0,
1559 const ON_Interval* sub_domain1 = 0
1560 ) const;
1561
1563 // Implementation
1564public:
1565 // NOTE: These members are left "public" so that expert users may efficiently
1566 // create bezier curves using the default constructor and borrow the
1567 // knot and CV arrays from their native NURBS representation.
1568 // No technical support will be provided for users who access these
1569 // members directly. If you can't get your stuff to work, then use
1570 // the constructor with the arguments and the SetKnot() and SetCV()
1571 // functions to fill in the arrays.
1572
1573
1574 int m_dim; // >= 1
1575 int m_is_rat; // 0 = no, 1 = yes
1576 int m_order[2]; // order = degree+1 >= 2
1577 int m_cv_stride[2];
1578 double* m_cv;
1579 int m_cv_capacity; // if 0, then destructor does not free m_cv
1580#if 8 == ON_SIZEOF_POINTER
1581 // pad to a multiple of 8 bytes so custom allocators
1582 // will keep m_cv aligned and tail-padding reuse will
1583 // not be an issue.
1584 int m_reserved_ON_BezierSurface;
1585#endif
1586};
1587
1588
1589
1590
1592{
1593public:
1594 ON_BezierCage();
1595
1597 int dim,
1598 bool is_rat,
1599 int order0,
1600 int order1,
1601 int order2
1602 );
1603
1604
1605 /*
1606 Description:
1607 Construct a bezier volume that maps the unit cube
1608 to a bounding box.
1609 Parameters:
1610 bbox - [in] target bounding box
1611 order0 - [in]
1612 order1 - [in]
1613 order2 - [in]
1614 */
1616 const ON_BoundingBox& bbox,
1617 int order0,
1618 int order1,
1619 int order2
1620 );
1621
1622
1623 /*
1624 Description:
1625 Construct a bezier volume that maps the unit cube
1626 to an eight sided box.
1627 Parameters:
1628 box_corners - [in] 8 points that define corners of the
1629 target volume.
1630
1631 7______________6
1632 |\ |\
1633 | \ | \
1634 | \ _____________\
1635 | 4 | 5
1636 | | | |
1637 | | | |
1638 3---|----------2 |
1639 \ | \ |
1640 \ |t \ |
1641 s \ | \ |
1642 \0_____________\1
1643 r
1644
1645 order0 - [in]
1646 order1 - [in]
1647 order2 - [in]
1648 */
1650 const ON_3dPoint* box_corners,
1651 int order0,
1652 int order1,
1653 int order2
1654 );
1655
1657
1658 ON_BezierCage(const ON_BezierCage& src);
1659
1660 ON_BezierCage& operator=(const ON_BezierCage& src);
1661
1662
1663 /*
1664 Description:
1665 Tests class to make sure members are correctly initialized.
1666 Returns:
1667 True if the orders are all >= 2, dimension is positive,
1668 and the rest of the members have settings that are
1669 valid for the orders and dimension.
1670 */
1671 bool IsValid() const;
1672
1673 void Dump( ON_TextLog& text_log) const;
1674
1675
1676 /*
1677 Description:
1678 The dimension of the image of the bazier volume map.
1679 This is generally three, but can be any positive
1680 integer.
1681 Returns:
1682 Dimesion of the image space.
1683 */
1684 int Dimension() const;
1685
1686
1687 /*
1688 Description:
1689 Creates a bezier volume with specified orders.
1690 Parameters:
1691 dim - [in]
1692 is_rat - [in]
1693 order0 - [in]
1694 order1 - [in]
1695 order2 - [in]
1696 Returns:
1697 True if input was valid and creation succeded.
1698 */
1699 bool Create(
1700 int dim,
1701 bool is_rat,
1702 int order0,
1703 int order1,
1704 int order2
1705 );
1706
1707 /*
1708 Description:
1709 Create a Bezier volume with corners defined by a bounding box.
1710 Parameters:
1711 bbox - [in] target bounding box - the bezier will
1712 map the unit cube onto this bounding box.
1713 order0 - [in]
1714 order1 - [in]
1715 order2 - [in]
1716 */
1717 bool Create(
1718 const ON_BoundingBox& bbox,
1719 int order0,
1720 int order1,
1721 int order2
1722 );
1723
1724 /*
1725 Description:
1726 Create a bezier volume from a 3d box
1727 Parameters:
1728 box_corners - [in] 8 points that define corners of the volume
1729
1730 7______________6
1731 |\ |\
1732 | \ | \
1733 | \ _____________\
1734 | 4 | 5
1735 | | | |
1736 | | | |
1737 3---|----------2 |
1738 \ | \ |
1739 \ |t \ |
1740 s \ | \ |
1741 \0_____________\1
1742 r
1743
1744 */
1745 bool Create(
1746 const ON_3dPoint* box_corners,
1747 int order0,
1748 int order1,
1749 int order2
1750 );
1751
1752
1753 /*
1754 Description:
1755 Frees the CV array and sets all members to zero.
1756 */
1757 void Destroy();
1758
1759 /*
1760 Description:
1761 Sets all members to zero. Does not free the CV array
1762 even when m_cv is not NULL. Generally used when the
1763 CVs were allocated from a memory pool that no longer
1764 exists and the free done in ~ON_BezierCage would
1765 cause a crash.
1766 */
1767 void EmergencyDestroy();
1768
1769
1770 /*
1771 Description:
1772 Reads the definition of this class from an
1773 archive previously saved by ON_BezierVolue::Write.
1774 Parameters:
1775 archive - [in] target archive
1776 Returns:
1777 True if successful.
1778 */
1779 bool Read(ON_BinaryArchive& archive);
1780
1781 /*
1782 Description:
1783 Saves the definition of this class in serial binary
1784 form that can be read by ON_BezierVolue::Read.
1785 Parameters:
1786 archive - [in] target archive
1787 Returns:
1788 True if successful.
1789 */
1790 bool Write(ON_BinaryArchive& archive) const;
1791
1792
1793 /*
1794 Description:
1795 Gets the axis aligned bounding box that contains
1796 the bezier's control points. The bezier volume
1797 maps the unit cube into this box.
1798 Parameters:
1799 boxmin - [in] array of Dimension() doubles
1800 boxmax - [in] array of Dimension() doubles
1801 bGrowBox = [in] if true and the input is a valid box
1802 then the input box is grown to
1803 include this object's bounding box.
1804 Returns:
1805 true if successful.
1806 */
1807 bool GetBBox(
1808 double* boxmin,
1809 double* boxmax,
1810 int bGrowBox = false
1811 ) const;
1812
1813 bool Transform(
1814 const ON_Xform& xform
1815 );
1816
1817 bool Morph( const ON_SpaceMorph& morph );
1818
1819 // Description:
1820 // Rotates the bezier surface about the specified axis. A positive
1821 // rotation angle results in a counter-clockwise rotation
1822 // about the axis (right hand rule).
1823 // Parameters:
1824 // sin_angle - [in] sine of rotation angle
1825 // cos_angle - [in] sine of rotation angle
1826 // rotation_axis - [in] direction of the axis of rotation
1827 // rotation_center - [in] point on the axis of rotation
1828 // Returns:
1829 // true if bezier surface successfully rotated
1830 // Remarks:
1831 // Uses ON_BezierCage::Transform() function to calculate the result.
1832 bool Rotate(
1833 double sin_angle,
1834 double cos_angle,
1835 const ON_3dVector& rotation_axis,
1836 const ON_3dPoint& rotation_center
1837 );
1838
1839 // Description:
1840 // Rotates the bezier surface about the specified axis. A positive
1841 // rotation angle results in a counter-clockwise rotation
1842 // about the axis (right hand rule).
1843 // Parameters:
1844 // rotation_angle - [in] angle of rotation in radians
1845 // rotation_axis - [in] direction of the axis of rotation
1846 // rotation_center - [in] point on the axis of rotation
1847 // Returns:
1848 // true if bezier surface successfully rotated
1849 // Remarks:
1850 // Uses ON_BezierCage::Transform() function to calculate the result.
1851 bool Rotate(
1852 double rotation_angle,
1853 const ON_3dVector& rotation_axis,
1854 const ON_3dPoint& rotation_center
1855 );
1856
1857 // Description:
1858 // Translates the bezier surface along the specified vector.
1859 // Parameters:
1860 // translation_vector - [in] translation vector
1861 // Returns:
1862 // true if bezier surface successfully translated
1863 // Remarks:
1864 // Uses ON_BezierCage::Transform() function to calculate the result.
1865 bool Translate(
1866 const ON_3dVector& translation_vector
1867 );
1868
1869 // Description:
1870 // Scales the bezier surface by the specified facotor. The scale is
1871 // centered at the origin.
1872 // Parameters:
1873 // scale_factor - [in] scale factor
1874 // Returns:
1875 // true if bezier surface successfully scaled
1876 // Remarks:
1877 // Uses ON_BezierCage::Transform() function to calculate the result.
1878 bool Scale(
1879 double scale_factor
1880 );
1881
1882 ON_Interval Domain(
1883 int // 0 = "u" domain, 1 = "v" domain, 2 = "w" domain
1884 ) const;
1885
1886 // returns false if unable to evaluate
1887 bool Evaluate(
1888 double r,
1889 double s,
1890 double t,
1891 int der_count,
1892 int v_stride,
1893 double* v // array of length stride*(ndir+1)*(ndir+2)/2
1894 ) const;
1895
1896 /*
1897 Description:
1898 Evaluates bezer volume map.
1899 Parameters:
1900 rst - [in]
1901 Returns:
1902 Value of the bezier volume map at (r,s,t).
1903 */
1904 ON_3dPoint PointAt(
1905 double r,
1906 double s,
1907 double t
1908 ) const;
1909
1910 /*
1911 Description:
1912 Evaluates bezer volume map.
1913 Parameters:
1914 rst - [in]
1915 Returns:
1916 Value of the bezier volume map at (rst.x,rst.y,rst.z).
1917 */
1918 ON_3dPoint PointAt(
1919 ON_3dPoint rst
1920 ) const;
1921
1922 bool IsRational() const; // true if NURBS curve is rational
1923
1924 bool IsSingular( // true if surface side is collapsed to a point
1925 int // side of parameter space to test
1926 // 0 = south, 1 = east, 2 = north, 3 = west
1927 ) const;
1928
1929 int CVSize() const; // number of doubles per control vertex
1930 // = IsRational() ? Dim()+1 : Dim()
1931
1932 int Order( // order = degree + 1
1933 int // dir
1934 ) const;
1935
1936 int Degree( // degree = order - 1
1937 int // dir
1938 ) const;
1939
1940 /*
1941 Description:
1942 Expert user function to get a pointer to control vertex
1943 memory. If you are not an expert user, please use
1944 ON_BezierCage::GetCV( ON_3dPoint& ) or
1945 ON_BezierCage::GetCV( ON_4dPoint& ).
1946 Parameters:
1947 cv_index0 - [in] (0 <= cv_index0 < m_order[0])
1948 cv_index1 - [in] (0 <= cv_index1 < m_order[1])
1949 Returns:
1950 Pointer to control vertex.
1951 Remarks:
1952 If the Bezier surface is rational, the format of the
1953 returned array is a homogeneos rational point with
1954 length m_dim+1. If the Bezier surface is not rational,
1955 the format of the returned array is a nonrational
1956 euclidean point with length m_dim.
1957 See Also
1958 ON_BezierCage::CVStyle
1959 ON_BezierCage::GetCV
1960 ON_BezierCage::Weight
1961 */
1962 double* CV(
1963 int i,
1964 int j,
1965 int k
1966 ) const;
1967
1968 /*
1969 Description:
1970 Returns the style of control vertices in the m_cv array.
1971 Returns:
1972 @untitled table
1973 ON::not_rational m_is_rat is false
1974 ON::homogeneous_rational m_is_rat is true
1975 */
1976 ON::point_style CVStyle() const;
1977
1978 double Weight( // get value of control vertex weight
1979 int i,
1980 int j,
1981 int k
1982 ) const;
1983
1984 bool SetWeight( // set value of control vertex weight
1985 int i,
1986 int j,
1987 int k,
1988 double w
1989 );
1990
1991 bool SetCV( // set a single control vertex
1992 int i,
1993 int j,
1994 int k,
1995 ON::point_style, // style of input point
1996 const double* // value of control vertex
1997 );
1998
1999 // set a single control vertex
2000 // If NURBS is rational, weight
2001 // will be set to 1.
2002 bool SetCV(
2003 int i,
2004 int j,
2005 int k,
2006 const ON_3dPoint& point
2007 );
2008
2009 // set a single control vertex
2010 // value of control vertex
2011 // If NURBS is not rational, euclidean
2012 // location of homogeneous point will
2013 // be used.
2014 bool SetCV(
2015 int i,
2016 int j,
2017 int k,
2018 const ON_4dPoint& hpoint
2019 );
2020
2021 bool GetCV( // get a single control vertex
2022 int i,
2023 int j,
2024 int k,
2025 ON::point_style, // style to use for output point
2026 double* // array of length >= CVSize()
2027 ) const;
2028
2029 bool GetCV( // get a single control vertex
2030 int i,
2031 int j,
2032 int k,
2033 ON_3dPoint& // gets euclidean cv when NURBS is rational
2034 ) const;
2035
2036 bool GetCV( // get a single control vertex
2037 int i,
2038 int j,
2039 int k,
2040 ON_4dPoint& // gets homogeneous cv
2041 ) const;
2042
2043 bool ZeroCVs(); // zeros control vertices and, if rational, sets weights to 1
2044
2045 bool MakeRational();
2046
2047 bool MakeNonRational();
2048
2049
2051 // Tools for managing CV and knot memory
2052
2053 /*
2054 Description:
2055 cv_capacity - [in] number of doubles to reserve
2056 */
2057 bool ReserveCVCapacity(
2058 int cv_capacity
2059 );
2060
2062 // Implementation
2063public:
2064 // NOTE: These members are left "public" so that expert users may efficiently
2065 // create bezier curves using the default constructor and borrow the
2066 // knot and CV arrays from their native NURBS representation.
2067 // No technical support will be provided for users who access these
2068 // members directly. If you can't get your stuff to work, then use
2069 // the constructor with the arguments and the SetKnot() and SetCV()
2070 // functions to fill in the arrays.
2071
2072
2075 int m_order[3];
2076 int m_cv_stride[3];
2078 double* m_cv;
2079};
2080
2081
2083{
2084public:
2087
2088 /*
2089 Description:
2090 Override of virtual ON_SpaceMorph::MorphPoint.
2091 Parameters:
2092 point - [in]
2093 (x,y,z) gets mapped to m_rst2xyz(m_xyz2rst*point);
2094 */
2095 ON_3dPoint MorphPoint(
2096 ON_3dPoint point
2097 ) const;
2098
2099 /*
2100 Description:
2101 Create a Bezier volume.
2102 Parameters:
2103 P0 - [in]
2104 P1 - [in]
2105 P2 - [in]
2106 P3 - [in]
2107 P0,P1,P2,P3 defines a parallepiped in world space. The morph
2108 maps this parallepiped to the (0,1)x(0,1)x(0,1) unit cube
2109 and then applies the BezierCage map.
2110
2111
2112 ______________
2113 |\ |\
2114 | \ | \
2115 | \P3____________\
2116 | | | |
2117 | | | |
2118 | | | |
2119 P2---|---------- |
2120 \ | \ |
2121 \ |z \ |
2122 y \ | \ |
2123 \P0____________P1
2124 x
2125
2126
2127 point_countX - [in]
2128 point_countY - [in]
2129 point_countZ - [in]
2130 Number of control points in the bezier volume map. The
2131 bezier volume in the returned morph is the identity map
2132 which can be modified as needed.
2133 Returns:
2134 True if resulting morph is valid.
2135 See Also:
2136 ON_BezierCage::SetBezierCage
2137 ON_BezierCage::SetXform
2138 */
2139 bool Create(
2140 ON_3dPoint P0,
2141 ON_3dPoint P1,
2142 ON_3dPoint P2,
2143 ON_3dPoint P3,
2144 int point_countX,
2145 int point_countY,
2146 int point_countZ
2147 );
2148
2149 /*
2150 Description:
2151 Set the world to unit cube map.
2152 Parameters:
2153 world2unitcube - [in]
2154 Tranformation matrix that maps world coordinates
2155 to the unit cube (0,1)x(0,1)x(0,1).
2156 Returns
2157 True if current bezier volum and input transformation
2158 matrix are valid. In all cases, the morph's m_xyz2rst
2159 member is set.
2160 See Also:
2161 ON_BezierCage::Create
2162 ON_BezierCage::SetBezierCage
2163 */
2164 bool SetXform( ON_Xform world2unitcube );
2165
2166 /*
2167 Description:
2168 Set the unit cube to world map.
2169 Parameters:
2170 world2unitcube - [in]
2171 Bezier volume map from the unit cube (0,1)x(0,1)x(0,1)
2172 to world space.
2173 Returns
2174 True if current transformation matrix and input
2175 bezier volume are valid. In all cases, the
2176 morph's m_rst2xyz member is set.
2177 See Also:
2178 ON_BezierCage::Create
2179 ON_BezierCage::SetXform
2180 */
2181 bool SetBezierCage( ON_BezierCage& unitcube2world );
2182
2183 const ON_Xform& WorldToUnitCube() const;
2184 const ON_BezierCage& BezierCage() const;
2185
2186 bool Read(ON_BinaryArchive& archive);
2187 bool Write(ON_BinaryArchive& archive) const;
2188
2189 /*
2190 Description:
2191 Transforms the morph by transforming the bezier volume map.
2192 Parameters:
2193 xform - [in]
2194 Returns
2195 True if input is valid.
2196 */
2197 bool Transform(const ON_Xform& xform);
2198
2199private:
2201
2202 // transforms world (x,y,z) coordinate into
2203 // unit cube.
2205
2206 // function that maps unit cube into world
2208};
2209
2210#if defined(ON_DLL_TEMPLATE)
2211
2212// This stuff is here because of a limitation in the way Microsoft
2213// handles templates and DLLs. See Microsoft's knowledge base
2214// article ID Q168958 for details.
2215#pragma warning( push )
2216#pragma warning( disable : 4231 )
2217ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_BezierCurve>;
2218ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_BezierCurve*>;
2219ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_BezierSurface>;
2220ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_BezierSurface*>;
2221ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_BezierCage>;
2222ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_BezierCage*>;
2223ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_BezierCageMorph>;
2224ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_BezierCageMorph*>;
2225#pragma warning( pop )
2226
2227#endif
2228
2229#endif
@ Transform
Definition RSMetaType.h:67
int i
Copyright (c) 2011-2018 by Andrew Mustun.
Definition autostart.js:32
Base class for all dimensioning tools.
Definition Dimension.js:18
Definition opennurbs_array.h:353
Definition opennurbs_array.h:398
Definition opennurbs_point.h:403
Definition opennurbs_point.h:931
Definition opennurbs_array.h:626
Definition opennurbs_point.h:555
Definition opennurbs_bezier.h:1592
double * m_cv
Definition opennurbs_bezier.h:2078
int m_cv_capacity
Definition opennurbs_bezier.h:2077
bool Morph(const ON_SpaceMorph &morph)
int m_dim
Definition opennurbs_bezier.h:2073
bool m_is_rat
Definition opennurbs_bezier.h:2074
Definition opennurbs_bezier.h:2083
ON_BezierCage m_rst2xyz
Definition opennurbs_bezier.h:2207
bool m_bValid
Definition opennurbs_bezier.h:2200
ON_Xform m_xyz2rst
Definition opennurbs_bezier.h:2204
Definition opennurbs_bezier.h:148
int m_is_rat
Definition opennurbs_bezier.h:1171
int m_cv_capacity
Definition opennurbs_bezier.h:1186
int m_cv_stride
Definition opennurbs_bezier.h:1177
double * m_cv
Definition opennurbs_bezier.h:1180
int m_order
Definition opennurbs_bezier.h:1174
int m_dim
Definition opennurbs_bezier.h:1168
Definition opennurbs_bezier.h:1198
double * m_cv
Definition opennurbs_bezier.h:1578
int m_dim
Definition opennurbs_bezier.h:1574
int m_cv_capacity
Definition opennurbs_bezier.h:1579
int m_is_rat
Definition opennurbs_bezier.h:1575
Definition opennurbs_archive.h:152
Definition opennurbs_bounding_box.h:25
Definition opennurbs_array.h:760
Definition opennurbs_point.h:46
Definition opennurbs_nurbscurve.h:27
Definition opennurbs_nurbssurface.h:62
Definition opennurbs_bezier.h:29
int m_is_rat
Definition opennurbs_bezier.h:95
ON_4dPointArray m_cv
Definition opennurbs_bezier.h:101
ON_Interval m_domain
Definition opennurbs_bezier.h:104
int m_dim
Definition opennurbs_bezier.h:92
int m_order
Definition opennurbs_bezier.h:98
Definition opennurbs_bezier.h:108
int m_is_rat
Definition opennurbs_bezier.h:140
int m_dim
Definition opennurbs_bezier.h:139
ON_4dPointArray m_cv
Definition opennurbs_bezier.h:142
Definition opennurbs_array.h:46
Definition opennurbs_xform.h:1146
Definition opennurbs_textlog.h:20
Definition opennurbs_x.h:22
Definition opennurbs_xform.h:28
Reverses all selected entities which support reversing (lines, arcs, splines).
Definition Reverse.js:11
Rotates selected entities.
Definition Rotate.js:11
Scales selected entities.
Definition Scale.js:11
Translates (moves or copies) selected entities.
Definition Translate.js:11
Trims an entity to another entity or trims both entities if this.trimBoth is true.
Definition Trim.js:12
#define ON_DEPRECATED
Definition opennurbs_defines.h:106
#define ON_CLASS
Definition opennurbs_defines.h:91
char s
Definition opennurbs_string.cpp:32
#define NULL
Definition opennurbs_system.h:256
int ON_BOOL32
Definition opennurbs_system.h:362