cgma
CubitBox Class Reference

#include <CubitBox.hpp>

List of all members.

Public Member Functions

 CubitBox ()
 CubitBox (const CubitVector &min, const CubitVector &max)
 CubitBox (const double min[3], const double max[3])
 CubitBox (const CubitVector &min_max)
 CubitBox (const CubitBox &copy_from)
 CubitBox (const CubitBoxStruct &from)
 CubitBox (const std::vector< CubitVector > &pts)
 ~CubitBox ()
CubitBoxbounding_box ()
void reset (const CubitVector &vector)
void reset (const CubitVector &min, const CubitVector &max)
void reset (const CubitBox &box)
void reset (const double min[3], const double max[3])
double max_x () const
double max_y () const
double max_z () const
double min_x () const
double min_y () const
double min_z () const
CubitVector minimum () const
CubitVector maximum () const
CubitVector center () const
CubitVector diagonal () const
void get_corners (CubitVector corners[8]) const
double x_range () const
double y_range () const
double z_range () const
double minimum_range (void)
double maximum_range (void)
bool overlap (double tolerance, const CubitBox &other_box) const
bool intersect (const CubitVector &ray_origin, const CubitVector &ray_direction, CubitVector &intersection_pt)
bool intersect (const CubitVector &ray_origin, const CubitVector &ray_direction)
CubitBoxoperator= (const CubitBox &box)
CubitBoxoperator|= (const CubitBox &box)
CubitBoxoperator|= (const CubitVector &vector)
CubitBoxoperator&= (const CubitBox &box)
CubitBoxoperator*= (double scale)
CubitBoxoperator/= (double scale)
CubitBoxoperator+= (const CubitVector &offset)
CubitBoxoperator-= (const CubitVector &offset)
int operator< (const CubitBox &box) const
int operator<= (const CubitBox &box) const
int operator> (const CubitBox &box) const
int operator>= (const CubitBox &box) const
int operator> (const CubitVector &vect) const
int operator>= (const CubitVector &vect) const
int operator<= (const CubitVector &vect) const
int operator&& (const CubitBox &box) const
int operator|| (const CubitBox &box) const
CubitBoxoperator= (const CubitBoxStruct &from)
 operator CubitBoxStruct ()
double distance_squared (const CubitVector &position) const
CubitVector closest_point (const CubitVector &position) const

Private Attributes

CubitVector minimum_
CubitVector maximum_

Friends

CUBIT_UTIL_EXPORT CubitBox operator| (const CubitBox &lhs, const CubitBox &rhs)
CUBIT_UTIL_EXPORT CubitBox operator| (const CubitBox &lhs, const CubitVector &rhs)
CUBIT_UTIL_EXPORT CubitBox operator& (const CubitBox &lhs, const CubitBox &rhs)
CUBIT_UTIL_EXPORT CubitBox operator* (const CubitBox &lhs, double rhs)
CUBIT_UTIL_EXPORT CubitBox operator* (double rhs, const CubitBox &lhs)
CUBIT_UTIL_EXPORT CubitBox operator/ (const CubitBox &lhs, double rhs)
CUBIT_UTIL_EXPORT CubitBox operator+ (const CubitBox &lhs, const CubitVector &rhs)
CUBIT_UTIL_EXPORT CubitBox operator- (const CubitBox &lhs, const CubitVector &rhs)

Detailed Description

Definition at line 18 of file CubitBox.hpp.


Constructor & Destructor Documentation

Definition at line 17 of file CubitBox.cpp.

                   :
    minimum_(0.0, 0.0, 0.0),
    maximum_(0.0, 0.0, 0.0)
{}
CubitBox::CubitBox ( const CubitVector min,
const CubitVector max 
)

Definition at line 22 of file CubitBox.cpp.

{
  minimum_.set (CUBIT_MIN (min.x(), max.x()),
                CUBIT_MIN (min.y(), max.y()),
                CUBIT_MIN (min.z(), max.z()));
  maximum_.set (CUBIT_MAX (min.x(), max.x()),
                CUBIT_MAX (min.y(), max.y()),
                CUBIT_MAX (min.z(), max.z()));
}
CubitBox::CubitBox ( const double  min[3],
const double  max[3] 
)

