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 virtual parametric curve 00020 // 00022 00023 #if !defined(OPENNURBS_CURVE_INC_) 00024 #define OPENNURBS_CURVE_INC_ 00025 00026 class ON_Curve; 00027 class ON_Plane; 00028 class ON_Arc; 00029 class ON_NurbsCurve; 00030 class ON_CurveTree; 00031 00032 00035 00036 00037 class ON_CLASS ON_MeshCurveParameters 00038 { 00039 public: 00040 ON_MeshCurveParameters(); 00041 00042 // If main_seg_count <= 0, then both these parameters are ignored. 00043 // If main_seg_count > 0, then sub_seg_count must be >= 1. In this 00044 // case the curve will be broken into main_seg_count equally spaced 00045 // chords. If needed, each of these chords can be split into as many 00046 // sub_seg_count sub-parts if the subdivision is necessary for the 00047 // mesh to meet the other meshing constraints. In particular, if 00048 // sub_seg_count = 0, then the curve is broken into main_seg_count 00049 // pieces and no further testing is performed. 00050 int m_main_seg_count; 00051 int m_sub_seg_count; 00052 00053 int m_reserved1; 00054 int m_reserved2; 00055 00056 // Maximum angle (in radians) between unit tangents at adjacent 00057 // vertices. 00058 double m_max_ang_radians; 00059 00060 // Maximum permitted value of 00061 // distance chord midpoint to curve) / (length of chord) 00062 double m_max_chr; 00063 00064 // If max_aspect < 1.0, the parameter is ignored. 00065 // If 1 <= max_aspect < sqrt(2), it is treated as if 00066 // max_aspect = sqrt(2). 00067 // This parameter controls the maximum permitted value of 00068 // (length of longest chord) / (length of shortest chord) 00069 double m_max_aspect; 00070 00071 // If tolerance = 0, the parameter is ignored. 00072 // This parameter controls the maximum permitted value of the 00073 // distance from the curve to the mesh. 00074 double m_tolerance; 00075 00076 // If m_min_edge_length = 0, the parameter is ignored. 00077 // This parameter controls the minimum permitted edge length. 00078 double m_min_edge_length; 00079 00080 // If max_edge_length = 0, the parameter is ignored. 00081 // This parameter controls the maximum permitted edge length. 00082 double m_max_edge_length; 00083 00084 double m_reserved3; 00085 double m_reserved4; 00086 }; 00087 00088 class ON_CLASS ON_Curve : public ON_Geometry 00089 { 00090 // pure virtual class for curve objects 00091 00092 // Any object derived from ON_Curve should have a 00093 // ON_OBJECT_DECLARE(ON_...); 00094 // as the last line of its class definition and a 00095 // ON_OBJECT_IMPLEMENT( ON_..., ON_baseclass ); 00096 // in a .cpp file. 00097 // 00098 // See the definition of ON_Object for details. 00099 ON_OBJECT_DECLARE(ON_Curve); 00100 00101 public: 00102 // virtual ON_Object::DestroyRuntimeCache override 00103 void DestroyRuntimeCache( bool bDelete = true ); 00104 00105 public: 00106 ON_Curve(); 00107 ON_Curve(const ON_Curve&); 00108 ON_Curve& operator=(const ON_Curve&); 00109 virtual ~ON_Curve(); 00110 00111 // virtual ON_Object::SizeOf override 00112 unsigned int SizeOf() const; 00113 00114 // virtual ON_Geometry override 00115 bool EvaluatePoint( const class ON_ObjRef& objref, ON_3dPoint& P ) const; 00116 00117 /* 00118 Description: 00119 Get a duplicate of the curve. 00120 Returns: 00121 A duplicate of the curve. 00122 Remarks: 00123 The caller must delete the returned curve. 00124 For non-ON_CurveProxy objects, this simply duplicates the curve using 00125 ON_Object::Duplicate. 00126 For ON_CurveProxy objects, this duplicates the actual proxy curve 00127 geometry and, if necessary, trims and reverse the result to that 00128 the returned curve's parameterization and locus match the proxy curve's. 00129 */ 00130 virtual 00131 ON_Curve* DuplicateCurve() const; 00132 00133 // Description: 00134 // overrides virtual ON_Object::ObjectType. 00135 // Returns: 00136 // ON::curve_object 00137 ON::object_type ObjectType() const; 00138 00139 /* 00140 Description: 00141 Get tight bounding box of the curve. 00142 Parameters: 00143 tight_bbox - [in/out] tight bounding box 00144 bGrowBox -[in] (default=false) 00145 If true and the input tight_bbox is valid, then returned 00146 tight_bbox is the union of the input tight_bbox and the 00147 curve's tight bounding box. 00148 xform -[in] (default=NULL) 00149 If not NULL, the tight bounding box of the transformed 00150 curve is calculated. The curve is not modified. 00151 Returns: 00152 True if the returned tight_bbox is set to a valid 00153 bounding box. 00154 */ 00155 bool GetTightBoundingBox( 00156 ON_BoundingBox& tight_bbox, 00157 int bGrowBox = false, 00158 const ON_Xform* xform = 0 00159 ) const; 00160 00162 // curve interface 00163 00164 // Description: 00165 // Gets domain of the curve 00166 // Parameters: 00167 // t0 - [out] 00168 // t1 - [out] domain is [*t0, *t1] 00169 // Returns: 00170 // true if successful. 00171 ON_BOOL32 GetDomain( double* t0, double* t1 ) const; 00172 00173 // Returns: 00174 // domain of the curve. 00175 virtual 00176 ON_Interval Domain() const = 0; 00177 00178 /* 00179 Description: 00180 Set the domain of the curve. 00181 Parameters: 00182 domain - [in] increasing interval 00183 Returns: 00184 true if successful. 00185 */ 00186 bool SetDomain( ON_Interval domain ); 00187 00188 // Description: 00189 // Set the domain of the curve 00190 // Parameters: 00191 // t0 - [in] 00192 // t1 - [in] new domain will be [t0,t1] 00193 // Returns: 00194 // true if successful. 00195 virtual 00196 ON_BOOL32 SetDomain( 00197 double t0, 00198 double t1 00199 ); 00200 00201 00202 /* 00203 Description: 00204 If this curve is closed, then modify it so that 00205 the start/end point is at curve parameter t. 00206 Parameters: 00207 t - [in] curve parameter of new start/end point. The 00208 returned curves domain will start at t. 00209 Returns: 00210 true if successful. 00211 */ 00212 virtual 00213 ON_BOOL32 ChangeClosedCurveSeam( 00214 double t 00215 ); 00216 00217 /* 00218 Description: 00219 Change the dimension of a curve. 00220 Parameters: 00221 desired_dimension - [in] 00222 Returns: 00223 true if the curve's dimension was already desired_dimension 00224 or if the curve's dimension was successfully changed to 00225 desired_dimension. 00226 */ 00227 virtual 00228 bool ChangeDimension( 00229 int desired_dimension 00230 ); 00231 00232 00233 // Description: 00234 // Get number of nonempty smooth (c-infinity) spans in curve 00235 // Returns: 00236 // Number of nonempty smooth (c-infinity) spans. 00237 virtual 00238 int SpanCount() const = 0; 00239 00240 // Description: 00241 // Get number of parameters of "knots". 00242 // Parameters: 00243 // knots - [out] an array of length SpanCount()+1 is filled in 00244 // with the parameters where the curve is not smooth (C-infinity). 00245 // Returns: 00246 // true if successful 00247 virtual 00248 ON_BOOL32 GetSpanVector( 00249 double* knots 00250 ) const = 0; // 00251 00253 // If t is in the domain of the curve, GetSpanVectorIndex() returns the 00254 // span vector index "i" such that span_vector[i] <= t <= span_vector[i+1]. 00255 // The "side" parameter determines which span is selected when t is at the 00256 // end of a span. 00257 virtual 00258 ON_BOOL32 GetSpanVectorIndex( 00259 double t , // [IN] t = evaluation parameter 00260 int side, // [IN] side 0 = default, -1 = from below, +1 = from above 00261 int* span_vector_index, // [OUT] span vector index 00262 ON_Interval* span_domain // [OUT] domain of the span containing "t" 00263 ) const; 00264 00265 // Description: 00266 // Returns maximum algebraic degree of any span 00267 // or a good estimate if curve spans are not algebraic. 00268 // Returns: 00269 // degree 00270 virtual 00271 int Degree() const = 0; 00272 00273 // Description: 00274 // Returns maximum algebraic degree of any span 00275 // or a good estimate if curve spans are not algebraic. 00276 // Returns: 00277 // degree 00278 virtual 00279 ON_BOOL32 GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus 00280 double t, // [IN] t = parameter in domain 00281 double* tminus, // [OUT] tminus 00282 double* tplus // [OUT] tplus 00283 ) const; 00284 00285 // Description: 00286 // Test a curve to see if the locus if its points is a line segment. 00287 // Parameters: 00288 // tolerance - [in] // tolerance to use when checking linearity 00289 // Returns: 00290 // true if the ends of the curve are farther than tolerance apart 00291 // and the maximum distance from any point on the curve to 00292 // the line segment connecting the curve's ends is <= tolerance. 00293 virtual 00294 ON_BOOL32 IsLinear( 00295 double tolerance = ON_ZERO_TOLERANCE 00296 ) const; 00297 00298 /* 00299 Description: 00300 Several types of ON_Curve can have the form of a polyline including 00301 a degree 1 ON_NurbsCurve, an ON_PolylineCurve, and an ON_PolyCurve 00302 all of whose segments are some form of polyline. IsPolyline tests 00303 a curve to see if it can be represented as a polyline. 00304 Parameters: 00305 pline_points - [out] if not NULL and true is returned, then the 00306 points of the polyline form are returned here. 00307 t - [out] if not NULL and true is returned, then the parameters of 00308 the polyline points are returned here. 00309 Returns: 00310 @untitled table 00311 0 curve is not some form of a polyline 00312 >=2 number of points in polyline form 00313 */ 00314 virtual 00315 int IsPolyline( 00316 ON_SimpleArray<ON_3dPoint>* pline_points = NULL, 00317 ON_SimpleArray<double>* pline_t = NULL 00318 ) const; 00319 00320 // Description: 00321 // Test a curve to see if the locus if its points is an arc or circle. 00322 // Parameters: 00323 // plane - [in] if not NULL, test is performed in this plane 00324 // arc - [out] if not NULL and true is returned, then arc parameters 00325 // are filled in 00326 // tolerance - [in] tolerance to use when checking 00327 // Returns: 00328 // ON_Arc.m_angle > 0 if curve locus is an arc between 00329 // specified points. If ON_Arc.m_angle is 2.0*ON_PI, then the curve 00330 // is a circle. 00331 virtual 00332 ON_BOOL32 IsArc( 00333 const ON_Plane* plane = NULL, 00334 ON_Arc* arc = NULL, 00335 double tolerance = ON_ZERO_TOLERANCE 00336 ) const; 00337 00338 /* 00339 Description: 00340 Parameters: 00341 t - [in] curve parameter 00342 plane - [in] 00343 if not NULL, test is performed in this plane 00344 arc - [out] 00345 if not NULL and true is returned, then arc parameters 00346 are filled in 00347 tolerance - [in] 00348 tolerance to use when checking 00349 t0 - [out] 00350 if not NULL, and then *t0 is set to the parameter 00351 at the start of the G2 curve segment that was 00352 tested. 00353 t1 - [out] 00354 if not NULL, and then *t0 is set to the parameter 00355 at the start of the G2 curve segment that was 00356 tested. 00357 Returns: 00358 True if the paramter t is on a arc segment of the curve. 00359 */ 00360 bool IsArcAt( 00361 double t, 00362 const ON_Plane* plane = 0, 00363 ON_Arc* arc = 0, 00364 double tolerance = ON_ZERO_TOLERANCE, 00365 double* t0 = 0, 00366 double* t1 = 0 00367 ) const; 00368 00369 virtual 00370 bool IsEllipse( 00371 const ON_Plane* plane = NULL, 00372 ON_Ellipse* ellipse = NULL, 00373 double tolerance = ON_ZERO_TOLERANCE 00374 ) const; 00375 00376 // Description: 00377 // Test a curve to see if it is planar. 00378 // Parameters: 00379 // plane - [out] if not NULL and true is returned, 00380 // the plane parameters are filled in. 00381 // tolerance - [in] tolerance to use when checking 00382 // Returns: 00383 // true if there is a plane such that the maximum distance from 00384 // the curve to the plane is <= tolerance. 00385 virtual 00386 ON_BOOL32 IsPlanar( 00387 ON_Plane* plane = NULL, 00388 double tolerance = ON_ZERO_TOLERANCE 00389 ) const; 00390 00391 // Description: 00392 // Test a curve to see if it lies in a specific plane. 00393 // Parameters: 00394 // test_plane - [in] 00395 // tolerance - [in] tolerance to use when checking 00396 // Returns: 00397 // true if the maximum distance from the curve to the 00398 // test_plane is <= tolerance. 00399 virtual 00400 ON_BOOL32 IsInPlane( 00401 const ON_Plane& test_plane, 00402 double tolerance = ON_ZERO_TOLERANCE 00403 ) const = 0; 00404 00405 /* 00406 Description: 00407 Decide if it makes sense to close off this curve by moving 00408 the endpoint to the start based on start-end gap size and length 00409 of curve as approximated by chord defined by 6 points. 00410 Parameters: 00411 tolerance - [in] maximum allowable distance between start and end. 00412 if start - end gap is greater than tolerance, returns false 00413 min_abs_size - [in] if greater than 0.0 and none of the interior sampled 00414 points are at least min_abs_size from start, returns false. 00415 min_rel_size - [in] if greater than 1.0 and chord length is less than 00416 min_rel_size*gap, returns false. 00417 Returns: 00418 true if start and end points are close enough based on above conditions. 00419 */ 00420 00421 bool IsClosable( 00422 double tolerance, 00423 double min_abs_size = 0.0, 00424 double min_rel_size = 10.0 00425 ) const; 00426 00427 // Description: 00428 // Test a curve to see if it is closed. 00429 // Returns: 00430 // true if the curve is closed. 00431 virtual 00432 ON_BOOL32 IsClosed() const; 00433 00434 // Description: 00435 // Test a curve to see if it is periodic. 00436 // Returns: 00437 // true if the curve is closed and at least C2 at the start/end. 00438 virtual 00439 ON_BOOL32 IsPeriodic() const; 00440 00441 /* 00442 Description: 00443 Search for a derivatitive, tangent, or curvature 00444 discontinuity. 00445 Parameters: 00446 c - [in] type of continity to test for. 00447 t0 - [in] Search begins at t0. If there is a discontinuity 00448 at t0, it will be ignored. This makes it 00449 possible to repeatedly call GetNextDiscontinuity 00450 and step through the discontinuities. 00451 t1 - [in] (t0 != t1) If there is a discontinuity at t1 is 00452 will be ingored unless c is a locus discontinuity 00453 type and t1 is at the start or end of the curve. 00454 t - [out] if a discontinuity is found, then *t reports the 00455 parameter at the discontinuity. 00456 hint - [in/out] if GetNextDiscontinuity will be called 00457 repeatedly, passing a "hint" with initial value *hint=0 00458 will increase the speed of the search. 00459 dtype - [out] if not NULL, *dtype reports the kind of 00460 discontinuity found at *t. A value of 1 means the first 00461 derivative or unit tangent was discontinuous. A value 00462 of 2 means the second derivative or curvature was 00463 discontinuous. A value of 0 means teh curve is not 00464 closed, a locus discontinuity test was applied, and 00465 t1 is at the start of end of the curve. 00466 If 'c', the type of continuity to test for 00467 is ON::Gsmooth_continuous and the curvature changes 00468 from curved to 0 or 0 to curved and there is no 00469 tangency kink dtype is returns 3 00470 cos_angle_tolerance - [in] default = cos(1 degree) Used only 00471 when c is ON::G1_continuous or ON::G2_continuous. If the 00472 cosine of the angle between two tangent vectors is 00473 <= cos_angle_tolerance, then a G1 discontinuity is reported. 00474 curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used 00475 only when c is ON::G2_continuous. If K0 and K1 are 00476 curvatures evaluated from above and below and 00477 |K0 - K1| > curvature_tolerance, then a curvature 00478 discontinuity is reported. 00479 Returns: 00480 Parametric continuity tests c = (C0_continuous, ..., G2_continuous): 00481 00482 true if a parametric discontinuity was found strictly 00483 between t0 and t1. Note well that all curves are 00484 parametrically continuous at the ends of their domains. 00485 00486 Locus continuity tests c = (C0_locus_continuous, ...,G2_locus_continuous): 00487 00488 true if a locus discontinuity was found strictly between 00489 t0 and t1 or at t1 is the at the end of a curve. 00490 Note well that all open curves (IsClosed()=false) are locus 00491 discontinuous at the ends of their domains. All closed 00492 curves (IsClosed()=true) are at least C0_locus_continuous at 00493 the ends of their domains. 00494 */ 00495 virtual 00496 bool GetNextDiscontinuity( 00497 ON::continuity c, 00498 double t0, 00499 double t1, 00500 double* t, 00501 int* hint=NULL, 00502 int* dtype=NULL, 00503 double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE, 00504 double curvature_tolerance=ON_SQRT_EPSILON 00505 ) const; 00506 00507 /* 00508 Description: 00509 Test continuity at a curve parameter value. 00510 Parameters: 00511 c - [in] type of continuity to test for. Read ON::continuity 00512 comments for details. 00513 t - [in] parameter to test 00514 hint - [in] evaluation hint 00515 point_tolerance - [in] if the distance between two points is 00516 greater than point_tolerance, then the curve is not C0. 00517 d1_tolerance - [in] if the difference between two first derivatives is 00518 greater than d1_tolerance, then the curve is not C1. 00519 d2_tolerance - [in] if the difference between two second derivatives is 00520 greater than d2_tolerance, then the curve is not C2. 00521 cos_angle_tolerance - [in] default = cos(1 degree) Used only when 00522 c is ON::G1_continuous or ON::G2_continuous. If the cosine 00523 of the angle between two tangent vectors 00524 is <= cos_angle_tolerance, then a G1 discontinuity is reported. 00525 curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when 00526 c is ON::G2_continuous or ON::Gsmooth_continuous. 00527 ON::G2_continuous: 00528 If K0 and K1 are curvatures evaluated 00529 from above and below and |K0 - K1| > curvature_tolerance, 00530 then a curvature discontinuity is reported. 00531 ON::Gsmooth_continuous: 00532 If K0 and K1 are curvatures evaluated from above and below 00533 and the angle between K0 and K1 is at least twice angle tolerance 00534 or ||K0| - |K1|| > (max(|K0|,|K1|) > curvature_tolerance, 00535 then a curvature discontinuity is reported. 00536 Returns: 00537 true if the curve has at least the c type continuity at 00538 the parameter t. 00539 */ 00540 virtual 00541 bool IsContinuous( 00542 ON::continuity c, 00543 double t, 00544 int* hint = NULL, 00545 double point_tolerance=ON_ZERO_TOLERANCE, 00546 double d1_tolerance=ON_ZERO_TOLERANCE, 00547 double d2_tolerance=ON_ZERO_TOLERANCE, 00548 double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE, 00549 double curvature_tolerance=ON_SQRT_EPSILON 00550 ) const; 00551 00552 00553 // Description: 00554 // Reverse the direction of the curve. 00555 // Returns: 00556 // true if curve was reversed. 00557 // Remarks: 00558 // If reveresed, the domain changes from [a,b] to [-b,-a] 00559 virtual 00560 ON_BOOL32 Reverse()=0; 00561 00562 00563 /* 00564 Description: 00565 Force the curve to start at a specified point. 00566 Parameters: 00567 start_point - [in] 00568 Returns: 00569 true if successful. 00570 Remarks: 00571 Some end points cannot be moved. Be sure to check return 00572 code. 00573 See Also: 00574 ON_Curve::SetEndPoint 00575 ON_Curve::PointAtStart 00576 ON_Curve::PointAtEnd 00577 */ 00578 virtual 00579 ON_BOOL32 SetStartPoint( 00580 ON_3dPoint start_point 00581 ); 00582 00583 /* 00584 Description: 00585 Force the curve to end at a specified point. 00586 Parameters: 00587 end_point - [in] 00588 Returns: 00589 true if successful. 00590 Remarks: 00591 Some end points cannot be moved. Be sure to check return 00592 code. 00593 See Also: 00594 ON_Curve::SetStartPoint 00595 ON_Curve::PointAtStart 00596 ON_Curve::PointAtEnd 00597 */ 00598 virtual 00599 ON_BOOL32 SetEndPoint( 00600 ON_3dPoint end_point 00601 ); 00602 00603 // Description: 00604 // Evaluate point at a parameter. 00605 // Parameters: 00606 // t - [in] evaluation parameter 00607 // Returns: 00608 // Point (location of curve at the parameter t). 00609 // Remarks: 00610 // No error handling. 00611 // See Also: 00612 // ON_Curve::EvPoint 00613 // ON_Curve::PointAtStart 00614 // ON_Curve::PointAtEnd 00615 ON_3dPoint PointAt( 00616 double t 00617 ) const; 00618 00619 // Description: 00620 // Evaluate point at the start of the curve. 00621 // Parameters: 00622 // t - [in] evaluation parameter 00623 // Returns: 00624 // Point (location of the start of the curve.) 00625 // Remarks: 00626 // No error handling. 00627 // See Also: 00628 // ON_Curve::PointAt 00629 ON_3dPoint PointAtStart() const; 00630 00631 // Description: 00632 // Evaluate point at the end of the curve. 00633 // Parameters: 00634 // t - [in] evaluation parameter 00635 // Returns: 00636 // Point (location of the end of the curve.) 00637 // Remarks: 00638 // No error handling. 00639 // See Also: 00640 // ON_Curve::PointAt 00641 ON_3dPoint PointAtEnd() const; 00642 00643 // Description: 00644 // Evaluate first derivative at a parameter. 00645 // Parameters: 00646 // t - [in] evaluation parameter 00647 // Returns: 00648 // First derivative of the curve at the parameter t. 00649 // Remarks: 00650 // No error handling. 00651 // See Also: 00652 // ON_Curve::Ev1Der 00653 ON_3dVector DerivativeAt( 00654 double t 00655 ) const; 00656 00657 // Description: 00658 // Evaluate unit tangent vector at a parameter. 00659 // Parameters: 00660 // t - [in] evaluation parameter 00661 // Returns: 00662 // Unit tangent vector of the curve at the parameter t. 00663 // Remarks: 00664 // No error handling. 00665 // See Also: 00666 // ON_Curve::EvTangent 00667 ON_3dVector TangentAt( 00668 double t 00669 ) const; 00670 00671 // Description: 00672 // Evaluate the curvature vector at a parameter. 00673 // Parameters: 00674 // t - [in] evaluation parameter 00675 // Returns: 00676 // curvature vector of the curve at the parameter t. 00677 // Remarks: 00678 // No error handling. 00679 // See Also: 00680 // ON_Curve::EvCurvature 00681 ON_3dVector CurvatureAt( 00682 double t 00683 ) const; 00684 00685 // Description: 00686 // Return a 3d frame at a parameter. 00687 // Parameters: 00688 // t - [in] evaluation parameter 00689 // plane - [out] the frame is returned here 00690 // Returns: 00691 // true if successful 00692 // See Also: 00693 // ON_Curve::PointAt, ON_Curve::TangentAt, 00694 // ON_Curve::Ev1Der, Ev2Der 00695 ON_BOOL32 FrameAt( double t, ON_Plane& plane) const; 00696 00697 // Description: 00698 // Evaluate point at a parameter with error checking. 00699 // Parameters: 00700 // t - [in] evaluation parameter 00701 // point - [out] value of curve at t 00702 // side - [in] optional - determines which side to evaluate from 00703 // =0 default 00704 // <0 to evaluate from below, 00705 // >0 to evaluate from above 00706 // hint - [in/out] optional evaluation hint used to speed repeated evaluations 00707 // Returns: 00708 // false if unable to evaluate. 00709 // See Also: 00710 // ON_Curve::PointAt 00711 // ON_Curve::EvTangent 00712 // ON_Curve::Evaluate 00713 ON_BOOL32 EvPoint( 00714 double t, 00715 ON_3dPoint& point, 00716 int side = 0, 00717 int* hint = 0 00718 ) const; 00719 00720 // Description: 00721 // Evaluate first derivative at a parameter with error checking. 00722 // Parameters: 00723 // t - [in] evaluation parameter 00724 // point - [out] value of curve at t 00725 // first_derivative - [out] value of first derivative at t 00726 // side - [in] optional - determines which side to evaluate from 00727 // =0 default 00728 // <0 to evaluate from below, 00729 // >0 to evaluate from above 00730 // hint - [in/out] optional evaluation hint used to speed repeated evaluations 00731 // Returns: 00732 // false if unable to evaluate. 00733 // See Also: 00734 // ON_Curve::EvPoint 00735 // ON_Curve::Ev2Der 00736 // ON_Curve::EvTangent 00737 // ON_Curve::Evaluate 00738 ON_BOOL32 Ev1Der( 00739 double t, 00740 ON_3dPoint& point, 00741 ON_3dVector& first_derivative, 00742 int side = 0, 00743 int* hint = 0 00744 ) const; 00745 00746 // Description: 00747 // Evaluate second derivative at a parameter with error checking. 00748 // Parameters: 00749 // t - [in] evaluation parameter 00750 // point - [out] value of curve at t 00751 // first_derivative - [out] value of first derivative at t 00752 // second_derivative - [out] value of second derivative at t 00753 // side - [in] optional - determines which side to evaluate from 00754 // =0 default 00755 // <0 to evaluate from below, 00756 // >0 to evaluate from above 00757 // hint - [in/out] optional evaluation hint used to speed repeated evaluations 00758 // Returns: 00759 // false if unable to evaluate. 00760 // See Also: 00761 // ON_Curve::Ev1Der 00762 // ON_Curve::EvCurvature 00763 // ON_Curve::Evaluate 00764 ON_BOOL32 Ev2Der( 00765 double t, 00766 ON_3dPoint& point, 00767 ON_3dVector& first_derivative, 00768 ON_3dVector& second_derivative, 00769 int side = 0, 00770 int* hint = 0 00771 ) const; 00772 00773 /* 00774 Description: 00775 Evaluate unit tangent at a parameter with error checking. 00776 Parameters: 00777 t - [in] evaluation parameter 00778 point - [out] value of curve at t 00779 tangent - [out] value of unit tangent 00780 side - [in] optional - determines which side to evaluate from 00781 =0 default 00782 <0 to evaluate from below, 00783 >0 to evaluate from above 00784 hint - [in/out] optional evaluation hint used to speed repeated evaluations 00785 Returns: 00786 false if unable to evaluate. 00787 See Also: 00788 ON_Curve::TangentAt 00789 ON_Curve::Ev1Der 00790 */ 00791 ON_BOOL32 EvTangent( 00792 double t, 00793 ON_3dPoint& point, 00794 ON_3dVector& tangent, 00795 int side = 0, 00796 int* hint = 0 00797 ) const; 00798 00799 /* 00800 Description: 00801 Evaluate unit tangent and curvature at a parameter with error checking. 00802 Parameters: 00803 t - [in] evaluation parameter 00804 point - [out] value of curve at t 00805 tangent - [out] value of unit tangent 00806 kappa - [out] value of curvature vector 00807 side - [in] optional - determines which side to evaluate from 00808 =0 default 00809 <0 to evaluate from below, 00810 >0 to evaluate from above 00811 hint - [in/out] optional evaluation hint used to speed repeated evaluations 00812 Returns: 00813 false if unable to evaluate. 00814 See Also: 00815 ON_Curve::CurvatureAt 00816 ON_Curve::Ev2Der 00817 ON_EvCurvature 00818 */ 00819 ON_BOOL32 EvCurvature( 00820 double t, 00821 ON_3dPoint& point, 00822 ON_3dVector& tangent, 00823 ON_3dVector& kappa, 00824 int side = 0, 00825 int* hint = 0 00826 ) const; 00827 00828 /* 00829 Description: 00830 This evaluator actually does all the work. The other ON_Curve 00831 evaluation tools call this virtual function. 00832 Parameters: 00833 t - [in] evaluation parameter ( usually in Domain() ). 00834 der_count - [in] (>=0) number of derivatives to evaluate 00835 v_stride - [in] (>=Dimension()) stride to use for the v[] array 00836 v - [out] array of length (der_count+1)*v_stride 00837 curve(t) is returned in (v[0],...,v[m_dim-1]), 00838 curve'(t) is retuned in (v[v_stride],...,v[v_stride+m_dim-1]), 00839 curve"(t) is retuned in (v[2*v_stride],...,v[2*v_stride+m_dim-1]), 00840 etc. 00841 side - [in] optional - determines which side to evaluate from 00842 =0 default 00843 <0 to evaluate from below, 00844 >0 to evaluate from above 00845 hint - [in/out] optional evaluation hint used to speed repeated evaluations 00846 Returns: 00847 false if unable to evaluate. 00848 See Also: 00849 ON_Curve::EvPoint 00850 ON_Curve::Ev1Der 00851 ON_Curve::Ev2Der 00852 */ 00853 virtual 00854 ON_BOOL32 Evaluate( 00855 double t, 00856 int der_count, 00857 int v_stride, 00858 double* v, 00859 int side = 0, 00860 int* hint = 0 00861 ) const = 0; 00862 00863 00864 /* 00865 Parameters: 00866 min_length -[in] 00867 minimum length of a linear span 00868 tolerance -[in] 00869 distance tolerance to use when checking linearity. 00870 Returns 00871 true if the span is a non-degenrate line. This means: 00872 - dimension = 2 or 3 00873 - The length of the the line segment from the span's initial 00874 point to the span's control point is >= min_length. 00875 - The maximum distance from the line segment to the span 00876 is <= tolerance and the span increases monotonically 00877 in the direction of the line segment. 00878 */ 00879 bool FirstSpanIsLinear( 00880 double min_length, 00881 double tolerance 00882 ) const; 00883 00884 bool LastSpanIsLinear( 00885 double min_length, 00886 double tolerance 00887 ) const; 00888 00889 bool FirstSpanIsLinear( 00890 double min_length, 00891 double tolerance, 00892 ON_Line* span_line 00893 ) const; 00894 00895 bool LastSpanIsLinear( 00896 double min_length, 00897 double tolerance, 00898 ON_Line* span_line 00899 ) const; 00900 00901 // Description: 00902 // Removes portions of the curve outside the specified interval. 00903 // Parameters: 00904 // domain - [in] interval of the curve to keep. Portions of the 00905 // curve before curve(domain[0]) and after curve(domain[1]) are 00906 // removed. 00907 // Returns: 00908 // true if successful. 00909 virtual 00910 ON_BOOL32 Trim( 00911 const ON_Interval& domain 00912 ); 00913 00914 // Description: 00915 // Pure virtual function. Default returns false. 00916 // Where possible, analytically extends curve to include domain. 00917 // Parameters: 00918 // domain - [in] if domain is not included in curve domain, 00919 // curve will be extended so that its domain includes domain. 00920 // Will not work if curve is closed. Original curve is identical 00921 // to the restriction of the resulting curve to the original curve domain, 00922 // Returns: 00923 // true if successful. 00924 virtual 00925 bool Extend( 00926 const ON_Interval& domain 00927 ); 00928 00929 /* 00930 Description: 00931 Splits (divides) the curve at the specified parameter. 00932 The parameter must be in the interior of the curve's domain. 00933 The pointers passed to Split must either be NULL or point to 00934 an ON_Curve object of the same type. If the pointer is NULL, 00935 then a curve will be created in Split(). You may pass "this" 00936 as left_side or right_side. 00937 Parameters: 00938 t - [in] parameter to split the curve at in the 00939 interval returned by Domain(). 00940 left_side - [out] left portion of curve returned here 00941 right_side - [out] right portion of curve returned here 00942 Returns: 00943 true - The curve was split into two pieces. 00944 false - The curve could not be split. For example if the parameter is 00945 too close to an endpoint. 00946 00947 Example: 00948 For example, if crv were an ON_NurbsCurve, then 00949 00950 ON_NurbsCurve right_side; 00951 crv.Split( crv.Domain().Mid() &crv, &right_side ); 00952 00953 would split crv at the parametric midpoint, put the left side 00954 in crv, and return the right side in right_side. 00955 */ 00956 virtual 00957 ON_BOOL32 Split( 00958 double t, 00959 ON_Curve*& left_side, 00960 ON_Curve*& right_side 00961 ) const; 00962 00963 /* 00964 Description: 00965 Get a NURBS curve representation of this curve. 00966 Parameters: 00967 nurbs_curve - [out] NURBS representation returned here 00968 tolerance - [in] tolerance to use when creating NURBS 00969 representation. 00970 subdomain - [in] if not NULL, then the NURBS representation 00971 for this portion of the curve is returned. 00972 Returns: 00973 0 unable to create NURBS representation 00974 with desired accuracy. 00975 1 success - returned NURBS parameterization 00976 matches the curve's to wthe desired accuracy 00977 2 success - returned NURBS point locus matches 00978 the curve's to the desired accuracy and the 00979 domain of the NURBS curve is correct. On 00980 However, This curve's parameterization and 00981 the NURBS curve parameterization may not 00982 match to the desired accuracy. This situation 00983 happens when getting NURBS representations of 00984 curves that have a transendental parameterization 00985 like circles 00986 Remarks: 00987 This is a low-level virtual function. If you do not need 00988 the parameterization information provided by the return code, 00989 then ON_Curve::NurbsCurve may be easier to use. 00990 See Also: 00991 ON_Curve::NurbsCurve 00992 */ 00993 virtual 00994 int GetNurbForm( 00995 ON_NurbsCurve& nurbs_curve, 00996 double tolerance = 0.0, 00997 const ON_Interval* subdomain = NULL 00998 ) const; 00999 /* 01000 Description: 01001 Does a NURBS curve representation of this curve. 01002 Parameters: 01003 Returns: 01004 0 unable to create NURBS representation 01005 with desired accuracy. 01006 1 success - NURBS parameterization 01007 matches the curve's to wthe desired accuracy 01008 2 success - NURBS point locus matches 01009 the curve's and the 01010 domain of the NURBS curve is correct. 01011 However, This curve's parameterization and 01012 the NURBS curve parameterization may not 01013 match. This situation 01014 happens when getting NURBS representations of 01015 curves that have a transendental parameterization 01016 like circles 01017 Remarks: 01018 This is a low-level virtual function. 01019 See Also: 01020 ON_Curve::GetNurbForm 01021 ON_Curve::NurbsCurve 01022 */ 01023 virtual 01024 int HasNurbForm() const; 01025 01026 /* 01027 Description: 01028 Get a NURBS curve representation of this curve. 01029 Parameters: 01030 pNurbsCurve - [in/out] if not NULL, this ON_NurbsCurve 01031 will be used to store the NURBS representation 01032 of the curve will be returned. 01033 tolerance - [in] tolerance to use when creating NURBS 01034 representation. 01035 subdomain - [in] if not NULL, then the NURBS representation 01036 for this portion of the curve is returned. 01037 Returns: 01038 NULL or a NURBS representation of the curve. 01039 Remarks: 01040 See ON_Surface::GetNurbForm for important details about 01041 the NURBS surface parameterization. 01042 See Also: 01043 ON_Curve::GetNurbForm 01044 */ 01045 ON_NurbsCurve* NurbsCurve( 01046 ON_NurbsCurve* pNurbsCurve = NULL, 01047 double tolerance = 0.0, 01048 const ON_Interval* subdomain = NULL 01049 ) const; 01050 01051 // Description: 01052 // Convert a NURBS curve parameter to a curve parameter 01053 // 01054 // Parameters: 01055 // nurbs_t - [in] nurbs form parameter 01056 // curve_t - [out] curve parameter 01057 // 01058 // Remarks: 01059 // If GetNurbForm returns 2, this function converts the curve 01060 // parameter to the NURBS curve parameter. 01061 // 01062 // See Also: 01063 // ON_Curve::GetNurbForm, ON_Curve::GetNurbFormParameterFromCurveParameter 01064 virtual 01065 ON_BOOL32 GetCurveParameterFromNurbFormParameter( 01066 double nurbs_t, 01067 double* curve_t 01068 ) const; 01069 01070 // Description: 01071 // Convert a curve parameter to a NURBS curve parameter. 01072 // 01073 // Parameters: 01074 // curve_t - [in] curve parameter 01075 // nurbs_t - [out] nurbs form parameter 01076 // 01077 // Remarks: 01078 // If GetNurbForm returns 2, this function converts the curve 01079 // parameter to the NURBS curve parameter. 01080 // 01081 // See Also: 01082 // ON_Curve::GetNurbForm, ON_Curve::GetCurveParameterFromNurbFormParameter 01083 virtual 01084 ON_BOOL32 GetNurbFormParameterFromCurveParameter( 01085 double curve_t, 01086 double* nurbs_t 01087 ) const; 01088 01089 01090 // Description: 01091 // Destroys the runtime curve tree used to speed closest 01092 // point and intersection calcuations. 01093 // Remarks: 01094 // If the geometry of the curve is modified in any way, 01095 // then call DestroyCurveTree(); The curve tree is 01096 // created as needed. 01097 void DestroyCurveTree(); 01098 01099 /* 01100 Description: 01101 Lookup a parameter in the m_t array, optionally using a built in snap tolerance to 01102 snap a parameter value to an element of m_t. 01103 This function is used by some types derived from ON_Curve to snap parameter values 01104 Parameters: 01105 t - [in] parameter 01106 index -[out] index into m_t such that 01107 if function returns false then 01108 01109 @table 01110 value condition 01111 -1 t<m_t[0] or m_t is empty 01112 0<=i<=m_t.Count()-2 m_t[i] < t < m_t[i+1] 01113 m_t.Count()-1 t>m_t[ m_t.Count()-1] 01114 01115 if the function returns true then t is equal to, or is closest to and 01116 within tolerance of m_t[index]. 01117 01118 bEnableSnap-[in] enable snapping 01119 m_t -[in] Array of parameter values to snap to 01120 RelTol -[in] tolerance used in snapping 01121 01122 Returns: 01123 true if the t is exactly equal to (bEnableSnap==false), or within tolerance of 01124 (bEnableSnap==true) m_t[index]. 01125 */ 01126 protected: 01127 bool ParameterSearch( double t, int& index, bool bEnableSnap, const ON_SimpleArray<double>& m_t, 01128 double RelTol=ON_SQRT_EPSILON) const; 01129 01130 private: 01131 }; 01132 01133 #if defined(ON_DLL_TEMPLATE) 01134 // This stuff is here because of a limitation in the way Microsoft 01135 // handles templates and DLLs. See Microsoft's knowledge base 01136 // article ID Q168958 for details. 01137 #pragma warning( push ) 01138 #pragma warning( disable : 4231 ) 01139 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_Curve*>; 01140 #pragma warning( pop ) 01141 #endif 01142 01143 class ON_CLASS ON_CurveArray : public ON_SimpleArray<ON_Curve*> 01144 { 01145 public: 01146 ON_CurveArray( int = 0 ); 01147 ~ON_CurveArray(); // deletes any non-NULL curves 01148 01149 bool Write( ON_BinaryArchive& ) const; 01150 bool Read( ON_BinaryArchive& ); 01151 01152 void Destroy(); // deletes curves, sets pointers to NULL, sets count to zero 01153 01154 bool Duplicate( ON_CurveArray& ) const; // operator= copies the pointer values 01155 // duplicate copies the curves themselves 01156 01157 /* 01158 Description: 01159 Get tight bounding box of the bezier. 01160 Parameters: 01161 tight_bbox - [in/out] tight bounding box 01162 bGrowBox -[in] (default=false) 01163 If true and the input tight_bbox is valid, then returned 01164 tight_bbox is the union of the input tight_bbox and the 01165 tight bounding box of the bezier curve. 01166 xform -[in] (default=NULL) 01167 If not NULL, the tight bounding box of the transformed 01168 bezier is calculated. The bezier curve is not modified. 01169 Returns: 01170 True if the returned tight_bbox is set to a valid 01171 bounding box. 01172 */ 01173 bool GetTightBoundingBox( 01174 ON_BoundingBox& tight_bbox, 01175 int bGrowBox = false, 01176 const ON_Xform* xform = 0 01177 ) const; 01178 }; 01179 01180 /* 01181 Description: 01182 Trim a curve. 01183 Parameters: 01184 curve - [in] curve to trim (not modified) 01185 trim_parameters - [in] trimming parameters 01186 If curve is open, then trim_parameters must be an increasing 01187 interval.If curve is closed, and trim_parameters ins a 01188 decreasing interval, then the portion of the curve across the 01189 start/end is returned. 01190 Returns: 01191 trimmed curve or NULL if input is invalid. 01192 */ 01193 ON_DECL 01194 ON_Curve* ON_TrimCurve( 01195 const ON_Curve& curve, 01196 ON_Interval trim_parameters 01197 ); 01198 01199 /* 01200 Description: 01201 Move ends of curves to a common point. Neither curve can be closed or an ON_CurveProxy. 01202 If one is an arc or polycurve with arc at end to change, and the other is not, 01203 then the arc is left unchanged and the other curve is moved to the arc endpoint. 01204 Otherwise, both are moved to the midpoint of the segment between the ends. 01205 Parameters: 01206 Crv0 - [in] first curve to modify. 01207 [out] with one endpoint possibly changed. 01208 end0 - [in] if 0, change start of Crv0. Otherwise change end. 01209 Crv1 - [in] second curve to modify. 01210 [out] with one endpoint possibly changed. 01211 end1 - [in] if 0, change start of Crv1. Otherwise change end. 01212 Returns: 01213 true if the endpoints match. Falsse otherwise, 01214 */ 01215 ON_DECL 01216 bool ON_ForceMatchCurveEnds( 01217 ON_Curve& Crv0, 01218 int end0, 01219 ON_Curve& Crv1, 01220 int end1 01221 ); 01222 01223 /* 01224 Description: 01225 Join all contiguous curves of an array of ON_Curves. 01226 Parameters: 01227 InCurves - [in] Array of curves to be joined (not modified) 01228 OutCurves - [out] Resulting joined curves and copies of curves that were not joined to anything 01229 are appended. 01230 join_tol - [in] Distance tolerance used to decide if endpoints are close enough 01231 bPreserveDirection - [in] If true, curve endpoints will be compared to curve startpoints. 01232 If false, all start and endpoints will be compared, and copies of input 01233 curves may be reversed in output. 01234 key - [out] if key is not null, InCurves[i] was joined into OutCurves[key[i]]. 01235 Returns: 01236 Number of curves added to Outcurves 01237 Remarks: 01238 Closed curves are copied to OutCurves. 01239 Curves that cannot be joined to others are copied to OutCurves. When curves are joined, the results 01240 are ON_PolyCurves. All members of InCurves must have same dimension, at most 3. 01241 */ 01242 ON_DECL 01243 int ON_JoinCurves(const ON_SimpleArray<const ON_Curve*>& InCurves, 01244 ON_SimpleArray<ON_Curve*>& OutCurves, 01245 double join_tol, 01246 bool bPreserveDirection = false, 01247 ON_SimpleArray<int>* key = 0 01248 ); 01249 01250 01251 /* 01252 Description: 01253 Sort a list of lines so they are geometrically continuous. 01254 Parameters: 01255 line_count - [in] number of lines 01256 line_list - [in] array of lines 01257 index - [out] The input index[] is an array of line_count unused integers. 01258 The returned index[] is a permutation of {0,1,...,line_count-1} 01259 so that the list of lines is in end-to-end order. 01260 bReverse - [out] The input bReverse[] is an array of line_count unused bools. 01261 If the returned value of bReverse[j] is true, then 01262 line_list[index[j]] needs to be reversed. 01263 Returns: 01264 True if successful, false if not. 01265 */ 01266 ON_DECL 01267 bool ON_SortLines( 01268 int line_count, 01269 const ON_Line* line_list, 01270 int* index, 01271 bool* bReverse 01272 ); 01273 01274 /* 01275 Description: 01276 Sort a list of lines so they are geometrically continuous. 01277 Parameters: 01278 line_list - [in] array of lines 01279 index - [out] The input index[] is an array of line_count unused integers. 01280 The returned index[] is a permutation of {0,1,...,line_count-1} 01281 so that the list of lines is in end-to-end order. 01282 bReverse - [out] The input bReverse[] is an array of line_count unused bools. 01283 If the returned value of bReverse[j] is true, then 01284 line_list[index[j]] needs to be reversed. 01285 Returns: 01286 True if successful, false if not. 01287 */ 01288 ON_DECL 01289 bool ON_SortLines( 01290 const ON_SimpleArray<ON_Line>& line_list, 01291 int* index, 01292 bool* bReverse 01293 ); 01294 01295 /* 01296 Description: 01297 Sort a list of open curves so end of a curve matches the start of the next curve. 01298 Parameters: 01299 curve_count - [in] number of curves 01300 curve_list - [in] array of curve pointers 01301 index - [out] The input index[] is an array of curve_count unused integers. 01302 The returned index[] is a permutation of {0,1,...,curve_count-1} 01303 so that the list of curves is in end-to-end order. 01304 bReverse - [out] The input bReverse[] is an array of curve_count unused bools. 01305 If the returned value of bReverse[j] is true, then 01306 curve_list[index[j]] needs to be reversed. 01307 Returns: 01308 True if successful, false if not. 01309 */ 01310 ON_DECL 01311 bool ON_SortCurves( 01312 int curve_count, 01313 const ON_Curve* const* curve_list, 01314 int* index, 01315 bool* bReverse 01316 ); 01317 01318 /* 01319 Description: 01320 Sort a list of curves so end of a curve matches the start of the next curve. 01321 Parameters: 01322 curve - [in] array of curves to sort. The curves themselves are not modified. 01323 index - [out] The input index[] is an array of curve_count unused integers. 01324 The returned index[] is a permutation of {0,1,...,curve_count-1} 01325 so that the list of curves is in end-to-end order. 01326 bReverse - [out] The input bReverse[] is an array of curve_count unused bools. 01327 If the returned value of bReverse[j] is true, then 01328 curve[index[j]] needs to be reversed. 01329 Returns: 01330 True if successful, false if not. 01331 */ 01332 ON_DECL 01333 bool ON_SortCurves( 01334 const ON_SimpleArray<const ON_Curve*>& curves, 01335 ON_SimpleArray<int>& index, 01336 ON_SimpleArray<bool>& bReverse 01337 ); 01338 01339 /* 01340 Description: 01341 Sort a list of curves so end of a curve matches the start of the next curve. 01342 Parameters: 01343 curve_count - [in] number of curves 01344 curve - [in] array of curve pointers 01345 index - [out] The input index[] is an array of curve_count unused integers. 01346 The returned index[] is a permutation of {0,1,...,curve_count-1} 01347 so that the list of curves is in end-to-end order. 01348 bReverse - [out] The input bReverse[] is an array of curve_count unused bools. 01349 If the returned value of bReverse[j] is true, then 01350 curve[index[j]] needs to be reversed. 01351 Returns: 01352 True if successful, false if not. 01353 */ 01354 ON_DECL 01355 bool ON_SortCurves( 01356 const ON_SimpleArray<ON_Curve*>& curves, 01357 ON_SimpleArray<int>& index, 01358 ON_SimpleArray<bool>& bReverse 01359 ); 01360 01361 /* 01362 Description: 01363 Determine the orientaion (counterclockwise or clockwise) of a closed 01364 planar curve. 01365 Paramters: 01366 curve - [in] simple (no self intersections) closed planar curve 01367 xform - [in] Transformation to map the curve to the xy plane. If the 01368 curve is parallel to the xy plane, you may pass NULL. 01369 Returns: 01370 +1: The curve's orientation is counter clockwise in the xy plane. 01371 -1: The curve's orientation is clockwise in the xy plane. 01372 0: Unable to compute the curve's orientation. 01373 */ 01374 ON_DECL 01375 int ON_ClosedCurveOrientation( const ON_Curve& curve, const ON_Xform* xform ); 01376 01377 #endif