source: trunk/source/geometry/solids/Boolean/src/G4BooleanSolid.cc @ 1228

Last change on this file since 1228 was 1228, checked in by garnier, 14 years ago

update geant4.9.3 tag

File size: 7.6 KB
Line 
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,v 1.21 2006/10/19 15:34:49 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-03 $
29//
30// Implementation for the abstract base class for solids created by boolean
31// operations between other solids
32//
33// History:
34//
35// 10.09.98 V.Grichine, created
36//
37// --------------------------------------------------------------------
38
39#include "G4BooleanSolid.hh"
40#include "G4VSolid.hh"
41#include "G4Polyhedron.hh"
42#include "Randomize.hh"
43
44//////////////////////////////////////////////////////////////////
45//
46// Constructor
47
48G4BooleanSolid::G4BooleanSolid( const G4String& pName,
49                                G4VSolid* pSolidA ,
50                                G4VSolid* pSolidB   ) :
51  G4VSolid(pName), 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
63G4BooleanSolid::G4BooleanSolid( const G4String& pName,
64                                      G4VSolid* pSolidA ,
65                                      G4VSolid* pSolidB ,
66                                      G4RotationMatrix* rotMatrix,
67                                const G4ThreeVector& transVector    ) :
68  G4VSolid(pName), 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
80G4BooleanSolid::G4BooleanSolid( const G4String& pName,
81                                      G4VSolid* pSolidA ,
82                                      G4VSolid* pSolidB ,
83                                const G4Transform3D& transform    ) :
84  G4VSolid(pName), 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
97G4BooleanSolid::G4BooleanSolid( __void__& a )
98  : G4VSolid(a), fPtrSolidA(0), fPtrSolidB(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
109G4BooleanSolid::~G4BooleanSolid() 
110{
111  if(createdDisplacedSolid)
112  {
113    ((G4DisplacedSolid*)fPtrSolidB)->CleanTransformations();
114  }
115  delete fpPolyhedron;
116}
117
118///////////////////////////////////////////////////////////////
119//
120// If Solid is made up from a Boolean operation of two solids,
121//   return the corresponding solid (for no=0 and 1)
122// If the solid is not a "Boolean", return 0
123
124const G4VSolid* G4BooleanSolid::GetConstituentSolid(G4int no) const
125{
126  const G4VSolid*  subSolid=0;
127  if( no == 0 ) 
128    subSolid = fPtrSolidA;
129  else if( no == 1 ) 
130    subSolid = fPtrSolidB;
131  else
132  {
133    DumpInfo();
134    G4Exception("G4BooleanSolid::GetConstituentSolid()",
135                "WrongArgumentValue", FatalException,
136                "Invalid solid index.");
137  }
138
139  return subSolid;
140}
141
142///////////////////////////////////////////////////////////////
143//
144// If Solid is made up from a Boolean operation of two solids,
145//   return the corresponding solid (for no=0 and 1)
146// If the solid is not a "Boolean", return 0
147
148G4VSolid* G4BooleanSolid::GetConstituentSolid(G4int no)
149{
150  G4VSolid*  subSolid=0;
151  if( no == 0 ) 
152    subSolid = fPtrSolidA;
153  else if( no == 1 ) 
154    subSolid = fPtrSolidB;
155  else
156  {
157    DumpInfo();
158    G4Exception("G4BooleanSolid::GetConstituentSolid()",
159                "WrongArgumentValue", FatalException,
160                "Invalid solid index.");
161  }
162
163  return subSolid;
164}
165
166//////////////////////////////////////////////////////////////////////////
167//
168// Returns entity type
169
170G4GeometryType G4BooleanSolid::GetEntityType() const 
171{
172  return G4String("G4BooleanSolid");
173}
174
175//////////////////////////////////////////////////////////////////////////
176//
177// Stream object contents to an output stream
178
179std::ostream& G4BooleanSolid::StreamInfo(std::ostream& os) const
180{
181  os << "-----------------------------------------------------------\n"
182     << "    *** Dump for Boolean solid - " << GetName() << " ***\n"
183     << "    ===================================================\n"
184     << " Solid type: " << GetEntityType() << "\n"
185     << " Parameters of constituent solids: \n"
186     << "===========================================================\n";
187  fPtrSolidA->StreamInfo(os);
188  fPtrSolidB->StreamInfo(os);
189  os << "===========================================================\n";
190
191  return os;
192}
193
194//////////////////////////////////////////////////////////////////////////
195//
196// Returns a point (G4ThreeVector) randomly and uniformly selected
197// on the solid surface
198//
199
200G4ThreeVector G4BooleanSolid::GetPointOnSurface() const
201{
202  G4bool condition = true;
203  G4double rand;
204  G4ThreeVector p;
205
206  while(condition)
207  {
208    rand = G4UniformRand();
209
210    if(rand > 0.5) { p = fPtrSolidA->GetPointOnSurface(); }
211    else           { p = fPtrSolidB->GetPointOnSurface(); }
212
213    if(Inside(p) == kSurface)  { break; }
214  }
215  return p;
216}
217
218//////////////////////////////////////////////////////////////////////////
219//
220// Returns polyhedron for visualization
221
222G4Polyhedron* G4BooleanSolid::GetPolyhedron () const
223{
224  if (!fpPolyhedron ||
225      fpPolyhedron->GetNumberOfRotationStepsAtTimeOfCreation() !=
226      fpPolyhedron->GetNumberOfRotationSteps())
227    {
228      delete fpPolyhedron;
229      fpPolyhedron = CreatePolyhedron();
230    }
231  return fpPolyhedron;
232}
Note: See TracBrowser for help on using the repository browser.