libMesh
bounding_box.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 
61  /*
62  * Sets the bounding box to encompass the universe.
63  */
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 
73  /*
74  * \returns A point at the minimum x,y,z coordinates of the box.
75  */
76  const Point & min() const
77  { return this->first; }
78 
79  Point & min()
80  { return this->first; }
81 
82  /*
83  * \returns A point at the maximum x,y,z coordinates of the box.
84  */
85  const Point & max() const
86  { return this->second; }
87 
88  Point & max()
89  { return this->second; }
90 
91  /*
92  * \returns \p true if the other bounding box has a non-empty
93  * intersection with this bounding box.
94  */
95  bool intersects (const BoundingBox &) const;
96 
103 #ifdef LIBMESH_ENABLE_DEPRECATED
104  bool intersect (const BoundingBox & b) const
105  { libmesh_deprecated(); return this->intersects(b); }
106 #endif
107 
108  /*
109  * \returns \p true if the bounding box contains the given point.
110  */
111  bool contains_point (const Point &) const;
112 
113  /*
114  * Sets this bounding box to be the intersection with the other
115  * bounding box.
116  */
117  void intersect_with (const BoundingBox &);
118 
119  /*
120  * Enlarges this bounding box to include the given point
121  */
122  void union_with (const Point & p);
123 
124  /*
125  * Sets this bounding box to be the union with the other
126  * bounding box.
127  */
128  void union_with (const BoundingBox &);
129 
130 private:
131 };
132 
133 
134 
135 // ------------------------------------------------------------
136 // BoundingBox class member functions
137 
138 inline
139 void
141 {
142  for (unsigned int i=0; i<LIBMESH_DIM; i++)
143  {
144  min()(i) = std::min(min()(i), p(i));
145  max()(i) = std::max(max()(i), p(i));
146  }
147 }
148 
149 } // namespace libMesh
150 
151 
152 #endif // LIBMESH_BOUNDING_BOX_H
bool contains_point(const Point &) const
Definition: bounding_box.C:73
BoundingBox()
Default constructor sets invalid bounds.
Definition: bounding_box.h:56
bool intersects(const BoundingBox &) const
Definition: bounding_box.C:33
BoundingBox(const std::pair< Point, Point > &bbox)
Definition: bounding_box.h:49
void intersect_with(const BoundingBox &)
Definition: bounding_box.C:103
const Point & max() const
Definition: bounding_box.h:85
The libMesh namespace provides an interface to certain functionality in the library.
long double max(long double a, double b)
bool intersect(const BoundingBox &b) const
Definition: bounding_box.h:104
const Point & min() const
Definition: bounding_box.h:76
BoundingBox(const Point &new_min, const Point &new_max)
Definition: bounding_box.h:44
Defines a Cartesian bounding box by the two corner extremum.
Definition: bounding_box.h:40
void union_with(const Point &p)
Definition: bounding_box.h:140
long double min(long double a, double b)
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38