Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // >> 27 // >> 28 // 26 // G4AffineTransformation Inline implementatio 29 // G4AffineTransformation Inline implementation 27 // 30 // 28 // ------------------------------------------- 31 // -------------------------------------------------------------------- 29 32 30 inline G4AffineTransform::G4AffineTransform() 33 inline G4AffineTransform::G4AffineTransform() 31 : rxx(1),rxy(0),rxz(0), 34 : rxx(1),rxy(0),rxz(0), 32 ryx(0),ryy(1),ryz(0), 35 ryx(0),ryy(1),ryz(0), 33 rzx(0),rzy(0),rzz(1), 36 rzx(0),rzy(0),rzz(1), 34 tx(0),ty(0),tz(0) 37 tx(0),ty(0),tz(0) 35 {} 38 {} 36 39 37 inline G4AffineTransform::G4AffineTransform(co 40 inline G4AffineTransform::G4AffineTransform(const G4ThreeVector& tlate) 38 : rxx(1),rxy(0),rxz(0), 41 : rxx(1),rxy(0),rxz(0), 39 ryx(0),ryy(1),ryz(0), 42 ryx(0),ryy(1),ryz(0), 40 rzx(0),rzy(0),rzz(1), 43 rzx(0),rzy(0),rzz(1), 41 tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 44 tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 42 {} 45 {} 43 46 44 inline G4AffineTransform::G4AffineTransform(co 47 inline G4AffineTransform::G4AffineTransform(const G4RotationMatrix& rot) 45 : rxx(rot.xx()),rxy(rot.xy()),rxz(rot.xz()), 48 : rxx(rot.xx()),rxy(rot.xy()),rxz(rot.xz()), 46 ryx(rot.yx()),ryy(rot.yy()),ryz(rot.yz()), 49 ryx(rot.yx()),ryy(rot.yy()),ryz(rot.yz()), 47 rzx(rot.zx()),rzy(rot.zy()),rzz(rot.zz()), 50 rzx(rot.zx()),rzy(rot.zy()),rzz(rot.zz()), 48 tx(0),ty(0),tz(0) 51 tx(0),ty(0),tz(0) 49 {} 52 {} 50 53 51 inline G4AffineTransform::G4AffineTransform( c 54 inline G4AffineTransform::G4AffineTransform( const G4RotationMatrix& rot, 52 c 55 const G4ThreeVector& tlate ) 53 : rxx(rot.xx()),rxy(rot.xy()),rxz(rot.xz()), 56 : rxx(rot.xx()),rxy(rot.xy()),rxz(rot.xz()), 54 ryx(rot.yx()),ryy(rot.yy()),ryz(rot.yz()), 57 ryx(rot.yx()),ryy(rot.yy()),ryz(rot.yz()), 55 rzx(rot.zx()),rzy(rot.zy()),rzz(rot.zz()), 58 rzx(rot.zx()),rzy(rot.zy()),rzz(rot.zz()), 56 tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 59 tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 57 {} 60 {} 58 61 59 inline G4AffineTransform::G4AffineTransform( c 62 inline G4AffineTransform::G4AffineTransform( const G4RotationMatrix* rot, 60 c 63 const G4ThreeVector& tlate ) 61 : tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 64 : tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 62 { 65 { 63 if (rot != nullptr) << 66 if (rot) 64 { 67 { 65 rxx=rot->xx();rxy=rot->xy();rxz=rot->xz(); 68 rxx=rot->xx();rxy=rot->xy();rxz=rot->xz(); 66 ryx=rot->yx();ryy=rot->yy();ryz=rot->yz(); 69 ryx=rot->yx();ryy=rot->yy();ryz=rot->yz(); 67 rzx=rot->zx();rzy=rot->zy();rzz=rot->zz(); 70 rzx=rot->zx();rzy=rot->zy();rzz=rot->zz(); 68 } 71 } 69 else 72 else 70 { 73 { 71 rxx=1; rxy=0; rxz=0; 74 rxx=1; rxy=0; rxz=0; 72 ryx=0; ryy=1; ryz=0; 75 ryx=0; ryy=1; ryz=0; 73 rzx=0; rzy=0; rzz=1; 76 rzx=0; rzy=0; rzz=1; 74 } 77 } 75 } 78 } 76 79 77 inline 80 inline 78 G4AffineTransform:: 81 G4AffineTransform:: 79 G4AffineTransform( const G4double prxx,const G 82 G4AffineTransform( const G4double prxx,const G4double prxy,const G4double prxz, 80 const G4double pryx,const G 83 const G4double pryx,const G4double pryy,const G4double pryz, 81 const G4double przx,const G 84 const G4double przx,const G4double przy,const G4double przz, 82 const G4double ptx,const G4 85 const G4double ptx,const G4double pty,const G4double ptz ) 83 : rxx(prxx),rxy(prxy),rxz(prxz), 86 : rxx(prxx),rxy(prxy),rxz(prxz), 84 ryx(pryx),ryy(pryy),ryz(pryz), 87 ryx(pryx),ryy(pryy),ryz(pryz), 85 rzx(przx),rzy(przy),rzz(przz), 88 rzx(przx),rzy(przy),rzz(przz), 86 tx(ptx),ty(pty),tz(ptz) 89 tx(ptx),ty(pty),tz(ptz) 87 {} 90 {} 88 91 >> 92 inline G4AffineTransform::G4AffineTransform(const G4AffineTransform& rhs) >> 93 : rxx(rhs.rxx),rxy(rhs.rxy),rxz(rhs.rxz), >> 94 ryx(rhs.ryx),ryy(rhs.ryy),ryz(rhs.ryz), >> 95 rzx(rhs.rzx),rzy(rhs.rzy),rzz(rhs.rzz), >> 96 tx(rhs.tx),ty(rhs.ty),tz(rhs.tz) >> 97 {} >> 98 89 inline G4AffineTransform& 99 inline G4AffineTransform& 90 G4AffineTransform::operator = (const G4AffineT 100 G4AffineTransform::operator = (const G4AffineTransform& rhs) 91 { 101 { 92 if (this == &rhs) { return *this; } 102 if (this == &rhs) { return *this; } 93 rxx = rhs.rxx; rxy = rhs.rxy; rxz = rhs.rxz; 103 rxx = rhs.rxx; rxy = rhs.rxy; rxz = rhs.rxz; 94 ryx = rhs.ryx; ryy = rhs.ryy; ryz = rhs.ryz; 104 ryx = rhs.ryx; ryy = rhs.ryy; ryz = rhs.ryz; 95 rzx = rhs.rzx; rzy = rhs.rzy; rzz = rhs.rzz; 105 rzx = rhs.rzx; rzy = rhs.rzy; rzz = rhs.rzz; 96 tx = rhs.tx; ty = rhs.ty; tz = rhs.tz; 106 tx = rhs.tx; ty = rhs.ty; tz = rhs.tz; 97 return *this; 107 return *this; 98 } 108 } 99 109 >> 110 inline G4AffineTransform::~G4AffineTransform() >> 111 {} >> 112 100 inline G4AffineTransform 113 inline G4AffineTransform 101 G4AffineTransform::operator * (const G4AffineT 114 G4AffineTransform::operator * (const G4AffineTransform& tf) const 102 { 115 { 103 return G4AffineTransform(rxx*tf.rxx+rxy*tf.r 116 return G4AffineTransform(rxx*tf.rxx+rxy*tf.ryx+rxz*tf.rzx, 104 rxx*tf.rxy+rxy*tf.r 117 rxx*tf.rxy+rxy*tf.ryy+rxz*tf.rzy, 105 rxx*tf.rxz+rxy*tf.r 118 rxx*tf.rxz+rxy*tf.ryz+rxz*tf.rzz, 106 119 107 ryx*tf.rxx+ryy*tf.r 120 ryx*tf.rxx+ryy*tf.ryx+ryz*tf.rzx, 108 ryx*tf.rxy+ryy*tf.r 121 ryx*tf.rxy+ryy*tf.ryy+ryz*tf.rzy, 109 ryx*tf.rxz+ryy*tf.r 122 ryx*tf.rxz+ryy*tf.ryz+ryz*tf.rzz, 110 123 111 rzx*tf.rxx+rzy*tf.r 124 rzx*tf.rxx+rzy*tf.ryx+rzz*tf.rzx, 112 rzx*tf.rxy+rzy*tf.r 125 rzx*tf.rxy+rzy*tf.ryy+rzz*tf.rzy, 113 rzx*tf.rxz+rzy*tf.r 126 rzx*tf.rxz+rzy*tf.ryz+rzz*tf.rzz, 114 127 115 tx*tf.rxx+ty*tf.ryx 128 tx*tf.rxx+ty*tf.ryx+tz*tf.rzx+tf.tx, 116 tx*tf.rxy+ty*tf.ryy 129 tx*tf.rxy+ty*tf.ryy+tz*tf.rzy+tf.ty, 117 tx*tf.rxz+ty*tf.ryz 130 tx*tf.rxz+ty*tf.ryz+tz*tf.rzz+tf.tz); 118 } 131 } 119 132 120 inline G4AffineTransform& 133 inline G4AffineTransform& 121 G4AffineTransform::operator *= (const G4Affine 134 G4AffineTransform::operator *= (const G4AffineTransform& tf) 122 { 135 { 123 // Use temporaries for `in place' compound t 136 // Use temporaries for `in place' compound transform computation 124 // 137 // 125 G4double nrxx=rxx*tf.rxx+rxy*tf.ryx+rxz*tf.r 138 G4double nrxx=rxx*tf.rxx+rxy*tf.ryx+rxz*tf.rzx; 126 G4double nrxy=rxx*tf.rxy+rxy*tf.ryy+rxz*tf.r 139 G4double nrxy=rxx*tf.rxy+rxy*tf.ryy+rxz*tf.rzy; 127 G4double nrxz=rxx*tf.rxz+rxy*tf.ryz+rxz*tf.r 140 G4double nrxz=rxx*tf.rxz+rxy*tf.ryz+rxz*tf.rzz; 128 141 129 G4double nryx=ryx*tf.rxx+ryy*tf.ryx+ryz*tf.r 142 G4double nryx=ryx*tf.rxx+ryy*tf.ryx+ryz*tf.rzx; 130 G4double nryy=ryx*tf.rxy+ryy*tf.ryy+ryz*tf.r 143 G4double nryy=ryx*tf.rxy+ryy*tf.ryy+ryz*tf.rzy; 131 G4double nryz=ryx*tf.rxz+ryy*tf.ryz+ryz*tf.r 144 G4double nryz=ryx*tf.rxz+ryy*tf.ryz+ryz*tf.rzz; 132 145 133 G4double nrzx=rzx*tf.rxx+rzy*tf.ryx+rzz*tf.r 146 G4double nrzx=rzx*tf.rxx+rzy*tf.ryx+rzz*tf.rzx; 134 G4double nrzy=rzx*tf.rxy+rzy*tf.ryy+rzz*tf.r 147 G4double nrzy=rzx*tf.rxy+rzy*tf.ryy+rzz*tf.rzy; 135 G4double nrzz=rzx*tf.rxz+rzy*tf.ryz+rzz*tf.r 148 G4double nrzz=rzx*tf.rxz+rzy*tf.ryz+rzz*tf.rzz; 136 149 137 G4double ntx=tx*tf.rxx+ty*tf.ryx+tz*tf.rzx+t 150 G4double ntx=tx*tf.rxx+ty*tf.ryx+tz*tf.rzx+tf.tx; 138 G4double nty=tx*tf.rxy+ty*tf.ryy+tz*tf.rzy+t 151 G4double nty=tx*tf.rxy+ty*tf.ryy+tz*tf.rzy+tf.ty; 139 G4double ntz=tx*tf.rxz+ty*tf.ryz+tz*tf.rzz+t 152 G4double ntz=tx*tf.rxz+ty*tf.ryz+tz*tf.rzz+tf.tz; 140 153 141 tx=ntx; ty=nty; tz=ntz; 154 tx=ntx; ty=nty; tz=ntz; 142 rxx=nrxx; rxy=nrxy; rxz=nrxz; 155 rxx=nrxx; rxy=nrxy; rxz=nrxz; 143 ryx=nryx; ryy=nryy; ryz=nryz; 156 ryx=nryx; ryy=nryy; ryz=nryz; 144 rzx=nrzx; rzy=nrzy; rzz=nrzz; 157 rzx=nrzx; rzy=nrzy; rzz=nrzz; 145 158 146 return *this; 159 return *this; 147 } 160 } 148 161 149 inline G4AffineTransform& 162 inline G4AffineTransform& 150 G4AffineTransform::Product( const G4AffineTran 163 G4AffineTransform::Product( const G4AffineTransform& tf1, 151 const G4AffineTran 164 const G4AffineTransform& tf2 ) 152 { 165 { 153 rxx = tf1.rxx*tf2.rxx + tf1.rxy*tf2.ryx + tf 166 rxx = tf1.rxx*tf2.rxx + tf1.rxy*tf2.ryx + tf1.rxz*tf2.rzx; 154 rxy = tf1.rxx*tf2.rxy + tf1.rxy*tf2.ryy + tf 167 rxy = tf1.rxx*tf2.rxy + tf1.rxy*tf2.ryy + tf1.rxz*tf2.rzy; 155 rxz = tf1.rxx*tf2.rxz + tf1.rxy*tf2.ryz + tf 168 rxz = tf1.rxx*tf2.rxz + tf1.rxy*tf2.ryz + tf1.rxz*tf2.rzz; 156 169 157 ryx = tf1.ryx*tf2.rxx + tf1.ryy*tf2.ryx + tf 170 ryx = tf1.ryx*tf2.rxx + tf1.ryy*tf2.ryx + tf1.ryz*tf2.rzx; 158 ryy = tf1.ryx*tf2.rxy + tf1.ryy*tf2.ryy + tf 171 ryy = tf1.ryx*tf2.rxy + tf1.ryy*tf2.ryy + tf1.ryz*tf2.rzy; 159 ryz = tf1.ryx*tf2.rxz + tf1.ryy*tf2.ryz + tf 172 ryz = tf1.ryx*tf2.rxz + tf1.ryy*tf2.ryz + tf1.ryz*tf2.rzz; 160 173 161 rzx = tf1.rzx*tf2.rxx + tf1.rzy*tf2.ryx + tf 174 rzx = tf1.rzx*tf2.rxx + tf1.rzy*tf2.ryx + tf1.rzz*tf2.rzx; 162 rzy = tf1.rzx*tf2.rxy + tf1.rzy*tf2.ryy + tf 175 rzy = tf1.rzx*tf2.rxy + tf1.rzy*tf2.ryy + tf1.rzz*tf2.rzy; 163 rzz = tf1.rzx*tf2.rxz + tf1.rzy*tf2.ryz + tf 176 rzz = tf1.rzx*tf2.rxz + tf1.rzy*tf2.ryz + tf1.rzz*tf2.rzz; 164 177 165 tx = tf1.tx*tf2.rxx + tf1.ty*tf2.ryx + tf1.t 178 tx = tf1.tx*tf2.rxx + tf1.ty*tf2.ryx + tf1.tz*tf2.rzx + tf2.tx; 166 ty = tf1.tx*tf2.rxy + tf1.ty*tf2.ryy + tf1.t 179 ty = tf1.tx*tf2.rxy + tf1.ty*tf2.ryy + tf1.tz*tf2.rzy + tf2.ty; 167 tz = tf1.tx*tf2.rxz + tf1.ty*tf2.ryz + tf1.t 180 tz = tf1.tx*tf2.rxz + tf1.ty*tf2.ryz + tf1.tz*tf2.rzz + tf2.tz; 168 181 169 return *this; 182 return *this; 170 } 183 } 171 184 172 inline G4AffineTransform& 185 inline G4AffineTransform& 173 G4AffineTransform::InverseProduct( const G4Aff 186 G4AffineTransform::InverseProduct( const G4AffineTransform& tf1, 174 const G4Aff 187 const G4AffineTransform& tf2 ) 175 { 188 { 176 if ((tf2.rxx + tf2.ryy + tf2.rzz) == 3.) 189 if ((tf2.rxx + tf2.ryy + tf2.rzz) == 3.) 177 { 190 { 178 rxx = tf1.rxx; 191 rxx = tf1.rxx; 179 rxy = tf1.rxy; 192 rxy = tf1.rxy; 180 rxz = tf1.rxz; 193 rxz = tf1.rxz; 181 194 182 ryx = tf1.ryx; 195 ryx = tf1.ryx; 183 ryy = tf1.ryy; 196 ryy = tf1.ryy; 184 ryz = tf1.ryz; 197 ryz = tf1.ryz; 185 198 186 rzx = tf1.rzx; 199 rzx = tf1.rzx; 187 rzy = tf1.rzy; 200 rzy = tf1.rzy; 188 rzz = tf1.rzz; 201 rzz = tf1.rzz; 189 202 190 tx = tf1.tx - tf2.tx; 203 tx = tf1.tx - tf2.tx; 191 ty = tf1.ty - tf2.ty; 204 ty = tf1.ty - tf2.ty; 192 tz = tf1.tz - tf2.tz; 205 tz = tf1.tz - tf2.tz; 193 } 206 } 194 else 207 else 195 { 208 { 196 G4double tf1rxx = tf1.rxx, tf1rxy = tf1.rx 209 G4double tf1rxx = tf1.rxx, tf1rxy = tf1.rxy, tf1rxz = tf1.rxz; 197 rxx = tf1rxx*tf2.rxx + tf1rxy*tf2.rxy + tf 210 rxx = tf1rxx*tf2.rxx + tf1rxy*tf2.rxy + tf1rxz*tf2.rxz; 198 rxy = tf1rxx*tf2.ryx + tf1rxy*tf2.ryy + tf 211 rxy = tf1rxx*tf2.ryx + tf1rxy*tf2.ryy + tf1rxz*tf2.ryz; 199 rxz = tf1rxx*tf2.rzx + tf1rxy*tf2.rzy + tf 212 rxz = tf1rxx*tf2.rzx + tf1rxy*tf2.rzy + tf1rxz*tf2.rzz; 200 213 201 G4double tf1ryx = tf1.ryx, tf1ryy = tf1.ry 214 G4double tf1ryx = tf1.ryx, tf1ryy = tf1.ryy, tf1ryz = tf1.ryz; 202 ryx = tf1ryx*tf2.rxx + tf1ryy*tf2.rxy + tf 215 ryx = tf1ryx*tf2.rxx + tf1ryy*tf2.rxy + tf1ryz*tf2.rxz; 203 ryy = tf1ryx*tf2.ryx + tf1ryy*tf2.ryy + tf 216 ryy = tf1ryx*tf2.ryx + tf1ryy*tf2.ryy + tf1ryz*tf2.ryz; 204 ryz = tf1ryx*tf2.rzx + tf1ryy*tf2.rzy + tf 217 ryz = tf1ryx*tf2.rzx + tf1ryy*tf2.rzy + tf1ryz*tf2.rzz; 205 218 206 G4double tf1rzx = tf1.rzx, tf1rzy = tf1.rz 219 G4double tf1rzx = tf1.rzx, tf1rzy = tf1.rzy, tf1rzz = tf1.rzz; 207 rzx = tf1rzx*tf2.rxx + tf1rzy*tf2.rxy + tf 220 rzx = tf1rzx*tf2.rxx + tf1rzy*tf2.rxy + tf1rzz*tf2.rxz; 208 rzy = tf1rzx*tf2.ryx + tf1rzy*tf2.ryy + tf 221 rzy = tf1rzx*tf2.ryx + tf1rzy*tf2.ryy + tf1rzz*tf2.ryz; 209 rzz = tf1rzx*tf2.rzx + tf1rzy*tf2.rzy + tf 222 rzz = tf1rzx*tf2.rzx + tf1rzy*tf2.rzy + tf1rzz*tf2.rzz; 210 223 211 G4double tf1_2tx = tf1.tx - tf2.tx; 224 G4double tf1_2tx = tf1.tx - tf2.tx; 212 G4double tf1_2ty = tf1.ty - tf2.ty; 225 G4double tf1_2ty = tf1.ty - tf2.ty; 213 G4double tf1_2tz = tf1.tz - tf2.tz; 226 G4double tf1_2tz = tf1.tz - tf2.tz; 214 tx = tf1_2tx*tf2.rxx + tf1_2ty*tf2.rxy + t 227 tx = tf1_2tx*tf2.rxx + tf1_2ty*tf2.rxy + tf1_2tz*tf2.rxz; 215 ty = tf1_2tx*tf2.ryx + tf1_2ty*tf2.ryy + t 228 ty = tf1_2tx*tf2.ryx + tf1_2ty*tf2.ryy + tf1_2tz*tf2.ryz; 216 tz = tf1_2tx*tf2.rzx + tf1_2ty*tf2.rzy + t 229 tz = tf1_2tx*tf2.rzx + tf1_2ty*tf2.rzy + tf1_2tz*tf2.rzz; 217 } 230 } 218 return *this; 231 return *this; 219 } 232 } 220 233 221 inline G4ThreeVector 234 inline G4ThreeVector 222 G4AffineTransform::TransformPoint(const G4Thre 235 G4AffineTransform::TransformPoint(const G4ThreeVector& vec) const 223 { 236 { 224 G4double vecx = vec.x(), vecy = vec.y(), vec 237 G4double vecx = vec.x(), vecy = vec.y(), vecz = vec.z(); 225 return { vecx*rxx + vecy*ryx + vecz*rzx + tx << 238 return G4ThreeVector( vecx*rxx + vecy*ryx + vecz*rzx + tx, 226 vecx*rxy + vecy*ryy + vecz*rzy + ty << 239 vecx*rxy + vecy*ryy + vecz*rzy + ty, 227 vecx*rxz + vecy*ryz + vecz*rzz + tz << 240 vecx*rxz + vecy*ryz + vecz*rzz + tz ); 228 } 241 } 229 242 230 inline G4ThreeVector 243 inline G4ThreeVector 231 G4AffineTransform::InverseTransformPoint(const 244 G4AffineTransform::InverseTransformPoint(const G4ThreeVector& vec) const 232 { 245 { 233 G4double vecx = vec.x()-tx, vecy = vec.y()-t 246 G4double vecx = vec.x()-tx, vecy = vec.y()-ty, vecz = vec.z()-tz; 234 return { vecx*rxx + vecy*rxy + vecz*rxz, << 247 return G4ThreeVector( vecx*rxx + vecy*rxy + vecz*rxz, 235 vecx*ryx + vecy*ryy + vecz*ryz, << 248 vecx*ryx + vecy*ryy + vecz*ryz, 236 vecx*rzx + vecy*rzy + vecz*rzz }; << 249 vecx*rzx + vecy*rzy + vecz*rzz ); 237 } 250 } 238 251 239 inline G4ThreeVector 252 inline G4ThreeVector 240 G4AffineTransform::TransformAxis(const G4Three 253 G4AffineTransform::TransformAxis(const G4ThreeVector& axis) const 241 { 254 { 242 G4double axisx = axis.x(), axisy = axis.y(), 255 G4double axisx = axis.x(), axisy = axis.y(), axisz = axis.z(); 243 return { axisx*rxx + axisy*ryx + axisz*rzx, << 256 return G4ThreeVector( axisx*rxx + axisy*ryx + axisz*rzx, 244 axisx*rxy + axisy*ryy + axisz*rzy, << 257 axisx*rxy + axisy*ryy + axisz*rzy, 245 axisx*rxz + axisy*ryz + axisz*rzz } << 258 axisx*rxz + axisy*ryz + axisz*rzz ); 246 } 259 } 247 260 248 inline G4ThreeVector 261 inline G4ThreeVector 249 G4AffineTransform::InverseTransformAxis(const 262 G4AffineTransform::InverseTransformAxis(const G4ThreeVector& axis) const 250 { 263 { 251 G4double axisx = axis.x(), axisy = axis.y(), 264 G4double axisx = axis.x(), axisy = axis.y(), axisz = axis.z(); 252 return { axisx*rxx + axisy*rxy + axisz*rxz, << 265 return G4ThreeVector( axisx*rxx + axisy*rxy + axisz*rxz, 253 axisx*ryx + axisy*ryy + axisz*ryz, << 266 axisx*ryx + axisy*ryy + axisz*ryz, 254 axisx*rzx + axisy*rzy + axisz*rzz } << 267 axisx*rzx + axisy*rzy + axisz*rzz ); 255 } 268 } 256 269 257 inline 270 inline 258 void G4AffineTransform::ApplyPointTransform(G4 271 void G4AffineTransform::ApplyPointTransform(G4ThreeVector& vec) const 259 { 272 { 260 G4double vecx = vec.x(), vecy = vec.y(), vec 273 G4double vecx = vec.x(), vecy = vec.y(), vecz = vec.z(); 261 vec.setX( vecx*rxx + vecy*ryx + vecz*rzx + t 274 vec.setX( vecx*rxx + vecy*ryx + vecz*rzx + tx ); 262 vec.setY( vecx*rxy + vecy*ryy + vecz*rzy + t 275 vec.setY( vecx*rxy + vecy*ryy + vecz*rzy + ty ); 263 vec.setZ( vecx*rxz + vecy*ryz + vecz*rzz + t 276 vec.setZ( vecx*rxz + vecy*ryz + vecz*rzz + tz ); 264 } 277 } 265 278 266 inline 279 inline 267 void G4AffineTransform::ApplyAxisTransform(G4T 280 void G4AffineTransform::ApplyAxisTransform(G4ThreeVector& axis) const 268 { 281 { 269 G4double axisx = axis.x(), axisy = axis.y(), 282 G4double axisx = axis.x(), axisy = axis.y(), axisz = axis.z(); 270 axis.setX( axisx*rxx + axisy*ryx + axisz*rzx 283 axis.setX( axisx*rxx + axisy*ryx + axisz*rzx ); 271 axis.setY( axisx*rxy + axisy*ryy + axisz*rzy 284 axis.setY( axisx*rxy + axisy*ryy + axisz*rzy ); 272 axis.setZ( axisx*rxz + axisy*ryz + axisz*rzz 285 axis.setZ( axisx*rxz + axisy*ryz + axisz*rzz ); 273 } 286 } 274 287 275 inline 288 inline 276 G4AffineTransform G4AffineTransform::Inverse() 289 G4AffineTransform G4AffineTransform::Inverse() const 277 { 290 { 278 G4double ttx = -tx, tty = -ty, ttz = -tz; 291 G4double ttx = -tx, tty = -ty, ttz = -tz; 279 return G4AffineTransform( rxx, ryx, rzx, 292 return G4AffineTransform( rxx, ryx, rzx, 280 rxy, ryy, rzy, 293 rxy, ryy, rzy, 281 rxz, ryz, rzz, 294 rxz, ryz, rzz, 282 ttx*rxx + tty*rxy 295 ttx*rxx + tty*rxy + ttz*rxz, 283 ttx*ryx + tty*ryy 296 ttx*ryx + tty*ryy + ttz*ryz, 284 ttx*rzx + tty*rzy 297 ttx*rzx + tty*rzy + ttz*rzz ); 285 } 298 } 286 299 287 inline 300 inline 288 G4AffineTransform& G4AffineTransform::Invert() 301 G4AffineTransform& G4AffineTransform::Invert() 289 { 302 { 290 G4double ttx = -tx, tty = -ty, ttz = -tz; 303 G4double ttx = -tx, tty = -ty, ttz = -tz; 291 tx = ttx*rxx + tty*rxy + ttz*rxz; 304 tx = ttx*rxx + tty*rxy + ttz*rxz; 292 ty = ttx*ryx + tty*ryy + ttz*ryz; 305 ty = ttx*ryx + tty*ryy + ttz*ryz; 293 tz = ttx*rzx + tty*rzy + ttz*rzz; 306 tz = ttx*rzx + tty*rzy + ttz*rzz; 294 307 295 G4double tmp1=ryx; ryx=rxy; rxy=tmp1; 308 G4double tmp1=ryx; ryx=rxy; rxy=tmp1; 296 G4double tmp2=rzx; rzx=rxz; rxz=tmp2; 309 G4double tmp2=rzx; rzx=rxz; rxz=tmp2; 297 G4double tmp3=rzy; rzy=ryz; ryz=tmp3; 310 G4double tmp3=rzy; rzy=ryz; ryz=tmp3; 298 311 299 return *this; 312 return *this; 300 } 313 } 301 314 302 inline 315 inline 303 G4AffineTransform& G4AffineTransform::operator 316 G4AffineTransform& G4AffineTransform::operator +=(const G4ThreeVector& tlate) 304 { 317 { 305 tx += tlate.x(); 318 tx += tlate.x(); 306 ty += tlate.y(); 319 ty += tlate.y(); 307 tz += tlate.z(); 320 tz += tlate.z(); 308 321 309 return *this; 322 return *this; 310 } 323 } 311 324 312 inline 325 inline 313 G4AffineTransform& G4AffineTransform::operator 326 G4AffineTransform& G4AffineTransform::operator -=(const G4ThreeVector& tlate) 314 { 327 { 315 tx -= tlate.x(); 328 tx -= tlate.x(); 316 ty -= tlate.y(); 329 ty -= tlate.y(); 317 tz -= tlate.z(); 330 tz -= tlate.z(); 318 331 319 return *this; 332 return *this; 320 } 333 } 321 334 322 inline 335 inline 323 G4bool G4AffineTransform::operator == (const G 336 G4bool G4AffineTransform::operator == (const G4AffineTransform& tf) const 324 { 337 { 325 return tx==tf.tx&&ty==tf.ty&&tz==tf.tz&& << 338 return (tx==tf.tx&&ty==tf.ty&&tz==tf.tz&& 326 rxx==tf.rxx&&rxy==tf.rxy&&rxz==tf.rxz << 339 rxx==tf.rxx&&rxy==tf.rxy&&rxz==tf.rxz&& 327 ryx==tf.ryx&&ryy==tf.ryy&&ryz==tf.ryz << 340 ryx==tf.ryx&&ryy==tf.ryy&&ryz==tf.ryz&& 328 rzx==tf.rzx&&rzy==tf.rzy&&rzz==tf.rzz << 341 rzx==tf.rzx&&rzy==tf.rzy&&rzz==tf.rzz) ? true : false; 329 } 342 } 330 343 331 inline 344 inline 332 G4bool G4AffineTransform::operator != (const G 345 G4bool G4AffineTransform::operator != (const G4AffineTransform& tf) const 333 { 346 { 334 return tx!=tf.tx||ty!=tf.ty||tz!=tf.tz|| << 347 return (tx!=tf.tx||ty!=tf.ty||tz!=tf.tz|| 335 rxx!=tf.rxx||rxy!=tf.rxy||rxz!=tf.rxz << 348 rxx!=tf.rxx||rxy!=tf.rxy||rxz!=tf.rxz|| 336 ryx!=tf.ryx||ryy!=tf.ryy||ryz!=tf.ryz << 349 ryx!=tf.ryx||ryy!=tf.ryy||ryz!=tf.ryz|| 337 rzx!=tf.rzx||rzy!=tf.rzy||rzz!=tf.rzz << 350 rzx!=tf.rzx||rzy!=tf.rzy||rzz!=tf.rzz) ? true : false; 338 } 351 } 339 352 340 inline 353 inline 341 G4double G4AffineTransform::operator [] (const 354 G4double G4AffineTransform::operator [] (const G4int n) const 342 { 355 { 343 G4double v = 0.0; 356 G4double v = 0.0; 344 switch(n) 357 switch(n) 345 { 358 { 346 case 0: 359 case 0: 347 v=rxx; 360 v=rxx; 348 break; 361 break; 349 case 1: 362 case 1: 350 v=rxy; 363 v=rxy; 351 break; 364 break; 352 case 2: 365 case 2: 353 v=rxz; 366 v=rxz; 354 break; 367 break; 355 case 4: 368 case 4: 356 v=ryx; 369 v=ryx; 357 break; 370 break; 358 case 5: 371 case 5: 359 v=ryy; 372 v=ryy; 360 break; 373 break; 361 case 6: 374 case 6: 362 v=ryz; 375 v=ryz; 363 break; 376 break; 364 case 8: 377 case 8: 365 v=rzx; 378 v=rzx; 366 break; 379 break; 367 case 9: 380 case 9: 368 v=rzy; 381 v=rzy; 369 break; 382 break; 370 case 10: 383 case 10: 371 v=rzz; 384 v=rzz; 372 break; 385 break; 373 case 12: 386 case 12: 374 v=tx; 387 v=tx; 375 break; 388 break; 376 case 13: 389 case 13: 377 v=ty; 390 v=ty; 378 break; 391 break; 379 case 14: 392 case 14: 380 v=tz; 393 v=tz; 381 break; 394 break; 382 case 3: 395 case 3: 383 case 7: 396 case 7: 384 case 11: 397 case 11: 385 break; 398 break; 386 case 15: 399 case 15: 387 v=1.0; 400 v=1.0; 388 break; 401 break; 389 } 402 } 390 return v; 403 return v; 391 } 404 } 392 405 393 inline 406 inline 394 G4bool G4AffineTransform::IsRotated() const 407 G4bool G4AffineTransform::IsRotated() const 395 { 408 { 396 return !(rxx==1.0 && ryy==1.0 && rzz==1.0); << 409 return (rxx==1.0 && ryy==1.0 && rzz==1.0) ? false : true; 397 } 410 } 398 411 399 inline 412 inline 400 G4bool G4AffineTransform::IsTranslated() const 413 G4bool G4AffineTransform::IsTranslated() const 401 { 414 { 402 return (tx != 0.0) || (ty != 0.0) || (tz != << 415 return (tx || ty || tz) ? true:false; 403 } 416 } 404 417 405 inline G4RotationMatrix G4AffineTransform::Net 418 inline G4RotationMatrix G4AffineTransform::NetRotation() const 406 { 419 { 407 return G4Rep3x3(rxx,rxy,rxz, 420 return G4Rep3x3(rxx,rxy,rxz, 408 ryx,ryy,ryz, 421 ryx,ryy,ryz, 409 rzx,rzy,rzz); 422 rzx,rzy,rzz); 410 } 423 } 411 424 412 inline G4RotationMatrix G4AffineTransform::Inv 425 inline G4RotationMatrix G4AffineTransform::InverseNetRotation() const 413 { 426 { 414 return G4Rep3x3(rxx,ryx,rzx, 427 return G4Rep3x3(rxx,ryx,rzx, 415 rxy,ryy,rzy, 428 rxy,ryy,rzy, 416 rxz,ryz,rzz); 429 rxz,ryz,rzz); 417 } 430 } 418 431 419 inline 432 inline 420 G4ThreeVector G4AffineTransform::NetTranslatio 433 G4ThreeVector G4AffineTransform::NetTranslation() const 421 { 434 { 422 return {tx,ty,tz}; << 435 return G4ThreeVector(tx,ty,tz); 423 } 436 } 424 437 425 inline 438 inline 426 G4ThreeVector G4AffineTransform::InverseNetTra 439 G4ThreeVector G4AffineTransform::InverseNetTranslation() const 427 { 440 { 428 G4double ttx = -tx, tty = -ty, ttz = -tz; 441 G4double ttx = -tx, tty = -ty, ttz = -tz; 429 G4double invtx = ttx*rxx + tty*rxy + ttz*rxz 442 G4double invtx = ttx*rxx + tty*rxy + ttz*rxz; 430 G4double invty = ttx*ryx + tty*ryy + ttz*ryz 443 G4double invty = ttx*ryx + tty*ryy + ttz*ryz; 431 G4double invtz = ttx*rzx + tty*rzy + ttz*rzz 444 G4double invtz = ttx*rzx + tty*rzy + ttz*rzz; 432 return {invtx,invty,invtz}; << 445 return G4ThreeVector(invtx,invty,invtz); 433 } 446 } 434 447 435 inline 448 inline 436 void G4AffineTransform::SetNetRotation(const G 449 void G4AffineTransform::SetNetRotation(const G4RotationMatrix& rot) 437 { 450 { 438 rxx=rot.xx(); 451 rxx=rot.xx(); 439 rxy=rot.xy(); 452 rxy=rot.xy(); 440 rxz=rot.xz(); 453 rxz=rot.xz(); 441 ryx=rot.yx(); 454 ryx=rot.yx(); 442 ryy=rot.yy(); 455 ryy=rot.yy(); 443 ryz=rot.yz(); 456 ryz=rot.yz(); 444 rzx=rot.zx(); 457 rzx=rot.zx(); 445 rzy=rot.zy(); 458 rzy=rot.zy(); 446 rzz=rot.zz(); 459 rzz=rot.zz(); 447 } 460 } 448 461 449 inline 462 inline 450 void G4AffineTransform::SetNetTranslation(cons 463 void G4AffineTransform::SetNetTranslation(const G4ThreeVector& tlate) 451 { 464 { 452 tx=tlate.x(); 465 tx=tlate.x(); 453 ty=tlate.y(); 466 ty=tlate.y(); 454 tz=tlate.z(); 467 tz=tlate.z(); 455 } 468 } 456 469 457 inline 470 inline 458 G4AffineTransform::operator G4Transform3D () c 471 G4AffineTransform::operator G4Transform3D () const 459 { 472 { 460 return G4Transform3D(NetRotation().inverse() 473 return G4Transform3D(NetRotation().inverse(),NetTranslation()); 461 } 474 } 462 475 463 inline 476 inline 464 std::ostream& operator << (std::ostream& os, c 477 std::ostream& operator << (std::ostream& os, const G4AffineTransform& transf) 465 { 478 { 466 std::streamsize oldPrec = os.precision(6); 479 std::streamsize oldPrec = os.precision(6); 467 G4double DeviationTolerance = 1.0e-05; 480 G4double DeviationTolerance = 1.0e-05; 468 481 469 G4double diagDeviation = 0.0; 482 G4double diagDeviation = 0.0; 470 G4double offdDeviationUL = 0.0; 483 G4double offdDeviationUL = 0.0; 471 G4double offdDeviationDR = 0.0; 484 G4double offdDeviationDR = 0.0; 472 G4double offdDeviation = 0.0; 485 G4double offdDeviation = 0.0; 473 486 474 os << " Transformation: " << G4endl; 487 os << " Transformation: " << G4endl; 475 488 476 // double a = std::max ( 1, 2, 3 ) ; 489 // double a = std::max ( 1, 2, 3 ) ; 477 490 478 G4bool UnitTr = ! transf.IsRotated(); 491 G4bool UnitTr = ! transf.IsRotated(); 479 diagDeviation = std::max( std::fabs( transf[ 492 diagDeviation = std::max( std::fabs( transf[0] - 1.0 ) , // |rxx - 1| 480 std::fabs( transf[ 493 std::fabs( transf[5] - 1.0 ) ); // |ryy - 1| 481 diagDeviation = std::max( diagDeviation, 494 diagDeviation = std::max( diagDeviation, 482 std::fabs( transf[ 495 std::fabs( transf[10] - 1.0 ) ); // |rzz - 1| 483 496 484 offdDeviationUL = std::max( std::fabs( trans 497 offdDeviationUL = std::max( std::fabs( transf[1] ) , // |rxy| 485 std::fabs( trans 498 std::fabs( transf[2] ) ); // |rxz| 486 offdDeviationUL = std::max( offdDeviationUL, 499 offdDeviationUL = std::max( offdDeviationUL, 487 std::fabs( trans 500 std::fabs( transf[4] ) ); // |ryx| 488 501 489 offdDeviationDR = std::max( std::fabs( trans 502 offdDeviationDR = std::max( std::fabs( transf[6] ) , // |ryz| 490 std::fabs( trans 503 std::fabs( transf[8] ) ); // |rzx| 491 offdDeviationDR = std::max( offdDeviationDR, 504 offdDeviationDR = std::max( offdDeviationDR, 492 std::fabs( trans 505 std::fabs( transf[9] ) ); // |rzy| 493 offdDeviation = std::max( offdDeviationUL, o 506 offdDeviation = std::max( offdDeviationUL, offdDeviationDR ); 494 507 495 if( UnitTr || std::max(diagDeviation, offdDe 508 if( UnitTr || std::max(diagDeviation, offdDeviation) < DeviationTolerance ) 496 { 509 { 497 os << " UNIT Rotation " << G4endl; 510 os << " UNIT Rotation " << G4endl; 498 } 511 } 499 else 512 else 500 { 513 { 501 os << "rx/x,y,z: " 514 os << "rx/x,y,z: " 502 << transf[0] << " " << transf[1] << " 515 << transf[0] << " " << transf[1] << " " << transf[2] << G4endl 503 << "ry/x,y,z: " 516 << "ry/x,y,z: " 504 << transf[4] << " " << transf[5] << " 517 << transf[4] << " " << transf[5] << " " << transf[6] << G4endl 505 << "rz/x,y,z: " 518 << "rz/x,y,z: " 506 << transf[8] << " " << transf[9] << " 519 << transf[8] << " " << transf[9] << " " << transf[10] << G4endl; 507 } 520 } 508 521 509 os << "tr/x,y,z: " << transf[12] << " " << 522 os << "tr/x,y,z: " << transf[12] << " " << transf[13] << " " << transf[14] 510 << G4endl; 523 << G4endl; 511 524 512 os.precision(oldPrec); 525 os.precision(oldPrec); 513 526 514 return os; 527 return os; 515 } 528 } 516 529