Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-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: $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_DATASTRUCTURES_DBOUNDINGBOX_H
36 #define OPENMS_DATASTRUCTURES_DBOUNDINGBOX_H
37 
39 #include <OpenMS/CONCEPT/Types.h>
40 
41 namespace OpenMS
42 {
43 
51  template <UInt D>
52  class DBoundingBox :
53  public Internal::DIntervalBase<D>
54  {
55 
56 public:
57 
62  enum {DIMENSION = D};
67  typedef typename Base::PositionType PositionType;
71 
72 
73  // for convenience
74  using Base::min_;
75  using Base::max_;
76 
79  DBoundingBox() :
81  Base()
82  {
83  }
84 
86  DBoundingBox(const DBoundingBox& rhs) :
87  Base(rhs)
88  {
89  }
90 
93  {
94  Base::operator=(rhs);
95  return *this;
96  }
97 
99  DBoundingBox& operator=(const Base& rhs)
100  {
101  Base::operator=(rhs);
102  return *this;
103  }
104 
107  {
108  }
109 
111  DBoundingBox(const PositionType& minimum, const PositionType& maximum) :
112  Base(minimum, maximum)
113  {
114  }
115 
117 
120 
122  void enlarge(const PositionType& p)
123  {
124  for (UInt i = 0; i < DIMENSION; ++i)
125  {
126  if (p[i] < min_[i]) min_[i] = p[i];
127  if (p[i] > max_[i]) max_[i] = p[i];
128  }
129  }
130 
132  void enlarge(CoordinateType x, CoordinateType y)
133  {
134  enlarge(PositionType(x, y));
135  }
136 
137  //}@
138 
141 
143  bool operator==(const DBoundingBox& rhs) const
144  {
145  return Base::operator==(rhs);
146  }
147 
149  bool operator==(const Base& rhs) const
150  {
151  return Base::operator==(rhs);
152  }
153 
160  bool encloses(const PositionType& position) const
161  {
162  for (UInt i = 0; i < DIMENSION; ++i)
163  {
164  if (position[i] < min_[i] || position[i] > max_[i])
165  {
166  return false;
167  }
168  }
169  return true;
170  }
171 
173  bool encloses(CoordinateType x, CoordinateType y) const
174  {
175  return encloses(PositionType(x, y));
176  }
177 
181  bool intersects(const DBoundingBox& bounding_box) const
182  {
183  for (UInt i = 0; i < DIMENSION; ++i)
184  {
185  if (bounding_box.min_[i] > max_[i]) return false;
186 
187  if (bounding_box.max_[i] < min_[i]) return false;
188  }
189  return true;
190  }
191 
193  bool isEmpty() const
194  {
195  for (UInt i = 0; i != D; i++)
196  {
197  if (max_[i] <= min_[i])
198  {
199  return true;
200  }
201  }
202  return false;
203  }
204 
206 
207 
208  };
209 
214  template <UInt D>
215  std::ostream& operator<<(std::ostream& os, const DBoundingBox<D>& bounding_box)
216  {
217  os << "--DBOUNDINGBOX BEGIN--" << std::endl;
218  os << "MIN --> " << bounding_box.minPosition() << std::endl;
219  os << "MAX --> " << bounding_box.maxPosition() << std::endl;
220  os << "--DBOUNDINGBOX END--" << std::endl;
221  return os;
222  }
223 
224 } // namespace OpenMS
225 
226 #endif // OPENMS_KERNEL_DBOUNDINGBOX_H
Internal::DIntervalBase< D > Base
Base class type.
Definition: DBoundingBox.h:65
PositionType min_
lower left point
Definition: DIntervalBase.h:309
void enlarge(const PositionType &p)
Enlarges the bounding box such that it contains a position.
Definition: DBoundingBox.h:122
Definition: DBoundingBox.h:63
DIntervalBase & operator=(const DIntervalBase &rhs)
Assignment operator.
Definition: DIntervalBase.h:94
DBoundingBox & operator=(const Base &rhs)
Assignment operator for the base class.
Definition: DBoundingBox.h:99
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
DBoundingBox()
Default constructor.
Definition: DBoundingBox.h:80
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
bool intersects(const DBoundingBox &bounding_box) const
Definition: DBoundingBox.h:181
Base::PositionType PositionType
Position type.
Definition: DBoundingBox.h:67
bool encloses(CoordinateType x, CoordinateType y) const
2D-version encloses(x,y) is for convenience only
Definition: DBoundingBox.h:173
DBoundingBox & operator=(const DBoundingBox &rhs)
Assignment operator.
Definition: DBoundingBox.h:92
bool isEmpty() const
Test if bounding box is empty.
Definition: DBoundingBox.h:193
bool operator==(const Base &rhs) const
Equality operator.
Definition: DBoundingBox.h:149
bool operator==(const DBoundingBox &rhs) const
Equality operator.
Definition: DBoundingBox.h:143
PositionType max_
upper right point
Definition: DIntervalBase.h:312
A base class for D-dimensional interval.
Definition: DIntervalBase.h:56
DBoundingBox(const DBoundingBox &rhs)
Copy constructor.
Definition: DBoundingBox.h:86
bool encloses(const PositionType &position) const
Checks whether this range contains a certain point.
Definition: DBoundingBox.h:160
~DBoundingBox()
Destructor.
Definition: DBoundingBox.h:106
Base::CoordinateType CoordinateType
Coordinate type of the positions.
Definition: DBoundingBox.h:69
void enlarge(CoordinateType x, CoordinateType y)
Enlarges the bounding box such that it contains a position specified by two coordinates.
Definition: DBoundingBox.h:132
A D-dimensional bounding box.
Definition: DBoundingBox.h:52
DBoundingBox(const PositionType &minimum, const PositionType &maximum)
Constructor from two positions.
Definition: DBoundingBox.h:111
bool operator==(const DIntervalBase &rhs) const
Equality operator.
Definition: DIntervalBase.h:193

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