libMesh::MeshTools::BoundingBox Class Reference

#include <mesh_tools.h>

Inheritance diagram for libMesh::MeshTools::BoundingBox:

Public Member Functions

 BoundingBox (const Point &new_min, const Point &new_max)
 
 BoundingBox (const std::pair< Point, Point > &bbox)
 
 BoundingBox ()
 
void invalidate ()
 
const Pointmin () const
 
Pointmin ()
 
const Pointmax () const
 
Pointmax ()
 
bool intersects (const BoundingBox &) const
 
bool intersects (const BoundingBox &, Real abstol) const
 
bool intersect (const BoundingBox &b) const
 
bool contains_point (const Point &) const
 
void intersect_with (const BoundingBox &)
 
void union_with (const Point &p)
 
void union_with (const BoundingBox &)
 
Real signed_distance (const Point &p) const
 

Detailed Description

Backwards compatibility with forward declarations.

Deprecated:
Use libMesh::BoundingBox instead.

Definition at line 70 of file mesh_tools.h.

Constructor & Destructor Documentation

◆ BoundingBox() [1/3]

libMesh::MeshTools::BoundingBox::BoundingBox ( const Point new_min,
const Point new_max 
)
inline

Definition at line 73 of file mesh_tools.h.

74  :
75  libMesh::BoundingBox(new_min, new_max) {
76  libmesh_deprecated(); // Switch to libMesh::BoundingBox
77  }

◆ BoundingBox() [2/3]

libMesh::MeshTools::BoundingBox::BoundingBox ( const std::pair< Point, Point > &  bbox)
inline

Definition at line 79 of file mesh_tools.h.

79  :
80  libMesh::BoundingBox(bbox) {
81  libmesh_deprecated(); // Switch to libMesh::BoundingBox
82  }

◆ BoundingBox() [3/3]

libMesh::MeshTools::BoundingBox::BoundingBox ( )
inline

Definition at line 84 of file mesh_tools.h.

84  {
85  libmesh_deprecated(); // Switch to libMesh::BoundingBox
86  }

Member Function Documentation

◆ contains_point()

bool libMesh::BoundingBox::contains_point ( const Point p) const
inherited
Returns
true if the bounding box contains the given point.

Definition at line 135 of file bounding_box.C.

References libMesh::is_between(), and libMesh::Real.

Referenced by libMesh::BoundingBox::signed_distance().

136 {
137  // Make local variables first to make things more clear in a moment
138  Real my_min_x = this->first(0);
139  Real my_max_x = this->second(0);
140  bool x_int = is_between(my_min_x, p(0), my_max_x);
141 
142  bool intersection_true = x_int;
143 
144 #if LIBMESH_DIM > 1
145  Real my_min_y = this->first(1);
146  Real my_max_y = this->second(1);
147  bool y_int = is_between(my_min_y, p(1), my_max_y);
148 
149  intersection_true = intersection_true && y_int;
150 #endif
151 
152 
153 #if LIBMESH_DIM > 2
154  Real my_min_z = this->first(2);
155  Real my_max_z = this->second(2);
156  bool z_int = is_between(my_min_z, p(2), my_max_z);
157 
158  intersection_true = intersection_true && z_int;
159 #endif
160 
161  return intersection_true;
162 }
bool is_between(Real min, Real check, Real max)
Definition: bounding_box.C:30
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ intersect()

bool libMesh::BoundingBox::intersect ( const BoundingBox b) const
inlineinherited
Returns
true if the other bounding box has a non-empty intersection with this bounding box.
Deprecated:
Use the BoundingBox::intersects() function instead.

Definition at line 121 of file bounding_box.h.

References libMesh::BoundingBox::intersects().

122  { libmesh_deprecated(); return this->intersects(b); }
bool intersects(const BoundingBox &) const
Definition: bounding_box.C:35

◆ intersect_with()

void libMesh::BoundingBox::intersect_with ( const BoundingBox other_box)
inherited

Sets this bounding box to be the intersection with the other bounding box.

Definition at line 165 of file bounding_box.C.

References std::max(), and std::min().

166 {
167  this->first(0) = std::max(this->first(0), other_box.first(0));
168  this->second(0) = std::min(this->second(0), other_box.second(0));
169 
170 #if LIBMESH_DIM > 1
171  this->first(1) = std::max(this->first(1), other_box.first(1));
172  this->second(1) = std::min(this->second(1), other_box.second(1));
173 #endif
174 
175 #if LIBMESH_DIM > 2
176  this->first(2) = std::max(this->first(2), other_box.first(2));
177  this->second(2) = std::min(this->second(2), other_box.second(2));
178 #endif
179 }
long double max(long double a, double b)
long double min(long double a, double b)

◆ intersects() [1/2]

bool libMesh::BoundingBox::intersects ( const BoundingBox other_box) const
inherited
Returns
true if the other bounding box has a non-empty intersection with this bounding box. Exact floating point <= comparisons are performed.

Definition at line 35 of file bounding_box.C.

