bounding_box.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_BOUNDING_BOX_H
21 #define LIBMESH_BOUNDING_BOX_H
22 
23 // Local Includes
24 #include "libmesh/libmesh.h"
25 #include "libmesh/point.h" // some compilers want the full definition - I think so they can do
26 // return-value-optimization for BoundingBox'es - BSK
27 
28 // C++ Includes
29 #include <vector>
30 #include <set>
31 #include <limits>
32 
33 namespace libMesh
34 {
35 
40 class BoundingBox : public std::pair<Point, Point>
41 {
42 public:
43 
44  BoundingBox (const Point & new_min,
45  const Point & new_max) :
46  std::pair<Point, Point>(new_min, new_max)
47  {}
48 
49  BoundingBox (const std::pair<Point, Point> & bbox) :
50  std::pair<Point, Point> (bbox)
51  {}
52 
57  {
58  this->invalidate();
59  }
60 
64  void invalidate ()
65  {
66  for (unsigned int i=0; i<LIBMESH_DIM; i++)
67  {
68  this->first(i) = std::numeric_limits<Real>::max();
69  this->second(i) = -std::numeric_limits<Real>::max();
70  }
71  }
72 
76  const Point & min() const
77  { return this->first; }
78 
79  Point & min()
80  { return this->first; }
81 
85  const Point & max() const
86  { return this->second; }
87 
88  Point & max()
89  { return this->second; }
90 
96  bool intersects (const BoundingBox &) const;
97 
112  bool intersects (const BoundingBox &, Real abstol) const;
113 
120 #ifdef LIBMESH_ENABLE_DEPRECATED
121  bool intersect (const BoundingBox & b) const
122  { libmesh_deprecated(); return this->intersects(b); }
123 #endif
124 
128  bool contains_point (const Point &) const;
129 
134  void intersect_with (const BoundingBox &);
135 
139  void union_with (const Point & p);
140 
145  void union_with (const BoundingBox &);
146 
153  Real signed_distance(const Point & p) const;
154 };
155 
156 
157 
158 // ------------------------------------------------------------
159 // BoundingBox class member functions
160 
161 inline
162 void
164 {
165  for (unsigned int i=0; i<LIBMESH_DIM; i++)
166  {
167  min()(i) = std::min(min()(i), p(i));
168  max()(i) = std::max(max()(i), p(i));
169  }
170 }
171 
172 } // namespace libMesh
173 
174 
175 #endif // LIBMESH_BOUNDING_BOX_H
bool contains_point(const Point &) const
Definition: bounding_box.C:135
BoundingBox(const std::pair< Point, Point > &bbox)
Definition: bounding_box.h:49
void intersect_with(const BoundingBox &)
Definition: bounding_box.C:165
bool intersects(const BoundingBox &) const
Definition: bounding_box.C:35
bool intersect(const BoundingBox &b) const
Definition: bounding_box.h:121
long double max(long double a, double b)
Real signed_distance(const Point &p) const
Definition: bounding_box.C:200
const Point & min() const
Definition: bounding_box.h:76
BoundingBox(const Point &new_min, const Point &new_max)
Definition: bounding_box.h:44
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void union_with(const Point &p)
Definition: bounding_box.h:163
const Point & max() const
Definition: bounding_box.h:85
long double min(long double a, double b)
A geometric point in (x,y,z) space.
Definition: point.h:38