Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
44 #include "G4VPVParameterisation.hh"
45 
46 #include "G4VGraphicsScene.hh"
47 #include "G4Polyhedron.hh"
48 #include "G4NURBS.hh"
49 // #include "G4NURBSbox.hh"
50 
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 
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()) ;
83  fPtrTransform->Invert() ;
84 }
85 
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 
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 
113 //
114 // Destructor
115 
117 {
119  delete fpPolyhedron;
120 }
121 
123 //
124 // Copy constructor
125 
127  : G4VSolid (rhs), fPtrSolid(rhs.fPtrSolid), fpPolyhedron(0)
128 {
131 }
132 
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  //
145  G4VSolid::operator=(rhs);
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  {
162  delete fPtrTransform; fPtrTransform=0;
164  }
165 }
166 
168 {
169  return this;
170 }
171 
173 {
174  return this;
175 }
176 
178 {
179  return fPtrSolid;
180 }
181 
183 
185 {
186  G4AffineTransform aTransform = *fPtrTransform;
187  return aTransform;
188 }
189 
191 {
192  fPtrTransform = &transform ;
193  fpPolyhedron = 0;
194 }
195 
197 
199 {
200  G4AffineTransform aTransform= *fDirectTransform;
201  return aTransform;
202 }
203 
205 {
206  fDirectTransform = &transform ;
207  fpPolyhedron = 0;
208 }
209 
211 
213 {
215  return InvRotation;
216 }
217 
219 {
221  fpPolyhedron = 0;
222 }
223 
225 
227 {
228  return fPtrTransform->NetTranslation();
229 }
230 
232 {
234  fpPolyhedron = 0;
235 }
236 
238 
240 {
242  return Rotation;
243 }
244 
246 {
247  fPtrTransform->SetNetRotation(matrix);
248  fpPolyhedron = 0;
249 }
250 
252 
254 {
256 }
257 
259 {
261  fpPolyhedron = 0;
262 }
263 
265 //
266 //
267 
268 G4bool
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 
281 //
282 //
283 
285 {
287  return fPtrSolid->Inside(newPoint) ;
288 }
289 
291 //
292 //
293 
296 {
298  G4ThreeVector normal = fPtrSolid->SurfaceNormal(newPoint) ;
299  return fDirectTransform->TransformAxis(normal) ;
300 }
301 
303 //
304 // The same algorithm as in DistanceToIn(p)
305 
306 G4double
308  const G4ThreeVector& v ) const
309 {
311  G4ThreeVector newDirection = fPtrTransform->TransformAxis(v) ;
312  return fPtrSolid->DistanceToIn(newPoint,newDirection) ;
313 }
314 
316 //
317 // Approximate nearest distance from the point p to the intersection of
318 // two solids
319 
320 G4double
322 {
324  return fPtrSolid->DistanceToIn(newPoint) ;
325 }
326 
328 //
329 // The same algorithm as DistanceToOut(p)
330 
331 G4double
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 
351 //
352 // Inverted algorithm of DistanceToIn(p)
353 
354 G4double
356 {
358  return fPtrSolid->DistanceToOut(newPoint) ;
359 }
360 
362 //
363 //
364 
365 void
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 
377 //
378 // Returns a point (G4ThreeVector) randomly and uniformly selected
379 // on the solid surface
380 //
381 
383 {
385  return fDirectTransform->TransformPoint(p);
386 }
387 
389 //
390 // Return object type name
391 
393 {
394  return G4String("G4DisplacedSolid");
395 }
396 
398 //
399 // Make a clone of the object
400 //
402 {
403  return new G4DisplacedSolid(*this);
404 }
405 
407 //
408 // Stream object contents to an output stream
409 
410 std::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";
418  fPtrSolid->StreamInfo(os);
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 
433 //
434 //
435 
436 void
438 {
439  scene.AddSolid (*this);
440 }
441 
443 //
444 //
445 
446 G4Polyhedron*
448 {
449  G4Polyhedron* polyhedron = fPtrSolid->CreatePolyhedron();
450  polyhedron
452  return polyhedron;
453 }
454 
456 //
457 //
458 
459 G4NURBS*
461 {
462  // Take into account local transformation - see CreatePolyhedron.
463  // return fPtrSolid->CreateNURBS() ;
464  return 0;
465 }
466 
468 //
469 //
470 
472 {
473  if (!fpPolyhedron ||
476  {
477  delete fpPolyhedron;
479  }
480  return fpPolyhedron;
481 }