ESyS-Particle  4.0.1
BoundingBox.hpp
1 
2 // //
3 // Copyright (c) 2003-2011 by The University of Queensland //
4 // Earth Systems Science Computational Centre (ESSCC) //
5 // http://www.uq.edu.au/esscc //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 
14 namespace esys
15 {
16  namespace lsm
17  {
18  BoundingBox::BoundingBox()
19  : m_minPt(Vec3::ZERO),
20  m_maxPt(Vec3::ZERO)
21  {
22  }
23 
24  BoundingBox::BoundingBox(const Vec3 &minBBoxPt, const Vec3 &maxBBoxPt)
25  : m_minPt(minBBoxPt),
26  m_maxPt(maxBBoxPt)
27  {
28  }
29 
30  BoundingBox::~BoundingBox()
31  {
32  }
33 
34  double BoundingBox::getVolume() const
35  {
36  Vec3 diff(m_maxPt-m_minPt);
37  return diff.X()*diff.Y()*diff.Z();
38  }
39 
40  const Vec3 &BoundingBox::getMinPt() const
41  {
42  return m_minPt;
43  }
44 
45  const Vec3 &BoundingBox::getMaxPt() const
46  {
47  return m_maxPt;
48  }
49 
50  bool BoundingBox::operator==(const BoundingBox &bbox) const
51  {
52  return
53  (
54  (getMinPt() == bbox.getMinPt())
55  &&
56  (getMaxPt() == bbox.getMaxPt())
57  );
58  }
59 
60  bool BoundingBox::contains(const Vec3 &pt, double tolerance) const
61  {
62  return
63  (
64  (getMinPt().X() <= (pt.X() + tolerance))
65  &&
66  (getMinPt().Y() <= (pt.Y() + tolerance))
67  &&
68  (getMinPt().Z() <= (pt.Z() + tolerance))
69  &&
70  (getMaxPt().X() >= (pt.X() - tolerance))
71  &&
72  (getMaxPt().Y() >= (pt.Y() - tolerance))
73  &&
74  (getMaxPt().Z() >= (pt.Z() - tolerance))
75  );
76  }
77 
78  Vec3 BoundingBox::getSizes() const
79  {
80  return (getMaxPt() - getMinPt());
81  }
82 
83  std::ostream &operator<<(std::ostream &oStream, const BoundingBox &bbox)
84  {
85  oStream << bbox.getMinPt() << " " << bbox.getMaxPt();
86  return oStream;
87  }
88  };
89 };