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