opennurbs_pointgrid.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_PointGrid,ON_Geometry,"4ED7D4E5-E947-11d3-BFE5-0010830122F0");
00020 
00021 ON_3dPoint ON_PointGrid::m_no_point(0.0,0.0,0.0);
00022 
00023 ON_PointGrid::ON_PointGrid()
00024 {
00025   Initialize();
00026 }
00027 
00028 ON_PointGrid::ON_PointGrid( int c0, int c1 )
00029 {
00030   Initialize();
00031   Create(c0,c1);
00032 }
00033 
00034 ON_PointGrid::ON_PointGrid( const ON_PointGrid& src )
00035 {
00036   *this = src;
00037 }
00038 
00039 ON_PointGrid::~ON_PointGrid()
00040 {
00041   Destroy();
00042 }
00043 
00044 int ON_PointGrid::Dimension() const
00045 {
00046   return 3;
00047 }
00048 
00049 int ON_PointGrid::PointCount( int dir ) const
00050 {
00051   return m_point_count[dir?1:0];
00052 }
00053 
00054 int ON_PointGrid::PointCount( void ) const
00055 {
00056   return m_point_count[0]*m_point_count[1];
00057 }
00058 
00059 ON_3dPoint& ON_PointGrid::Point( int i, int j )
00060 {
00061   return (0 <= i && i < m_point_count[0] && 0 <= j && j < m_point_count[1]) 
00062          ? m_point[i*m_point_stride0 + j] 
00063          : m_no_point;
00064 }
00065 
00066 ON_3dPoint ON_PointGrid::Point( int i, int j ) const
00067 {
00068   return (0 <= i && i < m_point_count[0] && 0 <= j && j < m_point_count[1]) 
00069          ? m_point[i*m_point_stride0 + j] 
00070          : m_no_point;
00071 }
00072 
00073 double* ON_PointGrid::PointArray()
00074 {
00075   return (m_point_count[0]>0&&m_point_count[1]>0) ? &m_point[0].x : NULL;
00076 }
00077 
00078 const double* ON_PointGrid::PointArray() const
00079 {
00080   return (m_point_count[0]>0&&m_point_count[1]>0) ? &m_point[0].x : NULL;
00081 }
00082 
00083 int ON_PointGrid::PointArrayStride(  // point stride in grid direction
00084       int dir        // dir 0 = "s", 1 = "t"
00085       ) const
00086 {
00087   return ((dir) ? 3 : 3*m_point_stride0);
00088 }
00089 
00090 
00091 ON_BOOL32 ON_PointGrid::SetPoint( int i, int j, const ON_3dPoint& point )
00092 {
00093   ON_BOOL32 rc = false;
00094   if ( 0 <= i && i < m_point_count[0] && 0 <= j && j < m_point_count[1] ) {
00095     m_point[i*m_point_stride0+j] = point;
00096     rc = true;
00097   }
00098   return rc;
00099 }
00100 
00101 ON_BOOL32 ON_PointGrid::GetPoint( int i, int j, ON_3dPoint& point ) const
00102 {
00103   ON_BOOL32 rc = false;
00104   if ( 0 <= i && i < m_point_count[0] && 0 <= j && j < m_point_count[1] ) {
00105     point = m_point[i*m_point_stride0+j];
00106     rc = true;
00107   }
00108   return rc;
00109 }
00110 
00111 ON_3dPoint* ON_PointGrid::operator[](int i)
00112 {
00113   return ( 0 <= i && i < m_point_count[0] ) 
00114          ? m_point.Array() + i*m_point_stride0 : 0;
00115 }
00116 
00117 const ON_3dPoint* ON_PointGrid::operator[](int i) const
00118 {
00119   return ( 0 <= i && i < m_point_count[0] ) 
00120          ? m_point.Array() + i*m_point_stride0 : 0;
00121 }
00122 
00123 ON_BOOL32
00124 ON_PointGrid::Create(
00125         int point_count0,  // cv count0 (>= order0)
00126         int point_count1   // cv count1 (>= order1)
00127         )
00128 {
00129   if ( point_count0 < 1 )
00130     return false;
00131   if ( point_count1 < 1 )
00132     return false;
00133   m_point_count[0] = point_count0;
00134   m_point_count[1] = point_count1;
00135   m_point_stride0 = m_point_count[1];
00136   m_point.Reserve(m_point_count[0]*m_point_count[1]);
00137   return true;
00138 }
00139 
00140 void ON_PointGrid::Destroy()
00141 {
00142   Initialize();
00143   m_point.SetCapacity(0);
00144 }
00145 
00146 void ON_PointGrid::EmergencyDestroy()
00147 {
00148   // call if memory used by point grid becomes invalid
00149   m_point_count[0] = 0;
00150   m_point_count[1] = 0;
00151   m_point_stride0 = 0;
00152   m_point.EmergencyDestroy();
00153 }
00154 
00155 void ON_PointGrid::Initialize()
00156 {
00157   m_point_count[0] = 0;
00158   m_point_count[1] = 0;
00159   m_point_stride0 = 0;
00160   m_point.SetCount(0);
00161 }
00162 
00163 ON_PointGrid& ON_PointGrid::operator=( const ON_PointGrid& src )
00164 {
00165   if ( this != &src ) {
00166     ON_Geometry::operator=(src);
00167     m_point_count[0] = src.m_point_count[0];
00168     m_point_count[1] = src.m_point_count[1];
00169     m_point_stride0 = m_point_count[1];
00170     m_point.Reserve(PointCount());
00171     m_point.SetCount(PointCount());
00172     if ( PointCount() > 0 ) {
00173       // copy cv array
00174       if ( m_point_stride0 == src.m_point_stride0 ) {
00175         memcpy( m_point.Array(), src.m_point.Array(), PointCount()*sizeof(ON_3dPoint) );
00176       }
00177       else {
00178         int i, j;
00179         for ( i = 0; i < m_point_count[0]; i++ ) for ( j = 0; j < m_point_count[1]; j++ ) {
00180           m_point[i*m_point_stride0+j] = src[i][j];
00181         }
00182       }
00183     }
00184   }
00185   return *this;
00186 }
00187 
00188 void ON_PointGrid::Dump( ON_TextLog& dump ) const
00189 {
00190   dump.Print( "ON_PointGrid size = %d X %d\n",
00191                m_point_count[0], m_point_count[1] );
00192   if ( m_point.Count() < 1 ) {
00193     dump.Print("  NO point array\n");
00194   }
00195   else {
00196     dump.PrintPointGrid( 3, false, m_point_count[0], m_point_count[1], 
00197                          3*m_point_stride0, 3, 
00198                          &m_point[0].x,
00199                          "  point" 
00200                          );
00201   }
00202 }
00203 
00204 ON_BOOL32 ON_PointGrid::IsValid( ON_TextLog* text_log ) const
00205 {
00206   ON_BOOL32 rc = false;
00207   if ( ON_IsValidPointGrid( 3, false, 
00208                             m_point_count[0], m_point_count[1], 
00209                             m_point_stride0*3, 3, 
00210                             &m_point[0].x ) ) 
00211   {
00212     if ( m_point.Count() >= m_point_stride0*m_point_count[0] )
00213       rc = true;
00214   }
00215   return rc;
00216 }
00217 
00218 ON_BOOL32 ON_PointGrid::GetBBox( // returns true if successful
00219        double* boxmin,    // minimum
00220        double* boxmax,    // maximum
00221        ON_BOOL32 bGrowBox  // true means grow box
00222        ) const
00223 {
00224   return ON_GetPointGridBoundingBox( 3, 0, 
00225             m_point_count[0], m_point_count[1], 
00226             m_point_stride0*3, 3, &m_point[0].x, 
00227             boxmin, boxmax, bGrowBox?true:false );
00228 }
00229 
00230 bool ON_PointGrid::GetTightBoundingBox(
00231          ON_BoundingBox& tight_bbox,
00232          int bGrowBox,
00233                                  const ON_Xform* xform 
00234          ) const
00235 {
00236   if ( bGrowBox && !tight_bbox.IsValid() )
00237   {
00238     bGrowBox = false;
00239   }
00240   if ( !bGrowBox )
00241   {
00242     tight_bbox.Destroy();
00243   }
00244   
00245   int i;
00246   for ( i = 0; i < m_point_count[0]; i++ )
00247   {
00248     if ( ON_GetPointListBoundingBox( 3, 0, m_point_count[1], 3, &m_point[i].x, tight_bbox, bGrowBox, xform ) )
00249       bGrowBox = true;
00250   }
00251   return bGrowBox?true:false;
00252 }
00253 
00254 ON_BOOL32 ON_PointGrid::Transform( const ON_Xform& xform )
00255 {
00256   TransformUserData(xform);
00257   return ON_TransformPointGrid( 3, false, 
00258             m_point_count[0], m_point_count[1],
00259             m_point_stride0*3, 3,
00260             Point(0,0), 
00261             xform );
00262 }
00263 
00264 // virtual ON_Geometry::IsDeformable() override
00265 bool ON_PointGrid::IsDeformable() const
00266 {
00267   return true;
00268 }
00269 
00270 // virtual ON_Geometry::MakeDeformable() override
00271 bool ON_PointGrid::MakeDeformable()
00272 {
00273   return true;
00274 }
00275 
00276 ON_BOOL32 ON_PointGrid::SwapCoordinates(
00277       int i, int j // indices of coords to swap
00278       )
00279 {
00280   return ON_SwapPointGridCoordinates( 
00281             m_point_count[0], m_point_count[1], 
00282             m_point_stride0*3, 3, 
00283             Point(0,0), 
00284             i, j );
00285 
00286 }
00287 
00288 
00289 ON_BOOL32 ON_PointGrid::Write(
00290        ON_BinaryArchive&  // open binary file
00291      ) const
00292 {
00293   // TODO
00294   return false;
00295 }
00296 
00297 ON_BOOL32 ON_PointGrid::Read(
00298        ON_BinaryArchive&  // open binary file
00299      )
00300 {
00301   // TODO
00302   return false;
00303 }
00304 
00305 ON::object_type ON_PointGrid::ObjectType() const
00306 {
00307   return ON::pointset_object;
00308 }
00309 
00310 ON_BOOL32 
00311 ON_PointGrid::IsClosed( int dir ) const
00312 {
00313   return ON_IsPointGridClosed( 3, 0, 
00314                     m_point_count[0], m_point_count[1], 
00315                     m_point_stride0*3, 3, 
00316                     &m_point[0].x, dir );
00317 }
00318 
00319 ON_BOOL32
00320 ON_PointGrid::Reverse(int dir)
00321 {
00322   return ON_ReversePointGrid( 3, false, m_point_count[0], m_point_count[1], m_point_stride0*3, 3, Point(0,0), dir );
00323 }
00324 
00325 ON_BOOL32
00326 ON_PointGrid::Transpose()
00327 {
00328   int i, j;
00329   ON_BOOL32 rc = false;
00330   if ( IsValid() ) {
00331     // slow stupid way - can be imporved if necessary
00332     ON_PointGrid t(m_point_count[1],m_point_count[0]);
00333     for ( i = 0; i < m_point_count[0]; i++ ) for ( j = 0; j < m_point_count[1]; j++ ) {
00334       t[j][i] = Point(i,j);
00335     }
00336     *this = t;
00337     rc = true;
00338   }
00339   return rc;
00340 }
00341 
00342 


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