19 color_map(std::map<float, float3> map,
int steps = 4000) : _map(map)
24 color_map(
const std::vector<float3>& values,
int steps = 4000)
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))];
49 return b * t + a * (1 - t);
52 float3 calc(
float value)
const 56 if (_map.find(
value) != _map.end())
return _map.at(
value);
58 if (
value < _map.begin()->first)
return _map.begin()->second;
59 if (
value > _map.rbegin()->first)
return _map.rbegin()->second;
61 auto lower = _map.lower_bound(
value) == _map.begin() ? _map.begin() : --(_map.lower_bound(
value));
62 auto upper = _map.upper_bound(
value);
64 auto t = (
value - lower->first) / (upper->first - lower->first);
65 auto c1 = lower->second;
66 auto c2 = upper->second;
67 return lerp(c1, c2, t);
70 void initialize(
int steps)
72 if (_map.size() == 0)
return;
74 _min = _map.begin()->first;
75 _max = _map.rbegin()->first;
77 _cache.resize(steps + 1);
78 for (
int i = 0; i <= steps; i++)
80 auto t = (float)i / steps;
81 auto x = _min + t*(_max - _min);
86 _size = _cache.size();
87 _data = _cache.data();
90 std::map<float, float3> _map;
91 std::vector<float3> _cache;
93 size_t _size; float3* _data;
104 std::vector<color_map*> _maps;
108 std::shared_ptr<rs2::stream_profile> _stream;
color_map(const std::vector< float3 > &values, int steps=4000)
Definition: colorizer.h:24
Definition: synthetic-stream.h:41
Definition: rs_context.hpp:11
float max_key() const
Definition: colorizer.h:44
float min_key() const
Definition: colorizer.h:43
color_map()
Definition: colorizer.h:33
Definition: colorizer.h:16
T clamp_val(T val, const T &min, const T &max)
Definition: types.h:118
Definition: colorizer.h:96
color_map(std::map< float, float3 > map, int steps=4000)
Definition: colorizer.h:19