54 transfer_function(std::initializer_list<color_point_type> colors, std::initializer_list<opacity_point_type> opacities);
60 return opacity_points_.empty();
73 return color_points_.empty() && opacity_points_.empty();
80 void clear_color_points();
83 void clear_opacity_points();
89 void set_color_points(
const std::vector<color_point_type>& colors);
103 void set_opacity_points(
const std::vector<opacity_point_type>& opacities);
110 void add_color_point(
float x,
const color_type&
color);
118 void add_opacity_point(
float x,
float opacity);
125 bool set_color(
size_t index,
const color_type&
color);
132 bool set_color_at(
float x,
const color_type&
color);
139 bool set_opacity(
size_t index,
const opacity_type& opacity);
146 bool set_opacity_at(
float x,
const opacity_type& opacity);
152 bool remove_color_point(
float x);
158 bool remove_opacity_point(
float x);
164 return color_points_.size();
171 return opacity_points_.size();
178 return color_points_;
185 return opacity_points_;
194 void set_domain(
cgv::vec2 domain)
override;
203 float normalize_value(
float value)
const override;
206 cgv::rgba map_value(
float value)
const override;
209 cgv::rgb get_mapped_color(
float value)
const override;
212 float get_mapped_opacity(
float value)
const override;
215 std::vector<cgv::rgba> quantize(
size_t count)
const override;
219 std::vector<cgv::rgb> quantize_color(
size_t count)
const;
223 std::vector<float> quantize_opacity(
size_t count)
const;
226 std::vector<float> get_ticks(
size_t request_count)
const override;
231 void set_interpolation(InterpolationMode interpolation);
236 void set_color_interpolation(InterpolationMode interpolation);
242 return color_interpolation_;
248 void set_opacity_interpolation(InterpolationMode interpolation);
254 return opacity_interpolation_;
264 template<
typename value_type>
265 typename std::vector<std::pair<float, value_type>>::iterator find_point(std::vector<std::pair<float, value_type>>& points,
float x) {
266 return std::find_if(points.begin(), points.end(), [&x](
const std::pair<float, value_type>& point) { return point.first == x; });
275 template<
typename value_type>
276 bool remove_point(std::vector<std::pair<float, value_type>>& points,
float x) {
277 auto it = find_point(points, x);
278 if(it == points.end() || it == points.begin() || it == --points.end())
289 template<
typename value_type>
290 void ensure_control_points_cover_domain(std::vector<std::pair<float, value_type>>& points) {
291 if(!points.empty()) {
293 if(domain[0] < points.front().first)
294 points.insert(points.begin(), { domain[0], points.front().second });
295 if(domain[1] > points.back().first)
296 points.push_back({ domain[1], points.back().second });
304 template<
typename value_type>
305 void sort_points_and_update_domain(std::vector<std::pair<float, value_type>>& points) {
306 std::sort(points.begin(), points.end(), [](
const auto& lhs,
const auto& rhs) { return lhs.first < rhs.first; });
318 template<
typename value_type>
319 value_type interpolate_step(
const std::vector<std::pair<float, value_type>>& points,
float x)
const {
320 return cgv::math::detail::interpolate_piece(points, x, [](
const value_type& a,
const value_type& b,
float t_local) {
return a; });
329 template<
typename value_type>
330 std::vector<value_type> interpolate_step_n(
const std::vector<std::pair<float, value_type>>& points,
size_t n)
const {
331 return cgv::math::detail::interpolate_n(points, [](
const value_type& a,
const value_type& b,
float t_local) {
return a; }, n);
341 template<
typename value_type>
342 value_type interpolate(
const std::vector<std::pair<float, value_type>>& points,
float x, InterpolationMode interpolation)
const {
343 switch(interpolation) {
344 case InterpolationMode::kStep:
345 return interpolate_step(points, x);
346 case InterpolationMode::kSmooth:
347 return cgv::math::interpolate_smooth_cubic(points, x);
349 return cgv::math::interpolate_linear(points, x);
360 template<
typename value_type>
361 std::vector<value_type> quantize(
const std::vector<std::pair<float, value_type>>& points,
size_t n, InterpolationMode interpolation)
const {
362 switch(interpolation) {
363 case InterpolationMode::kStep:
364 return interpolate_step_n(points, n);
365 case InterpolationMode::kSmooth:
366 return cgv::math::interpolate_smooth_cubic_n(points, n);
368 return cgv::math::interpolate_linear_n(points, n);
377 bool update_domain();
380 InterpolationMode color_interpolation_ = InterpolationMode::kLinear;
382 InterpolationMode opacity_interpolation_ = InterpolationMode::kLinear;
384 std::vector<color_point_type> color_points_;
386 std::vector<opacity_point_type> opacity_points_;