Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
moab::BoundBox Class Reference

#include <BoundBox.hpp>

+ Collaboration diagram for moab::BoundBox:

Public Member Functions

 BoundBox ()
 
 BoundBox (const CartVect &min, const CartVect &max)
 
 BoundBox (const double *corners)
 
 BoundBox (std::vector< CartVect > points)
 
 BoundBox (const BoundBox &from)
 
 ~BoundBox ()
 
bool contains_point (const double *point, const double tol=0.0) const
 
bool intersects_box (const BoundBox &b, const double tol=0.0) const
 
void compute_center (CartVect &center)
 
void update (const BoundBox &other_box)
 
void update (const double *coords)
 
ErrorCode update (Interface &iface, const Range &elems, bool spherical=false, double radius=1.)
 
ErrorCode update (Interface &iface, const EntityHandle ent, bool spherical=false, double radius=1.)
 
void update_min (const BoundBox &other_box)
 
void update_min (const double *coords)
 
void update_max (const BoundBox &other_box)
 
void update_max (const double *coords)
 
ErrorCode get (double *coords)
 
void update_box_spherical_elem (const CartVect *coordverts, int len, double radius)
 
double diagonal_length () const
 Return the diagonal length of this box. More...
 
double diagonal_squared () const
 Return the square of the diagonal length of this box. More...
 
double distance_squared (const double *from_point) const
 Return square of distance from box, or zero if inside. More...
 
double distance (const double *from_point) const
 Return distance from box, or zero if inside. More...
 
BoundBoxoperator= (const BoundBox &from)
 
bool operator== (const BoundBox &box) const
 

Public Attributes

CartVect bMin
 
CartVect bMax
 

Detailed Description

Definition at line 12 of file BoundBox.hpp.

Constructor & Destructor Documentation

◆ BoundBox() [1/5]

moab::BoundBox::BoundBox ( )
inline

Definition at line 15 of file BoundBox.hpp.

15 : bMin( DBL_MAX ), bMax( -DBL_MAX ) {}

◆ BoundBox() [2/5]

moab::BoundBox::BoundBox ( const CartVect min,
const CartVect max 
)
inline

Definition at line 16 of file BoundBox.hpp.

16 : bMin( min ), bMax( max ) {}

◆ BoundBox() [3/5]

moab::BoundBox::BoundBox ( const double *  corners)
inline

Definition at line 79 of file BoundBox.hpp.

80 {
81  // relies on CartVect being Plain Old Data, no virtual table
82  double* arr = bMin.array();
83  for( int i = 0; i < 6; i++ )
84  arr[i] = corners[i];
85 }

References moab::CartVect::array(), and bMin.

◆ BoundBox() [4/5]

moab::BoundBox::BoundBox ( std::vector< CartVect points)
inline

Definition at line 19 of file BoundBox.hpp.

19  : bMin( DBL_MAX ), bMax( -DBL_MAX )
20  {
21  for( size_t i = 0; i < points.size(); i++ )
22  {
23  update_min( points[i].array() );
24  update_max( points[i].array() );
25  }
26  }

References update_max(), and update_min().

◆ BoundBox() [5/5]

moab::BoundBox::BoundBox ( const BoundBox from)
inline

Definition at line 27 of file BoundBox.hpp.

27 : bMin( from.bMin ), bMax( from.bMax ) {}

◆ ~BoundBox()

moab::BoundBox::~BoundBox ( )
inline

Definition at line 29 of file BoundBox.hpp.

29 {}

Member Function Documentation

◆ compute_center()

void moab::BoundBox::compute_center ( CartVect center)
inline

Definition at line 153 of file BoundBox.hpp.

154 {
155  center = 0.5 * ( bMin + bMax );
156 }

References bMax, bMin, and center().

◆ contains_point()

bool moab::BoundBox::contains_point ( const double *  point,
const double  tol = 0.0 
) const
inline

Definition at line 87 of file BoundBox.hpp.

88 {
89  if( point[0] < bMin[0] - tol || point[0] > bMax[0] + tol || point[1] < bMin[1] - tol || point[1] > bMax[1] + tol ||
90  point[2] < bMin[2] - tol || point[2] > bMax[2] + tol )
91  return false;
92  else
93  return true;
94 }

References bMax, and bMin.

