CMS 3D CMS Logo

SSERot.h
Go to the documentation of this file.
1 #ifndef DataFormat_Math_SSERot_H
2 #define DataFormat_Math_SSERot_H
3 
5 
6 namespace mathSSE {
7 
8  template <typename T>
9  struct OldRot {
10  T R11, R12, R13;
11  T R21, R22, R23;
12  T R31, R32, R33;
13  } __attribute__((aligned(16)));
14 
15  template <typename T>
16  struct Rot3 {
17  Vec4<T> axis[3];
18 
19  Rot3() {
20  axis[0].arr[0] = 1;
21  axis[1].arr[1] = 1;
22  axis[2].arr[2] = 1;
23  }
24 
25  Rot3(Vec4<T> ix, Vec4<T> iy, Vec4<T> iz) {
26  axis[0] = ix;
27  axis[1] = iy;
28  axis[2] = iz;
29  }
30 
31  Rot3(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz) {
32  axis[0].set(xx, xy, xz);
33  axis[1].set(yx, yy, yz);
34  axis[2].set(zx, zy, zz);
35  }
36 
37  Rot3 transpose() const {
38  return Rot3(axis[0].arr[0],
39  axis[1].arr[0],
40  axis[2].arr[0],
41  axis[0].arr[1],
42  axis[1].arr[1],
43  axis[2].arr[1],
44  axis[0].arr[2],
45  axis[1].arr[2],
46  axis[2].arr[2]);
47  }
48 
49  Vec4<T> x() { return axis[0]; }
50  Vec4<T> y() { return axis[1]; }
51  Vec4<T> z() { return axis[2]; }
52 
53  // toLocal...
54  Vec4<T> rotate(Vec4<T> v) const { return transpose().rotateBack(v); }
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  typedef Rot3<float> Rot3F;
72 
74 
75 #ifdef __SSE4_1__
76  template <>
78  return _mm_or_ps(_mm_or_ps(_mm_dp_ps(axis[0].vec, v.vec, 0x71), _mm_dp_ps(axis[1].vec, v.vec, 0x72)),
79  _mm_dp_ps(axis[2].vec, v.vec, 0x74));
80  }
81  template <>
82  inline Rot3<float> Rot3<float>::rotate(Rot3<float> const& r) const {
83  return Rot3<float>(rotate(r.axis[0]), rotate(r.axis[1]), rotate(r.axis[2]));
84  }
85 
86 #endif
87 
88 } // namespace mathSSE
89 
90 template <typename T>
92  // return Rot3(lh.rotateBack(rh.axis[0]),lh.rotateBack(rh.axis[1]),lh.rotateBack(rh.axis[2]));
93  return lh.rotateBack(rh);
94 }
95 
96 namespace mathSSE {
97 
98  template <typename T>
99  struct Rot2 {
100  Vec2<T> axis[2];
101 
102  Rot2() {
103  axis[0].arr[0] = 1;
104  axis[1].arr[1] = 1;
105  }
106 
107  Rot2(Vec2<T> ix, Vec2<T> iy) {
108  axis[0] = ix;
109  axis[1] = iy;
110  }
111 
112  Rot2(T xx, T xy, T yx, T yy) {
113  axis[0].set(xx, xy);
114  axis[1].set(yx, yy);
115  }
116 
117  Rot2 transpose() const { return Rot2(axis[0].arr[0], axis[1].arr[0], axis[0].arr[1], axis[1].arr[1]); }
118 
119  Vec2<T> x() { return axis[0]; }
120  Vec2<T> y() { return axis[1]; }
121 
122  // toLocal...
123  Vec2<T> rotate(Vec2<T> v) const { return transpose().rotateBack(v); }
124 
125  // toGlobal...
126  Vec2<T> rotateBack(Vec2<T> v) const { return v.template get1<0>() * axis[0] + v.template get1<1>() * axis[1]; }
127 
128  Rot2 rotate(Rot2 const& r) const {
129  Rot2 tr = transpose();
130  return Rot2(tr.rotateBack(r.axis[0]), tr.rotateBack(r.axis[1]));
131  }
132 
133  Rot2 rotateBack(Rot2 const& r) const { return Rot2(rotateBack(r.axis[0]), rotateBack(r.axis[1])); }
134  };
135 
137 
139 
140 } // namespace mathSSE
141 
142 template <typename T>
144  return lh.rotateBack(rh);
145 }
146 
147 #include <iosfwd>
148 std::ostream& operator<<(std::ostream& out, mathSSE::Rot3F const& v);
149 std::ostream& operator<<(std::ostream& out, mathSSE::Rot3D const& v);
150 std::ostream& operator<<(std::ostream& out, mathSSE::Rot2F const& v);
151 std::ostream& operator<<(std::ostream& out, mathSSE::Rot2D const& v);
153 #endif // DataFormat_Math_SSERot_H
Definition: AVXVec.h:6
Rot2 transpose() const
Definition: SSERot.h:117
ExtVec< T, 2 > Vec2
Definition: ExtVec.h:66
def transpose(a)
Definition: geometryDiff.py:39
Vec4< T > rotateBack(Vec4< T > v) const
Definition: SSERot.h:57
Rot2(Vec2< T > ix, Vec2< T > iy)
Definition: SSERot.h:107
Vec4< T > x()
Definition: SSERot.h:49
Rot2< double > Rot2D
Definition: SSERot.h:138
Vec2< T > rotate(Vec2< T > v) const
Definition: SSERot.h:123
bool int lh
Definition: SIMDVec.h:20
Rot2 rotate(Rot2 const &r) const
Definition: SSERot.h:128
Vec2< T > y()
Definition: SSERot.h:120
mathSSE::Rot3< T > operator*(mathSSE::Rot3< T > const &rh, mathSSE::Rot3< T > const &lh)
Definition: SSERot.h:91
Vec2< T > axis[2]
Definition: ExtVec.h:229
Vec4< T > y()
Definition: SSERot.h:50
Rot2 rotateBack(Rot2 const &r) const
Definition: SSERot.h:133
Rot2(T xx, T xy, T yx, T yy)
Definition: SSERot.h:112
Vec4< T > axis[3]
Definition: SSERot.h:17
Rot3 rotate(Rot3 const &r) const
Definition: SSERot.h:61
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:64
Rot3< float > Rot3F
Definition: SSERot.h:71
Rot3< double > Rot3D
Definition: SSERot.h:73
Vec4< T > z()
Definition: SSERot.h:51
struct mathSSE::Rot3 __attribute__
Rot3(Vec4< T > ix, Vec4< T > iy, Vec4< T > iz)
Definition: SSERot.h:25
Rot3 transpose() const
Definition: SSERot.h:37
std::ostream & operator<<(std::ostream &out, mathSSE::Rot3F const &v)
Vec2< T > rotateBack(Vec2< T > v) const
Definition: SSERot.h:126
Vec2< T > x()
Definition: SSERot.h:119
Rot3(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz)
Definition: SSERot.h:31
constexpr Vec4< T > rotateBack(Vec4< T > v) const
Definition: ExtVec.h:205
Definition: ExtVec.h:181
constexpr Vec2< T > rotateBack(Vec2< T > v) const
Definition: ExtVec.h:246
Definition: ExtVec.h:227
long double T
Vec axis[3]
Definition: ExtVec.h:183
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:136
Vec4< T > rotate(Vec4< T > v) const
Definition: SSERot.h:54