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
79template <
typename dst_t,
typename src_t>
82 typedef dst_t return_type;
84 inline static return_type cast(
const src_t& _src)
87 vector_cast(_src, dst, GenProg::Int2Type<vector_traits<dst_t>::size_>());
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 Vec4ui return_type;
218 inline static return_type cast(
const Vec3f& _src)
220 return Vec4ui( (
unsigned int)(_src[0]* 255.0f + 0.5f),
221 (
unsigned int)(_src[1]* 255.0f + 0.5f),
222 (
unsigned int)(_src[2]* 255.0f + 0.5f),
223 (
unsigned int)(255) );
230 typedef Vec4f return_type;
232 inline static return_type cast(
const Vec3f& _src)
234 return Vec4f( _src[0],
244 typedef Vec4ui return_type;
246 inline static return_type cast(
const Vec3uc& _src)
258 typedef Vec4f return_type;
260 inline static return_type cast(
const Vec3i& _src)
262 const float f = 1.0f / 255.0f;
263 return Vec4f(_src[0]*f, _src[1]*f, _src[2]*f, 1.0f );
270 typedef Vec4uc return_type;
272 inline static return_type cast(
const Vec4f& _src)
274 return Vec4uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
275 (
unsigned char)(_src[1]* 255.0f + 0.5f),
276 (
unsigned char)(_src[2]* 255.0f + 0.5f),
277 (
unsigned char)(_src[3]* 255.0f + 0.5f) );
284 typedef Vec4f return_type;
286 inline static return_type cast(
const Vec4i& _src)
288 const float f = 1.0f / 255.0f;
289 return Vec4f( _src[0] * f, _src[1] * f, _src[2] * f , _src[3] * f );
296 typedef Vec4uc return_type;
298 inline static return_type cast(
const Vec3uc& _src)
300 return Vec4uc( _src[0], _src[1], _src[2], 255 );
307 typedef Vec3f return_type;
309 inline static return_type cast(
const Vec3uc& _src)
311 const float f = 1.0f / 255.0f;
312 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
319 typedef Vec3f return_type;
321 inline static return_type cast(
const Vec4uc& _src)
323 const float f = 1.0f / 255.0f;
324 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
331 typedef Vec4f return_type;
333 inline static return_type cast(
const Vec3uc& _src)
335 const float f = 1.0f / 255.0f;
336 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, 1.0f );
343 typedef Vec4f return_type;
345 inline static return_type cast(
const Vec4uc& _src)
347 const float f = 1.0f / 255.0f;
348 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, _src[3] * f );
355#ifndef DOXY_IGNORE_THIS
357#if !defined(OM_CC_MSVC)
358template <
typename dst_t>
359struct color_caster<dst_t,dst_t>
361 typedef const dst_t& return_type;
363 inline static return_type cast(
const dst_t& _src)
375template <
typename dst_t,
typename src_t>
377typename color_caster<dst_t, src_t>::return_type
378color_cast(
const src_t& _src )
380 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:868
VectorT< unsigned char, 3 > Vec3uc
3-byte unsigned vector
Definition Vector11T.hh:841
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:866
VectorT< float, 4 > Vec4f
4-float vector
Definition Vector11T.hh:870
VectorT< unsigned char, 4 > Vec4uc
4-byte unsigned vector
Definition Vector11T.hh:860
VectorT< unsigned int, 3 > Vec3ui
3-int unsigned vector
Definition Vector11T.hh:849
VectorT< float, 3 > Vec3f
3-float vector
Definition Vector11T.hh:851
VectorT< signed int, 3 > Vec3i
3-int signed vector
Definition Vector11T.hh:847