Referenced by moab::AdaptiveKDTree::distance_search(), moab::Element::Map::inside_box(), moab::AdaptiveKDTree::point_search(), and moab::BVHTree::point_search().

◆ diagonal_length()

double moab::BoundBox::diagonal_length ( ) const
inline

Return the diagonal length of this box.

Definition at line 192 of file BoundBox.hpp.

193 {
194  if( DBL_MAX == bMax[0] || DBL_MAX == bMax[1] || DBL_MAX == bMax[2] || DBL_MAX == bMin[0] || DBL_MAX == bMin[1] ||
195  DBL_MAX == bMin[2] )
196  return DBL_MAX;
197  return ( bMax - bMin ).length();
198 }

References bMax, and bMin.

Referenced by moab::LloydSmoother::perform_smooth(), and moab::Coupler::test_local_box().

◆ diagonal_squared()

double moab::BoundBox::diagonal_squared ( ) const
inline

Return the square of the diagonal length of this box.

Definition at line 200 of file BoundBox.hpp.

201 {
202  if( DBL_MAX == bMax[0] || DBL_MAX == bMax[1] || DBL_MAX == bMax[2] || DBL_MAX == bMin[0] || DBL_MAX == bMin[1] ||
203  DBL_MAX == bMin[2] )
204  return DBL_MAX;
205  return ( bMax - bMin ).length_squared();
206 }

References bMax, and bMin.

◆ distance()

double moab::BoundBox::distance ( const double *  from_point) const
inline

Return distance from box, or zero if inside.

Parameters
from_pointPoint from which you want distance

Definition at line 186 of file BoundBox.hpp.

187 {
188  double dist_sq = distance_squared( from_point );
189  return sqrt( dist_sq );
190 }

References distance_squared().

Referenced by moab::Coupler::locate_points().

◆ distance_squared()

double moab::BoundBox::distance_squared ( const double *  from_point) const
inline

Return square of distance from box, or zero if inside.

Parameters
from_pointPoint from which you want distance_sq

Definition at line 173 of file BoundBox.hpp.

174 {
175  double dist_sq = 0.0;
176  for( int i = 0; i < 3; ++i )
177  {
178  if( from_point[i] < bMin[i] )
179  dist_sq += ( bMin[i] - from_point[i] ) * ( bMin[i] - from_point[i] );
180  else if( from_point[i] > bMax[i] )
181  dist_sq += ( bMax[i] - from_point[i] ) * ( bMax[i] - from_point[i] );
182  }
183  return dist_sq;
184 }

References bMax, and bMin.

Referenced by distance(), and moab::BVHTree::distance_search().

◆ get()

ErrorCode moab::BoundBox::get ( double *  coords)
inline

Definition at line 146 of file BoundBox.hpp.

147 {
148  bMin.get( coords );
149  bMax.get( coords + 3 );
150  return MB_SUCCESS;
151 }

References bMax, bMin, moab::CartVect::get(), and MB_SUCCESS.

◆ intersects_box()

bool moab::BoundBox::intersects_box ( const BoundBox b,
const double  tol = 0.0 
) const
inline

Definition at line 96 of file BoundBox.hpp.

97 {
98  if( b.bMax[0] < bMin[0] - tol || b.bMin[0] > bMax[0] + tol || b.bMax[1] < bMin[1] - tol ||
99  b.bMin[1] > bMax[1] + tol || b.bMax[2] < bMin[2] - tol || b.bMin[2] > bMax[2] + tol )
100  return false;
101 
102  else
103  return true;
104 }

References bMax, and bMin.

Referenced by moab::BVHTree::build_tree(), moab::BVHTree::establish_buckets(), moab::BVHTree::find_split(), moab::BVHTree::initialize_splits(), moab::BVHTree::local_build_tree(), and moab::BVHTree::median_order().

◆ operator=()

BoundBox& moab::BoundBox::operator= ( const BoundBox from)
inline

Definition at line 65 of file BoundBox.hpp.

66  {
67  bMin = from.bMin;
68  bMax = from.bMax;
69  return *this;
70  }

References bMax, and bMin.

◆ operator==()

bool moab::BoundBox::operator== ( const BoundBox box) const
inline

Definition at line 71 of file BoundBox.hpp.

72  {
73  return ( bMin == box.bMin && bMax == box.bMax );
74  }

References bMax, and bMin.

◆ update() [1/4]

◆ update() [2/4]

void moab::BoundBox::update ( const double *  coords)
inline

