Debian Codegraph @

src/ClippedCircleVol.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 "ClippedCircleVol.h"
14
15 using std::make_pair;
16
17 ClippedCircleVol::ClippedCircleVol()
18 {}
19
20 /*!
21 constructor taking center and radius of the circle as arguments
22
23 \param center the center of the circle
24 \param radius the radius of the circle
25 */
26 ClippedCircleVol::ClippedCircleVol(const Vector3& center,double radius):
27 CircleVol(center,radius)
28 {}
29
30
31 /*!
32 add a line to the volume
33
34 \param l the line
35 \param fit if true, line is used for fitting, if false line is only used for in/out detection
36 */
37 void ClippedCircleVol::addLine(const Line2D& l,bool fit)
38 {
39 m_lines.push_back(make_pair(l,fit));
40 }
41
42
43 /*!
44 get a random point inside the volume
45
46 \param n is ignored
47 */
48 Vector3 ClippedCircleVol::getAPoint(int n) const
49 {
50 Vector3 res;
51
52 do {
53 res=CircleVol::getAPoint(n);
54 } while (!isIn(res));
55
56 return res;
57 }
58
59 /*!
60 get objects closest to a given point
61
62 \param pos the point
63 \param nr the max. number of objects returned
64 */
65 const map<double,const AGeometricObject*> ClippedCircleVol::getClosestObjects(const Vector3& pos,int nr) const
66 {
67 map<double,const AGeometricObject*> res=CircleVol::getClosestObjects(pos,nr);
68
69 for(vector<pair<Line2D,bool> >::const_iterator iter=m_lines.begin();
70 iter!=m_lines.end();
71 iter++){
72 if(iter->second){
73 double dist=iter->first.getDist(pos);
74 res.insert(make_pair(dist,&(iter->first)));
75 }
76 }
77 return res;
78 }
79
80 /*!
81 test if a point is inside the volume
82
83 \param pos the point
84 */
85 bool ClippedCircleVol::isIn(const Vector3& pos) const
86 {
87 bool res=CircleVol::isIn(pos);
88
89 vector<pair<Line2D,bool> >::const_iterator iter=m_lines.begin();
90 while(res && iter!=m_lines.end()){
91 bool rside=((pos-iter->first.getOrig())*iter->first.getNormal())>0.0;
92 res=res && rside;
93 iter++;
94 }
95 return res;
96 }
97
98 /*!
99 test if a sphere(circle) is completely inside the volume
100
101 \param S the sphere
102 */
103 bool ClippedCircleVol::isIn(const Sphere& S)
104 {
105 bool res=CircleVol::isIn(S);
106
107 vector<pair<Line2D,bool> >::const_iterator iter=m_lines.begin();
108 while(res && iter!=m_lines.end()){
109 bool rside=((S.Center()-iter->first.getOrig())*iter->first.getNormal())>S.Radius();
110 res=res && rside;
111 iter++;
112 }
113
114 return res;
115 }