GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/Geometry/RGrid.h
00001 #ifndef __GEOMETRY_RGRID_H
00002 #define __GEOMETRY_RGRID_H
00003 
00004 #include <vector>
00005 #include "CGLA/Vec3i.h"
00006 #include "AncestorGrid.h"
00007 
00008 namespace Geometry 
00009 {
00010 
00016         template<class T>
00017         class RGrid: public AncestorGrid<T,RGrid<T> >
00018         {
00019         public:
00020                 typedef T DataType;
00021 
00022         private:
00024                 int x_dim;
00025                 
00027                 int xy_dim;
00028 
00030                 std::vector<T> data;
00031 
00033                 int grid_idx(const CGLA::Vec3i& idx) const
00034                 {
00035                         return  idx[2] * xy_dim + idx[1] * x_dim + idx[0];
00036                 }
00037 
00039                 DataType default_val;
00040 
00041         public:
00042         
00048                 RGrid(CGLA::Vec3i _dims, const T& val = T()):
00049                         AncestorGrid<T,RGrid<T> >(_dims), 
00050                         x_dim(_dims[0]), xy_dim(_dims[0]*_dims[1]),
00051                         data(_dims[0]*_dims[1]*_dims[2],val),
00052                         default_val(val)
00053                 {}      
00054 
00056                 RGrid(): AncestorGrid<T,RGrid<T> >(CGLA::Vec3i(0)), 
00057                         x_dim(0), xy_dim(0),
00058                         data(0,0), default_val(0)
00059                 {}      
00060 
00062                 void store(const CGLA::Vec3i& p, const T& t) 
00063                 {
00064                         assert(this->in_domain(p));
00065                         data[grid_idx(p)] = t;
00066                 }
00067 
00073                 T& operator[](const CGLA::Vec3i& p) 
00074                 {
00075                         assert(this->in_domain(p));
00076                         return data[grid_idx(p)];
00077                 }
00078 
00080                 const T& operator[](const CGLA::Vec3i& p) const 
00081                 {
00082                         assert(this->in_domain(p));
00083                         return data[grid_idx(p)];
00084                 }
00085 
00087                 const T* get() const {return &data[0];}
00088 
00090                 T* get() {return &data[0];}
00091 
00093                 int get_x_dim() const { return x_dim;}
00094 
00096                 int get_xy_dim() const { return xy_dim;}
00097 
00099                 int get_size() const { return data.size();}
00100 
00101                 void clear()
00102                 {
00103                         int N = data.size();
00104                         for(int i=0;i<N;++i)
00105                                 data[i] = default_val;
00106                 }
00107 
00108 
00109         };
00110 
00111 }
00112 
00113 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations