moab
moab::BoundBox Class Reference

#include <BoundBox.hpp>

List of all members.

Public Member Functions

 BoundBox ()
 BoundBox (const CartVect &min, const CartVect &max)
 BoundBox (const double *corners)
 ~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)
ErrorCode update (Interface &iface, const EntityHandle ent)
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)
double diagonal_length () const
 Return the diagonal length of this box.
double diagonal_squared () const
 Return the square of the diagonal length of this box.
double distance_squared (const double *from_point) const
 Return square of distance from box, or zero if inside.
double distance (const double *from_point) const
 Return distance from box, or zero if inside.
BoundBoxoperator= (const BoundBox &from)
bool operator== (const BoundBox &box) const

Public Attributes

CartVect bMin
CartVect bMax

Detailed Description

Examples:
DeformMeshRemap.cpp.

Definition at line 11 of file BoundBox.hpp.


Constructor & Destructor Documentation

Definition at line 13 of file BoundBox.hpp.

: bMin(DBL_MAX), bMax(-DBL_MAX) {}
moab::BoundBox::BoundBox ( const CartVect min,
const CartVect max 
) [inline]

Definition at line 14 of file BoundBox.hpp.

                                                         : 
              bMin(min), bMax(max) {}
moab::BoundBox::BoundBox ( const double *  corners) [inline]

Definition at line 62 of file BoundBox.hpp.

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

Definition at line 17 of file BoundBox.hpp.

{}

Member Function Documentation

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

Definition at line 134 of file BoundBox.hpp.

                                                        {
      center = 0.5 * (bMin + bMax);
    }
bool moab::BoundBox::contains_point ( const double *  point,
const double  tol = 0.0 
) const [inline]

Definition at line 70 of file BoundBox.hpp.

                                                                                    {
      if (point[0] < bMin[0]-tol || point[0] > bMax[0]+tol ||
          point[1] < bMin[1]-tol || point[1] > bMax[1]+tol ||
          point[2] < bMin[2]-tol || point[2] > bMax[2]+tol)
        return false;
      else return true;
    }
double moab::BoundBox::diagonal_length ( ) const [inline]

Return the diagonal length of this box.

Definition at line 170 of file BoundBox.hpp.

    {
      if (DBL_MAX == bMax[0] || DBL_MAX == bMax[1] || DBL_MAX == bMax[2] ||
          DBL_MAX == bMin[0] || DBL_MAX == bMin[1] || DBL_MAX == bMin[2]) return DBL_MAX;
      return (bMax - bMin).length();
    }
double moab::BoundBox::diagonal_squared ( ) const [inline]

Return the square of the diagonal length of this box.

Definition at line 177 of file BoundBox.hpp.

    {
      if (DBL_MAX == bMax[0] || DBL_MAX == bMax[1] || DBL_MAX == bMax[2] ||
          DBL_MAX == bMin[0] || DBL_MAX == bMin[1] || DBL_MAX == bMin[2]) return DBL_MAX;
      return (bMax - bMin).length_squared();
    }
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 164 of file BoundBox.hpp.

    {
      double dist_sq = distance_squared(from_point);
      return sqrt(dist_sq);
    }
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 152 of file BoundBox.hpp.

    {
      double dist_sq = 0.0;
      for (int i = 0; i < 3; ++i) {
        if (from_point[i] < bMin[i])
          dist_sq += (bMin[i] - from_point[i]) * (bMin[i] - from_point[i]);
        else if (from_point[i] > bMax[i]) 
          dist_sq += (bMax[i] - from_point[i]) * (bMax[i] - from_point[i]);
      }
      return dist_sq;
    }
ErrorCode moab::BoundBox::get ( double *  coords) [inline]

Definition at line 127 of file BoundBox.hpp.

    {
      bMin.get(coords);
      bMax.get(coords+3);
      return MB_SUCCESS;
    }
bool moab::BoundBox::intersects_box ( const BoundBox b,
const double  tol = 0.0 
) const [inline]

Definition at line 78 of file BoundBox.hpp.

                                                                                  {
      if (b.bMax[0] < bMin[0]-tol || b.bMin[0] > bMax[0]+tol ||
          b.bMax[1] < bMin[1]-tol || b.bMin[1] > bMax[1]+tol ||
          b.bMax[2] < bMin[2]-tol || b.bMin[2] > bMax[2]+tol) 
        return false;

      else return true;
    }
BoundBox& moab::BoundBox::operator= ( const BoundBox from) [inline]

Definition at line 50 of file BoundBox.hpp.

                                                {
        bMin = from.bMin;
        bMax = from.bMax;
        return *this;
      }
bool moab::BoundBox::operator== ( const BoundBox box) const [inline]

Definition at line 55 of file BoundBox.hpp.

                                                        {
        return (bMin == box.bMin && bMax == box.bMax);
      }
