OpenMesh
|
00001 /*===========================================================================*\ 00002 * * 00003 * OpenMesh * 00004 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen * 00005 * www.openmesh.org * 00006 * * 00007 *---------------------------------------------------------------------------* 00008 * This file is part of OpenMesh. * 00009 * * 00010 * OpenMesh is free software: you can redistribute it and/or modify * 00011 * it under the terms of the GNU Lesser General Public License as * 00012 * published by the Free Software Foundation, either version 3 of * 00013 * the License, or (at your option) any later version with the * 00014 * following exceptions: * 00015 * * 00016 * If other files instantiate templates or use macros * 00017 * or inline functions from this file, or you compile this file and * 00018 * link it with other files to produce an executable, this file does * 00019 * not by itself cause the resulting executable to be covered by the * 00020 * GNU Lesser General Public License. This exception does not however * 00021 * invalidate any other reasons why the executable file might be * 00022 * covered by the GNU Lesser General Public License. * 00023 * * 00024 * OpenMesh is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU Lesser General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU LesserGeneral Public * 00030 * License along with OpenMesh. If not, * 00031 * see <http://www.gnu.org/licenses/>. * 00032 * * 00033 \*===========================================================================*/ 00034 00035 /*===========================================================================*\ 00036 * * 00037 * $Revision: 362 $ * 00038 * $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $ * 00039 * * 00040 \*===========================================================================*/ 00041 00042 00043 //============================================================================= 00044 // 00045 // CLASS VectorT 00046 // 00047 //============================================================================= 00048 00049 // Don't parse this header file with doxygen since 00050 // for some reason (obviously due to a bug in doxygen, 00051 // bugreport: https://bugzilla.gnome.org/show_bug.cgi?id=629182) 00052 // macro expansion and preprocessor defines 00053 // don't work properly. 00054 #ifndef DOXYGEN 00055 00056 #ifndef OPENMESH_VECTOR_HH 00057 #define OPENMESH_VECTOR_HH 00058 00059 00060 //== INCLUDES ================================================================= 00061 00062 00063 #include <OpenMesh/Core/System/config.h> 00064 #include <iostream> 00065 #include <assert.h> 00066 #include <math.h> 00067 #include <string.h> 00068 00069 #if defined(__GNUC__) && defined(__SSE__) 00070 #include <xmmintrin.h> 00071 #endif 00072 00073 00074 //== NAMESPACES =============================================================== 00075 00076 00077 namespace OpenMesh { 00078 00079 00080 //== CLASS DEFINITION ========================================================= 00081 00082 00083 00093 template <typename Scalar,int N> struct VectorDataT 00094 { 00095 Scalar values_[N]; 00096 }; 00097 00098 00099 #if defined(__GNUC__) && defined(__SSE__) 00100 00102 template <> struct VectorDataT<float, 4> 00103 { 00104 union 00105 { 00106 __m128 m128; 00107 float values_[4]; 00108 }; 00109 }; 00110 00111 #endif 00112 00113 00114 00115 00116 //== CLASS DEFINITION ========================================================= 00117 00118 00119 #define DIM N 00120 #define TEMPLATE_HEADER template <typename Scalar, int N> 00121 #define CLASSNAME VectorT 00122 #define DERIVED VectorDataT<Scalar,N> 00123 #define unroll(expr) for (int i=0; i<N; ++i) expr(i) 00124 00130 #include "VectorT_inc.hh" 00131 00132 #undef DIM 00133 #undef TEMPLATE_HEADER 00134 #undef CLASSNAME 00135 #undef DERIVED 00136 #undef unroll 00137 00138 00139 00140 00141 //== PARTIAL TEMPLATE SPECIALIZATIONS ========================================= 00142 #if OM_PARTIAL_SPECIALIZATION 00143 00144 00145 #define TEMPLATE_HEADER template <typename Scalar> 00146 #define CLASSNAME VectorT<Scalar,DIM> 00147 #define DERIVED VectorDataT<Scalar,DIM> 00148 00149 00150 #define DIM 2 00151 #define unroll(expr) expr(0) expr(1) 00152 #define unroll_comb(expr, op) expr(0) op expr(1) 00153 #define unroll_csv(expr) expr(0), expr(1) 00154 #include "VectorT_inc.hh" 00155 #undef DIM 00156 #undef unroll 00157 #undef unroll_comb 00158 #undef unroll_csv 00159 00160 00161 #define DIM 3 00162 #define unroll(expr) expr(0) expr(1) expr(2) 00163 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) 00164 #define unroll_csv(expr) expr(0), expr(1), expr(2) 00165 #include "VectorT_inc.hh" 00166 #undef DIM 00167 #undef unroll 00168 #undef unroll_comb 00169 #undef unroll_csv 00170 00171 00172 #define DIM 4 00173 #define unroll(expr) expr(0) expr(1) expr(2) expr(3) 00174 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3) 00175 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3) 00176 #include "VectorT_inc.hh" 00177 #undef DIM 00178 #undef unroll 00179 #undef unroll_comb 00180 #undef unroll_csv 00181 00182 00183 #undef TEMPLATE_HEADER 00184 #undef CLASSNAME 00185 #undef DERIVED 00186 00187 00188 00189 00190 //== FULL TEMPLATE SPECIALIZATIONS ============================================ 00191 #else 00192 00194 template<> 00195 inline VectorT<float,3> 00196 VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const 00197 { 00198 return 00199 VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1], 00200 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2], 00201 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]); 00202 } 00203 00204 00206 template<> 00207 inline VectorT<double,3> 00208 VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const 00209 { 00210 return 00211 VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1], 00212 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2], 00213 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]); 00214 } 00215 00216 #endif 00217 00218 00219 00220 //== GLOBAL FUNCTIONS ========================================================= 00221 00222 00225 template<typename Scalar,int N> 00226 inline VectorT<Scalar,N> operator*(Scalar _s, const VectorT<Scalar,N>& _v) { 00227 return VectorT<Scalar,N>(_v) *= _s; 00228 } 00229 00230 00233 template<typename Scalar, int N> 00234 inline Scalar 00235 dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) { 00236 return (_v1 | _v2); 00237 } 00238 00239 00242 template<typename Scalar, int N> 00243 inline VectorT<Scalar,N> 00244 cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) { 00245 return (_v1 % _v2); 00246 } 00247 00248 00249 00250 00251 //== TYPEDEFS ================================================================= 00252 00254 typedef VectorT<signed char,1> Vec1c; 00256 typedef VectorT<unsigned char,1> Vec1uc; 00258 typedef VectorT<signed short int,1> Vec1s; 00260 typedef VectorT<unsigned short int,1> Vec1us; 00262 typedef VectorT<signed int,1> Vec1i; 00264 typedef VectorT<unsigned int,1> Vec1ui; 00266 typedef VectorT<float,1> Vec1f; 00268 typedef VectorT<double,1> Vec1d; 00269 00271 typedef VectorT<signed char,2> Vec2c; 00273 typedef VectorT<unsigned char,2> Vec2uc; 00275 typedef VectorT<signed short int,2> Vec2s; 00277 typedef VectorT<unsigned short int,2> Vec2us; 00279 typedef VectorT<signed int,2> Vec2i; 00281 typedef VectorT<unsigned int,2> Vec2ui; 00283 typedef VectorT<float,2> Vec2f; 00285 typedef VectorT<double,2> Vec2d; 00286 00288 typedef VectorT<signed char,3> Vec3c; 00290 typedef VectorT<unsigned char,3> Vec3uc; 00292 typedef VectorT<signed short int,3> Vec3s; 00294 typedef VectorT<unsigned short int,3> Vec3us; 00296 typedef VectorT<signed int,3> Vec3i; 00298 typedef VectorT<unsigned int,3> Vec3ui; 00300 typedef VectorT<float,3> Vec3f; 00302 typedef VectorT<double,3> Vec3d; 00303 00305 typedef VectorT<signed char,4> Vec4c; 00307 typedef VectorT<unsigned char,4> Vec4uc; 00309 typedef VectorT<signed short int,4> Vec4s; 00311 typedef VectorT<unsigned short int,4> Vec4us; 00313 typedef VectorT<signed int,4> Vec4i; 00315 typedef VectorT<unsigned int,4> Vec4ui; 00317 typedef VectorT<float,4> Vec4f; 00319 typedef VectorT<double,4> Vec4d; 00320 00322 typedef VectorT<signed char,6> Vec6c; 00324 typedef VectorT<unsigned char,6> Vec6uc; 00326 typedef VectorT<signed short int,6> Vec6s; 00328 typedef VectorT<unsigned short int,6> Vec6us; 00330 typedef VectorT<signed int,6> Vec6i; 00332 typedef VectorT<unsigned int,6> Vec6ui; 00334 typedef VectorT<float,6> Vec6f; 00336 typedef VectorT<double,6> Vec6d; 00337 00338 00339 //============================================================================= 00340 } // namespace OpenMesh 00341 //============================================================================= 00342 #endif // OPENMESH_VECTOR_HH defined 00343 //============================================================================= 00344 #endif // DOXYGEN