57 #ifndef OPENMESH_COLOR_CAST_HH 58 #define OPENMESH_COLOR_CAST_HH 64 #include <OpenMesh/Core/System/config.h> 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)
99 struct color_caster<Vec3uc,Vec3f>
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) );
112 struct color_caster<Vec3uc,Vec4f>
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) );
125 struct color_caster<Vec3i,Vec3f>
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) );
138 struct color_caster<Vec3i,Vec4f>
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) );
151 struct color_caster<Vec4i,Vec4f>
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) );
165 struct color_caster<Vec3ui,Vec3f>
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) );
178 struct color_caster<Vec3ui,Vec4f>
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) );
191 struct color_caster<Vec4ui,Vec4f>
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) );
205 struct color_caster<Vec4uc,Vec3f>
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) );
219 struct color_caster<Vec4f,Vec3f>
221 typedef Vec4f return_type;
223 inline static return_type cast(
const Vec3f& _src)
225 return Vec4f( _src[0],
233 struct color_caster<Vec4ui,Vec3uc>
235 typedef Vec4ui return_type;
237 inline static return_type cast(
const Vec3uc& _src)
239 return Vec4ui(_src[0],
247 struct color_caster<Vec4f,Vec3i>
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 );
259 struct color_caster<Vec4uc,Vec4f>
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) );
273 struct color_caster<Vec4f,Vec4i>
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 );
285 struct color_caster<Vec4uc,Vec3uc>
287 typedef Vec4uc return_type;
289 inline static return_type cast(
const Vec3uc& _src)
291 return Vec4uc( _src[0], _src[1], _src[2], 255 );
296 struct color_caster<Vec3f, Vec3uc>
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 );
308 struct color_caster<Vec3f, Vec4uc>
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 );
320 struct color_caster<Vec4f, Vec3uc>
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 );
332 struct color_caster<Vec4f, Vec4uc>
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 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.
Definition: vector_cast.hh:86
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
static const size_t size_
size/dimension of the vector
Definition: vector_traits.hh:102