OpenMS  2.4.0
DIntervalBase.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2018.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Clemens Groepl, Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 #include <OpenMS/CONCEPT/Types.h>
39 
40 #include <utility>
41 
42 namespace OpenMS
43 {
44  namespace Internal
45  {
54  template <UInt D>
56  {
57 public:
58 
63  enum {DIMENSION = D};
70 
73 
80  min_(PositionType::maxPositive()),
81  max_(PositionType::minNegative())
82  {
83  }
84 
87  min_(rhs.min_),
88  max_(rhs.max_)
89  {
90  }
91 
94  {
95  min_ = rhs.min_;
96  max_ = rhs.max_;
97  return *this;
98  }
99 
102  {
103  }
104 
108  DIntervalBase(PositionType const& minimum, PositionType const& maximum) :
109  min_(minimum),
110  max_(maximum)
111  {
112  normalize_();
113  }
114 
116 
119 
121  inline PositionType const& minPosition() const
122  {
123  return min_;
124  }
125 
127  inline PositionType const& maxPosition() const
128  {
129  return max_;
130  }
131 
139  {
140  min_ = position;
141  for (UInt i = 0; i < DIMENSION; ++i)
142  {
143  if (min_[i] > max_[i]) max_[i] = min_[i];
144  }
145  }
146 
154  {
155  max_ = position;
156  for (UInt i = 0; i < DIMENSION; ++i)
157  {
158  if (min_[i] > max_[i]) min_[i] = max_[i];
159  }
160  }
161 
165  void setMinMax(PositionType const& min, PositionType const& max)
166  {
167  min_ = min;
168  max_ = max;
169  normalize_();
170  }
171 
177  template <UInt D2>
178  void assign(const DIntervalBase<D2> rhs)
179  {
180  for (UInt i = 0; i < std::min(D, D2); ++i)
181  {
182  min_[i] = rhs.minPosition()[i];
183  max_[i] = rhs.maxPosition()[i];
184  }
185  }
186 
187  //}@
188 
191  bool operator==(const DIntervalBase& rhs) const
193  {
194  return (min_ == rhs.min_) && (max_ == rhs.max_);
195  }
196 
198  bool operator!=(const DIntervalBase& rhs) const
199  {
200  return !(operator==(rhs));
201  }
202 
204  inline void clear()
205  {
206  *this = empty;
207  }
208 
210 
213 
216  {
218  center += max_;
219  center /= 2;
220  return center;
221  }
222 
225  {
226  return max_ - min_;
227  }
228 
230  static DIntervalBase const empty;
232  static DIntervalBase const zero;
233 
234  //}@
235 
238 
240  inline CoordinateType minX() const
241  {
242  return min_[0];
243  }
244 
246  inline CoordinateType minY() const
247  {
248  return min_[1];
249  }
250 
252  inline CoordinateType maxX() const
253  {
254  return max_[0];
255  }
256 
258  inline CoordinateType maxY() const
259  {
260  return max_[1];
261  }
262 
265  {
266  min_[0] = c;
267  if (min_[0] > max_[0]) max_[0] = min_[0];
268  }
269 
272  {
273  min_[1] = c;
274  if (min_[1] > max_[1]) max_[1] = min_[1];
275  }
276 
279  {
280  max_[0] = c;
281  if (min_[0] > max_[0]) min_[0] = max_[0];
282  }
283 
286  {
287  max_[1] = c;
288  if (min_[1] > max_[1]) min_[1] = max_[1];
289  }
290 
292  inline CoordinateType width() const
293  {
294  return max_[0] - min_[0];
295  }
296 
298  inline CoordinateType height() const
299  {
300  return max_[1] - min_[1];
301  }
302 
304 
305 protected:
306 
309 
312 
314  void normalize_()
315  {
316  for (UInt i = 0; i < DIMENSION; ++i)
317  {
318  if (min_[i] > max_[i])
319  {
320  std::swap(min_[i], max_[i]);
321  }
322  }
323  }
324 
326  DIntervalBase(const std::pair<PositionType, PositionType>& pair) :
327  min_(pair.first),
328  max_(pair.second)
329  {
330 
331  }
332 
333  };
334 
335  template <UInt D>
338 
339  template <UInt D>
342 
344  template <UInt D>
345  std::ostream& operator<<(std::ostream& os, const DIntervalBase<D>& rhs)
346  {
347  os << "--DIntervalBase BEGIN--" << std::endl;
348  os << "MIN --> " << rhs.minPosition() << std::endl;
349  os << "MAX --> " << rhs.maxPosition() << std::endl;
350  os << "--DIntervalBase END--" << std::endl;
351  return os;
352  }
353 
354  } // namespace Internal
355 
356 } // namespace OpenMS
357 
DIntervalBase(const DIntervalBase &rhs)
Copy constructor.
Definition: DIntervalBase.h:86
void normalize_()
normalization to keep all dimensions in the right geometrical order (min_[X] < max_[X]) ...
Definition: DIntervalBase.h:314
void setMaxX(CoordinateType const c)
Mutator for min_ coordinate of the larger point.
Definition: DIntervalBase.h:278
PositionType min_
lower left point
Definition: DIntervalBase.h:308
DIntervalBase(const std::pair< PositionType, PositionType > &pair)
Protected constructor for the construction of static instances.
Definition: DIntervalBase.h:326
~DIntervalBase()
Destructor.
Definition: DIntervalBase.h:101
void setMinY(CoordinateType const c)
Mutator for max_ coordinate of the smaller point.
Definition: DIntervalBase.h:271
Size< TNeedle >::Type position(const PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:561
CoordinateType maxX() const
Accessor for min_ coordinate maximum.
Definition: DIntervalBase.h:252
void setMin(PositionType const &position)
Mutator for minimum position.
Definition: DIntervalBase.h:138
DIntervalBase & operator=(const DIntervalBase &rhs)
Assignment operator.
Definition: DIntervalBase.h:93
void setMaxY(CoordinateType const c)
Mutator for max_ coordinate of the larger point.
Definition: DIntervalBase.h:285
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
const double c
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
CoordinateType height() const
Returns the height of the area i.e. the difference of dimension one (Y).
Definition: DIntervalBase.h:298
Definition: DIntervalBase.h:64
static DIntervalBase const zero
instance with all positions zero
Definition: DIntervalBase.h:232
void setMax(PositionType const &position)
Mutator for maximum position.
Definition: DIntervalBase.h:153
PositionType const & maxPosition() const
Accessor to maximum position.
Definition: DIntervalBase.h:127
DPosition< D > PositionType
Position type.
Definition: DIntervalBase.h:66
DIntervalBase()
Default constructor.
Definition: DIntervalBase.h:79
bool operator!=(const DIntervalBase &rhs) const
Equality operator.
Definition: DIntervalBase.h:198
PositionType center() const
Returns the center of the interval.
Definition: DIntervalBase.h:215
void assign(const DIntervalBase< D2 > rhs)
Assignment from a DIntervalBase of different dimensions.
Definition: DIntervalBase.h:178
static const DPosition zero()
all zero
Definition: DPosition.h:360
DIntervalBase(PositionType const &minimum, PositionType const &maximum)
This constructor sets min_ and max_ directly.
Definition: DIntervalBase.h:108
CoordinateType minY() const
Accessor for max_ coordinate minimum.
Definition: DIntervalBase.h:246
CoordinateType maxY() const
Accessor for max_ coordinate maximum.
Definition: DIntervalBase.h:258
CoordinateType width() const
Returns the width of the area i.e. the difference of dimension zero (X).
Definition: DIntervalBase.h:292
PositionType diagonal() const
Returns the diagonal of the area, i.e. max_ - min_.
Definition: DIntervalBase.h:224
PositionType max_
upper right point
Definition: DIntervalBase.h:311
A base class for D-dimensional interval.
Definition: DIntervalBase.h:55
CoordinateType minX() const
Accessor for min_ coordinate minimum.
Definition: DIntervalBase.h:240
void setMinX(CoordinateType const c)
Mutator for min_ coordinate of the smaller point.
Definition: DIntervalBase.h:264
void setMinMax(PositionType const &min, PositionType const &max)
Mutator for minimum and maximum position.
Definition: DIntervalBase.h:165
static DIntervalBase const empty
empty instance
Definition: DIntervalBase.h:230
bool operator==(const DIntervalBase &rhs) const
Equality operator.
Definition: DIntervalBase.h:192
void clear()
Make the interval empty.
Definition: DIntervalBase.h:204
PositionType::CoordinateType CoordinateType
Coordinate type of the positions.
Definition: DIntervalBase.h:68
PositionType const & minPosition() const
Accessor to minimum position.
Definition: DIntervalBase.h:121