References libMesh::is_between(), and libMesh::Real.

Referenced by libMesh::TreeNode< N >::insert(), and libMesh::BoundingBox::intersect().

36 {
37  // Make local variables first to make things more clear in a moment
38  const Real & my_min_x = this->first(0);
39  const Real & my_max_x = this->second(0);
40  const Real & other_min_x = other_box.first(0);
41  const Real & other_max_x = other_box.second(0);
42 
43  const bool x_int = is_between(my_min_x, other_min_x, my_max_x) || is_between(my_min_x, other_max_x, my_max_x) ||
44  is_between(other_min_x, my_min_x, other_max_x) || is_between(other_min_x, my_max_x, other_max_x);
45 
46  bool intersection_true = x_int;
47 
48 #if LIBMESH_DIM > 1
49  const Real & my_min_y = this->first(1);
50  const Real & my_max_y = this->second(1);
51  const Real & other_min_y = other_box.first(1);
52  const Real & other_max_y = other_box.second(1);
53 
54  const bool y_int = is_between(my_min_y, other_min_y, my_max_y) || is_between(my_min_y, other_max_y, my_max_y) ||
55  is_between(other_min_y, my_min_y, other_max_y) || is_between(other_min_y, my_max_y, other_max_y);
56 
57  intersection_true = intersection_true && y_int;
58 #endif
59 
60 #if LIBMESH_DIM > 2
61  const Real & my_min_z = this->first(2);
62  const Real & my_max_z = this->second(2);
63  const Real & other_min_z = other_box.first(2);
64  const Real & other_max_z = other_box.second(2);
65 
66  const bool z_int = is_between(my_min_z, other_min_z, my_max_z) || is_between(my_min_z, other_max_z, my_max_z) ||
67  is_between(other_min_z, my_min_z, other_max_z) || is_between(other_min_z, my_max_z, other_max_z);
68 
69  intersection_true = intersection_true && z_int;
70 #endif
71 
72  return intersection_true;
73 }
bool is_between(Real min, Real check, Real max)
Definition: bounding_box.C:30
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ intersects() [2/2]

bool libMesh::BoundingBox::intersects ( const BoundingBox other_box,
Real  abstol 
) const
inherited
Returns
true if the other bounding box has a non-empty intersection with this bounding box. abstol is an absolute tolerance used to make "fuzzy" comparisons. abstol must be strictly > 0.0, and both BBoxes being compared are "inflated" by abstol in each direction, i.e. (xmin, ymin, zmin) -> (xmin - abstol, ymin - abstol, zmin - abstol) (xmax, ymax, zmax) -> (xmax + abstol, ymax + abstol, zmax + abstol) before the intersection comparisons are made. This approach can be helpful for detecting intersections between two degenerate (planar) bounding boxes that lie in nearly (to within abstol) the same plane and in certain situations should be considered intersecting.

Definition at line 75 of file bounding_box.C.

References libMesh::is_between(), and libMesh::Real.

77 {
78  // If you want to use abstol==0, you need to call the "exact"
79  // comparison version of the intersects() function.
80  libmesh_assert(abstol > 0.);
81 
82  // Make local variables first to make things more clear in a moment
83  const Real & my_min_x = this->first(0);
84  const Real & my_max_x = this->second(0);
85  const Real & ot_min_x = other_box.first(0);
86  const Real & ot_max_x = other_box.second(0);
87 
88  const bool x_int =
89  is_between(my_min_x - abstol, ot_min_x, my_max_x + abstol) ||
90  is_between(my_min_x - abstol, ot_max_x, my_max_x + abstol) ||
91  is_between(ot_min_x - abstol, my_min_x, ot_max_x + abstol) ||
92  is_between(ot_min_x - abstol, my_max_x, ot_max_x + abstol);
93 
94  bool intersection_true = x_int;
95 
96  if (!intersection_true)
97  return false;
98 
99 #if LIBMESH_DIM > 1
100  const Real & my_min_y = this->first(1);
101  const Real & my_max_y = this->second(1);
102  const Real & ot_min_y = other_box.first(1);
103  const Real & ot_max_y = other_box.second(1);
104 
105  const bool y_int =
106  is_between(my_min_y - abstol, ot_min_y, my_max_y + abstol) ||
107  is_between(my_min_y - abstol, ot_max_y, my_max_y + abstol) ||
108  is_between(ot_min_y - abstol, my_min_y, ot_max_y + abstol) ||
109  is_between(ot_min_y - abstol, my_max_y, ot_max_y + abstol);
110 
111  intersection_true = intersection_true && y_int;
112 
113  if (!intersection_true)
114  return false;
115 #endif
116 
117 #if LIBMESH_DIM > 2
118  const Real & my_min_z = this->first(2);
119  const Real & my_max_z = this->second(2);
120  const Real & ot_min_z = other_box.first(2);
121  const Real & ot_max_z = other_box.second(2);
122 
123  const bool z_int =
124  is_between(my_min_z - abstol, ot_min_z, my_max_z + abstol) ||
125  is_between(my_min_z - abstol, ot_max_z, my_max_z + abstol) ||
126  is_between(ot_min_z - abstol, my_min_z, ot_max_z + abstol) ||
127  is_between(ot_min_z - abstol, my_max_z, ot_max_z + abstol);
128 
129  intersection_true = intersection_true && z_int;
130 #endif
131 
132  return intersection_true;
133 }
bool is_between(Real min, Real check, Real max)
Definition: bounding_box.C:30
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ invalidate()

