Debian Codegraph @

src/IntersectionVol.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 "IntersectionVol.h"
14
15 //---
16 #include <cmath>
17 #include <cstdlib>
18
19 using std::cos;
20 using std::sin;
21
22 // --- STL includes ---
23 #include <utility>
24
25 using std::make_pair;
26
27 IntersectionVol::IntersectionVol()
28 {
29 std::cout << "WARNING: IntersectionVol is an experimental feature and may not always work as expected. For details see doc/CSG.readme" << std::endl;
30 m_vol1 = NULL;
31 m_vol2 = NULL;
32 }
33
34 IntersectionVol::IntersectionVol(AVolume3D& v1, AVolume3D& v2)
35 {
36 std::cout << "WARNING: IntersectionVol is an experimental feature and may not always work as expected. For details see doc/CSG.readme" << std::endl;
37 m_vol1 = &v1;
38 m_vol2 = &v2;
39
40 // std::cout << m_vol1 << std::endl;
41 // std::cout << m_vol2 << std::endl;
42 }
43
44 pair<Vector3,Vector3> IntersectionVol::getBoundingBox()
45 {
46 // BoundingBox is the box containing both volumes
47
48 pair<Vector3,Vector3> bbx1=m_vol1->getBoundingBox();
49 // std::cout << "bbx1 = (" << bbx1.first.X() << " , " << bbx1.first.Y() << " , " << bbx1.first.Z() << ") ; (" << bbx1.second.X() << " , " << bbx1.second.Y() << " , " << bbx1.second.Z() << ")" << std::endl;
50
51 pair<Vector3,Vector3> bbx2=m_vol2->getBoundingBox();
52 // std::cout << "bbx2 = (" << bbx2.first.X() << " , " << bbx2.first.Y() << " , " << bbx2.first.Z() << ") ; (" << bbx2.second.X() << " , " << bbx2.second.Y() << " , " << bbx2.second.Z() << ")" << std::endl;
53
54 double X0,X1;
55 double Y0,Y1;
56 double Z0,Z1;
57
58 if (bbx1.first.X() < bbx2.first.X()) {
59 X0 = bbx1.first.X();
60 }
61 else {
62 X0 = bbx2.first.X();
63 }
64 if (bbx1.first.Y() < bbx2.first.Y()) {
65 Y0 = bbx1.first.Y();
66 }
67 else {
68 Y0 = bbx2.first.Y();
69 }
70 if (bbx1.first.Z() < bbx2.first.Z()) {
71 Z0 = bbx1.first.Z();
72 }
73 else {
74 Z0 = bbx2.first.Z();
75 }
76 Vector3 minPt = Vector3(X0,Y0,Z0);
77
78 if (bbx1.second.X() > bbx2.second.X()) {
79 X1 = bbx1.second.X();
80 }
81 else {
82 X1 = bbx2.second.X();
83 }
84 if (bbx1.second.Y() > bbx2.second.Y()) {
85 Y1 = bbx1.second.Y();
86 }
87 else {
88 Y1 = bbx2.second.Y();
89 }
90 if (bbx1.second.Z() > bbx2.second.Z()) {
91 Z1 = bbx1.second.Z();
92 }
93 else {
94 Z1 = bbx2.second.Z();
95 }
96 Vector3 maxPt = Vector3(X1,Y1,Z1);
97
98 // std::cout << "minPt = (" << X0 << " , " << Y0 << " , " << Z0 << ")" << std::endl;
99 // std::cout << "maxPt = (" << X1 << " , " << Y1 << " , " << Z1 << ")" << std::endl;
100
101 return make_pair(minPt,maxPt);
102 }
103
104 Vector3 IntersectionVol::getAPoint(int ivol) const
105 {
106 Vector3 aPoint;
107 bool found = false;
108
109 while (!(found)) {
110 aPoint = m_vol1->getAPoint(ivol);
111 found = m_vol2->isIn(aPoint);
112 }
113
114 return aPoint;
115 }
116
117 const map<double,const AGeometricObject*> IntersectionVol::getClosestObjects(const Vector3& P,int ival) const
118 {
119 map<double,const AGeometricObject*> res;
120 map<double,const AGeometricObject*> res2;
121
122 res = m_vol1->getClosestObjects(P,ival);
123 res2 = m_vol2->getClosestObjects(P,ival);
124
125 res.insert(res2.begin(), res2.end());
126
127 return res;
128 }
129
130 bool IntersectionVol::isIn(const Vector3& P) const
131 {
132 bool res = false;
133
134 if ((m_vol1->isIn(P)) && (m_vol2->isIn(P))) {
135 res = true;
136 }
137
138 return res;
139 }
140
141 bool IntersectionVol::isIn(const Sphere& S)
142 {
143 bool res = false;
144
145 if ((m_vol1->isIn(S)) && (m_vol2->isIn(S))) {
146 res = true;
147 }
148
149 return res;
150 }
151
152 /*!
153 Check if sphere is fully outside the volume. Tests if the sphere
154 is outside one of the subvolumes.
155
156 \param S the sphere
157 */
158 bool IntersectionVol::isFullyOutside(const Sphere& S)
159 {
160 return m_vol1->isFullyOutside(S) || m_vol2->isFullyOutside(S);
161 }
162
163 ostream& operator << (ostream& ost,const IntersectionVol& T)
164 {
165 return ost;
166 }