OpenMS
DBoundingBox.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 #include <OpenMS/CONCEPT/Types.h>
13 
14 namespace OpenMS
15 {
16 
24  template <UInt D>
25  class DBoundingBox :
26  public Internal::DIntervalBase<D>
27  {
28 
29 public:
30 
36  enum {DIMENSION = D};
40  typedef typename Base::PositionType PositionType;
44 
45 
46  // for convenience
47  using Base::min_;
48  using Base::max_;
49 
54  Base()
55  {
56  }
57 
59  DBoundingBox(const DBoundingBox& rhs) :
60  Base(rhs)
61  {
62  }
63 
66  {
67  Base::operator=(rhs);
68  return *this;
69  }
70 
73  {
74  Base::operator=(rhs);
75  return *this;
76  }
77 
80  {
81  }
82 
84  DBoundingBox(const PositionType& minimum, const PositionType& maximum) :
85  Base(minimum, maximum)
86  {
87  }
88 
90 
93 
95  void enlarge(const PositionType& p)
96  {
97  for (UInt i = 0; i < DIMENSION; ++i)
98  {
99  if (p[i] < min_[i]) min_[i] = p[i];
100  if (p[i] > max_[i]) max_[i] = p[i];
101  }
102  }
103 
106  {
107  enlarge(PositionType(x, y));
108  }
109 
110  //}@
111 
114 
116  bool operator==(const DBoundingBox& rhs) const
117  {
118  return Base::operator==(rhs);
119  }
120 
122  bool operator==(const Base& rhs) const
123  {
124  return Base::operator==(rhs);
125  }
126 
133  bool encloses(const PositionType& position) const
134  {
135  for (UInt i = 0; i < DIMENSION; ++i)
136  {
137  if (position[i] < min_[i] || position[i] > max_[i])
138  {
139  return false;
140  }
141  }
142  return true;
143  }
144 
147  {
148  return encloses(PositionType(x, y));
149  }
150 
154  bool intersects(const DBoundingBox& bounding_box) const
155  {
156  for (UInt i = 0; i < DIMENSION; ++i)
157  {
158  if (bounding_box.min_[i] > max_[i]) return false;
159 
160  if (bounding_box.max_[i] < min_[i]) return false;
161  }
162  return true;
163  }
164 
166  bool isEmpty() const
167  {
168  for (UInt i = 0; i != D; i++)
169  {
170  if (max_[i] <= min_[i])
171  {
172  return true;
173  }
174  }
175  return false;
176  }
177 
179 
180 
181  };
182 
187  template <UInt D>
188  std::ostream& operator<<(std::ostream& os, const DBoundingBox<D>& bounding_box)
189  {
190  os << "--DBOUNDINGBOX BEGIN--" << std::endl;
191  os << "MIN --> " << bounding_box.minPosition() << std::endl;
192  os << "MAX --> " << bounding_box.maxPosition() << std::endl;
193  os << "--DBOUNDINGBOX END--" << std::endl;
194  return os;
195  }
196 
197 } // namespace OpenMS
198 
A D-dimensional bounding box.
Definition: DBoundingBox.h:27
PositionType min_
lower left point
Definition: DIntervalBase.h:336
DBoundingBox()
Default constructor.
Definition: DBoundingBox.h:53
bool encloses(const PositionType &position) const
Checks whether this range contains a certain point.
Definition: DBoundingBox.h:133
Base::PositionType PositionType
Position type.
Definition: DBoundingBox.h:40
DBoundingBox(const DBoundingBox &rhs)
Copy constructor.
Definition: DBoundingBox.h:59
std::ostream & operator<<(std::ostream &os, const DBoundingBox< D > &bounding_box)
Print the contents to a stream.
Definition: DBoundingBox.h:188
PositionType max_
upper right point
Definition: DIntervalBase.h:339
bool encloses(CoordinateType x, CoordinateType y) const
2D-version encloses(x,y) is for convenience only
Definition: DBoundingBox.h:146
bool operator==(const DBoundingBox &rhs) const
Equality operator.
Definition: DBoundingBox.h:116
bool operator==(const Base &rhs) const
Equality operator.
Definition: DBoundingBox.h:122
DBoundingBox(const PositionType &minimum, const PositionType &maximum)
Constructor from two positions.
Definition: DBoundingBox.h:84
@ DIMENSION
Definition: DBoundingBox.h:36
Internal::DIntervalBase< D > Base
Base class type.
Definition: DBoundingBox.h:38
Base::CoordinateType CoordinateType
Coordinate type of the positions.
Definition: DBoundingBox.h:42
void enlarge(CoordinateType x, CoordinateType y)
Enlarges the bounding box such that it contains a position specified by two coordinates.
Definition: DBoundingBox.h:105
DBoundingBox & operator=(const DBoundingBox &rhs)
Assignment operator.
Definition: DBoundingBox.h:65
bool intersects(const DBoundingBox &bounding_box) const
Definition: DBoundingBox.h:154
bool isEmpty() const
Test if bounding box is empty.
Definition: DBoundingBox.h:166
DBoundingBox & operator=(const Base &rhs)
Assignment operator for the base class.
Definition: DBoundingBox.h:72
~DBoundingBox()
Destructor.
Definition: DBoundingBox.h:79
void enlarge(const PositionType &p)
Enlarges the bounding box such that it contains a position.
Definition: DBoundingBox.h:95
A base class for D-dimensional interval.
Definition: DIntervalBase.h:30
PositionType min_
lower left point
Definition: DIntervalBase.h:336
DIntervalBase & operator=(const DIntervalBase &rhs)
Assignment operator.
Definition: DIntervalBase.h:70
PositionType::CoordinateType CoordinateType
Coordinate type of the positions.
Definition: DIntervalBase.h:42
PositionType const & maxPosition() const
Accessor to maximum position.
Definition: DIntervalBase.h:104
PositionType max_
upper right point
Definition: DIntervalBase.h:339
bool operator==(const DIntervalBase &rhs) const
Equality operator.
Definition: DIntervalBase.h:169
DPosition< D > PositionType
Position type.
Definition: DIntervalBase.h:40
PositionType const & minPosition() const
Accessor to minimum position.
Definition: DIntervalBase.h:98
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22