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 // Implementation of G4DisplacedSolid class fo << 26 // >> 27 // $Id: G4DisplacedSolid.cc 110069 2018-05-15 09:32:07Z gcosmo $ >> 28 // >> 29 // Implementation for G4DisplacedSolid class for boolean 27 // operations between other solids 30 // operations between other solids 28 // 31 // >> 32 // History: >> 33 // 29 // 28.10.98 V.Grichine: created 34 // 28.10.98 V.Grichine: created >> 35 // 14.11.99 V.Grichine: modifications in CalculateExtent(...) method >> 36 // 22.11.00 V.Grichine: new set methods for matrix/vectors 30 // 28.02.18 E.Tcherniaev: improved contruction 37 // 28.02.18 E.Tcherniaev: improved contruction from G4DisplacedSolid >> 38 // 31 // ------------------------------------------- 39 // -------------------------------------------------------------------- 32 40 33 #include "G4DisplacedSolid.hh" 41 #include "G4DisplacedSolid.hh" 34 42 35 #include "G4VoxelLimits.hh" 43 #include "G4VoxelLimits.hh" 36 44 37 #include "G4VPVParameterisation.hh" 45 #include "G4VPVParameterisation.hh" 38 46 39 #include "G4VGraphicsScene.hh" 47 #include "G4VGraphicsScene.hh" 40 #include "G4Polyhedron.hh" 48 #include "G4Polyhedron.hh" 41 49 42 ////////////////////////////////////////////// 50 //////////////////////////////////////////////////////////////// 43 // 51 // 44 // Constructor for transformation like rotatio 52 // Constructor for transformation like rotation of frame then translation 45 // in new frame. It is similar to 1st constrac 53 // in new frame. It is similar to 1st constractor in G4PVPlacement 46 54 47 G4DisplacedSolid::G4DisplacedSolid( const G4St 55 G4DisplacedSolid::G4DisplacedSolid( const G4String& pName, 48 G4VS 56 G4VSolid* pSolid , 49 G4Ro 57 G4RotationMatrix* rotMatrix, 50 const G4Th 58 const G4ThreeVector& transVector ) 51 : G4VSolid(pName) << 59 : G4VSolid(pName), fRebuildPolyhedron(false), fpPolyhedron(0) 52 { 60 { 53 if (pSolid->GetEntityType() == "G4DisplacedS 61 if (pSolid->GetEntityType() == "G4DisplacedSolid") 54 { 62 { 55 fPtrSolid = ((G4DisplacedSolid*)pSolid)->G 63 fPtrSolid = ((G4DisplacedSolid*)pSolid)->GetConstituentMovedSolid(); 56 G4AffineTransform t1 = ((G4DisplacedSolid* 64 G4AffineTransform t1 = ((G4DisplacedSolid*)pSolid)->GetDirectTransform(); 57 G4AffineTransform t2 = G4AffineTransform(r 65 G4AffineTransform t2 = G4AffineTransform(rotMatrix,transVector); 58 fDirectTransform = new G4AffineTransform(t 66 fDirectTransform = new G4AffineTransform(t1*t2); 59 } 67 } 60 else 68 else 61 { 69 { 62 fPtrSolid = pSolid; 70 fPtrSolid = pSolid; 63 fDirectTransform = new G4AffineTransform(r 71 fDirectTransform = new G4AffineTransform(rotMatrix,transVector); 64 } 72 } 65 fPtrTransform = new G4AffineTransform(fDirec 73 fPtrTransform = new G4AffineTransform(fDirectTransform->Inverse()); 66 } 74 } 67 75 68 ////////////////////////////////////////////// 76 ///////////////////////////////////////////////////////////////////////////////// 69 // 77 // 70 // Constructor 78 // Constructor 71 79 72 G4DisplacedSolid::G4DisplacedSolid( const G4St 80 G4DisplacedSolid::G4DisplacedSolid( const G4String& pName, 73 G4VS 81 G4VSolid* pSolid , 74 const G4Tr 82 const G4Transform3D& transform ) 75 : G4VSolid(pName) << 83 : G4VSolid(pName), fRebuildPolyhedron(false), fpPolyhedron(0) 76 { 84 { 77 if (pSolid->GetEntityType() == "G4DisplacedS 85 if (pSolid->GetEntityType() == "G4DisplacedSolid") 78 { 86 { 79 fPtrSolid = ((G4DisplacedSolid*)pSolid)->G 87 fPtrSolid = ((G4DisplacedSolid*)pSolid)->GetConstituentMovedSolid(); 80 G4AffineTransform t1 = ((G4DisplacedSolid* 88 G4AffineTransform t1 = ((G4DisplacedSolid*)pSolid)->GetDirectTransform(); 81 G4AffineTransform t2 = G4AffineTransform(t 89 G4AffineTransform t2 = G4AffineTransform(transform.getRotation().inverse(), 82 t 90 transform.getTranslation()); 83 fDirectTransform = new G4AffineTransform(t 91 fDirectTransform = new G4AffineTransform(t1*t2); 84 } 92 } 85 else 93 else 86 { 94 { 87 fPtrSolid = pSolid; 95 fPtrSolid = pSolid; 88 fDirectTransform = new G4AffineTransform(t 96 fDirectTransform = new G4AffineTransform(transform.getRotation().inverse(), 89 t 97 transform.getTranslation()) ; 90 } 98 } 91 fPtrTransform = new G4AffineTransform(fDirec 99 fPtrTransform = new G4AffineTransform(fDirectTransform->Inverse()); 92 } 100 } 93 101 94 ////////////////////////////////////////////// 102 /////////////////////////////////////////////////////////////////// 95 // 103 // 96 // Constructor for use with creation of Transi 104 // Constructor for use with creation of Transient object 97 // from Persistent object 105 // from Persistent object 98 106 99 G4DisplacedSolid::G4DisplacedSolid( const G4St 107 G4DisplacedSolid::G4DisplacedSolid( const G4String& pName, 100 G4VS 108 G4VSolid* pSolid , 101 const G4Af 109 const G4AffineTransform directTransform ) 102 : G4VSolid(pName) << 110 : G4VSolid(pName), fRebuildPolyhedron(false), fpPolyhedron(0) 103 { 111 { 104 if (pSolid->GetEntityType() == "G4DisplacedS 112 if (pSolid->GetEntityType() == "G4DisplacedSolid") 105 { 113 { 106 fPtrSolid = ((G4DisplacedSolid*)pSolid)->G 114 fPtrSolid = ((G4DisplacedSolid*)pSolid)->GetConstituentMovedSolid(); 107 G4AffineTransform t1 = ((G4DisplacedSolid* 115 G4AffineTransform t1 = ((G4DisplacedSolid*)pSolid)->GetDirectTransform(); 108 auto t2 = G4AffineTransform(directTransfo << 116 G4AffineTransform t2 = G4AffineTransform(directTransform); 109 fDirectTransform = new G4AffineTransform(t 117 fDirectTransform = new G4AffineTransform(t1*t2); 110 } 118 } 111 else 119 else 112 { 120 { 113 fPtrSolid = pSolid; 121 fPtrSolid = pSolid; 114 fDirectTransform = new G4AffineTransform(d 122 fDirectTransform = new G4AffineTransform(directTransform); 115 } 123 } 116 fPtrTransform = new G4AffineTransform(fDirec 124 fPtrTransform = new G4AffineTransform(fDirectTransform->Inverse()); 117 } 125 } 118 126 119 ////////////////////////////////////////////// 127 /////////////////////////////////////////////////////////////////// 120 // 128 // 121 // Fake default constructor - sets only member 129 // Fake default constructor - sets only member data and allocates memory 122 // for usage restri 130 // for usage restricted to object persistency. 123 131 124 G4DisplacedSolid::G4DisplacedSolid( __void__& 132 G4DisplacedSolid::G4DisplacedSolid( __void__& a ) 125 : G4VSolid(a) << 133 : G4VSolid(a), fPtrSolid(0), fPtrTransform(0), >> 134 fDirectTransform(0), fRebuildPolyhedron(false), fpPolyhedron(0) 126 { 135 { 127 } 136 } 128 137 129 ////////////////////////////////////////////// 138 /////////////////////////////////////////////////////////////////// 130 // 139 // 131 // Destructor 140 // Destructor 132 141 133 G4DisplacedSolid::~G4DisplacedSolid() 142 G4DisplacedSolid::~G4DisplacedSolid() 134 { 143 { 135 CleanTransformations(); 144 CleanTransformations(); 136 delete fpPolyhedron; fpPolyhedron = nullptr; << 145 delete fpPolyhedron; fpPolyhedron = 0; 137 } 146 } 138 147 139 ////////////////////////////////////////////// 148 /////////////////////////////////////////////////////////////// 140 // 149 // 141 // Copy constructor 150 // Copy constructor 142 151 143 G4DisplacedSolid::G4DisplacedSolid(const G4Dis 152 G4DisplacedSolid::G4DisplacedSolid(const G4DisplacedSolid& rhs) 144 : G4VSolid (rhs), fPtrSolid(rhs.fPtrSolid) << 153 : G4VSolid (rhs), fPtrSolid(rhs.fPtrSolid), >> 154 fRebuildPolyhedron(false), fpPolyhedron(0) 145 { 155 { 146 fPtrTransform = new G4AffineTransform(*(rhs. 156 fPtrTransform = new G4AffineTransform(*(rhs.fPtrTransform)); 147 fDirectTransform = new G4AffineTransform(*(r 157 fDirectTransform = new G4AffineTransform(*(rhs.fDirectTransform)); 148 } 158 } 149 159 150 ////////////////////////////////////////////// 160 /////////////////////////////////////////////////////////////// 151 // 161 // 152 // Assignment operator 162 // Assignment operator 153 163 154 G4DisplacedSolid& G4DisplacedSolid::operator = 164 G4DisplacedSolid& G4DisplacedSolid::operator = (const G4DisplacedSolid& rhs) 155 { 165 { 156 // Check assignment to self 166 // Check assignment to self 157 // 167 // 158 if (this == &rhs) { return *this; } 168 if (this == &rhs) { return *this; } 159 169 160 // Copy base class data 170 // Copy base class data 161 // 171 // 162 G4VSolid::operator=(rhs); 172 G4VSolid::operator=(rhs); 163 173 164 // Copy data 174 // Copy data 165 // 175 // 166 fPtrSolid = rhs.fPtrSolid; 176 fPtrSolid = rhs.fPtrSolid; 167 delete fPtrTransform; delete fDirectTransfor 177 delete fPtrTransform; delete fDirectTransform; 168 fPtrTransform = new G4AffineTransform(*(rhs. 178 fPtrTransform = new G4AffineTransform(*(rhs.fPtrTransform)); 169 fDirectTransform = new G4AffineTransform(*(r 179 fDirectTransform = new G4AffineTransform(*(rhs.fDirectTransform)); 170 fRebuildPolyhedron = false; 180 fRebuildPolyhedron = false; 171 delete fpPolyhedron; fpPolyhedron = nullptr; << 181 delete fpPolyhedron; fpPolyhedron= 0; 172 182 173 return *this; 183 return *this; 174 } 184 } 175 185 176 void G4DisplacedSolid::CleanTransformations() 186 void G4DisplacedSolid::CleanTransformations() 177 { 187 { 178 if(fPtrTransform != nullptr) << 188 if(fPtrTransform) 179 { 189 { 180 delete fPtrTransform; fPtrTransform = null << 190 delete fPtrTransform; fPtrTransform=0; 181 delete fDirectTransform; fDirectTransform << 191 delete fDirectTransform; fDirectTransform=0; 182 } 192 } 183 } 193 } 184 194 185 const G4DisplacedSolid* G4DisplacedSolid::GetD 195 const G4DisplacedSolid* G4DisplacedSolid::GetDisplacedSolidPtr() const 186 { 196 { 187 return this; 197 return this; 188 } 198 } 189 199 190 G4DisplacedSolid* G4DisplacedSolid::GetDisplac 200 G4DisplacedSolid* G4DisplacedSolid::GetDisplacedSolidPtr() 191 { 201 { 192 return this; 202 return this; 193 } 203 } 194 204 195 G4VSolid* G4DisplacedSolid::GetConstituentMove 205 G4VSolid* G4DisplacedSolid::GetConstituentMovedSolid() const 196 { 206 { 197 return fPtrSolid; 207 return fPtrSolid; 198 } 208 } 199 209 200 ////////////////////////////////////////////// 210 ///////////////////////////////////////////////////////////////////////////// 201 211 202 G4AffineTransform G4DisplacedSolid::GetTransf 212 G4AffineTransform G4DisplacedSolid::GetTransform() const 203 { 213 { 204 G4AffineTransform aTransform = *fPtrTransfor 214 G4AffineTransform aTransform = *fPtrTransform; 205 return aTransform; 215 return aTransform; 206 } 216 } 207 217 208 void G4DisplacedSolid::SetTransform(G4AffineTr 218 void G4DisplacedSolid::SetTransform(G4AffineTransform& transform) 209 { 219 { 210 fPtrTransform = &transform ; 220 fPtrTransform = &transform ; 211 fRebuildPolyhedron = true; 221 fRebuildPolyhedron = true; 212 } 222 } 213 223 214 ////////////////////////////////////////////// 224 ////////////////////////////////////////////////////////////////////////////// 215 225 216 G4AffineTransform G4DisplacedSolid::GetDirect 226 G4AffineTransform G4DisplacedSolid::GetDirectTransform() const 217 { 227 { 218 G4AffineTransform aTransform= *fDirectTransf 228 G4AffineTransform aTransform= *fDirectTransform; 219 return aTransform; 229 return aTransform; 220 } 230 } 221 231 222 void G4DisplacedSolid::SetDirectTransform(G4Af 232 void G4DisplacedSolid::SetDirectTransform(G4AffineTransform& transform) 223 { 233 { 224 fDirectTransform = &transform ; 234 fDirectTransform = &transform ; 225 fRebuildPolyhedron = true; 235 fRebuildPolyhedron = true; 226 } 236 } 227 237 228 ////////////////////////////////////////////// 238 ///////////////////////////////////////////////////////////////////////////// 229 239 230 G4RotationMatrix G4DisplacedSolid::GetFrameRot 240 G4RotationMatrix G4DisplacedSolid::GetFrameRotation() const 231 { 241 { 232 G4RotationMatrix InvRotation = fDirectTransf << 242 G4RotationMatrix InvRotation= fDirectTransform->NetRotation(); 233 return InvRotation; 243 return InvRotation; 234 } 244 } 235 245 236 void G4DisplacedSolid::SetFrameRotation(const 246 void G4DisplacedSolid::SetFrameRotation(const G4RotationMatrix& matrix) 237 { 247 { 238 fDirectTransform->SetNetRotation(matrix); 248 fDirectTransform->SetNetRotation(matrix); 239 fRebuildPolyhedron = true; 249 fRebuildPolyhedron = true; 240 } 250 } 241 251 242 ////////////////////////////////////////////// 252 ///////////////////////////////////////////////////////////////////////////// 243 253 244 G4ThreeVector G4DisplacedSolid::GetFrameTrans 254 G4ThreeVector G4DisplacedSolid::GetFrameTranslation() const 245 { 255 { 246 return fPtrTransform->NetTranslation(); 256 return fPtrTransform->NetTranslation(); 247 } 257 } 248 258 249 void G4DisplacedSolid::SetFrameTranslation(con 259 void G4DisplacedSolid::SetFrameTranslation(const G4ThreeVector& vector) 250 { 260 { 251 fPtrTransform->SetNetTranslation(vector); 261 fPtrTransform->SetNetTranslation(vector); 252 fRebuildPolyhedron = true; 262 fRebuildPolyhedron = true; 253 } 263 } 254 264 255 ////////////////////////////////////////////// 265 /////////////////////////////////////////////////////////////// 256 266 257 G4RotationMatrix G4DisplacedSolid::GetObjectRo 267 G4RotationMatrix G4DisplacedSolid::GetObjectRotation() const 258 { 268 { 259 G4RotationMatrix Rotation = fPtrTransform->N << 269 G4RotationMatrix Rotation= fPtrTransform->NetRotation(); 260 return Rotation; 270 return Rotation; 261 } 271 } 262 272 263 void G4DisplacedSolid::SetObjectRotation(const 273 void G4DisplacedSolid::SetObjectRotation(const G4RotationMatrix& matrix) 264 { 274 { 265 fPtrTransform->SetNetRotation(matrix); 275 fPtrTransform->SetNetRotation(matrix); 266 fRebuildPolyhedron = true; 276 fRebuildPolyhedron = true; 267 } 277 } 268 278 269 ////////////////////////////////////////////// 279 /////////////////////////////////////////////////////////////////////// 270 280 271 G4ThreeVector G4DisplacedSolid::GetObjectTran 281 G4ThreeVector G4DisplacedSolid::GetObjectTranslation() const 272 { 282 { 273 return fDirectTransform->NetTranslation(); 283 return fDirectTransform->NetTranslation(); 274 } 284 } 275 285 276 void G4DisplacedSolid::SetObjectTranslation(co 286 void G4DisplacedSolid::SetObjectTranslation(const G4ThreeVector& vector) 277 { 287 { 278 fDirectTransform->SetNetTranslation(vector); 288 fDirectTransform->SetNetTranslation(vector); 279 fRebuildPolyhedron = true; 289 fRebuildPolyhedron = true; 280 } 290 } 281 291 282 ////////////////////////////////////////////// 292 ////////////////////////////////////////////////////////////////////////// 283 // 293 // 284 // Get bounding box 294 // Get bounding box 285 295 286 void G4DisplacedSolid::BoundingLimits(G4ThreeV 296 void G4DisplacedSolid::BoundingLimits(G4ThreeVector& pMin, 287 G4ThreeV 297 G4ThreeVector& pMax) const 288 { 298 { 289 if (!fDirectTransform->IsRotated()) 299 if (!fDirectTransform->IsRotated()) 290 { 300 { 291 // Special case of pure translation 301 // Special case of pure translation 292 // 302 // 293 fPtrSolid->BoundingLimits(pMin,pMax); 303 fPtrSolid->BoundingLimits(pMin,pMax); 294 G4ThreeVector offset = fDirectTransform->N 304 G4ThreeVector offset = fDirectTransform->NetTranslation(); 295 pMin += offset; 305 pMin += offset; 296 pMax += offset; 306 pMax += offset; 297 } 307 } 298 else 308 else 299 { 309 { 300 // General case, use CalculateExtent() to 310 // General case, use CalculateExtent() to find bounding box 301 // 311 // 302 G4VoxelLimits unLimit; 312 G4VoxelLimits unLimit; 303 G4double xmin,xmax,ymin,ymax,zmin,zmax; 313 G4double xmin,xmax,ymin,ymax,zmin,zmax; 304 fPtrSolid->CalculateExtent(kXAxis,unLimit, 314 fPtrSolid->CalculateExtent(kXAxis,unLimit,*fDirectTransform,xmin,xmax); 305 fPtrSolid->CalculateExtent(kYAxis,unLimit, 315 fPtrSolid->CalculateExtent(kYAxis,unLimit,*fDirectTransform,ymin,ymax); 306 fPtrSolid->CalculateExtent(kZAxis,unLimit, 316 fPtrSolid->CalculateExtent(kZAxis,unLimit,*fDirectTransform,zmin,zmax); 307 pMin.set(xmin,ymin,zmin); 317 pMin.set(xmin,ymin,zmin); 308 pMax.set(xmax,ymax,zmax); 318 pMax.set(xmax,ymax,zmax); 309 } 319 } 310 320 311 // Check correctness of the bounding box 321 // Check correctness of the bounding box 312 // 322 // 313 if (pMin.x() >= pMax.x() || pMin.y() >= pMax 323 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z()) 314 { 324 { 315 std::ostringstream message; 325 std::ostringstream message; 316 message << "Bad bounding box (min >= max) 326 message << "Bad bounding box (min >= max) for solid: " 317 << GetName() << " !" 327 << GetName() << " !" 318 << "\npMin = " << pMin 328 << "\npMin = " << pMin 319 << "\npMax = " << pMax; 329 << "\npMax = " << pMax; 320 G4Exception("G4DisplacedSolid::BoundingLim 330 G4Exception("G4DisplacedSolid::BoundingLimits()", "GeomMgt0001", 321 JustWarning, message); 331 JustWarning, message); 322 DumpInfo(); 332 DumpInfo(); 323 } 333 } 324 } 334 } 325 335 326 ////////////////////////////////////////////// 336 ////////////////////////////////////////////////////////////////////////// 327 // 337 // 328 // Calculate extent under transform and specif 338 // Calculate extent under transform and specified limit 329 339 330 G4bool 340 G4bool 331 G4DisplacedSolid::CalculateExtent( const EAxis 341 G4DisplacedSolid::CalculateExtent( const EAxis pAxis, 332 const G4Vox 342 const G4VoxelLimits& pVoxelLimit, 333 const G4Aff 343 const G4AffineTransform& pTransform, 334 G4dou 344 G4double& pMin, 335 G4dou 345 G4double& pMax ) const 336 { 346 { 337 G4AffineTransform sumTransform ; 347 G4AffineTransform sumTransform ; 338 sumTransform.Product(*fDirectTransform,pTran 348 sumTransform.Product(*fDirectTransform,pTransform) ; 339 return fPtrSolid->CalculateExtent(pAxis,pVox 349 return fPtrSolid->CalculateExtent(pAxis,pVoxelLimit,sumTransform,pMin,pMax) ; 340 } 350 } 341 351 342 ////////////////////////////////////////////// 352 ///////////////////////////////////////////////////// 343 // 353 // 344 // SurfaceNormal << 354 // 345 355 346 EInside G4DisplacedSolid::Inside(const G4Three 356 EInside G4DisplacedSolid::Inside(const G4ThreeVector& p) const 347 { 357 { 348 G4ThreeVector newPoint = fPtrTransform->Tran 358 G4ThreeVector newPoint = fPtrTransform->TransformPoint(p) ; 349 return fPtrSolid->Inside(newPoint) ; 359 return fPtrSolid->Inside(newPoint) ; 350 } 360 } 351 361 352 ////////////////////////////////////////////// 362 ////////////////////////////////////////////////////////////// 353 // 363 // 354 // 364 // 355 365 356 G4ThreeVector 366 G4ThreeVector 357 G4DisplacedSolid::SurfaceNormal( const G4Three 367 G4DisplacedSolid::SurfaceNormal( const G4ThreeVector& p ) const 358 { 368 { 359 G4ThreeVector newPoint = fPtrTransform->Tran 369 G4ThreeVector newPoint = fPtrTransform->TransformPoint(p) ; 360 G4ThreeVector normal = fPtrSolid->SurfaceNor 370 G4ThreeVector normal = fPtrSolid->SurfaceNormal(newPoint) ; 361 return fDirectTransform->TransformAxis(norma 371 return fDirectTransform->TransformAxis(normal) ; 362 } 372 } 363 373 364 ////////////////////////////////////////////// 374 ///////////////////////////////////////////////////////////// 365 // 375 // 366 // The same algorithm as in DistanceToIn(p) 376 // The same algorithm as in DistanceToIn(p) 367 377 368 G4double 378 G4double 369 G4DisplacedSolid::DistanceToIn( const G4ThreeV 379 G4DisplacedSolid::DistanceToIn( const G4ThreeVector& p, 370 const G4ThreeV 380 const G4ThreeVector& v ) const 371 { 381 { 372 G4ThreeVector newPoint = fPtrTransform->Tran 382 G4ThreeVector newPoint = fPtrTransform->TransformPoint(p) ; 373 G4ThreeVector newDirection = fPtrTransform-> 383 G4ThreeVector newDirection = fPtrTransform->TransformAxis(v) ; 374 return fPtrSolid->DistanceToIn(newPoint,newD 384 return fPtrSolid->DistanceToIn(newPoint,newDirection) ; 375 } 385 } 376 386 377 ////////////////////////////////////////////// 387 //////////////////////////////////////////////////////// 378 // 388 // 379 // Approximate nearest distance from the point 389 // Approximate nearest distance from the point p to the intersection of 380 // two solids 390 // two solids 381 391 382 G4double 392 G4double 383 G4DisplacedSolid::DistanceToIn( const G4ThreeV 393 G4DisplacedSolid::DistanceToIn( const G4ThreeVector& p ) const 384 { 394 { 385 G4ThreeVector newPoint = fPtrTransform->Tran 395 G4ThreeVector newPoint = fPtrTransform->TransformPoint(p) ; 386 return fPtrSolid->DistanceToIn(newPoint) ; 396 return fPtrSolid->DistanceToIn(newPoint) ; 387 } 397 } 388 398 389 ////////////////////////////////////////////// 399 ////////////////////////////////////////////////////////// 390 // 400 // 391 // The same algorithm as DistanceToOut(p) 401 // The same algorithm as DistanceToOut(p) 392 402 393 G4double 403 G4double 394 G4DisplacedSolid::DistanceToOut( const G4Three 404 G4DisplacedSolid::DistanceToOut( const G4ThreeVector& p, 395 const G4Three 405 const G4ThreeVector& v, 396 const G4bool 406 const G4bool calcNorm, 397 G4bool 407 G4bool *validNorm, 398 G4Three 408 G4ThreeVector *n ) const 399 { 409 { 400 G4ThreeVector solNorm ; 410 G4ThreeVector solNorm ; 401 G4ThreeVector newPoint = fPtrTransform->Tran 411 G4ThreeVector newPoint = fPtrTransform->TransformPoint(p) ; 402 G4ThreeVector newDirection = fPtrTransform-> 412 G4ThreeVector newDirection = fPtrTransform->TransformAxis(v) ; 403 G4double dist = fPtrSolid->DistanceToOut(new 413 G4double dist = fPtrSolid->DistanceToOut(newPoint,newDirection, 404 cal 414 calcNorm,validNorm,&solNorm) ; 405 if(calcNorm) 415 if(calcNorm) 406 { 416 { 407 *n = fDirectTransform->TransformAxis(solNo 417 *n = fDirectTransform->TransformAxis(solNorm) ; 408 } 418 } 409 return dist ; 419 return dist ; 410 } 420 } 411 421 412 ////////////////////////////////////////////// 422 ////////////////////////////////////////////////////////////// 413 // 423 // 414 // Inverted algorithm of DistanceToIn(p) 424 // Inverted algorithm of DistanceToIn(p) 415 425 416 G4double 426 G4double 417 G4DisplacedSolid::DistanceToOut( const G4Three 427 G4DisplacedSolid::DistanceToOut( const G4ThreeVector& p ) const 418 { 428 { 419 G4ThreeVector newPoint = fPtrTransform->Tran 429 G4ThreeVector newPoint = fPtrTransform->TransformPoint(p) ; 420 return fPtrSolid->DistanceToOut(newPoint) ; 430 return fPtrSolid->DistanceToOut(newPoint) ; 421 } 431 } 422 432 423 ////////////////////////////////////////////// 433 ////////////////////////////////////////////////////////////// 424 // 434 // 425 // ComputeDimensions << 435 // 426 436 427 void 437 void 428 G4DisplacedSolid::ComputeDimensions( G4V 438 G4DisplacedSolid::ComputeDimensions( G4VPVParameterisation*, 429 const G4i 439 const G4int, 430 const G4V 440 const G4VPhysicalVolume* ) 431 { 441 { 432 DumpInfo(); 442 DumpInfo(); 433 G4Exception("G4DisplacedSolid::ComputeDimens 443 G4Exception("G4DisplacedSolid::ComputeDimensions()", 434 "GeomSolids0001", FatalException 444 "GeomSolids0001", FatalException, 435 "Method not applicable in this c 445 "Method not applicable in this context!"); 436 } 446 } 437 447 438 ////////////////////////////////////////////// << 439 // << 440 // Return volume << 441 << 442 G4double G4DisplacedSolid::GetCubicVolume() << 443 { << 444 return fPtrSolid->GetCubicVolume(); << 445 } << 446 << 447 ////////////////////////////////////////////// << 448 // << 449 // Return surface area << 450 << 451 G4double G4DisplacedSolid::GetSurfaceArea() << 452 { << 453 return fPtrSolid->GetSurfaceArea(); << 454 } << 455 << 456 ////////////////////////////////////////////// 448 ////////////////////////////////////////////////////////////////////////// 457 // 449 // 458 // Returns a point (G4ThreeVector) randomly an 450 // Returns a point (G4ThreeVector) randomly and uniformly selected 459 // on the solid surface 451 // on the solid surface 460 // 452 // 461 453 462 G4ThreeVector G4DisplacedSolid::GetPointOnSurf 454 G4ThreeVector G4DisplacedSolid::GetPointOnSurface() const 463 { 455 { 464 G4ThreeVector p = fPtrSolid->GetPointOnSurfa << 456 G4ThreeVector p = fPtrSolid->GetPointOnSurface(); 465 return fDirectTransform->TransformPoint(p); 457 return fDirectTransform->TransformPoint(p); 466 } 458 } 467 459 468 ////////////////////////////////////////////// 460 ////////////////////////////////////////////////////////////////////////// 469 // 461 // 470 // Return the number of constituents used for << 471 << 472 G4int G4DisplacedSolid::GetNumOfConstituents() << 473 { << 474 return fPtrSolid->GetNumOfConstituents(); << 475 } << 476 << 477 ////////////////////////////////////////////// << 478 // << 479 // Return true if the solid has only planar fa << 480 << 481 G4bool G4DisplacedSolid::IsFaceted() const << 482 { << 483 return fPtrSolid->IsFaceted(); << 484 } << 485 << 486 ////////////////////////////////////////////// << 487 // << 488 // Return object type name 462 // Return object type name 489 463 490 G4GeometryType G4DisplacedSolid::GetEntityType 464 G4GeometryType G4DisplacedSolid::GetEntityType() const 491 { 465 { 492 return {"G4DisplacedSolid"}; << 466 return G4String("G4DisplacedSolid"); 493 } 467 } 494 468 495 ////////////////////////////////////////////// 469 ////////////////////////////////////////////////////////////////////////// 496 // 470 // 497 // Make a clone of the object 471 // Make a clone of the object 498 // 472 // 499 G4VSolid* G4DisplacedSolid::Clone() const 473 G4VSolid* G4DisplacedSolid::Clone() const 500 { 474 { 501 return new G4DisplacedSolid(*this); 475 return new G4DisplacedSolid(*this); 502 } 476 } 503 477 504 ////////////////////////////////////////////// 478 ////////////////////////////////////////////////////////////////////////// 505 // 479 // 506 // Stream object contents to an output stream 480 // Stream object contents to an output stream 507 481 508 std::ostream& G4DisplacedSolid::StreamInfo(std 482 std::ostream& G4DisplacedSolid::StreamInfo(std::ostream& os) const 509 { 483 { 510 os << "------------------------------------- 484 os << "-----------------------------------------------------------\n" 511 << " *** Dump for Displaced solid - " 485 << " *** Dump for Displaced solid - " << GetName() << " ***\n" 512 << " ================================= 486 << " ===================================================\n" 513 << " Solid type: " << GetEntityType() << 487 << " Solid type: " << GetEntityType() << "\n" 514 << " Parameters of constituent solid: \n" 488 << " Parameters of constituent solid: \n" 515 << "===================================== 489 << "===========================================================\n"; 516 fPtrSolid->StreamInfo(os); 490 fPtrSolid->StreamInfo(os); 517 os << "===================================== 491 os << "===========================================================\n" 518 << " Transformations: \n" 492 << " Transformations: \n" 519 << " Direct transformation - translati 493 << " Direct transformation - translation : \n" 520 << " " << fDirectTransform->Net 494 << " " << fDirectTransform->NetTranslation() << "\n" 521 << " - rotation 495 << " - rotation : \n" 522 << " "; 496 << " "; 523 fDirectTransform->NetRotation().print(os); 497 fDirectTransform->NetRotation().print(os); 524 os << "\n" 498 os << "\n" 525 << "===================================== 499 << "===========================================================\n"; 526 500 527 return os; 501 return os; 528 } 502 } 529 503 530 ////////////////////////////////////////////// 504 ////////////////////////////////////////////////////////////////////////// 531 // 505 // 532 // DescribeYourselfTo << 506 // 533 507 534 void 508 void 535 G4DisplacedSolid::DescribeYourselfTo ( G4VGrap 509 G4DisplacedSolid::DescribeYourselfTo ( G4VGraphicsScene& scene ) const 536 { 510 { 537 scene.AddSolid (*this); 511 scene.AddSolid (*this); 538 } 512 } 539 513 540 ////////////////////////////////////////////// 514 ////////////////////////////////////////////////////////////////////////// 541 // 515 // 542 // CreatePolyhedron << 516 // 543 517 544 G4Polyhedron* 518 G4Polyhedron* 545 G4DisplacedSolid::CreatePolyhedron () const 519 G4DisplacedSolid::CreatePolyhedron () const 546 { 520 { 547 G4Polyhedron* polyhedron = fPtrSolid->Create 521 G4Polyhedron* polyhedron = fPtrSolid->CreatePolyhedron(); 548 if (polyhedron != nullptr) << 522 if (polyhedron) 549 { 523 { 550 polyhedron 524 polyhedron 551 ->Transform(G4Transform3D(GetObjectRotatio 525 ->Transform(G4Transform3D(GetObjectRotation(),GetObjectTranslation())); 552 } 526 } 553 else 527 else 554 { 528 { 555 DumpInfo(); 529 DumpInfo(); 556 G4Exception("G4DisplacedSolid::CreatePolyh 530 G4Exception("G4DisplacedSolid::CreatePolyhedron()", 557 "GeomSolids2002", JustWarning, 531 "GeomSolids2002", JustWarning, 558 "No G4Polyhedron for displaced 532 "No G4Polyhedron for displaced solid"); 559 } 533 } 560 return polyhedron; 534 return polyhedron; 561 } 535 } 562 536 563 ////////////////////////////////////////////// 537 ////////////////////////////////////////////////////////////////////////// 564 // 538 // 565 // GetPolyhedron << 539 // 566 540 567 G4Polyhedron* G4DisplacedSolid::GetPolyhedron 541 G4Polyhedron* G4DisplacedSolid::GetPolyhedron () const 568 { 542 { 569 if (fpPolyhedron == nullptr || << 543 if (!fpPolyhedron || 570 fRebuildPolyhedron || 544 fRebuildPolyhedron || 571 fpPolyhedron->GetNumberOfRotationStepsAt 545 fpPolyhedron->GetNumberOfRotationStepsAtTimeOfCreation() != 572 fpPolyhedron->GetNumberOfRotationSteps() 546 fpPolyhedron->GetNumberOfRotationSteps()) 573 { 547 { 574 fpPolyhedron = CreatePolyhedron(); 548 fpPolyhedron = CreatePolyhedron(); 575 fRebuildPolyhedron = false; 549 fRebuildPolyhedron = false; 576 } 550 } 577 return fpPolyhedron; 551 return fpPolyhedron; 578 } 552 } 579 553