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 curve proxy object 00020 // 00022 00023 #if !defined(OPENNURBS_CURVEPROXY_INC_) 00024 #define OPENNURBS_CURVEPROXY_INC_ 00025 00026 /* 00027 Description: 00028 An ON_CurveProxy is a reference to an ON_Curve. 00029 One may specify a subdomain of the referenced curve 00030 and apply a affine reparameterization, possibly reversing 00031 the orientation. The underlying curve cannot be modified through 00032 the curve proxy. 00033 Details: 00034 The reference to the "real_curve" is const, so most functions 00035 which modify an ON_Curve will fail when passed an ON_CurveProxy. 00036 */ 00037 class ON_CurveProxy; 00038 class ON_CLASS ON_CurveProxy : public ON_Curve 00039 { 00040 ON_OBJECT_DECLARE(ON_CurveProxy); 00041 00042 public: 00043 // virtual ON_Object::DestroyRuntimeCache override 00044 void DestroyRuntimeCache( bool bDelete = true ); 00045 00046 public: 00047 ON_CurveProxy(); 00048 ON_CurveProxy( const ON_CurveProxy& ); 00049 ON_CurveProxy( const ON_Curve* ); 00050 ON_CurveProxy( const ON_Curve*, ON_Interval ); 00051 00052 ON_CurveProxy& operator=(const ON_CurveProxy&); 00053 00054 virtual ~ON_CurveProxy(); 00055 00056 // virtual ON_Object::SizeOf override 00057 unsigned int SizeOf() const; 00058 00059 // virtual ON_Object::DataCRC override 00060 ON__UINT32 DataCRC(ON__UINT32 current_remainder) const; 00061 00062 /* 00063 Description: 00064 Sets the curve geometry that "this" is a proxy for. 00065 Sets proxy domain to proxy_curve->Domain(). 00066 Parameters: 00067 real_curve - [in] 00068 */ 00069 void SetProxyCurve( const ON_Curve* real_curve ); 00070 00071 /* 00072 Description: 00073 Sets the curve geometry that "this" is a proxy for. 00074 Sets proxy domain to proxy_curve->Domain(). 00075 Parameters: 00076 real_curve - [in] 00077 real_curve_subdomain - [in] increasing sub interval of 00078 real_curve->Domain(). This interval defines the 00079 portion the "real" curve geometry that "this" proxy 00080 uses. 00081 bReversed - [in] true if the parameterization of "this" proxy 00082 as a curve is reversed from the underlying "real" curve 00083 geometry. 00084 */ 00085 void SetProxyCurve( const ON_Curve* real_curve, 00086 ON_Interval real_curve_subdomain 00087 ); 00088 00089 /* 00090 Returns: 00091 "Real" curve geometry that "this" is a proxy for. 00092 */ 00093 const ON_Curve* ProxyCurve() const; 00094 00095 /* 00096 Description: 00097 Sets portion of the "real" curve that this proxy represents. 00098 Does NOT change the domain of "this" curve. 00099 Parameters: 00100 proxy_curve_subdomain - [in] increasing sub interval of 00101 ProxyCurve()->Domain(). This interval defines the 00102 portion the curve geometry that "this" proxy uses. 00103 Remarks: 00104 This function is poorly named. It does NOT set the proxy 00105 curve's domain. It does set the interval of the "real" 00106 curve for which "this" is a proxy. 00107 */ 00108 bool SetProxyCurveDomain( ON_Interval proxy_curve_subdomain ); 00109 00110 00111 /* 00112 Returns: 00113 Sub interval of the "real" curve's domain that "this" uses. 00114 This interval is not necessarily the same as "this" curve's 00115 domain. 00116 Remarks: 00117 This function is poorly named. It does NOT get the proxy 00118 curve's domain. It does get the evaluation interval 00119 of the "real" curve for which "this" is a proxy. 00120 */ 00121 ON_Interval ProxyCurveDomain() const; 00122 00123 /* 00124 Returns: 00125 True if "this" as a curve is reversed from the "real" curve 00126 geometry. 00127 */ 00128 bool ProxyCurveIsReversed() const; 00129 00130 /* 00131 Parameters: 00132 t - [in] parameter for "this" curve 00133 Returns: 00134 Corresponding parameter in m_real_curve's domain. 00135 */ 00136 double RealCurveParameter( double t ) const; 00137 00138 /* 00139 Parameters: 00140 real_curve_parameter - [in] m_real_curve parameter 00141 Returns: 00142 Corresponding parameter for "this" curve 00143 */ 00144 double ThisCurveParameter( double real_curve_parameter ) const; 00145 00146 private: 00147 // "real" curve geometry that "this" is a proxy for. 00148 const ON_Curve* m_real_curve; 00149 00150 // If true, the parameterization of "this" proxy is 00151 // the reverse of the m_curve parameterization. 00152 bool m_bReversed; 00153 00154 // The m_domain interval is always increasing and included in 00155 // m_curve->Domain(). The m_domain interval defines the portion 00156 // of m_curve that "this" proxy uses and it can be a proper 00157 // sub-interval of m_curve->Domain(). 00158 ON_Interval m_real_curve_domain; 00159 00160 // The evaluation domain of this curve. If "t" is a parameter for 00161 // "this" and "r" is a parameter for m_curve, then when m_bReversed==false 00162 // we have 00163 // t = m_this_domain.ParameterAt(m_real_curve_domain.NormalizedParameterAt(r)) 00164 // r = m_real_curve_domain.ParameterAt(m_this_domain.NormalizedParameterAt(t)) 00165 // and when m_bReversed==true we have 00166 // t = m_this_domain.ParameterAt(1 - m_real_curve_domain.NormalizedParameterAt(r)) 00167 // r = m_real_curve_domain.ParameterAt(1 - m_this_domain.NormalizedParameterAt(t)) 00168 ON_Interval m_this_domain; 00169 00170 ON_Interval RealCurveInterval( const ON_Interval* sub_domain ) const; 00171 00172 00173 public: 00174 /* 00175 Description: 00176 Get a duplicate of the curve. 00177 Returns: 00178 A duplicate of the curve. 00179 Remarks: 00180 The caller must delete the returned curve. 00181 For non-ON_CurveProxy objects, this simply duplicates the curve using 00182 ON_Object::Duplicate. 00183 For ON_CurveProxy objects, this duplicates the actual proxy curve 00184 geometry and, if necessary, trims and reverse the result to that 00185 the returned curve's parameterization and locus match the proxy curve's. 00186 */ 00187 ON_Curve* DuplicateCurve() const; 00188 00190 // ON_Object overrides 00191 00192 /* 00193 Description: 00194 Tests an object to see if its data members are correctly 00195 initialized. 00196 Parameters: 00197 text_log - [in] if the object is not valid and text_log 00198 is not NULL, then a brief englis description of the 00199 reason the object is not valid is appened to the log. 00200 The information appended to text_log is suitable for 00201 low-level debugging purposes by programmers and is 00202 not intended to be useful as a high level user 00203 interface tool. 00204 Returns: 00205 @untitled table 00206 true object is valid 00207 false object is invalid, uninitialized, etc. 00208 Remarks: 00209 Overrides virtual ON_Object::IsValid 00210 */ 00211 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00212 00213 void Dump( ON_TextLog& ) const; // for debugging 00214 00215 ON_BOOL32 Write( // returns false - nothing serialized 00216 ON_BinaryArchive& // open binary file 00217 ) const; 00218 00219 ON_BOOL32 Read( // returns false - nothing serialized 00220 ON_BinaryArchive& // open binary file 00221 ); 00222 00224 // ON_Geometry overrides 00225 00226 int Dimension() const; 00227 00228 ON_BOOL32 GetBBox( // returns true if successful 00229 double*, // minimum 00230 double*, // maximum 00231 ON_BOOL32 = false // true means grow box 00232 ) const; 00233 00234 ON_BOOL32 Transform( 00235 const ON_Xform& 00236 ); 00237 00239 // ON_Curve overrides 00240 00241 // Returns: 00242 // domain of the curve. 00243 // Remarks: 00244 // If m_bReverse is true, this returns the reverse 00245 // of m_domain. 00246 ON_Interval Domain() const; 00247 00248 /* virtual ON_Curve::SetDomain() override */ 00249 ON_BOOL32 SetDomain( 00250 double t0, 00251 double t1 00252 ); 00253 00254 bool SetDomain( ON_Interval domain ); 00255 00256 int SpanCount() const; // number of smooth spans in curve 00257 00258 ON_BOOL32 GetSpanVector( 00259 double* 00260 ) const; 00261 00262 int Degree( // returns maximum algebraic degree of any span 00263 // ( or a good estimate if curve spans are not algebraic ) 00264 ) const; 00265 00266 // (optional - override if curve is piecewise smooth) 00267 ON_BOOL32 GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus 00268 double, // t = parameter in domain 00269 double*, // tminus 00270 double* // tplus 00271 ) const; 00272 00273 ON_BOOL32 IsLinear( // true if curve locus is a line segment between 00274 // between specified points 00275 double = ON_ZERO_TOLERANCE // tolerance to use when checking linearity 00276 ) const; 00277 00278 // virtual override of ON_Curve::IsPolyline 00279 int IsPolyline( 00280 ON_SimpleArray<ON_3dPoint>* pline_points = NULL, 00281 ON_SimpleArray<double>* pline_t = NULL 00282 ) const; 00283 00284 ON_BOOL32 IsArc( // ON_Arc.m_angle > 0 if curve locus is an arc between 00285 // specified points 00286 const ON_Plane* = NULL, // if not NULL, test is performed in this plane 00287 ON_Arc* = NULL, // if not NULL and true is returned, then arc parameters 00288 // are filled in 00289 double = ON_ZERO_TOLERANCE // tolerance to use when checking 00290 ) const; 00291 00292 ON_BOOL32 IsPlanar( 00293 ON_Plane* = NULL, // if not NULL and true is returned, then plane parameters 00294 // are filled in 00295 double = ON_ZERO_TOLERANCE // tolerance to use when checking 00296 ) const; 00297 00298 ON_BOOL32 IsInPlane( 00299 const ON_Plane&, // plane to test 00300 double = ON_ZERO_TOLERANCE // tolerance to use when checking 00301 ) const; 00302 00303 ON_BOOL32 IsClosed( // true if curve is closed (either curve has 00304 void // clamped end knots and euclidean location of start 00305 ) const; // CV = euclidean location of end CV, or curve is 00306 // periodic.) 00307 00308 ON_BOOL32 IsPeriodic( // true if curve is a single periodic segment 00309 void 00310 ) const; 00311 00312 /* 00313 Description: 00314 Search for a derivatitive, tangent, or curvature discontinuity. 00315 Parameters: 00316 c - [in] type of continity to test for. If ON::C1_continuous 00317 t0 - [in] search begins at t0 00318 t1 - [in] (t0 < t1) search ends at t1 00319 t - [out] if a discontinuity is found, the *t reports the 00320 parameter at the discontinuity. 00321 hint - [in/out] if GetNextDiscontinuity will be called repeatedly, 00322 passing a "hint" with initial value *hint=0 will increase the speed 00323 of the search. 00324 dtype - [out] if not NULL, *dtype reports the kind of discontinuity 00325 found at *t. A value of 1 means the first derivative or unit tangent 00326 was discontinuous. A value of 2 means the second derivative or 00327 curvature was discontinuous. 00328 cos_angle_tolerance - [in] default = cos(1 degree) Used only when 00329 c is ON::G1_continuous or ON::G2_continuous. If the cosine 00330 of the angle between two tangent vectors 00331 is <= cos_angle_tolerance, then a G1 discontinuity is reported. 00332 curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when 00333 c is ON::G2_continuous or ON::Gsmooth_continuous. 00334 ON::G2_continuous: 00335 If K0 and K1 are curvatures evaluated 00336 from above and below and |K0 - K1| > curvature_tolerance, 00337 then a curvature discontinuity is reported. 00338 ON::Gsmooth_continuous: 00339 If K0 and K1 are curvatures evaluated from above and below 00340 and the angle between K0 and K1 is at least twice angle tolerance 00341 or ||K0| - |K1|| > (max(|K0|,|K1|) > curvature_tolerance, 00342 then a curvature discontinuity is reported. 00343 Returns: 00344 true if a discontinuity was found on the interior of the interval (t0,t1). 00345 Remarks: 00346 Overrides ON_Curve::GetNextDiscontinuity. 00347 */ 00348 bool GetNextDiscontinuity( 00349 ON::continuity c, 00350 double t0, 00351 double t1, 00352 double* t, 00353 int* hint=NULL, 00354 int* dtype=NULL, 00355 double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE, 00356 double curvature_tolerance=ON_SQRT_EPSILON 00357 ) const; 00358 00359 /* 00360 Description: 00361 Test continuity at a curve parameter value. 00362 Parameters: 00363 c - [in] continuity to test for 00364 t - [in] parameter to test 00365 hint - [in] evaluation hint 00366 point_tolerance - [in] if the distance between two points is 00367 greater than point_tolerance, then the curve is not C0. 00368 d1_tolerance - [in] if the difference between two first derivatives is 00369 greater than d1_tolerance, then the curve is not C1. 00370 d2_tolerance - [in] if the difference between two second derivatives is 00371 greater than d2_tolerance, then the curve is not C2. 00372 cos_angle_tolerance - [in] default = cos(1 degree) Used only when 00373 c is ON::G1_continuous or ON::G2_continuous. If the cosine 00374 of the angle between two tangent vectors 00375 is <= cos_angle_tolerance, then a G1 discontinuity is reported. 00376 curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when 00377 c is ON::G2_continuous or ON::Gsmooth_continuous. 00378 ON::G2_continuous: 00379 If K0 and K1 are curvatures evaluated 00380 from above and below and |K0 - K1| > curvature_tolerance, 00381 then a curvature discontinuity is reported. 00382 ON::Gsmooth_continuous: 00383 If K0 and K1 are curvatures evaluated from above and below 00384 and the angle between K0 and K1 is at least twice angle tolerance 00385 or ||K0| - |K1|| > (max(|K0|,|K1|) > curvature_tolerance, 00386 then a curvature discontinuity is reported. 00387 Returns: 00388 true if the curve has at least the c type continuity at the parameter t. 00389 Remarks: 00390 Overrides ON_Curve::IsContinuous. 00391 */ 00392 bool IsContinuous( 00393 ON::continuity c, 00394 double t, 00395 int* hint = NULL, 00396 double point_tolerance=ON_ZERO_TOLERANCE, 00397 double d1_tolerance=ON_ZERO_TOLERANCE, 00398 double d2_tolerance=ON_ZERO_TOLERANCE, 00399 double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE, 00400 double curvature_tolerance=ON_SQRT_EPSILON 00401 ) const; 00402 00403 ON_BOOL32 Reverse(); // reverse parameterizatrion 00404 // Domain changes from [a,b] to [-b,-a] 00405 00406 ON_BOOL32 Evaluate( // returns false if unable to evaluate 00407 double, // evaluation parameter 00408 int, // number of derivatives (>=0) 00409 int, // array stride (>=Dimension()) 00410 double*, // array of length stride*(ndir+1) 00411 int = 0, // optional - determines which side to evaluate from 00412 // 0 = default 00413 // < 0 to evaluate from below, 00414 // > 0 to evaluate from above 00415 int* = 0 // optional - evaluation hint (int) used to speed 00416 // repeated evaluations 00417 ) const; 00418 00419 // override of virtual ON_Curve::Trim 00420 ON_BOOL32 Trim( 00421 const ON_Interval& domain 00422 ); 00423 00424 // override of virtual ON_Curve::Split 00425 ON_BOOL32 Split( 00426 double t, 00427 ON_Curve*& left_side, 00428 ON_Curve*& right_side 00429 ) const; 00430 00431 int GetNurbForm( // returns 0: unable to create NURBS representation 00432 // with desired accuracy. 00433 // 1: success - returned NURBS parameterization 00434 // matches the curve's to wthe desired accuracy 00435 // 2: success - returned NURBS point locus matches 00436 // the curve's to the desired accuracy but, on 00437 // the interior of the curve's domain, the 00438 // curve's parameterization and the NURBS 00439 // parameterization may not match to the 00440 // desired accuracy. 00441 ON_NurbsCurve&, 00442 double = 0.0, 00443 const ON_Interval* = NULL // OPTIONAL subdomain of ON_CurveProxy::Domain() 00444 ) const; 00445 00446 int HasNurbForm( // returns 0: unable to create NURBS representation 00447 // with desired accuracy. 00448 // 1: success - returned NURBS parameterization 00449 // matches the curve's to wthe desired accuracy 00450 // 2: success - returned NURBS point locus matches 00451 // the curve's to the desired accuracy but, on 00452 // the interior of the curve's domain, the 00453 // curve's parameterization and the NURBS 00454 // parameterization may not match to the 00455 // desired accuracy. 00456 ) const; 00457 00458 // virtual ON_Curve::GetCurveParameterFromNurbFormParameter override 00459 ON_BOOL32 GetCurveParameterFromNurbFormParameter( 00460 double, // nurbs_t 00461 double* // curve_t 00462 ) const; 00463 00464 // virtual ON_Curve::GetNurbFormParameterFromCurveParameter override 00465 ON_BOOL32 GetNurbFormParameterFromCurveParameter( 00466 double, // curve_t 00467 double* // nurbs_t 00468 ) const; 00469 }; 00470 00471 00472 #endif