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 // Helper Functions for binary reading / writing 00046 // 00047 //============================================================================= 00048 00049 00050 #ifndef OPENMESH_VECTORCAST_HH 00051 #define OPENMESH_VECTORCAST_HH 00052 00053 00054 //== INCLUDES ================================================================= 00055 00056 00057 #include <OpenMesh/Core/System/config.h> 00058 #include <OpenMesh/Core/Utils/vector_traits.hh> 00059 #include <OpenMesh/Core/Utils/GenProg.hh> 00060 #include <iostream> 00061 #include <algorithm> 00062 #include <OpenMesh/Core/Geometry/VectorT.hh> 00063 00064 00065 //== NAMESPACES =============================================================== 00066 00067 00068 namespace OpenMesh { 00069 00070 00071 //============================================================================= 00072 00073 00077 00078 //----------------------------------------------------------------------------- 00079 00080 00081 template <typename src_t, typename dst_t> 00082 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<1> ) 00083 { 00084 _dst[0] = _src[0]; 00085 } 00086 00087 template <typename src_t, typename dst_t> 00088 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<2> ) 00089 { 00090 _dst[0] = _src[0]; 00091 _dst[1] = _src[1]; 00092 } 00093 00094 template <typename src_t, typename dst_t> 00095 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<3> ) 00096 { 00097 _dst[0] = _src[0]; 00098 _dst[1] = _src[1]; 00099 _dst[2] = _src[2]; 00100 } 00101 00102 template <typename src_t, typename dst_t> 00103 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<4> ) 00104 { 00105 _dst[0] = _src[0]; 00106 _dst[1] = _src[1]; 00107 _dst[2] = _src[2]; 00108 _dst[3] = _src[3]; 00109 } 00110 00111 template <typename src_t, typename dst_t> 00112 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<5> ) 00113 { 00114 _dst[0] = _src[0]; 00115 _dst[1] = _src[1]; 00116 _dst[2] = _src[2]; 00117 _dst[3] = _src[3]; 00118 _dst[4] = _src[4]; 00119 } 00120 00121 template <typename src_t, typename dst_t> 00122 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<6> ) 00123 { 00124 _dst[0] = _src[0]; 00125 _dst[1] = _src[1]; 00126 _dst[2] = _src[2]; 00127 _dst[3] = _src[3]; 00128 _dst[4] = _src[4]; 00129 _dst[5] = _src[5]; 00130 } 00131 00132 00133 //----------------------------------------------------------------------------- 00134 #ifndef DOXY_IGNORE_THIS 00135 00136 template <typename dst_t, typename src_t> 00137 struct vector_caster 00138 { 00139 typedef dst_t return_type; 00140 00141 inline static return_type cast(const src_t& _src) 00142 { 00143 dst_t dst; 00144 vector_copy(_src, dst, GenProg::Int2Type<vector_traits<dst_t>::size_>()); 00145 return dst; 00146 } 00147 }; 00148 00149 #if !defined(OM_CC_MSVC) 00150 template <typename dst_t> 00151 struct vector_caster<dst_t,dst_t> 00152 { 00153 typedef const dst_t& return_type; 00154 00155 inline static return_type cast(const dst_t& _src) 00156 { 00157 return _src; 00158 } 00159 }; 00160 #endif 00161 00162 #endif 00163 //----------------------------------------------------------------------------- 00164 00165 00167 template <typename dst_t, typename src_t> 00168 inline 00169 typename vector_caster<dst_t, src_t>::return_type 00170 vector_cast(const src_t& _src ) 00171 { 00172 return vector_caster<dst_t, src_t>::cast(_src); 00173 } 00174 00175 00177 00178 00179 //============================================================================= 00180 } // namespace OpenMesh 00181 //============================================================================= 00182 #endif // OPENMESH_MESHREADER_HH defined 00183 //=============================================================================