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<Vec3i,Vec3f>
120 typedef Vec3i return_type;
122 inline static return_type cast(
const Vec3f& _src)
124 return Vec3i( (
int)(_src[0]* 255.0f + 0.5f),
125 (
int)(_src[1]* 255.0f + 0.5f),
126 (
int)(_src[2]* 255.0f + 0.5f) );
131 struct color_caster<Vec3i,Vec4f>
133 typedef Vec3i return_type;
135 inline static return_type cast(
const Vec4f& _src)
137 return Vec3i( (
int)(_src[0]* 255.0f + 0.5f),
138 (
int)(_src[1]* 255.0f + 0.5f),
139 (
int)(_src[2]* 255.0f + 0.5f) );
144 struct color_caster<Vec4i,Vec4f>
146 typedef Vec4i return_type;
148 inline static return_type cast(
const Vec4f& _src)
150 return Vec4i( (
int)(_src[0]* 255.0f + 0.5f),
151 (
int)(_src[1]* 255.0f + 0.5f),
152 (
int)(_src[2]* 255.0f + 0.5f),
153 (
int)(_src[3]* 255.0f + 0.5f) );
158 struct color_caster<Vec3ui,Vec3f>
160 typedef Vec3ui return_type;
162 inline static return_type cast(
const Vec3f& _src)
164 return Vec3ui( (
unsigned int)(_src[0]* 255.0f + 0.5f),
165 (
unsigned int)(_src[1]* 255.0f + 0.5f),
166 (
unsigned int)(_src[2]* 255.0f + 0.5f) );
171 struct color_caster<Vec3ui,Vec4f>
173 typedef Vec3ui return_type;
175 inline static return_type cast(
const Vec4f& _src)
177 return Vec3ui( (
unsigned int)(_src[0]* 255.0f + 0.5f),
178 (
unsigned int)(_src[1]* 255.0f + 0.5f),
179 (
unsigned int)(_src[2]* 255.0f + 0.5f) );
184 struct color_caster<Vec4ui,Vec4f>
186 typedef Vec4ui return_type;
188 inline static return_type cast(
const Vec4f& _src)
190 return Vec4ui( (
unsigned int)(_src[0]* 255.0f + 0.5f),
191 (
unsigned int)(_src[1]* 255.0f + 0.5f),
192 (
unsigned int)(_src[2]* 255.0f + 0.5f),
193 (
unsigned int)(_src[3]* 255.0f + 0.5f) );
198 struct color_caster<Vec4uc,Vec3f>
200 typedef Vec4uc return_type;
202 inline static return_type cast(
const Vec3f& _src)
204 return Vec4uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
205 (
unsigned char)(_src[1]* 255.0f + 0.5f),
206 (
unsigned char)(_src[2]* 255.0f + 0.5f),
207 (
unsigned char)(255) );
212 struct color_caster<Vec4f,Vec3f>
214 typedef Vec4f return_type;
216 inline static return_type cast(
const Vec3f& _src)
218 return Vec4f( _src[0],
226 struct color_caster<Vec4uc,Vec4f>
228 typedef Vec4uc return_type;
230 inline static return_type cast(
const Vec4f& _src)
232 return Vec4uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
233 (
unsigned char)(_src[1]* 255.0f + 0.5f),
234 (
unsigned char)(_src[2]* 255.0f + 0.5f),
235 (
unsigned char)(_src[3]* 255.0f + 0.5f) );
240 struct color_caster<Vec4f,Vec4i>
242 typedef Vec4f return_type;
244 inline static return_type cast(
const Vec4i& _src)
246 const float f = 1.0f / 255.0f;
247 return Vec4f( _src[0] * f, _src[1] * f, _src[2] * f , _src[3] * f );
252 struct color_caster<Vec4uc,Vec3uc>
254 typedef Vec4uc return_type;
256 inline static return_type cast(
const Vec3uc& _src)
258 return Vec4uc( _src[0], _src[1], _src[2], 255 );
263 struct color_caster<Vec3f, Vec3uc>
265 typedef Vec3f return_type;
267 inline static return_type cast(
const Vec3uc& _src)
269 const float f = 1.0f / 255.0f;
270 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
275 struct color_caster<Vec3f, Vec4uc>
277 typedef Vec3f return_type;
279 inline static return_type cast(
const Vec4uc& _src)
281 const float f = 1.0f / 255.0f;
282 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
287 struct color_caster<Vec4f, Vec3uc>
289 typedef Vec4f return_type;
291 inline static return_type cast(
const Vec3uc& _src)
293 const float f = 1.0f / 255.0f;
294 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, 1.0f );
299 struct color_caster<Vec4f, Vec4uc>
301 typedef Vec4f return_type;
303 inline static return_type cast(
const Vec4uc& _src)
305 const float f = 1.0f / 255.0f;
306 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, _src[3] * f );
313 #ifndef DOXY_IGNORE_THIS
315 #if !defined(OM_CC_MSVC)
316 template <
typename dst_t>
317 struct color_caster<dst_t,dst_t>
319 typedef const dst_t& return_type;
321 inline static return_type cast(
const dst_t& _src)
333 template <
typename dst_t,
typename src_t>
335 typename color_caster<dst_t, src_t>::return_type
336 color_cast(
const src_t& _src )
338 return color_caster<dst_t, src_t>::cast(_src);
350 #endif // OPENMESH_COLOR_CAST_HH defined
void vector_copy(const src_t &_src, dst_t &_dst, GenProg::Int2Type< 1 >)
Cast vector type to another vector type by copying the vector elements.
Definition: vector_cast.hh:82