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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 
 32 inline G4ScaleTransform::G4ScaleTransform()
 33   : fScale(1.,1.,1.), fIScale(1.,1.,1.)
 34 {
 35 }
 36 
 37 inline G4ScaleTransform::G4ScaleTransform(G4double sx, G4double sy, G4double sz)
 38   : fScale(sx,sy,sz), fIScale()
 39 {
 40   Init();
 41 }  
 42 
 43 inline G4ScaleTransform::G4ScaleTransform(const G4ThreeVector& scale)
 44   : fScale(scale), fIScale()
 45 {
 46   Init();
 47 }
 48         
 49 inline G4ScaleTransform::G4ScaleTransform(const G4Scale3D& scale)
 50   : fScale(scale.xx(), scale.yy(), scale.zz()), fIScale()
 51 {
 52   Init();
 53 }
 54 
 55 inline G4ScaleTransform::G4ScaleTransform(const G4ScaleTransform& right)
 56   : fScale(right.fScale), fIScale(right.fIScale),
 57     flFactor(right.flFactor), fgFactor(right.fgFactor)
 58 {
 59 }
 60   
 61 inline G4ScaleTransform&
 62 G4ScaleTransform::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           
 71 inline 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 
 83 inline const G4ThreeVector& G4ScaleTransform::GetScale() const
 84 {
 85   return fScale;
 86 }
 87 
 88 inline const G4ThreeVector& G4ScaleTransform::GetInvScale() const
 89 {
 90   return fIScale;
 91 }
 92 
 93 inline void G4ScaleTransform::SetScale(const G4ThreeVector& scale)
 94 {
 95   fScale = scale;
 96   Init();
 97 }
 98 
 99 inline void G4ScaleTransform::SetScale(const G4Scale3D& scale)
100 {
101   fScale.set(scale.xx(), scale.yy(), scale.zz());
102   Init();
103 }
104  
105 inline void G4ScaleTransform::SetScale(G4double sx, G4double sy, G4double sz)
106 {
107   fScale.set(sx,sy,sz);
108   Init();
109 }
110 
111 inline 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   
119 inline G4ThreeVector
120 G4ScaleTransform::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     
128 inline void
129 G4ScaleTransform::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 
137 inline G4ThreeVector
138 G4ScaleTransform::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 
146 inline void
147 G4ScaleTransform::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   
155 inline G4ThreeVector
156 G4ScaleTransform::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     
164 inline void
165 G4ScaleTransform::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 
173 inline G4ThreeVector
174 G4ScaleTransform::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 
182 inline G4double
183 G4ScaleTransform::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 
193 inline G4double G4ScaleTransform::TransformDistance(G4double safety) const
194 {
195   return ( safety*flFactor );
196 }
197     
198 inline G4double
199 G4ScaleTransform::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 
209 inline G4double
210 G4ScaleTransform::InverseTransformDistance(G4double safety) const
211 {
212   return ( safety*fgFactor );
213 }
214 
215 inline
216 std::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 }
234