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