Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_DATASTRUCTURES_DRANGE_H
00036 #define OPENMS_DATASTRUCTURES_DRANGE_H
00037
00038 #include <OpenMS/DATASTRUCTURES/DIntervalBase.h>
00039
00040 namespace OpenMS
00041 {
00058 template <UInt D>
00059 class DRange :
00060 public Internal::DIntervalBase<D>
00061 {
00062 public:
00063
00068
00069 enum {DIMENSION = D};
00071 typedef Internal::DIntervalBase<D> Base;
00073 typedef typename Base::PositionType PositionType;
00075 typedef typename Base::CoordinateType CoordinateType;
00077 enum DRangeIntersection
00078 {
00079 Disjoint,
00080 Intersects,
00081 Inside
00082 };
00083
00085
00086 using Base::min_;
00087 using Base::max_;
00088
00096 DRange() :
00097 Base()
00098 {
00099 }
00100
00102 DRange(const PositionType & lower, const PositionType & upper) :
00103 Base(lower, upper)
00104 {
00105 }
00106
00108 DRange(const DRange & range) :
00109 Base(range)
00110 {
00111 }
00112
00114 DRange(const Base & range) :
00115 Base(range)
00116 {
00117 }
00118
00120 DRange(CoordinateType minx, CoordinateType miny, CoordinateType maxx, CoordinateType maxy)
00121 {
00122 OPENMS_PRECONDITION(D == 2, "DRange<D>:DRange(minx, miny, maxx, maxy): index overflow!");
00123 min_[0] = minx;
00124 min_[1] = miny;
00125 max_[0] = maxx;
00126 max_[1] = maxy;
00127 }
00128
00130 DRange & operator=(const DRange & rhs)
00131 {
00132 Base::operator=(rhs);
00133 return *this;
00134 }
00135
00137 DRange & operator=(const Base & rhs)
00138 {
00139 Base::operator=(rhs);
00140 return *this;
00141 }
00142
00144 ~DRange()
00145 {
00146 }
00147
00149
00152
00153 bool operator==(const DRange & rhs) const
00154 {
00155 return Base::operator==(rhs);
00156 }
00157
00159 bool operator==(const Base & rhs) const
00160 {
00161 return Base::operator==(rhs);
00162 }
00163
00170 bool encloses(const PositionType & position) const
00171 {
00172 for (UInt i = 0; i != D; i++)
00173 {
00174 if (position[i] < min_[i]) return false;
00175
00176 if (position[i] >= max_[i]) return false;
00177 }
00178 return true;
00179 }
00180
00182 bool encloses(CoordinateType x, CoordinateType y) const
00183 {
00184 if (x < min_[0]) return false;
00185
00186 if (x >= max_[0]) return false;
00187
00188 if (y < min_[1]) return false;
00189
00190 if (y >= max_[1]) return false;
00191
00192 return true;
00193 }
00194
00196 DRange united(const DRange<D> & other_range) const
00197 {
00198 PositionType united_min;
00199 PositionType united_max;
00200 DRange<D> united_range = DRange<D>::empty;
00201
00202 PositionType other_min = other_range.minPosition();
00203 PositionType other_max = other_range.maxPosition();
00204
00205 for (Size i = 0; i != D; ++i)
00206 {
00207 united_min[i] = min_[i] < other_min[i] ? min_[i] : other_min[i];
00208 united_max[i] = max_[i] > other_max[i] ? max_[i] : other_max[i];
00209 }
00210 united_range.setMinMax(united_min, united_max);
00211
00212 return united_range;
00213 }
00214
00220 DRangeIntersection intersects(const DRange & range) const
00221 {
00222
00223 if (encloses(range.min_))
00224 {
00225
00226 for (Size i = 0; i != D; i++)
00227 {
00228 if (range.max_[i] > max_[i])
00229 {
00230 return Intersects;
00231 }
00232 }
00233 return Inside;
00234 }
00235
00236
00237 for (Size i = 0; i != D; i++)
00238 {
00239 if (range.min_[i] >= max_[i])
00240 {
00241 return Disjoint;
00242 }
00243 }
00244
00245
00246 for (Size i = 0; i != D; i++)
00247 {
00248 if (range.max_[i] <= min_[i])
00249 {
00250 return Disjoint;
00251 }
00252 }
00253 return Intersects;
00254 }
00255
00262 bool isIntersected(const DRange & range) const
00263 {
00264
00265 if (encloses(range.min_))
00266 {
00267 return true;
00268 }
00269
00270
00271
00272 for (Size i = 0; i != D; i++)
00273 {
00274 if (range.min_[i] >= max_[i])
00275 {
00276 return false;
00277 }
00278 }
00279
00280
00281 for (Size i = 0; i != D; i++)
00282 {
00283 if (range.max_[i] <= min_[i])
00284 {
00285 return false;
00286 }
00287 }
00288 return true;
00289 }
00290
00292 bool isEmpty() const
00293 {
00294 for (UInt i = 0; i != D; i++)
00295 {
00296 if (max_[i] <= min_[i])
00297 {
00298 return true;
00299 }
00300 }
00301 return false;
00302 }
00303
00305 };
00306
00308 template <UInt D>
00309 std::ostream & operator<<(std::ostream & os, const DRange<D> & area)
00310 {
00311 os << "--DRANGE BEGIN--" << std::endl;
00312 os << "MIN --> " << area.min_ << std::endl;
00313 os << "MAX --> " << area.max_ << std::endl;
00314 os << "--DRANGE END--" << std::endl;
00315 return os;
00316 }
00317
00318 }
00319
00320 #endif // OPENMS_DATASTRUCTURES_DRANGE_H