20 template<
typename DataT>
23 control_point(
vec2 size,
const cgv::g2d::irect* constraint) : cgv::g2d::draggable({ 0.0f }, size) {
24 position_is_center =
true;
25 constraint_reference = cgv::g2d::ConstraintReference::kCenter;
26 this->constraint = constraint;
29 void set_position_and_update_uv(
vec2 position) {
33 const auto& area =
static_cast<cgv::g2d::rect
>(*constraint);
34 this->position = cgv::math::clamp(position, area.a(), area.b());
35 uv = (this->position - area.position) / area.size;
38 void set_uv_and_update_position(
vec2 uv) {
42 const auto& area =
static_cast<cgv::g2d::rect
>(*constraint);
43 this->uv = cgv::math::clamp(uv, 0.0f, 1.0f);
44 position = area.position + this->uv * area.
size;
48 return uv.
x() < other.uv.
x();
52 vec2 value = { 0.0f };
59 static const vec2 color_point_size;
60 static const vec2 opacity_point_size;
62 enum class DraggableType {
69 int color_editor_height;
70 int opacity_editor_height;
71 cgv::g2d::irect color_draggables_rect;
72 cgv::g2d::irect color_editor_rect;
73 cgv::g2d::irect opacity_editor_rect;
76 bool supports_opacity =
false;
80 std::string value_label;
81 cgv::g2d::rect value_label_rectangle;
84 rgba handle_color = { 0.9f, 0.9f, 0.9f, 1.0f };
85 rgba highlight_color = { 0.5f, 0.5f, 0.5f, 1.0f };
86 cgv::g2d::shape2d_style border_style, color_map_style, bg_style, hist_style, label_box_style, opacity_handle_style, polygon_style;
87 cgv::g2d::arrow2d_style color_handle_style;
88 cgv::g2d::line2d_style line_style;
91 cgv::g2d::text2d_style cursor_label_style, value_label_style;
93 std::vector<unsigned> histogram;
94 unsigned hist_max = 1;
95 unsigned hist_max_non_zero = 1;
96 bool hist_norm_ignore_zero =
true;
97 float hist_norm_gamma = 1.0f;
98 enum class HistogramType {
104 HistogramType histogram_type = HistogramType::kNone;
107 float opacity_scale_exponent = 1.0f;
109 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 };
113 cgv::g2d::generic_2d_renderer color_handle_renderer, opacity_handle_renderer, line_renderer, polygon_renderer;
114 DEFINE_GENERIC_RENDER_DATA_CLASS(textured_geometry, 2, vec2, position, vec2, texcoord);
116 std::shared_ptr<cgv::media::transfer_function> transfer_function;
118 cgv::g2d::draggable_collection<color_point> color_draggables;
119 cgv::g2d::draggable_collection<opacity_point> opacity_draggables;
120 color_point* selected_color_draggable =
nullptr;
121 opacity_point* selected_opacity_draggable =
nullptr;
122 vec2 color_draggable_start_position = { 0.0f };
123 vec2 opacity_draggable_start_position = { 0.0f };
124 cgv::g2d::generic_render_data_vec2_rgba color_draggables_geometry, opacity_draggables_geometry;
125 textured_geometry line_geometry;
126 textured_geometry triangle_geometry;
127 vec2 input_domain = { 0.0f, 1.0f };
128 float input_position = 0.0f;
132 void init_styles()
override;
133 void update_layout(
const ivec2& parent_size);
135 color_point make_color_point()
const {
136 return color_point(color_point_size, &layout.color_draggables_rect);
139 opacity_point make_opacity_point()
const {
140 return opacity_point(opacity_point_size, &layout.opacity_editor_rect);
144 void force_update_data_from_transfer_function();
145 void update_data_from_transfer_function();
146 void update_transfer_function_from_data();
147 void rescale_domain();
149 void add_point(
const vec2& pos);
150 void erase_point(
const cgv::g2d::draggable* point);
151 void set_selected_point_domain_value();
152 cgv::g2d::draggable* get_hit_point(
const vec2& pos);
154 void set_value_label(vec2 position,
const std::string& text);
155 void handle_drag(cgv::g2d::DragAction action, DraggableType type);
156 void handle_selection_change();
157 std::string value_to_string(
float value);
159 void update_point_positions();
161 bool create_preview_texture();
162 bool create_background_texture();
163 void create_geometry();
165 void create_gui_impl()
override;
167 std::function<void(
void)> on_change_callback;
168 std::function<void(rgb)> on_color_point_select_callback;
169 std::function<void(
void)> on_color_point_deselect_callback;
172 transfer_function_editor();
173 std::string
get_type_name()
const override {
return "transfer_function_editor"; }
186 bool get_opacity_support() {
return supports_opacity; }
187 void set_opacity_support(
bool flag);
189 std::shared_ptr<cgv::media::transfer_function> get_transfer_function()
const {
190 return transfer_function;
192 void set_transfer_function(std::shared_ptr<cgv::media::transfer_function> transfer_function);
194 void notify_transfer_function_change() {
195 force_update_data_from_transfer_function();
198 void set_histogram_data(
const std::vector<unsigned> data);
200 void set_selected_color(rgb color);
202 void set_on_change_callback(std::function<
void(
void)> cb) {
203 on_change_callback = cb;
205 void set_on_color_point_select_callback(std::function<
void(rgb)> cb) {
206 on_color_point_select_callback = cb;
208 void set_on_color_point_deselect_callback(std::function<
void(
void)> cb) {
209 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.