Geant4_10
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: G4DisplacedSolid.cc 66356 2012-12-18 09:02: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 //
38 // --------------------------------------------------------------------
39 
40 #include "G4DisplacedSolid.hh"
41 
42 #include "G4VoxelLimits.hh"
43 
44 #include "G4VPVParameterisation.hh"
45 
46 #include "G4VGraphicsScene.hh"
47 #include "G4Polyhedron.hh"
48 
50 //
51 // Constructor for transformation like rotation of frame then translation
52 // in new frame. It is similar to 1st constractor in G4PVPlacement
53 
55  G4VSolid* pSolid ,
56  G4RotationMatrix* rotMatrix,
57  const G4ThreeVector& transVector )
58  : G4VSolid(pName), fpPolyhedron(0)
59 {
60  fPtrSolid = pSolid ;
61  fPtrTransform = new G4AffineTransform(rotMatrix,transVector) ;
63  fDirectTransform = new G4AffineTransform(rotMatrix,transVector) ;
64 }
65 
67 //
68 // Constructor
69 
71  G4VSolid* pSolid ,
72  const G4Transform3D& transform )
73  : G4VSolid(pName), fpPolyhedron(0)
74 {
75  fPtrSolid = pSolid ;
77  transform.getTranslation()) ;
78 
80  transform.getTranslation()) ;
81  fPtrTransform->Invert() ;
82 }
83 
85 //
86 // Constructor for use with creation of Transient object
87 // from Persistent object
88 
90  G4VSolid* pSolid ,
91  const G4AffineTransform directTransform )
92  : G4VSolid(pName), fpPolyhedron(0)
93 {
94  fPtrSolid = pSolid ;
95  fDirectTransform = new G4AffineTransform( directTransform );
96  fPtrTransform = new G4AffineTransform( directTransform.Inverse() ) ;
97 }
98 
100 //
101 // Fake default constructor - sets only member data and allocates memory
102 // for usage restricted to object persistency.
103 
105  : G4VSolid(a), fPtrSolid(0), fPtrTransform(0),
106  fDirectTransform(0), fpPolyhedron(0)
107 {
108 }
109 
111 //
112 // Destructor
113 
115 {
117  delete fpPolyhedron;
118 }
119 
121 //
122 // Copy constructor
123 
125  : G4VSolid (rhs), fPtrSolid(rhs.fPtrSolid), fpPolyhedron(0)
126 {
129 }
130 
132 //
133 // Assignment operator
134 
136 {
137  // Check assignment to self
138  //
139  if (this == &rhs) { return *this; }
140 
141  // Copy base class data
142  //
143  G4VSolid::operator=(rhs);
144 
145  // Copy data
146  //
147  fPtrSolid = rhs.fPtrSolid;
148  delete fPtrTransform; delete fDirectTransform;
151  delete fpPolyhedron; fpPolyhedron= 0;
152 
153  return *this;
154 }
155 
157 {
158  if(fPtrTransform)
159  {
160  delete fPtrTransform; fPtrTransform=0;
162  }
163 }
164 
166 {
167  return this;
168 }
169 
171 {
172  return this;
173 }
174 
176 {
177  return fPtrSolid;
178 }
179 
181 
183 {
184  G4AffineTransform aTransform = *fPtrTransform;
185  return aTransform;
186 }
187 
189 {
190  fPtrTransform = &transform ;
191  fpPolyhedron = 0;
192 }
193 
195 
197 {
198  G4AffineTransform aTransform= *fDirectTransform;
199  return aTransform;
200 }
201 
203 {
204  fDirectTransform = &transform ;
205  fpPolyhedron = 0;
206 }
207 
209 
211 {
213  return InvRotation;
214 }
215 
217 {
219  fpPolyhedron = 0;
220 }
221 
223 
225 {
226  return fPtrTransform->NetTranslation();
227 }
228 
230 {
232  fpPolyhedron = 0;
233 }
234 
236 
238 {
240  return Rotation;
241 }
242 
244 {
245  fPtrTransform->SetNetRotation(matrix);
246  fpPolyhedron = 0;
247 }
248 
250 
252 {
254 }
255 
257 {
259  fpPolyhedron = 0;
260 }
261 
263 //
264 //
265 
266 G4bool
268  const G4VoxelLimits& pVoxelLimit,
269  const G4AffineTransform& pTransform,
270  G4double& pMin,
271  G4double& pMax ) const
272 {
273  G4AffineTransform sumTransform ;
274  sumTransform.Product(*fDirectTransform,pTransform) ;
275  return fPtrSolid->CalculateExtent(pAxis,pVoxelLimit,sumTransform,pMin,pMax) ;
276 }
277 
279 //
280 //
281 
283 {
285  return fPtrSolid->Inside(newPoint) ;
286 }
287 
289 //
290 //
291 
294 {
296  G4ThreeVector normal = fPtrSolid->SurfaceNormal(newPoint) ;
297  return fDirectTransform->TransformAxis(normal) ;
298 }
299 
301 //
302 // The same algorithm as in DistanceToIn(p)
303 
304 G4double
306  const G4ThreeVector& v ) const
307 {
309  G4ThreeVector newDirection = fPtrTransform->TransformAxis(v) ;
310  return fPtrSolid->DistanceToIn(newPoint,newDirection) ;
311 }
312 
314 //
315 // Approximate nearest distance from the point p to the intersection of
316 // two solids
317 
318 G4double
320 {
322  return fPtrSolid->DistanceToIn(newPoint) ;
323 }
324 
326 //
327 // The same algorithm as DistanceToOut(p)
328 
329 G4double
331  const G4ThreeVector& v,
332  const G4bool calcNorm,
333  G4bool *validNorm,
334  G4ThreeVector *n ) const
335 {
336  G4ThreeVector solNorm ;
338  G4ThreeVector newDirection = fPtrTransform->TransformAxis(v) ;
339  G4double dist = fPtrSolid->DistanceToOut(newPoint,newDirection,
340  calcNorm,validNorm,&solNorm) ;
341  if(calcNorm)
342  {
343  *n = fDirectTransform->TransformAxis(solNorm) ;
344  }
345  return dist ;
346 }
347 
349 //
350 // Inverted algorithm of DistanceToIn(p)
351 
352 G4double
354 {
356  return fPtrSolid->DistanceToOut(newPoint) ;
357 }
358 
360 //
361 //
362 
363 void
365  const G4int,
366  const G4VPhysicalVolume* )
367 {
368  DumpInfo();
369  G4Exception("G4DisplacedSolid::ComputeDimensions()",
370  "GeomSolids0001", FatalException,
371  "Method not applicable in this context!");
372 }
373 
375 //
376 // Returns a point (G4ThreeVector) randomly and uniformly selected
377 // on the solid surface
378 //
379 
381 {
383  return fDirectTransform->TransformPoint(p);
384 }
385 
387 //
388 // Return object type name
389 
391 {
392  return G4String("G4DisplacedSolid");
393 }
394 
396 //
397 // Make a clone of the object
398 //
400 {
401  return new G4DisplacedSolid(*this);
402 }
403 
405 //
406 // Stream object contents to an output stream
407 
408 std::ostream& G4DisplacedSolid::StreamInfo(std::ostream& os) const
409 {
410  os << "-----------------------------------------------------------\n"
411  << " *** Dump for Displaced solid - " << GetName() << " ***\n"
412  << " ===================================================\n"
413  << " Solid type: " << GetEntityType() << "\n"
414  << " Parameters of constituent solid: \n"
415  << "===========================================================\n";
416  fPtrSolid->StreamInfo(os);
417  os << "===========================================================\n"
418  << " Transformations: \n"
419  << " Direct transformation - translation : \n"
420  << " " << fDirectTransform->NetTranslation() << "\n"
421  << " - rotation : \n"
422  << " ";
424  os << "\n"
425  << "===========================================================\n";
426 
427  return os;
428 }
429 
431 //
432 //
433 
434 void
436 {
437  scene.AddSolid (*this);
438 }
439 
441 //
442 //
443 
444 G4Polyhedron*
446 {
447  G4Polyhedron* polyhedron = fPtrSolid->CreatePolyhedron();
448  polyhedron
450  return polyhedron;
451 }
452 
454 //
455 //
456 
458 {
459  if (!fpPolyhedron ||
462  {
463  delete fpPolyhedron;
465  }
466  return fpPolyhedron;
467 }
G4String GetName() const
G4DisplacedSolid & operator=(const G4DisplacedSolid &rhs)
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const =0
G4Polyhedron * GetPolyhedron() const
tuple a
Definition: test.py:11
virtual ~G4DisplacedSolid()
std::ostream & print(std::ostream &os) const
Definition: RotationIO.cc:21
G4AffineTransform Inverse() const
G4ThreeVector GetFrameTranslation() const
const char * p
Definition: xmltok.h:285
G4RotationMatrix GetObjectRotation() const
const G4DisplacedSolid * GetDisplacedSolidPtr() const
G4AffineTransform GetDirectTransform() const
G4ThreeVector NetTranslation() const
G4Polyhedron * CreatePolyhedron() const
HepPolyhedron & Transform(const G4Transform3D &t)
virtual void AddSolid(const G4Box &)=0
int G4int
Definition: G4Types.hh:78
G4VSolid * Clone() const
G4ThreeVector GetObjectTranslation() const
HepRotation inverse() const
void DumpInfo() const
G4RotationMatrix GetFrameRotation() const
G4AffineTransform & Invert()
Char_t n[5]
virtual std::ostream & StreamInfo(std::ostream &os) const =0
void SetNetTranslation(const G4ThreeVector &tlate)
void SetNetRotation(const G4RotationMatrix &rot)
void SetDirectTransform(G4AffineTransform &)
virtual EInside Inside(const G4ThreeVector &p) const =0
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
void SetFrameTranslation(const G4ThreeVector &)
bool G4bool
Definition: G4Types.hh:79
CLHEP::HepRotation getRotation() const
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
G4DisplacedSolid(const G4String &pName, G4VSolid *pSolid, G4RotationMatrix *rotMatrix, const G4ThreeVector &transVector)
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
HepGeom::Transform3D G4Transform3D
virtual G4Polyhedron * CreatePolyhedron() const
Definition: G4VSolid.cc:639
G4GeometryType GetEntityType() const
G4AffineTransform GetTransform() const
tuple v
Definition: test.py:18
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4AffineTransform * fPtrTransform
G4RotationMatrix NetRotation() const
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
static G4int GetNumberOfRotationSteps()
EInside
Definition: geomdefs.hh:58
G4VSolid * GetConstituentMovedSolid() const
EAxis
Definition: geomdefs.hh:54
virtual G4ThreeVector GetPointOnSurface() const
Definition: G4VSolid.cc:152
G4ThreeVector TransformAxis(const G4ThreeVector &axis) const
G4Polyhedron * fpPolyhedron
G4AffineTransform * fDirectTransform
G4AffineTransform & Product(const G4AffineTransform &tf1, const G4AffineTransform &tf2)
G4VSolid & operator=(const G4VSolid &rhs)
Definition: G4VSolid.cc:110
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
void SetObjectTranslation(const G4ThreeVector &)
void SetTransform(G4AffineTransform &)
double G4double
Definition: G4Types.hh:76
std::ostream & StreamInfo(std::ostream &os) const
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
CLHEP::Hep3Vector getTranslation() const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
void SetObjectRotation(const G4RotationMatrix &)
void SetFrameRotation(const G4RotationMatrix &)
G4ThreeVector GetPointOnSurface() const
void DescribeYourselfTo(G4VGraphicsScene &scene) const
EInside Inside(const G4ThreeVector &p) const