25 int color_editor_height;
26 int opacity_editor_height;
27 cgv::g2d::irect color_handles_rect;
28 cgv::g2d::irect color_editor_rect;
29 cgv::g2d::irect opacity_editor_rect;
31 void update(
const ivec2& parent_size,
bool color_and_opacity) {
33 int content_height = total_height - 10 - 2 * padding;
34 if(color_and_opacity) {
35 color_editor_height =
static_cast<int>(floor(0.15f *
static_cast<float>(content_height)));
36 color_editor_height = cgv::math::clamp(color_editor_height, 4, 80);
37 opacity_editor_height = content_height - color_editor_height - 1;
39 color_editor_height = content_height;
40 opacity_editor_height = 0;
45 color_handles_rect.position =
ivec2(padding, 20);
46 color_handles_rect.size =
ivec2(parent_size.
x() - 2 * padding, 0);
51 color_editor_rect.position =
ivec2(padding, y_off);
52 color_editor_rect.size =
ivec2(parent_size.
x() - 2 * padding, color_editor_height);
54 y_off += color_editor_height + 1;
56 opacity_editor_rect.position =
ivec2(padding, y_off);
57 opacity_editor_rect.size =
ivec2(parent_size.
x() - 2 * padding, opacity_editor_height);
62 static const float default_width;
63 static const float default_height;
68 size =
vec2(default_width, default_height);
69 position_is_center =
true;
70 constraint_reference = CR_CENTER;
74 vec2 p = position - la.color_handles_rect.position;
75 val = p.
x() / la.color_handles_rect.size.x();
76 val = cgv::math::clamp(val, 0.0f, 1.0f);
80 val = cgv::math::clamp(val, 0.0f, 1.0f);
82 position.x() =
static_cast<float>(la.color_handles_rect.position.x()) + t * la.color_handles_rect.size.x();
83 position.y() =
static_cast<float>(la.color_handles_rect.position.y());
88 static const float default_size;
92 size =
vec2(default_size);
93 position_is_center =
true;
94 constraint_reference = CR_CENTER;
98 vec2 p = position - la.opacity_editor_rect.position;
99 val = p / la.opacity_editor_rect.size;
101 val = cgv::math::clamp(val, 0.0f, 1.0f);
102 val.
y() = cgv::math::clamp(std::pow(val.
y(), scale_exponent), 0.0f, 1.0f);
106 val = cgv::math::clamp(val, 0.0f, 1.0f);
109 t.
y() = cgv::math::clamp(std::pow(t.
y(), 1.0f / scale_exponent), 0.0f, 1.0f);
111 position = la.opacity_editor_rect.position + t * la.opacity_editor_rect.size;
115 bool mouse_is_on_overlay;
116 bool supports_opacity;
117 bool use_interpolation;
118 bool use_linear_filtering;
121 ivec2 cursor_position;
122 std::string cursor_label;
123 bool show_value_label;
124 std::string value_label;
125 cgv::g2d::rect value_label_rectangle;
128 rgba handle_color =
rgba(0.9f, 0.9f, 0.9f, 1.0f);
129 rgba highlight_color =
rgba(0.5f, 0.5f, 0.5f, 1.0f);
130 std::string highlight_color_hex =
"0x808080";
131 cgv::g2d::shape2d_style border_style, color_map_style, bg_style, hist_style, label_box_style, opacity_handle_style, polygon_style;
132 cgv::g2d::arrow2d_style color_handle_style;
133 cgv::g2d::line2d_style line_style;
136 cgv::g2d::text2d_style cursor_label_style, value_label_style;
138 std::vector<unsigned> histogram;
139 unsigned hist_max = 1;
140 unsigned hist_max_non_zero = 1;
141 bool hist_norm_ignore_zero =
true;
142 float hist_norm_gamma = 1.0f;
146 float opacity_scale_exponent;
152 cgv::g2d::generic_2d_renderer color_handle_renderer, opacity_handle_renderer, line_renderer, polygon_renderer;
153 DEFINE_GENERIC_RENDER_DATA_CLASS(line_geometry, 2,
vec2, position,
vec2, texcoord);
157 cgv::g2d::draggable_collection<color_point> color_points;
158 cgv::g2d::draggable_collection<opacity_point> opacity_points;
160 cgv::g2d::generic_render_data_vec2_rgba color_handles, opacity_handles;
162 line_geometry triangles;
166 color_points.clear();
167 opacity_points.clear();
168 color_handles.clear();
169 opacity_handles.clear();
175 if(cm->has_texture_support())
181 void init_styles()
override;
185 void add_point(
const vec2& pos);
186 void remove_point(
const cgv::g2d::draggable* ptr);
187 cgv::g2d::draggable* get_hit_point(
const vec2& pos);
189 void update_value_label_rectangle(
vec2 position,
const cgv::g2d::rect& parent_rectangle);
190 void handle_color_drag(cgv::g2d::DragAction action);
191 void handle_opacity_drag(cgv::g2d::DragAction action);
194 void handle_drag_end();
195 std::string value_to_string(
float value);
197 void sort_color_points();
198 void sort_opacity_points();
199 void update_point_positions();
200 void update_color_map(
bool is_data_change);
201 bool update_geometry();
203 std::function<void(
void)> on_change_callback;
204 std::function<void(
rgb)> on_color_point_select_callback;
205 std::function<void(
void)> on_color_point_deselect_callback;
207 void create_gui_impl()
override;
225 bool get_opacity_support() {
return supports_opacity; }
226 void set_opacity_support(
bool flag);
228 vec2 get_range()
const {
return range; }
229 void set_range(vec2 r) { range = r; }
234 void set_histogram_data(
const std::vector<unsigned> data);
236 void set_selected_color(rgb color);
238 void set_on_change_callback(std::function<
void(
void)> cb) { on_change_callback = cb; }
239 void set_on_color_point_select_callback(std::function<
void(rgb)> cb) { on_color_point_select_callback = cb; }
240 void set_on_color_point_deselect_callback(std::function<
void(
void)> cb) { on_color_point_deselect_callback = cb; }
245static void connect_color_selector_to_color_map_editor(
const color_map_editor_ptr cme_ptr,
const color_selector_ptr cs_ptr) {
247 cme_ptr->set_on_color_point_select_callback(std::bind(&cgv::app::color_selector::set_rgb_color, cs_ptr, std::placeholders::_1));
249 cs_ptr->set_on_change_rgb_callback(std::bind(&cgv::app::color_map_editor::set_selected_color, cme_ptr, std::placeholders::_1));
base class for all drawables, which is independent of the used rendering API.
the texture class encapsulates all functionality independent of the rendering api.