Geant4  10.03
G4ScaleTransform.icc
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 //
30 // G4ScaleTransform Inline implementation.
31 // Based on implementation provided in Root
32 //
33 // --------------------------------------------------------------------
34 
35 inline G4ScaleTransform::G4ScaleTransform()
36  : fScale(1.,1.,1.), fIScale(1.,1.,1.), flFactor(1.), fgFactor(1.)
37 {
38 }
39 
40 inline G4ScaleTransform::G4ScaleTransform(G4double sx, G4double sy, G4double sz)
41  : fScale(sx,sy,sz), fIScale(), flFactor(1.), fgFactor(1.)
42 {
43  Init();
44 }
45 
46 inline G4ScaleTransform::G4ScaleTransform(const G4ThreeVector& scale)
47  : fScale(scale), fIScale(), flFactor(1.), fgFactor(1.)
48 {
49  Init();
50 }
51 
52 inline G4ScaleTransform::G4ScaleTransform(const G4Scale3D& scale)
53  : fScale(scale.xx(), scale.yy(), scale.zz()), fIScale(),
54  flFactor(1.), fgFactor(1.)
55 {
56  Init();
57 }
58 
59 inline G4ScaleTransform::G4ScaleTransform(const G4ScaleTransform& right)
60  : fScale(right.fScale), fIScale(right.fIScale),
61  flFactor(right.flFactor), fgFactor(right.fgFactor)
62 {
63 }
64 
65 inline G4ScaleTransform&
66 G4ScaleTransform::operator=(const G4ScaleTransform& right)
67 {
68  fScale = right.fScale;
69  fIScale = right.fIScale;
70  flFactor = right.flFactor;
71  fgFactor = right.fgFactor;
72  return *this;
73 }
74 
75 inline void G4ScaleTransform::Init()
76 {
77  if (!((fScale.x()>0) && (fScale.y()>0) && (fScale.z()>0)))
78  {
79  G4Exception("G4ScaleTransform::Init()", "GeomMgt0001",
80  FatalException, "Scale transformation must be positive!");
81  }
82  fIScale.set(1./fScale.x(), 1./fScale.y(), 1./fScale.z());
83  flFactor = std::min(std::min(fIScale.x(), fIScale.y()), fIScale.z());
84  fgFactor = std::min(std::min(fScale.x(), fScale.y()), fScale.z());
85 }
86 
87 inline const G4ThreeVector& G4ScaleTransform::GetScale() const
88 {
89  return fScale;
90 }
91 
92 inline const G4ThreeVector& G4ScaleTransform::GetInvScale() const
93 {
94  return fIScale;
95 }
96 
97 inline void G4ScaleTransform::SetScale(const G4ThreeVector& scale)
98 {
99  fScale = scale;
100  Init();
101 }
102 
103 inline void G4ScaleTransform::SetScale(const G4Scale3D& scale)
104 {
105  fScale.set(scale.xx(), scale.yy(), scale.zz());
106  Init();
107 }
108 
109 inline void G4ScaleTransform::SetScale(G4double sx, G4double sy, G4double sz)
110 {
111  fScale.set(sx,sy,sz);
112  Init();
113 }
114 
115 inline void G4ScaleTransform::Transform(const G4ThreeVector& global,
116  G4ThreeVector& local) const
117 {
118  local.set(global.x()*fIScale.x(),
119  global.y()*fIScale.y(),
120  global.z()*fIScale.z());
121 }
122 
123 inline G4ThreeVector
124 G4ScaleTransform::Transform(const G4ThreeVector& global) const
125 {
126  G4ThreeVector local(global.x()*fIScale.x(),
127  global.y()*fIScale.y(),
128  global.z()*fIScale.z());
129  return local;
130 }
131 
132 inline void
133 G4ScaleTransform::InverseTransform(const G4ThreeVector& local,
134  G4ThreeVector& global) const
135 {
136  global.set(local.x()*fScale.x(),
137  local.y()*fScale.y(),
138  local.z()*fScale.z());
139 }
140 
141 inline G4ThreeVector
142 G4ScaleTransform::InverseTransform(const G4ThreeVector& local) const
143 {
144  G4ThreeVector global(local.x()*fScale.x(),
145  local.y()*fScale.y(),
146  local.z()*fScale.z());
147  return global;
148 }
149 
150 inline void
151 G4ScaleTransform::TransformNormal(const G4ThreeVector& global,
152  G4ThreeVector& local) const
153 {
154  local.set(global.x()*fIScale.y()*fIScale.z(),
155  global.y()*fIScale.z()*fIScale.x(),
156  global.z()*fIScale.x()*fIScale.y());
157 }
158 
159 inline G4ThreeVector
160 G4ScaleTransform::TransformNormal(const G4ThreeVector& global) const
161 {
162  G4ThreeVector local(global.x()*fIScale.y()*fIScale.z(),
163  global.y()*fIScale.z()*fIScale.x(),
164  global.z()*fIScale.x()*fIScale.y());
165  return local;
166 }
167 
168 inline void
169 G4ScaleTransform::InverseTransformNormal(const G4ThreeVector& local,
170  G4ThreeVector& global) const
171 {
172  global.set(local.x()*fScale.y()*fScale.z(),
173  local.y()*fScale.z()*fScale.x(),
174  local.z()*fScale.x()*fScale.y());
175 }
176 
177 inline G4ThreeVector
178 G4ScaleTransform::InverseTransformNormal(const G4ThreeVector& local) const
179 {
180  G4ThreeVector global(local.x()*fScale.y()*fScale.z(),
181  local.y()*fScale.z()*fScale.x(),
182  local.z()*fScale.x()*fScale.y());
183  return global;
184 }
185 
186 inline G4double
187 G4ScaleTransform::TransformDistance(G4double dist,
188  const G4ThreeVector& dir) const
189 {
190  G4ThreeVector v(dir.x()*fIScale.x(),
191  dir.y()*fIScale.y(),
192  dir.z()*fIScale.z());
193  G4double scale = std::sqrt(v.dot(v));
194  return ( scale*dist );
195 }
196 
197 inline G4double G4ScaleTransform::TransformDistance(G4double safety) const
198 {
199  return ( safety*flFactor );
200 }
201 
202 inline G4double
203 G4ScaleTransform::InverseTransformDistance(G4double dist,
204  const G4ThreeVector& dir) const
205 {
206  G4ThreeVector v(dir.x()*fScale.x(),
207  dir.y()*fScale.y(),
208  dir.z()*fScale.z());
209  G4double scale = std::sqrt(v.dot(v));
210  return ( scale*dist );
211 }
212 
213 inline G4double
214 G4ScaleTransform::InverseTransformDistance(G4double safety) const
215 {
216  return ( safety*fgFactor );
217 }
218 
219 inline
220 std::ostream& operator << (std::ostream& os, const G4ScaleTransform& transf)
221 {
222  std::streamsize oldPrec = os.precision(6);
223 
224  os << " Scale Transformation: " << G4endl
225  << " x,y,z: "
226  << transf.GetScale().x() << " "
227  << transf.GetScale().y() << " "
228  << transf.GetScale().z() << G4endl
229  << " Inverse x,y,z: "
230  << transf.GetInvScale().x() << " "
231  << transf.GetInvScale().y() << " "
232  << transf.GetInvScale().z() << G4endl;
233 
234  os.precision(oldPrec);
235 
236  return os;
237 }