void moab::BoundBox::update ( const BoundBox other_box) [inline]
Examples:
DeformMeshRemap.cpp.

Definition at line 87 of file BoundBox.hpp.

    {
      update_min(other_box);
      update_max(other_box);
    }
void moab::BoundBox::update ( const double *  coords) [inline]

Definition at line 93 of file BoundBox.hpp.

    {
      update_min(coords);
      update_max(coords+3);
    }
ErrorCode moab::BoundBox::update ( Interface iface,
const Range elems 
)

Definition at line 6 of file BoundBox.cpp.

    {
      ErrorCode rval;
      bMin = CartVect(HUGE_VAL);
      bMax = CartVect(-HUGE_VAL);
      
      CartVect coords;
      EntityHandle const *conn, *conn2;
      int len, len2;
      Range::const_iterator i;
  
        // vertices
      const Range::const_iterator elem_begin = elems.lower_bound( MBEDGE );
      for (i = elems.begin(); i != elem_begin; ++i) {
        rval = iface.get_coords( &*i, 1, coords.array() );
        if (MB_SUCCESS != rval)
          return rval;
        update_min(coords.array());
        update_max(coords.array());
      }

        // elements with vertex-handle connectivity list
      const Range::const_iterator poly_begin = elems.lower_bound( MBPOLYHEDRON, elem_begin );
      std::vector<EntityHandle> dum_vector;
      for (i = elem_begin; i != poly_begin; ++i) {
        rval = iface.get_connectivity( *i, conn, len, true, &dum_vector);
        if (MB_SUCCESS != rval)
          return rval;

        for (int j = 0; j < len; ++j) {
          rval = iface.get_coords( conn+j, 1, coords.array() );
          if (MB_SUCCESS != rval)
            return rval;
          update_min(coords.array());
          update_max(coords.array());
        }
      }
  
        // polyhedra
      const Range::const_iterator set_begin  = elems.lower_bound( MBENTITYSET, poly_begin );
      for (i = poly_begin; i != set_begin; ++i) {
        rval = iface.get_connectivity( *i, conn, len, true );
        if (MB_SUCCESS != rval)
          return rval;

        for (int j = 0; j < len; ++j) {
          rval = iface.get_connectivity( conn[j], conn2, len2 );
          for (int k = 0; k < len2; ++k) {
            rval = iface.get_coords( conn2+k, 1, coords.array() );
            if (MB_SUCCESS != rval)
              return rval;
            update_min(coords.array());
            update_max(coords.array());
          }
        }
      }
  
        // sets
      BoundBox box;
      for (i = set_begin; i != elems.end(); ++i) {
        Range tmp_elems;
        rval = iface.get_entities_by_handle(*i, tmp_elems);
        if (MB_SUCCESS != rval) return rval;
        rval = box.update(iface, tmp_elems);
        if (MB_SUCCESS != rval) return rval;

        update(box);
      }
  
      return MB_SUCCESS;
    }
ErrorCode moab::BoundBox::update ( Interface iface,
const EntityHandle  ent 
) [inline]

Definition at line 146 of file BoundBox.hpp.

    {
      Range tmp_range(ent, ent);
      return update(iface, tmp_range);
    }
void moab::BoundBox::update_max ( const BoundBox other_box) [inline]

Definition at line 113 of file BoundBox.hpp.

    {
      bMax[0] = std::max(bMax[0], other_box.bMax[0]);
      bMax[1] = std::max(bMax[1], other_box.bMax[1]);
      bMax[2] = std::max(bMax[2], other_box.bMax[2]);
    }
void moab::BoundBox::update_max ( const double *  coords) [inline]

Definition at line 120 of file BoundBox.hpp.

    {
      bMax[0] = std::max(bMax[0], coords[0]);
      bMax[1] = std::max(bMax[1], coords[1]);
      bMax[2] = std::max(bMax[2], coords[2]);
    }
void moab::BoundBox::update_min ( const BoundBox other_box) [inline]

Definition at line 99 of file BoundBox.hpp.

    {
      bMin[0] = std::min(bMin[0], other_box.bMin[0]);
      bMin[1] = std::min(bMin[1], other_box.bMin[1]);
      bMin[2] = std::min(bMin[2], other_box.bMin[2]);
    }
void moab::BoundBox::update_min ( const double *  coords) [inline]

Definition at line 106 of file BoundBox.hpp.

    {
      bMin[0] = std::min(bMin[0], coords[0]);
      bMin[1] = std::min(bMin[1], coords[1]);
      bMin[2] = std::min(bMin[2], coords[2]);
    }

Member Data Documentation

Examples:
DeformMeshRemap.cpp.

Definition at line 59 of file BoundBox.hpp.

Examples:
DeformMeshRemap.cpp.

Definition at line 59 of file BoundBox.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines