00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef STRUCTURED_3D_VECTOR_HPP
00022 #define STRUCTURED_3D_VECTOR_HPP
00023
00024 #include <Vector.hpp>
00025 #include <Array3DShape.hpp>
00026
00036 template <typename T>
00037 class Structured3DVector
00038 : public Vector<T>
00039 {
00040 private:
00042 T*** __structured3dView;
00043
00045 Array3DShape __shape;
00046
00051 void __buildView()
00052 {
00053 __structured3dView = new T**[__shape.nx()];
00054 for (size_t i=0; i < __shape.nx(); ++i) {
00055 __structured3dView[i] = new T* [__shape.ny()];
00056 for (size_t j=0; j < __shape.ny(); ++j) {
00057 __structured3dView[i][j]
00058 = &Vector<T>::__values[i*__shape.ny()*__shape.nz() + j*__shape.nz()];
00059 }
00060 }
00061 }
00062
00067 void __clean()
00068 {
00069 for (size_t i=0; i<__shape.nx(); ++i)
00070 delete[] __structured3dView[i];
00071 delete [] __structured3dView;
00072 }
00073 public:
00074
00080 size_t nx() const
00081 {
00082 return __shape.nx();
00083 }
00084
00090 size_t ny() const
00091 {
00092 return __shape.ny();
00093 }
00094
00100 size_t nz() const
00101 {
00102 return __shape.nz();
00103 }
00104
00110 const Array3DShape& shape() const
00111 {
00112 return __shape;
00113 }
00114
00120 const T& operator()(const size_t& i, const size_t& j, const size_t& k) const
00121 {
00122 ASSERT ((i<__shape.nx()) and (j<__shape.ny()) and (k<__shape.nz()));
00123 return __structured3dView[i][j][k];
00124 }
00125
00131 T& operator()(const size_t& i, const size_t& j, const size_t& k)
00132 {
00133 ASSERT ((i<__shape.nx()) and (j<__shape.ny()) and (k<__shape.nz()));
00134 return __structured3dView[i][j][k];
00135 }
00136
00144 Structured3DVector<T>& operator=(const T& t)
00145 {
00146 this->Vector<T>::operator=(t);
00147 return *this;
00148 }
00149
00157 Structured3DVector<T>& operator=(const Structured3DVector<T>& v)
00158 {
00159 ASSERT (__shape==v.__shape);
00160 this->Vector<T>::operator=(v);
00161 return *this;
00162 }
00163
00171 const Structured3DVector<T>& operator=(const Vector<T>& v)
00172 {
00173 ASSERT (this->size() == v.size());
00174 this->Vector<T>::operator=(v);
00175 return *this;
00176 }
00177
00183 void resize(const Array3DShape& shape)
00184 {
00185 this->__clean();
00186 __shape = shape;
00187 this->Vector<T>::resize(shape.size());
00188 this->__buildView();
00189 }
00190
00198 Structured3DVector(const size_t& nx, const size_t& ny, const size_t& nz)
00199 : Vector<T>(nx*ny*nz),
00200 __shape(nx,ny,nz)
00201 {
00202 this->__buildView();
00203 }
00204
00210 Structured3DVector(const Array3DShape& shape)
00211 : Vector<T>(shape.size()),
00212 __shape(shape)
00213 {
00214 this->__buildView();
00215 }
00216
00222 Structured3DVector(const Structured3DVector& v)
00223 : Vector<T>(v),
00224 __shape(v.__shape)
00225 {
00226 this->__buildView();
00227 }
00228
00233 ~Structured3DVector()
00234 {
00235 this->__clean();
00236 }
00237 };
00238
00239 #endif // STRUCTURED_3D_VECTOR_HPP