00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef OPENMESH_VECTOR_HH
00051 #define OPENMESH_VECTOR_HH
00052
00053
00054
00055
00056
00057 #include <OpenMesh/Core/System/config.h>
00058 #include <iostream>
00059 #include <assert.h>
00060 #include <math.h>
00061
00062 #if defined(__GNUC__) && defined(__SSE__)
00063 #include <xmmintrin.h>
00064 #endif
00065
00066
00067
00068
00069
00070 namespace OpenMesh {
00071
00072
00073
00074
00075
00076
00086 template <typename Scalar,int N> struct VectorDataT
00087 {
00088 Scalar values_[N];
00089 };
00090
00091
00092 #if defined(__GNUC__) && defined(__SSE__)
00093
00095 template <> struct VectorDataT<float, 4>
00096 {
00097 union
00098 {
00099 __m128 m128;
00100 float values_[4];
00101 };
00102 };
00103
00104 #endif
00105
00106
00107
00108
00109
00110
00111
00112 #define DIM N
00113 #define TEMPLATE_HEADER template <typename Scalar, int N>
00114 #define CLASSNAME VectorT
00115 #define DERIVED VectorDataT<Scalar,N>
00116 #define unroll(expr) for (int i=0; i<N; ++i) expr(i)
00117
00123 #include "VectorT_inc.hh"
00124
00125 #undef DIM
00126 #undef TEMPLATE_HEADER
00127 #undef CLASSNAME
00128 #undef DERIVED
00129 #undef unroll
00130
00131
00132
00133
00134
00135 #if OM_PARTIAL_SPECIALIZATION
00136
00137
00138 #define TEMPLATE_HEADER template <typename Scalar>
00139 #define CLASSNAME VectorT<Scalar,DIM>
00140 #define DERIVED VectorDataT<Scalar,DIM>
00141
00142
00143 #define DIM 2
00144 #define unroll(expr) expr(0) expr(1)
00145 #define unroll_comb(expr, op) expr(0) op expr(1)
00146 #define unroll_csv(expr) expr(0), expr(1)
00147 #include "VectorT_inc.hh"
00148 #undef DIM
00149 #undef unroll
00150 #undef unroll_comb
00151 #undef unroll_csv
00152
00153
00154 #define DIM 3
00155 #define unroll(expr) expr(0) expr(1) expr(2)
00156 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2)
00157 #define unroll_csv(expr) expr(0), expr(1), expr(2)
00158 #include "VectorT_inc.hh"
00159 #undef DIM
00160 #undef unroll
00161 #undef unroll_comb
00162 #undef unroll_csv
00163
00164
00165 #define DIM 4
00166 #define unroll(expr) expr(0) expr(1) expr(2) expr(3)
00167 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3)
00168 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3)
00169 #include "VectorT_inc.hh"
00170 #undef DIM
00171 #undef unroll
00172 #undef unroll_comb
00173 #undef unroll_csv
00174
00175
00176 #undef TEMPLATE_HEADER
00177 #undef CLASSNAME
00178 #undef DERIVED
00179
00180
00181
00182
00183
00184 #else
00185
00186 # ifndef DOXY_IGNORE_THIS
00187
00189 template<>
00190 inline VectorT<float,3>
00191 VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const
00192 {
00193 return
00194 VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
00195 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
00196 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
00197 }
00198
00199
00201 template<>
00202 inline VectorT<double,3>
00203 VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const
00204 {
00205 return
00206 VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
00207 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
00208 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
00209 }
00210
00211 # endif // DOXY_IGNORE_THIS
00212
00213 #endif
00214
00215
00216
00217
00218
00219
00222 template<typename Scalar,int N>
00223 inline VectorT<Scalar,N> operator*(Scalar _s, const VectorT<Scalar,N>& _v) {
00224 return VectorT<Scalar,N>(_v) *= _s;
00225 }
00226
00227
00230 template<typename Scalar, int N>
00231 inline Scalar
00232 dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
00233 return (_v1 | _v2);
00234 }
00235
00236
00239 template<typename Scalar, int N>
00240 inline VectorT<Scalar,N>
00241 cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
00242 return (_v1 % _v2);
00243 }
00244
00245
00246
00247
00248
00249
00251 typedef VectorT<signed char,1> Vec1c;
00253 typedef VectorT<unsigned char,1> Vec1uc;
00255 typedef VectorT<signed short int,1> Vec1s;
00257 typedef VectorT<unsigned short int,1> Vec1us;
00259 typedef VectorT<signed int,1> Vec1i;
00261 typedef VectorT<unsigned int,1> Vec1ui;
00263 typedef VectorT<float,1> Vec1f;
00265 typedef VectorT<double,1> Vec1d;
00266
00268 typedef VectorT<signed char,2> Vec2c;
00270 typedef VectorT<unsigned char,2> Vec2uc;
00272 typedef VectorT<signed short int,2> Vec2s;
00274 typedef VectorT<unsigned short int,2> Vec2us;
00276 typedef VectorT<signed int,2> Vec2i;
00278 typedef VectorT<unsigned int,2> Vec2ui;
00280 typedef VectorT<float,2> Vec2f;
00282 typedef VectorT<double,2> Vec2d;
00283
00285 typedef VectorT<signed char,3> Vec3c;
00287 typedef VectorT<unsigned char,3> Vec3uc;
00289 typedef VectorT<signed short int,3> Vec3s;
00291 typedef VectorT<unsigned short int,3> Vec3us;
00293 typedef VectorT<signed int,3> Vec3i;
00295 typedef VectorT<unsigned int,3> Vec3ui;
00297 typedef VectorT<float,3> Vec3f;
00299 typedef VectorT<double,3> Vec3d;
00300
00302 typedef VectorT<signed char,4> Vec4c;
00304 typedef VectorT<unsigned char,4> Vec4uc;
00306 typedef VectorT<signed short int,4> Vec4s;
00308 typedef VectorT<unsigned short int,4> Vec4us;
00310 typedef VectorT<signed int,4> Vec4i;
00312 typedef VectorT<unsigned int,4> Vec4ui;
00314 typedef VectorT<float,4> Vec4f;
00316 typedef VectorT<double,4> Vec4d;
00317
00319 typedef VectorT<signed char,6> Vec6c;
00321 typedef VectorT<unsigned char,6> Vec6uc;
00323 typedef VectorT<signed short int,6> Vec6s;
00325 typedef VectorT<unsigned short int,6> Vec6us;
00327 typedef VectorT<signed int,6> Vec6i;
00329 typedef VectorT<unsigned int,6> Vec6ui;
00331 typedef VectorT<float,6> Vec6f;
00333 typedef VectorT<double,6> Vec6d;
00334
00335
00336
00337 }
00338
00339 #endif // OPENMESH_VECTOR_HH defined
00340