Definition at line 393 of file CubitBox.cpp.

{
  minimum_.set (CUBIT_MIN (min[0], max[0]),
                CUBIT_MIN (min[1], max[1]),
                CUBIT_MIN (min[2], max[2]));
  maximum_.set (CUBIT_MAX (min[0], max[0]),
                CUBIT_MAX (min[1], max[1]),
                CUBIT_MAX (min[2], max[2]));
}
CubitBox::CubitBox ( const CubitVector min_max)

Definition at line 32 of file CubitBox.cpp.

                                             :
    minimum_(min_max),
    maximum_(min_max)
{}
CubitBox::CubitBox ( const CubitBox copy_from)

Definition at line 37 of file CubitBox.cpp.

                                           :
    minimum_(copy_from.minimum_),
    maximum_(copy_from.maximum_)
{}
CubitBox::CubitBox ( const CubitBoxStruct from) [inline]

Definition at line 186 of file CubitBox.hpp.

{
  minimum_ = from.minimum_;
  maximum_ = from.maximum_;
}
CubitBox::CubitBox ( const std::vector< CubitVector > &  pts)

Definition at line 42 of file CubitBox.cpp.

{
  minimum_.set(0.0, 0.0, 0.0);
  maximum_.set(0.0, 0.0, 0.0);
  for ( size_t i=0; i<pts.size(); i++ )
  {
    double x = pts[i].x();
    double y = pts[i].y();
    double z = pts[i].z();
    minimum_.set(CUBIT_MIN(minimum_.x(), x),
                 CUBIT_MIN(minimum_.y(), y),
                 CUBIT_MIN(minimum_.z(), z));
    maximum_.set(CUBIT_MAX(maximum_.x(), x),
                 CUBIT_MAX(maximum_.y(), y),
                 CUBIT_MAX(maximum_.z(), z));
  }
}

Definition at line 14 of file CubitBox.cpp.

{}

Member Function Documentation

Definition at line 122 of file CubitBox.cpp.

{
  return CubitVector(minimum_ + maximum_) / 2.0;
}
CubitVector CubitBox::closest_point ( const CubitVector position) const

Definition at line 365 of file CubitBox.cpp.

{
  CubitVector result;
  
  if( point.x() < minimum_.x() )
    result.x( minimum_.x() );
  else if( point.x() > maximum_.x() )
    result.x( maximum_.x() );
  else
    result.x( point.x() );
  
  if( point.y() < minimum_.y() )
    result.y( minimum_.y() );
  else if( point.y() > maximum_.y() )
    result.y( maximum_.y() );
  else
    result.y( point.y() );
  
  if( point.z() < minimum_.z() )
    result.z( minimum_.z() );
  else if( point.z() > maximum_.z() )
    result.z( maximum_.z() );
  else
    result.z( point.z() );
  
  return result;
}

Definition at line 127 of file CubitBox.cpp.

{
  return CubitVector(maximum_ - minimum_);
}
double CubitBox::distance_squared ( const CubitVector position) const

Definition at line 349 of file CubitBox.cpp.

{
  return (point - closest_point(point)).length_squared();
}
void CubitBox::get_corners ( CubitVector  corners[8]) const

Definition at line 413 of file CubitBox.cpp.

{
  vectors[0] = minimum_;
  vectors[1] = CubitVector (maximum_.x(), minimum_.y(), minimum_.z());
  vectors[2] = CubitVector (maximum_.x(), maximum_.y(), minimum_.z());
  vectors[3] = CubitVector (minimum_.x(), maximum_.y(), minimum_.z());
  
  vectors[4] = CubitVector (minimum_.x(), minimum_.y(), maximum_.z());
  vectors[5] = CubitVector (maximum_.x(), minimum_.y(), maximum_.z());
  vectors[6] = maximum_;
  vectors[7] = CubitVector (minimum_.x(), maximum_.y(), maximum_.z());
}
bool CubitBox::intersect ( const CubitVector ray_origin,
const CubitVector ray_direction,
CubitVector intersection_pt 
)

Definition at line 548 of file CubitBox.cpp.