Definition at line 112 of file BoundBox.hpp.

113 {
114  update_min( coords );
115  update_max( coords + 3 );
116 }

References update_max(), and update_min().

◆ update() [3/4]

ErrorCode moab::BoundBox::update ( Interface iface,
const EntityHandle  ent,
bool  spherical = false,
double  radius = 1. 
)
inline

Definition at line 167 of file BoundBox.hpp.

168 {
169  Range tmp_range( ent, ent );
170  return update( iface, tmp_range, spherical, radius );
171 }

References iface, and update().

◆ update() [4/4]

ErrorCode moab::BoundBox::update ( Interface iface,
const Range elems,
bool  spherical = false,
double  radius = 1. 
)

Definition at line 9 of file BoundBox.cpp.

10 {
11  ErrorCode rval;
12  bMin = CartVect( HUGE_VAL );
13  bMax = CartVect( -HUGE_VAL );
14 
15  CartVect coords;
16  EntityHandle const *conn = NULL, *conn2 = NULL;
17  int len = 0, len2 = 0;
18  Range::const_iterator i;
19  CartVect coordverts[27]; // maximum nodes per element supported by MOAB
20 
21  // vertices
22  const Range::const_iterator elem_begin = elems.lower_bound( MBEDGE );
23  for( i = elems.begin(); i != elem_begin; ++i )
24  {
25  rval = iface.get_coords( &*i, 1, coords.array() );
26  if( MB_SUCCESS != rval ) return rval;
27  update_min( coords.array() );
28  update_max( coords.array() );
29  }
30 
31  // elements with vertex-handle connectivity list
32  const Range::const_iterator poly_begin = elems.lower_bound( MBPOLYHEDRON, elem_begin );
33  std::vector< EntityHandle > dum_vector;
34  for( i = elem_begin; i != poly_begin; ++i )
35  {
36  rval = iface.get_connectivity( *i, conn, len, true, &dum_vector );
37  if( MB_SUCCESS != rval ) return rval;
38 
39  rval = iface.get_coords( conn, len, &( coordverts[0][0] ) );
40  if( MB_SUCCESS != rval ) return rval;
41  for( int j = 0; j < len; ++j )
42  {
43  update_min( coordverts[j].array() );
44  update_max( coordverts[j].array() );
45  }
46  // if spherical, use gnomonic projection to improve the computed box
47  // it is used now for coupling only
48  if( spherical ) update_box_spherical_elem( coordverts, len, radius );
49  }
50 
51  // polyhedra
52  const Range::const_iterator set_begin = elems.lower_bound( MBENTITYSET, poly_begin );
53  for( i = poly_begin; i != set_begin; ++i )
54  {
55  rval = iface.get_connectivity( *i, conn, len, true );
56  if( MB_SUCCESS != rval ) return rval;
57 
58  for( int j = 0; j < len; ++j )
59  {
60  rval = iface.get_connectivity( conn[j], conn2, len2 );
61  if( MB_SUCCESS != rval ) return rval;
62  rval = iface.get_coords( conn2, len2, &( coordverts[0][0] ) );
63  if( MB_SUCCESS != rval ) return rval;
64  for( int k = 0; k < len2; ++k )
65  {
66  update_min( coordverts[k].array() );
67  update_max( coordverts[k].array() );
68  }
69  }
70  }
71 
72  // sets
73  BoundBox box;
74  for( i = set_begin; i != elems.end(); ++i )
75  {
76  Range tmp_elems;
77  rval = iface.get_entities_by_handle( *i, tmp_elems );
78  if( MB_SUCCESS != rval ) return rval;
79  rval = box.update( iface, tmp_elems, spherical, radius );
80  if( MB_SUCCESS != rval ) return rval;
81 
82  update( box );
83  }
84 
85  return MB_SUCCESS;
86 }

References moab::CartVect::array(), moab::Range::begin(), bMax, bMin, moab::Range::end(), ErrorCode, iface, moab::Range::lower_bound(), MB_SUCCESS, MBEDGE, MBENTITYSET, MBPOLYHEDRON, update(), update_box_spherical_elem(), update_max(), and update_min().

◆ update_box_spherical_elem()

void moab::BoundBox::update_box_spherical_elem ( const CartVect coordverts,
int  len,
double  radius 
)

in case of spherical elements, account for curvature if needed

