opennurbs_surfaceproxy.cpp
Go to the documentation of this file.
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 
00017 #include "pcl/surface/3rdparty/opennurbs/opennurbs.h"
00018 
00019 ON_OBJECT_IMPLEMENT(ON_SurfaceProxy,ON_Surface,"4ED7D4E2-E947-11d3-BFE5-0010830122F0")
00020 ;
00021 
00022 ON_SurfaceProxy::ON_SurfaceProxy () :
00023   m_surface (0), m_bTransposed (0)
00024 {
00025 }
00026 
00027 ON_SurfaceProxy::ON_SurfaceProxy (const ON_Surface* s) :
00028   m_surface (s), m_bTransposed (0)
00029 {
00030 }
00031 
00032 ON_SurfaceProxy::ON_SurfaceProxy (const ON_SurfaceProxy& src) :
00033   ON_Surface (src), m_surface (0), m_bTransposed (0)
00034 {
00035   *this = src;
00036 }
00037 
00038 unsigned int
00039 ON_SurfaceProxy::SizeOf () const
00040 {
00041   unsigned int sz = ON_Surface::SizeOf ();
00042   sz += (sizeof(*this) - sizeof(ON_Surface));
00043   // Do not add in size of m_surface - its memory is not
00044   // managed by this class.
00045   return sz;
00046 }
00047 
00048 ON__UINT32
00049 ON_SurfaceProxy::DataCRC (ON__UINT32 current_remainder) const
00050 {
00051   if (m_surface)
00052     current_remainder = m_surface->DataCRC (current_remainder);
00053   current_remainder = ON_CRC32 (current_remainder, sizeof(m_bTransposed), &m_bTransposed);
00054   return current_remainder;
00055 }
00056 
00057 ON_SurfaceProxy&
00058 ON_SurfaceProxy::operator= (const ON_SurfaceProxy& src)
00059 {
00060   if (this != &src)
00061   {
00062     ON_Surface::operator= (src);
00063     m_surface = src.m_surface;
00064     m_bTransposed = src.m_bTransposed;
00065   }
00066   return *this;
00067 }
00068 
00069 ON_SurfaceProxy::~ON_SurfaceProxy ()
00070 {
00071   m_surface = 0;
00072 }
00073 
00074 void
00075 ON_SurfaceProxy::SetProxySurface (const ON_Surface* proxy_surface)
00076 {
00077   // setting m_surface=0 prevents crashes if user has deleted
00078   // "real" surface before calling SetProxySurface().
00079   m_surface = 0;
00080 
00081   DestroySurfaceTree ();
00082   if (proxy_surface == this)
00083     proxy_surface = 0;
00084   m_surface = proxy_surface;
00085   m_bTransposed = false;
00086 }
00087 
00088 const ON_Surface*
00089 ON_SurfaceProxy::ProxySurface () const
00090 {
00091   return m_surface;
00092 }
00093 
00094 bool
00095 ON_SurfaceProxy::ProxySurfaceIsTransposed () const
00096 {
00097   return m_bTransposed;
00098 }
00099 
00100 ON_Surface*
00101 ON_SurfaceProxy::DuplicateSurface () const
00102 {
00103   ON_Surface* dup_srf = 0;
00104   if (m_surface)
00105   {
00106     dup_srf = m_surface->Duplicate ();
00107     if (m_bTransposed && dup_srf)
00108       dup_srf->Transpose ();
00109   }
00110   return dup_srf;
00111 }
00112 
00113 ON_BOOL32
00114 ON_SurfaceProxy::IsValid (ON_TextLog* text_log) const
00115 {
00116   return (m_surface) ? m_surface->IsValid (text_log) : false;
00117 }
00118 
00119 void
00120 ON_SurfaceProxy::Dump (ON_TextLog& dump) const
00121 {
00122   dump.Print ("ON_SurfaceProxy uses %x\n", m_surface);
00123   if (m_surface)
00124     m_surface->Dump (dump);
00125 }
00126 
00127 ON_BOOL32
00128 ON_SurfaceProxy::Write (ON_BinaryArchive& // open binary file
00129 ) const
00130 {
00131   return false;
00132 }
00133 
00134 ON_BOOL32
00135 ON_SurfaceProxy::Read (ON_BinaryArchive& // open binary file
00136 )
00137 {
00138   return false;
00139 }
00140 
00141 int
00142 ON_SurfaceProxy::Dimension () const
00143 {
00144   return (m_surface) ? m_surface->Dimension () : 0;
00145 }
00146 
00147 ON_BOOL32
00148 ON_SurfaceProxy::GetBBox ( // returns true if successful
00149                           double* boxmin, // minimum
00150                           double* boxmax, // maximum
00151                           ON_BOOL32 bGrowBox) const
00152 {
00153   return (m_surface) ? m_surface->GetBBox (boxmin, boxmax, bGrowBox) : false;
00154 }
00155 
00156 ON_BOOL32
00157 ON_SurfaceProxy::Transform (const ON_Xform& // xform - formal parameter intentionally ignored in this virtual function
00158 )
00159 {
00160   return false; // cannot modify m_surface
00161 }
00162 
00163 ON_Interval
00164 ON_SurfaceProxy::Domain (int dir) const
00165 {
00166   ON_Interval d;
00167   if (m_bTransposed)
00168   {
00169     dir = (dir) ? 0 : 1;
00170   }
00171   if (m_surface)
00172     d = m_surface->Domain (dir);
00173   return d;
00174 }
00175 
00176 ON_BOOL32
00177 ON_SurfaceProxy::GetSurfaceSize (double* width, double* height) const
00178 {
00179   ON_BOOL32 rc = false;
00180   if (m_surface)
00181   {
00182     if (m_bTransposed)
00183     {
00184       double* ptr = width;
00185       width = height;
00186       height = ptr;
00187     }
00188     rc = m_surface->GetSurfaceSize (width, height);
00189   }
00190   else
00191   {
00192     if (width)
00193       *width = 0.0;
00194     if (height)
00195       *height = 0.0;
00196   }
00197   return rc;
00198 }
00199 
00200 int
00201 ON_SurfaceProxy::SpanCount (int dir) const
00202 {
00203   if (m_bTransposed)
00204   {
00205     dir = (dir) ? 0 : 1;
00206   }
00207   return (m_surface) ? m_surface->SpanCount (dir) : false;
00208 }
00209 
00210 ON_BOOL32
00211 ON_SurfaceProxy::GetSpanVector (int dir, double* s) const
00212 {
00213   if (m_bTransposed)
00214   {
00215     dir = (dir) ? 0 : 1;
00216   }
00217   return (m_surface) ? m_surface->GetSpanVector (dir, s) : false;
00218 }
00219 
00220 int
00221 ON_SurfaceProxy::Degree (int dir) const
00222 {
00223   if (m_bTransposed)
00224   {
00225     dir = (dir) ? 0 : 1;
00226   }
00227   return (m_surface) ? m_surface->Degree (dir) : false;
00228 }
00229 
00230 ON_BOOL32
00231 ON_SurfaceProxy::GetParameterTolerance (int dir, double t, // t = parameter in domain
00232                                         double* tminus, // tminus
00233                                         double* tplus // tplus
00234 ) const
00235 {
00236   if (m_bTransposed)
00237   {
00238     dir = (dir) ? 0 : 1;
00239   }
00240   return (m_surface) ? m_surface->GetParameterTolerance (dir, t, tminus, tplus) : false;
00241 }
00242 
00243 ON_BOOL32
00244 ON_SurfaceProxy::IsClosed (int dir) const
00245 {
00246   if (m_bTransposed)
00247   {
00248     dir = (dir) ? 0 : 1;
00249   }
00250   return (m_surface) ? m_surface->IsClosed (dir) : false;
00251 }
00252 
00253 ON_Surface::ISO
00254 ON_SurfaceProxy::IsIsoparametric ( // returns isoparametric status of 2d curve
00255                                   const ON_Curve& crv, const ON_Interval* subdomain) const
00256 {
00257   // this is a virtual overide of an ON_Surface::IsIsoparametric
00258 
00259   const ON_Curve* pC = &crv;
00260   ON_Curve* pTranC = NULL;
00261   if (m_bTransposed)
00262   {
00263     pTranC = crv.DuplicateCurve ();
00264     pTranC->SwapCoordinates (0, 1);
00265     pC = pTranC;
00266   }
00267 
00268   ON_Surface::ISO iso = m_surface->IsIsoparametric (*pC, subdomain);
00269 
00270   if (pTranC)
00271   {
00272     switch (iso)
00273     {
00274       case x_iso:
00275         iso = y_iso;
00276         break;
00277       case y_iso:
00278         iso = x_iso;
00279         break;
00280       case W_iso:
00281         iso = S_iso;
00282         break;
00283       case S_iso:
00284         iso = W_iso;
00285         break;
00286       case N_iso:
00287         iso = E_iso;
00288         break;
00289       case E_iso:
00290         iso = N_iso;
00291         break;
00292       default:
00293         // intentionally ignoring other ON_Surface::ISO enum values
00294         break;
00295     }
00296     delete pTranC;
00297   }
00298 
00299   return iso;
00300 }
00301 
00302 ON_Surface::ISO
00303 ON_SurfaceProxy::IsIsoparametric ( // returns isoparametric status based on bounding box
00304                                   const ON_BoundingBox& box) const
00305 {
00306   // this is a virtual overide of an ON_Surface::IsIsoparametric
00307   const ON_BoundingBox* pbox = &box;
00308   ON_BoundingBox Tbox (ON_2dPoint (box.m_min[1], box.m_min[0]), ON_2dPoint (box.m_max[1], box.m_max[0]));
00309   if (m_bTransposed)
00310     pbox = &Tbox;
00311 
00312   ON_Surface::ISO iso = m_surface->IsIsoparametric (*pbox);
00313 
00314   if (m_bTransposed)
00315   {
00316     switch (iso)
00317     {
00318       case x_iso:
00319         iso = y_iso;
00320         break;
00321       case y_iso:
00322         iso = x_iso;
00323         break;
00324       case W_iso:
00325         iso = S_iso;
00326         break;
00327       case S_iso:
00328         iso = W_iso;
00329         break;
00330       case N_iso:
00331         iso = E_iso;
00332         break;
00333       case E_iso:
00334         iso = N_iso;
00335         break;
00336       default:
00337         // intentionally ignoring other ON_Surface::ISO enum values
00338         break;
00339     }
00340   }
00341   return iso;
00342 }
00343 
00344 ON_BOOL32
00345 ON_SurfaceProxy::IsPlanar (ON_Plane* plane, double tolerance) const
00346 {
00347   ON_BOOL32 rc = false;
00348   if (m_surface)
00349   {
00350     rc = m_surface->IsPlanar (plane, tolerance);
00351     if (rc && m_bTransposed && plane)
00352       plane->Flip ();
00353   }
00354   return rc;
00355 }
00356 
00357 ON_BOOL32
00358 ON_SurfaceProxy::IsPeriodic (int dir) const
00359 {
00360   if (m_bTransposed)
00361   {
00362     dir = (dir) ? 0 : 1;
00363   }
00364   return (m_surface) ? m_surface->IsPeriodic (dir) : false;
00365 }
00366 
00367 bool
00368 ON_SurfaceProxy::GetNextDiscontinuity (int dir, ON::continuity c, double t0, double t1, double* t, int* hint,
00369                                        int* dtype, double cos_angle_tolerance, double curvature_tolerance) const
00370 {
00371   // untested code
00372   bool rc = false;
00373 
00374   if (0 != m_surface && dir >= 0 && dir <= 1)
00375   {
00376     rc = m_surface->GetNextDiscontinuity (m_bTransposed ? 1 - dir : dir, c, t0, t1, t, hint, dtype,
00377                                           cos_angle_tolerance, curvature_tolerance);
00378   }
00379 
00380   return rc;
00381 }
00382 
00383 ON_BOOL32
00384 ON_SurfaceProxy::IsSingular (int side) const
00385 {
00386   if (m_bTransposed)
00387   {
00388     switch (side)
00389     {
00390       case 0:
00391         side = 3;
00392         break;
00393       case 1:
00394         side = 2;
00395         break;
00396       case 2:
00397         side = 1;
00398         break;
00399       case 3:
00400         side = 0;
00401         break;
00402     }
00403   }
00404   return (m_surface) ? m_surface->IsSingular (side) : false;
00405 }
00406 
00407 ON_BOOL32
00408 ON_SurfaceProxy::Reverse (int // dir - formal parameter intentionally ignored in this virtual function
00409 )
00410 {
00411   return false; // cannot modify m_surface
00412 }
00413 
00414 ON_BOOL32
00415 ON_SurfaceProxy::Transpose ()
00416 {
00417   DestroySurfaceTree ();
00418   m_bTransposed = (m_bTransposed) ? false : true;
00419   return true;
00420 }
00421 
00422 bool
00423 ON_SurfaceProxy::IsContinuous (ON::continuity desired_continuity, double s, double t, int* hint, // default = NULL,
00424                                double point_tolerance, // default=ON_ZERO_TOLERANCE
00425                                double d1_tolerance, // default==ON_ZERO_TOLERANCE
00426                                double d2_tolerance, // default==ON_ZERO_TOLERANCE
00427                                double cos_angle_tolerance, // default==ON_DEFAULT_ANGLE_TOLERANCE_COSINE
00428                                double curvature_tolerance // default==ON_SQRT_EPSILON
00429 ) const
00430 {
00431   bool rc = true;
00432   if (m_surface)
00433   {
00434     if (m_bTransposed)
00435     {
00436       double x = s;
00437       s = t;
00438       t = x;
00439     }
00440     rc = m_surface->IsContinuous (desired_continuity, s, t, hint, point_tolerance, d1_tolerance, d2_tolerance,
00441                                   cos_angle_tolerance, curvature_tolerance);
00442   }
00443   return rc;
00444 }
00445 
00446 ON_BOOL32
00447 ON_SurfaceProxy::Evaluate ( // returns false if unable to evaluate
00448                            double s, double t, // evaluation parameters
00449                            int der_count, // number of derivatives (>=0)
00450                            int v_stride, // v[] array stride (>=Dimension())
00451                            double* v, // v[] array of length stride*(ndir+1)
00452                            int side, // optional - determines which side to evaluate from
00453                            //         0 = default
00454                            //      <  0 to evaluate from below,
00455                            //      >  0 to evaluate from above
00456                            int* hint // optional - evaluation hint (int) used to speed
00457 //            repeated evaluations
00458 ) const
00459 {
00460   if (m_bTransposed)
00461   {
00462     double x = s;
00463     s = t;
00464     t = x;
00465   }
00466   return (m_surface) ? m_surface->Evaluate (s, t, der_count, v_stride, v, side, hint) : false;
00467 }
00468 
00469 ON_Curve*
00470 ON_SurfaceProxy::IsoCurve (int dir, double c) const
00471 {
00472   ON_Curve* isocurve = 0;
00473 
00474   if (m_bTransposed)
00475   {
00476     dir = 1 - dir;
00477   }
00478 
00479   if (0 != m_surface && dir >= 0 && dir <= 1)
00480   {
00481     isocurve = m_surface->IsoCurve (dir, c);
00482   }
00483 
00484   return isocurve;
00485 }
00486 
00487 int
00488 ON_SurfaceProxy::GetNurbForm ( // returns 0: unable to create NURBS representation
00489                               //            with desired accuracy.
00490                               //         1: success - returned NURBS parameterization
00491                               //            matches the surface's to wthe desired accuracy
00492                               //         2: success - returned NURBS point locus matches
00493                               //            the surfaces's to the desired accuracy but, on
00494                               //            the interior of the surface's domain, the
00495                               //            surface's parameterization and the NURBS
00496                               //            parameterization may not match to the
00497                               //            desired accuracy.
00498                               ON_NurbsSurface& nurbs, double tolerance) const
00499 {
00500   ON_BOOL32 rc = (m_surface) ? m_surface->GetNurbForm (nurbs, tolerance) : false;
00501   if (rc && m_bTransposed)
00502   {
00503     rc = nurbs.Transpose ();
00504   }
00505   return rc;
00506 }
00507 
00508 int
00509 ON_SurfaceProxy::HasNurbForm ( // returns 0: unable to create NURBS representation
00510 //            with desired accuracy.
00511 //         1: success - returned NURBS parameterization
00512 //            matches the surface's to wthe desired accuracy
00513 //         2: success - returned NURBS point locus matches
00514 //            the surfaces's to the desired accuracy but, on
00515 //            the interior of the surface's domain, the
00516 //            surface's parameterization and the NURBS
00517 //            parameterization may not match to the
00518 //            desired accuracy.
00519 ) const
00520 
00521 {
00522   if (!m_surface)
00523     return 0;
00524   return m_surface->HasNurbForm ();
00525 }
00526 
00527 bool
00528 ON_SurfaceProxy::GetSurfaceParameterFromNurbFormParameter (double nurbs_s, double nurbs_t, double* surface_s,
00529                                                            double* surface_t) const
00530 {
00531   bool rc = false;
00532   if (m_surface)
00533   {
00534     rc = m_bTransposed ? m_surface->GetSurfaceParameterFromNurbFormParameter (nurbs_t, nurbs_s, surface_t, surface_s)
00535         : m_surface->GetSurfaceParameterFromNurbFormParameter (nurbs_s, nurbs_t, surface_s, surface_t);
00536   }
00537   return rc;
00538 }
00539 
00540 bool
00541 ON_SurfaceProxy::GetNurbFormParameterFromSurfaceParameter (double surface_s, double surface_t, double* nurbs_s,
00542                                                            double* nurbs_t) const
00543 {
00544   bool rc = false;
00545   if (m_surface)
00546   {
00547     rc = m_bTransposed ? m_surface->GetNurbFormParameterFromSurfaceParameter (surface_t, surface_s, nurbs_t, nurbs_s)
00548         : m_surface->GetNurbFormParameterFromSurfaceParameter (surface_s, surface_t, nurbs_s, nurbs_t);
00549   }
00550   return rc;
00551 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:03