{
  bool inside = true;
  int quadrant[NUMDIM];
  register int i;
  int whichPlane;
  double maxT[NUMDIM];
  double candidatePlane[NUMDIM];

  /* Find candidate planes; this loop can be avoided if
  rays cast all from the eye(assume perpsective view) */
  for (i=0; i<NUMDIM; i++)
  {
    if((ray_origin)[i] < (this->minimum())[i])
    {
      quadrant[i] = LEFT;
      candidatePlane[i] = (this->minimum())[i];
      inside = false;
    }
    else if ( (ray_origin)[i] > (this->maximum())[i])
    {
      quadrant[i] = RIGHT;
      candidatePlane[i] = (this->maximum())[i];
      inside = false;
    }
    else    
    {
      quadrant[i] = MIDDLE;
    }
  }

  /* Ray origin inside bounding box */
  if(inside)
  {
    intersection_pt = ray_origin;
    return true;
  }

  /* Calculate T distances to candidate planes */
  for (i = 0; i < NUMDIM; i++)
  {
    if (quadrant[i] != MIDDLE && (ray_direction)[i] !=0.)
      maxT[i] = ( candidatePlane[i]-(ray_origin)[i]) / ((ray_direction)[i]);
    else
      maxT[i] = -1.;
  }

  /* Get largest of the maxT's for final choice of intersection */
  whichPlane = 0;
  for (i = 1; i < NUMDIM; i++)
  {
    if (maxT[whichPlane] < maxT[i])
      whichPlane = i;
  }

  /* Check final candidate actually inside box */
  double intersection_coords[3];

  if (maxT[whichPlane] < 0.)
    return false;

  for (i = 0; i < NUMDIM; i++)
  {
    if (whichPlane != i)
    {
      intersection_coords[i] = (ray_origin)[i] + maxT[whichPlane] * (ray_direction)[i];
      if (intersection_coords[i] < (this->minimum())[i] ||
          intersection_coords[i] > (this->maximum())[i])
        return false;
    }
    else
    {
      intersection_coords[i] = candidatePlane[i];
    }
  }

  return true;  /* ray hits box */
}
bool CubitBox::intersect ( const CubitVector ray_origin,
const CubitVector ray_direction 
)

Definition at line 476 of file CubitBox.cpp.

{
    double tNear=CUBIT_DBL_MIN;
    double tFar=CUBIT_DBL_MAX;

    for(int i=0;i<3;i++)
    {
        //X plane
        if(fabs(ray_direction[i])<=CUBIT_DBL_MIN)
        {
            //Ray parallel to x plane
            if(ray_origin[i]<this->minimum_[i] || ray_origin[i]>this->maximum_[i])
            {
                //Not between
                return false;
            }
            else
            {
                return true;
            }
        }

        double t1 = (this->minimum_[i] - ray_origin[i]) / ray_direction[i];
        double t2 = (this->maximum_[i] - ray_origin[i]) / ray_direction[i];

        if(t1>t2)
        {
            double temp=t1;
            t1=t2;
            t2=temp;
        }
        if(t1>tNear)
        {
            tNear=t1;
        }

        if(t2<tFar)
        {
            tFar=t2;
        }

        if(tNear>tFar)
        {
            return false;
        }

        if(tFar<0)
        {
            return false;
        }

    }

    return true;
}
double CubitBox::max_x ( ) const

Definition at line 92 of file CubitBox.cpp.

{
  return maximum_.x();
}
double CubitBox::max_y ( ) const

Definition at line 97 of file CubitBox.cpp.

{
  return maximum_.y();
}
double CubitBox::max_z ( ) const

Definition at line 102 of file CubitBox.cpp.

{
  return maximum_.z();
}

Definition at line 87 of file CubitBox.cpp.

{
  return CubitVector(maximum_);
}
double CubitBox::maximum_range ( void  )

Definition at line 138 of file CubitBox.cpp.

{
  return CUBIT_MAX( CUBIT_MAX( x_range(), y_range()), z_range());
}
double CubitBox::min_x ( ) const

Definition at line 107 of file CubitBox.cpp.

{
  return minimum_.x();
}
double CubitBox::min_y ( ) const

Definition at line 112 of file CubitBox.cpp.

{
  return minimum_.y();
}
double CubitBox::min_z ( ) const

