Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4BooleanSolid.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: G4BooleanSolid.cc 66356 2012-12-18 09:02:32Z gcosmo $
28 //
29 // Implementation for the abstract base class for solids created by boolean
30 // operations between other solids
31 //
32 // History:
33 //
34 // 10.09.98 V.Grichine, created
35 //
36 // --------------------------------------------------------------------
37 
38 #include "G4BooleanSolid.hh"
39 #include "G4VSolid.hh"
40 #include "G4Polyhedron.hh"
41 #include "HepPolyhedronProcessor.h"
42 #include "Randomize.hh"
43 
44 //////////////////////////////////////////////////////////////////
45 //
46 // Constructor
47 
49  G4VSolid* pSolidA ,
50  G4VSolid* pSolidB ) :
51  G4VSolid(pName), fAreaRatio(0.), fStatistics(1000000), fCubVolEpsilon(0.001),
52  fAreaAccuracy(-1.), fCubicVolume(0.), fSurfaceArea(0.),
53  fpPolyhedron(0), createdDisplacedSolid(false)
54 {
55  fPtrSolidA = pSolidA ;
56  fPtrSolidB = pSolidB ;
57 }
58 
59 //////////////////////////////////////////////////////////////////
60 //
61 // Constructor
62 
64  G4VSolid* pSolidA ,
65  G4VSolid* pSolidB ,
66  G4RotationMatrix* rotMatrix,
67  const G4ThreeVector& transVector ) :
68  G4VSolid(pName), fAreaRatio(0.), fStatistics(1000000), fCubVolEpsilon(0.001),
69  fAreaAccuracy(-1.), fCubicVolume(0.), fSurfaceArea(0.),
70  fpPolyhedron(0), createdDisplacedSolid(true)
71 {
72  fPtrSolidA = pSolidA ;
73  fPtrSolidB = new G4DisplacedSolid("placedB",pSolidB,rotMatrix,transVector) ;
74 }
75 
76 //////////////////////////////////////////////////////////////////
77 //
78 // Constructor
79 
81  G4VSolid* pSolidA ,
82  G4VSolid* pSolidB ,
83  const G4Transform3D& transform ) :
84  G4VSolid(pName), fAreaRatio(0.), fStatistics(1000000), fCubVolEpsilon(0.001),
85  fAreaAccuracy(-1.), fCubicVolume(0.), fSurfaceArea(0.),
86  fpPolyhedron(0), createdDisplacedSolid(true)
87 {
88  fPtrSolidA = pSolidA ;
89  fPtrSolidB = new G4DisplacedSolid("placedB",pSolidB,transform) ;
90 }
91 
92 ///////////////////////////////////////////////////////////////
93 //
94 // Fake default constructor - sets only member data and allocates memory
95 // for usage restricted to object persistency.
96 
98  : G4VSolid(a), fPtrSolidA(0), fPtrSolidB(0), fAreaRatio(0.),
99  fStatistics(1000000), fCubVolEpsilon(0.001),
100  fAreaAccuracy(-1.), fCubicVolume(0.), fSurfaceArea(0.),
101  fpPolyhedron(0), createdDisplacedSolid(false)
102 {
103 }
104 
105 ///////////////////////////////////////////////////////////////
106 //
107 // Destructor deletes transformation contents of the created displaced solid
108 
110 {
111  if(createdDisplacedSolid)
112  {
113  ((G4DisplacedSolid*)fPtrSolidB)->CleanTransformations();
114  }
115  delete fpPolyhedron;
116 }
117 
118 ///////////////////////////////////////////////////////////////
119 //
120 // Copy constructor
121 
123  : G4VSolid (rhs), fPtrSolidA(rhs.fPtrSolidA), fPtrSolidB(rhs.fPtrSolidB),
124  fAreaRatio(rhs.fAreaRatio),
125  fStatistics(rhs.fStatistics), fCubVolEpsilon(rhs.fCubVolEpsilon),
126  fAreaAccuracy(rhs.fAreaAccuracy), fCubicVolume(rhs.fCubicVolume),
127  fSurfaceArea(rhs.fSurfaceArea), fpPolyhedron(0),
128  createdDisplacedSolid(rhs.createdDisplacedSolid)
129 {
130 }
131 
132 ///////////////////////////////////////////////////////////////
133 //
134 // Assignment operator
135 
137 {
138  // Check assignment to self
139  //
140  if (this == &rhs) { return *this; }
141 
142  // Copy base class data
143  //
144  G4VSolid::operator=(rhs);
145 
146  // Copy data
147  //
149  fAreaRatio= rhs.fAreaRatio;
150  fStatistics= rhs.fStatistics; fCubVolEpsilon= rhs.fCubVolEpsilon;
151  fAreaAccuracy= rhs.fAreaAccuracy; fCubicVolume= rhs.fCubicVolume;
152  fSurfaceArea= rhs.fSurfaceArea; fpPolyhedron= 0;
153  createdDisplacedSolid= rhs.createdDisplacedSolid;
154 
155  return *this;
156 }
157 
158 ///////////////////////////////////////////////////////////////
159 //
160 // If Solid is made up from a Boolean operation of two solids,
161 // return the corresponding solid (for no=0 and 1)
162 // If the solid is not a "Boolean", return 0
163 
165 {
166  const G4VSolid* subSolid=0;
167  if( no == 0 )
168  subSolid = fPtrSolidA;
169  else if( no == 1 )
170  subSolid = fPtrSolidB;
171  else
172  {
173  DumpInfo();
174  G4Exception("G4BooleanSolid::GetConstituentSolid()",
175  "GeomSolids0002", FatalException, "Invalid solid index.");
176  }
177 
178  return subSolid;
179 }
180 
181 ///////////////////////////////////////////////////////////////
182 //
183 // If Solid is made up from a Boolean operation of two solids,
184 // return the corresponding solid (for no=0 and 1)
185 // If the solid is not a "Boolean", return 0
186 
188 {
189  G4VSolid* subSolid=0;
190  if( no == 0 )
191  subSolid = fPtrSolidA;
192  else if( no == 1 )
193  subSolid = fPtrSolidB;
194  else
195  {
196  DumpInfo();
197  G4Exception("G4BooleanSolid::GetConstituentSolid()",
198  "GeomSolids0002", FatalException, "Invalid solid index.");
199  }
200 
201  return subSolid;
202 }
203 
204 //////////////////////////////////////////////////////////////////////////
205 //
206 // Returns entity type
207 
209 {
210  return G4String("G4BooleanSolid");
211 }
212 
213 //////////////////////////////////////////////////////////////////////////
214 //
215 // Stream object contents to an output stream
216 
217 std::ostream& G4BooleanSolid::StreamInfo(std::ostream& os) const
218 {
219  os << "-----------------------------------------------------------\n"
220  << " *** Dump for Boolean solid - " << GetName() << " ***\n"
221  << " ===================================================\n"
222  << " Solid type: " << GetEntityType() << "\n"
223  << " Parameters of constituent solids: \n"
224  << "===========================================================\n";
225  fPtrSolidA->StreamInfo(os);
226  fPtrSolidB->StreamInfo(os);
227  os << "===========================================================\n";
228 
229  return os;
230 }
231 
232 //////////////////////////////////////////////////////////////////////////
233 //
234 // Returns a point (G4ThreeVector) randomly and uniformly selected
235 // on the solid surface
236 //
237 
239 {
240  G4double rand;
242 
243  do
244  {
245  rand = G4UniformRand();
246 
247  if (rand < GetAreaRatio()) { p = fPtrSolidA->GetPointOnSurface(); }
248  else { p = fPtrSolidB->GetPointOnSurface(); }
249  } while (Inside(p) != kSurface);
250 
251  return p;
252 }
253 
254 //////////////////////////////////////////////////////////////////////////
255 //
256 // Returns polyhedron for visualization
257 
259 {
260  if (!fpPolyhedron ||
262  fpPolyhedron->GetNumberOfRotationSteps())
263  {
264  delete fpPolyhedron;
265  fpPolyhedron = CreatePolyhedron();
266  }
267  return fpPolyhedron;
268 }
269 
270 //////////////////////////////////////////////////////////////////////////
271 //
272 // Stacks polyhedra for processing. Returns top polyhedron.
273 
276  const G4VSolid* solid) const
277 {
279  const G4String& type = solid->GetEntityType();
280  if (type == "G4UnionSolid")
281  { operation = HepPolyhedronProcessor::UNION; }
282  else if (type == "G4IntersectionSolid")
283  { operation = HepPolyhedronProcessor::INTERSECTION; }
284  else if (type == "G4SubtractionSolid")
285  { operation = HepPolyhedronProcessor::SUBTRACTION; }
286  else
287  {
288  std::ostringstream message;
289  message << "Solid - " << solid->GetName()
290  << " - Unrecognised composite solid" << G4endl
291  << " Returning NULL !";
292  G4Exception("StackPolyhedron()", "GeomSolids1001", JustWarning, message);
293  return 0;
294  }
295 
296  G4Polyhedron* top = 0;
297  const G4VSolid* solidA = solid->GetConstituentSolid(0);
298  const G4VSolid* solidB = solid->GetConstituentSolid(1);
299 
300  if (solidA->GetConstituentSolid(0))
301  {
302  top = StackPolyhedron(processor, solidA);
303  }
304  else
305  {
306  top = solidA->GetPolyhedron();
307  }
308  G4Polyhedron* operand = solidB->GetPolyhedron();
309  processor.push_back (operation, *operand);
310 
311  return top;
312 }
virtual G4Polyhedron * GetPolyhedron() const
Definition: G4VSolid.cc:644
G4String GetName() const
G4VSolid * fPtrSolidB
virtual G4Polyhedron * GetPolyhedron() const
G4BooleanSolid(const G4String &pName, G4VSolid *pSolidA, G4VSolid *pSolidB)
virtual G4GeometryType GetEntityType() const
const char * p
Definition: xmltok.h:285
virtual G4GeometryType GetEntityType() const =0
int G4int
Definition: G4Types.hh:78
void DumpInfo() const
void push_back(Operation, const HepPolyhedron &)
virtual std::ostream & StreamInfo(std::ostream &os) const =0
#define G4UniformRand()
Definition: Randomize.hh:87
virtual EInside Inside(const G4ThreeVector &p) const =0
std::ostream & StreamInfo(std::ostream &os) const
virtual G4Polyhedron * CreatePolyhedron() const
Definition: G4VSolid.cc:639
virtual ~G4BooleanSolid()
virtual const G4VSolid * GetConstituentSolid(G4int no) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4double GetAreaRatio() const
#define processor
Definition: xmlparse.cc:600
static G4int GetNumberOfRotationSteps()
virtual G4ThreeVector GetPointOnSurface() const
Definition: G4VSolid.cc:152
virtual const G4VSolid * GetConstituentSolid(G4int no) const
Definition: G4VSolid.cc:167
G4VSolid * fPtrSolidA
G4ThreeVector GetPointOnSurface() const
#define G4endl
Definition: G4ios.hh:61
G4VSolid & operator=(const G4VSolid &rhs)
Definition: G4VSolid.cc:110
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
G4BooleanSolid & operator=(const G4BooleanSolid &rhs)
double G4double
Definition: G4Types.hh:76
G4Polyhedron * StackPolyhedron(HepPolyhedronProcessor &, const G4VSolid *) const