ESyS-Particle  2.3.4
IntersectionVolCalculator.h
Go to the documentation of this file.
1 // //
3 // Copyright (c) 2003-2017 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.apache.org/licenses/LICENSE-2.0 //
10 // //
12 
13 
14 #ifndef ESYS_LSM_IMPLINTERSECTIONVOLCALCULATOR_H
15 #define ESYS_LSM_IMPLINTERSECTIONVOLCALCULATOR_H
16 
17 #include <math.h>
18 
19 namespace esys
20 {
21  namespace lsm
22  {
23  namespace impl
24  {
25  double square(double val);
26 
27  template <int tmplDim, typename TmplVec>
29  {
30  public:
31  typedef TmplVec Vec;
32  DimBasicBox(const Vec &minPt, const Vec &maxPt);
33 
34  const Vec &getMinPt() const;
35 
36  const Vec &getMaxPt() const;
37 
38  double getVolume() const;
39 
40  template <typename TmplSphere>
41  bool intersectsWith(const TmplSphere &sphere) const;
42 
43  bool intersectsWith(const Vec &pt) const;
44 
45  template <typename TmplSphere>
46  bool contains(const TmplSphere &sphere) const;
47 
48  private:
51  };
52 
53  template <int tmplDim, typename TmplVec>
54  class DimPlane
55  {
56  public:
57  typedef TmplVec Vec;
58 
59  static double norm(const Vec &pt);
60 
61  static double dot(const Vec &p1, const Vec &p2);
62 
63  DimPlane();
64 
65  DimPlane(const Vec &normal, const Vec &pt);
66 
67  DimPlane(const DimPlane &plane);
68 
69  DimPlane &operator=(const DimPlane &plane);
70 
71  double getSignedDistanceTo(const Vec &pt) const;
72 
73  double getDistanceTo(const Vec &pt) const;
74 
75  const Vec &getNormal() const;
76 
77  private:
81  };
82 
83  template <int tmplDim, typename TmplVec>
85  {
86  public:
87  typedef TmplVec Vec;
89 
90  static const double FOUR_THIRDS_PI;
91  static const double ONE_THIRD_PI;
92 
94 
95  DimBasicSphere(const Vec &centrePt, double radius);
96 
97  DimBasicSphere(const DimBasicSphere &sphere);
98 
99  DimBasicSphere &operator=(const DimBasicSphere &sphere);
100 
101  double getRadius() const;
102 
103  const Vec &getCentre() const;
104 
105  double getVolume() const;
106 
107  double getVolume(const Vec &minPt, const Vec &maxPt, const int dimX = 0, const int dimY = 1) const;
108 
109  bool intersectsWith(const Vec &pt) const;
110 
111  double getSegmentVolume(const Plane &plane) const;
112 
113  private:
115  double m_radius;
116  };
117 
118  template <int tmplDim, typename TmplVec>
120  {
121  public:
122  typedef TmplVec Vec;
126 
127  static Vec getNormal(int dim);
128 
129  static Vec getNegNormal(int dim);
130 
132  {
133  public:
134  VolumeSphere();
135 
136  VolumeSphere(const BasicSphere &sphere);
137 
138  VolumeSphere(const VolumeSphere &sphere);
139 
140  VolumeSphere &operator=(const VolumeSphere &sphere);
141 
142  double getRadius() const;
143 
144  const Vec &getCentre() const;
145 
146  double getVolume() const;
147 
148  double getVolume(const Vec &minPt, const Vec &maxPt, const int dimX = 0, const int dimY = 1) const;
149 
150  double calcVolume() const;
151 
152  bool intersectsWith(const Vec &pt) const;
153 
154  double getSegmentVolume(const Plane &plane) const;
155 
156  private:
158  double m_volume;
159  };
160 
161  class Vertex
162  {
163  public:
164  Vertex();
165 
166  Vertex(const Vec &pt);
167 
168  Vertex(const Vertex &vtx);
169 
170  Vertex &operator=(const Vertex &vtx);
171 
172  const Vec &getPoint() const;
173 
174  void setPoint(const Vec &pt);
175 
176  private:
178  };
179 
180  class VertexBox : public BasicBox
181  {
182  public:
183  VertexBox(const BasicBox &box);
184 
185  VertexBox(const VertexBox &box);
186 
187  VertexBox &operator=(const VertexBox &box);
188 
189  void createVertices();
190 
191  const Vertex &getVertex(int i) const;
192 
193  static int getNumVertices();
194 
195  private:
196  static const int s_numVertices = ((tmplDim == 2) ? 4 : 8);
198  };
199 
201 
202  const VolumeSphere &getSphere() const;
203 
204  void setSphere(const BasicSphere &sphere);
205 
206  const BasicBox &getBox() const;
207 
208  const VertexBox &getVertexBox() const;
209 
210  static Vec componentMin(const Vec &p1, const Vec &p2);
211 
212  static Vec componentMax(const Vec &p1, const Vec &p2);
213 
214  double getInsidePointVolume(const Vec &pt) const;
215 
216  double getTwoPlaneVolume(const Vec &pt, const int orientDim) const;
217 
218  double getOutsidePointVolume(const Vec &pt) const;
219 
220  double getVolume(const Vertex &vtx);
221 
222  double getVertexVolume(const BasicSphere &sphere);
223 
224  bool sphereContainsBox(const BasicSphere &sphere) const;
225 
226  double getVolume(const BasicSphere &sphere);
227 
228  private:
229  VolumeSphere m_sphere;
230  VertexBox m_box;
231  };
232  }
233  }
234 }
235 
237 
238 #endif
esys::lsm::impl::IntersectionVolCalculator::VertexBox::s_numVertices
static const int s_numVertices
Definition: IntersectionVolCalculator.h:196
esys::lsm::impl::DimBasicSphere::getCentre
const Vec & getCentre() const
Definition: IntersectionVolCalculator.hpp:230
esys::lsm::impl::DimBasicSphere::Plane
DimPlane< tmplDim, Vec > Plane
Definition: IntersectionVolCalculator.h:88
esys::lsm::impl::IntersectionVolCalculator::VolumeSphere::operator=
VolumeSphere & operator=(const VolumeSphere &sphere)
Definition: IntersectionVolCalculator.hpp:495
esys::lsm::impl::square
double square(double val)
Definition: IntersectionVolCalculator.hpp:25
esys::lsm::impl::DimPlane::getDistanceTo
double getDistanceTo(const Vec &pt) const
Definition: IntersectionVolCalculator.hpp:176
esys::lsm::impl::DimBasicBox
Definition: IntersectionVolCalculator.h:29
esys::lsm::impl::IntersectionVolCalculator::getVertexVolume
double getVertexVolume(const BasicSphere &sphere)
Definition: IntersectionVolCalculator.hpp:1119
esys::lsm::impl::IntersectionVolCalculator::getVertexBox
const VertexBox & getVertexBox() const
Definition: IntersectionVolCalculator.hpp:692
esys::lsm::impl::IntersectionVolCalculator::getNormal
static Vec getNormal(int dim)
Definition: IntersectionVolCalculator.hpp:452
esys::lsm::impl::DimPlane::DimPlane
DimPlane()
Definition: IntersectionVolCalculator.hpp:136
esys::lsm::impl::IntersectionVolCalculator::Vertex::getPoint
const Vec & getPoint() const
Definition: IntersectionVolCalculator.hpp:577
esys::lsm::impl::IntersectionVolCalculator::Vertex::m_pt
Vec m_pt
Definition: IntersectionVolCalculator.h:177
esys::lsm::impl::IntersectionVolCalculator::VertexBox::getNumVertices
static int getNumVertices()
Definition: IntersectionVolCalculator.hpp:654
esys::lsm::impl::IntersectionVolCalculator::getBox
const BasicBox & getBox() const
Definition: IntersectionVolCalculator.hpp:685
esys::lsm::impl::DimPlane::dot
static double dot(const Vec &p1, const Vec &p2)
Definition: IntersectionVolCalculator.hpp:125
esys::lsm::impl::IntersectionVolCalculator::VolumeSphere::m_volume
double m_volume
Definition: IntersectionVolCalculator.h:158
esys::lsm::impl::DimBasicSphere::m_radius
double m_radius
Definition: IntersectionVolCalculator.h:115
esys::lsm::impl::IntersectionVolCalculator::setSphere
void setSphere(const BasicSphere &sphere)
Definition: IntersectionVolCalculator.hpp:676
esys::lsm::impl::DimBasicSphere::getSegmentVolume
double getSegmentVolume(const Plane &plane) const
Definition: IntersectionVolCalculator.hpp:423
esys::lsm::impl::IntersectionVolCalculator::m_sphere
VolumeSphere m_sphere
Definition: IntersectionVolCalculator.h:229
esys::lsm::impl::IntersectionVolCalculator::VertexBox::VertexBox
VertexBox(const BasicBox &box)
Definition: IntersectionVolCalculator.hpp:589
esys::lsm::impl::DimBasicSphere::ONE_THIRD_PI
static const double ONE_THIRD_PI
Definition: IntersectionVolCalculator.h:91
esys::lsm::impl::DimBasicSphere::FOUR_THIRDS_PI
static const double FOUR_THIRDS_PI
Definition: IntersectionVolCalculator.h:90
esys::lsm::impl::IntersectionVolCalculator::sphereContainsBox
bool sphereContainsBox(const BasicSphere &sphere) const
Definition: IntersectionVolCalculator.hpp:1148
esys::lsm::impl::DimPlane::Vec
TmplVec Vec
Definition: IntersectionVolCalculator.h:57
esys::lsm::impl::IntersectionVolCalculator::VertexBox::createVertices
void createVertices()
Definition: IntersectionVolCalculator.hpp:625
esys::lsm::impl::DimPlane::m_invNormalNorm
double m_invNormalNorm
Definition: IntersectionVolCalculator.h:80
esys::lsm::impl::IntersectionVolCalculator::getSphere
const VolumeSphere & getSphere() const
Definition: IntersectionVolCalculator.hpp:670
esys::lsm::impl::IntersectionVolCalculator::getTwoPlaneVolume
double getTwoPlaneVolume(const Vec &pt, const int orientDim) const
Definition: IntersectionVolCalculator.hpp:887
esys::lsm::impl::IntersectionVolCalculator::getInsidePointVolume
double getInsidePointVolume(const Vec &pt) const
Definition: IntersectionVolCalculator.hpp:728
esys::lsm::impl::IntersectionVolCalculator::componentMin
static Vec componentMin(const Vec &p1, const Vec &p2)
Definition: IntersectionVolCalculator.hpp:699
esys::lsm::impl::IntersectionVolCalculator::VolumeSphere::m_sphere
BasicSphere m_sphere
Definition: IntersectionVolCalculator.h:157
esys::lsm::impl::DimBasicBox::getVolume
double getVolume() const
Definition: IntersectionVolCalculator.hpp:50
esys::lsm::impl::IntersectionVolCalculator::Vertex::operator=
Vertex & operator=(const Vertex &vtx)
Definition: IntersectionVolCalculator.hpp:569
esys::lsm::impl::DimPlane::operator=
DimPlane & operator=(const DimPlane &plane)
Definition: IntersectionVolCalculator.hpp:157
esys::lsm::impl::IntersectionVolCalculator::VolumeSphere::getRadius
double getRadius() const
Definition: IntersectionVolCalculator.hpp:505
esys::lsm::impl::IntersectionVolCalculator::Plane
DimPlane< tmplDim, Vec > Plane
Definition: IntersectionVolCalculator.h:125
esys::lsm::impl::IntersectionVolCalculator::IntersectionVolCalculator
IntersectionVolCalculator(const BasicBox &box)
Definition: IntersectionVolCalculator.hpp:660
esys
Definition: CheckPointable.cpp:17
esys::lsm::impl::DimBasicBox::Vec
TmplVec Vec
Definition: IntersectionVolCalculator.h:31
esys::lsm::impl::DimBasicSphere
Definition: IntersectionVolCalculator.h:85
esys::lsm::impl::DimPlane::norm
static double norm(const Vec &pt)
Definition: IntersectionVolCalculator.hpp:114
esys::lsm::impl::IntersectionVolCalculator::VertexBox::operator=
VertexBox & operator=(const VertexBox &box)
Definition: IntersectionVolCalculator.hpp:612
esys::lsm::impl::DimBasicBox::intersectsWith
bool intersectsWith(const TmplSphere &sphere) const
Definition: IntersectionVolCalculator.hpp:62
esys::lsm::impl::IntersectionVolCalculator::VolumeSphere::getSegmentVolume
double getSegmentVolume(const Plane &plane) const
Definition: IntersectionVolCalculator.hpp:547
esys::lsm::impl::IntersectionVolCalculator::getNegNormal
static Vec getNegNormal(int dim)
Definition: IntersectionVolCalculator.hpp:461
esys::lsm::impl::IntersectionVolCalculator::VolumeSphere::getCentre
const Vec & getCentre() const
Definition: IntersectionVolCalculator.hpp:512
esys::lsm::impl::DimPlane
Definition: IntersectionVolCalculator.h:55
esys::lsm::impl::IntersectionVolCalculator::Vertex
Definition: IntersectionVolCalculator.h:162
esys::lsm::impl::IntersectionVolCalculator::Vertex::setPoint
void setPoint(const Vec &pt)
Definition: IntersectionVolCalculator.hpp:583
esys::lsm::impl::DimBasicBox::contains
bool contains(const TmplSphere &sphere) const
Definition: IntersectionVolCalculator.hpp:94
esys::lsm::impl::IntersectionVolCalculator::Vec
TmplVec Vec
Definition: IntersectionVolCalculator.h:122
esys::lsm::impl::DimBasicBox::getMaxPt
const Vec & getMaxPt() const
Definition: IntersectionVolCalculator.hpp:44
esys::lsm::impl::DimBasicSphere::getRadius
double getRadius() const
Definition: IntersectionVolCalculator.hpp:223
esys::lsm::impl::DimBasicBox::getMinPt
const Vec & getMinPt() const
Definition: IntersectionVolCalculator.hpp:38
esys::lsm::impl::DimBasicSphere::intersectsWith
bool intersectsWith(const Vec &pt) const
Definition: IntersectionVolCalculator.hpp:412
esys::lsm::impl::IntersectionVolCalculator::getOutsidePointVolume
double getOutsidePointVolume(const Vec &pt) const
Definition: IntersectionVolCalculator.hpp:986
esys::lsm::impl::IntersectionVolCalculator::m_box
VertexBox m_box
Definition: IntersectionVolCalculator.h:230
esys::lsm::impl::DimBasicSphere::m_centre
Vec m_centre
Definition: IntersectionVolCalculator.h:114
esys::lsm::impl::IntersectionVolCalculator::componentMax
static Vec componentMax(const Vec &p1, const Vec &p2)
Definition: IntersectionVolCalculator.hpp:714
esys::lsm::impl::IntersectionVolCalculator::VolumeSphere::intersectsWith
bool intersectsWith(const Vec &pt) const
Definition: IntersectionVolCalculator.hpp:541
Vec3
Definition: vec3.h:47
esys::lsm::impl::DimPlane::getSignedDistanceTo
double getSignedDistanceTo(const Vec &pt) const
Definition: IntersectionVolCalculator.hpp:166
esys::lsm::impl::IntersectionVolCalculator::Vertex::Vertex
Vertex()
Definition: IntersectionVolCalculator.hpp:553
esys::lsm::impl::IntersectionVolCalculator::VolumeSphere
Definition: IntersectionVolCalculator.h:132
esys::lsm::impl::IntersectionVolCalculator
Definition: IntersectionVolCalculator.h:120
esys::lsm::impl::IntersectionVolCalculator::VertexBox::m_vertexArray
Vertex m_vertexArray[s_numVertices]
Definition: IntersectionVolCalculator.h:197
esys::lsm::impl::DimPlane::getNormal
const Vec & getNormal() const
Definition: IntersectionVolCalculator.hpp:182
esys::lsm::impl::DimBasicSphere::Vec
TmplVec Vec
Definition: IntersectionVolCalculator.h:87
esys::lsm::impl::DimBasicSphere::operator=
DimBasicSphere & operator=(const DimBasicSphere &sphere)
Definition: IntersectionVolCalculator.hpp:215
esys::lsm::impl::IntersectionVolCalculator::VolumeSphere::getVolume
double getVolume() const
Definition: IntersectionVolCalculator.hpp:518
esys::lsm::impl::DimBasicBox::DimBasicBox
DimBasicBox(const Vec &minPt, const Vec &maxPt)
Definition: IntersectionVolCalculator.hpp:31
esys::lsm::impl::DimBasicSphere::getVolume
double getVolume() const
Definition: IntersectionVolCalculator.hpp:236
esys::lsm::impl::IntersectionVolCalculator::VertexBox::getVertex
const Vertex & getVertex(int i) const
Definition: IntersectionVolCalculator.hpp:648
esys::lsm::impl::IntersectionVolCalculator::getVolume
double getVolume(const Vertex &vtx)
Definition: IntersectionVolCalculator.hpp:1102
esys::lsm::impl::DimPlane::m_normal
Vec m_normal
Definition: IntersectionVolCalculator.h:78
esys::lsm::impl::DimBasicSphere::DimBasicSphere
DimBasicSphere()
Definition: IntersectionVolCalculator.hpp:194
esys::lsm::impl::IntersectionVolCalculator::BasicSphere
DimBasicSphere< tmplDim, Vec > BasicSphere
Definition: IntersectionVolCalculator.h:123
esys::lsm::impl::IntersectionVolCalculator::VolumeSphere::VolumeSphere
VolumeSphere()
Definition: IntersectionVolCalculator.hpp:469
esys::lsm::impl::IntersectionVolCalculator::VertexBox
Definition: IntersectionVolCalculator.h:181
esys::lsm::impl::IntersectionVolCalculator::VolumeSphere::calcVolume
double calcVolume() const
Definition: IntersectionVolCalculator.hpp:535
esys::lsm::impl::IntersectionVolCalculator::BasicBox
DimBasicBox< tmplDim, Vec > BasicBox
Definition: IntersectionVolCalculator.h:124
esys::lsm::impl::DimPlane::m_pt
Vec m_pt
Definition: IntersectionVolCalculator.h:79
esys::lsm::impl::DimBasicBox::m_minPt
Vec m_minPt
Definition: IntersectionVolCalculator.h:49
IntersectionVolCalculator.hpp
IntersectionVolCalculator.h
esys::lsm::impl::DimBasicBox::m_maxPt
Vec m_maxPt
Definition: IntersectionVolCalculator.h:50