moab
moab::AxisBox Class Reference

Class representing axis-aligned bounding box. More...

#include <AxisBox.hpp>

List of all members.

Public Member Functions

 AxisBox ()
 AxisBox (const double *min, const double *max)
 AxisBox (const double *point)
AxisBoxoperator&= (const AxisBox &other)
AxisBoxoperator|= (const AxisBox &other)
AxisBoxoperator|= (const double *point)
const double * minimum () const
const double * maximum () const
double * minimum ()
double * maximum ()
void center (double *center_out) const
void diagonal (double *diagonal_out) const
bool intersects (const AxisBox &other, double tolerance) const
 Check if two boxes intersect.
bool intersects (const double *point, double tolerance) const
 Check if box contains point.
bool valid () const
 Check that box is valid.
void closest_position_within_box (const double *input_position, double *output_position) const
 Find closest position on/within box to input position.

Static Public Member Functions

static ErrorCode get_tag (Tag &tag_handle_out, Interface *interface, const char *tag_name=0)
static ErrorCode calculate (AxisBox &box_out, EntityHandle set, Interface *interface)
static ErrorCode calculate (AxisBox &box_out, const Range &elements, Interface *interface)

Private Attributes

double minVect [3]
double maxVect [3]

Detailed Description

Class representing axis-aligned bounding box.

Author:
Jason Kraftcheck ([email protected])
Date:
August, 2006

Definition at line 30 of file AxisBox.hpp.


Constructor & Destructor Documentation

moab::AxisBox::AxisBox ( ) [inline]

Definition at line 133 of file AxisBox.hpp.

{
  minVect[0] = minVect[1] = minVect[2] =  std::numeric_limits<double>::max();
  maxVect[0] = maxVect[1] = maxVect[2] = -std::numeric_limits<double>::max();
}
moab::AxisBox::AxisBox ( const double *  min,
const double *  max 
) [inline]

Definition at line 139 of file AxisBox.hpp.

{   
  minVect[0] = min[0];
  minVect[1] = min[1];
  minVect[2] = min[2];
  maxVect[0] = max[0];
  maxVect[1] = max[1];
  maxVect[2] = max[2];
}
moab::AxisBox::AxisBox ( const double *  point) [inline]

Definition at line 149 of file AxisBox.hpp.

{
  minVect[0] = maxVect[0] = point[0];
  minVect[1] = maxVect[1] = point[1];
  minVect[2] = maxVect[2] = point[2];
}

Member Function Documentation

ErrorCode moab::AxisBox::calculate ( AxisBox box_out,
EntityHandle  set,
Interface interface 
) [static]

Calculate a box bounding the entities contained in the passed set

Definition at line 48 of file AxisBox.cpp.

{
  Range range;
  ErrorCode rval = interface->get_entities_by_handle( set, range );
  if (MB_SUCCESS != rval)
    return rval;
  
  return calculate( box, range, interface );
}
ErrorCode moab::AxisBox::calculate ( AxisBox box_out,
const Range elements,
Interface interface 
) [static]

Calculate a box bounding the vertices/elements in the passed Range

Definition at line 60 of file AxisBox.cpp.

{
  ErrorCode rval;
  Range vertices;
  Range elements;
  
  elements.merge( entities.upper_bound(MBVERTEX), entities.lower_bound(MBENTITYSET) );
  rval = interface->get_adjacencies( elements, 0, false, vertices );
  if (MB_SUCCESS != rval)
    return rval;
  
  vertices.merge( entities.begin(), entities.upper_bound(MBVERTEX) );
  
  std::vector<double> coords( 3*vertices.size() );
  rval = interface->get_coords( vertices, &coords[0] );
  if (MB_SUCCESS != rval)
    return rval;
  
  box = AxisBox();
  std::vector<double>::const_iterator i = coords.begin();
  for (; i != coords.end(); i += 3)
    box |= &*i;
  
  return MB_SUCCESS;
}
void moab::AxisBox::center ( double *  center_out) const [inline]

Definition at line 189 of file AxisBox.hpp.

{
  center_out[0] = 0.5 * (minVect[0] + maxVect[0]);
  center_out[1] = 0.5 * (minVect[1] + maxVect[1]);
  center_out[2] = 0.5 * (minVect[2] + maxVect[2]);
}
void moab::AxisBox::closest_position_within_box ( const double *  input_position,
double *  output_position 
) const [inline]

Find closest position on/within box to input position.

Find the closest position in the solid box to the input position. If the input position is on or within the box, then the output position will be the same as the input position. If the input position is outside the box, the outside position will be the closest point on the box boundary to the input position.

Definition at line 233 of file AxisBox.hpp.

