00001 /* $NoKeywords: $ */ 00002 /* 00003 // 00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved. 00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert 00006 // McNeel & Associates. 00007 // 00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED. 00011 // 00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>. 00013 // 00015 */ 00016 00018 // 00019 // Definition of NURBS curve 00020 // 00022 00023 #if !defined(OPENNURBS_NURBSCURVE_INC_) 00024 #define OPENNURBS_NURBSCURVE_INC_ 00025 00026 #include <pcl/pcl_exports.h> 00027 00028 class ON_NurbsCurve; 00029 class PCL_EXPORTS ON_CLASS ON_NurbsCurve : public ON_Curve 00030 { 00031 ON_OBJECT_DECLARE(ON_NurbsCurve); 00032 00033 public: 00034 /* 00035 Description: 00036 Use ON_NurbsCurve::New(...) instead of new ON_NurbsCurve(...) 00037 Returns: 00038 Pointer to an ON_NurbsCurve. Destroy by calling delete. 00039 Remarks: 00040 See static ON_Brep* ON_Brep::New() for details. 00041 */ 00042 static ON_NurbsCurve* New(); 00043 static ON_NurbsCurve* New( 00044 const ON_NurbsCurve& nurbs_curve 00045 ); 00046 static ON_NurbsCurve* New( 00047 const ON_BezierCurve& bezier_curve 00048 ); 00049 static ON_NurbsCurve* New( 00050 int dimension, 00051 ON_BOOL32 bIsRational, 00052 int order, 00053 int cv_count 00054 ); 00055 00056 ON_NurbsCurve(); 00057 ON_NurbsCurve(const ON_NurbsCurve&); 00058 00059 // Description: 00060 // Create a NURBS curve equal to bezier with domain [0,1]. 00061 // Parameters: 00062 // bezier_curve - [in] 00063 ON_NurbsCurve( 00064 const ON_BezierCurve& bezier_curve 00065 ); 00066 00067 // Description: 00068 // Create a NURBS curve with knot a cv memory allocated. 00069 // Parameters: 00070 // dimension - [in] (>= 1) 00071 // bIsRational - [in] true to make a rational NURBS 00072 // order - [in] (>= 2) The order=degree+1 00073 // cv_count - [in] (>= order) number of control vertices 00074 ON_NurbsCurve( 00075 int dimension, 00076 ON_BOOL32 bIsRational, 00077 int order, 00078 int cv_count 00079 ); 00080 00081 // virtual ON_Object::SizeOf override 00082 unsigned int SizeOf() const; 00083 00084 // virtual ON_Object::DataCRC override 00085 ON__UINT32 DataCRC(ON__UINT32 current_remainder) const; 00086 00087 /* 00088 Description: 00089 See if this and other are same NURBS geometry. 00090 Parameters: 00091 other - [in] other NURBS curve 00092 bIgnoreParameterization - [in] if true, parameterization 00093 and orientaion are ignored. 00094 tolerance - [in] tolerance to use when comparing 00095 control points. 00096 Returns: 00097 true if curves are tne same. 00098 */ 00099 bool IsDuplicate( 00100 const ON_NurbsCurve& other, 00101 bool bIgnoreParameterization, 00102 double tolerance = ON_ZERO_TOLERANCE 00103 ) const; 00104 00105 // Description: 00106 // Zeros all fields. 00107 void Initialize(void); 00108 00109 // Description: 00110 // Create a NURBS curve with knot a cv memory allocated. 00111 // Parameters: 00112 // dimension - [in] (>= 1) 00113 // bIsRational - [in] true to make a rational NURBS 00114 // order - [in] (>= 2) The order=degree+1 00115 // cv_count - [in] (>= order) number of control vertices 00116 bool Create( 00117 int dimension, 00118 ON_BOOL32 bIsRational, 00119 int order, 00120 int cv_count 00121 ); 00122 00123 // Description: 00124 // Create a clamped uniform NURBS curve from a list 00125 // of control points 00126 // Parameters: 00127 // dimension - [in] 1, 2 or 3 00128 // order - [in] (>=2) order=degree+1 00129 // point_count - [in] (>=order) number of control vertices 00130 // point - [in] array of control vertex locations. 00131 // knot_delta - [in] (>0.0) knot spacing 00132 // Returns: 00133 // true if successful 00134 bool CreateClampedUniformNurbs( 00135 int dimension, 00136 int order, 00137 int point_count, 00138 const ON_3dPoint* point, 00139 double knot_delta = 1.0 00140 ); 00141 00142 // Description: 00143 // Create a periodic uniform NURBS curve from a list 00144 // of control points 00145 // Parameters: 00146 // dimension - [in] 1, 2 or 3 00147 // order - [in] (>=2) order=degree+1 00148 // point_count - [in] (>=max(3,order-1)) number of distinct control vertices 00149 // point - [in] array of distinct control vertex locations. 00150 // knot_delta - [in] (>0.0) knot spacing 00151 // Returns: 00152 // true if successful 00153 bool CreatePeriodicUniformNurbs( 00154 int dimension, 00155 int order, 00156 int point_count, 00157 const ON_3dPoint* point, 00158 double knot_delta = 1.0 00159 ); 00160 00161 // Description: 00162 // Deallocate knot and cv memory. Zeros all fields. 00163 void Destroy(); 00164 00165 virtual ~ON_NurbsCurve(); 00166 00167 // Description: 00168 // Call if memory used by ON_NurbsCurve becomes invalid. 00169 void EmergencyDestroy(); 00170 00171 ON_NurbsCurve& operator=(const ON_NurbsCurve& src); 00172 00173 // Description: 00174 // Set NURBS curve equal to bezier with domain [0,1]. 00175 // Parameters: 00176 // bezier_curve - [in] 00177 ON_NurbsCurve& operator=( 00178 const ON_BezierCurve& bezier_curve 00179 ); 00180 00182 // ON_Object overrides 00183 00184 /* 00185 Description: 00186 Tests an object to see if its data members are correctly 00187 initialized. 00188 Parameters: 00189 text_log - [in] if the object is not valid and text_log 00190 is not NULL, then a brief englis description of the 00191 reason the object is not valid is appened to the log. 00192 The information appended to text_log is suitable for 00193 low-level debugging purposes by programmers and is 00194 not intended to be useful as a high level user 00195 interface tool. 00196 Returns: 00197 @untitled table 00198 true object is valid 00199 false object is invalid, uninitialized, etc. 00200 Remarks: 00201 Overrides virtual ON_Object::IsValid 00202 */ 00203 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00204 00205 // Description: 00206 // virtual ON_Object::Dump override 00207 void Dump( 00208 ON_TextLog& dump 00209 ) const; 00210 00211 // Description: 00212 // virtual ON_Object::Write override 00213 ON_BOOL32 Write( 00214 ON_BinaryArchive& binary_archive 00215 ) const; 00216 00217 // Description: 00218 // virtual ON_Object::Read override 00219 ON_BOOL32 Read( 00220 ON_BinaryArchive& binary_archive 00221 ); 00222 00224 // ON_Geometry overrides 00225 00226 // Description: 00227 // virtual ON_Geometry::Dimension override 00228 // Returns: 00229 // value of m_dim 00230 int Dimension() const; 00231 00232 // Description: 00233 // virtual ON_Geometry::GetBBox override 00234 // Calculates axis aligned bounding box. 00235 // Parameters: 00236 // boxmin - [in/out] array of Dimension() doubles 00237 // boxmax - [in/out] array of Dimension() doubles 00238 // bGrowBox - [in] (default=false) 00239 // If true, then the union of the input bbox and the 00240 // object's bounding box is returned in bbox. 00241 // If false, the object's bounding box is returned in bbox. 00242 // Returns: 00243 // true if object has bounding box and calculation was successful 00244 ON_BOOL32 GetBBox( // returns true if successful 00245 double* boxmin, 00246 double* boxmax, 00247 int bGrowBox = false 00248 ) const; 00249 00250 // Description: 00251 // virtual ON_Geometry::Transform override. 00252 // Transforms the NURBS curve. 00253 // 00254 // Parameters: 00255 // xform - [in] transformation to apply to object. 00256 // 00257 // Remarks: 00258 // When overriding this function, be sure to include a call 00259 // to ON_Object::TransformUserData() which takes care of 00260 // transforming any ON_UserData that may be attached to 00261 // the object. 00262 ON_BOOL32 Transform( 00263 const ON_Xform& xform 00264 ); 00265 00266 // virtual ON_Geometry::IsDeformable() override 00267 bool IsDeformable() const; 00268 00269 // virtual ON_Geometry::MakeDeformable() override 00270 bool MakeDeformable(); 00271 00272 // Description: 00273 // virtual ON_Geometry::SwapCoordinates override. 00274 // Swaps control vertex coordinate values with indices i and j. 00275 // Parameters: 00276 // i - [in] coordinate index 00277 // j - [in] coordinate index 00278 ON_BOOL32 SwapCoordinates( 00279 int i, 00280 int j 00281 ); 00282 00284 // ON_Curve overrides 00285 00286 // Description: 00287 // virtual ON_Curve::Domain override. 00288 // Returns: 00289 // domain of the NURBS curve. 00290 ON_Interval Domain() const; 00291 00292 // Description: 00293 // virtual ON_Curve::SetDomain override. 00294 // Set the domain of the curve 00295 // Parameters: 00296 // t0 - [in] 00297 // t1 - [in] new domain will be [t0,t1] 00298 // Returns: 00299 // true if successful. 00300 ON_BOOL32 SetDomain( 00301 double t0, 00302 double t1 00303 ); 00304 00305 /* 00306 Description: 00307 If this curve is closed, then modify it so that 00308 the start/end point is at curve parameter t. 00309 Parameters: 00310 t - [in] curve parameter of new start/end point. The 00311 returned curves domain will start at t. 00312 Returns: 00313 true if successful. 00314 Remarks: 00315 Overrides virtual ON_Curve::ChangeClosedCurveSeam 00316 */ 00317 ON_BOOL32 ChangeClosedCurveSeam( 00318 double t 00319 ); 00320 00321 // Description: 00322 // virtual ON_Curve::SpanCount override. 00323 // Get number of nonempty smooth (c-infinity) spans in curve 00324 // Returns: 00325 // Number of nonempty smooth (c-infinity) spans. 00326 // Remarks: 00327 // A nonempty span is bracked by knots m_knot[i] < m_knot[i+1] 00328 // with m_order-2 <= i < m_cv_count-1. 00329 int SpanCount() const; 00330 00331 // Description: 00332 // virtual ON_Curve::GetSpanVector override. 00333 // Get number of parameters of distinct knots in NURBS curve's domain. 00334 // Parameters: 00335 // knot_values - [out] an array of length SpanCount()+1 is 00336 // filled in with the distinct knot values in the list 00338 // Returns: 00339 // true if successful 00340 ON_BOOL32 GetSpanVector( 00341 double* knot_values 00342 ) const; // 00343 00344 // Description: 00345 // virtual ON_Curve::Degree override. 00346 // Returns: 00347 // m_order-1 00348 int Degree() const; 00349 00350 // Description: 00351 // virtual ON_Curve::GetParameterTolerance override. 00352 ON_BOOL32 GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus 00353 double t, 00354 double* tminus, 00355 double* tplus 00356 ) const; 00357 00358 // Description: 00359 // virtual ON_Curve::IsLinear override. 00360 ON_BOOL32 IsLinear( 00361 double tolerance = ON_ZERO_TOLERANCE 00362 ) const; 00363 00364 /* 00365 Description: 00366 Several types of ON_Curve can have the form of a polyline including 00367 a degree 1 ON_NurbsCurve, an ON_PolylineCurve, and an ON_PolyCurve 00368 all of whose segments are some form of polyline. IsPolyline tests 00369 a curve to see if it can be represented as a polyline. 00370 Parameters: 00371 pline_points - [out] if not NULL and true is returned, then the 00372 points of the polyline form are returned here. 00373 t - [out] if not NULL and true is returned, then the parameters of 00374 the polyline points are returned here. 00375 Returns: 00376 @untitled table 00377 0 curve is not some form of a polyline 00378 >=2 number of points in polyline form 00379 */ 00380 int IsPolyline( 00381 ON_SimpleArray<ON_3dPoint>* pline_points = NULL, 00382 ON_SimpleArray<double>* pline_t = NULL 00383 ) const; 00384 00385 // Description: 00386 // virtual ON_Curve::IsArc override. 00387 ON_BOOL32 IsArc( 00388 const ON_Plane* plane = NULL, 00389 ON_Arc* arc = NULL, 00390 double tolerance = ON_ZERO_TOLERANCE 00391 ) const; 00392 00393 // Description: 00394 // virtual ON_Curve::IsPlanar override. 00395 ON_BOOL32 IsPlanar( 00396 ON_Plane* plane = NULL, 00397 double tolerance = ON_ZERO_TOLERANCE 00398 ) const; 00399 00400 // Description: 00401 // virtual ON_Curve::IsInPlane override. 00402 ON_BOOL32 IsInPlane( 00403 const ON_Plane& test_plane, 00404 double tolerance = ON_ZERO_TOLERANCE 00405 ) const; 00406 00407 // Description: 00408 // virtual ON_Curve::IsClosed override. 00409 // Returns: 00410 // true if NURBS curve is closed. (Either curve has 00411 // clamped end knots and euclidean location of start 00412 // CV = euclidean location of end CV, or curve is 00413 // periodic.) 00414 ON_BOOL32 IsClosed() const; 00415 00416 // Description: 00417 // virtual ON_Curve::IsPeriodic override. 00418 // Returns: 00419 // true if NURBS curve is periodic (degree > 1, 00420 // periodic knot vector, last degree many CVs 00421 // are duplicates of first degree many CVs). 00422 ON_BOOL32 IsPeriodic() const; 00423 00424 /* 00425 Description: 00426 Search for a derivatitive, tangent, or curvature discontinuity. 00427 Parameters: 00428 c - [in] type of continity to test for. If ON::C1_continuous 00429 t0 - [in] search begins at t0 00430 t1 - [in] (t0 < t1) search ends at t1 00431 t - [out] if a discontinuity is found, the *t reports the 00432 parameter at the discontinuity. 00433 hint - [in/out] if GetNextDiscontinuity will be called repeatedly, 00434 passing a "hint" with initial value *hint=0 will increase the speed 00435 of the search. 00436 dtype - [out] if not NULL, *dtype reports the kind of discontinuity 00437 found at *t. A value of 1 means the first derivative or unit tangent 00438 was discontinuous. A value of 2 means the second derivative or 00439 curvature was discontinuous. 00440 cos_angle_tolerance - [in] default = cos(1 degree) Used only when 00441 c is ON::G1_continuous or ON::G2_continuous. If the cosine 00442 of the angle between two tangent vectors 00443 is <= cos_angle_tolerance, then a G1 discontinuity is reported. 00444 curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when 00445 c is ON::G2_continuous or ON::Gsmooth_continuous. 00446 ON::G2_continuous: 00447 If K0 and K1 are curvatures evaluated 00448 from above and below and |K0 - K1| > curvature_tolerance, 00449 then a curvature discontinuity is reported. 00450 ON::Gsmooth_continuous: 00451 If K0 and K1 are curvatures evaluated from above and below 00452 and the angle between K0 and K1 is at least twice angle tolerance 00453 or ||K0| - |K1|| > (max(|K0|,|K1|) > curvature_tolerance, 00454 then a curvature discontinuity is reported. 00455 Returns: 00456 true if a discontinuity was found on the interior of the interval (t0,t1). 00457 Remarks: 00458 Overrides ON_Curve::GetNextDiscontinuity. 00459 */ 00460 bool GetNextDiscontinuity( 00461 ON::continuity c, 00462 double t0, 00463 double t1, 00464 double* t, 00465 int* hint=NULL, 00466 int* dtype=NULL, 00467 double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE, 00468 double curvature_tolerance=ON_SQRT_EPSILON 00469 ) const; 00470 00471 /* 00472 Description: 00473 Test continuity at a curve parameter value. 00474 Parameters: 00475 c - [in] continuity to test for 00476 t - [in] parameter to test 00477 hint - [in] evaluation hint 00478 point_tolerance - [in] if the distance between two points is 00479 greater than point_tolerance, then the curve is not C0. 00480 d1_tolerance - [in] if the difference between two first derivatives is 00481 greater than d1_tolerance, then the curve is not C1. 00482 d2_tolerance - [in] if the difference between two second derivatives is 00483 greater than d2_tolerance, then the curve is not C2. 00484 cos_angle_tolerance - [in] default = cos(1 degree) Used only when 00485 c is ON::G1_continuous or ON::G2_continuous. If the cosine 00486 of the angle between two tangent vectors 00487 is <= cos_angle_tolerance, then a G1 discontinuity is reported. 00488 curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when 00489 c is ON::G2_continuous or ON::Gsmooth_continuous. 00490 ON::G2_continuous: 00491 If K0 and K1 are curvatures evaluated 00492 from above and below and |K0 - K1| > curvature_tolerance, 00493 then a curvature discontinuity is reported. 00494 ON::Gsmooth_continuous: 00495 If K0 and K1 are curvatures evaluated from above and below 00496 and the angle between K0 and K1 is at least twice angle tolerance 00497 or ||K0| - |K1|| > (max(|K0|,|K1|) > curvature_tolerance, 00498 then a curvature discontinuity is reported. 00499 Returns: 00500 true if the curve has at least the c type continuity at the parameter t. 00501 Remarks: 00502 Overrides ON_Curve::IsContinuous. 00503 */ 00504 bool IsContinuous( 00505 ON::continuity c, 00506 double t, 00507 int* hint = NULL, 00508 double point_tolerance=ON_ZERO_TOLERANCE, 00509 double d1_tolerance=ON_ZERO_TOLERANCE, 00510 double d2_tolerance=ON_ZERO_TOLERANCE, 00511 double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE, 00512 double curvature_tolerance=ON_SQRT_EPSILON 00513 ) const; 00514 00515 /* 00516 Description: 00517 Force the curve to start at a specified point. 00518 Parameters: 00519 start_point - [in] 00520 Returns: 00521 true if successful. 00522 Remarks: 00523 Some end points cannot be moved. Be sure to check return 00524 code. 00525 See Also: 00526 ON_Curve::SetEndPoint 00527 ON_Curve::PointAtStart 00528 ON_Curve::PointAtEnd 00529 */ 00530 //virtual 00531 ON_BOOL32 SetStartPoint( 00532 ON_3dPoint start_point 00533 ); 00534 00535 /* 00536 Description: 00537 Force the curve to end at a specified point. 00538 Parameters: 00539 end_point - [in] 00540 Returns: 00541 true if successful. 00542 Remarks: 00543 Some end points cannot be moved. Be sure to check return 00544 code. 00545 See Also: 00546 ON_Curve::SetStartPoint 00547 ON_Curve::PointAtStart 00548 ON_Curve::PointAtEnd 00549 */ 00550 //virtual 00551 ON_BOOL32 SetEndPoint( 00552 ON_3dPoint end_point 00553 ); 00554 00555 // Description: 00556 // virtual ON_Curve::Reverse override. 00557 // Reverse parameterizatrion by negating all knots 00558 // and reversing the order of the control vertices. 00559 // Remarks: 00560 // Domain changes from [a,b] to [-b,-a] 00561 ON_BOOL32 Reverse(); 00562 00563 // Description: 00564 // virtual ON_Curve::Evaluate override. 00565 ON_BOOL32 Evaluate( // returns false if unable to evaluate 00566 double, // evaluation parameter 00567 int, // number of derivatives (>=0) 00568 int, // array stride (>=Dimension()) 00569 double*, // array of length stride*(ndir+1) 00570 int = 0, // optional - determines which side to evaluate from 00571 // 0 = default 00572 // < 0 to evaluate from below, 00573 // > 0 to evaluate from above 00574 int* = 0 // optional - evaluation hint (int) used to speed 00575 // repeated evaluations 00576 ) const; 00577 00578 /* 00579 Parameters: 00580 span_index - [in] 00581 (0 <= span_index <= m_cv_count-m_order) 00582 min_length -[in] 00583 minimum length of a linear span 00584 tolerance -[in] 00585 distance tolerance to use when checking control points 00586 between the span ends 00587 Returns 00588 true if the span is a non-degenrate line. This means: 00589 - dimension = 2 or 3 00590 - There are full multiplicity knots at each end of the span. 00591 - The length of the the line segment from the span's initial 00592 control point to the span's final control point is 00593 >= min_length. 00594 - The distance from the line segment to the interior control points 00595 is <= tolerance and the projections of these points onto 00596 the line increases monotonically. 00597 */ 00598 bool SpanIsLinear( 00599 int span_index, 00600 double min_length, 00601 double tolerance 00602 ) const; 00603 00604 bool SpanIsLinear( 00605 int span_index, 00606 double min_length, 00607 double tolerance, 00608 ON_Line* line 00609 ) const; 00610 00611 /* 00612 Description: 00613 Looks for problems caused by knots that are close together 00614 or have mulitplicity >= order. If bRepair is true, the problems 00615 are fixed. Does not change the domain. 00616 Parameters: 00617 knot_tolerance - [in] >= 0 When in doubt, use zero. 00618 bRepair - [in] If true, then problems are repaired. 00619 Otherwise this function looks for problemsn that 00620 can be repaired, but does not modify the curve. 00621 Returns: 00622 True if bad knots were found and can be repaired. 00623 See Also: 00624 ON_NurbsCurve::RemoveShortSegments 00625 */ 00626 bool RepairBadKnots( 00627 double knot_tolerance=0.0, 00628 bool bRepair = true 00629 ); 00630 00631 // Description: 00632 // virtual ON_Curve::Trim override. 00633 ON_BOOL32 Trim( const ON_Interval& ); 00634 00635 // Description: 00636 // Where possible, analytically extends curve to include domain. 00637 // Parameters: 00638 // domain - [in] if domain is not included in curve domain, 00639 // curve will be extended so that its domain includes domain. 00640 // Will not work if curve is closed. Original curve is identical 00641 // to the restriction of the resulting curve to the original curve domain, 00642 // Returns: 00643 // true if successful. 00644 bool Extend( 00645 const ON_Interval& domain 00646 ); 00647 00648 // Description: 00649 // virtual ON_Curve::Split override. 00650 // 00651 // Split() divides the curve at the specified parameter. The parameter 00652 // must be in the interior of the curve's domain. The pointers passed 00653 // to ON_NurbsCurve::Split must either be NULL or point to an ON_NurbsCurve. 00654 // If the pointer is NULL, then a curve will be created 00655 // in Split(). You may pass "this" as one of the pointers to Split(). 00656 // For example, 00657 // 00658 // ON_NurbsCurve right_side; 00659 // crv.Split( crv.Domain().Mid() &crv, &right_side ); 00660 // 00661 // would split crv at the parametric midpoint, put the left side in crv, 00662 // and return the right side in right_side. 00663 ON_BOOL32 Split( 00664 double split_param, // t = curve parameter to split curve at 00665 ON_Curve*& left_result, // left portion returned here (must be an ON_NurbsCurve) 00666 ON_Curve*& right_result // right portion returned here (must be an ON_NurbsCurve) 00667 ) const; 00668 00669 // Description: 00670 // virtual ON_Curve::GetNurbForm override. 00671 int GetNurbForm( // returns 0: unable to create NURBS representation 00672 // with desired accuracy. 00673 // 1: success - returned NURBS parameterization 00674 // matches the curve's to wthe desired accuracy 00675 // 2: success - returned NURBS point locus matches 00676 // the curve's to the desired accuracy but, on 00677 // the interior of the curve's domain, the 00678 // curve's parameterization and the NURBS 00679 // parameterization may not match to the 00680 // desired accuracy. 00681 ON_NurbsCurve& nurbsform, 00682 double tolerance = 0.0, 00683 const ON_Interval* subdomain = NULL // OPTIONAL subdomain of curve 00684 ) const; 00685 00686 // Description: 00687 // virtual ON_Curve::HasNurbForm override. 00688 int HasNurbForm( // returns 0: unable to create NURBS representation 00689 // with desired accuracy. 00690 // 1: success - returned NURBS parameterization 00691 // matches the curve's to wthe desired accuracy 00692 // 2: success - returned NURBS point locus matches 00693 // the curve's to the desired accuracy but, on 00694 // the interior of the curve's domain, the 00695 // curve's parameterization and the NURBS 00696 // parameterization may not match to the 00697 // desired accuracy. 00698 ) const; 00699 00700 // Description: 00701 // virtual ON_Curve::GetCurveParameterFromNurbFormParameter override 00702 ON_BOOL32 GetCurveParameterFromNurbFormParameter( 00703 double nurbs_t, 00704 double* curve_t 00705 ) const; 00706 00707 // Description: 00708 // virtual ON_Curve::GetNurbFormParameterFromCurveParameter override 00709 ON_BOOL32 GetNurbFormParameterFromCurveParameter( 00710 double curve_t, 00711 double* nurbs_t 00712 ) const; 00713 00714 public: 00715 00717 // Interface 00718 00719 bool IsRational( // true if NURBS curve is rational 00720 void 00721 ) const; 00722 00723 int CVSize( // number of doubles per control vertex 00724 void // = IsRational() ? Dim()+1 : Dim() 00725 ) const; 00726 00727 int Order( // order = degree + 1 00728 void 00729 ) const; 00730 00731 int CVCount( // number of control vertices 00732 void 00733 ) const; 00734 00735 int KnotCount( // total number of knots in knot vector 00736 void 00737 ) const; 00738 00739 /* 00740 Description: 00741 Expert user function to get a pointer to control vertex 00742 memory. If you are not an expert user, please use 00743 ON_NurbsCurve::GetCV( ON_3dPoint& ) or 00744 ON_NurbsCurve::GetCV( ON_4dPoint& ). 00745 Parameters: 00746 cv_index - [in] 00747 Returns: 00748 Pointer to control vertex. 00749 Remarks: 00750 If the NURBS curve is rational, the format of the 00751 returned array is a homogeneos rational point with 00752 length m_dim+1. If the NURBS curve is not rational, 00753 the format of the returned array is a nonrational 00754 euclidean point with length m_dim. 00755 See Also 00756 ON_NurbsCurve::CVStyle 00757 ON_NurbsCurve::GetCV 00758 ON_NurbsCurve::Weight 00759 */ 00760 double* CV( 00761 int cv_index 00762 ) const; 00763 00764 /* 00765 Description: 00766 Returns the style of control vertices in the m_cv array. 00767 Returns: 00768 @untitled table 00769 ON::not_rational m_is_rat is false 00770 ON::homogeneous_rational m_is_rat is true 00771 */ 00772 ON::point_style CVStyle() const; 00773 00774 00775 double Weight( // get value of control vertex weight 00776 int // CV index ( >= 0 and < CVCount() ) 00777 ) const; 00778 00779 ON_BOOL32 SetWeight( // get value of control vertex weight 00780 int, // CV index ( >= 0 and < CVCount() ) 00781 double 00782 ); 00783 00784 ON_BOOL32 SetCV( // set a single control vertex 00785 int, // CV index ( >= 0 and < CVCount() ) 00786 ON::point_style, // style of input point 00787 const double* // value of control vertex 00788 ); 00789 00790 ON_BOOL32 SetCV( // set a single control vertex 00791 int, // CV index ( >= 0 and < CVCount() ) 00792 const ON_3dPoint& // value of control vertex 00793 // If NURBS is rational, weight 00794 // will be set to 1. 00795 ); 00796 00797 ON_BOOL32 SetCV( // set a single control vertex 00798 int, // CV index ( >= 0 and < CVCount() ) 00799 const ON_4dPoint& // value of control vertex 00800 // If NURBS is not rational, euclidean 00801 // location of homogeneous point will 00802 // be used. 00803 ); 00804 00805 ON_BOOL32 GetCV( // get a single control vertex 00806 int, // CV index ( >= 0 and < CVCount() ) 00807 ON::point_style, // style to use for output point 00808 double* // array of length >= CVSize() 00809 ) const; 00810 00811 ON_BOOL32 GetCV( // get a single control vertex 00812 int, // CV index ( >= 0 and < CVCount() ) 00813 ON_3dPoint& // gets euclidean cv when NURBS is rational 00814 ) const; 00815 00816 ON_BOOL32 GetCV( // get a single control vertex 00817 int, // CV index ( >= 0 and < CVCount() ) 00818 ON_4dPoint& // gets homogeneous cv 00819 ) const; 00820 00821 // Description: 00822 // Set knot value. 00823 // Parameters: 00824 // knot_index - [in] 0 <= knot_index <= KnotCount()-1 00825 // knot_value - [in] 00826 // Remarks: 00827 // m_knot[] must exist. Use ReserveKnotCapacity to 00828 // allocate m_knot[]. 00829 // Returns: 00830 // true if successful 00831 // See Also: 00832 // ON_NurbsCurve::ReserveKnotCapacity 00833 bool SetKnot( 00834 int knot_index, 00835 double knot_value 00836 ); 00837 00838 // Description: 00839 // Get knot value. 00840 // Parameters: 00841 // knot_index - [in] 0 <= knot_index <= KnotCount()-1 00842 // Returns: 00843 // knot value = m_knot[knot_index] 00844 // See Also: 00845 // ON_NurbsCurve::SetKnot, ON_NurbsCurve::KnotMultiplicity 00846 double Knot( 00847 int knot_index 00848 ) const; 00849 00850 // Description: 00851 // Get knot multiplicity. 00852 // Parameters: 00853 // knot_index - [in] 0 <= knot_index <= KnotCount()-1 00854 // Returns: 00855 // knot multiplicity = m_knot[knot_index] 00856 // See Also: 00857 // ON_NurbsCurve::SetKnot, ON_NurbsCurve::Knot, 00858 // ON_NurbsCurve::InsertKnot 00859 int KnotMultiplicity( 00860 int knot_index 00861 ) const; 00862 00863 // Description: 00864 // Get pointer to knot vector array. 00865 // Returns: 00866 // pointer to knot vector array (m_knot). 00867 // See Also: 00868 // ON_NurbsCurve::SetKnot, ON_NurbsCurve::Knot, 00869 // ON_NurbsCurve::InsertKnot 00870 const double* Knot() const; 00871 00872 // Description: 00873 // Make knot vector a clamped uniform knot vector 00874 // based on the current values of m_order and m_cv_count. 00875 // Does not change values of control vertices. 00876 // Parameters: 00877 // delta - [in] (>0.0) knot spacing. 00878 // Returns: 00879 // true if successful. 00880 // Remarks: 00881 // Allocates m_knot[] if it is not big enough. 00882 // See Also: 00883 // ON_MakeClampedUniformKnotVector 00884 bool MakeClampedUniformKnotVector( 00885 double delta = 1.0 00886 ); 00887 00888 // Description: 00889 // Make knot vector a periodic uniform knot vector 00890 // based on the current values of m_order and m_cv_count. 00891 // Does not change values of control vertices. 00892 // Parameters: 00893 // delta - [in] (>0.0) knot spacing. 00894 // Returns: 00895 // true if successful. 00896 // Remarks: 00897 // Allocates m_knot[] if it is not big enough. 00898 // See Also: 00899 // ON_MakePeriodicUniformKnotVector 00900 bool MakePeriodicUniformKnotVector( 00901 double delta = 1.0 00902 ); 00903 00904 bool IsClamped( // determine if knot vector is clamped 00905 int = 2 // end to check: 0 = start, 1 = end, 2 = start and end 00906 ) const; 00907 00908 double SuperfluousKnot( 00909 int // 0 = start, 1 = end 00910 ) const; 00911 00912 double GrevilleAbcissa( 00913 int // index (0 <= index < CVCount(dir) 00914 ) const; 00915 00916 bool GetGrevilleAbcissae( // see ON_GetGrevilleAbcissae() for details 00917 double* // g[cv_count] 00918 ) const; 00919 00920 bool ZeroCVs(); // zeros control vertices and, if rational, sets weights to 1 00921 00922 // Description: 00923 // Clamp end knots. Does not modify control points. 00924 // Parameters: 00925 // end - [in] 0 = clamp start, 1 = clamp end, 2 = clamp start and end 00926 // Returns: 00927 // true if successful 00928 bool ClampEnd( 00929 int end 00930 ); 00931 00932 // Description: 00933 // Insert a knot and update cv locations. 00934 // Parameters: 00935 // knot_value - [in] m_knot[order-2] < knot_value < m_knot[m_cv_count-1] 00936 // knot_multiplicity - [in] 1 to degree - includes multiplicity of existing knots. 00937 // Remarks: 00938 // Does not change parameterization or locus of curve. 00939 // Returns: 00940 // true if successful 00941 bool InsertKnot( 00942 double knot_value, 00943 int knot_multiplicity 00944 ); 00945 00946 bool MakeRational(); 00947 00948 bool MakeNonRational(); 00949 00950 bool IncreaseDegree( 00951 int desired_degree 00952 ); 00953 00954 bool ChangeDimension( 00955 int desired_dimension 00956 ); 00957 00958 bool Append( const ON_NurbsCurve& ); 00959 00961 // Tools for managing CV and knot memory 00962 bool ReserveCVCapacity( 00963 int // number of doubles to reserve 00964 ); 00965 bool ReserveKnotCapacity( 00966 int // number of doubles to reserve 00967 ); 00968 00970 // returns the length of the control polygon 00971 double ControlPolygonLength() const; 00972 00974 // Converts a span of the NURBS curve into a bezier. If 00975 // the span is empty 00976 // (m_knot[span_index+m_order-2] == m_knot[span_index+m_order-1]), 00977 // then false is returned. 00978 bool ConvertSpanToBezier( 00979 int, // span_index (0 <= span_index <= m_cv_count-m_order) 00980 ON_BezierCurve& // bezier returned here 00981 ) const; 00982 00983 /* 00984 Paramaters: 00985 span_index - [in] 00986 The index of a non-empty span to test. 00987 span_index >= 0 00988 span_index <= m_cv_count-m_order 00989 m_knot[span_index+m_order-2] < m_knot[span_index+m_order-1] 00990 Returns: 00991 true if the span_index parameter is valid and the span is singular 00992 (collapsed to a point). 00993 false if the span is not singular or span_index does not identify 00994 a non-empty span. 00995 */ 00996 bool SpanIsSingular( 00997 int span_index 00998 ) const; 00999 01000 /* 01001 Returns: 01002 True if every span in the NURBS curve is singular. 01003 See Also: 01004 ON_NurbsCurve::RepairBadKnots() 01005 ON_NurbsCurve::RemoveShortSegments() 01006 */ 01007 bool IsSingular() const; 01008 01009 /* 01010 Paramaters: 01011 span_index - [in] 01012 The index of a non-empty span to remove. 01013 span_index >= 0 01014 span_index <= m_cv_count-m_order 01015 m_knot[span_index+m_order-2] < m_knot[span_index+m_order-1] 01016 Returns: 01017 True if the span was successfully removed. 01018 Remarks: 01019 The NURBS curve must have 2 or more spans (m_cv_count > m_order). 01020 Set m0 = mulitiplicity of the knot at m_knot[span_index+m_order-2] 01021 and m1 = mulitiplicity of the knot at m_knot[span_index+m_order-1]. 01022 If (m0 + m1) < degree, then the degree-(m0+m1) cvs will be added 01023 to the NURBS curve. If (m0+m1) > degree, then (m0+m1)-degree cvs will 01024 be removed from the curve. 01025 See Also: 01026 ON_NurbsCurve::RepairBadKnots() 01027 ON_NurbsCurve::RemoveShortSegments() 01028 */ 01029 bool RemoveSpan( 01030 int span_index 01031 ); 01032 01033 /* 01034 Returns: 01035 Number of spans removed. 01036 */ 01037 int RemoveSingularSpans(); 01038 01040 // Returns true if the NURBS curve has bezier spans 01041 // (all distinct knots have multiplitity = degree) 01042 bool HasBezierSpans() const; 01043 01044 /* 01045 Description: 01046 Clamps ends and adds knots so the NURBS curve has bezier spans 01047 (all distinct knots have multiplitity = degree). 01048 Paremeters: 01049 bSetEndWeightsToOne - [in] If true and the first or last weight is 01050 not one, then the first and last spans are reparameterized so 01051 that the end weights are one. 01052 Returns: 01053 true if successful. 01054 */ 01055 bool MakePiecewiseBezier( 01056 bool bSetEndWeightsToOne = false 01057 ); 01058 01059 /* 01060 Description: 01061 Use a combination of scaling and reparameterization to change 01062 the end weights to the specified values. 01063 Parameters: 01064 w0 - [in] weight for first cv 01065 w1 - [in] weight for last cv 01066 Returns: 01067 true if successful. 01068 See Also: 01069 ON_ChangeRationalNurbsCurveEndWeights 01070 Remarks: 01071 The domain, eucleanean locations of the control points, 01072 and locus of the curve do not change, but the weights, 01073 homogeneous cv values and internal knot values may change. 01074 If w0 and w1 are 1 and the curve is not rational, the 01075 curve is not changed. 01076 */ 01077 bool ChangeEndWeights( double w0, double w1 ); 01078 01079 /* 01080 Description: 01081 Use a linear fractional transformation to reparameterize 01082 the NURBS curve. This does not change the curve's domain. 01083 Parameters: 01084 c - [in] 01085 reparameterization constant (generally speaking, c should be > 0). 01086 The control points and knots are adjusted so that 01087 output_nurbs(t) = input_nurbs(lambda(t)), where 01088 lambda(t) = c*t/( (c-1)*t + 1 ). 01089 Note that lambda(0) = 0, lambda(1) = 1, lambda'(t) > 0, 01090 lambda'(0) = c and lambda'(1) = 1/c. 01091 Returns: 01092 true if successful. 01093 Remarks: 01094 The cv and knot values are values are changed so that 01095 output_nurbs(t) = input_nurbs(lambda(t)). 01096 See Also: 01097 ON_ReparameterizeRationalNurbsCurve 01098 */ 01099 bool Reparameterize( double c ); 01100 01101 01102 01104 // Implementation 01105 public: 01106 // NOTE: These members are left "public" so that expert users may efficiently 01107 // create NURBS curves using the default constructor and borrow the 01108 // knot and CV arrays from their native NURBS representation. 01109 // No technical support will be provided for users who access these 01110 // members directly. If you can't get your stuff to work, then use 01111 // the constructor with the arguments and the SetKnot() and SetCV() 01112 // functions to fill in the arrays. 01113 01114 int m_dim; // (>=1) 01115 01116 int m_is_rat; // 1 for rational B-splines. (Rational control 01117 // vertices use homogeneous form.) 01118 // 0 for non-rational B-splines. (Control 01119 // verticies do not have a weight coordinate.) 01120 01121 int m_order; // order = degree+1 (>=2) 01122 01123 int m_cv_count; // number of control vertices ( >= order ) 01124 01125 // knot vector memory 01126 01127 int m_knot_capacity; // If m_knot_capacity > 0, then m_knot[] 01128 // is an array of at least m_knot_capacity 01129 // doubles whose memory is managed by the 01130 // ON_NurbsCurve class using rhmalloc(), 01131 // onrealloc(), and rhfree(). 01132 // If m_knot_capacity is 0 and m_knot is 01133 // not NULL, then m_knot[] is assumed to 01134 // be big enough for any requested operation 01135 // and m_knot[] is not deleted by the 01136 // destructor. 01137 01138 double* m_knot; // Knot vector. ( The knot vector has length 01139 // m_order+m_cv_count-2. ) 01140 01141 // control vertex net memory 01142 01143 int m_cv_stride; // The pointer to start of "CV[i]" is 01144 // m_cv + i*m_cv_stride. 01145 01146 int m_cv_capacity; // If m_cv_capacity > 0, then m_cv[] is an array 01147 // of at least m_cv_capacity doubles whose 01148 // memory is managed by the ON_NurbsCurve 01149 // class using rhmalloc(), onrealloc(), and rhfree(). 01150 // If m_cv_capacity is 0 and m_cv is not 01151 // NULL, then m_cv[] is assumed to be big enough 01152 // for any requested operation and m_cv[] is not 01153 // deleted by the destructor. 01154 01155 double* m_cv; // Control points. 01156 // If m_is_rat is false, then control point is 01157 // 01158 // ( CV(i)[0], ..., CV(i)[m_dim-1] ). 01159 // 01160 // If m_is_rat is true, then the control point 01161 // is stored in HOMOGENEOUS form and is 01162 // 01163 // [ CV(i)[0], ..., CV(i)[m_dim] ]. 01164 // 01165 }; 01166 01167 #endif