Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4DisplacedSolid.cc
이 파일의 문서화 페이지로 가기
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4DisplacedSolid.cc 108788 2018-03-07 08:39:32Z gcosmo $
28 //
29 // Implementation for G4DisplacedSolid class for boolean
30 // operations between other solids
31 //
32 // History:
33 //
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
37 // 28.02.18 E.Tcherniaev: improved contruction from G4DisplacedSolid
38 //
39 // --------------------------------------------------------------------
40 
41 #include "G4DisplacedSolid.hh"
42 
43 #include "G4VoxelLimits.hh"
44 
45 #include "G4VPVParameterisation.hh"
46 
47 #include "G4VGraphicsScene.hh"
48 #include "G4Polyhedron.hh"
49 
51 //
52 // Constructor for transformation like rotation of frame then translation
53 // in new frame. It is similar to 1st constractor in G4PVPlacement
54 
56  G4VSolid* pSolid ,
57  G4RotationMatrix* rotMatrix,
58  const G4ThreeVector& transVector )
59  : G4VSolid(pName), fRebuildPolyhedron(false), fpPolyhedron(0)
60 {
61  if (pSolid->GetEntityType() == "G4DisplacedSolid")
62  {
63  fPtrSolid = ((G4DisplacedSolid*)pSolid)->GetConstituentMovedSolid();
64  G4AffineTransform t1 = ((G4DisplacedSolid*)pSolid)->GetDirectTransform();
65  G4AffineTransform t2 = G4AffineTransform(rotMatrix,transVector);
67  }
68  else
69  {
70  fPtrSolid = pSolid;
71  fDirectTransform = new G4AffineTransform(rotMatrix,transVector);
72  }
74 }
75 
77 //
78 // Constructor
79 
81  G4VSolid* pSolid ,
82  const G4Transform3D& transform )
83  : G4VSolid(pName), fRebuildPolyhedron(false), fpPolyhedron(0)
84 {
85  if (pSolid->GetEntityType() == "G4DisplacedSolid")
86  {
87  fPtrSolid = ((G4DisplacedSolid*)pSolid)->GetConstituentMovedSolid();
88  G4AffineTransform t1 = ((G4DisplacedSolid*)pSolid)->GetDirectTransform();
90  transform.getTranslation());
92  }
93  else
94  {
95  fPtrSolid = pSolid;
97  transform.getTranslation()) ;
98  }
100 }
101 
103 //
104 // Constructor for use with creation of Transient object
105 // from Persistent object
106 
108  G4VSolid* pSolid ,
109  const G4AffineTransform directTransform )
110  : G4VSolid(pName), fRebuildPolyhedron(false), fpPolyhedron(0)
111 {
112  if (pSolid->GetEntityType() == "G4DisplacedSolid")
113  {
114  fPtrSolid = ((G4DisplacedSolid*)pSolid)->GetConstituentMovedSolid();
115  G4AffineTransform t1 = ((G4DisplacedSolid*)pSolid)->GetDirectTransform();
116  G4AffineTransform t2 = G4AffineTransform(directTransform);
117  fDirectTransform = new G4AffineTransform(t1*t2);
118  }
119  else
120  {
121  fPtrSolid = pSolid;
122  fDirectTransform = new G4AffineTransform(directTransform);
123  }
125 }
126 
128 //
129 // Fake default constructor - sets only member data and allocates memory
130 // for usage restricted to object persistency.
131 
133  : G4VSolid(a), fPtrSolid(0), fPtrTransform(0),
134  fDirectTransform(0), fRebuildPolyhedron(false), fpPolyhedron(0)
135 {
136 }
137 
139 //
140 // Destructor
141 
143 {
145  delete fpPolyhedron; fpPolyhedron = 0;
146 }
147 
149 //
150 // Copy constructor
151 
153  : G4VSolid (rhs), fPtrSolid(rhs.fPtrSolid),
154  fRebuildPolyhedron(false), fpPolyhedron(0)
155 {
158 }
159 
161 //
162 // Assignment operator
163 
165 {
166  // Check assignment to self
167  //
168  if (this == &rhs) { return *this; }
169 
170  // Copy base class data
171  //
172  G4VSolid::operator=(rhs);
173 
174  // Copy data
175  //
176  fPtrSolid = rhs.fPtrSolid;
177  delete fPtrTransform; delete fDirectTransform;
180  fRebuildPolyhedron = false;
181  delete fpPolyhedron; fpPolyhedron= 0;
182 
183  return *this;
184 }
185 
187 {
188  if(fPtrTransform)
189  {
190  delete fPtrTransform; fPtrTransform=0;
192  }
193 }
194 
196 {
197  return this;
198 }
199 
201 {
202  return this;
203 }
204 
206 {
207  return fPtrSolid;
208 }
209 
211 
213 {
214  G4AffineTransform aTransform = *fPtrTransform;
215  return aTransform;
216 }
217 
219 {
220  fPtrTransform = &transform ;
221  fRebuildPolyhedron = true;
222 }
223 
225 
227 {
228  G4AffineTransform aTransform= *fDirectTransform;
229  return aTransform;
230 }
231 
233 {
234  fDirectTransform = &transform ;
235  fRebuildPolyhedron = true;
236 }
237 
239 
241 {
243  return InvRotation;
244 }
245 
247 {
249  fRebuildPolyhedron = true;
250 }
251 
253 
255 {
256  return fPtrTransform->NetTranslation();
257 }
258 
260 {
262  fRebuildPolyhedron = true;
263 }
264 
266 
268 {
270  return Rotation;
271 }
272 
274 {
275  fPtrTransform->SetNetRotation(matrix);
276  fRebuildPolyhedron = true;
277 }
278 
280 
282 {
284 }
285 
287 {
289  fRebuildPolyhedron = true;
290 }
291 
293 //
294 // Get bounding box
295 
297  G4ThreeVector& pMax) const
298 {
299  if (!fDirectTransform->IsRotated())
300  {
301  // Special case of pure translation
302  //
303  fPtrSolid->BoundingLimits(pMin,pMax);
305  pMin += offset;
306  pMax += offset;
307  }
308  else
309  {
310  // General case, use CalculateExtent() to find bounding box
311  //
312  G4VoxelLimits unLimit;
313  G4double xmin,xmax,ymin,ymax,zmin,zmax;
314  fPtrSolid->CalculateExtent(kXAxis,unLimit,*fDirectTransform,xmin,xmax);
315  fPtrSolid->CalculateExtent(kYAxis,unLimit,*fDirectTransform,ymin,ymax);
316  fPtrSolid->CalculateExtent(kZAxis,unLimit,*fDirectTransform,zmin,zmax);
317  pMin.set(xmin,ymin,zmin);
318  pMax.set(xmax,ymax,zmax);
319  }
320 
321  // Check correctness of the bounding box
322  //
323  if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
324  {
325  std::ostringstream message;
326  message << "Bad bounding box (min >= max) for solid: "
327  << GetName() << " !"
328  << "\npMin = " << pMin
329  << "\npMax = " << pMax;
330  G4Exception("G4DisplacedSolid::BoundingLimits()", "GeomMgt0001",
331  JustWarning, message);
332  DumpInfo();
333  }
334 }
335 
337 //
338 // Calculate extent under transform and specified limit
339 
340 G4bool
342  const G4VoxelLimits& pVoxelLimit,
343  const G4AffineTransform& pTransform,
344  G4double& pMin,
345  G4double& pMax ) const
346 {
347  G4AffineTransform sumTransform ;
348  sumTransform.Product(*fDirectTransform,pTransform) ;
349  return fPtrSolid->CalculateExtent(pAxis,pVoxelLimit,sumTransform,pMin,pMax) ;
350 }
351 
353 //
354 //
355 
357 {
359  return fPtrSolid->Inside(newPoint) ;
360 }
361 
363 //
364 //
365 
368 {
371  return fDirectTransform->TransformAxis(normal) ;
372 }
373 
375 //
376 // The same algorithm as in DistanceToIn(p)
377 
378 G4double
380  const G4ThreeVector& v ) const
381 {
383  G4ThreeVector newDirection = fPtrTransform->TransformAxis(v) ;
384  return fPtrSolid->DistanceToIn(newPoint,newDirection) ;
385 }
386 
388 //
389 // Approximate nearest distance from the point p to the intersection of
390 // two solids
391 
392 G4double
394 {
396  return fPtrSolid->DistanceToIn(newPoint) ;
397 }
398 
400 //
401 // The same algorithm as DistanceToOut(p)
402 
403 G4double
405  const G4ThreeVector& v,
406  const G4bool calcNorm,
407  G4bool *validNorm,
408  G4ThreeVector *n ) const
409 {
410  G4ThreeVector solNorm ;
412  G4ThreeVector newDirection = fPtrTransform->TransformAxis(v) ;
413  G4double dist = fPtrSolid->DistanceToOut(newPoint,newDirection,
414  calcNorm,validNorm,&solNorm) ;
415  if(calcNorm)
416  {
417  *n = fDirectTransform->TransformAxis(solNorm) ;
418  }
419  return dist ;
420 }
421 
423 //
424 // Inverted algorithm of DistanceToIn(p)
425 
426 G4double
428 {
430  return fPtrSolid->DistanceToOut(newPoint) ;
431 }
432 
434 //
435 //
436 
437 void
439  const G4int,
440  const G4VPhysicalVolume* )
441 {
442  DumpInfo();
443  G4Exception("G4DisplacedSolid::ComputeDimensions()",
444  "GeomSolids0001", FatalException,
445  "Method not applicable in this context!");
446 }
447 
449 //
450 // Returns a point (G4ThreeVector) randomly and uniformly selected
451 // on the solid surface
452 //
453 
455 {
457  return fDirectTransform->TransformPoint(p);
458 }
459 
461 //
462 // Return object type name
463 
465 {
466  return G4String("G4DisplacedSolid");
467 }
468 
470 //
471 // Make a clone of the object
472 //
474 {
475  return new G4DisplacedSolid(*this);
476 }
477 
479 //
480 // Stream object contents to an output stream
481 
482 std::ostream& G4DisplacedSolid::StreamInfo(std::ostream& os) const
483 {
484  os << "-----------------------------------------------------------\n"
485  << " *** Dump for Displaced solid - " << GetName() << " ***\n"
486  << " ===================================================\n"
487  << " Solid type: " << GetEntityType() << "\n"
488  << " Parameters of constituent solid: \n"
489  << "===========================================================\n";
490  fPtrSolid->StreamInfo(os);
491  os << "===========================================================\n"
492  << " Transformations: \n"
493  << " Direct transformation - translation : \n"
494  << " " << fDirectTransform->NetTranslation() << "\n"
495  << " - rotation : \n"
496  << " ";
498  os << "\n"
499  << "===========================================================\n";
500 
501  return os;
502 }
503 
505 //
506 //
507 
508 void
510 {
511  scene.AddSolid (*this);
512 }
513 
515 //
516 //
517 
518 G4Polyhedron*
520 {
521  G4Polyhedron* polyhedron = fPtrSolid->CreatePolyhedron();
522  if (polyhedron)
523  {
524  polyhedron
526  }
527  else
528  {
529  DumpInfo();
530  G4Exception("G4DisplacedSolid::CreatePolyhedron()",
531  "GeomSolids2002", JustWarning,
532  "No G4Polyhedron for displaced solid");
533  }
534  return polyhedron;
535 }
536 
538 //
539 //
540 
542 {
543  if (!fpPolyhedron ||
547  {
549  fRebuildPolyhedron = false;
550  }
551  return fpPolyhedron;
552 }
G4AffineTransform GetTransform() const
void set(double x, double y, double z)
CLHEP::HepRotation getRotation() const
G4Polyhedron * GetPolyhedron() const
G4ThreeVector TransformAxis(const G4ThreeVector &axis) const
CLHEP::Hep3Vector getTranslation() const
void SetNetTranslation(const G4ThreeVector &tlate)
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
G4AffineTransform & Product(const G4AffineTransform &tf1, const G4AffineTransform &tf2)
TTree * t1
Definition: plottest35.C:26
virtual void AddSolid(const G4Box &)=0
G4ThreeVector GetFrameTranslation() const
void SetTransform(G4AffineTransform &)
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const =0
HepGeom::Transform3D G4Transform3D
std::ostream & print(std::ostream &os) const
Definition: RotationIO.cc:21
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
G4VSolid * Clone() const
G4RotationMatrix GetFrameRotation() const
virtual void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
Definition: G4VSolid.cc:625
const char * p
Definition: xmltok.h:285
void SetNetRotation(const G4RotationMatrix &rot)
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
G4VSolid * GetConstituentMovedSolid() const
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
G4DisplacedSolid(const G4String &pName, G4VSolid *pSolid, G4RotationMatrix *rotMatrix, const G4ThreeVector &transVector)
virtual G4ThreeVector GetPointOnSurface() const
Definition: G4VSolid.cc:152
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
double z() const
static double normal(HepRandomEngine *eptr)
Definition: RandPoisson.cc:77
const G4DisplacedSolid * GetDisplacedSolidPtr() const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
EInside Inside(const G4ThreeVector &p) const
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual EInside Inside(const G4ThreeVector &p) const =0
G4VSolid & operator=(const G4VSolid &rhs)
Definition: G4VSolid.cc:110
G4Polyhedron * CreatePolyhedron() const
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
void DescribeYourselfTo(G4VGraphicsScene &scene) const
void SetObjectTranslation(const G4ThreeVector &)
void SetDirectTransform(G4AffineTransform &)
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
void SetObjectRotation(const G4RotationMatrix &)
G4RotationMatrix GetObjectRotation() const
HepPolyhedron & Transform(const G4Transform3D &t)
G4AffineTransform GetDirectTransform() const
std::ostream & StreamInfo(std::ostream &os) const
virtual std::ostream & StreamInfo(std::ostream &os) const =0
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
G4ThreeVector GetObjectTranslation() const
G4Polyhedron * fpPolyhedron
static G4int GetNumberOfRotationSteps()
TTree * t2
Definition: plottest35.C:36
G4AffineTransform * fPtrTransform
G4ThreeVector NetTranslation() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
G4bool IsRotated() const
int G4int
Definition: G4Types.hh:78
EInside
Definition: geomdefs.hh:58
EAxis
Definition: geomdefs.hh:54
G4String GetName() const
void DumpInfo() const
G4DisplacedSolid & operator=(const G4DisplacedSolid &rhs)
void SetFrameTranslation(const G4ThreeVector &)
double x() const
G4AffineTransform Inverse() const
void SetFrameRotation(const G4RotationMatrix &)
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
virtual ~G4DisplacedSolid()
virtual G4Polyhedron * CreatePolyhedron() const
Definition: G4VSolid.cc:660
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
Char_t n[5]
G4AffineTransform * fDirectTransform
double y() const
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
virtual G4GeometryType GetEntityType() const =0
G4GeometryType GetEntityType() const
HepRotation inverse() const
G4ThreeVector GetPointOnSurface() const
G4RotationMatrix NetRotation() const