void libMesh::BoundingBox::invalidate ( )
inlineinherited

Sets the bounding box to encompass the universe.

Definition at line 64 of file bounding_box.h.

References std::max().

Referenced by libMesh::BoundingBox::BoundingBox().

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  }
long double max(long double a, double b)

◆ max() [1/2]

const Point& libMesh::BoundingBox::max ( ) const
inlineinherited
Returns
A point at the maximum x,y,z coordinates of the box.

Definition at line 85 of file bounding_box.h.

Referenced by libMesh::BoundingBox::union_with().

86  { return this->second; }

◆ max() [2/2]

Point& libMesh::BoundingBox::max ( )
inlineinherited

Definition at line 88 of file bounding_box.h.

89  { return this->second; }

◆ min() [1/2]

const Point& libMesh::BoundingBox::min ( ) const
inlineinherited
Returns
A point at the minimum x,y,z coordinates of the box.

Definition at line 76 of file bounding_box.h.

Referenced by libMesh::BoundingBox::union_with().

77  { return this->first; }

◆ min() [2/2]

Point& libMesh::BoundingBox::min ( )
inlineinherited

Definition at line 79 of file bounding_box.h.

80  { return this->first; }

◆ signed_distance()

Real libMesh::BoundingBox::signed_distance ( const Point p) const
inherited

Computes the signed distance, d, from a given Point p to this BoundingBox. The sign convention is: d > 0 if the point is outside the BoundingBox d <= 0 if the point is inside the Bounding Box

Definition at line 200 of file bounding_box.C.

References std::abs(), libMesh::BoundingBox::contains_point(), std::max(), std::min(), and libMesh::Real.

201 {
202  if (contains_point(p))
203  {
204  // Sign convention: if Point is inside the bbox, the distance is
205  // negative. We then find the smallest distance to the different
206  // sides of the box and return that.
208 
209  for (unsigned int dir=0; dir<LIBMESH_DIM; ++dir)
210  {
211  min_dist = std::min(min_dist, std::abs(p(dir) - second(dir)));
212  min_dist = std::min(min_dist, std::abs(p(dir) - first(dir)));
213  }
214 
215  return -min_dist;
216  }
217  else // p is outside the box
218  {
219  Real dx[3] = {0., 0., 0.};
220 
221  // Compute distance "above"/"below" the box in each
222  // direction. If the point is somewhere in between the (min,
223  // max) values of the box, dx is 0.
224  for (unsigned int dir=0; dir<LIBMESH_DIM; ++dir)
225  {
226  if (p(dir) > second(dir))
227  dx[dir] = p(dir) - second(dir);
228  else if (p(dir) < first(dir))
229  dx[dir] = p(dir) - first(dir);
230  }
231 
232  return std::sqrt(dx[0]*dx[0] + dx[1]*dx[1] + dx[2]*dx[2]);
233  }
234 }
double abs(double a)
bool contains_point(const Point &) const
Definition: bounding_box.C:135
long double max(long double a, double b)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
long double min(long double a, double b)

◆ union_with() [1/2]

void libMesh::BoundingBox::union_with ( const Point p)
inlineinherited

Enlarges this bounding box to include the given point

Definition at line 163 of file bounding_box.h.

References std::max(), libMesh::BoundingBox::max(), std::min(), and libMesh::BoundingBox::min().

Referenced by libMesh::Cell::loose_bounding_box().

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 }
long double max(long double a, double b)
const Point & min() const
Definition: bounding_box.h:76
const Point & max() const
Definition: bounding_box.h:85
long double min(long double a, double b)

◆ union_with() [2/2]

void libMesh::BoundingBox::union_with ( const BoundingBox other_box)
inherited

Sets this bounding box to be the union with the other bounding box.

Definition at line 182 of file bounding_box.C.

References std::max(), and std::min().

183 {
184  this->first(0) = std::min(this->first(0), other_box.first(0));
185  this->second(0) = std::max(this->second(0), other_box.second(0));
186 
187 #if LIBMESH_DIM > 1
188  this->first(1) = std::min(this->first(1), other_box.first(1));
189  this->second(1) = std::max(this->second(1), other_box.second(1));
190 #endif
191 
192 #if LIBMESH_DIM > 2
193  this->first(2) = std::min(this->first(2), other_box.first(2));
194  this->second(2) = std::max(this->second(2), other_box.second(2));
195 #endif
196 }
long double max(long double a, double b)
long double min(long double a, double b)

The documentation for this class was generated from the following file: