50 #ifndef OPENMESH_COLOR_CAST_HH
51 #define OPENMESH_COLOR_CAST_HH
57 #include <OpenMesh/Core/System/config.h>
58 #include <OpenMesh/Core/Utils/vector_cast.hh>
74 #ifndef DOXY_IGNORE_THIS
77 template <
typename dst_t,
typename src_t>
80 typedef dst_t return_type;
82 inline static return_type cast(
const src_t& _src)
85 vector_copy(_src, dst, GenProg::Int2Type<vector_traits<dst_t>::size_>());
92 struct color_caster<Vec3uc,Vec3f>
94 typedef Vec3uc return_type;
96 inline static return_type cast(
const Vec3f& _src)
98 return Vec3uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
99 (
unsigned char)(_src[1]* 255.0f + 0.5f),
100 (
unsigned char)(_src[2]* 255.0f + 0.5f) );
105 struct color_caster<Vec3uc,Vec4f>
107 typedef Vec3uc return_type;
109 inline static return_type cast(
const Vec4f& _src)
111 return Vec3uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
112 (
unsigned char)(_src[1]* 255.0f + 0.5f),
113 (
unsigned char)(_src[2]* 255.0f + 0.5f) );
118 struct color_caster<Vec4uc,Vec3f>
120 typedef Vec4uc return_type;
122 inline static return_type cast(
const Vec3f& _src)
124 return Vec4uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
125 (
unsigned char)(_src[1]* 255.0f + 0.5f),
126 (
unsigned char)(_src[2]* 255.0f + 0.5f),
127 (
unsigned char)(255) );
132 struct color_caster<Vec4f,Vec3f>
134 typedef Vec4f return_type;
136 inline static return_type cast(
const Vec3f& _src)
138 return Vec4f( _src[0],
146 struct color_caster<Vec4uc,Vec4f>
148 typedef Vec4uc return_type;
150 inline static return_type cast(
const Vec4f& _src)
152 return Vec4uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
153 (
unsigned char)(_src[1]* 255.0f + 0.5f),
154 (
unsigned char)(_src[2]* 255.0f + 0.5f),
155 (
unsigned char)(_src[3]* 255.0f + 0.5f) );
160 struct color_caster<Vec4f,Vec4i>
162 typedef Vec4f return_type;
164 inline static return_type cast(
const Vec4i& _src)
166 const float f = 1.0f / 255.0f;
167 return Vec4f( _src[0] * f, _src[1] * f, _src[2] * f , _src[3] * f );
172 struct color_caster<Vec4uc,Vec3uc>
174 typedef Vec4uc return_type;
176 inline static return_type cast(
const Vec3uc& _src)
178 return Vec4uc( _src[0], _src[1], _src[2], 255 );
183 struct color_caster<Vec3f, Vec3uc>
185 typedef Vec3f return_type;
187 inline static return_type cast(
const Vec3uc& _src)
189 const float f = 1.0f / 255.0f;
190 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
195 struct color_caster<Vec3f, Vec4uc>
197 typedef Vec3f return_type;
199 inline static return_type cast(
const Vec4uc& _src)
201 const float f = 1.0f / 255.0f;
202 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
207 struct color_caster<Vec4f, Vec3uc>
209 typedef Vec4f return_type;
211 inline static return_type cast(
const Vec3uc& _src)
213 const float f = 1.0f / 255.0f;
214 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, 1.0f );
219 struct color_caster<Vec4f, Vec4uc>
221 typedef Vec4f return_type;
223 inline static return_type cast(
const Vec4uc& _src)
225 const float f = 1.0f / 255.0f;
226 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, _src[3] * f );
233 #ifndef DOXY_IGNORE_THIS
235 #if !defined(OM_CC_MSVC)
236 template <
typename dst_t>
237 struct color_caster<dst_t,dst_t>
239 typedef const dst_t& return_type;
241 inline static return_type cast(
const dst_t& _src)
253 template <
typename dst_t,
typename src_t>
255 typename color_caster<dst_t, src_t>::return_type
256 color_cast(
const src_t& _src )
258 return color_caster<dst_t, src_t>::cast(_src);
270 #endif // OPENMESH_COLOR_CAST_HH defined