Definition at line 117 of file CubitBox.cpp.

{
  return minimum_.z();
}

Definition at line 82 of file CubitBox.cpp.

{
  return CubitVector(minimum_);
}
double CubitBox::minimum_range ( void  )

Definition at line 132 of file CubitBox.cpp.

{
  return CUBIT_MIN(CUBIT_MIN( x_range(), y_range()), z_range());
}
CubitBox::operator CubitBoxStruct ( ) [inline]

Definition at line 144 of file CubitBox.hpp.

    {
      CubitBoxStruct to;
      to.minimum_ = minimum_;
      to.maximum_ = maximum_;
      return to;
    }
int CubitBox::operator&& ( const CubitBox box) const

Definition at line 426 of file CubitBox.cpp.

{
    // Return false if there is no overlap
    // along at least one of the 3 axes.
  if (minimum_.x() > box.maximum_.x() ||
      maximum_.x() < box.minimum_.x() ||
      minimum_.y() > box.maximum_.y() ||
      maximum_.y() < box.minimum_.y() ||
      minimum_.z() > box.maximum_.z() ||
      maximum_.z() < box.minimum_.z() )
    return CUBIT_FALSE;
  
    // If you didn't return false...
  return CUBIT_TRUE;
}
CubitBox & CubitBox::operator&= ( const CubitBox box)

Definition at line 204 of file CubitBox.cpp.

{
  minimum_.x(CUBIT_MAX(minimum_.x(), box.minimum_.x()));
  minimum_.y(CUBIT_MAX(minimum_.y(), box.minimum_.y()));
  minimum_.z(CUBIT_MAX(minimum_.z(), box.minimum_.z()));

  maximum_.x(CUBIT_MIN(maximum_.x(), box.maximum_.x()));
  maximum_.y(CUBIT_MIN(maximum_.y(), box.maximum_.y()));
  maximum_.z(CUBIT_MIN(maximum_.z(), box.maximum_.z()));

  if (minimum_.x() > maximum_.x() ||
      minimum_.y() > maximum_.y() ||
      minimum_.z() > maximum_.z())
  {
    minimum_.set(0.0, 0.0, 0.0);
    maximum_.set(0.0, 0.0, 0.0);
  }
  return *this;
}
CubitBox & CubitBox::operator*= ( double  scale)

Definition at line 224 of file CubitBox.cpp.

{
  CubitVector center_vec = center();
  *this -= center_vec;
  minimum_ *= scale;
  maximum_ *= scale;
  *this += center_vec;
  return *this;
}
CubitBox & CubitBox::operator+= ( const CubitVector offset)

Definition at line 243 of file CubitBox.cpp.

{
  minimum_ += offset;
  maximum_ += offset;
  return *this;
}
CubitBox & CubitBox::operator-= ( const CubitVector offset)

Definition at line 250 of file CubitBox.cpp.

{
  minimum_ -= offset;
  maximum_ -= offset;
  return *this;
}
CubitBox & CubitBox::operator/= ( double  scale)

Definition at line 234 of file CubitBox.cpp.

{
  if(scale == 0.0)
    throw ("Cannot Divide by Zero");
  //assert(scale != 0.0);
  *this *= 1/scale;
  return *this;
}
int CubitBox::operator< ( const CubitBox box) const

Definition at line 257 of file CubitBox.cpp.

{
  return (box.minimum_.x() < minimum_.x() &&
          box.minimum_.y() < minimum_.y() &&
          box.minimum_.z() < minimum_.z() &&
          box.maximum_.x() > maximum_.x() &&
          box.maximum_.y() > maximum_.y() &&
          box.maximum_.z() > maximum_.z());
}
int CubitBox::operator<= ( const CubitBox box) const

Definition at line 267 of file CubitBox.cpp.

{
  return (box.minimum_.x() <= minimum_.x() &&
          box.minimum_.y() <= minimum_.y() &&
          box.minimum_.z() <= minimum_.z() &&
          box.maximum_.x() >= maximum_.x() &&
          box.maximum_.y() >= maximum_.y() &&
          box.maximum_.z() >= maximum_.z());
}
int CubitBox::operator<= ( const CubitVector vect) const

