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_COLOR_CAST_HH
00040 #define OPENMESH_COLOR_CAST_HH
00041
00042
00043
00044
00045
00046 #include <OpenMesh/Core/System/config.hh>
00047 #include <OpenMesh/Core/Utils/vector_cast.hh>
00048
00049
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 }
00146
00147 #endif // OPENMESH_COLOR_CAST_HH defined
00148
00149