UniGridMapper.hpp

00001 #ifndef __UNIGRIDMAPPER_HPP
00002 #define __UNIGRIDMAPPER_HPP
00003 
00004 #include <aerie/BoundingBox.hpp>
00005 #include <eagle/PhysicalSpace.hpp>
00006 #include <eagle/QuadraticMatrix.hpp> 
00007 
00008 #include <field/UniformCartesianArray.hpp>
00009 
00010 #include <fish/fiber/vector/Interpolate.hpp>
00011 #include <fish/fiber/vector/LinearIpol.hpp>
00012 
00013 #include <memcore/RefPtr.hpp>
00014 
00015 using namespace Fiber;
00016 using namespace Eagle;
00017 using namespace std;
00018 
00019 using namespace Eagle::PhysicalSpace;
00020 
00021 
00028 class UniGridMapper : public ReferenceBase<UniGridMapper>
00029 {
00030         typedef MemArray<3, point> CoordsArray_t;
00031         typedef MemArray<3, tvector> TVectorArray_t;
00032         typedef std::list<MultiIndex<3> > IndexList_t; 
00033         typedef MemArray<3, IndexList_t > IndexListArray_t;
00034 
00035 //      typedef LinearDirectProductMemArray<Eagle::point3>   ProcArray_t; 
00036 
00037         RefPtr<IndexListArray_t>        CurviIndexList;
00038         RefPtr<UniformCartesianArray>   UniGridCoords;
00039         RefPtr<CoordsArray_t>           CurviCoords;
00040 
00041         RefPtr<BoundingBox>        BBox;
00042 
00043         double                  prec;
00044         tvector                 cell_len;
00045         MultiIndex<3>           res, ix, iy, iz;
00046 
00047         int     MaxListSize;
00048 
00049         // used for the correction of 'bad' points by EpsilonPreventer
00050         struct DistPoint_t
00051         {
00052                 double dist;
00053                 point uvw;
00054                 MultiIndex<3> self;
00055         };
00056 
00057 public:
00064         UniGridMapper(const RefPtr<CoordsArray_t>&_CurviCoords, const double res_scale = 1.0, const double prec_scale = 1.0);
00065 
00066         int     MaximalCurvicellPerUnicell() const
00067         {
00068                 return MaxListSize;
00069         }
00070 
00071 
00072 static  inline double avg(const double a, const double b)
00073         {
00074                 return (a+b)/2;
00075         }
00076         
00077 static  inline void clampRange(point&p, const double min, const double max)
00078         {
00079                 for(unsigned i = 0; i < 3; i++)
00080                 {
00081                         p[i] = ( p[i] < min) ? min : p[i]; 
00082                         p[i] = ( p[i] > max) ? max : p[i]; 
00083                 }
00084         } 
00085                 
00086 static  inline bool uvwInRange2( point& u, const MultiIndex<3>&it, const MultiIndex<3>&max, const double prec) 
00087         {
00088                 if( u[0] >= it[0] && u[0] <= it[0]+1 &&
00089                     u[1] >= it[1] && u[1] <= it[1]+1 && 
00090                     u[2] >= it[2] && u[2] <= it[2]+1    )
00091                 {
00092                         return true;
00093                 }
00094                 else
00095                 {
00096                         return false;
00097                 }
00098         } 
00099         
00100 static  inline bool localPointToIndex(const point&p, MultiIndex<3>&cc)
00101         {
00102                 if(p[0] >= 0.0 && p[1] >= 0.0 && p[2] >= 0.0)
00103                 {
00104                         cc[0] = unsigned(floor(p[0])); 
00105                         cc[1] = unsigned(floor(p[1])); 
00106                         cc[2] = unsigned(floor(p[2])); 
00107                         return true;
00108                 } 
00109                 return false;
00110         }
00111         
00112 
00114         MultiIndex<3>  Size() const                            { return CurviIndexList->Size();}
00115         
00117         point          operator[](const MultiIndex<3>&m) const { return (*UniGridCoords)[m];   }
00118         
00120         IndexList_t&   operator()(const MultiIndex<3>&m) const { return (*CurviIndexList)[m];   }
00121         RefPtr<CoordsArray_t> getCurviCoords() const           { return  CurviCoords;           }
00122         RefPtr<UniformCartesianArray> getUniCoords() const      { return  UniGridCoords;        }
00123         
00125         point          getMin()                                { return BBox->mincoord();      }
00126         
00128         point          getMax()                                { return BBox->maxcoord();      }
00129         
00130         
00132         bool     add( MultiIndex<3>& curvi_i );
00133         
00137         bool     inUniCell(const point&p, MultiIndex<3>&index );
00138         
00142         bool     curviCells(const point&p, IndexList_t&list);
00143         
00152         unsigned localCellCoordinatesFromCurviGrid(const point&p, point&uvw, double grid_epsilon = 0.0);
00153                 
00161         bool     localCellCoordinatesFromCell(point&uvw, const point&P, MultiIndex<3>&it,const CoordsArray_t&Data, const MultiIndex<3>&max,const double prec);
00162 }; 
00163 
00164 
00165 
00166 #endif // __UNIGRIDMAPPER_HPP
00167