1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
/////////////////////////////////////////////////////////////
// //
// Copyright (c) 2007-2014 by The University of Queensland //
// Centre for Geoscience Computing //
// http://earth.uq.edu.au/centre-geoscience-computing //
// //
// Primary Business: Brisbane, Queensland, Australia //
// Licensed under the Open Software License version 3.0 //
// http://www.opensource.org/licenses/osl-3.0.php //
// //
/////////////////////////////////////////////////////////////
#include "BoxWithJointSet.h"
// --- STL includes ---
#include <utility>
#include <map>
using std::make_pair;
using std::map;
BoxWithJointSet::BoxWithJointSet()
{}
/*!
Construct box. Just calls constructor of base class.
\param pmin minimum point of bounding box
\param pmax maximum point of bounding box
*/
BoxWithJointSet::BoxWithJointSet(const Vector3& pmin,const Vector3& pmax) : BoxWithPlanes3D(pmin,pmax)
{}
/*!
get the n geometrical objects closest to a given point
\param p the point
\param nmax the max. nr. of objects
\return a map of [dist,*object] pairs
*/
const map<double,const AGeometricObject*> BoxWithJointSet::getClosestObjects(const Vector3& p,int nmax) const
{
map<double,const AGeometricObject*> res;
for(vector<Plane>::const_iterator iter=m_planes.begin();
iter!=m_planes.end();
iter++){
double ndist=iter->getDist(p);
res.insert(make_pair(ndist,&(*iter)));
}
for(vector<Triangle3D>::const_iterator iter=m_joints.begin();
iter!=m_joints.end();
iter++){
double ndist=iter->getDist(p);
res.insert(make_pair(ndist,&(*iter)));
}
return res;
}
/*!
add a set of triangular patches as joints
\param t the joint set
*/
void BoxWithJointSet::addJoints(const TriPatchSet& t)
{
for(vector<Triangle3D>::const_iterator iter=t.triangles_begin();
iter!=t.triangles_end();
iter++){
m_joints.push_back(*iter);
}
}
/*!
check if a Sphere is inside and doesn't intersect any planes or other objects
\param S the Sphere
*/
bool BoxWithJointSet::isIn(const Sphere& S)
{
double r=S.Radius();
Vector3 p=S.Center();
// check inside & planes via base class
bool res=BoxWithPlanes3D::isIn(S);
if(res){
// check intersection with joints
vector<Triangle3D>::iterator iter=m_joints.begin();
double dist=2*r;
while((iter!=m_joints.end()) && res){
dist=iter->getDist(p);
res=(dist>r);
iter++;
}
}
return res;
}
ostream& operator<< (ostream& ost, const BoxWithJointSet& B)
{
ost << B.m_pmin << " to " << B.m_pmax;
return ost;
}
|