00001
00002
00008 #if !defined(__geom_RegularGrid_h__)
00009 #define __geom_RegularGrid_h__
00010
00011 #include <iosfwd>
00012
00013 #include "../kernel/BBox.h"
00014
00015 #include <limits>
00016
00017 BEGIN_NAMESPACE_GEOM
00018
00020
00024 template<int N, typename T = double>
00025 class RegularGrid {
00026
00027
00028
00029
00030 public:
00031
00033 typedef T Number;
00035 typedef int SizeType;
00037 typedef ads::FixedArray<N,SizeType> Index;
00039 typedef ads::FixedArray<N,Number> Point;
00041 typedef geom::BBox<N,T> BBox;
00042
00043
00044
00045
00046
00047 private:
00048
00050 Index _extents;
00051
00053 BBox _domain;
00054
00056 Point _length;
00057
00059 Point _delta;
00060
00062 Number _indexEpsilon;
00063
00065 Number _cartesianEpsilon;
00066
00067
00068 public:
00069
00070
00072
00073
00075 RegularGrid() :
00076 _extents(),
00077 _domain(),
00078 _length(),
00079 _delta(),
00080 _indexEpsilon(),
00081 _cartesianEpsilon()
00082 {}
00083
00085
00092 RegularGrid(const Index& extents, const BBox& domain);
00093
00095 RegularGrid(const RegularGrid& other);
00096
00098 RegularGrid&
00099 operator=(const RegularGrid& other);
00100
00102 ~RegularGrid()
00103 {}
00104
00105
00106
00108
00109
00111 const Index&
00112 getExtents() const {
00113 return _extents;
00114 }
00115
00117 const Point&
00118 getDelta() const {
00119 return _delta;
00120 }
00121
00123 const BBox&
00124 getDomain() const {
00125 return _domain;
00126 }
00127
00129 Number
00130 getIndexEpsilon() const {
00131 return _indexEpsilon;
00132 }
00133
00135 Number
00136 getCartesianEpsilon() const {
00137 return _cartesianEpsilon;
00138 }
00139
00140
00141
00143
00144
00146 void
00147 convertLocationToIndex(Point* p) const {
00148 *p = (*p - _domain.getLowerCorner()) / _delta;
00149 }
00150
00152 void
00153 convertIndexToLocation(Point* p) const {
00154 *p = _domain.getLowerCorner() + *p * _delta;
00155 }
00156
00158 void
00159 convertVectorToIndex(Point* p) const {
00160 *p /= _delta;
00161 }
00162
00164 void
00165 convertBBoxLocationsToIndices(BBox* box) const {
00166 Point p = box->getLowerCorner();
00167 convertLocationToIndex(&p);
00168 box->setLowerCorner(p);
00169 p = box->getUpperCorner();
00170 convertLocationToIndex(&p);
00171 box->setUpperCorner(p);
00172 }
00173
00175 void
00176 convertBBoxIndicesToLocations(BBox* box) const {
00177 Point p = box->getLowerCorner();
00178 convertIndexToLocation(&p);
00179 box->setLowerCorner(p);
00180 p = box->getUpperCorner();
00181 convertIndexToLocation(&p);
00182 box->setUpperCorner(p);
00183 }
00184
00186 void
00187 convertBBoxIndicesToLocations(const geom::BBox<N,int>& indexBox,
00188 BBox* cartesianBox) const {
00189 Point p = indexBox.getLowerCorner();
00190 convertIndexToLocation(&p);
00191 cartesianBox->setLowerCorner(p);
00192 p = indexBox.getUpperCorner();
00193 convertIndexToLocation(&p);
00194 cartesianBox->setUpperCorner(p);
00195 }
00196
00198 template<typename OutputIterator>
00199 void
00200 convertLocationsToIndices(OutputIterator begin, OutputIterator end) const {
00201 for (; begin != end; ++begin) {
00202 convertLocationToIndex(&*begin);
00203 }
00204 }
00205
00207 template<typename OutputIterator>
00208 void
00209 convertIndicesToLocations(OutputIterator begin, OutputIterator end) const {
00210 for (; begin != end; ++begin) {
00211 convertIndexToLocation(&*begin);
00212 }
00213 }
00214
00216 template<typename OutputIterator>
00217 void
00218 convertVectorsToIndices(OutputIterator begin, OutputIterator end) const {
00219 for (; begin != end; ++begin) {
00220 convertVectorToIndex(&*begin);
00221 }
00222 }
00223
00224
00225 };
00226
00227
00228
00229
00230
00231
00232
00234
00235 template<int N, typename T>
00236 bool
00237 operator==(const RegularGrid<N,T>& a, const RegularGrid<N,T>& b);
00238
00239
00241
00242 template<int N, typename T>
00243 inline
00244 bool
00245 operator!=(const RegularGrid<N,T>& a, const RegularGrid<N,T>& b) {
00246 return !(a == b);
00247 }
00248
00249
00250
00251
00252
00253
00254
00256
00257 template<int N, typename T>
00258 std::ostream&
00259 operator<<(std::ostream& out, const RegularGrid<N,T>& grid);
00260
00261
00263
00264 template<int N, typename T>
00265 std::istream&
00266 operator>>(std::istream& in, RegularGrid<N,T>& grid);
00267
00268
00269 END_NAMESPACE_GEOM
00270
00271 #define __geom_RegularGrid_ipp__
00272 #include "RegularGrid.ipp"
00273 #undef __geom_RegularGrid_ipp__
00274
00275 #endif