source: trunk/examples/advanced/radiation_monitor/detector/src/RadmonVDetectorLayerVolumeItemOperation.cc @ 1321

Last change on this file since 1321 was 807, checked in by garnier, 16 years ago

update

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// File name:     RadmonVDetectorLayerVolumeItemOperation.cc
28// Creation date: Sep 2005
29// Main author:   Riccardo Capra <capra@ge.infn.it>
30//
31// Id:            $Id: RadmonVDetectorLayerVolumeItemOperation.cc,v 1.3 2006/06/29 16:14:15 gunter Exp $
32// Tag:           $Name:  $
33//
34
35// Include files
36#include "RadmonVDetectorLayerVolumeItemOperation.hh"
37#include "RadmonDetectorLayerVolumeItem.hh"
38#include "G4VSolid.hh"
39
40void                                            RadmonVDetectorLayerVolumeItemOperation :: Initialize(G4VSolid * solid, const G4RotationMatrix & rotation, const G4ThreeVector & position, G4bool ownSolid)
41{
42 Validate();
43
44 leftRotation=rotation;
45 invLeftRotation=rotation.inverse();
46 leftPosition=position;
47 leftSolid=solid;
48
49 if (ownSolid)
50  ownedSolids.push(solid);
51}
52
53
54
55void                                            RadmonVDetectorLayerVolumeItemOperation :: Initialize(G4VSolid * solid, const G4ThreeVector & position, G4bool ownSolid)
56{
57 Validate();
58
59 leftRotation=G4RotationMatrix::IDENTITY;
60 invLeftRotation=G4RotationMatrix::IDENTITY;
61 leftPosition=position;
62 leftSolid=solid;
63
64 if (ownSolid)
65  ownedSolids.push(solid);
66}
67
68
69
70void                                            RadmonVDetectorLayerVolumeItemOperation :: Initialize(G4VSolid * solid, G4bool ownSolid)
71{
72 Validate();
73
74 leftRotation=G4RotationMatrix::IDENTITY;
75 invLeftRotation=G4RotationMatrix::IDENTITY;
76 leftPosition=G4ThreeVector(0, 0, 0);
77 leftSolid=solid;
78
79 if (ownSolid)
80  ownedSolids.push(solid);
81}
82
83
84
85void                                            RadmonVDetectorLayerVolumeItemOperation :: Initialize(const RadmonDetectorLayerVolumeItem * item)
86{
87 Validate();
88
89 leftSolid=item->GetSolid();
90
91 Absolute(item, leftRotation, leftPosition);
92 invLeftRotation=leftRotation.inverse();
93}
94
95
96
97
98
99G4VSolid *                                      RadmonVDetectorLayerVolumeItemOperation :: ApplyTo(G4VSolid * solid, const G4RotationMatrix & rotation, const G4ThreeVector & position, G4bool ownSolid, G4bool ownResult)
100{
101 if (ownSolid)
102  ownedSolids.push(solid);
103
104 G4ThreeVector relativePosition;
105 ownedMatrices.push(G4RotationMatrix::IDENTITY);
106 Merge(rotation, position, ownedMatrices.top(), relativePosition);
107
108 G4VSolid * result(Operate(leftSolid, solid, &ownedMatrices.top(), relativePosition));
109 
110 if (ownResult)
111  ownedSolids.push(result);
112
113 return result;
114}
115
116
117
118void                                            RadmonVDetectorLayerVolumeItemOperation :: ApplyTo(RadmonDetectorLayerVolumeItem * item, G4bool ownResult)
119{
120 G4ThreeVector rightPosition;
121 G4RotationMatrix rightRotation;
122 Absolute(item, rightRotation, rightPosition);
123
124 G4ThreeVector relativePosition;
125 ownedMatrices.push(G4RotationMatrix::IDENTITY);
126 Merge(rightRotation, rightPosition, ownedMatrices.top(), relativePosition);
127 
128 G4VSolid * result(Operate(leftSolid, item->GetSolid(), &ownedMatrices.top(), relativePosition));
129 
130 if (ownResult)
131  ownedSolids.push(result);
132
133 item->SetSolid(result);
134 item->SetPosition(leftPosition);
135 item->SetRotation(leftRotation);
136}
137
138
139
140
141
142                                                RadmonVDetectorLayerVolumeItemOperation :: RadmonVDetectorLayerVolumeItemOperation(G4VSolid * solid, const G4RotationMatrix & rotation, const G4ThreeVector & position, G4bool ownSolid)
143:
144 leftRotation(rotation),
145 invLeftRotation(rotation.inverse()),
146 leftPosition(position),
147 leftSolid(solid)
148{
149 if (ownSolid)
150  ownedSolids.push(solid);
151}
152
153
154
155                                                RadmonVDetectorLayerVolumeItemOperation :: RadmonVDetectorLayerVolumeItemOperation(G4VSolid * solid, const G4ThreeVector & position, G4bool ownSolid)
156:
157 leftRotation(G4RotationMatrix::IDENTITY),
158 invLeftRotation(G4RotationMatrix::IDENTITY),
159 leftPosition(position),
160 leftSolid(solid)
161{
162 if (ownSolid)
163  ownedSolids.push(solid);
164}
165
166
167                                               
168                                                RadmonVDetectorLayerVolumeItemOperation :: RadmonVDetectorLayerVolumeItemOperation(G4VSolid * solid, G4bool ownSolid)
169:
170 leftRotation(G4RotationMatrix::IDENTITY),
171 invLeftRotation(G4RotationMatrix::IDENTITY),
172 leftPosition(0, 0, 0),
173 leftSolid(solid)
174{
175 if (ownSolid)
176  ownedSolids.push(solid);
177}
178
179
180
181                                                RadmonVDetectorLayerVolumeItemOperation :: RadmonVDetectorLayerVolumeItemOperation(const RadmonDetectorLayerVolumeItem * item)
182:
183 leftSolid(item->GetSolid())
184{
185 Absolute(item, leftRotation, leftPosition);
186 invLeftRotation=leftRotation.inverse();
187}
188
189
190
191                                                RadmonVDetectorLayerVolumeItemOperation :: ~RadmonVDetectorLayerVolumeItemOperation()
192{
193 while (! ownedSolids.empty())
194 {
195  delete ownedSolids.top();
196  ownedSolids.pop();
197 }
198}
199
200
201
202
203
204inline void                                     RadmonVDetectorLayerVolumeItemOperation :: Validate()
205{
206 if (leftSolid!=0 || (!ownedSolids.empty()))
207  G4Exception("RadmonVDetectorLayerVolumeItemOperation::Validate: Initialization happened twice.");
208}
209
210
211
212
213
214void                                            RadmonVDetectorLayerVolumeItemOperation :: Merge(const G4RotationMatrix & rightRotation, const G4ThreeVector & rightPosition, G4RotationMatrix & relativeRotation, G4ThreeVector & relativePosition) const
215{
216 // X_a = O_r + R_r * X_r                               X_r --> X_a
217 // X_a = O_l + R_l * X_l                               X_l --> X_a
218 // X_l = R_l^-1 * (O_r - O_l) + R_l^-1 * R_r * X_r     X_r --> X_l
219 
220 relativeRotation=rightRotation;
221 relativeRotation.transform(invLeftRotation);
222 
223 relativePosition=rightPosition;
224 relativePosition-=leftPosition;
225 relativePosition.transform(invLeftRotation);
226}
227
228
229
230void                                            RadmonVDetectorLayerVolumeItemOperation :: Absolute(const RadmonDetectorLayerVolumeItem * item, G4RotationMatrix & rotation, G4ThreeVector & position) const
231{
232 rotation=item->GetRotation();
233 position=item->GetPosition();
234
235 for(;;)
236 {
237  item=item->GetMotherVolumeItem();
238  if (!item)
239   return;
240   
241  rotation.transform(item->GetRotation());
242  position.transform(item->GetRotation());
243 }
244}
245
Note: See TracBrowser for help on using the repository browser.