Geant4 Cross Reference |
1 // ******************************************* 1 // ******************************************************************** 2 // * License and Disclaimer 2 // * License and Disclaimer * 3 // * 3 // * * 4 // * The Geant4 software is copyright of th 4 // * The Geant4 software is copyright of the Copyright Holders of * 5 // * the Geant4 Collaboration. It is provided 5 // * the Geant4 Collaboration. It is provided under the terms and * 6 // * conditions of the Geant4 Software License 6 // * conditions of the Geant4 Software License, included in the file * 7 // * LICENSE and available at http://cern.ch/ 7 // * LICENSE and available at http://cern.ch/geant4/license . These * 8 // * include a list of copyright holders. 8 // * include a list of copyright holders. * 9 // * 9 // * * 10 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 11 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 12 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 13 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 14 // * use. Please see the license in the file 14 // * use. Please see the license in the file LICENSE and URL above * 15 // * for the full disclaimer and the limitatio 15 // * for the full disclaimer and the limitation of liability. * 16 // * 16 // * * 17 // * This code implementation is the result 17 // * This code implementation is the result of the scientific and * 18 // * technical work of the GEANT4 collaboratio 18 // * technical work of the GEANT4 collaboration. * 19 // * By using, copying, modifying or distri 19 // * By using, copying, modifying or distributing the software (or * 20 // * any work based on the software) you ag 20 // * any work based on the software) you agree to acknowledge its * 21 // * use in resulting scientific publicati 21 // * use in resulting scientific publications, and indicate your * 22 // * acceptance of all terms of the Geant4 Sof 22 // * acceptance of all terms of the Geant4 Software license. * 23 // ******************************************* 23 // ******************************************************************** 24 // 24 // 25 // 25 // 26 // Author: HoangTRAN, 20/2/2019 26 // Author: HoangTRAN, 20/2/2019 27 #include "G4DNABoundingBox.hh" 27 #include "G4DNABoundingBox.hh" 28 #include <array> 28 #include <array> 29 #include "G4UnitsTable.hh" 29 #include "G4UnitsTable.hh" 30 using std::array; 30 using std::array; 31 using std::initializer_list; 31 using std::initializer_list; 32 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 33 34 G4DNABoundingBox::G4DNABoundingBox(G4DNABoundi 34 G4DNABoundingBox::G4DNABoundingBox(G4DNABoundingBox&& rhs) noexcept 35 { 35 { 36 fxhi = rhs.fxhi; 36 fxhi = rhs.fxhi; 37 fxlo = rhs.fxlo; 37 fxlo = rhs.fxlo; 38 fyhi = rhs.fyhi; 38 fyhi = rhs.fyhi; 39 fylo = rhs.fylo; 39 fylo = rhs.fylo; 40 fzhi = rhs.fzhi; 40 fzhi = rhs.fzhi; 41 fzlo = rhs.fzlo; 41 fzlo = rhs.fzlo; 42 } 42 } 43 ////....oooOO0OOooo........oooOO0OOooo........ 43 ////....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 44 44 45 G4DNABoundingBox::G4DNABoundingBox(const initi 45 G4DNABoundingBox::G4DNABoundingBox(const initializer_list<G4double>& l) 46 { 46 { 47 fxhi = 0.; << 48 fxlo = 0.; << 49 fyhi = 0.; << 50 fylo = 0.; << 51 fzhi = 0.; << 52 fzlo = 0.; << 53 std::copy(l.begin(), l.end(), &fxhi); 47 std::copy(l.begin(), l.end(), &fxhi); 54 } 48 } 55 49 56 //....oooOO0OOooo........oooOO0OOooo........oo 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 51 58 G4DNABoundingBox& G4DNABoundingBox::operator=( 52 G4DNABoundingBox& G4DNABoundingBox::operator=(G4DNABoundingBox&& rhs) noexcept 59 { 53 { 60 fxhi = rhs.fxhi; 54 fxhi = rhs.fxhi; 61 fxlo = rhs.fxlo; 55 fxlo = rhs.fxlo; 62 fyhi = rhs.fyhi; 56 fyhi = rhs.fyhi; 63 fylo = rhs.fylo; 57 fylo = rhs.fylo; 64 fzhi = rhs.fzhi; 58 fzhi = rhs.fzhi; 65 fzlo = rhs.fzlo; 59 fzlo = rhs.fzlo; 66 return *this; 60 return *this; 67 } 61 } 68 62 69 G4double G4DNABoundingBox::Volume() const 63 G4double G4DNABoundingBox::Volume() const 70 { 64 { 71 auto LengthY = this->Getyhi() - this->Getylo 65 auto LengthY = this->Getyhi() - this->Getylo(); 72 auto LengthX = this->Getxhi() - this->Getxlo 66 auto LengthX = this->Getxhi() - this->Getxlo(); 73 auto LengthZ = this->Getzhi() - this->Getzlo 67 auto LengthZ = this->Getzhi() - this->Getzlo(); 74 G4double V = LengthY * LengthX * LengthZ; 68 G4double V = LengthY * LengthX * LengthZ; 75 return V; 69 return V; 76 } 70 } 77 71 78 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 79 73 80 void G4DNABoundingBox::resize(G4ThreeVector pi 74 void G4DNABoundingBox::resize(G4ThreeVector pics[8]) 81 { 75 { 82 for(size_t i = 0; i < 8; i++) 76 for(size_t i = 0; i < 8; i++) 83 { 77 { 84 const G4ThreeVector& point = pics[i]; 78 const G4ThreeVector& point = pics[i]; 85 if(point.x() < fxlo) 79 if(point.x() < fxlo) 86 { 80 { 87 fxlo = point.x(); 81 fxlo = point.x(); 88 } 82 } 89 if(point.x() > fxhi) 83 if(point.x() > fxhi) 90 { 84 { 91 fxhi = point.x(); 85 fxhi = point.x(); 92 } 86 } 93 87 94 if(point.y() < fylo) 88 if(point.y() < fylo) 95 { 89 { 96 fylo = point.y(); 90 fylo = point.y(); 97 } 91 } 98 if(point.y() > fyhi) 92 if(point.y() > fyhi) 99 { 93 { 100 fyhi = point.y(); 94 fyhi = point.y(); 101 } 95 } 102 96 103 if(point.z() < fzlo) 97 if(point.z() < fzlo) 104 { 98 { 105 fzlo = point.z(); 99 fzlo = point.z(); 106 } 100 } 107 if(point.z() > fzhi) 101 if(point.z() > fzhi) 108 { 102 { 109 fzhi = point.z(); 103 fzhi = point.z(); 110 } 104 } 111 } 105 } 112 } 106 } 113 107 114 //-------------------------------------------- 108 //------------------------------------------------------------------------------ 115 109 116 G4DNABoundingBox G4DNABoundingBox::translate(c 110 G4DNABoundingBox G4DNABoundingBox::translate(const G4ThreeVector& trans) const 117 { 111 { 118 G4DNABoundingBox output; 112 G4DNABoundingBox output; 119 113 120 output.fxhi = fxhi + trans.x(); 114 output.fxhi = fxhi + trans.x(); 121 output.fxlo = fxlo + trans.x(); 115 output.fxlo = fxlo + trans.x(); 122 116 123 output.fyhi = fyhi + trans.y(); 117 output.fyhi = fyhi + trans.y(); 124 output.fylo = fylo + trans.x(); 118 output.fylo = fylo + trans.x(); 125 119 126 output.fzhi = fzhi + trans.z(); 120 output.fzhi = fzhi + trans.z(); 127 output.fzlo = fzlo + trans.z(); 121 output.fzlo = fzlo + trans.z(); 128 122 129 return output; 123 return output; 130 } 124 } 131 //....oooOO0OOooo........oooOO0OOooo........oo 125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 132 126 133 G4bool G4DNABoundingBox::contains(const G4DNAB 127 G4bool G4DNABoundingBox::contains(const G4DNABoundingBox& other) const 134 { 128 { 135 return fxlo <= other.fxlo && fxhi >= other.f 129 return fxlo <= other.fxlo && fxhi >= other.fxhi && fylo <= other.fylo && 136 fyhi >= other.fyhi && fzlo <= other.f 130 fyhi >= other.fyhi && fzlo <= other.fzlo && fzhi >= other.fzhi; 137 } 131 } 138 132 139 //....oooOO0OOooo........oooOO0OOooo........oo 133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 140 134 141 G4bool G4DNABoundingBox::contains(const G4Thre 135 G4bool G4DNABoundingBox::contains(const G4ThreeVector& point) const 142 { 136 { 143 return fxlo <= point.x() && fxhi >= point.x( 137 return fxlo <= point.x() && fxhi >= point.x() && fylo <= point.y() && 144 fyhi >= point.y() && fzlo <= point.z( 138 fyhi >= point.y() && fzlo <= point.z() && fzhi >= point.z(); 145 } 139 } 146 140 147 //....oooOO0OOooo........oooOO0OOooo........oo 141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 148 142 149 G4bool G4DNABoundingBox::overlap(const G4DNABo 143 G4bool G4DNABoundingBox::overlap(const G4DNABoundingBox& other, 150 G4DNABounding 144 G4DNABoundingBox* out) const 151 { 145 { 152 if(contains(other)) 146 if(contains(other)) 153 { 147 { 154 *out = other; 148 *out = other; 155 return true; 149 return true; 156 } 150 } 157 if(other.contains(*this)) << 151 else if(other.contains(*this)) 158 { 152 { 159 *out = *this; 153 *out = *this; 160 return true; 154 return true; 161 } 155 } 162 156 163 // Check if there is no intersection 157 // Check if there is no intersection 164 if(fxhi < other.fxlo || fxlo > other.fxhi || 158 if(fxhi < other.fxlo || fxlo > other.fxhi || fyhi < other.fylo || 165 fylo > other.fyhi || fzhi < other.fzlo || 159 fylo > other.fyhi || fzhi < other.fzlo || fzlo > other.fzhi) 166 { 160 { 167 *out = invalid; 161 *out = invalid; 168 return false; 162 return false; 169 } 163 } 170 164 171 G4double upperX = std::min(fxhi, other.fxhi) 165 G4double upperX = std::min(fxhi, other.fxhi); 172 G4double upperY = std::min(fyhi, other.fyhi) 166 G4double upperY = std::min(fyhi, other.fyhi); 173 G4double upperZ = std::min(fzhi, other.fzhi) 167 G4double upperZ = std::min(fzhi, other.fzhi); 174 168 175 G4double lowerX = std::max(fxlo, other.fxlo) 169 G4double lowerX = std::max(fxlo, other.fxlo); 176 G4double lowerY = std::max(fylo, other.fylo) 170 G4double lowerY = std::max(fylo, other.fylo); 177 G4double lowerZ = std::max(fzlo, other.fzlo) 171 G4double lowerZ = std::max(fzlo, other.fzlo); 178 172 179 *out = G4DNABoundingBox{ upperX, lowerX, upp 173 *out = G4DNABoundingBox{ upperX, lowerX, upperY, lowerY, upperZ, lowerZ }; 180 return true; 174 return true; 181 } 175 } 182 176 183 //....oooOO0OOooo........oooOO0OOooo........oo 177 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 184 178 185 G4bool G4DNABoundingBox::overlap(const G4Three 179 G4bool G4DNABoundingBox::overlap(const G4ThreeVector& query, 186 const G4doubl 180 const G4double& Radius) const 187 { 181 { 188 G4double x = query.x() - this->middlePoint() 182 G4double x = query.x() - this->middlePoint().x(); 189 G4double y = query.y() - this->middlePoint() 183 G4double y = query.y() - this->middlePoint().y(); 190 G4double z = query.z() - this->middlePoint() 184 G4double z = query.z() - this->middlePoint().z(); 191 185 192 x = std::abs(x); 186 x = std::abs(x); 193 y = std::abs(y); 187 y = std::abs(y); 194 z = std::abs(z); 188 z = std::abs(z); 195 189 196 if((x > (Radius + this->halfSideLengthInX()) 190 if((x > (Radius + this->halfSideLengthInX())) || 197 (y > (Radius + this->halfSideLengthInY()) 191 (y > (Radius + this->halfSideLengthInY())) || 198 (z > (Radius + this->halfSideLengthInZ()) 192 (z > (Radius + this->halfSideLengthInZ()))) 199 { 193 { 200 return false; // 194 return false; // 201 } 195 } 202 G4int num_less_extent = static_cast<int>(x < << 196 G4int num_less_extent = (x < this->halfSideLengthInX()) + 203 static_cast<int>(y < << 197 (y < this->halfSideLengthInY()) + 204 static_cast<int>(z < << 198 (z < this->halfSideLengthInZ()); 205 199 206 if(num_less_extent > 1) 200 if(num_less_extent > 1) 207 { 201 { 208 return true; 202 return true; 209 } 203 } 210 204 211 x = std::max(x - this->halfSideLengthInX(), 205 x = std::max(x - this->halfSideLengthInX(), 0.0); 212 y = std::max(y - this->halfSideLengthInY(), 206 y = std::max(y - this->halfSideLengthInY(), 0.0); 213 z = std::max(z - this->halfSideLengthInZ(), 207 z = std::max(z - this->halfSideLengthInZ(), 0.0); 214 208 215 G4double norm = std::sqrt(x * x + y * y + z 209 G4double norm = std::sqrt(x * x + y * y + z * z); 216 210 217 return (norm < Radius); 211 return (norm < Radius); 218 } 212 } 219 //....oooOO0OOooo........oooOO0OOooo........oo 213 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 220 214 221 G4bool G4DNABoundingBox::contains(const G4Thre 215 G4bool G4DNABoundingBox::contains(const G4ThreeVector& query, 222 const G4doub 216 const G4double& Radius) const 223 { 217 { 224 G4ThreeVector temp = query - this->middlePoi 218 G4ThreeVector temp = query - this->middlePoint(); 225 G4double x = std::abs(temp.x()) + th 219 G4double x = std::abs(temp.x()) + this->halfSideLengthInX(); 226 G4double y = std::abs(temp.y()) + th 220 G4double y = std::abs(temp.y()) + this->halfSideLengthInY(); 227 G4double z = std::abs(temp.z()) + th 221 G4double z = std::abs(temp.z()) + this->halfSideLengthInZ(); 228 G4double norm = std::sqrt(x * x + y * y 222 G4double norm = std::sqrt(x * x + y * y + z * z); 229 return (norm < Radius); 223 return (norm < Radius); 230 } 224 } 231 //....oooOO0OOooo........oooOO0OOooo........oo 225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 232 226 233 G4bool G4DNABoundingBox::contains(const G4Thre 227 G4bool G4DNABoundingBox::contains(const G4ThreeVector& query, 234 const G4Thre 228 const G4ThreeVector& Point, 235 const G4doub 229 const G4double& Radius) const 236 { 230 { 237 return (((query - Point).mag()) < Radius); 231 return (((query - Point).mag()) < Radius); 238 } 232 } 239 233 240 //....oooOO0OOooo........oooOO0OOooo........oo 234 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 241 235 242 array<G4DNABoundingBox, 8> G4DNABoundingBox::p 236 array<G4DNABoundingBox, 8> G4DNABoundingBox::partition() const 243 { 237 { 244 G4double xmid = (fxhi + fxlo) / 2.; 238 G4double xmid = (fxhi + fxlo) / 2.; 245 G4double ymid = (fyhi + fylo) / 2.; 239 G4double ymid = (fyhi + fylo) / 2.; 246 G4double zmid = (fzhi + fzlo) / 2.; 240 G4double zmid = (fzhi + fzlo) / 2.; 247 241 248 std::array<G4DNABoundingBox, 8> ret{ { 242 std::array<G4DNABoundingBox, 8> ret{ { 249 G4DNABoundingBox{ xmid, fxlo, ymid, fylo, 243 G4DNABoundingBox{ xmid, fxlo, ymid, fylo, zmid, 250 fzlo }, // bottom left 244 fzlo }, // bottom left front 251 G4DNABoundingBox{ fxhi, xmid, ymid, fylo, 245 G4DNABoundingBox{ fxhi, xmid, ymid, fylo, zmid, 252 fzlo }, // bottom right 246 fzlo }, // bottom right front 253 G4DNABoundingBox{ xmid, fxlo, fyhi, ymid, 247 G4DNABoundingBox{ xmid, fxlo, fyhi, ymid, zmid, fzlo }, // bottom left back 254 G4DNABoundingBox{ fxhi, xmid, fyhi, ymid, 248 G4DNABoundingBox{ fxhi, xmid, fyhi, ymid, zmid, 255 fzlo }, // bottom right 249 fzlo }, // bottom right back 256 G4DNABoundingBox{ xmid, fxlo, ymid, fylo, 250 G4DNABoundingBox{ xmid, fxlo, ymid, fylo, fzhi, zmid }, // top left front 257 G4DNABoundingBox{ fxhi, xmid, ymid, fylo, 251 G4DNABoundingBox{ fxhi, xmid, ymid, fylo, fzhi, zmid }, // top right front 258 G4DNABoundingBox{ xmid, fxlo, fyhi, ymid, 252 G4DNABoundingBox{ xmid, fxlo, fyhi, ymid, fzhi, zmid }, // top left back 259 G4DNABoundingBox{ fxhi, xmid, fyhi, ymid, 253 G4DNABoundingBox{ fxhi, xmid, fyhi, ymid, fzhi, zmid } // top right back 260 } }; 254 } }; 261 return ret; 255 return ret; 262 } 256 } 263 //....oooOO0OOooo........oooOO0OOooo........oo 257 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 264 258 265 G4bool G4DNABoundingBox::operator==(const G4DN 259 G4bool G4DNABoundingBox::operator==(const G4DNABoundingBox& rhs) const 266 { 260 { 267 return (fxhi == rhs.fxhi && fxlo == rhs.fxlo 261 return (fxhi == rhs.fxhi && fxlo == rhs.fxlo && fyhi == rhs.fyhi && 268 fylo == rhs.fylo && fzhi == rhs.fzhi 262 fylo == rhs.fylo && fzhi == rhs.fzhi && fzlo == rhs.fzlo) || 269 (std::isnan(fxhi) && std::isnan(rhs.f 263 (std::isnan(fxhi) && std::isnan(rhs.fxhi) && std::isnan(fxlo) && 270 std::isnan(rhs.fxlo) && std::isnan(f 264 std::isnan(rhs.fxlo) && std::isnan(fyhi) && std::isnan(rhs.fyhi) && 271 std::isnan(fylo) && std::isnan(rhs.f 265 std::isnan(fylo) && std::isnan(rhs.fylo) && std::isnan(fzhi) && 272 std::isnan(rhs.fzhi) && std::isnan(f 266 std::isnan(rhs.fzhi) && std::isnan(fzlo) && std::isnan(rhs.fzlo)); 273 } 267 } 274 268 275 G4bool G4DNABoundingBox::operator!=(const G4DN 269 G4bool G4DNABoundingBox::operator!=(const G4DNABoundingBox& rhs) const 276 { 270 { 277 return !operator==(rhs); 271 return !operator==(rhs); 278 } 272 } 279 //....oooOO0OOooo........oooOO0OOooo........oo 273 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 280 274 281 std::ostream& operator<<(std::ostream& stream, 275 std::ostream& operator<<(std::ostream& stream, const G4DNABoundingBox& rhs) 282 { 276 { 283 stream << "{" << G4BestUnit(rhs.fxhi, "Lengt 277 stream << "{" << G4BestUnit(rhs.fxhi, "Length") << ", " 284 << G4BestUnit(rhs.fxlo, "Length") << 278 << G4BestUnit(rhs.fxlo, "Length") << ", " 285 << G4BestUnit(rhs.fyhi, "Length") << 279 << G4BestUnit(rhs.fyhi, "Length") << ", " 286 << G4BestUnit(rhs.fylo, "Length") << 280 << G4BestUnit(rhs.fylo, "Length") << ", " 287 << G4BestUnit(rhs.fzhi, "Length") << 281 << G4BestUnit(rhs.fzhi, "Length") << ", " 288 << G4BestUnit(rhs.fzlo, "Length") << 282 << G4BestUnit(rhs.fzlo, "Length") << ", " 289 << "}"; 283 << "}"; 290 return stream; 284 return stream; 291 } 285 } 292 286