opennurbs_geometry.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_VIRTUAL_OBJECT_IMPLEMENT(ON_Geometry,ON_Object,"4ED7D4DA-E947-11d3-BFE5-0010830122F0");
00020 
00021 ON_Geometry::ON_Geometry()
00022 {}
00023 
00024 ON_Geometry::ON_Geometry(const ON_Geometry& src) : ON_Object(src)
00025 {}
00026 
00027 ON_Geometry& ON_Geometry::operator=(const ON_Geometry& src)
00028 {
00029   ON_Object::operator=(src);
00030   return *this;
00031 }
00032 
00033 ON_Geometry::~ON_Geometry()
00034 {}
00035 
00036 ON_BoundingBox ON_Geometry::BoundingBox() const
00037 {
00038   ON_BoundingBox bbox;
00039   if ( !GetBoundingBox( bbox.m_min, bbox.m_max, false ) )
00040     bbox.Destroy();
00041   return bbox;
00042 }
00043 
00044 ON_BOOL32 
00045 ON_Geometry::GetBoundingBox( // returns true if successful
00046        ON_BoundingBox& bbox,
00047        ON_BOOL32 bGrowBox
00048        ) const
00049 {
00050   return GetBoundingBox( bbox.m_min, bbox.m_max, bGrowBox );
00051 }
00052 
00053 ON_BOOL32 
00054 ON_Geometry::GetBoundingBox( // returns true if successful
00055        ON_3dPoint& boxmin,
00056        ON_3dPoint& boxmax,
00057        ON_BOOL32 bGrowBox
00058        ) const
00059 {
00060   ON_Workspace ws;
00061   const int dim = Dimension();
00062   double *bmin, *bmax;
00063   if ( dim <= 3 ) {
00064     bmin = &boxmin.x;
00065     bmax = &boxmax.x;
00066   }
00067   else {
00068     bmin = ws.GetDoubleMemory(dim*2);
00069     bmax = bmin+dim;
00070     memset( bmin, 0, 2*dim*sizeof(*bmin) );
00071     if ( bGrowBox ) {
00072       bmin[0] = boxmin.x; bmin[1] = boxmin.y; bmin[1] = boxmin.z;
00073       bmax[0] = boxmax.x; bmax[1] = boxmax.y; bmax[1] = boxmax.z;
00074     }
00075   }
00076         // Treat invalid box on input as empty
00077         bool invalid=false;     //input box invalid=empty
00078         if(bGrowBox)
00079                 invalid =  boxmin.x>boxmax.x || boxmin.y>boxmax.y|| boxmin.z>boxmax.z;
00080         if(bGrowBox && invalid)
00081                 bGrowBox=false;
00082 
00083   const ON_BOOL32 rc = GetBBox( bmin, bmax, bGrowBox );
00084   if ( dim > 3 ) {
00085     boxmin.x = bmin[0]; boxmin.y = bmin[1]; boxmin.z = bmin[2];
00086     boxmax.x = bmax[0]; boxmax.y = bmax[1]; boxmax.z = bmax[2];
00087   }
00088   else if ( dim <= 2 ) {
00089     boxmin.z = 0.0;
00090     boxmax.z = 0.0;
00091     if ( dim <= 1 ) {
00092       boxmin.y = 0.0;
00093       boxmax.y = 0.0;
00094     }
00095   }
00096   return rc;
00097 }
00098 
00099 bool ON_Geometry::GetTightBoundingBox( 
00100                         ON_BoundingBox& tight_bbox, 
00101       int bGrowBox,
00102                         const ON_Xform* xform
00103       ) const
00104 {
00105   //    This implementation should be overridden by classes devived
00106   //  from ON_Geometry
00107   if ( bGrowBox && !tight_bbox.IsValid() )
00108   {
00109     bGrowBox = false;
00110   }
00111   if ( !bGrowBox )
00112   {
00113     tight_bbox.Destroy();
00114   }
00115 
00116   if ( xform && !xform->IsIdentity() )
00117   {
00118     ON_3dPointArray corners(8);
00119     ON_BoundingBox world_bbox;
00120     if ( GetBoundingBox(world_bbox,false) )
00121     {
00122       world_bbox.GetCorners(corners);
00123       if ( corners.GetTightBoundingBox(tight_bbox,bGrowBox,xform) )
00124         bGrowBox = true;
00125     }
00126   }
00127   else
00128   {
00129     if ( GetBoundingBox(tight_bbox,bGrowBox) )
00130       bGrowBox = true;
00131   }
00132 
00133   return bGrowBox?true:false;
00134 }
00135 
00136 ON_BOOL32 ON_Geometry::SwapCoordinates(
00137       int i, int j        // indices of coords to swap
00138       )
00139 {
00140   ON_BOOL32 rc = false;
00141   const int dim = Dimension();
00142   if ( dim > 0 && dim <= 3 && i >= 0 && i < 3 && j >= 0 && j < 3 ) {
00143     if ( i == j ) {
00144       rc = true;
00145     }
00146     else {
00147       int k;
00148       ON_Xform swapij(0.0);
00149       for ( k = 0; k < 4; k++ ) {
00150         if ( i == k )
00151           swapij[k][j] = 1.0;
00152         else if ( j == k )
00153           swapij[k][i] = 1.0;
00154         else
00155           swapij[k][k] = 1.0;
00156       }
00157       rc = Transform( swapij );
00158     }
00159   }
00160   return rc;
00161 }
00162 
00163 ON_BOOL32 ON_Geometry::Rotate(
00164       double sin_angle,          // sin(angle)
00165       double cos_angle,          // cos(angle)
00166       const ON_3dVector& axis, // axis of rotation
00167       const ON_3dPoint& center // center of rotation
00168       )
00169 {
00170   if ( sin_angle == 0.0 && cos_angle == 1.0 )
00171     return true;
00172   ON_Xform rot;
00173   rot.Rotation( sin_angle, cos_angle, axis, center );
00174   return Transform( rot );
00175 }
00176 
00177 ON_BOOL32 ON_Geometry::Rotate(
00178       double angle,              // angle in radians
00179       const ON_3dVector& axis, // axis of rotation
00180       const ON_3dPoint& center // center of rotation
00181       )
00182 {
00183   if ( angle == 0.0 )
00184     return true;
00185   return Rotate( sin(angle), cos(angle), axis, center );
00186 }
00187 
00188 ON_BOOL32 ON_Geometry::Translate( const ON_3dVector& delta )
00189 {
00190   if ( delta.IsZero() )
00191     return true;
00192   ON_Xform tr;
00193   tr.Translation( delta );
00194   return Transform( tr );
00195 }
00196 
00197 ON_BOOL32 ON_Geometry::Scale( double x )
00198 {
00199   if ( x == 1.0 )
00200     return true;
00201   ON_Xform s;
00202   s.Scale( x, x, x );
00203   return Transform( s );
00204 }
00205 
00206 bool ON_Geometry::IsDeformable() const
00207 {
00208   return false;
00209 }
00210 
00211 bool ON_Geometry::MakeDeformable()
00212 {
00213   return false;
00214 }
00215 
00216 void ON_Geometry::ClearBoundingBox()
00217 {
00218   // default implementation does nothing
00219 }
00220 
00221 ON_BOOL32 ON_Geometry::Transform( const ON_Xform& xform )
00222 {
00223   TransformUserData(xform);
00224   return true;
00225 }
00226 
00227 ON_BOOL32 ON_Geometry::HasBrepForm() const
00228 {
00229   // override if specific geoemtry has brep form
00230   return false;
00231 }
00232 
00233 ON_Brep* ON_Geometry::BrepForm( ON_Brep* brep ) const
00234 {
00235   // override if specific geoemtry has brep form
00236   return NULL;
00237 }
00238 
00239 
00240 ON_COMPONENT_INDEX ON_Geometry::ComponentIndex() const
00241 {
00242   // default constructor sets
00243   // m_type = ON_COMPONENT_INDEX::invalid_type and m_index = -1.
00244   ON_COMPONENT_INDEX ci;
00245   return ci;  
00246 }
00247 
00248 bool ON_Geometry::EvaluatePoint( const class ON_ObjRef& objref, ON_3dPoint& P ) const
00249 {
00250   // virtual function default
00251   P = ON_UNSET_POINT;
00252   return false;
00253 }
00254 


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