Definition at line 458 of file CubitBox.cpp.

{
  return (vect.x() <= minimum_.x() ||
          vect.x() >= maximum_.x() ||
          vect.y() <= minimum_.y() ||
          vect.y() >= maximum_.y() ||
          vect.z() <= minimum_.z() ||
          vect.z() >= maximum_.z() );
}
CubitBox & CubitBox::operator= ( const CubitBox box)

Definition at line 152 of file CubitBox.cpp.

{
  if (this != &box)
    {
      minimum_ = box.minimum_;
      maximum_ = box.maximum_;
    }
  return *this;
}
CubitBox & CubitBox::operator= ( const CubitBoxStruct from) [inline]

Definition at line 179 of file CubitBox.hpp.

{
  minimum_ = from.minimum_;
  maximum_ = from.maximum_;
  return *this;
}
int CubitBox::operator> ( const CubitBox box) const

Definition at line 277 of file CubitBox.cpp.

{
  return (box.minimum_.x() > minimum_.x() &&
          box.minimum_.y() > minimum_.y() &&
          box.minimum_.z() > minimum_.z() &&
          box.maximum_.x() < maximum_.x() &&
          box.maximum_.y() < maximum_.y() &&
          box.maximum_.z() < maximum_.z());
}
int CubitBox::operator> ( const CubitVector vect) const

Definition at line 297 of file CubitBox.cpp.

{
  return (vect.x() > minimum_.x() && vect.x() < maximum_.x() &&
          vect.y() > minimum_.y() && vect.y() < maximum_.y() &&
          vect.z() > minimum_.z() && vect.z() < maximum_.z() );
}
int CubitBox::operator>= ( const CubitBox box) const

Definition at line 287 of file CubitBox.cpp.

{
  return (box.minimum_.x() >= minimum_.x() &&
          box.minimum_.y() >= minimum_.y() &&
          box.minimum_.z() >= minimum_.z() &&
          box.maximum_.x() <= maximum_.x() &&
          box.maximum_.y() <= maximum_.y() &&
          box.maximum_.z() <= maximum_.z());
}
int CubitBox::operator>= ( const CubitVector vect) const

Definition at line 304 of file CubitBox.cpp.

{
  return (vect.x() >= minimum_.x() && 
          vect.x() <= maximum_.x() &&
          vect.y() >= minimum_.y() && 
          vect.y() <= maximum_.y() &&
          vect.z() >= minimum_.z() && 
          vect.z() <= maximum_.z() );
}
CubitBox & CubitBox::operator|= ( const CubitBox box)

Definition at line 178 of file CubitBox.cpp.

CubitBox & CubitBox::operator|= ( const CubitVector vector)

Definition at line 191 of file CubitBox.cpp.

{
  minimum_.x(CUBIT_MIN(minimum_.x(), vector.x()));
  minimum_.y(CUBIT_MIN(minimum_.y(), vector.y()));
  minimum_.z(CUBIT_MIN(minimum_.z(), vector.z()));

  maximum_.x(CUBIT_MAX(maximum_.x(), vector.x()));
  maximum_.y(CUBIT_MAX(maximum_.y(), vector.y()));
  maximum_.z(CUBIT_MAX(maximum_.z(), vector.z()));
  return *this;
}
int CubitBox::operator|| ( const CubitBox box) const

Definition at line 442 of file CubitBox.cpp.

{
    // Return false if there is no overlap
    // along at least one of the 3 axes.
  if (minimum_.x() >= box.maximum_.x() ||
      maximum_.x() <= box.minimum_.x() ||
      minimum_.y() >= box.maximum_.y() ||
      maximum_.y() <= box.minimum_.y() ||
      minimum_.z() >= box.maximum_.z() ||
      maximum_.z() <= box.minimum_.z() )
    return CUBIT_FALSE;
  
    // If you didn't return false...
  return CUBIT_TRUE;
}
bool CubitBox::overlap ( double  tolerance,
const CubitBox other_box 
) const

Definition at line 162 of file CubitBox.cpp.

