Debian Codegraph @

src/UnionVol.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 "UnionVol.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 UnionVol::UnionVol()
28 {
29 std::cout << "WARNING: UnionVol 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 UnionVol::UnionVol(AVolume3D& v1, AVolume3D& v2)
35 {
36 std::cout << "WARNING: UnionVol 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> UnionVol::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 UnionVol::getAPoint(int ivol) const
105 {
106 double r=((double)(rand())/(double)(RAND_MAX));
107 Vector3 aPoint;
108
109 if (r < 0.5) {
110 //if (ivol == 0) {
111 aPoint = m_vol1->getAPoint(ivol);
112 }
113 else {
114 aPoint = m_vol2->getAPoint(ivol);
115 }
116
117 return aPoint;
118 }
119
120 const map<double,const AGeometricObject*> UnionVol::getClosestObjects(const Vector3& P,int ival) const
121 {
122 map<double,const AGeometricObject*> res;
123 map<double,const AGeometricObject*> res2;
124
125 if (!m_vol2->isIn(P)) {
126 res = m_vol1->getClosestObjects(P,ival);
127 }
128 if (!m_vol1->isIn(P)) {
129 res2 = m_vol2->getClosestObjects(P,ival);
130 }
131
132 res.insert(res2.begin(), res2.end());
133
134 return res;
135 }
136
137 bool UnionVol::isIn(const Vector3& P) const
138 {
139 bool res = false;
140
141 if ((m_vol1->isIn(P)) || (m_vol2->isIn(P))) {
142 res = true;
143 }
144
145 return res;
146 }
147
148 bool UnionVol::isIn(const Sphere& S)
149 {
150 bool res = false;
151
152 if ((m_vol1->isIn(S)) || (m_vol2->isIn(S))) {
153 res = true;
154 }
155
156 return res;
157 }
158
159 /*!
160 Check if sphere is fully outside the volume. Tests if the sphere
161 is outside both subvolumes.
162
163 \param S the sphere
164 */
165 bool UnionVol::isFullyOutside(const Sphere& S)
166 {
167 return m_vol1->isFullyOutside(S) && m_vol2->isFullyOutside(S);
168 }
169
170 ostream& operator << (ostream& ost,const UnionVol& T)
171 {
172 return ost;
173 }