ESyS-Particle  4.0.1
BoundingBox.hpp
00001 
00002 //                                                         //
00003 // Copyright (c) 2003-2011 by The University of Queensland //
00004 // Earth Systems Science Computational Centre (ESSCC)      //
00005 // http://www.uq.edu.au/esscc                              //
00006 //                                                         //
00007 // Primary Business: Brisbane, Queensland, Australia       //
00008 // Licensed under the Open Software License version 3.0    //
00009 // http://www.opensource.org/licenses/osl-3.0.php          //
00010 //                                                         //
00012 
00013 
00014 namespace esys
00015 {
00016   namespace lsm
00017   {
00018     BoundingBox::BoundingBox()
00019       : m_minPt(Vec3::ZERO),
00020         m_maxPt(Vec3::ZERO)
00021     {
00022     }
00023 
00024     BoundingBox::BoundingBox(const Vec3 &minBBoxPt, const Vec3 &maxBBoxPt)
00025       : m_minPt(minBBoxPt),
00026         m_maxPt(maxBBoxPt)
00027     {
00028     }
00029 
00030     BoundingBox::~BoundingBox()
00031     {
00032     }
00033 
00034     double BoundingBox::getVolume() const
00035     {
00036       Vec3 diff(m_maxPt-m_minPt);
00037       return diff.X()*diff.Y()*diff.Z();
00038     }
00039 
00040     const Vec3 &BoundingBox::getMinPt() const
00041     {
00042       return m_minPt;
00043     }
00044 
00045     const Vec3 &BoundingBox::getMaxPt() const
00046     {
00047       return m_maxPt;
00048     }
00049 
00050     bool BoundingBox::operator==(const BoundingBox &bbox) const
00051     {
00052       return
00053         (
00054           (getMinPt() == bbox.getMinPt())
00055           &&
00056           (getMaxPt() == bbox.getMaxPt())
00057         );
00058     }
00059 
00060     bool BoundingBox::contains(const Vec3 &pt, double tolerance) const
00061     {
00062       return
00063         (
00064           (getMinPt().X() <= (pt.X() + tolerance))
00065           &&
00066           (getMinPt().Y() <= (pt.Y() + tolerance))
00067           &&
00068           (getMinPt().Z() <= (pt.Z() + tolerance))
00069           &&
00070           (getMaxPt().X() >= (pt.X() - tolerance))
00071           &&
00072           (getMaxPt().Y() >= (pt.Y() - tolerance))
00073           &&
00074           (getMaxPt().Z() >= (pt.Z() - tolerance))
00075         );
00076     }
00077     
00078     Vec3 BoundingBox::getSizes() const
00079     {
00080       return (getMaxPt() - getMinPt());
00081     }
00082 
00083     std::ostream &operator<<(std::ostream &oStream, const BoundingBox &bbox)
00084     {
00085       oStream << bbox.getMinPt() << " " << bbox.getMaxPt();
00086       return oStream;
00087     }
00088   };
00089 };