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 #ifndef OPENMESH_VECTOR_HH
00040 #define OPENMESH_VECTOR_HH
00041
00042
00043
00044
00045
00046 #include <OpenMesh/Core/System/config.hh>
00047 #include <iostream>
00048 #include <assert.h>
00049 #include <math.h>
00050
00051 #if defined(__GNUC__) && defined(__SSE__)
00052 #include <xmmintrin.h>
00053 #endif
00054
00055
00056
00057
00058
00059 namespace OpenMesh {
00060
00061
00062
00063
00064
00065
00075 template <typename Scalar,int N> struct VectorDataT
00076 {
00077 Scalar values_[N];
00078 };
00079
00080
00081 #if defined(__GNUC__) && defined(__SSE__)
00082
00084 template <> struct VectorDataT<float, 4>
00085 {
00086 union
00087 {
00088 __m128 m128;
00089 float values_[4];
00090 };
00091 };
00092
00093 #endif
00094
00095
00096
00097
00098
00099
00100
00101 #define DIM N
00102 #define TEMPLATE_HEADER template <typename Scalar, int N>
00103 #define CLASSNAME VectorT
00104 #define DERIVED VectorDataT<Scalar,N>
00105 #define unroll(expr) for (int i=0; i<N; ++i) expr(i)
00106
00112 #include "VectorT_inc.hh"
00113
00114 #undef DIM
00115 #undef TEMPLATE_HEADER
00116 #undef CLASSNAME
00117 #undef DERIVED
00118 #undef unroll
00119
00120
00121
00122
00123
00124 #if OM_PARTIAL_SPECIALIZATION
00125
00126
00127 #define TEMPLATE_HEADER template <typename Scalar>
00128 #define CLASSNAME VectorT<Scalar,DIM>
00129 #define DERIVED VectorDataT<Scalar,DIM>
00130
00131
00132 #define DIM 2
00133 #define unroll(expr) expr(0) expr(1)
00134 #define unroll_comb(expr, op) expr(0) op expr(1)
00135 #define unroll_csv(expr) expr(0), expr(1)
00136 #include "VectorT_inc.hh"
00137 #undef DIM
00138 #undef unroll
00139 #undef unroll_comb
00140 #undef unroll_csv
00141
00142
00143 #define DIM 3
00144 #define unroll(expr) expr(0) expr(1) expr(2)
00145 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2)
00146 #define unroll_csv(expr) expr(0), expr(1), expr(2)
00147 #include "VectorT_inc.hh"
00148 #undef DIM
00149 #undef unroll
00150 #undef unroll_comb
00151 #undef unroll_csv
00152
00153
00154 #define DIM 4
00155 #define unroll(expr) expr(0) expr(1) expr(2) expr(3)
00156 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3)
00157 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3)
00158 #include "VectorT_inc.hh"
00159 #undef DIM
00160 #undef unroll
00161 #undef unroll_comb
00162 #undef unroll_csv
00163
00164
00165 #undef TEMPLATE_HEADER
00166 #undef CLASSNAME
00167 #undef DERIVED
00168
00169
00170
00171
00172
00173 #else
00174
00175 # ifndef DOXY_IGNORE_THIS
00176
00178 template<>
00179 inline VectorT<float,3>
00180 VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const
00181 {
00182 return
00183 VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
00184 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
00185 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
00186 }
00187
00188
00190 template<>
00191 inline VectorT<double,3>
00192 VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const
00193 {
00194 return
00195 VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
00196 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
00197 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
00198 }
00199
00200 # endif // DOXY_IGNORE_THIS
00201
00202 #endif
00203
00204
00205
00206
00207
00208
00211 template<typename Scalar,int N>
00212 inline VectorT<Scalar,N> operator*(Scalar _s, const VectorT<Scalar,N>& _v) {
00213 return VectorT<Scalar,N>(_v) *= _s;
00214 }
00215
00216
00219 template<typename Scalar, int N>
00220 inline Scalar
00221 dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
00222 return (_v1 | _v2);
00223 }
00224
00225
00228 template<typename Scalar, int N>
00229 inline VectorT<Scalar,N>
00230 cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
00231 return (_v1 % _v2);
00232 }
00233
00234
00235
00236
00237
00238
00240 typedef VectorT<signed char,1> Vec1c;
00242 typedef VectorT<unsigned char,1> Vec1uc;
00244 typedef VectorT<signed short int,1> Vec1s;
00246 typedef VectorT<unsigned short int,1> Vec1us;
00248 typedef VectorT<signed int,1> Vec1i;
00250 typedef VectorT<unsigned int,1> Vec1ui;
00252 typedef VectorT<float,1> Vec1f;
00254 typedef VectorT<double,1> Vec1d;
00255
00257 typedef VectorT<signed char,2> Vec2c;
00259 typedef VectorT<unsigned char,2> Vec2uc;
00261 typedef VectorT<signed short int,2> Vec2s;
00263 typedef VectorT<unsigned short int,2> Vec2us;
00265 typedef VectorT<signed int,2> Vec2i;
00267 typedef VectorT<unsigned int,2> Vec2ui;
00269 typedef VectorT<float,2> Vec2f;
00271 typedef VectorT<double,2> Vec2d;
00272
00274 typedef VectorT<signed char,3> Vec3c;
00276 typedef VectorT<unsigned char,3> Vec3uc;
00278 typedef VectorT<signed short int,3> Vec3s;
00280 typedef VectorT<unsigned short int,3> Vec3us;
00282 typedef VectorT<signed int,3> Vec3i;
00284 typedef VectorT<unsigned int,3> Vec3ui;
00286 typedef VectorT<float,3> Vec3f;
00288 typedef VectorT<double,3> Vec3d;
00289
00291 typedef VectorT<signed char,4> Vec4c;
00293 typedef VectorT<unsigned char,4> Vec4uc;
00295 typedef VectorT<signed short int,4> Vec4s;
00297 typedef VectorT<unsigned short int,4> Vec4us;
00299 typedef VectorT<signed int,4> Vec4i;
00301 typedef VectorT<unsigned int,4> Vec4ui;
00303 typedef VectorT<float,4> Vec4f;
00305 typedef VectorT<double,4> Vec4d;
00306
00308 typedef VectorT<signed char,6> Vec6c;
00310 typedef VectorT<unsigned char,6> Vec6uc;
00312 typedef VectorT<signed short int,6> Vec6s;
00314 typedef VectorT<unsigned short int,6> Vec6us;
00316 typedef VectorT<signed int,6> Vec6i;
00318 typedef VectorT<unsigned int,6> Vec6ui;
00320 typedef VectorT<float,6> Vec6f;
00322 typedef VectorT<double,6> Vec6d;
00323
00324
00325
00326 }
00327
00328 #endif // OPENMESH_VECTOR_HH defined
00329