MOAB: Mesh Oriented datABase  (version 5.4.1)
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.
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 12 of file BoundBox.hpp.


Constructor & Destructor Documentation

Definition at line 15 of file BoundBox.hpp.

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

Definition at line 16 of file BoundBox.hpp.

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

Definition at line 79 of file BoundBox.hpp.

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

{
    // 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];
}
moab::BoundBox::BoundBox ( std::vector< CartVect points) [inline]

Definition at line 19 of file BoundBox.hpp.

References update_max(), and update_min().

                                             : bMin( DBL_MAX ), bMax( -DBL_MAX )
    {
        for( size_t i = 0; i < points.size(); i++ )
        {
            update_min( points[i].array() );
            update_max( points[i].array() );
        }
    }
moab::BoundBox::BoundBox ( const BoundBox from) [inline]

Definition at line 27 of file BoundBox.hpp.

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

Definition at line 29 of file BoundBox.hpp.

{}

Member Function Documentation

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

Definition at line 153 of file BoundBox.hpp.

References bMax, and bMin.

Referenced by test_bound_box().

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

Definition at line 87 of file BoundBox.hpp.

References bMax, and bMin.

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

{
    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 192 of file BoundBox.hpp.

References bMax, and bMin.

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

{
    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 200 of file BoundBox.hpp.

References bMax, and bMin.

Referenced by test_bound_box().

{
    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 186 of file BoundBox.hpp.

References distance_squared().

Referenced by moab::Coupler::locate_points(), and test_bound_box().

{
    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 173 of file BoundBox.hpp.

References bMax, and bMin.

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

{
    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 146 of file BoundBox.hpp.

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

{
    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 96 of file BoundBox.hpp.

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(), moab::BVHTree::median_order(), and test_bound_box().

{
    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 65 of file BoundBox.hpp.

References bMax, and bMin.

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

Definition at line 71 of file BoundBox.hpp.

References bMax, and bMin.

    {
        return ( bMin == box.bMin && bMax == box.bMax );
    }
void moab::BoundBox::update ( const double *  coords) [inline]

Definition at line 112 of file BoundBox.hpp.

References update_max(), and update_min().

{
    update_min( coords );
    update_max( coords + 3 );
}
ErrorCode moab::BoundBox::update ( Interface iface,
const Range elems,
bool  spherical = false,
double  radius = 1. 
)

Definition at line 9 of file BoundBox.cpp.

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

{
    ErrorCode rval;
    bMin = CartVect( HUGE_VAL );
    bMax = CartVect( -HUGE_VAL );

    CartVect coords;
    EntityHandle const *conn = NULL, *conn2 = NULL;
    int len = 0, len2 = 0;
    Range::const_iterator i;
    CartVect coordverts[27];  // maximum nodes per element supported by MOAB

    // 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;

        rval = iface.get_coords( conn, len, &( coordverts[0][0] ) );
        if( MB_SUCCESS != rval ) return rval;
        for( int j = 0; j < len; ++j )
        {
            update_min( coordverts[j].array() );
            update_max( coordverts[j].array() );
        }
        // if spherical, use gnomonic projection to improve the computed box
        // it is used now for coupling only
        if( spherical ) update_box_spherical_elem( coordverts, len, radius );
    }

    // 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 );
            if( MB_SUCCESS != rval ) return rval;
            rval = iface.get_coords( conn2, len2, &( coordverts[0][0] ) );
            if( MB_SUCCESS != rval ) return rval;
            for( int k = 0; k < len2; ++k )
            {
                update_min( coordverts[k].array() );
                update_max( coordverts[k].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, spherical, radius );
        if( MB_SUCCESS != rval ) return rval;

        update( box );
    }

    return MB_SUCCESS;
}
ErrorCode moab::BoundBox::update ( Interface iface,
const EntityHandle  ent,
bool  spherical = false,
double  radius = 1. 
) [inline]

Definition at line 167 of file BoundBox.hpp.

References update().

{
    Range tmp_range( ent, ent );
    return update( iface, tmp_range, spherical, radius );
}
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.

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

Referenced by update().

{
    // decide first the gnomonic plane, based on first coordinate
    int plane = -1;
    CartVect pos;
    IntxUtils::decide_gnomonic_plane( verts[0], plane );
    double in_plane_positions[20];  // at most polygons with 10 edges; do we need to revise this?
    for( int i = 0; i < len && i < 10; i++ )
        IntxUtils::gnomonic_projection( verts[i], R, plane, in_plane_positions[2 * i], in_plane_positions[2 * i + 1] );
    // look for points on the intersection between edges in gnomonic plane and coordinate axes
    // if yes, reverse projection of intx point, and update box
    double oriented_area2 = 0;
    // if oriented area is != zero, it means the origin is inside the polygon, so we need to upgrade
    // the box with the origin, so we do not miss anything (the top of the dome)
    for( int i = 0; i < len; i++ )
    {
        int i1 = ( i + 1 ) % len;  // next vertex in polygon
        // check intx with x axis
        double ax = in_plane_positions[2 * i], ay = in_plane_positions[2 * i + 1];
        double bx = in_plane_positions[2 * i1], by = in_plane_positions[2 * i1 + 1];
        if( ay * by < 0 )  // it intersects with x axis
        {
            double alfa  = ay / ( ay - by );
            double xintx = ax + alfa * ( bx - ax );
            IntxUtils::reverse_gnomonic_projection( xintx, 0, R, plane, pos );
            update_min( pos.array() );
            update_max( pos.array() );
        }
        if( ax * bx < 0 )  // it intersects with y axis
        {
            double alfa  = ax / ( ax - bx );
            double yintx = ay + alfa * ( by - ay );
            IntxUtils::reverse_gnomonic_projection( 0, yintx, R, plane, pos );
            update_min( pos.array() );
            update_max( pos.array() );
        }
        oriented_area2 += ( ax * by - ay * bx );
    }
    if( fabs( oriented_area2 ) > R * R * 1.e-6 )  // origin is in the interior, add the center
    {
        IntxUtils::reverse_gnomonic_projection( 0, 0, R, plane, pos );
        update_min( pos.array() );
        update_max( pos.array() );
    }
}
void moab::BoundBox::update_max ( const BoundBox other_box) [inline]

Definition at line 132 of file BoundBox.hpp.

References bMax.

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

{
    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 139 of file BoundBox.hpp.

References bMax.

{
    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 118 of file BoundBox.hpp.

References bMin.

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

{
    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 125 of file BoundBox.hpp.

References bMin.

{
    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

List of all members.


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