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 #ifndef OPENMS_DATASTRUCTURES_DRANGE_H
00028 #define OPENMS_DATASTRUCTURES_DRANGE_H
00029
00030 #include <OpenMS/DATASTRUCTURES/DIntervalBase.h>
00031
00032 namespace OpenMS
00033 {
00050 template <UInt D>
00051 class DRange
00052 : public Internal::DIntervalBase<D>
00053 {
00054 public:
00055
00060
00061 enum { DIMENSION = D };
00063 typedef Internal::DIntervalBase<D> Base;
00065 typedef typename Base::PositionType PositionType;
00067 typedef typename Base::CoordinateType CoordinateType;
00069 enum DRangeIntersection
00070 {
00071 Disjoint,
00072 Intersects,
00073 Inside
00074 };
00075
00077
00078 using Base::min_;
00079 using Base::max_;
00080
00088 DRange()
00089 : Base()
00090 {
00091
00092 }
00093
00095 DRange(const PositionType& lower, const PositionType& upper)
00096 :Base(lower, upper)
00097 {
00098
00099 }
00100
00102 DRange(const DRange& range)
00103 : Base(range)
00104 {
00105
00106 }
00107
00109 DRange(const Base& range)
00110 : Base(range)
00111 {
00112
00113 }
00114
00116 DRange(CoordinateType minx,CoordinateType miny, CoordinateType maxx,CoordinateType maxy)
00117 {
00118 OPENMS_PRECONDITION(D == 2, "DRange<D>:DRange(minx, miny, maxx, maxy): index overflow!");
00119 min_[0]=minx;
00120 min_[1]=miny;
00121 max_[0]=maxx;
00122 max_[1]=maxy;
00123 }
00124
00126 DRange & operator=(const DRange& rhs)
00127 {
00128 Base::operator=(rhs);
00129 return *this;
00130 }
00131
00133 DRange & operator=(const Base& rhs)
00134 {
00135 Base::operator=(rhs);
00136 return *this;
00137 }
00138
00140 ~DRange() {}
00142
00145
00146 bool operator == (const DRange& rhs) const throw()
00147 {
00148 return Base::operator==(rhs);
00149 }
00151 bool operator == (const Base& rhs) const throw()
00152 {
00153 return Base::operator==(rhs);
00154 }
00155
00162 bool encloses(const PositionType& position) const
00163 {
00164 for(UInt i = 0; i != D; i++)
00165 {
00166 if (position[i]<min_[i]) return false;
00167 if (position[i]>=max_[i]) return false;
00168 }
00169 return true;
00170 }
00171
00173 bool encloses(CoordinateType x, CoordinateType y) const
00174 {
00175 if (x<min_[0]) return false;
00176 if (x>=max_[0]) return false;
00177 if (y<min_[1]) return false;
00178 if (y>=max_[1]) return false;
00179 return true;
00180 }
00181
00187 DRangeIntersection intersects(const DRange& range) const
00188 {
00189
00190 if (encloses(range.min_))
00191 {
00192
00193 for(UInt i = 0; i != D; i++)
00194 {
00195 if (range.max_[i]>max_[i])
00196 {
00197 return Intersects;
00198 }
00199 }
00200 return Inside;
00201 }
00202
00203
00204 for(UInt i = 0; i != D; i++)
00205 {
00206 if (range.min_[i]>=max_[i])
00207 {
00208 return Disjoint;
00209 }
00210 }
00211
00212
00213 for(UInt i = 0; i != D; i++)
00214 {
00215 if (range.max_[i]<=min_[i])
00216 {
00217 return Disjoint;
00218 }
00219 }
00220 return Intersects;
00221 }
00222
00229 bool isIntersected(const DRange& range) const
00230 {
00231
00232 if (encloses(range.min_))
00233 {
00234 return true;
00235 }
00236
00237
00238
00239 for(UInt i = 0; i != D; i++)
00240 {
00241 if (range.min_[i]>=max_[i])
00242 {
00243 return false;
00244 }
00245 }
00246
00247
00248 for(UInt i = 0; i != D; i++)
00249 {
00250 if (range.max_[i]<=min_[i])
00251 {
00252 return false;
00253 }
00254 }
00255 return true;
00256 }
00257
00259 bool isEmpty() const
00260 {
00261 for(UInt i = 0; i != D; i++)
00262 {
00263 if (max_[i]<=min_[i])
00264 {
00265 return true;
00266 }
00267 }
00268 return false;
00269 }
00270
00272 };
00273
00275 template <UInt D>
00276 std::ostream& operator << (std::ostream& os, const DRange<D>& area)
00277 {
00278 os << "--DRANGE BEGIN--"<<std::endl;
00279 os << "MIN --> " << area.min_ << std::endl;
00280 os << "MAX --> " << area.max_ << std::endl;
00281 os << "--DRANGE END--"<<std::endl;
00282 return os;
00283 }
00284
00285
00286 }
00287
00288 #endif // OPENMS_KERNEL_DRANGE_H