OpenMS  3.0.0
DBoundingBox.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-2022.
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: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 #include <OpenMS/CONCEPT/Types.h>
39 
40 namespace OpenMS
41 {
42 
50  template <UInt D>
51  class DBoundingBox :
52  public Internal::DIntervalBase<D>
53  {
54 
55 public:
56 
61  enum {DIMENSION = D};
66  typedef typename Base::PositionType PositionType;
70 
71 
72  // for convenience
73  using Base::min_;
74  using Base::max_;
75 
78  DBoundingBox() :
80  Base()
81  {
82  }
83 
85  DBoundingBox(const DBoundingBox& rhs) :
86  Base(rhs)
87  {
88  }
89 
92  {
93  Base::operator=(rhs);
94  return *this;
95  }
96 
99  {
100  Base::operator=(rhs);
101  return *this;
102  }
103 
106  {
107  }
108 
110  DBoundingBox(const PositionType& minimum, const PositionType& maximum) :
111  Base(minimum, maximum)
112  {
113  }
114 
116 
119 
121  void enlarge(const PositionType& p)
122  {
123  for (UInt i = 0; i < DIMENSION; ++i)
124  {
125  if (p[i] < min_[i]) min_[i] = p[i];
126  if (p[i] > max_[i]) max_[i] = p[i];
127  }
128  }
129 
132  {
133  enlarge(PositionType(x, y));
134  }
135 
136  //}@
137 
140 
142  bool operator==(const DBoundingBox& rhs) const
143  {
144  return Base::operator==(rhs);
145  }
146 
148  bool operator==(const Base& rhs) const
149  {
150  return Base::operator==(rhs);
151  }
152 
159  bool encloses(const PositionType& position) const
160  {
161  for (UInt i = 0; i < DIMENSION; ++i)
162  {
163  if (position[i] < min_[i] || position[i] > max_[i])
164  {
165  return false;
166  }
167  }
168  return true;
169  }
170 
173  {
174  return encloses(PositionType(x, y));
175  }
176 
180  bool intersects(const DBoundingBox& bounding_box) const
181  {
182  for (UInt i = 0; i < DIMENSION; ++i)
183  {
184  if (bounding_box.min_[i] > max_[i]) return false;
185 
186  if (bounding_box.max_[i] < min_[i]) return false;
187  }
188  return true;
189  }
190 
192  bool isEmpty() const
193  {
194  for (UInt i = 0; i != D; i++)
195  {
196  if (max_[i] <= min_[i])
197  {
198  return true;
199  }
200  }
201  return false;
202  }
203 
205 
206 
207  };
208 
213  template <UInt D>
214  std::ostream& operator<<(std::ostream& os, const DBoundingBox<D>& bounding_box)
215  {
216  os << "--DBOUNDINGBOX BEGIN--" << std::endl;
217  os << "MIN --> " << bounding_box.minPosition() << std::endl;
218  os << "MAX --> " << bounding_box.maxPosition() << std::endl;
219  os << "--DBOUNDINGBOX END--" << std::endl;
220  return os;
221  }
222 
223 } // namespace OpenMS
224 
double
OpenMS::DBoundingBox::isEmpty
bool isEmpty() const
Test if bounding box is empty.
Definition: DBoundingBox.h:192
OpenMS::DBoundingBox::operator==
bool operator==(const DBoundingBox &rhs) const
Equality operator.
Definition: DBoundingBox.h:142
OpenMS::DBoundingBox::intersects
bool intersects(const DBoundingBox &bounding_box) const
Definition: DBoundingBox.h:180
OpenMS::DBoundingBox::min_
PositionType min_
lower left point
Definition: DIntervalBase.h:362
Types.h
OpenMS::DBoundingBox::PositionType
Base::PositionType PositionType
Position type.
Definition: DBoundingBox.h:66
OpenMS::DBoundingBox::DBoundingBox
DBoundingBox(const DBoundingBox &rhs)
Copy constructor.
Definition: DBoundingBox.h:85
OpenMS::DBoundingBox::operator=
DBoundingBox & operator=(const DBoundingBox &rhs)
Assignment operator.
Definition: DBoundingBox.h:91
OpenMS::Internal::DIntervalBase::min_
PositionType min_
lower left point
Definition: DIntervalBase.h:362
OpenMS::Internal::DIntervalBase::operator=
DIntervalBase & operator=(const DIntervalBase &rhs)
Assignment operator.
Definition: DIntervalBase.h:96
OpenMS::DBoundingBox::enlarge
void enlarge(CoordinateType x, CoordinateType y)
Enlarges the bounding box such that it contains a position specified by two coordinates.
Definition: DBoundingBox.h:131
OpenMS::DBoundingBox::encloses
bool encloses(const PositionType &position) const
Checks whether this range contains a certain point.
Definition: DBoundingBox.h:159
OpenMS::DBoundingBox::DBoundingBox
DBoundingBox(const PositionType &minimum, const PositionType &maximum)
Constructor from two positions.
Definition: DBoundingBox.h:110
OpenMS::Internal::DIntervalBase::maxPosition
PositionType const & maxPosition() const
Accessor to maximum position.
Definition: DIntervalBase.h:130
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
DIntervalBase.h
OpenMS::DBoundingBox::CoordinateType
Base::CoordinateType CoordinateType
Coordinate type of the positions.
Definition: DBoundingBox.h:68
OpenMS::DBoundingBox::DIMENSION
Definition: DBoundingBox.h:62
OpenMS::DBoundingBox::enlarge
void enlarge(const PositionType &p)
Enlarges the bounding box such that it contains a position.
Definition: DBoundingBox.h:121
OpenMS::DBoundingBox::max_
PositionType max_
upper right point
Definition: DIntervalBase.h:365
OpenMS::DBoundingBox::~DBoundingBox
~DBoundingBox()
Destructor.
Definition: DBoundingBox.h:105
OpenMS::Internal::DIntervalBase::max_
PositionType max_
upper right point
Definition: DIntervalBase.h:365
OpenMS::DBoundingBox
A D-dimensional bounding box.
Definition: DBoundingBox.h:51
OpenMS::DBoundingBox::Base
Internal::DIntervalBase< D > Base
Base class type.
Definition: DBoundingBox.h:64
OpenMS::operator<<
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
OpenMS::DPosition< D >
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::DBoundingBox::operator=
DBoundingBox & operator=(const Base &rhs)
Assignment operator for the base class.
Definition: DBoundingBox.h:98
OpenMS::Internal::DIntervalBase
A base class for D-dimensional interval.
Definition: DIntervalBase.h:55
OpenMS::Internal::DIntervalBase::minPosition
PositionType const & minPosition() const
Accessor to minimum position.
Definition: DIntervalBase.h:124
OpenMS::DBoundingBox::encloses
bool encloses(CoordinateType x, CoordinateType y) const
2D-version encloses(x,y) is for convenience only
Definition: DBoundingBox.h:172
OpenMS::Internal::DIntervalBase::operator==
bool operator==(const DIntervalBase &rhs) const
Equality operator.
Definition: DIntervalBase.h:195
OpenMS::DBoundingBox::DBoundingBox
DBoundingBox()
Default constructor.
Definition: DBoundingBox.h:79
OpenMS::DBoundingBox::operator==
bool operator==(const Base &rhs) const
Equality operator.
Definition: DBoundingBox.h:148