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

color_cast.hh

00001 //=============================================================================
00002 //                                                                            
00003 //                               OpenMesh                                     
00004 //      Copyright (C) 2001-2005 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.1.1.1 $
00027 //   $Date: 2004/09/06 12:35:36 $
00028 //                                                                            
00029 //=============================================================================
00030 
00031 
00032 //=============================================================================
00033 //
00034 //  Helper Functions for binary reading / writing
00035 //
00036 //=============================================================================
00037 
00038 
00039 #ifndef OPENMESH_COLOR_CAST_HH
00040 #define OPENMESH_COLOR_CAST_HH
00041 
00042 
00043 //== INCLUDES =================================================================
00044 
00045 
00046 #include <OpenMesh/Core/System/config.hh>
00047 #include <OpenMesh/Core/Utils/vector_cast.hh>
00048 
00049 //== NAMESPACES ===============================================================
00050 
00051 
00052 namespace OpenMesh {
00053 
00054 
00055 //=============================================================================
00056 
00057 
00061 
00062 //-----------------------------------------------------------------------------
00063 #ifndef DOXY_IGNORE_THIS
00064 
00066 template <typename dst_t, typename src_t>
00067 struct color_caster
00068 {
00069   typedef dst_t  return_type;
00070 
00071   inline static return_type cast(const src_t& _src)
00072   {
00073     dst_t dst;
00074     vector_copy(_src, dst, GenProg::Int2Type<vector_traits<dst_t>::size_>());
00075     return dst;
00076   }
00077 };
00078 
00079 
00080 template <>
00081 struct color_caster<Vec3uc,Vec3f>
00082 {
00083   typedef Vec3uc return_type;
00084 
00085   inline static return_type cast(const Vec3f& _src)
00086   {
00087     return Vec3uc( (unsigned char)(_src[0]* 255.0f + 0.5f),
00088                    (unsigned char)(_src[1]* 255.0f + 0.5f),
00089                    (unsigned char)(_src[2]* 255.0f + 0.5f) );
00090   }
00091 };
00092 
00093 
00094 template <>
00095 struct color_caster<Vec3f, Vec3uc>
00096 {
00097   typedef Vec3f return_type;
00098 
00099   inline static return_type cast(const Vec3uc& _src)
00100   {
00101     const float f = 1.0f / 255.0f;
00102     return Vec3f(_src[0] * f, _src[1] *  f, _src[2] * f );
00103   }
00104 };
00105 
00106 
00107 // ----------------------------------------------------------------------------
00108 
00109 
00110 #ifndef DOXY_IGNORE_THIS
00111 
00112 #if !defined(OM_CC_MSVC)
00113 template <typename dst_t>
00114 struct color_caster<dst_t,dst_t>
00115 {
00116   typedef const dst_t&  return_type;
00117 
00118   inline static return_type cast(const dst_t& _src)
00119   {
00120     return _src;
00121   }
00122 };
00123 #endif
00124 
00125 #endif
00126 
00127 //-----------------------------------------------------------------------------
00128 
00129 
00130 template <typename dst_t, typename src_t>
00131 inline
00132 typename color_caster<dst_t, src_t>::return_type
00133 color_cast(const src_t& _src )
00134 {
00135   return color_caster<dst_t, src_t>::cast(_src);
00136 }
00137 
00138 #endif
00139 //-----------------------------------------------------------------------------
00140 
00142 
00143 
00144 //=============================================================================
00145 } // namespace OpenMesh
00146 //=============================================================================
00147 #endif // OPENMESH_COLOR_CAST_HH defined
00148 //=============================================================================
00149 

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