| 1 |
///////////////////////////////////////////////////////////// |
| 2 |
// // |
| 3 |
// Copyright (c) 2007-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 |
// // |
| 11 |
///////////////////////////////////////////////////////////// |
| 12 |
|
| 13 |
#include "ClippedSphereVol.h" |
| 14 |
|
| 15 |
using std::make_pair; |
| 16 |
|
| 17 |
ClippedSphereVol::ClippedSphereVol() |
| 18 |
{} |
| 19 |
|
| 20 |
/*! |
| 21 |
constructor taking center and radius of the Sphere as arguments |
| 22 |
|
| 23 |
\param center the center of the sphere |
| 24 |
\param radius the radius of the sphere |
| 25 |
*/ |
| 26 |
ClippedSphereVol::ClippedSphereVol(const Vector3& center,double radius): |
| 27 |
SphereVol(center,radius) |
| 28 |
{} |
| 29 |
|
| 30 |
void ClippedSphereVol::addPlane(const Plane& p, bool fit) |
| 31 |
{ |
| 32 |
m_planes.push_back(make_pair(p,fit)); |
| 33 |
} |
| 34 |
|
| 35 |
Vector3 ClippedSphereVol::getAPoint(int n) const |
| 36 |
{ |
| 37 |
Vector3 res; |
| 38 |
|
| 39 |
do { |
| 40 |
res=SphereVol::getAPoint(n); |
| 41 |
} while (!isIn(res)); |
| 42 |
|
| 43 |
return res; |
| 44 |
} |
| 45 |
|
| 46 |
const map<double,const AGeometricObject*> ClippedSphereVol::getClosestObjects(const Vector3& pos ,int nr) const |
| 47 |
{ |
| 48 |
map<double,const AGeometricObject*> res=SphereVol::getClosestObjects(pos,nr); |
| 49 |
|
| 50 |
for(vector<pair<Plane,bool> >::const_iterator iter=m_planes.begin(); |
| 51 |
iter!=m_planes.end(); |
| 52 |
iter++){ |
| 53 |
if(iter->second){ |
| 54 |
double dist=iter->first.getDist(pos); |
| 55 |
res.insert(make_pair(dist,&(iter->first))); |
| 56 |
} |
| 57 |
} |
| 58 |
return res; |
| 59 |
} |
| 60 |
|
| 61 |
bool ClippedSphereVol::isIn(const Vector3& pos) const |
| 62 |
{ |
| 63 |
bool res=SphereVol::isIn(pos); |
| 64 |
|
| 65 |
vector<pair<Plane,bool> >::const_iterator iter=m_planes.begin(); |
| 66 |
while(res && iter!=m_planes.end()){ |
| 67 |
bool rside=((pos-iter->first.getOrig())*iter->first.getNormal())>0.0; |
| 68 |
res=res && rside; |
| 69 |
iter++; |
| 70 |
} |
| 71 |
return res; |
| 72 |
} |
| 73 |
|
| 74 |
bool ClippedSphereVol::isIn(const Sphere& S) |
| 75 |
{ |
| 76 |
bool res=SphereVol::isIn(S); |
| 77 |
|
| 78 |
vector<pair<Plane,bool> >::const_iterator iter=m_planes.begin(); |
| 79 |
while(res && iter!=m_planes.end()){ |
| 80 |
bool rside=((S.Center()-iter->first.getOrig())*iter->first.getNormal())>S.Radius(); |
| 81 |
res=res && rside; |
| 82 |
iter++; |
| 83 |
} |
| 84 |
|
| 85 |
return res; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|