Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // >> 27 // $Id: G4IntersectionSolid.cc 66356 2012-12-18 09:02:32Z gcosmo $ >> 28 // 26 // Implementation of methods for the class G4I 29 // Implementation of methods for the class G4IntersectionSolid 27 // 30 // >> 31 // History: >> 32 // >> 33 // 17.02.05 V.Grichine: bug was fixed in DistanceToIn(p,v) based on algorithm >> 34 // proposed by Dino Bazzacco <dino.bazzacco@pd.infn.it> >> 35 // 29.05.01 V.Grichine: bug was fixed in DistanceToIn(p,v) >> 36 // 16.03.01 V.Grichine: modifications in CalculateExtent() and Inside() >> 37 // 29.07.99 V.Grichine: modifications in DistanceToIn(p,v) 28 // 12.09.98 V.Grichine: first implementation 38 // 12.09.98 V.Grichine: first implementation >> 39 // 29 // ------------------------------------------- 40 // -------------------------------------------------------------------- 30 41 >> 42 31 #include <sstream> 43 #include <sstream> 32 44 33 #include "G4IntersectionSolid.hh" 45 #include "G4IntersectionSolid.hh" 34 46 35 #include "G4SystemOfUnits.hh" 47 #include "G4SystemOfUnits.hh" 36 #include "G4VoxelLimits.hh" 48 #include "G4VoxelLimits.hh" 37 #include "G4VPVParameterisation.hh" 49 #include "G4VPVParameterisation.hh" 38 50 39 #include "G4VGraphicsScene.hh" 51 #include "G4VGraphicsScene.hh" 40 #include "G4Polyhedron.hh" 52 #include "G4Polyhedron.hh" 41 #include "G4PolyhedronArbitrary.hh" << 42 #include "HepPolyhedronProcessor.h" 53 #include "HepPolyhedronProcessor.h" 43 54 44 ////////////////////////////////////////////// << 55 ///////////////////////////////////////////////////////////////////// 45 // 56 // 46 // Transfer all data members to G4BooleanSolid 57 // Transfer all data members to G4BooleanSolid which is responsible 47 // for them. pName will be in turn sent to G4V 58 // for them. pName will be in turn sent to G4VSolid 48 // 59 // 49 60 50 G4IntersectionSolid::G4IntersectionSolid( cons 61 G4IntersectionSolid::G4IntersectionSolid( const G4String& pName, 51 62 G4VSolid* pSolidA , 52 63 G4VSolid* pSolidB ) 53 : G4BooleanSolid(pName,pSolidA,pSolidB) 64 : G4BooleanSolid(pName,pSolidA,pSolidB) 54 { 65 { 55 } 66 } 56 67 57 ////////////////////////////////////////////// << 68 /////////////////////////////////////////////////////////////////// 58 // 69 // 59 70 60 G4IntersectionSolid::G4IntersectionSolid( cons 71 G4IntersectionSolid::G4IntersectionSolid( const G4String& pName, 61 72 G4VSolid* pSolidA, 62 73 G4VSolid* pSolidB, 63 74 G4RotationMatrix* rotMatrix, 64 cons 75 const G4ThreeVector& transVector ) 65 : G4BooleanSolid(pName,pSolidA,pSolidB,rotMa 76 : G4BooleanSolid(pName,pSolidA,pSolidB,rotMatrix,transVector) 66 { 77 { 67 } 78 } 68 79 69 ////////////////////////////////////////////// << 80 ////////////////////////////////////////////////////////////////// 70 // 81 // 71 // 82 // 72 83 73 G4IntersectionSolid::G4IntersectionSolid( cons 84 G4IntersectionSolid::G4IntersectionSolid( const G4String& pName, 74 85 G4VSolid* pSolidA, 75 86 G4VSolid* pSolidB, 76 cons 87 const G4Transform3D& transform ) 77 : G4BooleanSolid(pName,pSolidA,pSolidB,trans 88 : G4BooleanSolid(pName,pSolidA,pSolidB,transform) 78 { 89 { 79 } 90 } 80 91 81 ////////////////////////////////////////////// << 92 ////////////////////////////////////////////////////////////////// 82 // 93 // 83 // Fake default constructor - sets only member 94 // Fake default constructor - sets only member data and allocates memory 84 // for usage restri 95 // for usage restricted to object persistency. 85 96 86 G4IntersectionSolid::G4IntersectionSolid( __vo 97 G4IntersectionSolid::G4IntersectionSolid( __void__& a ) 87 : G4BooleanSolid(a) 98 : G4BooleanSolid(a) 88 { 99 { 89 } 100 } 90 101 91 ////////////////////////////////////////////// << 102 /////////////////////////////////////////////////////////////// 92 // 103 // 93 // 104 // 94 105 95 G4IntersectionSolid::~G4IntersectionSolid() = << 106 G4IntersectionSolid::~G4IntersectionSolid() >> 107 { >> 108 } 96 109 97 ////////////////////////////////////////////// << 110 /////////////////////////////////////////////////////////////// 98 // 111 // 99 // Copy constructor 112 // Copy constructor 100 113 101 G4IntersectionSolid::G4IntersectionSolid(const << 114 G4IntersectionSolid::G4IntersectionSolid(const G4IntersectionSolid& rhs) >> 115 : G4BooleanSolid (rhs) >> 116 { >> 117 } 102 118 103 ////////////////////////////////////////////// << 119 /////////////////////////////////////////////////////////////// 104 // 120 // 105 // Assignment operator 121 // Assignment operator 106 122 107 G4IntersectionSolid& 123 G4IntersectionSolid& 108 G4IntersectionSolid::operator = (const G4Inter 124 G4IntersectionSolid::operator = (const G4IntersectionSolid& rhs) 109 { 125 { 110 // Check assignment to self 126 // Check assignment to self 111 // 127 // 112 if (this == &rhs) { return *this; } 128 if (this == &rhs) { return *this; } 113 129 114 // Copy base class data 130 // Copy base class data 115 // 131 // 116 G4BooleanSolid::operator=(rhs); 132 G4BooleanSolid::operator=(rhs); 117 133 118 return *this; 134 return *this; 119 } 135 } 120 136 121 ////////////////////////////////////////////// << 137 /////////////////////////////////////////////////////////////// 122 // 138 // 123 // Get bounding box << 124 << 125 void << 126 G4IntersectionSolid::BoundingLimits(G4ThreeVec << 127 G4ThreeVec << 128 { << 129 G4ThreeVector minA,maxA, minB,maxB; << 130 fPtrSolidA->BoundingLimits(minA,maxA); << 131 fPtrSolidB->BoundingLimits(minB,maxB); << 132 << 133 pMin.set(std::max(minA.x(),minB.x()), << 134 std::max(minA.y(),minB.y()), << 135 std::max(minA.z(),minB.z())); << 136 << 137 pMax.set(std::min(maxA.x(),maxB.x()), << 138 std::min(maxA.y(),maxB.y()), << 139 std::min(maxA.z(),maxB.z())); << 140 << 141 // Check correctness of the bounding box << 142 // << 143 if (pMin.x() >= pMax.x() || pMin.y() >= pMax << 144 { << 145 std::ostringstream message; << 146 message << "Bad bounding box (min >= max) << 147 << GetName() << " !" << 148 << "\npMin = " << pMin << 149 << "\npMax = " << pMax; << 150 G4Exception("G4IntersectionSolid::Bounding << 151 JustWarning, message); << 152 DumpInfo(); << 153 } << 154 } << 155 << 156 ////////////////////////////////////////////// << 157 // 139 // 158 // Calculate extent under transform and specif << 159 140 160 G4bool 141 G4bool 161 G4IntersectionSolid::CalculateExtent(const EAx 142 G4IntersectionSolid::CalculateExtent(const EAxis pAxis, 162 const G4V 143 const G4VoxelLimits& pVoxelLimit, 163 const G4A 144 const G4AffineTransform& pTransform, 164 G4d 145 G4double& pMin, 165 G4d 146 G4double& pMax) const 166 { 147 { 167 G4bool retA, retB, out; 148 G4bool retA, retB, out; 168 G4double minA, minB, maxA, maxB; 149 G4double minA, minB, maxA, maxB; 169 150 170 retA = fPtrSolidA 151 retA = fPtrSolidA 171 ->CalculateExtent( pAxis, pVoxelLimi 152 ->CalculateExtent( pAxis, pVoxelLimit, pTransform, minA, maxA); 172 retB = fPtrSolidB 153 retB = fPtrSolidB 173 ->CalculateExtent( pAxis, pVoxelLimi 154 ->CalculateExtent( pAxis, pVoxelLimit, pTransform, minB, maxB); 174 155 175 if( retA && retB ) 156 if( retA && retB ) 176 { 157 { 177 pMin = std::max( minA, minB ); 158 pMin = std::max( minA, minB ); 178 pMax = std::min( maxA, maxB ); 159 pMax = std::min( maxA, maxB ); 179 out = (pMax > pMin); // true; 160 out = (pMax > pMin); // true; >> 161 #ifdef G4BOOLDEBUG >> 162 // G4cout.precision(16); >> 163 // G4cout<<"pMin = "<<pMin<<"; pMax = "<<pMax<<G4endl; >> 164 #endif 180 } 165 } 181 else << 166 else out = false; 182 { << 183 out = false; << 184 } << 185 167 186 return out; // It exists in this slice only 168 return out; // It exists in this slice only if both exist in it. 187 } 169 } 188 170 189 ////////////////////////////////////////////// << 171 ///////////////////////////////////////////////////// 190 // 172 // 191 // Touching ? Empty intersection ? 173 // Touching ? Empty intersection ? 192 174 193 EInside G4IntersectionSolid::Inside(const G4Th 175 EInside G4IntersectionSolid::Inside(const G4ThreeVector& p) const 194 { 176 { 195 EInside positionA = fPtrSolidA->Inside(p); << 177 EInside positionA = fPtrSolidA->Inside(p) ; 196 if(positionA == kOutside) return positionA; << 197 178 198 EInside positionB = fPtrSolidB->Inside(p); << 179 if( positionA == kOutside ) return kOutside ; 199 if(positionA == kInside) return positionB; << 200 180 201 if(positionB == kOutside) return positionB; << 181 EInside positionB = fPtrSolidB->Inside(p) ; 202 return kSurface; << 182 >> 183 if(positionA == kInside && positionB == kInside) >> 184 { >> 185 return kInside ; >> 186 } >> 187 else >> 188 { >> 189 if((positionA == kInside && positionB == kSurface) || >> 190 (positionB == kInside && positionA == kSurface) || >> 191 (positionA == kSurface && positionB == kSurface) ) >> 192 { >> 193 return kSurface ; >> 194 } >> 195 else >> 196 { >> 197 return kOutside ; >> 198 } >> 199 } 203 } 200 } 204 201 205 ////////////////////////////////////////////// << 202 ////////////////////////////////////////////////////////////// 206 // 203 // 207 204 208 G4ThreeVector 205 G4ThreeVector 209 G4IntersectionSolid::SurfaceNormal( const G4Th 206 G4IntersectionSolid::SurfaceNormal( const G4ThreeVector& p ) const 210 { 207 { 211 G4ThreeVector normal; 208 G4ThreeVector normal; 212 EInside insideA, insideB; 209 EInside insideA, insideB; 213 210 214 insideA = fPtrSolidA->Inside(p); << 211 insideA= fPtrSolidA->Inside(p); 215 insideB = fPtrSolidB->Inside(p); << 212 insideB= fPtrSolidB->Inside(p); 216 213 217 #ifdef G4BOOLDEBUG 214 #ifdef G4BOOLDEBUG 218 if( (insideA == kOutside) || (insideB == kOu 215 if( (insideA == kOutside) || (insideB == kOutside) ) 219 { 216 { 220 G4cout << "WARNING - Invalid call in " 217 G4cout << "WARNING - Invalid call in " 221 << "G4IntersectionSolid::SurfaceNor 218 << "G4IntersectionSolid::SurfaceNormal(p)" << G4endl 222 << " Point p is outside !" << G4en 219 << " Point p is outside !" << G4endl; 223 G4cout << " p = " << p << G4endl; 220 G4cout << " p = " << p << G4endl; 224 G4cerr << "WARNING - Invalid call in " 221 G4cerr << "WARNING - Invalid call in " 225 << "G4IntersectionSolid::SurfaceNor 222 << "G4IntersectionSolid::SurfaceNormal(p)" << G4endl 226 << " Point p is outside !" << G4en 223 << " Point p is outside !" << G4endl; 227 G4cerr << " p = " << p << G4endl; 224 G4cerr << " p = " << p << G4endl; 228 } 225 } 229 #endif 226 #endif 230 227 >> 228 // OLD: if(fPtrSolidA->DistanceToOut(p) <= fPtrSolidB->DistanceToOut(p) ) >> 229 231 // On the surface of both is difficult ... t 230 // On the surface of both is difficult ... treat it like on A now! 232 // 231 // >> 232 // if( (insideA == kSurface) && (insideB == kSurface) ) >> 233 // normal= fPtrSolidA->SurfaceNormal(p) ; >> 234 // else 233 if( insideA == kSurface ) 235 if( insideA == kSurface ) 234 { << 235 normal = fPtrSolidA->SurfaceNormal(p) ; << 236 } << 237 else if( insideB == kSurface ) << 238 { << 239 normal = fPtrSolidB->SurfaceNormal(p) ; << 240 } << 241 else // We are on neither surface, so we sh << 242 { << 243 if(fPtrSolidA->DistanceToOut(p) <= fPtrSol << 244 { << 245 normal= fPtrSolidA->SurfaceNormal(p) ; << 246 } << 247 else << 248 { 236 { 249 normal= fPtrSolidB->SurfaceNormal(p) ; << 237 normal= fPtrSolidA->SurfaceNormal(p) ; 250 } 238 } >> 239 else if( insideB == kSurface ) >> 240 { >> 241 normal= fPtrSolidB->SurfaceNormal(p) ; >> 242 } >> 243 // We are on neither surface, so we should generate an exception >> 244 else >> 245 { >> 246 if(fPtrSolidA->DistanceToOut(p) <= fPtrSolidB->DistanceToOut(p) ) >> 247 normal= fPtrSolidA->SurfaceNormal(p) ; >> 248 else >> 249 normal= fPtrSolidB->SurfaceNormal(p) ; 251 #ifdef G4BOOLDEBUG 250 #ifdef G4BOOLDEBUG 252 G4cout << "WARNING - Invalid call in " << 251 G4cout << "WARNING - Invalid call in " 253 << "G4IntersectionSolid::SurfaceNor << 252 << "G4IntersectionSolid::SurfaceNormal(p)" << G4endl 254 << " Point p is out of surface !" << 253 << " Point p is out of surface !" << G4endl; 255 G4cout << " p = " << p << G4endl; << 254 G4cout << " p = " << p << G4endl; 256 G4cerr << "WARNING - Invalid call in " << 255 G4cerr << "WARNING - Invalid call in " 257 << "G4IntersectionSolid::SurfaceNor << 256 << "G4IntersectionSolid::SurfaceNormal(p)" << G4endl 258 << " Point p is out of surface !" << 257 << " Point p is out of surface !" << G4endl; 259 G4cerr << " p = " << p << G4endl; << 258 G4cerr << " p = " << p << G4endl; 260 #endif 259 #endif 261 } 260 } 262 261 263 return normal; 262 return normal; 264 } 263 } 265 264 266 ////////////////////////////////////////////// << 265 ///////////////////////////////////////////////////////////// 267 // 266 // 268 // The same algorithm as in DistanceToIn(p) 267 // The same algorithm as in DistanceToIn(p) 269 268 270 G4double 269 G4double 271 G4IntersectionSolid::DistanceToIn( const G4Thr 270 G4IntersectionSolid::DistanceToIn( const G4ThreeVector& p, 272 const G4Thr 271 const G4ThreeVector& v ) const 273 { 272 { 274 G4double dist = 0.0; 273 G4double dist = 0.0; 275 if( Inside(p) == kInside ) 274 if( Inside(p) == kInside ) 276 { 275 { 277 #ifdef G4BOOLDEBUG 276 #ifdef G4BOOLDEBUG 278 G4cout << "WARNING - Invalid call in " 277 G4cout << "WARNING - Invalid call in " 279 << "G4IntersectionSolid::DistanceTo 278 << "G4IntersectionSolid::DistanceToIn(p,v)" << G4endl 280 << " Point p is inside !" << G4end 279 << " Point p is inside !" << G4endl; 281 G4cout << " p = " << p << G4endl; 280 G4cout << " p = " << p << G4endl; 282 G4cout << " v = " << v << G4endl; 281 G4cout << " v = " << v << G4endl; 283 G4cerr << "WARNING - Invalid call in " 282 G4cerr << "WARNING - Invalid call in " 284 << "G4IntersectionSolid::DistanceTo 283 << "G4IntersectionSolid::DistanceToIn(p,v)" << G4endl 285 << " Point p is inside !" << G4end 284 << " Point p is inside !" << G4endl; 286 G4cerr << " p = " << p << G4endl; 285 G4cerr << " p = " << p << G4endl; 287 G4cerr << " v = " << v << G4endl; 286 G4cerr << " v = " << v << G4endl; 288 #endif 287 #endif 289 } 288 } 290 else // if( Inside(p) == kSurface ) 289 else // if( Inside(p) == kSurface ) 291 { 290 { 292 EInside wA = fPtrSolidA->Inside(p); 291 EInside wA = fPtrSolidA->Inside(p); 293 EInside wB = fPtrSolidB->Inside(p); 292 EInside wB = fPtrSolidB->Inside(p); 294 293 295 G4ThreeVector pA = p, pB = p; 294 G4ThreeVector pA = p, pB = p; 296 G4double dA = 0., dA1=0., dA2=0.; 295 G4double dA = 0., dA1=0., dA2=0.; 297 G4double dB = 0., dB1=0., dB2=0.; 296 G4double dB = 0., dB1=0., dB2=0.; 298 G4bool doA = true, doB = true; 297 G4bool doA = true, doB = true; 299 298 300 static const std::size_t max_trials=10000; << 299 while(true) 301 for (std::size_t trial=0; trial<max_trials << 302 { 300 { 303 if(doA) 301 if(doA) 304 { 302 { 305 // find next valid range for A 303 // find next valid range for A 306 304 307 dA1 = 0.; 305 dA1 = 0.; 308 306 309 if( wA != kInside ) 307 if( wA != kInside ) 310 { 308 { 311 dA1 = fPtrSolidA->DistanceToIn(pA, v 309 dA1 = fPtrSolidA->DistanceToIn(pA, v); 312 310 313 if( dA1 == kInfinity ) return kInf 311 if( dA1 == kInfinity ) return kInfinity; 314 312 315 pA += dA1*v; 313 pA += dA1*v; 316 } 314 } 317 dA2 = dA1 + fPtrSolidA->DistanceToOut( 315 dA2 = dA1 + fPtrSolidA->DistanceToOut(pA, v); 318 } 316 } 319 dA1 += dA; 317 dA1 += dA; 320 dA2 += dA; 318 dA2 += dA; 321 319 322 if(doB) 320 if(doB) 323 { 321 { 324 // find next valid range for B 322 // find next valid range for B 325 323 326 dB1 = 0.; 324 dB1 = 0.; 327 if(wB != kInside) 325 if(wB != kInside) 328 { 326 { 329 dB1 = fPtrSolidB->DistanceToIn(pB, v 327 dB1 = fPtrSolidB->DistanceToIn(pB, v); 330 328 331 if(dB1 == kInfinity) return kInfin 329 if(dB1 == kInfinity) return kInfinity; 332 330 333 pB += dB1*v; 331 pB += dB1*v; 334 } 332 } 335 dB2 = dB1 + fPtrSolidB->DistanceToOut( 333 dB2 = dB1 + fPtrSolidB->DistanceToOut(pB, v); 336 } 334 } 337 dB1 += dB; 335 dB1 += dB; 338 dB2 += dB; 336 dB2 += dB; 339 337 340 // check if they overlap 338 // check if they overlap 341 339 342 if( dA1 < dB1 ) 340 if( dA1 < dB1 ) 343 { 341 { 344 if( dB1 < dA2 ) return dB1; 342 if( dB1 < dA2 ) return dB1; 345 343 346 dA = dA2; 344 dA = dA2; 347 pA = p + dA*v; // continue from her 345 pA = p + dA*v; // continue from here 348 wA = kSurface; 346 wA = kSurface; 349 doA = true; 347 doA = true; 350 doB = false; 348 doB = false; 351 } 349 } 352 else 350 else 353 { 351 { 354 if( dA1 < dB2 ) return dA1; 352 if( dA1 < dB2 ) return dA1; 355 353 356 dB = dB2; 354 dB = dB2; 357 pB = p + dB*v; // continue from her 355 pB = p + dB*v; // continue from here 358 wB = kSurface; 356 wB = kSurface; 359 doB = true; 357 doB = true; 360 doA = false; 358 doA = false; 361 } 359 } 362 } 360 } 363 } 361 } 364 #ifdef G4BOOLDEBUG << 365 G4Exception("G4IntersectionSolid::DistanceTo << 366 "GeomSolids0001", JustWarning, << 367 "Reached maximum number of itera << 368 #endif << 369 return dist ; 362 return dist ; 370 } 363 } 371 364 372 ////////////////////////////////////////////// << 365 //////////////////////////////////////////////////////// 373 // 366 // 374 // Approximate nearest distance from the point 367 // Approximate nearest distance from the point p to the intersection of 375 // two solids 368 // two solids 376 369 377 G4double 370 G4double 378 G4IntersectionSolid::DistanceToIn( const G4Thr 371 G4IntersectionSolid::DistanceToIn( const G4ThreeVector& p) const 379 { 372 { 380 #ifdef G4BOOLDEBUG 373 #ifdef G4BOOLDEBUG 381 if( Inside(p) == kInside ) 374 if( Inside(p) == kInside ) 382 { 375 { 383 G4cout << "WARNING - Invalid call in " 376 G4cout << "WARNING - Invalid call in " 384 << "G4IntersectionSolid::DistanceTo 377 << "G4IntersectionSolid::DistanceToIn(p)" << G4endl 385 << " Point p is inside !" << G4end 378 << " Point p is inside !" << G4endl; 386 G4cout << " p = " << p << G4endl; 379 G4cout << " p = " << p << G4endl; 387 G4cerr << "WARNING - Invalid call in " 380 G4cerr << "WARNING - Invalid call in " 388 << "G4IntersectionSolid::DistanceTo 381 << "G4IntersectionSolid::DistanceToIn(p)" << G4endl 389 << " Point p is inside !" << G4end 382 << " Point p is inside !" << G4endl; 390 G4cerr << " p = " << p << G4endl; 383 G4cerr << " p = " << p << G4endl; 391 } 384 } 392 #endif 385 #endif 393 EInside sideA = fPtrSolidA->Inside(p) ; 386 EInside sideA = fPtrSolidA->Inside(p) ; 394 EInside sideB = fPtrSolidB->Inside(p) ; 387 EInside sideB = fPtrSolidB->Inside(p) ; 395 G4double dist=0.0 ; 388 G4double dist=0.0 ; 396 389 397 if( sideA != kInside && sideB != kOutside ) << 390 if( sideA != kInside && sideB != kOutside ) 398 { 391 { 399 dist = fPtrSolidA->DistanceToIn(p) ; 392 dist = fPtrSolidA->DistanceToIn(p) ; 400 } 393 } 401 else 394 else 402 { 395 { 403 if( sideB != kInside && sideA != kOutside << 396 if( sideB != kInside && sideA != kOutside ) 404 { 397 { 405 dist = fPtrSolidB->DistanceToIn(p) ; 398 dist = fPtrSolidB->DistanceToIn(p) ; 406 } 399 } 407 else 400 else 408 { 401 { 409 dist = std::min(fPtrSolidA->DistanceToI 402 dist = std::min(fPtrSolidA->DistanceToIn(p), 410 fPtrSolidB->DistanceToI << 403 fPtrSolidB->DistanceToIn(p) ) ; 411 } 404 } 412 } 405 } 413 return dist ; 406 return dist ; 414 } 407 } 415 408 416 ////////////////////////////////////////////// << 409 ////////////////////////////////////////////////////////// 417 // 410 // 418 // The same algorithm as DistanceToOut(p) 411 // The same algorithm as DistanceToOut(p) 419 412 420 G4double 413 G4double 421 G4IntersectionSolid::DistanceToOut( const G4Th 414 G4IntersectionSolid::DistanceToOut( const G4ThreeVector& p, 422 const G4Th 415 const G4ThreeVector& v, 423 const G4bo 416 const G4bool calcNorm, 424 G4bo << 417 G4bool *validNorm, 425 G4Th << 418 G4ThreeVector *n ) const 426 { 419 { 427 G4bool validNormA, validNormB; 420 G4bool validNormA, validNormB; 428 G4ThreeVector nA, nB; 421 G4ThreeVector nA, nB; 429 422 430 #ifdef G4BOOLDEBUG 423 #ifdef G4BOOLDEBUG 431 if( Inside(p) == kOutside ) 424 if( Inside(p) == kOutside ) 432 { 425 { 433 G4cout << "Position:" << G4endl << G4endl 426 G4cout << "Position:" << G4endl << G4endl; 434 G4cout << "p.x() = " << p.x()/mm << " mm 427 G4cout << "p.x() = " << p.x()/mm << " mm" << G4endl; 435 G4cout << "p.y() = " << p.y()/mm << " mm 428 G4cout << "p.y() = " << p.y()/mm << " mm" << G4endl; 436 G4cout << "p.z() = " << p.z()/mm << " mm 429 G4cout << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl; 437 G4cout << "Direction:" << G4endl << G4endl 430 G4cout << "Direction:" << G4endl << G4endl; 438 G4cout << "v.x() = " << v.x() << G4endl; 431 G4cout << "v.x() = " << v.x() << G4endl; 439 G4cout << "v.y() = " << v.y() << G4endl; 432 G4cout << "v.y() = " << v.y() << G4endl; 440 G4cout << "v.z() = " << v.z() << G4endl 433 G4cout << "v.z() = " << v.z() << G4endl << G4endl; 441 G4cout << "WARNING - Invalid call in " 434 G4cout << "WARNING - Invalid call in " 442 << "G4IntersectionSolid::DistanceTo 435 << "G4IntersectionSolid::DistanceToOut(p,v)" << G4endl 443 << " Point p is outside !" << G4en 436 << " Point p is outside !" << G4endl; 444 G4cout << " p = " << p << G4endl; 437 G4cout << " p = " << p << G4endl; 445 G4cout << " v = " << v << G4endl; 438 G4cout << " v = " << v << G4endl; 446 G4cerr << "WARNING - Invalid call in " 439 G4cerr << "WARNING - Invalid call in " 447 << "G4IntersectionSolid::DistanceTo 440 << "G4IntersectionSolid::DistanceToOut(p,v)" << G4endl 448 << " Point p is outside !" << G4en 441 << " Point p is outside !" << G4endl; 449 G4cerr << " p = " << p << G4endl; 442 G4cerr << " p = " << p << G4endl; 450 G4cerr << " v = " << v << G4endl; 443 G4cerr << " v = " << v << G4endl; 451 } 444 } 452 #endif 445 #endif 453 G4double distA = fPtrSolidA->DistanceToOut(p 446 G4double distA = fPtrSolidA->DistanceToOut(p,v,calcNorm,&validNormA,&nA) ; 454 G4double distB = fPtrSolidB->DistanceToOut(p 447 G4double distB = fPtrSolidB->DistanceToOut(p,v,calcNorm,&validNormB,&nB) ; 455 448 456 G4double dist = std::min(distA,distB) ; 449 G4double dist = std::min(distA,distB) ; 457 450 458 if( calcNorm ) 451 if( calcNorm ) 459 { 452 { 460 if ( distA < distB ) 453 if ( distA < distB ) 461 { 454 { 462 *validNorm = validNormA; 455 *validNorm = validNormA; 463 *n = nA; 456 *n = nA; 464 } 457 } 465 else 458 else 466 { 459 { 467 *validNorm = validNormB; 460 *validNorm = validNormB; 468 *n = nB; 461 *n = nB; 469 } 462 } 470 } 463 } 471 464 472 return dist ; 465 return dist ; 473 } 466 } 474 467 475 ////////////////////////////////////////////// << 468 ////////////////////////////////////////////////////////////// 476 // 469 // 477 // Inverted algorithm of DistanceToIn(p) 470 // Inverted algorithm of DistanceToIn(p) 478 471 479 G4double 472 G4double 480 G4IntersectionSolid::DistanceToOut( const G4Th 473 G4IntersectionSolid::DistanceToOut( const G4ThreeVector& p ) const 481 { 474 { 482 #ifdef G4BOOLDEBUG 475 #ifdef G4BOOLDEBUG 483 if( Inside(p) == kOutside ) 476 if( Inside(p) == kOutside ) 484 { 477 { 485 G4cout << "WARNING - Invalid call in " 478 G4cout << "WARNING - Invalid call in " 486 << "G4IntersectionSolid::DistanceTo 479 << "G4IntersectionSolid::DistanceToOut(p)" << G4endl 487 << " Point p is outside !" << G4en 480 << " Point p is outside !" << G4endl; 488 G4cout << " p = " << p << G4endl; 481 G4cout << " p = " << p << G4endl; 489 G4cerr << "WARNING - Invalid call in " 482 G4cerr << "WARNING - Invalid call in " 490 << "G4IntersectionSolid::DistanceTo 483 << "G4IntersectionSolid::DistanceToOut(p)" << G4endl 491 << " Point p is outside !" << G4en 484 << " Point p is outside !" << G4endl; 492 G4cerr << " p = " << p << G4endl; 485 G4cerr << " p = " << p << G4endl; 493 } 486 } 494 #endif 487 #endif 495 488 496 return std::min(fPtrSolidA->DistanceToOut(p) 489 return std::min(fPtrSolidA->DistanceToOut(p), 497 fPtrSolidB->DistanceToOut(p) 490 fPtrSolidB->DistanceToOut(p) ) ; 498 491 499 } 492 } 500 493 501 ////////////////////////////////////////////// << 494 ////////////////////////////////////////////////////////////// >> 495 // 502 // 496 // 503 // ComputeDimensions << 504 497 505 void 498 void 506 G4IntersectionSolid::ComputeDimensions( G4VPVP 499 G4IntersectionSolid::ComputeDimensions( G4VPVParameterisation*, 507 const << 500 const G4int, 508 const 501 const G4VPhysicalVolume* ) 509 { 502 { 510 } 503 } 511 504 512 ////////////////////////////////////////////// << 505 ///////////////////////////////////////////////// 513 // 506 // 514 // GetEntityType << 507 // 515 508 516 G4GeometryType G4IntersectionSolid::GetEntityT 509 G4GeometryType G4IntersectionSolid::GetEntityType() const 517 { 510 { 518 return {"G4IntersectionSolid"}; << 511 return G4String("G4IntersectionSolid"); 519 } 512 } 520 513 521 ////////////////////////////////////////////// 514 ////////////////////////////////////////////////////////////////////////// 522 // 515 // 523 // Make a clone of the object 516 // Make a clone of the object 524 517 525 G4VSolid* G4IntersectionSolid::Clone() const 518 G4VSolid* G4IntersectionSolid::Clone() const 526 { 519 { 527 return new G4IntersectionSolid(*this); 520 return new G4IntersectionSolid(*this); 528 } 521 } 529 522 530 ////////////////////////////////////////////// << 523 ///////////////////////////////////////////////// 531 // 524 // 532 // DescribeYourselfTo << 525 // 533 526 534 void 527 void 535 G4IntersectionSolid::DescribeYourselfTo ( G4VG 528 G4IntersectionSolid::DescribeYourselfTo ( G4VGraphicsScene& scene ) const 536 { 529 { 537 scene.AddSolid (*this); 530 scene.AddSolid (*this); 538 } 531 } 539 532 540 ////////////////////////////////////////////// << 533 //////////////////////////////////////////////////// >> 534 // 541 // 535 // 542 // CreatePolyhedron << 543 536 544 G4Polyhedron* 537 G4Polyhedron* 545 G4IntersectionSolid::CreatePolyhedron () const 538 G4IntersectionSolid::CreatePolyhedron () const 546 { 539 { 547 if (fExternalBoolProcessor == nullptr) << 540 HepPolyhedronProcessor processor; 548 { << 541 // Stack components and components of components recursively 549 HepPolyhedronProcessor processor; << 542 // See G4BooleanSolid::StackPolyhedron 550 // Stack components and components of comp << 543 G4Polyhedron* top = StackPolyhedron(processor, this); 551 // See G4BooleanSolid::StackPolyhedron << 544 G4Polyhedron* result = new G4Polyhedron(*top); 552 G4Polyhedron* top = StackPolyhedron(proces << 545 if (processor.execute(*result)) { return result; } 553 auto result = new G4Polyhedron(*top); << 546 else { return 0; } 554 if (processor.execute(*result)) << 555 { << 556 return result; << 557 } << 558 else << 559 { << 560 return nullptr; << 561 } << 562 } << 563 else << 564 { << 565 return fExternalBoolProcessor->Process(thi << 566 } << 567 } 547 } 568 548