57 #ifndef OPENMESH_COLOR_CAST_HH 58 #define OPENMESH_COLOR_CAST_HH 65 #include <OpenMesh/Core/Utils/vector_cast.hh> 81 #ifndef DOXY_IGNORE_THIS 84 template <
typename dst_t,
typename src_t>
87 typedef dst_t return_type;
89 inline static return_type cast(
const src_t& _src)
101 typedef Vec3uc return_type;
103 inline static return_type cast(
const Vec3f& _src)
105 return Vec3uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
106 (
unsigned char)(_src[1]* 255.0f + 0.5f),
107 (
unsigned char)(_src[2]* 255.0f + 0.5f) );
114 typedef Vec3uc return_type;
116 inline static return_type cast(
const Vec4f& _src)
118 return Vec3uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
119 (
unsigned char)(_src[1]* 255.0f + 0.5f),
120 (
unsigned char)(_src[2]* 255.0f + 0.5f) );
127 typedef Vec3i return_type;
129 inline static return_type cast(
const Vec3f& _src)
131 return Vec3i( (
int)(_src[0]* 255.0f + 0.5f),
132 (
int)(_src[1]* 255.0f + 0.5f),
133 (
int)(_src[2]* 255.0f + 0.5f) );
140 typedef Vec3i return_type;
142 inline static return_type cast(
const Vec4f& _src)
144 return Vec3i( (
int)(_src[0]* 255.0f + 0.5f),
145 (
int)(_src[1]* 255.0f + 0.5f),
146 (
int)(_src[2]* 255.0f + 0.5f) );
153 typedef Vec4i return_type;
155 inline static return_type cast(
const Vec4f& _src)
157 return Vec4i( (
int)(_src[0]* 255.0f + 0.5f),
158 (
int)(_src[1]* 255.0f + 0.5f),
159 (
int)(_src[2]* 255.0f + 0.5f),
160 (
int)(_src[3]* 255.0f + 0.5f) );
167 typedef Vec3ui return_type;
169 inline static return_type cast(
const Vec3f& _src)
171 return Vec3ui( (
unsigned int)(_src[0]* 255.0f + 0.5f),
172 (
unsigned int)(_src[1]* 255.0f + 0.5f),
173 (
unsigned int)(_src[2]* 255.0f + 0.5f) );
180 typedef Vec3ui return_type;
182 inline static return_type cast(
const Vec4f& _src)
184 return Vec3ui( (
unsigned int)(_src[0]* 255.0f + 0.5f),
185 (
unsigned int)(_src[1]* 255.0f + 0.5f),
186 (
unsigned int)(_src[2]* 255.0f + 0.5f) );
193 typedef Vec4ui return_type;
195 inline static return_type cast(
const Vec4f& _src)
197 return Vec4ui( (
unsigned int)(_src[0]* 255.0f + 0.5f),
198 (
unsigned int)(_src[1]* 255.0f + 0.5f),
199 (
unsigned int)(_src[2]* 255.0f + 0.5f),
200 (
unsigned int)(_src[3]* 255.0f + 0.5f) );
207 typedef Vec4uc return_type;
209 inline static return_type cast(
const Vec3f& _src)
211 return Vec4uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
212 (
unsigned char)(_src[1]* 255.0f + 0.5f),
213 (
unsigned char)(_src[2]* 255.0f + 0.5f),
214 (
unsigned char)(255) );
221 typedef Vec4f return_type;
223 inline static return_type cast(
const Vec3f& _src)
225 return Vec4f( _src[0],
235 typedef Vec4ui return_type;
237 inline static return_type cast(
const Vec3uc& _src)
249 typedef Vec4f return_type;
251 inline static return_type cast(
const Vec3i& _src)
253 const float f = 1.0f / 255.0f;
254 return Vec4f(_src[0]*f, _src[1]*f, _src[2]*f, 1.0f );
261 typedef Vec4uc return_type;
263 inline static return_type cast(
const Vec4f& _src)
265 return Vec4uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
266 (
unsigned char)(_src[1]* 255.0f + 0.5f),
267 (
unsigned char)(_src[2]* 255.0f + 0.5f),
268 (
unsigned char)(_src[3]* 255.0f + 0.5f) );
275 typedef Vec4f return_type;
277 inline static return_type cast(
const Vec4i& _src)
279 const float f = 1.0f / 255.0f;
280 return Vec4f( _src[0] * f, _src[1] * f, _src[2] * f , _src[3] * f );
287 typedef Vec4uc return_type;
289 inline static return_type cast(
const Vec3uc& _src)
291 return Vec4uc( _src[0], _src[1], _src[2], 255 );
298 typedef Vec3f return_type;
300 inline static return_type cast(
const Vec3uc& _src)
302 const float f = 1.0f / 255.0f;
303 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
310 typedef Vec3f return_type;
312 inline static return_type cast(
const Vec4uc& _src)
314 const float f = 1.0f / 255.0f;
315 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
322 typedef Vec4f return_type;
324 inline static return_type cast(
const Vec3uc& _src)
326 const float f = 1.0f / 255.0f;
327 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, 1.0f );
334 typedef Vec4f return_type;
336 inline static return_type cast(
const Vec4uc& _src)
338 const float f = 1.0f / 255.0f;
339 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, _src[3] * f );
346 #ifndef DOXY_IGNORE_THIS 348 #if !defined(OM_CC_MSVC) 349 template <
typename dst_t>
350 struct color_caster<dst_t,dst_t>
352 typedef const dst_t& return_type;
354 inline static return_type cast(
const dst_t& _src)
366 template <
typename dst_t,
typename src_t>
368 typename color_caster<dst_t, src_t>::return_type
369 color_cast(
const src_t& _src )
371 return color_caster<dst_t, src_t>::cast(_src);
383 #endif // OPENMESH_COLOR_CAST_HH defined
VectorT< unsigned int, 4 > Vec4ui
void vector_cast(const src_t &_src, dst_t &_dst, GenProg::Int2Type< n >)
Cast vector type to another vector type by copying the vector elements.
VectorT< float, 4 > Vec4f
VectorT< signed int, 4 > Vec4i
VectorT< unsigned char, 4 > Vec4uc
VectorT< float, 3 > Vec3f
VectorT< unsigned int, 3 > Vec3ui
static const size_t size_
size/dimension of the vector
VectorT< signed int, 3 > Vec3i
VectorT< unsigned char, 3 > Vec3uc