Debian Codegraph @

src/BoxWithJointSet.cc

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