19 color_map(std::map<float, float3>
map,
int steps = 4000) : _map(map)
26 for (
size_t i = 0;
i < values.size();
i++)
28 _map[(float)
i / (values.size() - 1)] = values[
i];
37 if (_max == _min)
return *_data;
38 auto t = (
value - _min) / (_max - _min);
40 return _data[(int)(
t * (_size - 1))];
46 const std::vector<float3>&
get_cache()
const {
return _cache; }
51 return b * t + a * (1 -
t);
56 if (_map.size() == 0)
return{
value,
value, value };
58 if (_map.find(value) != _map.end())
return _map.at(value);
60 if (value < _map.begin()->first)
return _map.begin()->second;
61 if (value > _map.rbegin()->first)
return _map.rbegin()->second;
63 auto lower = _map.lower_bound(value) == _map.begin() ? _map.begin() : --(_map.lower_bound(value));
64 auto upper = _map.upper_bound(value);
66 auto t = (value - lower->first) / (upper->first - lower->first);
67 auto c1 = lower->second;
68 auto c2 = upper->second;
69 return lerp(c1, c2,
t);
74 if (_map.size() == 0)
return;
76 _min = _map.begin()->first;
77 _max = _map.rbegin()->first;
79 _cache.resize(steps + 1);
80 for (
int i = 0;
i <= steps;
i++)
82 auto t = (float)
i / steps;
83 auto x = _min +
t*(_max - _min);
88 _size = _cache.size();
89 _data = _cache.data();
92 std::map<float, float3>
_map;
106 memset(hist, 0, MAX_DEPTH *
sizeof(
int));
107 for (
auto i = 0;
i < w*
h; ++
i)
109 T depth_val = depth_data[
i];
110 int index =
static_cast< int >( depth_val );
114 for (
auto i = 2;
i < MAX_DEPTH; ++
i) hist[
i] += hist[
i - 1];
117 static const int MAX_DEPTH = 0x10000;
118 static const int MAX_DISPARITY = 0x2710;
126 template<
typename T,
typename F>
129 auto cm = _maps[_map_index];
132 auto d = depth_data[
i];
133 colorize_pixel(rgb_data,
i, cm,
d, coloring_func);
137 template<
typename T,
typename F>
142 auto f = coloring_func(data);
145 rgb_data[idx * 3 + 1] = (
uint8_t)
c.y;
146 rgb_data[idx * 3 + 2] = (
uint8_t)
c.z;
150 rgb_data[idx * 3 + 0] = 0;
151 rgb_data[idx * 3 + 1] = 0;
152 rgb_data[idx * 3 + 2] = 0;
169 float _depth_units = 0.f;
170 float _d2d_convert_factor = 0.f;
float lerp(float a, float b, float t)
GLboolean GLboolean GLboolean b
rs2::stream_profile _source_stream_profile
GLuint const GLchar * name
float3 get(float value) const
color_map(const std::vector< float3 > &values, int steps=4000)
void colorize_pixel(uint8_t *rgb_data, int idx, color_map *cm, T data, F coloring_func)
GLdouble GLdouble GLdouble w
#define LRS_EXTENSION_API
std::vector< float3 > _cache
GLfloat GLfloat GLfloat GLfloat h
GLboolean GLboolean GLboolean GLboolean a
std::map< float, float3 > _map
void make_rgb_data(const T *depth_data, uint8_t *rgb_data, int width, int height, F coloring_func)
const std::vector< float3 > & get_cache() const
std::vector< int > _histogram
T clamp_val(T val, const T &min, const T &max)
GLint GLsizei GLsizei height
std::vector< color_map * > _maps
rs2::stream_profile _target_stream_profile
color_map(std::map< float, float3 > map, int steps=4000)
float3 calc(float value) const
GLsizei const GLfloat * values
void initialize(int steps)
GLsizei GLsizei GLchar * source
float3 lerp(const float3 &a, const float3 &b, float t) const
static void update_histogram(int *hist, const T *depth_data, int w, int h)
GeneratorWrapper< T > map(Func &&function, GeneratorWrapper< U > &&generator)