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 // ********************************************************************
30 // G4ScaleTransform Inline implementation.
31 // Based on implementation provided in Root
33 // --------------------------------------------------------------------
35 inline G4ScaleTransform::G4ScaleTransform()
36 : fScale(1.,1.,1.), fIScale(1.,1.,1.), flFactor(1.), fgFactor(1.)
40 inline G4ScaleTransform::G4ScaleTransform(G4double sx, G4double sy, G4double sz)
41 : fScale(sx,sy,sz), fIScale(), flFactor(1.), fgFactor(1.)
46 inline G4ScaleTransform::G4ScaleTransform(const G4ThreeVector& scale)
47 : fScale(scale), fIScale(), flFactor(1.), fgFactor(1.)
52 inline G4ScaleTransform::G4ScaleTransform(const G4Scale3D& scale)
53 : fScale(scale.xx(), scale.yy(), scale.zz()), fIScale(),
54 flFactor(1.), fgFactor(1.)
59 inline G4ScaleTransform::G4ScaleTransform(const G4ScaleTransform& right)
60 : fScale(right.fScale), fIScale(right.fIScale),
61 flFactor(right.flFactor), fgFactor(right.fgFactor)
65 inline G4ScaleTransform&
66 G4ScaleTransform::operator=(const G4ScaleTransform& right)
68 fScale = right.fScale;
69 fIScale = right.fIScale;
70 flFactor = right.flFactor;
71 fgFactor = right.fgFactor;
75 inline void G4ScaleTransform::Init()
77 if (!((fScale.x()>0) && (fScale.y()>0) && (fScale.z()>0)))
79 G4Exception("G4ScaleTransform::Init()", "GeomMgt0001",
80 FatalException, "Scale transformation must be positive!");
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());
87 inline const G4ThreeVector& G4ScaleTransform::GetScale() const
92 inline const G4ThreeVector& G4ScaleTransform::GetInvScale() const
97 inline void G4ScaleTransform::SetScale(const G4ThreeVector& scale)
103 inline void G4ScaleTransform::SetScale(const G4Scale3D& scale)
105 fScale.set(scale.xx(), scale.yy(), scale.zz());
109 inline void G4ScaleTransform::SetScale(G4double sx, G4double sy, G4double sz)
111 fScale.set(sx,sy,sz);
115 inline void G4ScaleTransform::Transform(const G4ThreeVector& global,
116 G4ThreeVector& local) const
118 local.set(global.x()*fIScale.x(),
119 global.y()*fIScale.y(),
120 global.z()*fIScale.z());
124 G4ScaleTransform::Transform(const G4ThreeVector& global) const
126 G4ThreeVector local(global.x()*fIScale.x(),
127 global.y()*fIScale.y(),
128 global.z()*fIScale.z());
133 G4ScaleTransform::InverseTransform(const G4ThreeVector& local,
134 G4ThreeVector& global) const
136 global.set(local.x()*fScale.x(),
137 local.y()*fScale.y(),
138 local.z()*fScale.z());
142 G4ScaleTransform::InverseTransform(const G4ThreeVector& local) const
144 G4ThreeVector global(local.x()*fScale.x(),
145 local.y()*fScale.y(),
146 local.z()*fScale.z());
151 G4ScaleTransform::TransformNormal(const G4ThreeVector& global,
152 G4ThreeVector& local) const
154 local.set(global.x()*fIScale.y()*fIScale.z(),
155 global.y()*fIScale.z()*fIScale.x(),
156 global.z()*fIScale.x()*fIScale.y());
160 G4ScaleTransform::TransformNormal(const G4ThreeVector& global) const
162 G4ThreeVector local(global.x()*fIScale.y()*fIScale.z(),
163 global.y()*fIScale.z()*fIScale.x(),
164 global.z()*fIScale.x()*fIScale.y());
169 G4ScaleTransform::InverseTransformNormal(const G4ThreeVector& local,
170 G4ThreeVector& global) const
172 global.set(local.x()*fScale.y()*fScale.z(),
173 local.y()*fScale.z()*fScale.x(),
174 local.z()*fScale.x()*fScale.y());
178 G4ScaleTransform::InverseTransformNormal(const G4ThreeVector& local) const
180 G4ThreeVector global(local.x()*fScale.y()*fScale.z(),
181 local.y()*fScale.z()*fScale.x(),
182 local.z()*fScale.x()*fScale.y());
187 G4ScaleTransform::TransformDistance(G4double dist,
188 const G4ThreeVector& dir) const
190 G4ThreeVector v(dir.x()*fIScale.x(),
192 dir.z()*fIScale.z());
193 G4double scale = std::sqrt(v.dot(v));
194 return ( scale*dist );
197 inline G4double G4ScaleTransform::TransformDistance(G4double safety) const
199 return ( safety*flFactor );
203 G4ScaleTransform::InverseTransformDistance(G4double dist,
204 const G4ThreeVector& dir) const
206 G4ThreeVector v(dir.x()*fScale.x(),
209 G4double scale = std::sqrt(v.dot(v));
210 return ( scale*dist );
214 G4ScaleTransform::InverseTransformDistance(G4double safety) const
216 return ( safety*fgFactor );
220 std::ostream& operator << (std::ostream& os, const G4ScaleTransform& transf)
222 std::streamsize oldPrec = os.precision(6);
224 os << " Scale Transformation: " << G4endl
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;
234 os.precision(oldPrec);