File indexing completed on 2025-01-18 09:59:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 inline G4ScaleTransform::G4ScaleTransform()
0033 : fScale(1.,1.,1.), fIScale(1.,1.,1.)
0034 {
0035 }
0036
0037 inline G4ScaleTransform::G4ScaleTransform(G4double sx, G4double sy, G4double sz)
0038 : fScale(sx,sy,sz), fIScale()
0039 {
0040 Init();
0041 }
0042
0043 inline G4ScaleTransform::G4ScaleTransform(const G4ThreeVector& scale)
0044 : fScale(scale), fIScale()
0045 {
0046 Init();
0047 }
0048
0049 inline G4ScaleTransform::G4ScaleTransform(const G4Scale3D& scale)
0050 : fScale(scale.xx(), scale.yy(), scale.zz()), fIScale()
0051 {
0052 Init();
0053 }
0054
0055 inline G4ScaleTransform::G4ScaleTransform(const G4ScaleTransform& right)
0056 : fScale(right.fScale), fIScale(right.fIScale),
0057 flFactor(right.flFactor), fgFactor(right.fgFactor)
0058 {
0059 }
0060
0061 inline G4ScaleTransform&
0062 G4ScaleTransform::operator=(const G4ScaleTransform& right)
0063 {
0064 fScale = right.fScale;
0065 fIScale = right.fIScale;
0066 flFactor = right.flFactor;
0067 fgFactor = right.fgFactor;
0068 return *this;
0069 }
0070
0071 inline void G4ScaleTransform::Init()
0072 {
0073 if (!((fScale.x()>0) && (fScale.y()>0) && (fScale.z()>0)))
0074 {
0075 G4Exception("G4ScaleTransform::Init()", "GeomMgt0001",
0076 FatalException, "Scale transformation must be positive!");
0077 }
0078 fIScale.set(1./fScale.x(), 1./fScale.y(), 1./fScale.z());
0079 flFactor = std::min(std::min(fIScale.x(), fIScale.y()), fIScale.z());
0080 fgFactor = std::min(std::min(fScale.x(), fScale.y()), fScale.z());
0081 }
0082
0083 inline const G4ThreeVector& G4ScaleTransform::GetScale() const
0084 {
0085 return fScale;
0086 }
0087
0088 inline const G4ThreeVector& G4ScaleTransform::GetInvScale() const
0089 {
0090 return fIScale;
0091 }
0092
0093 inline void G4ScaleTransform::SetScale(const G4ThreeVector& scale)
0094 {
0095 fScale = scale;
0096 Init();
0097 }
0098
0099 inline void G4ScaleTransform::SetScale(const G4Scale3D& scale)
0100 {
0101 fScale.set(scale.xx(), scale.yy(), scale.zz());
0102 Init();
0103 }
0104
0105 inline void G4ScaleTransform::SetScale(G4double sx, G4double sy, G4double sz)
0106 {
0107 fScale.set(sx,sy,sz);
0108 Init();
0109 }
0110
0111 inline void G4ScaleTransform::Transform(const G4ThreeVector& global,
0112 G4ThreeVector& local) const
0113 {
0114 local.set(global.x()*fIScale.x(),
0115 global.y()*fIScale.y(),
0116 global.z()*fIScale.z());
0117 }
0118
0119 inline G4ThreeVector
0120 G4ScaleTransform::Transform(const G4ThreeVector& global) const
0121 {
0122 G4ThreeVector local(global.x()*fIScale.x(),
0123 global.y()*fIScale.y(),
0124 global.z()*fIScale.z());
0125 return local;
0126 }
0127
0128 inline void
0129 G4ScaleTransform::InverseTransform(const G4ThreeVector& local,
0130 G4ThreeVector& global) const
0131 {
0132 global.set(local.x()*fScale.x(),
0133 local.y()*fScale.y(),
0134 local.z()*fScale.z());
0135 }
0136
0137 inline G4ThreeVector
0138 G4ScaleTransform::InverseTransform(const G4ThreeVector& local) const
0139 {
0140 G4ThreeVector global(local.x()*fScale.x(),
0141 local.y()*fScale.y(),
0142 local.z()*fScale.z());
0143 return global;
0144 }
0145
0146 inline void
0147 G4ScaleTransform::TransformNormal(const G4ThreeVector& global,
0148 G4ThreeVector& local) const
0149 {
0150 local.set(global.x()*fIScale.y()*fIScale.z(),
0151 global.y()*fIScale.z()*fIScale.x(),
0152 global.z()*fIScale.x()*fIScale.y());
0153 }
0154
0155 inline G4ThreeVector
0156 G4ScaleTransform::TransformNormal(const G4ThreeVector& global) const
0157 {
0158 G4ThreeVector local(global.x()*fIScale.y()*fIScale.z(),
0159 global.y()*fIScale.z()*fIScale.x(),
0160 global.z()*fIScale.x()*fIScale.y());
0161 return local;
0162 }
0163
0164 inline void
0165 G4ScaleTransform::InverseTransformNormal(const G4ThreeVector& local,
0166 G4ThreeVector& global) const
0167 {
0168 global.set(local.x()*fScale.y()*fScale.z(),
0169 local.y()*fScale.z()*fScale.x(),
0170 local.z()*fScale.x()*fScale.y());
0171 }
0172
0173 inline G4ThreeVector
0174 G4ScaleTransform::InverseTransformNormal(const G4ThreeVector& local) const
0175 {
0176 G4ThreeVector global(local.x()*fScale.y()*fScale.z(),
0177 local.y()*fScale.z()*fScale.x(),
0178 local.z()*fScale.x()*fScale.y());
0179 return global;
0180 }
0181
0182 inline G4double
0183 G4ScaleTransform::TransformDistance(G4double dist,
0184 const G4ThreeVector& dir) const
0185 {
0186 G4ThreeVector v(dir.x()*fIScale.x(),
0187 dir.y()*fIScale.y(),
0188 dir.z()*fIScale.z());
0189 G4double scale = std::sqrt(v.dot(v));
0190 return ( scale*dist );
0191 }
0192
0193 inline G4double G4ScaleTransform::TransformDistance(G4double safety) const
0194 {
0195 return ( safety*flFactor );
0196 }
0197
0198 inline G4double
0199 G4ScaleTransform::InverseTransformDistance(G4double dist,
0200 const G4ThreeVector& dir) const
0201 {
0202 G4ThreeVector v(dir.x()*fScale.x(),
0203 dir.y()*fScale.y(),
0204 dir.z()*fScale.z());
0205 G4double scale = std::sqrt(v.dot(v));
0206 return ( scale*dist );
0207 }
0208
0209 inline G4double
0210 G4ScaleTransform::InverseTransformDistance(G4double safety) const
0211 {
0212 return ( safety*fgFactor );
0213 }
0214
0215 inline
0216 std::ostream& operator << (std::ostream& os, const G4ScaleTransform& transf)
0217 {
0218 std::streamsize oldPrec = os.precision(6);
0219
0220 os << " Scale Transformation: " << G4endl
0221 << " x,y,z: "
0222 << transf.GetScale().x() << " "
0223 << transf.GetScale().y() << " "
0224 << transf.GetScale().z() << G4endl
0225 << " Inverse x,y,z: "
0226 << transf.GetInvScale().x() << " "
0227 << transf.GetInvScale().y() << " "
0228 << transf.GetInvScale().z() << G4endl;
0229
0230 os.precision(oldPrec);
0231
0232 return os;
0233 }