CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SSERot.h
Go to the documentation of this file.
1 #ifndef DataFormat_Math_SSERot_H
2 #define DataFormat_Math_SSERot_H
3 
4 
6 
7 namespace mathSSE {
8 
9  template<typename T>
10  struct OldRot {
11  T R11, R12, R13;
12  T R21, R22, R23;
13  T R31, R32, R33;
14  } __attribute__ ((aligned (16)));
15 
16 
17  template<typename T>
18  struct Rot3 {
19  Vec4<T> axis[3];
20 
21  Rot3() {
22  axis[0].arr[0]=1;
23  axis[1].arr[1]=1;
24  axis[2].arr[2]=1;
25  }
26 
27  Rot3( Vec4<T> ix, Vec4<T> iy, Vec4<T> iz) {
28  axis[0] =ix;
29  axis[1] =iy;
30  axis[2] =iz;
31  }
32 
33  Rot3( T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz) {
34  axis[0].set(xx,xy,xz);
35  axis[1].set(yx,yy,yz);
36  axis[2].set(zx,zy,zz);
37  }
38 
39  Rot3 transpose() const {
40  return Rot3( axis[0].arr[0], axis[1].arr[0], axis[2].arr[0],
41  axis[0].arr[1], axis[1].arr[1], axis[2].arr[1],
42  axis[0].arr[2], axis[1].arr[2], axis[2].arr[2]
43  );
44  }
45 
46  Vec4<T> x() { return axis[0];}
47  Vec4<T> y() { return axis[1];}
48  Vec4<T> z() { return axis[2];}
49 
50  // toLocal...
52  return transpose().rotateBack(v);
53  }
54 
55 
56  // toGlobal...
58  return v.template get1<0>()*axis[0] + v.template get1<1>()*axis[1] + v.template get1<2>()*axis[2];
59  }
60 
61  Rot3 rotate(Rot3 const& r) const {
62  Rot3 tr = transpose();
63  return Rot3(tr.rotateBack(r.axis[0]),tr.rotateBack(r.axis[1]),tr.rotateBack(r.axis[2]));
64  }
65 
66  Rot3 rotateBack(Rot3 const& r) const {
67  return Rot3(rotateBack(r.axis[0]),rotateBack(r.axis[1]),rotateBack(r.axis[2]));
68  }
69 
70 
71  };
72 
73  typedef Rot3<float> Rot3F;
74 
76 
77 #ifdef __SSE4_1__
78  template<>
80  return _mm_or_ps(_mm_or_ps(_mm_dp_ps(axis[0].vec,v.vec,0x71),
81  _mm_dp_ps(axis[1].vec,v.vec,0x72)),
82  _mm_dp_ps(axis[2].vec,v.vec,0x74)
83  );
84  }
85  template<>
86  inline Rot3<float> Rot3<float>::rotate(Rot3<float> const& r) const {
87  return Rot3<float> (rotate(r.axis[0]),rotate(r.axis[1]),rotate(r.axis[2]));
88  }
89 
90 #endif
91 
92 
93 }
94 
95 template<typename T>
97  // return Rot3(lh.rotateBack(rh.axis[0]),lh.rotateBack(rh.axis[1]),lh.rotateBack(rh.axis[2]));
98  return lh.rotateBack(rh);
99 }
100 
101 namespace mathSSE {
102 
103  template<typename T>
104  struct Rot2 {
105  Vec2<T> axis[2];
106 
107  Rot2() {
108  axis[0].arr[0]=1;
109  axis[1].arr[1]=1;
110  }
111 
112  Rot2( Vec2<T> ix, Vec2<T> iy) {
113  axis[0] =ix;
114  axis[1] =iy;
115  }
116 
117  Rot2( T xx, T xy, T yx, T yy) {
118  axis[0].set(xx,xy);
119  axis[1].set(yx,yy);
120  }
121 
122  Rot2 transpose() const {
123  return Rot2( axis[0].arr[0], axis[1].arr[0],
124  axis[0].arr[1], axis[1].arr[1]
125  );
126  }
127 
128  Vec2<T> x() { return axis[0];}
129  Vec2<T> y() { return axis[1];}
130 
131  // toLocal...
133  return transpose().rotateBack(v);
134  }
135 
136 
137  // toGlobal...
139  return v.template get1<0>()*axis[0] + v.template get1<1>()*axis[1];
140  }
141 
142  Rot2 rotate(Rot2 const& r) const {
143  Rot2 tr = transpose();
144  return Rot2(tr.rotateBack(r.axis[0]),tr.rotateBack(r.axis[1]));
145  }
146 
147  Rot2 rotateBack(Rot2 const& r) const {
148  return Rot2(rotateBack(r.axis[0]),rotateBack(r.axis[1]));
149  }
150 
151 
152  };
153 
155 
157 
158 
159 }
160 
161 template<typename T>
163  return lh.rotateBack(rh);
164 }
165 
166 
167 
168 #include <iosfwd>
169 std::ostream & operator<<(std::ostream & out, mathSSE::Rot3F const & v);
170 std::ostream & operator<<(std::ostream & out, mathSSE::Rot3D const & v);
171 std::ostream & operator<<(std::ostream & out, mathSSE::Rot2F const & v);
172 std::ostream & operator<<(std::ostream & out, mathSSE::Rot2D const & v);
175 #endif // DataFormat_Math_SSERot_H
Definition: AVXVec.h:6
Rot2 transpose() const
Definition: SSERot.h:122
def transpose(a)
Definition: geometryDiff.py:39
Vec4< T > rotateBack(Vec4< T > v) const
Definition: SSERot.h:57
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:62
Rot2(Vec2< T > ix, Vec2< T > iy)
Definition: SSERot.h:112
Vec4< T > x()
Definition: SSERot.h:46
Rot2< double > Rot2D
Definition: SSERot.h:156
Vec2< T > rotate(Vec2< T > v) const
Definition: SSERot.h:132
bool int lh
Definition: SIMDVec.h:21
Rot2 rotate(Rot2 const &r) const
Definition: SSERot.h:142
Vec2< T > y()
Definition: SSERot.h:129
mathSSE::Rot3< T > operator*(mathSSE::Rot3< T > const &rh, mathSSE::Rot3< T > const &lh)
Definition: SSERot.h:96
Vec2< T > axis[2]
Definition: ExtVec.h:255
Vec4< T > y()
Definition: SSERot.h:47
Rot2 rotateBack(Rot2 const &r) const
Definition: SSERot.h:147
Rot2(T xx, T xy, T yx, T yy)
Definition: SSERot.h:117
Vec4< T > axis[3]
Definition: SSERot.h:19
Rot3 rotate(Rot3 const &r) const
Definition: SSERot.h:61
Rot3< float > Rot3F
Definition: SSERot.h:73
Rot3< double > Rot3D
Definition: SSERot.h:75
Vec4< T > z()
Definition: SSERot.h:48
struct mathSSE::Rot3 __attribute__
Rot3(Vec4< T > ix, Vec4< T > iy, Vec4< T > iz)
Definition: SSERot.h:27
Rot3 transpose() const
Definition: SSERot.h:39
std::ostream & operator<<(std::ostream &out, mathSSE::Rot3F const &v)
Vec2< T > rotateBack(Vec2< T > v) const
Definition: SSERot.h:138
Vec2< T > x()
Definition: SSERot.h:128
Rot3(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz)
Definition: SSERot.h:33
constexpr Vec4< T > rotateBack(Vec4< T > v) const
Definition: ExtVec.h:226
ExtVec< T, 2 > Vec2
Definition: ExtVec.h:63
Definition: ExtVec.h:189
constexpr Vec2< T > rotateBack(Vec2< T > v) const
Definition: ExtVec.h:286
Definition: ExtVec.h:253
long double T
Vec axis[3]
Definition: ExtVec.h:191
def rotate(angle, cx=0, cy=0)
Definition: svgfig.py:705
Rot3 rotateBack(Rot3 const &r) const
Definition: SSERot.h:66
Rot2< float > Rot2F
Definition: SSERot.h:154
Vec4< T > rotate(Vec4< T > v) const
Definition: SSERot.h:51