cgma
|
#include <CubitBox.hpp>
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 ©_from) | |
CubitBox (const CubitBoxStruct &from) | |
CubitBox (const std::vector< CubitVector > &pts) | |
~CubitBox () | |
CubitBox & | bounding_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) |
CubitBox & | operator= (const CubitBox &box) |
CubitBox & | operator|= (const CubitBox &box) |
CubitBox & | operator|= (const CubitVector &vector) |
CubitBox & | operator&= (const CubitBox &box) |
CubitBox & | operator*= (double scale) |
CubitBox & | operator/= (double scale) |
CubitBox & | operator+= (const CubitVector &offset) |
CubitBox & | operator-= (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 |
CubitBox & | operator= (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) |
Definition at line 18 of file CubitBox.hpp.
Definition at line 17 of file CubitBox.cpp.
CubitBox::CubitBox | ( | const CubitVector & | min, |
const CubitVector & | max | ||
) |
CubitBox::CubitBox | ( | const double | min[3], |
const double | max[3] | ||
) |
CubitBox::CubitBox | ( | const CubitVector & | min_max | ) |
Definition at line 32 of file CubitBox.cpp.
CubitBox::CubitBox | ( | const CubitBox & | copy_from | ) |
CubitBox::CubitBox | ( | const CubitBoxStruct & | from | ) | [inline] |
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.
{}
CubitVector CubitBox::center | ( | ) | const |
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; }
CubitVector CubitBox::diagonal | ( | ) | const |
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.
double CubitBox::max_y | ( | ) | const |
Definition at line 97 of file CubitBox.cpp.
double CubitBox::max_z | ( | ) | const |
Definition at line 102 of file CubitBox.cpp.
CubitVector CubitBox::maximum | ( | ) | const |
Definition at line 87 of file CubitBox.cpp.
{ return CubitVector(maximum_); }
double CubitBox::maximum_range | ( | void | ) |
double CubitBox::min_x | ( | ) | const |
Definition at line 107 of file CubitBox.cpp.
double CubitBox::min_y | ( | ) | const |
Definition at line 112 of file CubitBox.cpp.
double CubitBox::min_z | ( | ) | const |
Definition at line 117 of file CubitBox.cpp.
CubitVector CubitBox::minimum | ( | ) | const |
Definition at line 82 of file CubitBox.cpp.
{ return CubitVector(minimum_); }
double CubitBox::minimum_range | ( | void | ) |
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; }
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.
CubitBox & CubitBox::operator-= | ( | const CubitVector & | offset | ) |
Definition at line 250 of file CubitBox.cpp.
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 |
int CubitBox::operator<= | ( | const CubitBox & | box | ) | const |
int CubitBox::operator<= | ( | const CubitVector & | vect | ) | const |
CubitBox & CubitBox::operator= | ( | const CubitBoxStruct & | from | ) | [inline] |
int CubitBox::operator> | ( | const CubitBox & | box | ) | const |
int CubitBox::operator> | ( | const CubitVector & | vect | ) | const |
int CubitBox::operator>= | ( | const CubitBox & | box | ) | const |
int CubitBox::operator>= | ( | const CubitVector & | vect | ) | const |
Definition at line 178 of file CubitBox.cpp.
{ minimum_.x(CUBIT_MIN(minimum_.x(), box.minimum_.x())); minimum_.y(CUBIT_MIN(minimum_.y(), box.minimum_.y())); minimum_.z(CUBIT_MIN(minimum_.z(), box.minimum_.z())); maximum_.x(CUBIT_MAX(maximum_.x(), box.maximum_.x())); maximum_.y(CUBIT_MAX(maximum_.y(), box.maximum_.y())); maximum_.z(CUBIT_MAX(maximum_.z(), box.maximum_.z())); return *this; }
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.
void CubitBox::reset | ( | const CubitVector & | min, |
const CubitVector & | max | ||
) |
void CubitBox::reset | ( | const CubitBox & | box | ) |
void CubitBox::reset | ( | const double | min[3], |
const double | max[3] | ||
) |
double CubitBox::x_range | ( | ) | const |
double CubitBox::y_range | ( | ) | const |
double CubitBox::z_range | ( | ) | const |
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] |
CubitVector CubitBox::maximum_ [private] |
Definition at line 176 of file CubitBox.hpp.
CubitVector CubitBox::minimum_ [private] |
Definition at line 175 of file CubitBox.hpp.