Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DisplacedSolid.cc
Go to the documentation of this file.
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// Implementation of G4DisplacedSolid class for Boolean
27// operations between other solids
28//
29// 28.10.98 V.Grichine: created
30// 28.02.18 E.Tcherniaev: improved contruction from G4DisplacedSolid
31// --------------------------------------------------------------------
32
33#include "G4DisplacedSolid.hh"
34
35#include "G4VoxelLimits.hh"
36
38
39#include "G4VGraphicsScene.hh"
40#include "G4Polyhedron.hh"
41
42////////////////////////////////////////////////////////////////
43//
44// Constructor for transformation like rotation of frame then translation
45// in new frame. It is similar to 1st constractor in G4PVPlacement
46
48 G4VSolid* pSolid ,
49 G4RotationMatrix* rotMatrix,
50 const G4ThreeVector& transVector )
51 : G4VSolid(pName)
52{
53 if (pSolid->GetEntityType() == "G4DisplacedSolid")
54 {
55 fPtrSolid = ((G4DisplacedSolid*)pSolid)->GetConstituentMovedSolid();
56 G4AffineTransform t1 = ((G4DisplacedSolid*)pSolid)->GetDirectTransform();
57 G4AffineTransform t2 = G4AffineTransform(rotMatrix,transVector);
59 }
60 else
61 {
62 fPtrSolid = pSolid;
63 fDirectTransform = new G4AffineTransform(rotMatrix,transVector);
64 }
66}
67
68/////////////////////////////////////////////////////////////////////////////////
69//
70// Constructor
71
73 G4VSolid* pSolid ,
74 const G4Transform3D& transform )
75 : G4VSolid(pName)
76{
77 if (pSolid->GetEntityType() == "G4DisplacedSolid")
78 {
79 fPtrSolid = ((G4DisplacedSolid*)pSolid)->GetConstituentMovedSolid();
80 G4AffineTransform t1 = ((G4DisplacedSolid*)pSolid)->GetDirectTransform();
82 transform.getTranslation());
84 }
85 else
86 {
87 fPtrSolid = pSolid;
89 transform.getTranslation()) ;
90 }
92}
93
94///////////////////////////////////////////////////////////////////
95//
96// Constructor for use with creation of Transient object
97// from Persistent object
98
100 G4VSolid* pSolid ,
101 const G4AffineTransform directTransform )
102 : G4VSolid(pName)
103{
104 if (pSolid->GetEntityType() == "G4DisplacedSolid")
105 {
106 fPtrSolid = ((G4DisplacedSolid*)pSolid)->GetConstituentMovedSolid();
107 G4AffineTransform t1 = ((G4DisplacedSolid*)pSolid)->GetDirectTransform();
108 G4AffineTransform t2 = G4AffineTransform(directTransform);
110 }
111 else
112 {
113 fPtrSolid = pSolid;
114 fDirectTransform = new G4AffineTransform(directTransform);
115 }
117}
118
119///////////////////////////////////////////////////////////////////
120//
121// Fake default constructor - sets only member data and allocates memory
122// for usage restricted to object persistency.
123
125 : G4VSolid(a)
126{
127}
128
129///////////////////////////////////////////////////////////////////
130//
131// Destructor
132
134{
136 delete fpPolyhedron; fpPolyhedron = nullptr;
137}
138
139///////////////////////////////////////////////////////////////
140//
141// Copy constructor
142
144 : G4VSolid (rhs), fPtrSolid(rhs.fPtrSolid)
145{
148}
149
150///////////////////////////////////////////////////////////////
151//
152// Assignment operator
153
155{
156 // Check assignment to self
157 //
158 if (this == &rhs) { return *this; }
159
160 // Copy base class data
161 //
163
164 // Copy data
165 //
166 fPtrSolid = rhs.fPtrSolid;
167 delete fPtrTransform; delete fDirectTransform;
170 fRebuildPolyhedron = false;
171 delete fpPolyhedron; fpPolyhedron = nullptr;
172
173 return *this;
174}
175
177{
178 if(fPtrTransform != nullptr)
179 {
180 delete fPtrTransform; fPtrTransform = nullptr;
181 delete fDirectTransform; fDirectTransform = nullptr;
182 }
183}
184
186{
187 return this;
188}
189
191{
192 return this;
193}
194
196{
197 return fPtrSolid;
198}
199
200/////////////////////////////////////////////////////////////////////////////
201
203{
204 G4AffineTransform aTransform = *fPtrTransform;
205 return aTransform;
206}
207
209{
210 fPtrTransform = &transform ;
211 fRebuildPolyhedron = true;
212}
213
214//////////////////////////////////////////////////////////////////////////////
215
217{
219 return aTransform;
220}
221
223{
224 fDirectTransform = &transform ;
225 fRebuildPolyhedron = true;
226}
227
228/////////////////////////////////////////////////////////////////////////////
229
231{
233 return InvRotation;
234}
235
237{
239 fRebuildPolyhedron = true;
240}
241
242/////////////////////////////////////////////////////////////////////////////
243
245{
247}
248
250{
252 fRebuildPolyhedron = true;
253}
254
255///////////////////////////////////////////////////////////////
256
258{
260 return Rotation;
261}
262
264{
266 fRebuildPolyhedron = true;
267}
268
269///////////////////////////////////////////////////////////////////////
270
272{
274}
275
277{
279 fRebuildPolyhedron = true;
280}
281
282//////////////////////////////////////////////////////////////////////////
283//
284// Get bounding box
285
287 G4ThreeVector& pMax) const
288{
290 {
291 // Special case of pure translation
292 //
293 fPtrSolid->BoundingLimits(pMin,pMax);
295 pMin += offset;
296 pMax += offset;
297 }
298 else
299 {
300 // General case, use CalculateExtent() to find bounding box
301 //
302 G4VoxelLimits unLimit;
303 G4double xmin,xmax,ymin,ymax,zmin,zmax;
307 pMin.set(xmin,ymin,zmin);
308 pMax.set(xmax,ymax,zmax);
309 }
310
311 // Check correctness of the bounding box
312 //
313 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
314 {
315 std::ostringstream message;
316 message << "Bad bounding box (min >= max) for solid: "
317 << GetName() << " !"
318 << "\npMin = " << pMin
319 << "\npMax = " << pMax;
320 G4Exception("G4DisplacedSolid::BoundingLimits()", "GeomMgt0001",
321 JustWarning, message);
322 DumpInfo();
323 }
324}
325
326//////////////////////////////////////////////////////////////////////////
327//
328// Calculate extent under transform and specified limit
329
330G4bool
332 const G4VoxelLimits& pVoxelLimit,
333 const G4AffineTransform& pTransform,
334 G4double& pMin,
335 G4double& pMax ) const
336{
337 G4AffineTransform sumTransform ;
338 sumTransform.Product(*fDirectTransform,pTransform) ;
339 return fPtrSolid->CalculateExtent(pAxis,pVoxelLimit,sumTransform,pMin,pMax) ;
340}
341
342/////////////////////////////////////////////////////
343//
344// SurfaceNormal
345
347{
349 return fPtrSolid->Inside(newPoint) ;
350}
351
352//////////////////////////////////////////////////////////////
353//
354//
355
358{
360 G4ThreeVector normal = fPtrSolid->SurfaceNormal(newPoint) ;
361 return fDirectTransform->TransformAxis(normal) ;
362}
363
364/////////////////////////////////////////////////////////////
365//
366// The same algorithm as in DistanceToIn(p)
367
370 const G4ThreeVector& v ) const
371{
373 G4ThreeVector newDirection = fPtrTransform->TransformAxis(v) ;
374 return fPtrSolid->DistanceToIn(newPoint,newDirection) ;
375}
376
377////////////////////////////////////////////////////////
378//
379// Approximate nearest distance from the point p to the intersection of
380// two solids
381
384{
386 return fPtrSolid->DistanceToIn(newPoint) ;
387}
388
389//////////////////////////////////////////////////////////
390//
391// The same algorithm as DistanceToOut(p)
392
395 const G4ThreeVector& v,
396 const G4bool calcNorm,
397 G4bool *validNorm,
398 G4ThreeVector *n ) const
399{
400 G4ThreeVector solNorm ;
402 G4ThreeVector newDirection = fPtrTransform->TransformAxis(v) ;
403 G4double dist = fPtrSolid->DistanceToOut(newPoint,newDirection,
404 calcNorm,validNorm,&solNorm) ;
405 if(calcNorm)
406 {
407 *n = fDirectTransform->TransformAxis(solNorm) ;
408 }
409 return dist ;
410}
411
412//////////////////////////////////////////////////////////////
413//
414// Inverted algorithm of DistanceToIn(p)
415
418{
420 return fPtrSolid->DistanceToOut(newPoint) ;
421}
422
423//////////////////////////////////////////////////////////////
424//
425// ComputeDimensions
426
427void
429 const G4int,
430 const G4VPhysicalVolume* )
431{
432 DumpInfo();
433 G4Exception("G4DisplacedSolid::ComputeDimensions()",
434 "GeomSolids0001", FatalException,
435 "Method not applicable in this context!");
436}
437
438//////////////////////////////////////////////////////////////////////////
439//
440// Returns a point (G4ThreeVector) randomly and uniformly selected
441// on the solid surface
442//
443
445{
448}
449
450//////////////////////////////////////////////////////////////////////////
451//
452// Return object type name
453
455{
456 return G4String("G4DisplacedSolid");
457}
458
459//////////////////////////////////////////////////////////////////////////
460//
461// Make a clone of the object
462//
464{
465 return new G4DisplacedSolid(*this);
466}
467
468//////////////////////////////////////////////////////////////////////////
469//
470// Stream object contents to an output stream
471
472std::ostream& G4DisplacedSolid::StreamInfo(std::ostream& os) const
473{
474 os << "-----------------------------------------------------------\n"
475 << " *** Dump for Displaced solid - " << GetName() << " ***\n"
476 << " ===================================================\n"
477 << " Solid type: " << GetEntityType() << "\n"
478 << " Parameters of constituent solid: \n"
479 << "===========================================================\n";
481 os << "===========================================================\n"
482 << " Transformations: \n"
483 << " Direct transformation - translation : \n"
484 << " " << fDirectTransform->NetTranslation() << "\n"
485 << " - rotation : \n"
486 << " ";
488 os << "\n"
489 << "===========================================================\n";
490
491 return os;
492}
493
494//////////////////////////////////////////////////////////////////////////
495//
496// DescribeYourselfTo
497
498void
500{
501 scene.AddSolid (*this);
502}
503
504//////////////////////////////////////////////////////////////////////////
505//
506// CreatePolyhedron
507
510{
511 G4Polyhedron* polyhedron = fPtrSolid->CreatePolyhedron();
512 if (polyhedron != nullptr)
513 {
514 polyhedron
516 }
517 else
518 {
519 DumpInfo();
520 G4Exception("G4DisplacedSolid::CreatePolyhedron()",
521 "GeomSolids2002", JustWarning,
522 "No G4Polyhedron for displaced solid");
523 }
524 return polyhedron;
525}
526
527//////////////////////////////////////////////////////////////////////////
528//
529// GetPolyhedron
530
532{
533 if (fpPolyhedron == nullptr ||
537 {
539 fRebuildPolyhedron = false;
540 }
541 return fpPolyhedron;
542}
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
HepGeom::Transform3D G4Transform3D
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
double z() const
double x() const
double y() const
void set(double x, double y, double z)
std::ostream & print(std::ostream &os) const
Definition: RotationIO.cc:17
HepRotation inverse() const
G4AffineTransform & Product(const G4AffineTransform &tf1, const G4AffineTransform &tf2)
G4bool IsRotated() const
G4AffineTransform Inverse() const
void SetNetRotation(const G4RotationMatrix &rot)
G4ThreeVector NetTranslation() const
G4RotationMatrix NetRotation() const
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
G4ThreeVector TransformAxis(const G4ThreeVector &axis) const
void SetNetTranslation(const G4ThreeVector &tlate)
G4GeometryType GetEntityType() const
G4Polyhedron * CreatePolyhedron() const
G4RotationMatrix GetObjectRotation() const
G4Polyhedron * fpPolyhedron
void SetTransform(G4AffineTransform &)
virtual ~G4DisplacedSolid()
G4VSolid * Clone() const
G4AffineTransform * fPtrTransform
G4AffineTransform * fDirectTransform
G4VSolid * GetConstituentMovedSolid() const
G4AffineTransform GetTransform() const
G4Polyhedron * GetPolyhedron() const
const G4DisplacedSolid * GetDisplacedSolidPtr() const
void SetObjectRotation(const G4RotationMatrix &)
G4ThreeVector GetPointOnSurface() const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
G4DisplacedSolid & operator=(const G4DisplacedSolid &rhs)
G4DisplacedSolid(const G4String &pName, G4VSolid *pSolid, G4RotationMatrix *rotMatrix, const G4ThreeVector &transVector)
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
void DescribeYourselfTo(G4VGraphicsScene &scene) const
void SetDirectTransform(G4AffineTransform &)
G4ThreeVector GetObjectTranslation() const
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
std::ostream & StreamInfo(std::ostream &os) const
void SetFrameRotation(const G4RotationMatrix &)
void SetFrameTranslation(const G4ThreeVector &)
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
G4AffineTransform GetDirectTransform() const
EInside Inside(const G4ThreeVector &p) const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4RotationMatrix GetFrameRotation() const
void SetObjectTranslation(const G4ThreeVector &)
G4ThreeVector GetFrameTranslation() const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
virtual void AddSolid(const G4Box &)=0
G4String GetName() const
virtual std::ostream & StreamInfo(std::ostream &os) const =0
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const =0
virtual EInside Inside(const G4ThreeVector &p) const =0
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
void DumpInfo() const
virtual G4ThreeVector GetPointOnSurface() const
Definition: G4VSolid.cc:140
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
Definition: G4VSolid.cc:653
virtual G4Polyhedron * CreatePolyhedron() const
Definition: G4VSolid.cc:688
G4VSolid & operator=(const G4VSolid &rhs)
Definition: G4VSolid.cc:98
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
virtual G4GeometryType GetEntityType() const =0
CLHEP::HepRotation getRotation() const
CLHEP::Hep3Vector getTranslation() const
static G4int GetNumberOfRotationSteps()
HepPolyhedron & Transform(const G4Transform3D &t)
EAxis
Definition: geomdefs.hh:54
@ kYAxis
Definition: geomdefs.hh:56
@ kXAxis
Definition: geomdefs.hh:55
@ kZAxis
Definition: geomdefs.hh:57
EInside
Definition: geomdefs.hh:67