-
Notifications
You must be signed in to change notification settings - Fork 141
/
opennurbs_bezier.h
2017 lines (1763 loc) · 57.3 KB
/
opennurbs_bezier.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// Copyright (c) 1993-2022 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
#if !defined(OPENNURBS_BEZIER_INC_)
#define OPENNURBS_BEZIER_INC_
class ON_PolynomialCurve;
class ON_PolynomialSurface;
class ON_BezierCurve;
class ON_BezierSurface;
class ON_TextLog;
class ON_NurbsCurve;
class ON_NurbsSurface;
class ON_X_EVENT;
class ON_CLASS ON_PolynomialCurve
{
public:
ON_PolynomialCurve();
// Description:
// See ON_PolynomialCurve::Create.
// Parameters:
// dim - [in] dimension of the curve
// bIsRational - [in] true if rational
// order - [in] (>=2) order = degree+1
ON_PolynomialCurve(
int dim,
bool bIsRational,
int order
);
~ON_PolynomialCurve();
ON_PolynomialCurve(const ON_PolynomialCurve&);
ON_PolynomialCurve(const ON_BezierCurve&);
ON_PolynomialCurve& operator=(const ON_PolynomialCurve&);
ON_PolynomialCurve& operator=(const ON_BezierCurve&);
// Description:
// Initializes fields and allocates the m_cv array.
// Parameters:
// dim - [in] dimension of the curve
// bIsRational - [in] true if rational
// order - [in] (>=2) order = degree+1
bool Create(
int dim,
bool bIsRational,
int order
);
// Description:
// Deallocates the m_cv array and sets fields to zero.
void Destroy();
// Description:
// Evaluate a polynomial curve.
// Parameters:
// t - [in] evaluation parameter ( usually in Domain() ).
// der_count - [in] (>=0) number of derivatives to evaluate
// v_stride - [in] (>=Dimension()) stride to use for the v[] array
// v - [out] array of length (der_count+1)*v_stride
// curve(t) is returned in (v[0],...,v[m_dim-1]),
// curve'(t) is returned in (v[v_stride],...,v[v_stride+m_dim-1]),
// curve"(t) is returned in (v[2*v_stride],...,v[2*v_stride+m_dim-1]),
// etc.
// Returns:
// false if unable to evaluate.
bool Evaluate(
double t,
int der_count,
int v_stride,
double* v
) const;
// dimension of polynomial curve (1,2, or 3)
int m_dim;
// 1 if polynomial curve is rational, 0 if polynomial curve is not rational
int m_is_rat;
// order (=degree+1) of polynomial
int m_order;
// coefficients ( m_cv.Count() = order of monomial )
ON_4dPointArray m_cv;
// domain of polynomial
ON_Interval m_domain;
};
class ON_CLASS ON_PolynomialSurface
{
public:
ON_PolynomialSurface();
ON_PolynomialSurface(
int, // dim,
bool, // true if rational
int, // "u" order
int // "v" order
);
~ON_PolynomialSurface();
ON_PolynomialSurface(const ON_PolynomialSurface&);
ON_PolynomialSurface(const ON_BezierSurface&);
ON_PolynomialSurface& operator=(const ON_PolynomialSurface&);
ON_PolynomialSurface& operator=(const ON_BezierSurface&);
bool Create(
int, // dim,
bool, // true if rational
int, // "u" order
int // "v" order
);
void Destroy();
bool Evaluate( // returns false if unable to evaluate
double s,
double t, // evaluation parameter
int der_count, // number of derivatives (>=0)
int v_stride, // array stride (>=Dimension())
double* v // array of length stride*(ndir+1)*(ndir+2)/2
) const;
int m_dim; // 1,2, or 3
int m_is_rat; // 1 if rational, 0 if not rational
int m_order[2];
ON_4dPointArray m_cv; // coefficients ( m_C.Length() = m_order[0]*m_order[1]
// coefficient of s^m*t^n = m_cv[m_order[1]*m+n]
ON_Interval m_domain[2];
};
class ON_CLASS ON_BezierCurve
{
public:
ON_BezierCurve();
// Description:
// Creates a bezier with cv memory allocated.
// Parameters:
// dim - [in] (>0) dimension of bezier curve
// bIsRational - [in] true for a rational bezier
// order - [in] (>=2) order (=degree+1) of bezier curve
ON_BezierCurve(
int dim,
bool bIsRational,
int order
);
~ON_BezierCurve();
ON_BezierCurve(const ON_BezierCurve&);
ON_BezierCurve(const ON_PolynomialCurve&);
ON_BezierCurve(const ON_2dPointArray&); // sets control points
ON_BezierCurve(const ON_3dPointArray&); // sets control points
ON_BezierCurve(const ON_4dPointArray&); // sets control points
ON_BezierCurve& operator=(const ON_BezierCurve&);
ON_BezierCurve& operator=(const ON_PolynomialCurve&);
ON_BezierCurve& operator=(const ON_2dPointArray&); // sets control points
ON_BezierCurve& operator=(const ON_3dPointArray&); // sets control points
ON_BezierCurve& operator=(const ON_4dPointArray&); // sets control points
bool IsValid() const;
void Dump( ON_TextLog& ) const; // for debugging
// Returns:
// Dimension of bezier.
int Dimension() const;
// Description:
// Creates a bezier with cv memory allocated.
// Parameters:
// dim - [in] (>0) dimension of bezier curve
// bIsRational - [in] true for a rational bezier
// order - [in] (>=2) order (=degree+1) of bezier curve
// Returns:
// true if successful.
bool Create(
int dim,
bool bIsRational,
int order
);
// Description:
// Deallocates m_cv memory.
void Destroy();
void EmergencyDestroy(); // call if memory used by ON_NurbsCurve becomes invalid
// Description:
// Loft a bezier curve through a list of points.
// Parameters:
// points - [in] an array of 2 or more points to interpolate
// Returns:
// true if successful
// Remarks:
// The result has order = points.Count() and the loft uses the
// uniform parameterization curve( i/(points.Count()-1) ) = points[i].
bool Loft(
const ON_3dPointArray& points
);
// Description:
// Loft a bezier curve through a list of points.
// Parameters:
// pt_dim - [in] dimension of points to interpolate
// pt_count - [in] number of points (>=2)
// pt_stride - [in] (>=pt_dim) pt[] array stride
// pt - [in] array of points
// t_stride - [in] (>=1) t[] array stride
// t - [in] strictly increasing array of interpolation parameters
// Returns:
// true if successful
// Remarks:
// The result has order = points.Count() and the loft uses the
// parameterization curve( t[i] ) = points[i].
bool Loft(
int pt_dim,
int pt_count,
int pt_stride,
const double* pt,
int t_stride,
const double* t
);
// Description:
// Gets bounding box.
// Parameters:
// box_min - [out] minimum corner of axis aligned bounding box
// The box_min[] array must have size m_dim.
// box_max - [out] maximum corner of axis aligned bounding box
// The box_max[] array must have size m_dim.
// bGrowBox - [in] if true, input box_min/box_max must be set
// to valid bounding box corners and this box is enlarged to
// be the union of the input box and the bezier's bounding
// box.
// Returns:
// true if successful.
bool GetBBox( // returns true if successful
double* box_min,
double* box_max,
bool bGrowBox = false
) const;
// Description:
// Gets bounding box.
// Parameters:
// bbox - [out] axis aligned bounding box returned here.
// bGrowBox - [in] if true, input bbox must be a valid
// bounding box and this box is enlarged to
// be the union of the input box and the
// bezier's bounding box.
// Returns:
// true if successful.
bool GetBoundingBox(
ON_BoundingBox& bbox,
int bGrowBox = false
) const;
// Description:
// Gets bounding box.
// Returns:
// Axis aligned bounding box.
ON_BoundingBox BoundingBox() const;
/*
Description:
Get tight bounding box of the bezier.
Parameters:
tight_bbox - [in/out] tight bounding box
bGrowBox -[in] (default=false)
If true and the input tight_bbox is valid, then returned
tight_bbox is the union of the input tight_bbox and the
tight bounding box of the bezier curve.
xform -[in] (default=nullptr)
If not nullptr, the tight bounding box of the transformed
bezier is calculated. The bezier curve is not modified.
Returns:
True if the returned tight_bbox is set to a valid
bounding box.
*/
bool GetTightBoundingBox(
ON_BoundingBox& tight_bbox,
bool bGrowBox = false,
const ON_Xform* xform = nullptr
) const;
// Description:
// Transform the bezier.
// Parameters:
// xform - [in] transformation to apply to bezier
// Returns:
// true if successful. false if bezier is invalid
// and cannot be transformed.
bool Transform(
const ON_Xform& xform
);
// Description:
// Rotates the bezier curve about the specified axis. A positive
// rotation angle results in a counter-clockwise rotation
// about the axis (right hand rule).
// Parameters:
// sin_angle - [in] sine of rotation angle
// cos_angle - [in] sine of rotation angle
// rotation_axis - [in] direction of the axis of rotation
// rotation_center - [in] point on the axis of rotation
// Returns:
// true if bezier curve successfully rotated
// Remarks:
// Uses ON_BezierCurve::Transform() function to calculate the result.
bool Rotate(
double sin_angle,
double cos_angle,
const ON_3dVector& rotation_axis,
const ON_3dPoint& rotation_center
);
// Description:
// Rotates the bezier curve about the specified axis. A positive
// rotation angle results in a counter-clockwise rotation
// about the axis (right hand rule).
// Parameters:
// rotation_angle - [in] angle of rotation in radians
// rotation_axis - [in] direction of the axis of rotation
// rotation_center - [in] point on the axis of rotation
// Returns:
// true if bezier curve successfully rotated
// Remarks:
// Uses ON_BezierCurve::Transform() function to calculate the result.
bool Rotate(
double rotation_angle,
const ON_3dVector& rotation_axis,
const ON_3dPoint& rotation_center
);
// Description:
// Translates the bezier curve along the specified vector.
// Parameters:
// translation_vector - [in] translation vector
// Returns:
// true if bezier curve successfully translated
// Remarks:
// Uses ON_BezierCurve::Transform() function to calculate the result.
bool Translate(
const ON_3dVector& translation_vector
);
// Description:
// Scales the bezier curve by the specified facotor. The scale is
// centered at the origin.
// Parameters:
// scale_factor - [in] scale factor
// Returns:
// true if bezier curve successfully scaled
// Remarks:
// Uses ON_BezierCurve::Transform() function to calculate the result.
bool Scale(
double scale_factor
);
// Returns:
// Domain of bezier (always [0,1]).
ON_Interval Domain() const;
// Description:
// Reverses bezier by reversing the order
// of the control points.
bool Reverse();
// Description:
// Evaluate point at a parameter.
// Parameters:
// t - [in] evaluation parameter
// Returns:
// Point (location of curve at the parameter t).
ON_3dPoint PointAt(
double t
) const;
// Description:
// Evaluate first derivative at a parameter.
// Parameters:
// t - [in] evaluation parameter
// Returns:
// First derivative of the curve at the parameter t.
// Remarks:
// No error handling.
// See Also:
// ON_Curve::Ev1Der
ON_3dVector DerivativeAt(
double t
) const;
// Description:
// Evaluate unit tangent vector at a parameter.
// Parameters:
// t - [in] evaluation parameter
// Returns:
// Unit tangent vector of the curve at the parameter t.
// Remarks:
// No error handling.
// See Also:
// ON_Curve::EvTangent
ON_3dVector TangentAt(
double t
) const;
// Description:
// Evaluate the curvature vector at a parameter.
// Parameters:
// t - [in] evaluation parameter
// Returns:
// curvature vector of the curve at the parameter t.
// Remarks:
// No error handling.
// See Also:
// ON_Curve::EvCurvature
ON_3dVector CurvatureAt(
double t
) const;
// Description:
// Evaluate point at a parameter with error checking.
// Parameters:
// t - [in] evaluation parameter
// point - [out] value of curve at t
// Returns:
// false if unable to evaluate.
bool EvPoint(
double t,
ON_3dPoint& point
) const;
// Description:
// Evaluate first derivative at a parameter with error checking.
// Parameters:
// t - [in] evaluation parameter
// point - [out] value of curve at t
// first_derivative - [out] value of first derivative at t
// Returns:
// false if unable to evaluate.
bool Ev1Der(
double t,
ON_3dPoint& point,
ON_3dVector& first_derivative
) const;
// Description:
// Evaluate second derivative at a parameter with error checking.
// Parameters:
// t - [in] evaluation parameter
// point - [out] value of curve at t
// first_derivative - [out] value of first derivative at t
// second_derivative - [out] value of second derivative at t
// Returns:
// false if unable to evaluate.
bool Ev2Der(
double t,
ON_3dPoint& point,
ON_3dVector& first_derivative,
ON_3dVector& second_derivative
) const;
/*
Description:
Evaluate unit tangent at a parameter with error checking.
Parameters:
t - [in] evaluation parameter
point - [out] value of curve at t
tangent - [out] value of unit tangent
Returns:
false if unable to evaluate.
See Also:
ON_Curve::TangentAt
ON_Curve::Ev1Der
*/
bool EvTangent(
double t,
ON_3dPoint& point,
ON_3dVector& tangent
) const;
/*
Description:
Evaluate unit tangent and curvature at a parameter with error checking.
Parameters:
t - [in] evaluation parameter
point - [out] value of curve at t
tangent - [out] value of unit tangent
kappa - [out] value of curvature vector
Returns:
false if unable to evaluate.
*/
bool EvCurvature(
double t,
ON_3dPoint& point,
ON_3dVector& tangent,
ON_3dVector& kappa
) const;
// Description:
// Evaluate a bezier.
// Parameters:
// t - [in] evaluation parameter (usually 0 <= t <= 1)
// der_count - [in] (>=0) number of derivatives to evaluate
// v_stride - [in] (>=m_dim) stride to use for the v[] array
// v - [out] array of length (der_count+1)*v_stride
// bez(t) is returned in (v[0],...,v[m_dim-1]),
// bez'(t) is returned in (v[v_stride],...,v[v_stride+m_dim-1]),
// bez"(t) is returned in (v[2*v_stride],...,v[2*v_stride+m_dim-1]),
// etc.
// Returns:
// true if successful
bool Evaluate(
double t,
int der_count,
int v_stride,
double* v
) const;
// Description:
// Get ON_NurbsCurve form of a bezier.
// Parameters:
// nurbs_curve - [out] NURBS curve form of a bezier.
// The domain is [0,1].
// Returns:
// 0 = failure
// 1 = success
int GetNurbForm(
ON_NurbsCurve& nurbs_curve
) const;
// Returns:
// true if bezier is rational.
bool IsRational() const;
// Returns:
// Number of doubles per control vertex.
// (= IsRational() ? Dim()+1 : Dim())
int CVSize() const;
// Returns:
// Number of control vertices in the bezier.
// This is always the same as the order of the bezier.
int CVCount() const;
// Returns:
// Order of the bezier. (order=degree+1)
int Order() const; // order = degree + 1
// Returns:
// Degree of the bezier. (degree=order-1)
int Degree() const;
/*
Description:
Expert user function to get a pointer to control vertex
memory. If you are not an expert user, please use
ON_BezierCurve::GetCV( ON_3dPoint& ) or
ON_BezierCurve::GetCV( ON_4dPoint& ).
Parameters:
cv_index - [in] (0 <= cv_index < m_order)
Returns:
Pointer to control vertex.
Remarks:
If the Bezier curve is rational, the format of the
returned array is a homogeneous rational point with
length m_dim+1. If the Bezier curve is not rational,
the format of the returned array is a nonrational
euclidean point with length m_dim.
See Also
ON_BezierCurve::CVStyle
ON_BezierCurve::GetCV
ON_BezierCurve::Weight
*/
double* CV(
int cv_index
) const;
/*
Parameters:
cv_index - [in]
zero based control point index
Returns:
Control point as an ON_4dPoint.
Remarks:
If cv_index or the bezier is not valid, then ON_4dPoint::Nan is returned.
If dim < 3, unused coordinates are zero.
If dim >= 4, the first three coordinates are returned.
If is_rat is false, the weight is 1.
*/
const ON_4dPoint ControlPoint(
int cv_index
) const;
/*
Description:
Returns the style of control vertices in the m_cv array.
Returns:
@untitled table
ON::not_rational m_is_rat is false
ON::homogeneous_rational m_is_rat is true
*/
ON::point_style CVStyle() const;
// Parameters:
// cv_index - [in] control vertex index (0<=i<m_order)
// Returns:
// Weight of the i-th control vertex.
double Weight(
int cv_index
) const;
// Description:
// Set weight of a control vertex.
// Parameters:
// cv_index - [in] control vertex index (0 <= cv_index < m_order)
// weight - [in] weight
// Returns:
// true if the weight can be set. If weight is not 1 and
// the bezier is not rational, then false is returned.
// Use ON_BezierCurve::MakeRational to make a bezier curve
// rational.
// See Also:
// ON_BezierCurve::SetCV, ON_BezierCurve::MakeRational,
// ON_BezierCurve::IsRational, ON_BezierCurve::Weight
bool SetWeight(
int cv_index,
double weight
);
// Description:
// Set control vertex
// Parameters:
// cv_index - [in] control vertex index (0 <= cv_index < m_order)
// pointstyle - [in] specifies what kind of values are passed
// in the cv array.
// ON::not_rational
// cv[] is an array of length m_dim that defines
// a euclidean (world coordinate) point
// ON::homogeneous_rational
// cv[] is an array of length (m_dim+1) that defines
// a rational homogeneous point.
// ON::euclidean_rational
// cv[] is an array of length (m_dim+1). The first
// m_dim values define the euclidean (world coordinate)
// location of the point. cv[m_dim] is the weight
// ON::intrinsic_point_style
// If m_is_rat is true, cv[] has ON::homogeneous_rational
// point style. If m_is_rat is false, cv[] has
// ON::not_rational point style.
// cv - [in] array with control vertex value.
// Returns:
// true if the point can be set.
bool SetCV(
int cv_index,
ON::point_style pointstyle,
const double* cv
);
// Description:
// Set location of a control vertex.
// Parameters:
// cv_index - [in] control vertex index (0 <= cv_index < m_order)
// point - [in] control vertex location. If the bezier
// is rational, the weight will be set to 1.
// Returns:
// true if successful.
// See Also:
// ON_BezierCurve::CV, ON_BezierCurve::SetCV,
// ON_BezierCurve::SetWeight, ON_BezierCurve::Weight
bool SetCV(
int cv_index,
const ON_3dPoint& point
);
// Description:
// Set value of a control vertex.
// Parameters:
// cv_index - [in] control vertex index (0 <= cv_index < m_order)
// point - [in] control vertex value. If the bezier
// is not rational, the euclidean location of
// homogeneous point will be used.
// Returns:
// true if successful.
// See Also:
// ON_BezierCurve::CV, ON_BezierCurve::SetCV,
// ON_BezierCurve::SetWeight, ON_BezierCurve::Weight
bool SetCV(
int cv_index,
const ON_4dPoint& point
);
// Description:
// Get location of a control vertex.
// Parameters:
// cv_index - [in] control vertex index (0 <= cv_index < m_order)
// pointstyle - [in] specifies what kind of values to get
// ON::not_rational
// cv[] is an array of length m_dim that defines
// a euclidean (world coordinate) point
// ON::homogeneous_rational
// cv[] is an array of length (m_dim+1) that defines
// a rational homogeneous point.
// ON::euclidean_rational
// cv[] is an array of length (m_dim+1). The first
// m_dim values define the euclidean (world coordinate)
// location of the point. cv[m_dim] is the weight
// ON::intrinsic_point_style
// If m_is_rat is true, cv[] has ON::homogeneous_rational
// point style. If m_is_rat is false, cv[] has
// ON::not_rational point style.
// cv - [out] array with control vertex value.
// Returns:
// true if successful. false if cv_index is invalid.
bool GetCV(
int cv_index,
ON::point_style pointstyle,
double* cv
) const;
// Description:
// Get location of a control vertex.
// Parameters:
// cv_index - [in] control vertex index (0 <= cv_index < m_order)
// point - [out] Location of control vertex. If the bezier
// is rational, the euclidean location is returned.
// Returns:
// true if successful.
bool GetCV(
int cv_index,
ON_3dPoint& point
) const;
// Description:
// Get value of a control vertex.
// Parameters:
// cv_index - [in] control vertex index (0 <= cv_index < m_order)
// point - [out] Homogeneous value of control vertex.
// If the bezier is not rational, the weight is 1.
// Returns:
// true if successful.
bool GetCV(
int cv_index,
ON_4dPoint& point
) const;
// Description:
// Zeros control vertices and, if rational, sets weights to 1.
bool ZeroCVs();
// Description:
// Make beizer rational.
// Returns:
// true if successful.
// See Also:
// ON_Bezier::MakeNonRational
bool MakeRational();
// Description:
// Make beizer not rational by setting all control
// vertices to their euclidean locations and setting
// m_is_rat to false.
// See Also:
// ON_Bezier::MakeRational
bool MakeNonRational();
// Description:
// Increase degree of bezier.
// Parameters:
// desired_degree - [in]
// Returns:
// true if successful. false if desired_degree < current degree.
bool IncreaseDegree(
int desired_degree
);
// Description:
// Change dimension of bezier.
// Parameters:
// desired_dimension - [in]
// Returns:
// true if successful. false if desired_dimension < 1
bool ChangeDimension(
int desired_dimension
);
/////////////////////////////////////////////////////////////////
// Tools for managing CV and knot memory
// Description:
// Make sure m_cv array has a certain length.
// Parameters:
// desired_cv_capacity - [in] minimum length of m_cv array.
// Returns:
// true if successful.
bool ReserveCVCapacity(
int desired_cv_capacity
);
// Description:
// Trims (or extends) the bezier so the bezier so that the
// result starts bezier(interval[0]) and ends at
// bezier(interval[1]) (Evaluation performed on input bezier.)
// Parameters:
// interval -[in]
// Example:
// An interval of [0,1] leaves the bezier unchanged. An
// interval of [0.5,1] would trim away the left half. An
// interval of [0.0,2.0] would extend the right end.
bool Trim(
const ON_Interval& interval
);
// Description:
// Split() divides the Bezier curve at the specified parameter.
// The parameter must satisfy 0 < t < 1. You may pass *this as
// one of the curves to be returned.
// Parameters:
// t - [in] (0 < t < 1 ) parameter to split at
// left_side - [out]
// right_side - [out]
// Example:
// ON_BezierCurve crv = ...;
// ON_BezierCurve right_side;
// crv.Split( 0.5, crv, right_side );
// would split crv at the 1/2, put the left side in crv,
// and return the right side in right_side.
bool Split(
double t,
ON_BezierCurve& left_side,
ON_BezierCurve& right_side
) const;
// Description:
// returns the length of the control polygon
double ControlPolygonLength() const;
/*
Description:
Use a linear fractional transformation for [0,1] to reparameterize
the bezier. The locus of the curve is not changed, but the
parameterization is changed.
Parameters:
c - [in]
reparameterization constant (generally speaking, c should be > 0).
If c != 1, then the returned bezier will be rational.
Returns:
true if successful.
Remarks:
The reparameterization is performed by composing the input Bezier with
the function lambda: [0,1] -> [0,1] given by
t -> c*t / ( (c-1)*t + 1 )
Note that lambda(0) = 0, lambda(1) = 1, lambda'(t) > 0,
lambda'(0) = c and lambda'(1) = 1/c.
If the input Bezier has control vertices {B_0, ..., B_d}, then the
output Bezier has control vertices
(B_0, ... c^i * B_i, ..., c^d * B_d).
To derive this formula, simply compute the i-th Bernstein polynomial
composed with lambda().
The inverse parameterization is given by 1/c. That is, the
cumulative effect of the two calls
Reparameterize(c)
Reparameterize(1.0/c)
is to leave the bezier unchanged.
See Also:
ON_Bezier::ScaleConrolPoints
*/
bool Reparameterize(
double c
);
// misspelled function name is obsolete
ON_DEPRECATED_MSG("misspelled - use Reparameterize")
bool Reparametrize(double);
/*
Description:
Scale a rational Bezier's control vertices to set a weight to a
specified value.
Parameters:
i - [in] (0 <= i < order)
w - [in] w != 0.0
Returns:
True if successful. The i-th control vertex will have weight w.
Remarks:
Each control point is multiplied by w/w0, where w0 is the
input value of Weight(i).
See Also:
ON_Bezier::Reparameterize
ON_Bezier::ChangeWeights
*/
bool ScaleConrolPoints(
int i,
double w
);
/*
Description:
Use a combination of scaling and reparameterization to set two
rational Bezier weights to specified values.
Parameters:
i0 - [in] control point index (0 <= i0 < order, i0 != i1)
w0 - [in] Desired weight for i0-th control point
i1 - [in] control point index (0 <= i1 < order, i0 != i1)
w1 - [in] Desired weight for i1-th control point
Returns:
True if successful. The returned bezier has the same locus but
probably has a different parameterization.
Remarks:
The i0-th cv will have weight w0 and the i1-rst cv will have
weight w1. If v0 and v1 are the cv's input weights,
then v0, v1, w0 and w1 must all be nonzero, and w0*v0
and w1*v1 must have the same sign.
The equations
s * r^i0 = w0/v0
s * r^i1 = w1/v1
determine the scaling and reparameterization necessary to
change v0,v1 to w0,w1.
If the input Bezier has control vertices
(B_0, ..., B_d),
then the output Bezier has control vertices
(s*B_0, ... s*r^i * B_i, ..., s*r^d * B_d).
See Also:
ON_Bezier::Reparameterize
ON_Bezier::ScaleConrolPoints
*/
bool ChangeWeights(
int i0,
double w0,
int i1,
double w1
);
/////////////////////////////////////////////////////////////////
// Implementation
public:
// NOTE: These members are left "public" so that expert users may efficiently
// create bezier curves using the default constructor and borrow the
// knot and CV arrays from their native NURBS representation.
// No technical support will be provided for users who access these
// members directly. If you can't get your stuff to work, then use
// the constructor with the arguments and the SetKnot() and SetCV()
// functions to fill in the arrays.
// dimension of bezier (>=1)
int m_dim;
// 1 if bezier is rational, 0 if bezier is not rational
int m_is_rat;
// order = degree+1
int m_order;
// Number of doubles per cv ( >= ((m_is_rat)?m_dim+1:m_dim) )
int m_cv_stride;
// The i-th cv begins at cv[i*m_cv_stride].
double* m_cv;
// Number of doubles in m_cv array. If m_cv_capacity is zero
// and m_cv is not nullptr, an expert user is managing the m_cv
// memory. ~ON_BezierCurve will not deallocate m_cv unless
// m_cv_capacity is greater than zero.