{
  //     | - note the '!'.  This condition checks that the boxes
  //     |   do NOT intersect and negates the result. 
  return ! ( (box.minimum_.x() - maximum_.x() > tolerance) ||
             (box.minimum_.y() - maximum_.y() > tolerance) ||
             (box.minimum_.z() - maximum_.z() > tolerance) ||
             (minimum_.x() - box.maximum_.x() > tolerance) ||
             (minimum_.y() - box.maximum_.y() > tolerance) ||
             (minimum_.z() - box.maximum_.z() > tolerance) );
}
void CubitBox::reset ( const CubitVector vector)

Definition at line 60 of file CubitBox.cpp.

{
  minimum_ = vector;
  maximum_ = vector;
}
void CubitBox::reset ( const CubitVector min,
const CubitVector max 
)

Definition at line 66 of file CubitBox.cpp.

{
  minimum_.set (CUBIT_MIN (min.x(), max.x()),
        CUBIT_MIN (min.y(), max.y()),
        CUBIT_MIN (min.z(), max.z()));
  maximum_.set (CUBIT_MAX (min.x(), max.x()),
        CUBIT_MAX (min.y(), max.y()),
        CUBIT_MAX (min.z(), max.z()));
}
void CubitBox::reset ( const CubitBox box)

Definition at line 76 of file CubitBox.cpp.

{
  minimum_ = box.minimum_;
  maximum_ = box.maximum_;
}
void CubitBox::reset ( const double  min[3],
const double  max[3] 
)

Definition at line 403 of file CubitBox.cpp.

{
  minimum_.set (CUBIT_MIN (min[0], max[0]),
                CUBIT_MIN (min[1], max[1]),
                CUBIT_MIN (min[2], max[2]));
  maximum_.set (CUBIT_MAX (min[0], max[0]),
                CUBIT_MAX (min[1], max[1]),
                CUBIT_MAX (min[2], max[2]));
}
double CubitBox::x_range ( ) const

Definition at line 143 of file CubitBox.cpp.

{ return (maximum_.x() - minimum_.x()); }
double CubitBox::y_range ( ) const

Definition at line 146 of file CubitBox.cpp.

{ return (maximum_.y() - minimum_.y()); }
double CubitBox::z_range ( ) const

Definition at line 149 of file CubitBox.cpp.

{ return (maximum_.z() - minimum_.z()); }

Friends And Related Function Documentation

CUBIT_UTIL_EXPORT CubitBox operator& ( const CubitBox lhs,
const CubitBox rhs 
) [friend]

Definition at line 319 of file CubitBox.cpp.

{
  return CubitBox(lhs) &= rhs;
}
CUBIT_UTIL_EXPORT CubitBox operator* ( const CubitBox lhs,
double  rhs 
) [friend]

Definition at line 329 of file CubitBox.cpp.

{
  return CubitBox(lhs) *= rhs;
}
CUBIT_UTIL_EXPORT CubitBox operator* ( double  rhs,
const CubitBox lhs 
) [friend]

Definition at line 324 of file CubitBox.cpp.

{
  return CubitBox(rhs) *= lhs;
}
CUBIT_UTIL_EXPORT CubitBox operator+ ( const CubitBox lhs,
const CubitVector rhs 
) [friend]

Definition at line 339 of file CubitBox.cpp.

{
  return CubitBox(lhs) += rhs;
}
CUBIT_UTIL_EXPORT CubitBox operator- ( const CubitBox lhs,
const CubitVector rhs 
) [friend]

Definition at line 344 of file CubitBox.cpp.

{
  return CubitBox(lhs) -= rhs;
}
CUBIT_UTIL_EXPORT CubitBox operator/ ( const CubitBox lhs,
double  rhs 
) [friend]

Definition at line 334 of file CubitBox.cpp.

{
  return CubitBox(lhs) /= rhs;
}
CUBIT_UTIL_EXPORT CubitBox operator| ( const CubitBox lhs,
const CubitBox rhs 
) [friend]

Definition at line 314 of file CubitBox.cpp.

{
  return CubitBox(lhs) |= rhs;
}
CUBIT_UTIL_EXPORT CubitBox operator| ( const CubitBox lhs,
const CubitVector rhs 
) [friend]

Member Data Documentation

Definition at line 176 of file CubitBox.hpp.

Definition at line 175 of file CubitBox.hpp.


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