Definition at line 87 of file BoundBox.cpp.

88 {
89  // decide first the gnomonic plane, based on first coordinate
90  int plane = -1;
91  CartVect pos;
92  IntxUtils::decide_gnomonic_plane( verts[0], plane );
93  double in_plane_positions[20]; // at most polygons with 10 edges; do we need to revise this?
94  for( int i = 0; i < len && i < 10; i++ )
95  IntxUtils::gnomonic_projection( verts[i], R, plane, in_plane_positions[2 * i], in_plane_positions[2 * i + 1] );
96  // look for points on the intersection between edges in gnomonic plane and coordinate axes
97  // if yes, reverse projection of intx point, and update box
98  double oriented_area2 = 0;
99  // if oriented area is != zero, it means the origin is inside the polygon, so we need to upgrade
100  // the box with the origin, so we do not miss anything (the top of the dome)
101  for( int i = 0; i < len; i++ )
102  {
103  int i1 = ( i + 1 ) % len; // next vertex in polygon
104  // check intx with x axis
105  double ax = in_plane_positions[2 * i], ay = in_plane_positions[2 * i + 1];
106  double bx = in_plane_positions[2 * i1], by = in_plane_positions[2 * i1 + 1];
107  if( ay * by < 0 ) // it intersects with x axis
108  {
109  double alfa = ay / ( ay - by );
110  double xintx = ax + alfa * ( bx - ax );
111  IntxUtils::reverse_gnomonic_projection( xintx, 0, R, plane, pos );
112  update_min( pos.array() );
113  update_max( pos.array() );
114  }
115  if( ax * bx < 0 ) // it intersects with y axis
116  {
117  double alfa = ax / ( ax - bx );
118  double yintx = ay + alfa * ( by - ay );
119  IntxUtils::reverse_gnomonic_projection( 0, yintx, R, plane, pos );
120  update_min( pos.array() );
121  update_max( pos.array() );
122  }
123  oriented_area2 += ( ax * by - ay * bx );
124  }
125  if( fabs( oriented_area2 ) > R * R * 1.e-6 ) // origin is in the interior, add the center
126  {
127  IntxUtils::reverse_gnomonic_projection( 0, 0, R, plane, pos );
128  update_min( pos.array() );
129  update_max( pos.array() );
130  }
131 }

References moab::CartVect::array(), moab::IntxUtils::decide_gnomonic_plane(), moab::IntxUtils::gnomonic_projection(), moab::R, moab::IntxUtils::reverse_gnomonic_projection(), update_max(), and update_min().

Referenced by update().

◆ update_max() [1/2]

void moab::BoundBox::update_max ( const BoundBox other_box)
inline

Definition at line 132 of file BoundBox.hpp.

133 {
134  bMax[0] = std::max( bMax[0], other_box.bMax[0] );
135  bMax[1] = std::max( bMax[1], other_box.bMax[1] );
136  bMax[2] = std::max( bMax[2], other_box.bMax[2] );
137 }

References bMax.

Referenced by BoundBox(), update(), and update_box_spherical_elem().

◆ update_max() [2/2]

void moab::BoundBox::update_max ( const double *  coords)
inline

Definition at line 139 of file BoundBox.hpp.

140 {
141  bMax[0] = std::max( bMax[0], coords[0] );
142  bMax[1] = std::max( bMax[1], coords[1] );
143  bMax[2] = std::max( bMax[2], coords[2] );
144 }

References bMax.

◆ update_min() [1/2]

void moab::BoundBox::update_min ( const BoundBox other_box)
inline

Definition at line 118 of file BoundBox.hpp.

119 {
120  bMin[0] = std::min( bMin[0], other_box.bMin[0] );
121  bMin[1] = std::min( bMin[1], other_box.bMin[1] );
122  bMin[2] = std::min( bMin[2], other_box.bMin[2] );
123 }

References bMin.

Referenced by BoundBox(), update(), and update_box_spherical_elem().

◆ update_min() [2/2]

void moab::BoundBox::update_min ( const double *  coords)
inline

Definition at line 125 of file BoundBox.hpp.

126 {
127  bMin[0] = std::min( bMin[0], coords[0] );
128  bMin[1] = std::min( bMin[1], coords[1] );
129  bMin[2] = std::min( bMin[2], coords[2] );
130 }

References bMin.

Member Data Documentation

◆ bMax

◆ bMin


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