{
  for (int i = 0; i < 3; ++i) {
    if (input_position[i] < minVect[i])
      output_position[i] = minVect[i];
    else if (input_position[i] > maxVect[i])
      output_position[i] = maxVect[i];
    else
      output_position[i] = input_position[i];
  }
}
void moab::AxisBox::diagonal ( double *  diagonal_out) const [inline]

Definition at line 196 of file AxisBox.hpp.

{
  diagonal_out[0] = maxVect[0] - minVect[0];
  diagonal_out[1] = maxVect[1] - minVect[1];
  diagonal_out[2] = maxVect[2] - minVect[2];
}
ErrorCode moab::AxisBox::get_tag ( Tag tag_handle_out,
Interface interface,
const char *  tag_name = 0 
) [static]

Definition at line 32 of file AxisBox.cpp.

{
  assert( sizeof(AxisBox) == 6*sizeof(double) );
  
  if (!tagname)
    tagname = AXIS_BOX_TAG_NAME;
 
  return interface->tag_get_handle( tagname,
                                    sizeof(AxisBox),
                                    MB_TYPE_DOUBLE,
                                    tag_out,
                                    MB_TAG_DENSE|MB_TAG_CREAT|MB_TAG_BYTES );
}
bool moab::AxisBox::intersects ( const AxisBox other,
double  tolerance 
) const [inline]

Check if two boxes intersect.

Check if two boxes are within the specified tolerance of each other. If tolerance is less than zero, then boxes must overlap by at least the magnitude of the tolerance to be considered intersecting.

Definition at line 203 of file AxisBox.hpp.

{
  return minVect[0] - other.maxVect[0] <= tolerance &&
         minVect[1] - other.maxVect[1] <= tolerance &&
         minVect[2] - other.maxVect[2] <= tolerance &&
         other.minVect[0] - maxVect[0] <= tolerance &&
         other.minVect[1] - maxVect[1] <= tolerance &&
         other.minVect[2] - maxVect[2] <= tolerance;
}
bool moab::AxisBox::intersects ( const double *  point,
double  tolerance 
) const [inline]

Check if box contains point.

Check if a position is in or on the box, within the specified tolerance

Definition at line 214 of file AxisBox.hpp.

{
  return minVect[0] - point[0] <= tolerance &&
         minVect[1] - point[1] <= tolerance &&
         minVect[2] - point[2] <= tolerance &&
         maxVect[0] - point[0] <= tolerance &&
         maxVect[1] - point[1] <= tolerance &&
         maxVect[2] - point[2] <= tolerance;
}
const double* moab::AxisBox::maximum ( ) const [inline]

Definition at line 64 of file AxisBox.hpp.

{ return maxVect; }
double* moab::AxisBox::maximum ( ) [inline]

Definition at line 68 of file AxisBox.hpp.

{ return maxVect; }
const double* moab::AxisBox::minimum ( ) const [inline]

Definition at line 62 of file AxisBox.hpp.

{ return minVect; }
double* moab::AxisBox::minimum ( ) [inline]

Definition at line 66 of file AxisBox.hpp.

{ return minVect; }
AxisBox & moab::AxisBox::operator&= ( const AxisBox other) [inline]

intersect

Definition at line 156 of file AxisBox.hpp.

{
  for (int i = 0; i < 3; ++i) {
    if (minVect[i] < other.minVect[i])
      minVect[i] = other.minVect[i];
    if (maxVect[i] > other.maxVect[i])
      maxVect[i] = other.maxVect[i];
  }
  return *this;
}
AxisBox & moab::AxisBox::operator|= ( const AxisBox other) [inline]

unite

Definition at line 167 of file AxisBox.hpp.

{
  for (int i = 0; i < 3; ++i) {
    if (minVect[i] > other.minVect[i])
      minVect[i] = other.minVect[i];
    if (maxVect[i] < other.maxVect[i])
      maxVect[i] = other.maxVect[i];
  }
  return *this;
}
AxisBox & moab::AxisBox::operator|= ( const double *  point) [inline]

unite

Definition at line 178 of file AxisBox.hpp.

{
  for (int i = 0; i < 3; ++i) {
    if (minVect[i] > point[i])
      minVect[i] = point[i];
    if (maxVect[i] < point[i])
      maxVect[i] = point[i];
  }
  return *this;
}
bool moab::AxisBox::valid ( ) const [inline]

Check that box is valid.

Check that box is defined (contains at least a single point.)

Definition at line 226 of file AxisBox.hpp.

{
  return minVect[0] <= maxVect[0]
      && minVect[1] <= maxVect[1]
      && minVect[2] <= maxVect[2];
}

Member Data Documentation

double moab::AxisBox::maxVect[3] [private]

Definition at line 110 of file AxisBox.hpp.

double moab::AxisBox::minVect[3] [private]

Definition at line 110 of file AxisBox.hpp.


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