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 set_color_points(
const std::vector<color_point_type>& colors);
94 void set_opacity_points(
const std::vector<opacity_point_type>& opacities);
101 void add_color_point(
float x,
const color_type&
color);
109 void add_opacity_point(
float x,
float opacity);
115 bool remove_color_point(
float x);
121 bool remove_opacity_point(
float x);
129 void set_domain(
cgv::vec2 domain)
override;
138 float normalize_value(
float value)
const override;
141 cgv::rgba map_value(
float value)
const override;
144 cgv::rgb get_mapped_color(
float value)
const override;
147 float get_mapped_opacity(
float value)
const override;
150 std::vector<cgv::rgba> quantize(
size_t count)
const override;
154 std::vector<cgv::rgb> quantize_color(
size_t count)
const;
158 std::vector<float> quantize_opacity(
size_t count)
const;
161 std::vector<float> get_ticks(
size_t request_count)
const override;
167 void clear_color_points();
170 void clear_opacity_points();
176 return color_points_;
183 return opacity_points_;
189 void set_interpolation(InterpolationMode interpolation);
194 void set_color_interpolation(InterpolationMode interpolation);
200 return color_interpolation_;
206 void set_opacity_interpolation(InterpolationMode interpolation);
212 return color_interpolation_;
222 template<
typename value_type>
223 bool remove_point(std::vector<std::pair<float, value_type>>& points,
float x) {
224 auto it = std::find_if(points.begin(), points.end(), [&x](
const std::pair<float, value_type>& point) { return point.first == x; });
225 if(it == points.end() || it == points.begin() || it == --points.end())
236 template<
typename value_type>
237 void ensure_control_points_cover_domain(std::vector<std::pair<float, value_type>>& points) {
238 if(!points.empty()) {
240 if(domain[0] < points.front().first)
241 points.insert(points.begin(), { domain[0], points.front().second });
242 if(domain[1] > points.back().first)
243 points.push_back({ domain[1], points.back().second });
251 template<
typename value_type>
252 void sort_points_and_update_domain(std::vector<std::pair<float, value_type>>& points) {
253 std::sort(points.begin(), points.end(), [](
const auto& lhs,
const auto& rhs) { return lhs.first < rhs.first; });
265 template<
typename value_type>
266 value_type interpolate_step(
const std::vector<std::pair<float, value_type>>& points,
float x)
const {
267 return cgv::math::detail::interpolate_piece(points, x, [](
const value_type& a,
const value_type& b,
float t_local) {
return a; });
276 template<
typename value_type>
277 std::vector<value_type> interpolate_step_n(
const std::vector<std::pair<float, value_type>>& points,
size_t n)
const {
278 return cgv::math::detail::interpolate_n(points, [](
const value_type& a,
const value_type& b,
float t_local) {
return a; }, n);
288 template<
typename value_type>
289 value_type interpolate(
const std::vector<std::pair<float, value_type>>& points,
float x, InterpolationMode interpolation)
const {
290 switch(interpolation) {
291 case InterpolationMode::kStep:
292 return interpolate_step(points, x);
293 case InterpolationMode::kSmooth:
294 return cgv::math::interpolate_smooth_cubic(points, x);
296 return cgv::math::interpolate_linear(points, x);
307 template<
typename value_type>
308 std::vector<value_type> quantize(
const std::vector<std::pair<float, value_type>>& points,
size_t n, InterpolationMode interpolation)
const {
309 switch(interpolation) {
310 case InterpolationMode::kStep:
311 return interpolate_step_n(points, n);
312 case InterpolationMode::kSmooth:
313 return cgv::math::interpolate_smooth_cubic_n(points, n);
315 return cgv::math::interpolate_linear_n(points, n);
324 bool update_domain();
327 InterpolationMode color_interpolation_ = InterpolationMode::kLinear;
329 InterpolationMode opacity_interpolation_ = InterpolationMode::kLinear;
331 std::vector<color_point_type> color_points_;
333 std::vector<opacity_point_type> opacity_points_;