52 #ifndef OPENMESH_COLOR_CAST_HH
53 #define OPENMESH_COLOR_CAST_HH
59 #include <OpenMesh/Core/System/config.h>
60 #include <OpenMesh/Core/Utils/vector_cast.hh>
76 #ifndef DOXY_IGNORE_THIS
79 template <
typename dst_t,
typename src_t>
82 typedef dst_t return_type;
84 inline static return_type cast(
const src_t& _src)
96 typedef Vec3uc return_type;
98 inline static return_type cast(
const Vec3f& _src)
100 return Vec3uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
101 (
unsigned char)(_src[1]* 255.0f + 0.5f),
102 (
unsigned char)(_src[2]* 255.0f + 0.5f) );
109 typedef Vec3uc return_type;
111 inline static return_type cast(
const Vec4f& _src)
113 return Vec3uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
114 (
unsigned char)(_src[1]* 255.0f + 0.5f),
115 (
unsigned char)(_src[2]* 255.0f + 0.5f) );
122 typedef Vec3i return_type;
124 inline static return_type cast(
const Vec3f& _src)
126 return Vec3i( (
int)(_src[0]* 255.0f + 0.5f),
127 (
int)(_src[1]* 255.0f + 0.5f),
128 (
int)(_src[2]* 255.0f + 0.5f) );
135 typedef Vec3i return_type;
137 inline static return_type cast(
const Vec4f& _src)
139 return Vec3i( (
int)(_src[0]* 255.0f + 0.5f),
140 (
int)(_src[1]* 255.0f + 0.5f),
141 (
int)(_src[2]* 255.0f + 0.5f) );
148 typedef Vec4i return_type;
150 inline static return_type cast(
const Vec4f& _src)
152 return Vec4i( (
int)(_src[0]* 255.0f + 0.5f),
153 (
int)(_src[1]* 255.0f + 0.5f),
154 (
int)(_src[2]* 255.0f + 0.5f),
155 (
int)(_src[3]* 255.0f + 0.5f) );
162 typedef Vec3ui return_type;
164 inline static return_type cast(
const Vec3f& _src)
166 return Vec3ui( (
unsigned int)(_src[0]* 255.0f + 0.5f),
167 (
unsigned int)(_src[1]* 255.0f + 0.5f),
168 (
unsigned int)(_src[2]* 255.0f + 0.5f) );
175 typedef Vec3ui return_type;
177 inline static return_type cast(
const Vec4f& _src)
179 return Vec3ui( (
unsigned int)(_src[0]* 255.0f + 0.5f),
180 (
unsigned int)(_src[1]* 255.0f + 0.5f),
181 (
unsigned int)(_src[2]* 255.0f + 0.5f) );
188 typedef Vec4ui return_type;
190 inline static return_type cast(
const Vec4f& _src)
192 return Vec4ui( (
unsigned int)(_src[0]* 255.0f + 0.5f),
193 (
unsigned int)(_src[1]* 255.0f + 0.5f),
194 (
unsigned int)(_src[2]* 255.0f + 0.5f),
195 (
unsigned int)(_src[3]* 255.0f + 0.5f) );
202 typedef Vec4uc return_type;
204 inline static return_type cast(
const Vec3f& _src)
206 return Vec4uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
207 (
unsigned char)(_src[1]* 255.0f + 0.5f),
208 (
unsigned char)(_src[2]* 255.0f + 0.5f),
209 (
unsigned char)(255) );
216 typedef Vec4f return_type;
218 inline static return_type cast(
const Vec3f& _src)
220 return Vec4f( _src[0],
230 typedef Vec4ui return_type;
232 inline static return_type cast(
const Vec3uc& _src)
244 typedef Vec4f return_type;
246 inline static return_type cast(
const Vec3i& _src)
248 const float f = 1.0f / 255.0f;
249 return Vec4f(_src[0]*f, _src[1]*f, _src[2]*f, 1.0f );
256 typedef Vec4uc return_type;
258 inline static return_type cast(
const Vec4f& _src)
260 return Vec4uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
261 (
unsigned char)(_src[1]* 255.0f + 0.5f),
262 (
unsigned char)(_src[2]* 255.0f + 0.5f),
263 (
unsigned char)(_src[3]* 255.0f + 0.5f) );
270 typedef Vec4f return_type;
272 inline static return_type cast(
const Vec4i& _src)
274 const float f = 1.0f / 255.0f;
275 return Vec4f( _src[0] * f, _src[1] * f, _src[2] * f , _src[3] * f );
282 typedef Vec4uc return_type;
284 inline static return_type cast(
const Vec3uc& _src)
286 return Vec4uc( _src[0], _src[1], _src[2], 255 );
293 typedef Vec3f return_type;
295 inline static return_type cast(
const Vec3uc& _src)
297 const float f = 1.0f / 255.0f;
298 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
305 typedef Vec3f return_type;
307 inline static return_type cast(
const Vec4uc& _src)
309 const float f = 1.0f / 255.0f;
310 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
317 typedef Vec4f return_type;
319 inline static return_type cast(
const Vec3uc& _src)
321 const float f = 1.0f / 255.0f;
322 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, 1.0f );
329 typedef Vec4f return_type;
331 inline static return_type cast(
const Vec4uc& _src)
333 const float f = 1.0f / 255.0f;
334 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, _src[3] * f );
341 #ifndef DOXY_IGNORE_THIS
343 #if !defined(OM_CC_MSVC)
344 template <
typename dst_t>
345 struct color_caster<dst_t,dst_t>
347 typedef const dst_t& return_type;
349 inline static return_type cast(
const dst_t& _src)
361 template <
typename dst_t,
typename src_t>
363 typename color_caster<dst_t, src_t>::return_type
364 color_cast(
const src_t& _src )
366 return color_caster<dst_t, src_t>::cast(_src);
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
VectorT< unsigned int, 4 > Vec4ui
4-int unsigned vector
Definition: Vector11T.hh:867
VectorT< unsigned char, 3 > Vec3uc
3-byte unsigned vector
Definition: Vector11T.hh:840
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:81
VectorT< signed int, 4 > Vec4i
4-int signed vector
Definition: Vector11T.hh:865
VectorT< float, 4 > Vec4f
4-float vector
Definition: Vector11T.hh:869
VectorT< unsigned char, 4 > Vec4uc
4-byte unsigned vector
Definition: Vector11T.hh:859
VectorT< unsigned int, 3 > Vec3ui
3-int unsigned vector
Definition: Vector11T.hh:848
VectorT< float, 3 > Vec3f
3-float vector
Definition: Vector11T.hh:850
VectorT< signed int, 3 > Vec3i
3-int signed vector
Definition: Vector11T.hh:846
static const size_t size_
size/dimension of the vector
Definition: vector_traits.hh:97