20 enum class DraggableType {
25 template<
typename DataT>
28 control_point(
vec2 size,
const cgv::g2d::irect* constraint) : cgv::g2d::draggable({ 0.0f }, size) {
29 position_is_center =
true;
30 constraint_reference = cgv::g2d::ConstraintReference::kCenter;
31 this->constraint = constraint;
34 void set_position_and_update_uv(
vec2 position) {
38 const auto area =
static_cast<cgv::g2d::rect
>(*constraint);
39 this->position = cgv::math::clamp(position, area.a(), area.b());
40 uv = (this->position - area.position) / area.size;
41 update_domain_value();
44 void set_uv_and_update_position(
vec2 uv) {
48 const auto area =
static_cast<cgv::g2d::rect
>(*constraint);
49 this->uv = cgv::math::clamp(uv, 0.0f, 1.0f);
50 position = area.position + this->uv * area.
size;
51 update_domain_value();
55 return uv.
x() < other.uv.
x();
61 float domain_value = 0.0f;
65 void update_domain_value() {
66 domain_value = cgv::math::lerp(domain.
x(), domain.
y(), uv.
x());
75 int color_editor_height;
76 int opacity_editor_height;
77 cgv::g2d::irect color_draggables_rect;
78 cgv::g2d::irect color_editor_rect;
79 cgv::g2d::irect opacity_editor_rect;
82 static const vec2 color_point_size;
83 static const vec2 opacity_point_size;
84 static const size_t preview_texture_resolution;
86 bool supports_opacity =
false;
90 std::string value_label;
91 cgv::g2d::rect value_label_rectangle;
94 rgba handle_color = { 0.9f, 0.9f, 0.9f, 1.0f };
95 rgba highlight_color = { 0.5f, 0.5f, 0.5f, 1.0f };
96 cgv::g2d::shape2d_style border_style, color_map_style, background_style, histogram_style, label_box_style, opacity_handle_style, polygon_style;
97 cgv::g2d::arrow2d_style color_handle_style;
98 cgv::g2d::line2d_style line_style;
101 cgv::g2d::text2d_style cursor_label_style, value_label_style;
103 std::vector<unsigned> histogram;
104 unsigned hist_max = 1;
105 unsigned hist_max_non_zero = 1;
106 bool hist_norm_ignore_zero =
true;
107 float hist_norm_gamma = 1.0f;
108 enum class HistogramType {
114 HistogramType histogram_type = HistogramType::kNone;
116 cgv::render::texture background_tex = {
"flt32[R,G,B]", cgv::render::TF_NEAREST, cgv::render::TF_NEAREST, cgv::render::TW_REPEAT, cgv::render::TW_REPEAT };
120 cgv::g2d::generic_2d_renderer color_handle_renderer, opacity_handle_renderer, line_renderer, polygon_renderer;
121 DEFINE_GENERIC_RENDER_DATA_CLASS(textured_geometry, 2, vec2, position, vec2, texcoord);
123 std::shared_ptr<cgv::media::transfer_function> transfer_function;
125 cgv::g2d::draggable_collection<color_point> color_draggables;
126 cgv::g2d::draggable_collection<opacity_point> opacity_draggables;
127 color_point* selected_color_draggable =
nullptr;
128 opacity_point* selected_opacity_draggable =
nullptr;
129 vec2 color_draggable_start_position = { 0.0f };
130 vec2 opacity_draggable_start_position = { 0.0f };
131 cgv::g2d::generic_render_data_vec2_rgba color_draggables_geometry, opacity_draggables_geometry;
132 textured_geometry line_geometry;
133 textured_geometry triangle_geometry;
134 vec2 input_domain = { 0.0f, 1.0f };
135 float input_position = 0.0f;
139 void init_styles()
override;
140 void update_layout(
const ivec2& parent_size);
142 color_point make_color_point()
const {
143 return color_point(color_point_size, &layout.color_draggables_rect);
146 opacity_point make_opacity_point()
const {
147 return opacity_point(opacity_point_size, &layout.opacity_editor_rect);
151 void force_update_data_from_transfer_function();
152 void update_data_from_transfer_function();
153 void update_transfer_function_from_data();
154 void rescale_domain();
156 void add_point(
const vec2& pos);
157 void erase_point(
const cgv::g2d::draggable* point);
158 void set_selected_point_domain_value();
159 cgv::g2d::draggable* get_hit_point(
const vec2& pos);
161 void set_value_label(vec2 position,
const std::string& text);
162 void handle_drag(cgv::g2d::DragAction action, DraggableType type);
163 void handle_selection_change();
164 std::string value_to_string(
float value);
166 void update_point_positions();
168 bool create_preview_texture();
169 bool create_background_texture();
170 void create_geometry();
172 void create_gui_impl()
override;
174 std::function<void(
void)> on_change_callback;
175 std::function<void(rgb)> on_color_point_select_callback;
176 std::function<void(
void)> on_color_point_deselect_callback;
179 transfer_function_editor();
180 std::string
get_type_name()
const override {
return "transfer_function_editor"; }
193 bool get_opacity_support() {
return supports_opacity; }
194 void set_opacity_support(
bool flag);
196 std::shared_ptr<cgv::media::transfer_function> get_transfer_function()
const {
197 return transfer_function;
199 void set_transfer_function(std::shared_ptr<cgv::media::transfer_function> transfer_function);
201 void notify_transfer_function_change() {
202 force_update_data_from_transfer_function();
205 void set_histogram_data(
const std::vector<unsigned> data);
207 void set_selected_color(rgb color);
209 void set_on_change_callback(std::function<
void(
void)> cb) {
210 on_change_callback = cb;
212 void set_on_color_point_select_callback(std::function<
void(rgb)> cb) {
213 on_color_point_select_callback = cb;
215 void set_on_color_point_deselect_callback(std::function<
void(
void)> cb) {
216 on_color_point_deselect_callback = cb;
base class for all drawables, which is independent of the used rendering API.
the texture class encapsulates all functionality independent of the rendering api.