14 #ifndef ESYS_LSMGRIDITERATOR_H
15 #define ESYS_LSMGRIDITERATOR_H
17 #include "Foundation/BoundingBox.h"
18 #include "Foundation/vec3.h"
32 : m_sphereRadius(0.0),
46 inline GridIterator(
int numPtsX,
int numPtsY,
int numPtsZ,
double
48 : m_sphereRadius(sphereRadius),
64 minPt =
Vec3(0,0,0) + sphereRadius;
67 (numPtsX-1)*2.0*sphereRadius
84 (numPtsY-1)*(sphereRadius*2.0*sqrt(2.0/3.0)),
85 (numPtsZ-1)*(sphereRadius*sqrt(3.0))
87 ((numPtsY > 1) ? sphereRadius*sqrt(3.0)/3.0 : 0.0)
90 minPt =
Vec3(sphereRadius, sphereRadius, 0);
93 (numPtsX-1)*2.0*sphereRadius
101 (numPtsY-1)*(sphereRadius*sqrt(3.0)),
106 m_centrePtBBox =
BoundingBox(minPt, (minPt + maxPt));
113 : m_sphereRadius(sphereRadius),
125 int numPtsX ,numPtsY ,numPtsZ;
127 numPtsX = max(1,
int(nearbyint((particleBBox.getSizes().X()-(sphereRadius/4.0))/(sphereRadius*2.0))));
128 numPtsY = max(1,
int(nearbyint(particleBBox.getSizes().Y()/(sphereRadius*2.0*sqrt(2.0/3.0)))));
129 numPtsZ = max(1,
int(nearbyint(particleBBox.getSizes().Z()/(sphereRadius*sqrt(3.0)))));
131 numPtsX = max(1,
int(floor((particleBBox.getSizes().X()-(sphereRadius/4.0))/(sphereRadius*2.0))));
132 numPtsY = max(1,
int(floor(particleBBox.getSizes().Y()/(sphereRadius*2.0*sqrt(2.0/3.0)))));
133 numPtsZ = max(1,
int(floor(particleBBox.getSizes().Z()/(sphereRadius*sqrt(3.0)))));
135 if ((numPtsZ > 1) && (numPtsY > 1)) {
138 if (particleBBox.getSizes().Z() > 0.0) {
139 const Vec3 minPt = particleBBox.getMinPt() + sphereRadius;
142 (numPtsX-1)*2.0*sphereRadius + ((numPtsZ > 1) ? sphereRadius : 0.0) + ((numPtsY > 1) ? sphereRadius : 0.0),
143 (numPtsY-1)*(sphereRadius*2.0*sqrt(2.0/3.0)),
144 (numPtsZ-1)*(sphereRadius*sqrt(3.0))
146 ((numPtsY > 1) ? sphereRadius*sqrt(3.0)/3.0 : 0.0)
148 m_centrePtBBox =
BoundingBox(minPt, (minPt + maxPt));
150 numPtsX = int(nearbyint((particleBBox.getSizes().X()-(sphereRadius/4.0))/(sphereRadius*2.0)));
151 numPtsY = int(nearbyint(particleBBox.getSizes().Y()/(sphereRadius*sqrt(3.0))));
154 Vec3 minPt = particleBBox.getMinPt() + sphereRadius;
155 minPt.Z() = particleBBox.getMinPt().Z();
158 (numPtsX-1)*2.0*sphereRadius + ((numPtsY > 1) ? sphereRadius : 0.0),
159 (numPtsY-1)*(sphereRadius*sqrt(3.0)),
160 particleBBox.getMaxPt().Z()
162 m_centrePtBBox =
BoundingBox(minPt, (minPt + maxPt));
180 inline const BoundingBox &getBoundingBox()
const
182 return m_centrePtBBox;
185 inline BoundingBox getSphereBBox()
const
192 m_centrePtBBox.getMinPt() -
Vec3(m_sphereRadius, m_sphereRadius, 0.0),
193 m_centrePtBBox.getMaxPt() +
Vec3(m_sphereRadius, m_sphereRadius, 0.0)
197 m_centrePtBBox.getMinPt() - m_sphereRadius,
198 m_centrePtBBox.getMaxPt() + m_sphereRadius
209 return (m_i < m_maxI);
212 inline bool is2d()
const
214 return (m_minJ == m_maxJ);
217 inline Vec3 getPoint()
const
222 m_centrePtBBox.getMinPt().X() + (double(m_i)+0.5*double(m_k%2))*m_sphereRadius*2.0,
223 m_centrePtBBox.getMinPt().Y() + double(m_k)*sqrt(3.0)*m_sphereRadius,
229 m_centrePtBBox.getMinPt().X() + (double(m_i)+0.5*double(m_j%2)+0.5*double(m_k%2))*m_sphereRadius*2.0,
230 m_centrePtBBox.getMinPt().Y() + (double(m_k)*2.0*sqrt(2.0/3.0))*m_sphereRadius,
231 m_centrePtBBox.getMinPt().Z() + ((double(m_j)+double(m_k%2)/3.0)*sqrt(3.0))*m_sphereRadius
236 inline void increment()
238 if (m_k+1 < m_maxK) {
241 else if (m_j+1 < m_maxJ) {
257 const Vec3 pt = getPoint();
263 double m_sphereRadius;