Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-2017.
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 #ifndef OPENMS_DATASTRUCTURES_DINTERVALBASE_H
36 #define OPENMS_DATASTRUCTURES_DINTERVALBASE_H
37 
39 #include <OpenMS/CONCEPT/Types.h>
40 
41 #include <utility>
42 
43 namespace OpenMS
44 {
45  namespace Internal
46  {
55  template <UInt D>
57  {
58 public:
59 
64  enum {DIMENSION = D};
71 
74 
81  min_(PositionType::maxPositive()),
82  max_(PositionType::minNegative())
83  {
84  }
85 
88  min_(rhs.min_),
89  max_(rhs.max_)
90  {
91  }
92 
95  {
96  min_ = rhs.min_;
97  max_ = rhs.max_;
98  return *this;
99  }
100 
103  {
104  }
105 
109  DIntervalBase(PositionType const& minimum, PositionType const& maximum) :
110  min_(minimum),
111  max_(maximum)
112  {
113  normalize_();
114  }
115 
117 
120 
122  inline PositionType const& minPosition() const
123  {
124  return min_;
125  }
126 
128  inline PositionType const& maxPosition() const
129  {
130  return max_;
131  }
132 
139  void setMin(PositionType const& position)
140  {
141  min_ = position;
142  for (UInt i = 0; i < DIMENSION; ++i)
143  {
144  if (min_[i] > max_[i]) max_[i] = min_[i];
145  }
146  }
147 
154  void setMax(PositionType const& position)
155  {
156  max_ = position;
157  for (UInt i = 0; i < DIMENSION; ++i)
158  {
159  if (min_[i] > max_[i]) min_[i] = max_[i];
160  }
161  }
162 
166  void setMinMax(PositionType const& min, PositionType const& max)
167  {
168  min_ = min;
169  max_ = max;
170  normalize_();
171  }
172 
178  template <UInt D2>
179  void assign(const DIntervalBase<D2> rhs)
180  {
181  for (UInt i = 0; i < std::min(D, D2); ++i)
182  {
183  min_[i] = rhs.minPosition()[i];
184  max_[i] = rhs.maxPosition()[i];
185  }
186  }
187 
188  //}@
189 
192  bool operator==(const DIntervalBase& rhs) const
194  {
195  return (min_ == rhs.min_) && (max_ == rhs.max_);
196  }
197 
199  bool operator!=(const DIntervalBase& rhs) const
200  {
201  return !(operator==(rhs));
202  }
203 
205  inline void clear()
206  {
207  *this = empty;
208  }
209 
211 
214 
216  PositionType center() const
217  {
218  PositionType center(min_);
219  center += max_;
220  center /= 2;
221  return center;
222  }
223 
225  PositionType diagonal() const
226  {
227  return max_ - min_;
228  }
229 
231  static DIntervalBase const empty;
233  static DIntervalBase const zero;
234 
235  //}@
236 
239 
241  inline CoordinateType minX() const
242  {
243  return min_[0];
244  }
245 
247  inline CoordinateType minY() const
248  {
249  return min_[1];
250  }
251 
253  inline CoordinateType maxX() const
254  {
255  return max_[0];
256  }
257 
259  inline CoordinateType maxY() const
260  {
261  return max_[1];
262  }
263 
265  void setMinX(CoordinateType const c)
266  {
267  min_[0] = c;
268  if (min_[0] > max_[0]) max_[0] = min_[0];
269  }
270 
272  void setMinY(CoordinateType const c)
273  {
274  min_[1] = c;
275  if (min_[1] > max_[1]) max_[1] = min_[1];
276  }
277 
279  void setMaxX(CoordinateType const c)
280  {
281  max_[0] = c;
282  if (min_[0] > max_[0]) min_[0] = max_[0];
283  }
284 
286  void setMaxY(CoordinateType const c)
287  {
288  max_[1] = c;
289  if (min_[1] > max_[1]) min_[1] = max_[1];
290  }
291 
293  inline CoordinateType width() const
294  {
295  return max_[0] - min_[0];
296  }
297 
299  inline CoordinateType height() const
300  {
301  return max_[1] - min_[1];
302  }
303 
305 
306 protected:
307 
309  PositionType min_;
310 
312  PositionType max_;
313 
315  void normalize_()
316  {
317  for (UInt i = 0; i < DIMENSION; ++i)
318  {
319  if (min_[i] > max_[i])
320  {
321  std::swap(min_[i], max_[i]);
322  }
323  }
324  }
325 
327  DIntervalBase(const std::pair<PositionType, PositionType>& pair) :
328  min_(pair.first),
329  max_(pair.second)
330  {
331 
332  }
333 
334  };
335 
336  template <UInt D>
339 
340  template <UInt D>
343 
345  template <UInt D>
346  std::ostream& operator<<(std::ostream& os, const DIntervalBase<D>& rhs)
347  {
348  os << "--DIntervalBase BEGIN--" << std::endl;
349  os << "MIN --> " << rhs.minPosition() << std::endl;
350  os << "MAX --> " << rhs.maxPosition() << std::endl;
351  os << "--DIntervalBase END--" << std::endl;
352  return os;
353  }
354 
355  } // namespace Internal
356 
357 } // namespace OpenMS
358 
359 #endif // OPENMS_KERNEL_DINTERVALBASE_H
DIntervalBase(const DIntervalBase &rhs)
Copy constructor.
Definition: DIntervalBase.h:87
void normalize_()
normalization to keep all dimensions in the right geometrical order (min_[X] < max_[X]) ...
Definition: DIntervalBase.h:315
void setMaxX(CoordinateType const c)
Mutator for min_ coordinate of the larger point.
Definition: DIntervalBase.h:279
PositionType min_
lower left point
Definition: DIntervalBase.h:309
DIntervalBase(const std::pair< PositionType, PositionType > &pair)
Protected constructor for the construction of static instances.
Definition: DIntervalBase.h:327
~DIntervalBase()
Destructor.
Definition: DIntervalBase.h:102
void setMinY(CoordinateType const c)
Mutator for max_ coordinate of the smaller point.
Definition: DIntervalBase.h:272
CoordinateType maxX() const
Accessor for min_ coordinate maximum.
Definition: DIntervalBase.h:253
void setMin(PositionType const &position)
Mutator for minimum position.
Definition: DIntervalBase.h:139
DIntervalBase & operator=(const DIntervalBase &rhs)
Assignment operator.
Definition: DIntervalBase.h:94
void setMaxY(CoordinateType const c)
Mutator for max_ coordinate of the larger point.
Definition: DIntervalBase.h:286
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
const double c
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
CoordinateType height() const
Returns the height of the area i.e. the difference of dimension one (Y).
Definition: DIntervalBase.h:299
Definition: DIntervalBase.h:65
static DIntervalBase const zero
instance with all positions zero
Definition: DIntervalBase.h:233
void setMax(PositionType const &position)
Mutator for maximum position.
Definition: DIntervalBase.h:154
PositionType const & maxPosition() const
Accessor to maximum position.
Definition: DIntervalBase.h:128
DPosition< D > PositionType
Position type.
Definition: DIntervalBase.h:67
DIntervalBase()
Default constructor.
Definition: DIntervalBase.h:80
bool operator!=(const DIntervalBase &rhs) const
Equality operator.
Definition: DIntervalBase.h:199
PositionType center() const
Returns the center of the interval.
Definition: DIntervalBase.h:216
void assign(const DIntervalBase< D2 > rhs)
Assignment from a DIntervalBase of different dimensions.
Definition: DIntervalBase.h:179
static const DPosition zero()
all zero
Definition: DPosition.h:361
DIntervalBase(PositionType const &minimum, PositionType const &maximum)
This constructor sets min_ and max_ directly.
Definition: DIntervalBase.h:109
CoordinateType minY() const
Accessor for max_ coordinate minimum.
Definition: DIntervalBase.h:247
CoordinateType maxY() const
Accessor for max_ coordinate maximum.
Definition: DIntervalBase.h:259
CoordinateType width() const
Returns the width of the area i.e. the difference of dimension zero (X).
Definition: DIntervalBase.h:293
PositionType diagonal() const
Returns the diagonal of the area, i.e. max_ - min_.
Definition: DIntervalBase.h:225
PositionType max_
upper right point
Definition: DIntervalBase.h:312
A base class for D-dimensional interval.
Definition: DIntervalBase.h:56
CoordinateType minX() const
Accessor for min_ coordinate minimum.
Definition: DIntervalBase.h:241
void setMinX(CoordinateType const c)
Mutator for min_ coordinate of the smaller point.
Definition: DIntervalBase.h:265
void setMinMax(PositionType const &min, PositionType const &max)
Mutator for minimum and maximum position.
Definition: DIntervalBase.h:166
static DIntervalBase const empty
empty instance
Definition: DIntervalBase.h:231
bool operator==(const DIntervalBase &rhs) const
Equality operator.
Definition: DIntervalBase.h:193
void clear()
Make the interval empty.
Definition: DIntervalBase.h:205
PositionType::CoordinateType CoordinateType
Coordinate type of the positions.
Definition: DIntervalBase.h:69
PositionType const & minPosition() const
Accessor to minimum position.
Definition: DIntervalBase.h:122

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:21:59 using doxygen 1.8.13