2// ********************************************************************
3// * License and Disclaimer *
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. *
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. *
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// ********************************************************************
26// G4ScaleTransform inline implementation.
27// Based on implementation provided in Root
29// G.Cosmo, 18 Feb 2016 - initial version
30// --------------------------------------------------------------------
32inline G4ScaleTransform::G4ScaleTransform()
33 : fScale(1.,1.,1.), fIScale(1.,1.,1.)
37inline G4ScaleTransform::G4ScaleTransform(G4double sx, G4double sy, G4double sz)
38 : fScale(sx,sy,sz), fIScale()
43inline G4ScaleTransform::G4ScaleTransform(const G4ThreeVector& scale)
44 : fScale(scale), fIScale()
49inline G4ScaleTransform::G4ScaleTransform(const G4Scale3D& scale)
50 : fScale(scale.xx(), scale.yy(), scale.zz()), fIScale()
55inline G4ScaleTransform::G4ScaleTransform(const G4ScaleTransform& right)
56 : fScale(right.fScale), fIScale(right.fIScale),
57 flFactor(right.flFactor), fgFactor(right.fgFactor)
61inline G4ScaleTransform&
62G4ScaleTransform::operator=(const G4ScaleTransform& right)
64 fScale = right.fScale;
65 fIScale = right.fIScale;
66 flFactor = right.flFactor;
67 fgFactor = right.fgFactor;
71inline void G4ScaleTransform::Init()
73 if (!((fScale.x()>0) && (fScale.y()>0) && (fScale.z()>0)))
75 G4Exception("G4ScaleTransform::Init()", "GeomMgt0001",
76 FatalException, "Scale transformation must be positive!");
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());
83inline const G4ThreeVector& G4ScaleTransform::GetScale() const
88inline const G4ThreeVector& G4ScaleTransform::GetInvScale() const
93inline void G4ScaleTransform::SetScale(const G4ThreeVector& scale)
99inline void G4ScaleTransform::SetScale(const G4Scale3D& scale)
101 fScale.set(scale.xx(), scale.yy(), scale.zz());
105inline void G4ScaleTransform::SetScale(G4double sx, G4double sy, G4double sz)
107 fScale.set(sx,sy,sz);
111inline void G4ScaleTransform::Transform(const G4ThreeVector& global,
112 G4ThreeVector& local) const
114 local.set(global.x()*fIScale.x(),
115 global.y()*fIScale.y(),
116 global.z()*fIScale.z());
120G4ScaleTransform::Transform(const G4ThreeVector& global) const
122 G4ThreeVector local(global.x()*fIScale.x(),
123 global.y()*fIScale.y(),
124 global.z()*fIScale.z());
129G4ScaleTransform::InverseTransform(const G4ThreeVector& local,
130 G4ThreeVector& global) const
132 global.set(local.x()*fScale.x(),
133 local.y()*fScale.y(),
134 local.z()*fScale.z());
138G4ScaleTransform::InverseTransform(const G4ThreeVector& local) const
140 G4ThreeVector global(local.x()*fScale.x(),
141 local.y()*fScale.y(),
142 local.z()*fScale.z());
147G4ScaleTransform::TransformNormal(const G4ThreeVector& global,
148 G4ThreeVector& local) const
150 local.set(global.x()*fIScale.y()*fIScale.z(),
151 global.y()*fIScale.z()*fIScale.x(),
152 global.z()*fIScale.x()*fIScale.y());
156G4ScaleTransform::TransformNormal(const G4ThreeVector& global) const
158 G4ThreeVector local(global.x()*fIScale.y()*fIScale.z(),
159 global.y()*fIScale.z()*fIScale.x(),
160 global.z()*fIScale.x()*fIScale.y());
165G4ScaleTransform::InverseTransformNormal(const G4ThreeVector& local,
166 G4ThreeVector& global) const
168 global.set(local.x()*fScale.y()*fScale.z(),
169 local.y()*fScale.z()*fScale.x(),
170 local.z()*fScale.x()*fScale.y());
174G4ScaleTransform::InverseTransformNormal(const G4ThreeVector& local) const
176 G4ThreeVector global(local.x()*fScale.y()*fScale.z(),
177 local.y()*fScale.z()*fScale.x(),
178 local.z()*fScale.x()*fScale.y());
183G4ScaleTransform::TransformDistance(G4double dist,
184 const G4ThreeVector& dir) const
186 G4ThreeVector v(dir.x()*fIScale.x(),
188 dir.z()*fIScale.z());
189 G4double scale = std::sqrt(v.dot(v));
190 return ( scale*dist );
193inline G4double G4ScaleTransform::TransformDistance(G4double safety) const
195 return ( safety*flFactor );
199G4ScaleTransform::InverseTransformDistance(G4double dist,
200 const G4ThreeVector& dir) const
202 G4ThreeVector v(dir.x()*fScale.x(),
205 G4double scale = std::sqrt(v.dot(v));
206 return ( scale*dist );
210G4ScaleTransform::InverseTransformDistance(G4double safety) const
212 return ( safety*fgFactor );
216std::ostream& operator << (std::ostream& os, const G4ScaleTransform& transf)
218 std::streamsize oldPrec = os.precision(6);
220 os << " Scale Transformation: " << G4endl
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;
230 os.precision(oldPrec);