00001
00002
00008 #if !defined(__cpt_GridBase_h__)
00009 #define __cpt_GridBase_h__
00010
00011
00012 #include "defs.h"
00013
00014
00015 #include "../ads/array/Array.h"
00016 #include "../ads/array/IndexIterator.h"
00017
00018
00019 #include "../geom/grid/RegularGrid.h"
00020
00021 #include <iostream>
00022 #include <vector>
00023
00024 BEGIN_NAMESPACE_CPT
00025
00027
00032 template<int N, typename T>
00033 class GridBase {
00034
00035
00036
00037
00038 private:
00039
00041 typedef ads::Array<N,int> ArrayInt;
00042
00043
00044
00045
00046
00047 protected:
00048
00050 typedef T Number;
00052 typedef ads::FixedArray<N,Number> Point;
00054 typedef typename ArrayInt::index_type Index;
00056 typedef typename ArrayInt::range_type Range;
00058 typedef geom::RegularGrid<N,Number> Lattice;
00059
00060
00061
00062
00063
00064 private:
00065
00067 ads::Array<N,Number,false> _distance;
00068
00070 ads::Array<N,Point,false> _gradientOfDistance;
00071
00073 ads::Array<N,Point,false> _closestPoint;
00074
00076 ads::Array<N,int,false> _closestFace;
00077
00078 protected:
00079
00080
00082
00083
00085 GridBase() :
00086 _distance(),
00087 _gradientOfDistance(),
00088 _closestPoint(),
00089 _closestFace()
00090 {}
00091
00093 GridBase(const GridBase& other) :
00094 _distance(other._distance),
00095 _gradientOfDistance(other._gradientOfDistance),
00096 _closestPoint(other._closestPoint),
00097 _closestFace(other._closestFace)
00098 {}
00099
00101 template<bool A1, bool A2, bool A3, bool A4>
00102 GridBase(ads::Array<N,Number,A1>* distance,
00103 ads::Array<N,Point,A2>* gradientOfDistance,
00104 ads::Array<N,Point,A3>* closestPoint,
00105 ads::Array<N,int,A4>* closestFace);
00106
00108 ~GridBase()
00109 {}
00110
00112 GridBase&
00113 operator=(const GridBase& other);
00114
00116
00117 public:
00118
00119
00121
00122
00124 const Index&
00125 getExtents() const {
00126 return _distance.extents();
00127 }
00128
00130 const Range&
00131 getRanges() const {
00132 return _distance.ranges();
00133 }
00134
00136 bool
00137 isEmpty() const {
00138 return _distance.empty();
00139 }
00140
00142 const ads::Array<N,Number,false>&
00143 getDistance() const {
00144 return _distance;
00145 }
00146
00148 const ads::Array<N,Point,false>&
00149 getGradientOfDistance() const {
00150 return _gradientOfDistance;
00151 }
00152
00154 const ads::Array<N,Point,false>&
00155 getClosestPoint() const {
00156 return _closestPoint;
00157 }
00158
00160 const ads::Array<N,int,false>&
00161 getClosestFace() const {
00162 return _closestFace;
00163 }
00164
00166 bool
00167 isGradientOfDistanceBeingComputed() const {
00168 return ! _gradientOfDistance.empty();
00169 }
00170
00172 bool
00173 isClosestPointBeingComputed() const {
00174 return ! _closestPoint.empty();
00175 }
00176
00178 bool
00179 isClosestFaceBeingComputed() const {
00180 return ! _closestFace.empty();
00181 }
00182
00184
00186
00187
00189 ads::Array<N,Number,false>&
00190 getDistance() {
00191 return _distance;
00192 }
00193
00195 ads::Array<N,Point,false>&
00196 getGradientOfDistance() {
00197 return _gradientOfDistance;
00198 }
00199
00201 ads::Array<N,Point,false>&
00202 getClosestPoint() {
00203 return _closestPoint;
00204 }
00205
00207 ads::Array<N,int,false>&
00208 getClosestFace() {
00209 return _closestFace;
00210 }
00211
00213
00215
00216
00218
00221 template<class Component>
00222 std::pair<int,int>
00223 computeClosestPointTransform(const std::vector<Index>& indices,
00224 const std::vector<Point>& positions,
00225 const Component& component,
00226 Number maximumDistance);
00227
00229 template<class Component>
00230 std::pair<int,int>
00231 computeClosestPointTransformUnsigned(const std::vector<Index>& indices,
00232 const std::vector<Point>& positions,
00233 const Component& component,
00234 Number maximumDistance);
00235
00237
00243 template<class Component>
00244 std::pair<int,int>
00245 computeClosestPointTransform(const Lattice& lattice,
00246 const Range& indexRangeInLattice,
00247 const Component& component,
00248 Number maximumDistance);
00249
00251
00257 template<class Component>
00258 std::pair<int,int>
00259 computeClosestPointTransformUnsigned(const Lattice& lattice,
00260 const Range& indexRangeInLattice,
00261 const Component& component,
00262 Number maximumDistance);
00263
00265
00271 void
00272 initialize();
00273
00275
00280 bool
00281 floodFillUnsigned(const Number farAway);
00282
00284
00286
00287
00288 void
00289 put(std::ostream& out) const;
00290
00291 void
00292 displayInformation(std::ostream& out) const;
00293
00294 int
00295 countKnownDistances(const Number maximumDistance) const;
00296
00297 void
00298 computeMinimumAndMaximumDistances(const Number maximumDistance,
00299 Number* minimum, Number* maximum) const;
00300
00302 };
00303
00304 END_NAMESPACE_CPT
00305
00306
00307
00308
00309
00311
00312 template<int N, typename T>
00313 bool
00314 operator==(const cpt::GridBase<N,T>& a, const cpt::GridBase<N,T>& b);
00315
00317
00318 template<int N, typename T>
00319 inline
00320 bool
00321 operator!=(const cpt::GridBase<N,T>& a, const cpt::GridBase<N,T>& b) {
00322 return !(a == b);
00323 }
00324
00325 #define __GridBase_ipp__
00326 #include "GridBase.ipp"
00327 #undef __GridBase_ipp__
00328
00329 #endif