grid_static_obj.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *   
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 /****************************************************************************
00024   History
00025 
00026 $Log: not supported by cvs2svn $
00027 Revision 1.4  2006/09/27 08:49:32  spinelli
00028 bug fix, add return type to Init
00029 
00030 Revision 1.3  2006/08/23 15:20:14  marfr960
00031 corrected minor bugs
00032 
00033 Revision 1.2  2005/12/02 00:29:00  cignoni
00034 updated the templates of BasicGrid
00035 
00036 Revision 1.1  2005/07/28 08:41:00  cignoni
00037 First working version
00038 
00039 Revision 1.13  2005/04/14 17:23:08  ponchio
00040 *** empty log message ***
00041 
00042 ****************************************************************************/
00043 
00044 #ifndef __VCGLIB_UGRID_OBJ
00045 #define __VCGLIB_UGRID_OBJ
00046 
00047 #include <vector>
00048 #include <algorithm>
00049 #include <stdio.h>
00050 
00051 #include <vcg/space/box3.h>
00052 #include <vcg/space/line3.h>
00053 #include <vcg/space/index/grid_util.h>
00054 namespace vcg {
00061 template < class ObjType, class FLT=float  >
00062 class GridStaticObj : public BasicGrid<FLT>
00063 {
00064  public:
00065 
00067          ObjType *grid;
00068 
00069          int size() const { return this->siz[0]*this->siz[1]*this->siz[2];}
00070 
00071          inline  GridStaticObj() { grid = 0; }
00072          inline ~GridStaticObj() { if(grid) delete[] grid; }
00073          inline void Init(const ObjType &val)
00074          {
00075                  fill(grid,grid+size(),val);
00076          }
00077 
00078 
00080          inline ObjType & Grid( const int x, const int y, const int z ) {return grid[GridIndI(Point3i(x,y,z))]; }
00081 
00082          // Dato un punto ritorna la cella  
00083          inline ObjType & Grid( const Point3<FLT> & p )                 {                               return grid[GridIndF(p)];               }
00084 
00085          inline int GridIndI( const Point3i & pi ) const
00086          {
00087 #ifndef NDEBUG
00088                  if ( pi[0]<0 || pi[0]>=this->siz[0] || pi[1]<0 || pi[1]>=this->siz[1] || pi[2]<0 || pi[2]>=this->siz[2] )
00089                  {      assert(0);
00090                  return 0;
00091                  } 
00092 #endif
00093                  return pi[0]+this->siz[0]*(pi[1]+this->siz[1]*pi[2]);
00094          }
00095 
00096          // Dato un punto ritorna l'indice della cella
00097    inline int GridIndF( const Point3<FLT> & p ) const { return GridIndI(this->GridP(p));        }
00098   
00099         void Create( const Point3i &_siz, const ObjType & init )
00100         {
00101                 this->siz=_siz;
00102                 this->voxel[0] = this->dim[0]/this->siz[0];
00103                 this->voxel[1] = this->dim[1]/this->siz[1];
00104                 this->voxel[2] = this->dim[2]/this->siz[2];
00105 
00106                 if(grid) delete[] grid;
00107                 int n = this->siz[0]*this->siz[1]*this->siz[2];
00108                 grid = new ObjType[n];
00109     std::fill(grid,grid+n,init);
00110         }
00111 
00114 
00115         template<class FLT2>
00116         void Create(const Box3<FLT2> & b, int ncell, const ObjType & init, bool Inflate = true )
00117         {
00118                 this->bbox.Import(b);
00119                 if(Inflate) this->bbox.Offset(0.01*this->bbox.Diag());
00120                 this->dim  = this->bbox.max - this->bbox.min;
00121 
00122                 // Calcola la dimensione della griglia
00123                 Point3i _siz;
00124                 BestDim( ncell, this->dim, _siz );
00125                 Create(_siz, init );
00126         }
00127 };
00128 //end class SGrid
00129 
00130 
00131 }
00132 #endif


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:31:29