00001
00002
00008 #if !defined(__geom_StructuredGrid_h__)
00009 #define __geom_StructuredGrid_h__
00010
00011 #if defined(DEBUG_geom) && !defined(DEBUG_StructuredGrid)
00012 #define DEBUG_StructuredGrid
00013 #endif
00014
00015 #include "../../defs.h"
00016 #include "../../kernel/BBox.h"
00017 #include "../../kernel/content.h"
00018
00019 #include "../../../ads/array/Array.h"
00020
00021 #include <iosfwd>
00022
00023 #include <cassert>
00024
00025 BEGIN_NAMESPACE_GEOM
00026
00028
00035 template<int N, int M, typename T = double>
00036 class StructuredGrid {
00037 public:
00038
00039
00040
00041
00042
00044 typedef T Number;
00046 typedef ads::FixedArray<M,Number> Point;
00048 typedef ads::Array<N,Point> Array;
00050 typedef BBox<N,Number> BBox;
00051
00052
00053
00054
00055
00057 typedef typename Array::value_type Value;
00058
00060 typedef typename Array::pointer Pointer;
00062 typedef typename Array::const_pointer ConstPointer;
00063
00065 typedef typename Array::iterator Iterator;
00067 typedef typename Array::const_iterator ConstIterator;
00068
00070 typedef typename Array::reference Reference;
00072 typedef typename Array::const_reference ConstReference;
00073
00075 typedef typename Array::size_type SizeType;
00077 typedef typename Array::difference_type DifferenceType;
00078
00080 typedef typename Array::index_type Index;
00081
00082 private:
00083
00084
00085
00086
00087
00089 Array _grid;
00090
00091 public:
00092
00093
00096
00098 StructuredGrid() :
00099 _grid()
00100 {}
00101
00103
00106 template<bool A>
00107 StructuredGrid(const ads::Array<N,Point,A>& grid) :
00108 _grid(grid)
00109 {}
00110
00112
00115 StructuredGrid(const Index& extents) :
00116 _grid(extents)
00117 {}
00118
00120 StructuredGrid(const StructuredGrid& other) :
00121 _grid(other._grid)
00122 {}
00123
00125 StructuredGrid&
00126 operator=(const StructuredGrid& other) {
00127 if (this != &other) {
00128 _grid = other._grid;
00129 }
00130 return *this;
00131 }
00132
00134 ~StructuredGrid()
00135 {}
00136
00138
00141
00143 BBox
00144 computeBBox() const {
00145 BBox bbox;
00146 bbox.bound(_grid.begin(), _grid.end());
00147 return bbox;
00148 }
00149
00151
00154
00156 static
00157 int
00158 getSpaceDimension() {
00159 return N;
00160 }
00161
00163 static
00164 int
00165 getGridDimension() {
00166 return M;
00167 }
00168
00170 const Index&
00171 getExtents() const {
00172 return _grid.extents();
00173 }
00174
00176 SizeType
00177 getSize() const {
00178 return _grid.size();
00179 }
00180
00182 ConstIterator
00183 getBeginning() const {
00184 return _grid.begin();
00185 }
00186
00188 ConstIterator
00189 getEnd() const {
00190 return _grid.end();
00191 }
00192
00194 const Array&
00195 getGrid() const {
00196 return _grid;
00197 }
00198
00200 ConstReference
00201 operator()(const Index& mi) const {
00202 return _grid(mi);
00203 }
00204
00206 ConstReference
00207 operator()(const int i, const int j) const {
00208 return _grid(i, j);
00209 }
00210
00212 ConstReference
00213 operator()(const int i, const int j, const int k) const {
00214 return _grid(i, j, k);
00215 }
00216
00218
00221
00223 Iterator
00224 getBeginning() {
00225 return _grid.begin();
00226 }
00227
00229 Iterator
00230 getEnd() {
00231 return _grid.end();
00232 }
00233
00234
00235 #if 0
00236
00237 Array&
00238 grid() {
00239 return _grid;
00240 }
00241 #endif
00242
00244 Reference
00245 operator()(const Index& mi) {
00246 return _grid(mi);
00247 }
00248
00250 ConstReference
00251 operator()(const int i, const int j) {
00252 return _grid(i, j);
00253 }
00254
00256 ConstReference
00257 operator()(const int i, const int j, const int k) {
00258 return _grid(i, j, k);
00259 }
00260
00262
00265
00267 bool
00268 isEqualTo(const StructuredGrid& x) const {
00269 return _grid = x._grid;
00270 }
00271
00273
00276
00278 void
00279 put(std::ostream& out) const {
00280 out << _grid.extents() << '\n';
00281 _grid.write_elements_ascii(out);
00282 }
00283
00285 void
00286 get(std::istream& in) {
00287 Index extents;
00288 in >> extents;
00289 _grid.resize(extents);
00290 _grid.read_elements_ascii(in);
00291 }
00292
00294 void
00295 writeIndexedSimplexSet(std::ostream& out) const;
00296
00298 };
00299
00300
00301
00302
00303
00304
00305
00307
00308 template<int N, int M, typename T>
00309 inline
00310 std::ostream&
00311 operator<<(std::ostream& out, const StructuredGrid<N,M,T>& x) {
00312 x.put(out);
00313 return out;
00314 }
00315
00316
00318
00319 template<int N, int M, typename T>
00320 inline
00321 std::istream&
00322 operator>>(std::istream& in, StructuredGrid<N,M,T>& x) {
00323 x.get(in);
00324 return in;
00325 }
00326
00327
00328
00329
00330
00331
00332
00334
00335 template<int N, int M, typename T>
00336 inline
00337 bool
00338 operator==(const StructuredGrid<N,M,T>& a, const StructuredGrid<N,M,T>& b) {
00339 return a.isEqualTo(b);
00340 }
00341
00342
00344
00345 template<int N, int M, typename T>
00346 inline
00347 bool
00348 operator!=(const StructuredGrid<N,M,T>& a, const StructuredGrid<N,M,T>& b) {
00349 return !(a == b);
00350 }
00351
00352
00353 END_NAMESPACE_GEOM
00354
00355 #define __geom_StructuredGrid_ipp__
00356 #include "StructuredGrid.ipp"
00357 #undef __geom_StructuredGrid_ipp__
00358
00359 #endif