VGM Version 5.3
Loading...
Searching...
No Matches
BooleanSolid.cxx
Go to the documentation of this file.
1// $Id$
2
3// -----------------------------------------------------------------------
4// The Geant4GM package of the Virtual Geometry Model
5// Copyright (C) 2007, Ivana Hrivnacova
6// All rights reserved.
7//
8// For the licensing terms see vgm/LICENSE.
9// Contact: ivana@ipno.in2p3.fr
10// -----------------------------------------------------------------------
11
12//
13// Class BooleanSolid
14// ---------------------
15// VGM implementation for Geant4 Boolean solid
16//
17// Author: Ivana Hrivnacova; IPN Orsay
18
19#include "ClhepVGM/transform.h"
20
23
24#include "G4BooleanSolid.hh"
25#include "G4DisplacedSolid.hh"
26#include "G4IntersectionSolid.hh"
27#include "G4ReflectedSolid.hh"
28#include "G4SubtractionSolid.hh"
29#include "G4UnionSolid.hh"
30
31//_____________________________________________________________________________
33 VGM::BooleanType boolType, VGM::ISolid* solidA, VGM::ISolid* solidB,
34 CLHEP::HepRotation* rotation, const CLHEP::Hep3Vector& translation)
35 : VGM::ISolid(),
36 VGM::IBooleanSolid(),
37 BaseVGM::VBooleanSolid(),
38 fBooleanSolid(0),
39 fToBeReflected(false)
40{
47
48 // Get solids from the volumes map
49 G4VSolid* g4SolidA = Geant4GM::SolidMap::Instance()->GetSolid(solidA);
50 G4VSolid* g4SolidB = Geant4GM::SolidMap::Instance()->GetSolid(solidB);
51
52 switch (boolType) {
54 fBooleanSolid = new G4IntersectionSolid(
55 name, g4SolidA, g4SolidB, rotation, translation);
56 break;
57
59 fBooleanSolid =
60 new G4SubtractionSolid(name, g4SolidA, g4SolidB, rotation, translation);
61 break;
62
63 case VGM::kUnion:
64 fBooleanSolid =
65 new G4UnionSolid(name, g4SolidA, g4SolidB, rotation, translation);
66 break;
67
69 default:
70 std::cerr << " Geant4GM::BooleanSolid::BooleanSolid:" << std::endl;
71 std::cerr << " Unknown Boolean solid type (solid \"" << name << "\")"
72 << std::endl;
73 std::cerr << "*** Error: Aborting execution ***" << std::endl;
74 exit(1);
75 }
76
77 Geant4GM::SolidMap::Instance()->AddSolid(this, fBooleanSolid);
78}
79
80//_____________________________________________________________________________
82 G4BooleanSolid* booleanSolid, G4ReflectedSolid* reflectedBoolean)
83 : VGM::ISolid(),
84 VGM::IBooleanSolid(),
85 BaseVGM::VBooleanSolid(),
86 fBooleanSolid(booleanSolid),
87 fToBeReflected(false)
88{
90
91 if (reflectedBoolean) {
92 fToBeReflected = true;
93 Geant4GM::SolidMap::Instance()->AddSolid(this, reflectedBoolean);
94 }
95 else
96 Geant4GM::SolidMap::Instance()->AddSolid(this, fBooleanSolid);
97}
98
99//_____________________________________________________________________________
101 : VGM::ISolid(), VGM::IBooleanSolid(), BaseVGM::VBooleanSolid()
102{
104}
105
106//_____________________________________________________________________________
108 : VGM::ISolid(rhs), VGM::IBooleanSolid(rhs), BaseVGM::VBooleanSolid(rhs)
109{
111}
112
113//_____________________________________________________________________________
118
119//
120// private methods
121//
122
123//_____________________________________________________________________________
124const G4DisplacedSolid* Geant4GM::BooleanSolid::DisplacedSolid() const
125{
126 // Returns the G4 displaced solid
127 // ---
128
129 G4VSolid* g4SolidB = fBooleanSolid->GetConstituentSolid(1);
130 return g4SolidB->GetDisplacedSolidPtr();
131}
132
133//
134// public methods
135//
136
137//_____________________________________________________________________________
139{
140 // Returns the Boolean solid name
141 // ---
142
143 return fBooleanSolid->GetName();
144}
145
146//_____________________________________________________________________________
148{
149 // Returns the Boolean solid type name
150 // ---
151
152 if (fBooleanSolid->GetEntityType() == "G4IntersectionSolid")
153 return VGM::kIntersection;
154
155 if (fBooleanSolid->GetEntityType() == "G4SubtractionSolid")
156 return VGM::kSubtraction;
157
158 if (fBooleanSolid->GetEntityType() == "G4UnionSolid") return VGM::kUnion;
159
161}
162
163//_____________________________________________________________________________
165{
166 // Returns the first constituent solid.
167 // ---
168
169 G4VSolid* g4SolidA = GetConstituentSolid(0, fBooleanSolid);
171
172 return solidA;
173}
174
175//_____________________________________________________________________________
177{
178 // Returns the first constituent solid.
179 // ---
180
181 G4VSolid* g4SolidB = GetConstituentSolid(1, fBooleanSolid);
182
184
185 return solidB;
186}
187
188//_____________________________________________________________________________
190{
191 // Returns the first constituent solid.
192 // ---
193
194 const G4DisplacedSolid* g4DisplacedSolid = DisplacedSolid();
195
196 if (g4DisplacedSolid) {
197 return ClhepVGM::Transform(g4DisplacedSolid->GetObjectRotation(),
198 g4DisplacedSolid->GetObjectTranslation());
199 }
200 else
201 return ClhepVGM::Transform(CLHEP::HepRotation(), CLHEP::Hep3Vector());
202}
203
204//_____________________________________________________________________________
206 int index, G4BooleanSolid* booleanSolid)
207{
208 // Returns the constituent solid specified by index,
209 // if the constituent solid is displaced solid, returns
210 // its moved constituent
211 // ---
212
213 G4VSolid* consSolid = booleanSolid->GetConstituentSolid(index);
214 if (index == 0) return consSolid;
215
216 G4DisplacedSolid* displacedSolid = consSolid->GetDisplacedSolidPtr();
217 if (displacedSolid) consSolid = displacedSolid->GetConstituentMovedSolid();
218 // If displaced solid, import only its constituent
219
220 return consSolid;
221}
VGM implementation for Geant4 Boolean solid.
virtual VGM::ISolid * ConstituentSolidA() const
Return the first constituent solid.
virtual std::string Name() const
Return the name of this solid.
virtual VGM::Transform Displacement() const
Return the 3D displacement of the second constituent solid with respect to the first one.
static G4VSolid * GetConstituentSolid(int index, G4BooleanSolid *booleanSolid)
virtual VGM::BooleanType BoolType() const
Return the Boolean type of this solid.
virtual VGM::ISolid * ConstituentSolidB() const
Return the second constituent solid.
VGM implementation for Geant4 displaced solid.
G4VSolid * GetSolid(VGM::ISolid *iSolid) const
Definition SolidMap.cxx:68
static SolidMap * Instance()
Definition SolidMap.cxx:28
void AddSolid(VGM::ISolid *, G4VSolid *)
Definition SolidMap.cxx:59
The VGM interface to solids.
Definition ISolid.h:58
BaseVGM utilities.
Definition utilities.h:23
VGM::Transform Transform(const CLHEP::HepRotation &rotation, const CLHEP::Hep3Vector &translation)
Definition transform.cxx:26
VGM interfaces.
Definition VMedium.h:28
std::vector< double > Transform
Definition Transform.h:40
@ kUnknownBoolean
@ kIntersection
@ kSubtraction