Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

VectorT.hh

00001 //=============================================================================
00002 //                                                                            
00003 //                               OpenMesh                                     
00004 //        Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen          
00005 //                           www.openmesh.org                                 
00006 //                                                                            
00007 //-----------------------------------------------------------------------------
00008 //                                                                            
00009 //                                License                                     
00010 //                                                                            
00011 //   This library is free software; you can redistribute it and/or modify it 
00012 //   under the terms of the GNU Library General Public License as published  
00013 //   by the Free Software Foundation, version 2.                             
00014 //                                                                             
00015 //   This library is distributed in the hope that it will be useful, but       
00016 //   WITHOUT ANY WARRANTY; without even the implied warranty of                
00017 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         
00018 //   Library General Public License for more details.                          
00019 //                                                                            
00020 //   You should have received a copy of the GNU Library General Public         
00021 //   License along with this library; if not, write to the Free Software       
00022 //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 
00023 //                                                                            
00024 //-----------------------------------------------------------------------------
00025 //                                                                            
00026 //   $Revision: 1.15 $
00027 //   $Date: 2004/01/08 17:59:26 $
00028 //                                                                            
00029 //=============================================================================
00030 
00031 
00032 //=============================================================================
00033 //
00034 //  CLASS VectorT
00035 //
00036 //=============================================================================
00037 
00038 
00039 #ifndef OPENMESH_VECTOR_HH
00040 #define OPENMESH_VECTOR_HH
00041 
00042 
00043 //== INCLUDES =================================================================
00044 
00045 
00046 #include <OpenMesh/Core/System/config.h>
00047 #include <iostream>
00048 #include <assert.h>
00049 #include <math.h>
00050 
00051 
00052 //== NAMESPACES ===============================================================
00053 
00054 
00055 namespace OpenMesh {
00056 
00057 
00058 //== CLASS DEFINITION =========================================================
00059 
00060 
00061 
00071 template <typename Scalar,int N> struct VectorDataT
00072 {
00073   Scalar values_[N];
00074 };
00075 
00076 
00077 #if defined(OM_CC_GCC)
00078 
00080 template <> struct VectorDataT<float, 4>
00081 {
00082   float values_[4] __attribute__ ((aligned (16)));
00083 };
00084 
00085 #endif
00086 
00087 
00088 
00089 
00090 //== CLASS DEFINITION =========================================================
00091 
00092 
00093 #define DIM               N
00094 #define TEMPLATE_HEADER   template <typename Scalar, int N>
00095 #define CLASSNAME         VectorT
00096 #define DERIVED           VectorDataT<Scalar,N>
00097 #define unroll(expr)      for (int i=0; i<N; ++i) expr(i)
00098 
00104 #include "VectorT_inc.hh"
00105 
00106 #undef  DIM
00107 #undef  TEMPLATE_HEADER
00108 #undef  CLASSNAME
00109 #undef  DERIVED
00110 #undef  unroll
00111 
00112 
00113 
00114 
00115 //== PARTIAL TEMPLATE SPECIALIZATIONS ==========================================
00116 #if OM_PARTIAL_SPECIALIZATION
00117 
00118 
00119 #define TEMPLATE_HEADER        template <typename Scalar>
00120 #define CLASSNAME              VectorT<Scalar,DIM> 
00121 #define DERIVED                VectorDataT<Scalar,DIM>
00122 
00123 
00124 #define DIM                    2
00125 #define unroll(expr)           expr(0) expr(1)
00126 #define unroll_comb(expr, op)  expr(0) op expr(1)
00127 #define unroll_csv(expr)       expr(0), expr(1)
00128 #include "VectorT_inc.hh"
00129 #undef  DIM
00130 #undef  unroll
00131 #undef  unroll_comb
00132 #undef  unroll_csv
00133 
00134 
00135 #define DIM                    3
00136 #define unroll(expr)           expr(0) expr(1) expr(2)
00137 #define unroll_comb(expr, op)  expr(0) op expr(1) op expr(2)
00138 #define unroll_csv(expr)       expr(0), expr(1), expr(2)
00139 #include "VectorT_inc.hh"
00140 #undef  DIM
00141 #undef  unroll
00142 #undef  unroll_comb
00143 #undef  unroll_csv
00144 
00145 
00146 #define DIM                    4
00147 #define unroll(expr)           expr(0) expr(1) expr(2) expr(3)
00148 #define unroll_comb(expr, op)  expr(0) op expr(1) op expr(2) op expr(3)
00149 #define unroll_csv(expr)       expr(0), expr(1), expr(2), expr(2)
00150 #include "VectorT_inc.hh"
00151 #undef  DIM
00152 #undef  unroll
00153 #undef  unroll_comb
00154 #undef  unroll_csv
00155 
00156 
00157 #undef  TEMPLATE_HEADER
00158 #undef  CLASSNAME
00159 #undef  DERIVED
00160 
00161 
00162 
00163 
00164 //== FULL TEMPLATE SPECIALIZATIONS =============================================
00165 #else
00166 
00167 #  ifndef DOXY_IGNORE_THIS
00168 
00170 template<>
00171 inline VectorT<float,3>
00172 VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const 
00173 {
00174    return 
00175      VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
00176                       values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
00177                       values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
00178 }
00179   
00180 
00182 template<>
00183 inline VectorT<double,3>
00184 VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const
00185 {
00186  return 
00187    VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
00188                      values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
00189                      values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
00190 }
00191 
00192 #  endif // DOXY_IGNORE_THIS
00193 
00194 #endif
00195 
00196 
00197 
00198 
00199 //== GLOBAL FUNCTIONS =========================================================
00200 
00201 
00204 template<typename Scalar,int N>
00205 inline VectorT<Scalar,N> operator*(Scalar _s, const VectorT<Scalar,N>& _v) {
00206   return VectorT<Scalar,N>(_v) *= _s;
00207 }
00208 
00209 
00212 template<typename Scalar, int N>
00213 inline Scalar 
00214 dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
00215   return (_v1 | _v2); 
00216 }
00217 
00218 
00221 template<typename Scalar, int N>
00222 inline VectorT<Scalar,N> 
00223 cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
00224   return (_v1 % _v2);
00225 }
00226 
00227 
00228 
00229 
00230 //== TYPEDEFS =================================================================
00231 
00233 typedef VectorT<signed char,1> Vec1c;
00235 typedef VectorT<unsigned char,1> Vec1uc;
00237 typedef VectorT<signed short int,1> Vec1s;
00239 typedef VectorT<unsigned short int,1> Vec1us;
00241 typedef VectorT<signed int,1> Vec1i;
00243 typedef VectorT<unsigned int,1> Vec1ui;
00245 typedef VectorT<float,1> Vec1f;
00247 typedef VectorT<double,1> Vec1d;
00248 
00250 typedef VectorT<signed char,2> Vec2c;
00252 typedef VectorT<unsigned char,2> Vec2uc;
00254 typedef VectorT<signed short int,2> Vec2s;
00256 typedef VectorT<unsigned short int,2> Vec2us;
00258 typedef VectorT<signed int,2> Vec2i;
00260 typedef VectorT<unsigned int,2> Vec2ui;
00262 typedef VectorT<float,2> Vec2f;
00264 typedef VectorT<double,2> Vec2d;
00265 
00267 typedef VectorT<signed char,3> Vec3c;
00269 typedef VectorT<unsigned char,3> Vec3uc;
00271 typedef VectorT<signed short int,3> Vec3s;
00273 typedef VectorT<unsigned short int,3> Vec3us;
00275 typedef VectorT<signed int,3> Vec3i;
00277 typedef VectorT<unsigned int,3> Vec3ui;
00279 typedef VectorT<float,3> Vec3f;
00281 typedef VectorT<double,3> Vec3d;
00282 
00284 typedef VectorT<signed char,4> Vec4c;
00286 typedef VectorT<unsigned char,4> Vec4uc;
00288 typedef VectorT<signed short int,4> Vec4s;
00290 typedef VectorT<unsigned short int,4> Vec4us;
00292 typedef VectorT<signed int,4> Vec4i;
00294 typedef VectorT<unsigned int,4> Vec4ui;
00296 typedef VectorT<float,4> Vec4f;
00298 typedef VectorT<double,4> Vec4d;
00299 
00301 typedef VectorT<signed char,6> Vec6c;
00303 typedef VectorT<unsigned char,6> Vec6uc;
00305 typedef VectorT<signed short int,6> Vec6s;
00307 typedef VectorT<unsigned short int,6> Vec6us;
00309 typedef VectorT<signed int,6> Vec6i;
00311 typedef VectorT<unsigned int,6> Vec6ui;
00313 typedef VectorT<float,6> Vec6f;
00315 typedef VectorT<double,6> Vec6d;
00316 
00317 
00318 //=============================================================================
00319 } // namespace OpenMesh
00320 //=============================================================================
00321 #endif // OPENMESH_VECTOR_HH defined
00322 //=============================================================================

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .