Geant4 9.6.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//
27// $Id$
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//
38// --------------------------------------------------------------------
39
40#include "G4DisplacedSolid.hh"
41
42#include "G4VoxelLimits.hh"
43
45
46#include "G4VGraphicsScene.hh"
47#include "G4Polyhedron.hh"
48#include "G4NURBS.hh"
49// #include "G4NURBSbox.hh"
50
51////////////////////////////////////////////////////////////////
52//
53// Constructor for transformation like rotation of frame then translation
54// in new frame. It is similar to 1st constractor in G4PVPlacement
55
57 G4VSolid* pSolid ,
58 G4RotationMatrix* rotMatrix,
59 const G4ThreeVector& transVector )
60 : G4VSolid(pName), fpPolyhedron(0)
61{
62 fPtrSolid = pSolid ;
63 fPtrTransform = new G4AffineTransform(rotMatrix,transVector) ;
65 fDirectTransform = new G4AffineTransform(rotMatrix,transVector) ;
66}
67
68/////////////////////////////////////////////////////////////////////////////////
69//
70// Constructor
71
73 G4VSolid* pSolid ,
74 const G4Transform3D& transform )
75 : G4VSolid(pName), fpPolyhedron(0)
76{
77 fPtrSolid = pSolid ;
79 transform.getTranslation()) ;
80
82 transform.getTranslation()) ;
84}
85
86///////////////////////////////////////////////////////////////////
87//
88// Constructor for use with creation of Transient object
89// from Persistent object
90
92 G4VSolid* pSolid ,
93 const G4AffineTransform directTransform )
94 : G4VSolid(pName), fpPolyhedron(0)
95{
96 fPtrSolid = pSolid ;
97 fDirectTransform = new G4AffineTransform( directTransform );
98 fPtrTransform = new G4AffineTransform( directTransform.Inverse() ) ;
99}
100
101///////////////////////////////////////////////////////////////////
102//
103// Fake default constructor - sets only member data and allocates memory
104// for usage restricted to object persistency.
105
107 : G4VSolid(a), fPtrSolid(0), fPtrTransform(0),
108 fDirectTransform(0), fpPolyhedron(0)
109{
110}
111
112///////////////////////////////////////////////////////////////////
113//
114// Destructor
115
117{
119 delete fpPolyhedron;
120}
121
122///////////////////////////////////////////////////////////////
123//
124// Copy constructor
125
127 : G4VSolid (rhs), fPtrSolid(rhs.fPtrSolid), fpPolyhedron(0)
128{
131}
132
133///////////////////////////////////////////////////////////////
134//
135// Assignment operator
136
138{
139 // Check assignment to self
140 //
141 if (this == &rhs) { return *this; }
142
143 // Copy base class data
144 //
146
147 // Copy data
148 //
149 fPtrSolid = rhs.fPtrSolid;
150 delete fPtrTransform; delete fDirectTransform;
153 delete fpPolyhedron; fpPolyhedron= 0;
154
155 return *this;
156}
157
159{
160 if(fPtrTransform)
161 {
164 }
165}
166
168{
169 return this;
170}
171
173{
174 return this;
175}
176
178{
179 return fPtrSolid;
180}
181
182/////////////////////////////////////////////////////////////////////////////
183
185{
186 G4AffineTransform aTransform = *fPtrTransform;
187 return aTransform;
188}
189
191{
192 fPtrTransform = &transform ;
193 fpPolyhedron = 0;
194}
195
196//////////////////////////////////////////////////////////////////////////////
197
199{
201 return aTransform;
202}
203
205{
206 fDirectTransform = &transform ;
207 fpPolyhedron = 0;
208}
209
210/////////////////////////////////////////////////////////////////////////////
211
213{
215 return InvRotation;
216}
217
219{
221 fpPolyhedron = 0;
222}
223
224/////////////////////////////////////////////////////////////////////////////
225
227{
229}
230
232{
234 fpPolyhedron = 0;
235}
236
237///////////////////////////////////////////////////////////////
238
240{
242 return Rotation;
243}
244
246{
248 fpPolyhedron = 0;
249}
250
251///////////////////////////////////////////////////////////////////////
252
254{
256}
257
259{
261 fpPolyhedron = 0;
262}
263
264///////////////////////////////////////////////////////////////
265//
266//
267
268G4bool
270 const G4VoxelLimits& pVoxelLimit,
271 const G4AffineTransform& pTransform,
272 G4double& pMin,
273 G4double& pMax ) const
274{
275 G4AffineTransform sumTransform ;
276 sumTransform.Product(*fDirectTransform,pTransform) ;
277 return fPtrSolid->CalculateExtent(pAxis,pVoxelLimit,sumTransform,pMin,pMax) ;
278}
279
280/////////////////////////////////////////////////////
281//
282//
283
285{
287 return fPtrSolid->Inside(newPoint) ;
288}
289
290//////////////////////////////////////////////////////////////
291//
292//
293
296{
298 G4ThreeVector normal = fPtrSolid->SurfaceNormal(newPoint) ;
299 return fDirectTransform->TransformAxis(normal) ;
300}
301
302/////////////////////////////////////////////////////////////
303//
304// The same algorithm as in DistanceToIn(p)
305
308 const G4ThreeVector& v ) const
309{
311 G4ThreeVector newDirection = fPtrTransform->TransformAxis(v) ;
312 return fPtrSolid->DistanceToIn(newPoint,newDirection) ;
313}
314
315////////////////////////////////////////////////////////
316//
317// Approximate nearest distance from the point p to the intersection of
318// two solids
319
322{
324 return fPtrSolid->DistanceToIn(newPoint) ;
325}
326
327//////////////////////////////////////////////////////////
328//
329// The same algorithm as DistanceToOut(p)
330
333 const G4ThreeVector& v,
334 const G4bool calcNorm,
335 G4bool *validNorm,
336 G4ThreeVector *n ) const
337{
338 G4ThreeVector solNorm ;
340 G4ThreeVector newDirection = fPtrTransform->TransformAxis(v) ;
341 G4double dist = fPtrSolid->DistanceToOut(newPoint,newDirection,
342 calcNorm,validNorm,&solNorm) ;
343 if(calcNorm)
344 {
345 *n = fDirectTransform->TransformAxis(solNorm) ;
346 }
347 return dist ;
348}
349
350//////////////////////////////////////////////////////////////
351//
352// Inverted algorithm of DistanceToIn(p)
353
356{
358 return fPtrSolid->DistanceToOut(newPoint) ;
359}
360
361//////////////////////////////////////////////////////////////
362//
363//
364
365void
367 const G4int,
368 const G4VPhysicalVolume* )
369{
370 DumpInfo();
371 G4Exception("G4DisplacedSolid::ComputeDimensions()",
372 "GeomSolids0001", FatalException,
373 "Method not applicable in this context!");
374}
375
376//////////////////////////////////////////////////////////////////////////
377//
378// Returns a point (G4ThreeVector) randomly and uniformly selected
379// on the solid surface
380//
381
383{
386}
387
388//////////////////////////////////////////////////////////////////////////
389//
390// Return object type name
391
393{
394 return G4String("G4DisplacedSolid");
395}
396
397//////////////////////////////////////////////////////////////////////////
398//
399// Make a clone of the object
400//
402{
403 return new G4DisplacedSolid(*this);
404}
405
406//////////////////////////////////////////////////////////////////////////
407//
408// Stream object contents to an output stream
409
410std::ostream& G4DisplacedSolid::StreamInfo(std::ostream& os) const
411{
412 os << "-----------------------------------------------------------\n"
413 << " *** Dump for Displaced solid - " << GetName() << " ***\n"
414 << " ===================================================\n"
415 << " Solid type: " << GetEntityType() << "\n"
416 << " Parameters of constituent solid: \n"
417 << "===========================================================\n";
419 os << "===========================================================\n"
420 << " Transformations: \n"
421 << " Direct transformation - translation : \n"
422 << " " << fDirectTransform->NetTranslation() << "\n"
423 << " - rotation : \n"
424 << " ";
426 os << "\n"
427 << "===========================================================\n";
428
429 return os;
430}
431
432//////////////////////////////////////////////////////////////////////////
433//
434//
435
436void
438{
439 scene.AddSolid (*this);
440}
441
442//////////////////////////////////////////////////////////////////////////
443//
444//
445
448{
449 G4Polyhedron* polyhedron = fPtrSolid->CreatePolyhedron();
450 polyhedron
452 return polyhedron;
453}
454
455//////////////////////////////////////////////////////////////////////////
456//
457//
458
459G4NURBS*
461{
462 // Take into account local transformation - see CreatePolyhedron.
463 // return fPtrSolid->CreateNURBS() ;
464 return 0;
465}
466
467//////////////////////////////////////////////////////////////////////////
468//
469//
470
472{
473 if (!fpPolyhedron ||
476 {
477 delete fpPolyhedron;
479 }
480 return fpPolyhedron;
481}
@ FatalException
HepGeom::Transform3D G4Transform3D
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
std::ostream & print(std::ostream &os) const
Definition: RotationIO.cc:21
HepRotation inverse() const
G4AffineTransform & Product(const G4AffineTransform &tf1, const G4AffineTransform &tf2)
G4AffineTransform Inverse() const
void SetNetRotation(const G4RotationMatrix &rot)
G4ThreeVector NetTranslation() const
G4AffineTransform & Invert()
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
G4NURBS * CreateNURBS() 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 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
void DumpInfo() const
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
virtual G4ThreeVector GetPointOnSurface() const
Definition: G4VSolid.cc:152
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual G4Polyhedron * CreatePolyhedron() const
Definition: G4VSolid.cc:637
G4VSolid & operator=(const G4VSolid &rhs)
Definition: G4VSolid.cc:110
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
CLHEP::HepRotation getRotation() const
CLHEP::Hep3Vector getTranslation() const
static G4int GetNumberOfRotationSteps()
HepPolyhedron & Transform(const G4Transform3D &t)
EAxis
Definition: geomdefs.hh:54
EInside
Definition: geomdefs.hh:58
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41