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 surface proxy object 00020 // 00022 00023 #if !defined(OPENNURBS_SURFACEPROXY_INC_) 00024 #define OPENNURBS_SURFACEPROXY_INC_ 00025 00026 class ON_Curve; 00027 class ON_NurbsSurface; 00028 class ON_CLASS ON_SurfaceProxy : public ON_Surface 00029 { 00030 public: 00031 // virtual ON_Object::DestroyRuntimeCache override 00032 void DestroyRuntimeCache( bool bDelete = true ); 00033 00034 public: 00035 ON_SurfaceProxy(); 00036 ON_SurfaceProxy(const ON_Surface*); 00037 ON_SurfaceProxy(const ON_SurfaceProxy&); 00038 ON_SurfaceProxy& operator=(const ON_SurfaceProxy&); 00039 00040 virtual ~ON_SurfaceProxy(); 00041 00042 void SetProxySurface( const ON_Surface* proxy_surface ); 00043 const ON_Surface* ProxySurface() const; 00044 bool ProxySurfaceIsTransposed() const; 00045 00046 private: 00047 const ON_Surface* m_surface; 00048 bool m_bTransposed; // proxy surface parameterization is transpose of m_surface 00049 00050 public: 00051 /* 00052 Description: 00053 Get a duplicate of the surface. 00054 Returns: 00055 A duplicate of the surface. 00056 Remarks: 00057 The caller must delete the returned surface. 00058 For non-ON_SurfaceProxy objects, this simply duplicates the surface using 00059 ON_Object::Duplicate. 00060 For ON_SurfaceProxy objects, this duplicates the actual proxy surface 00061 geometry and, if necessary, transposes the result to that 00062 the returned surfaces's parameterization and locus match the proxy surface's. 00063 */ 00064 virtual 00065 ON_Surface* DuplicateSurface() const; 00066 00068 // ON_Object overrides 00069 00070 // virtual ON_Object::SizeOf override 00071 unsigned int SizeOf() const; 00072 00073 // virtual ON_Object::DataCRC override 00074 ON__UINT32 DataCRC(ON__UINT32 current_remainder) const; 00075 00076 /* 00077 Description: 00078 Tests an object to see if its data members are correctly 00079 initialized. 00080 Parameters: 00081 text_log - [in] if the object is not valid and text_log 00082 is not NULL, then a brief englis description of the 00083 reason the object is not valid is appened to the log. 00084 The information appended to text_log is suitable for 00085 low-level debugging purposes by programmers and is 00086 not intended to be useful as a high level user 00087 interface tool. 00088 Returns: 00089 @untitled table 00090 true object is valid 00091 false object is invalid, uninitialized, etc. 00092 Remarks: 00093 Overrides virtual ON_Object::IsValid 00094 */ 00095 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00096 00097 void Dump( ON_TextLog& ) const; // for debugging 00098 00099 ON_BOOL32 Write( 00100 ON_BinaryArchive& // open binary file 00101 ) const; 00102 00103 ON_BOOL32 Read( 00104 ON_BinaryArchive& // open binary file 00105 ); 00106 00108 // ON_Geometry overrides 00109 00110 int Dimension() const; 00111 00112 ON_BOOL32 GetBBox( // returns true if successful 00113 double*, // minimum 00114 double*, // maximum 00115 ON_BOOL32 = false // true means grow box 00116 ) const; 00117 00118 ON_BOOL32 Transform( 00119 const ON_Xform& 00120 ); 00121 00123 // ON_Surface overrides 00124 00125 ON_Interval Domain( 00126 int // 0 gets first parameter's domain, 1 gets second parameter's domain 00127 ) const; 00128 00129 00130 /* 00131 Description: 00132 Get an estimate of the size of the rectangle that would 00133 be created if the 3d surface where flattened into a rectangle. 00134 Parameters: 00135 width - [out] (corresponds to the first surface parameter) 00136 height - [out] (corresponds to the first surface parameter) 00137 Remarks: 00138 overrides virtual ON_Surface::GetSurfaceSize 00139 Returns: 00140 true if successful. 00141 */ 00142 ON_BOOL32 GetSurfaceSize( 00143 double* width, 00144 double* height 00145 ) const; 00146 00147 int SpanCount( 00148 int // 0 gets first parameter's domain, 1 gets second parameter's domain 00149 ) const; // number of smooth spans in curve 00150 00151 ON_BOOL32 GetSpanVector( // span "knots" 00152 int, // 0 gets first parameter's domain, 1 gets second parameter's domain 00153 double* // array of length SpanCount() + 1 00154 ) const; // 00155 00156 int Degree( // returns maximum algebraic degree of any span 00157 // ( or a good estimate if curve spans are not algebraic ) 00158 int // 0 gets first parameter's domain, 1 gets second parameter's domain 00159 ) const; 00160 00161 00162 ON_BOOL32 GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus 00163 int, // 0 gets first parameter, 1 gets second parameter 00164 double, // t = parameter in domain 00165 double*, // tminus 00166 double* // tplus 00167 ) const; 00168 00169 // override virtual ON_Surface::IsIsoparametric 00170 ISO IsIsoparametric( 00171 const ON_Curve& curve, 00172 const ON_Interval* curve_domain = NULL 00173 ) const; 00174 00175 // override virtual ON_Surface::IsIsoparametric 00176 ISO IsIsoparametric( 00177 const ON_BoundingBox& bbox 00178 ) const; 00179 00180 /* 00181 Description: 00182 Test a surface to see if it is planar. 00183 Parameters: 00184 plane - [out] if not NULL and true is returned, 00185 the plane parameters are filled in. 00186 tolerance - [in] tolerance to use when checking 00187 Returns: 00188 true if there is a plane such that the maximum distance from 00189 the surface to the plane is <= tolerance. 00190 Remarks: 00191 Overrides virtual ON_Surface::IsPlanar. 00192 */ 00193 ON_BOOL32 IsPlanar( 00194 ON_Plane* plane = NULL, 00195 double tolerance = ON_ZERO_TOLERANCE 00196 ) const; 00197 00198 ON_BOOL32 IsClosed( // true if surface is closed in direction 00199 int // dir 0 = "s", 1 = "t" 00200 ) const; 00201 00202 ON_BOOL32 IsPeriodic( // true if surface is periodic in direction 00203 int // dir 0 = "s", 1 = "t" 00204 ) const; 00205 00206 ON_BOOL32 IsSingular( // true if surface side is collapsed to a point 00207 int // side of parameter space to test 00208 // 0 = south, 1 = east, 2 = north, 3 = west 00209 ) const; 00210 00211 /* 00212 Description: 00213 Search for a derivatitive, tangent, or curvature 00214 discontinuity. 00215 Parameters: 00216 dir - [in] If 0, then "u" parameter is checked. If 1, then 00217 the "v" parameter is checked. 00218 c - [in] type of continity to test for. 00219 t0 - [in] Search begins at t0. If there is a discontinuity 00220 at t0, it will be ignored. This makes it 00221 possible to repeatedly call GetNextDiscontinuity 00222 and step through the discontinuities. 00223 t1 - [in] (t0 != t1) If there is a discontinuity at t1 is 00224 will be ingored unless c is a locus discontinuity 00225 type and t1 is at the start or end of the curve. 00226 t - [out] if a discontinuity is found, then *t reports the 00227 parameter at the discontinuity. 00228 hint - [in/out] if GetNextDiscontinuity will be called 00229 repeatedly, passing a "hint" with initial value *hint=0 00230 will increase the speed of the search. 00231 dtype - [out] if not NULL, *dtype reports the kind of 00232 discontinuity found at *t. A value of 1 means the first 00233 derivative or unit tangent was discontinuous. A value 00234 of 2 means the second derivative or curvature was 00235 discontinuous. A value of 0 means teh curve is not 00236 closed, a locus discontinuity test was applied, and 00237 t1 is at the start of end of the curve. 00238 cos_angle_tolerance - [in] default = cos(1 degree) Used only 00239 when c is ON::G1_continuous or ON::G2_continuous. If the 00240 cosine of the angle between two tangent vectors is 00241 <= cos_angle_tolerance, then a G1 discontinuity is reported. 00242 curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used 00243 only when c is ON::G2_continuous. If K0 and K1 are 00244 curvatures evaluated from above and below and 00245 |K0 - K1| > curvature_tolerance, then a curvature 00246 discontinuity is reported. 00247 Returns: 00248 Parametric continuity tests c = (C0_continuous, ..., G2_continuous): 00249 00250 true if a parametric discontinuity was found strictly 00251 between t0 and t1. Note well that all curves are 00252 parametrically continuous at the ends of their domains. 00253 00254 Locus continuity tests c = (C0_locus_continuous, ...,G2_locus_continuous): 00255 00256 true if a locus discontinuity was found strictly between 00257 t0 and t1 or at t1 is the at the end of a curve. 00258 Note well that all open curves (IsClosed()=false) are locus 00259 discontinuous at the ends of their domains. All closed 00260 curves (IsClosed()=true) are at least C0_locus_continuous at 00261 the ends of their domains. 00262 */ 00263 bool GetNextDiscontinuity( 00264 int dir, 00265 ON::continuity c, 00266 double t0, 00267 double t1, 00268 double* t, 00269 int* hint=NULL, 00270 int* dtype=NULL, 00271 double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE, 00272 double curvature_tolerance=ON_SQRT_EPSILON 00273 ) const; 00274 00275 /* 00276 Description: 00277 Test continuity at a surface parameter value. 00278 Parameters: 00279 c - [in] continuity to test for 00280 s - [in] surface parameter to test 00281 t - [in] surface parameter to test 00282 hint - [in] evaluation hint 00283 point_tolerance - [in] if the distance between two points is 00284 greater than point_tolerance, then the surface is not C0. 00285 d1_tolerance - [in] if the difference between two first derivatives is 00286 greater than d1_tolerance, then the surface is not C1. 00287 d2_tolerance - [in] if the difference between two second derivatives is 00288 greater than d2_tolerance, then the surface is not C2. 00289 cos_angle_tolerance - [in] default = cos(1 degree) Used only when 00290 c is ON::G1_continuous or ON::G2_continuous. If the cosine 00291 of the angle between two normal vectors 00292 is <= cos_angle_tolerance, then a G1 discontinuity is reported. 00293 curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when 00294 c is ON::G2_continuous. If K0 and K1 are curvatures evaluated 00295 from above and below and |K0 - K1| > curvature_tolerance, 00296 then a curvature discontinuity is reported. 00297 Returns: 00298 true if the surface has at least the c type continuity at the parameter t. 00299 Remarks: 00300 Overrides virtual ON_Surface::IsContinuous 00301 */ 00302 bool IsContinuous( 00303 ON::continuity c, 00304 double s, 00305 double t, 00306 int* hint = NULL, 00307 double point_tolerance=ON_ZERO_TOLERANCE, 00308 double d1_tolerance=ON_ZERO_TOLERANCE, 00309 double d2_tolerance=ON_ZERO_TOLERANCE, 00310 double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE, 00311 double curvature_tolerance=ON_SQRT_EPSILON 00312 ) const; 00313 00314 ON_BOOL32 Reverse( // reverse parameterizatrion, Domain changes from [a,b] to [-b,-a] 00315 int // dir 0 = "s", 1 = "t" 00316 ); 00317 00318 ON_BOOL32 Transpose(); // transpose surface parameterization (swap "s" and "t") 00319 00320 // work horse evaluator 00321 ON_BOOL32 Evaluate( // returns false if unable to evaluate 00322 double, double, // evaluation parameters 00323 int, // number of derivatives (>=0) 00324 int, // array stride (>=Dimension()) 00325 double*, // array of length stride*(ndir+1)*(ndir+2)/2 00326 int = 0, // optional - determines which quadrant to evaluate from 00327 // 0 = default 00328 // 1 from NE quadrant 00329 // 2 from NW quadrant 00330 // 3 from SW quadrant 00331 // 4 from SE quadrant 00332 int* = 0 // optional - evaluation hint (int[2]) used to speed 00333 // repeated evaluations 00334 ) const; 00335 00336 00337 ON_Curve* IsoCurve( 00338 int dir, 00339 double c 00340 ) const; 00341 00342 int GetNurbForm( // returns 0: unable to create NURBS representation 00343 // with desired accuracy. 00344 // 1: success - returned NURBS parameterization 00345 // matches the surface's to wthe desired accuracy 00346 // 2: success - returned NURBS point locus matches 00347 // the surfaces's to the desired accuracy but, on 00348 // the interior of the surface's domain, the 00349 // surface's parameterization and the NURBS 00350 // parameterization may not match to the 00351 // desired accuracy. 00352 ON_NurbsSurface&, 00353 double = 0.0 00354 ) const; 00355 00356 int HasNurbForm( // returns 0: unable to create NURBS representation 00357 // with desired accuracy. 00358 // 1: success - returned NURBS parameterization 00359 // matches the surface's to wthe desired accuracy 00360 // 2: success - returned NURBS point locus matches 00361 // the surfaces's to the desired accuracy but, on 00362 // the interior of the surface's domain, the 00363 // surface's parameterization and the NURBS 00364 // parameterization may not match to the 00365 // desired accuracy. 00366 ) const; 00367 00368 bool GetSurfaceParameterFromNurbFormParameter( 00369 double nurbs_s, double nurbs_t, 00370 double* surface_s, double* surface_t 00371 ) const; 00372 00373 bool GetNurbFormParameterFromSurfaceParameter( 00374 double surface_s, double surface_t, 00375 double* nurbs_s, double* nurbs_t 00376 ) const; 00377 00378 private: 00379 00380 ON_OBJECT_DECLARE(ON_SurfaceProxy); 00381 }; 00382 00383 #endif