cgv
Loading...
Searching...
No Matches
plot_base.cxx
1#include "plot_base.h"
2
3#include <algorithm>
4
5#include <cgv/math/ftransform.h>
6#include <cgv/media/named_color_schemes.h>
7#include <cgv/render/attribute_array_binding.h>
8#include <cgv/render/shader_program.h>
9#include <cgv/signal/rebind.h>
10#include <cgv/utils/scan.h>
11#include <libs/cgv_gl/gl/gl.h>
12#include <libs/cgv_gl/rectangle_renderer.h>
13#include <libs/tt_gl_font/tt_gl_font.h>
14
15namespace cgv {
16 namespace plot {
17
18std::vector<const char*> plot_base::font_names;
20
24
25plot_base::tick_batch_info::tick_batch_info(int _ai, int _aj, bool _primary, unsigned _first_vertex, unsigned _first_label)
26 : ai(_ai), aj(_aj), primary(_primary), first_vertex(_first_vertex), first_label(_first_label)
27{
28}
29domain_config::domain_config(unsigned dim, unsigned nr_attrs) : color(0.85f,0.85f,0.85f), axis_configs(dim+nr_attrs)
30{
31 show_domain = true;
32 fill = true;
33 reference_size = 0.001f;
36 label_font_size = 24.0f;
37 label_ffa = cgv::media::font::FFA_REGULAR;
38 show_title = true;
40 title_color = rgba(0.2f, 0.2f, 0.2f, 1.0f);
42 title_font_size = 36.0f;
43 title_ffa = cgv::media::font::FFA_REGULAR;
44 title_pos.zeros(dim);
45}
46
47plot_base_config::plot_base_config(const std::string& _name, unsigned dim) : name(_name)
48{
49 show_plot = true;
50 begin_sample = 0;
51 end_sample = size_t(-1);
52 ref_size = 2;
53 ref_color = rgb(1, 0, 0);
54 ref_opacity = 1.0f;
56 //point_halo_width = 1.0f;
57 //point_halo_color = rgba(0.5f, 0.5f, 0.5f, 1.0f);
59 stick_base_window = 0.0f;
61 bar_base_window = 0.0;
62 sub_plot_influence = SPI_ALL;
63 set_colors(ref_color.color);
65 set_sizes(ref_size.size);
66 configure_chart(CT_BAR_CHART);
67}
68void plot_base_config::configure_chart(ChartType chart_type)
69{
70 switch (chart_type) {
71 case CT_POINT :
72 case CT_LINE_CHART:
73 show_points = true;
74 show_sticks = false;
75 show_bars = false;
76 break;
77 case CT_BAR_CHART:
78 show_points = false;
79 show_sticks = false;
80 show_bars = true;
81 break;
82 }
83}
84void plot_base_config::set_colors(const rgb& base_color)
85{
86 ref_color.color = base_color;
87 if ((sub_plot_influence & SPI_POINT) != 0)
88 point_color.color = base_color;
89 if ((sub_plot_influence & SPI_POINT_HALO) != 0) {
91 hls_base.S() *= 0.6f;
92 point_halo_color.color = hls_base;
93 }
94 if ((sub_plot_influence & SPI_LINE) != 0)
95 line_color.color = 0.25f * rgb(1, 1, 1) + 0.75f * base_color;
96 if ((sub_plot_influence & SPI_LINE_HALO) != 0) {
98 hls_base.S() *= 0.6f;
99 line_halo_color.color = hls_base;
100 }
101 if ((sub_plot_influence & SPI_STICK) != 0)
102 stick_color.color = 0.25f * rgb(0, 0, 0) + 0.75f * base_color;
103 if ((sub_plot_influence & SPI_BAR) != 0)
104 bar_color.color = 0.5f * rgb(1, 1, 1) + 0.5f * base_color;
105 if ((sub_plot_influence & SPI_BAR_OUTLINE) != 0)
106 bar_outline_color.color = base_color;
107}
108void plot_base_config::set_color_indices(int idx)
109{
110 if ((sub_plot_influence & SPI_POINT) != 0)
111 point_color.color_idx = idx;
112 if ((sub_plot_influence & SPI_POINT_HALO) != 0)
113 point_halo_color.color_idx = idx;
114 if ((sub_plot_influence & SPI_LINE) != 0)
115 line_color.color_idx = idx;
116 if ((sub_plot_influence & SPI_LINE_HALO) != 0)
117 line_halo_color.color_idx = idx;
118 if ((sub_plot_influence & SPI_STICK) != 0)
119 stick_color.color_idx = idx;
120 if ((sub_plot_influence & SPI_BAR) != 0)
121 bar_color.color_idx = idx;
122 if ((sub_plot_influence & SPI_BAR_OUTLINE) != 0)
123 bar_outline_color.color_idx = idx;
124}
126{
127 ref_size.size = _size;
128 if ((sub_plot_influence & SPI_POINT) != 0)
129 point_size.size = _size;
130 if ((sub_plot_influence & SPI_POINT_HALO) != 0)
131 point_halo_width.size = 0.2f * _size;
132 if ((sub_plot_influence & SPI_LINE) != 0)
133 line_width.size = 0.5f * _size;
134 if ((sub_plot_influence & SPI_LINE_HALO) != 0)
135 line_halo_width.size = 0.1f * _size;
136 if ((sub_plot_influence & SPI_STICK) != 0)
137 stick_width.size = 0.4f * _size;
138 if ((sub_plot_influence & SPI_BAR_OUTLINE) != 0)
139 bar_outline_width.size = 0.2f * _size;
140}
141void plot_base_config::set_size_indices(int idx)
142{
143 if ((sub_plot_influence & SPI_POINT) != 0)
144 point_size.size_idx = idx;
145 if ((sub_plot_influence & SPI_POINT_HALO) != 0)
146 point_halo_width.size_idx = idx;
147 if ((sub_plot_influence & SPI_LINE) != 0)
148 line_width.size_idx = idx;
149 if ((sub_plot_influence & SPI_LINE_HALO) != 0)
150 line_halo_width.size_idx = idx;
151 if ((sub_plot_influence & SPI_STICK) != 0)
152 stick_width.size_idx = idx;
153 if ((sub_plot_influence & SPI_BAR_OUTLINE) != 0)
154 bar_outline_width.size_idx = idx;
155}
157{
158 ref_opacity = _opa;
159 if ((sub_plot_influence & SPI_POINT) != 0)
160 point_color.color.alpha() = _opa;
161 if ((sub_plot_influence & SPI_POINT_HALO) != 0)
162 point_halo_color.color.alpha() = _opa;
163 if ((sub_plot_influence & SPI_LINE) != 0)
164 line_color.color.alpha() = pow(_opa, 0.8f);
165 if ((sub_plot_influence & SPI_LINE_HALO) != 0)
166 line_halo_color.color.alpha() = _opa;
167 if ((sub_plot_influence & SPI_STICK) != 0)
168 stick_color.color.alpha() = pow(_opa, 0.9f);
169 if ((sub_plot_influence & SPI_BAR) != 0)
170 bar_outline_color.color.alpha() = pow(_opa, 0.7f);
171 if ((sub_plot_influence & SPI_BAR_OUTLINE) != 0)
172 bar_color.color.alpha() = pow(_opa, 0.7f);
173}
174void plot_base_config::set_opacity_indices(int idx)
175{
176 if ((sub_plot_influence & SPI_POINT) != 0)
177 point_color.opacity_idx = idx;
178 if ((sub_plot_influence & SPI_POINT_HALO) != 0)
179 point_halo_color.opacity_idx = idx;
180 if ((sub_plot_influence & SPI_LINE) != 0)
181 line_color.opacity_idx = idx;
182 if ((sub_plot_influence & SPI_LINE_HALO) != 0)
183 line_halo_color.opacity_idx = idx;
184 if ((sub_plot_influence & SPI_STICK) != 0)
185 stick_color.opacity_idx = idx;
186 if ((sub_plot_influence & SPI_BAR) != 0)
187 bar_outline_color.opacity_idx = idx;
188 if ((sub_plot_influence & SPI_BAR_OUTLINE) != 0)
189 bar_color.opacity_idx = idx;
190}
194
195attribute_source::attribute_source() : source(AS_NONE), pointer(0), offset(0), count(0), stride(0)
196{}
197attribute_source::attribute_source(int _sub_plot_index, size_t ai, size_t _count, size_t _stride) :
198 source(AS_SAMPLE_CONTAINER), sub_plot_index(_sub_plot_index), offset(ai), count(_count), stride(_stride) {}
199attribute_source::attribute_source(const float* _pointer, size_t _count, size_t _stride) :
200 source(AS_POINTER), pointer(_pointer), offset(0), count(_count), stride(_stride) {}
201attribute_source::attribute_source(const cgv::render::vertex_buffer* _vbo_ptr, size_t _offset, size_t _count, size_t _stride) :
202source(AS_VBO), vbo_ptr(_vbo_ptr), offset(_offset), count(_count), stride(_stride) {}
204{
205 source = as.source;
206 switch (source) {
207 case AS_NONE: pointer = 0; offset = count = stride = 0; break;
208 case AS_SAMPLE_CONTAINER: sub_plot_index = as.sub_plot_index; break;
209 case AS_POINTER: pointer = as.pointer; break;
210 case AS_VBO: vbo_ptr = as.vbo_ptr; break;
211 }
212 offset = as.offset;
213 count = as.count;
214 stride = as.stride;
215}
216attribute_source_array::attribute_source_array() : vbo(cgv::render::VBT_VERTICES, cgv::render::VBU_STREAM_DRAW)
217{
218 samples_out_of_date = true;
219 sources_out_of_date = true;
220 count = 0;
221}
222
223void plot_base::draw_rectangles(cgv::render::context& ctx, cgv::render::attribute_array_manager& aam,
224 std::vector<box2>& R, std::vector<rgb>& C, std::vector<float>& D, size_t offset)
225{
227 rr.set_render_style(rrs);
228 rr.enable_attribute_array_manager(ctx, aam);
229 rr.set_rectangle_array(ctx, R);
230 rr.set_color_array(ctx, C);
231 rr.set_depth_offset_array(ctx, D);
232 rr.render(ctx, offset, R.size() - offset);
233 rr.disable_attribute_array_manager(ctx, aam);
234}
235
236
237void plot_base::draw_sub_plot_samples(int count, const plot_base_config& spc, bool strip)
238{
239 if (spc.begin_sample >= spc.end_sample) {
240 glDrawArrays(strip ? GL_LINE_STRIP : GL_POINTS, GLint(spc.begin_sample), GLsizei(count - spc.begin_sample));
241 if (strip) {
242 GLint indices[2] = { count - 1, 0 };
243 glDrawElements(GL_LINES, 2, GL_UNSIGNED_INT, indices);
244 }
245 if (spc.end_sample > 0)
246 glDrawArrays(strip ? GL_LINE_STRIP : GL_POINTS, 0, GLsizei(spc.end_sample));
247 }
248 else {
249 if (spc.end_sample == size_t(-1))
250 glDrawArrays(strip ? GL_LINE_STRIP : GL_POINTS, GLint(spc.begin_sample), GLsizei(count - spc.begin_sample));
251 else
252 if (spc.begin_sample < spc.end_sample)
253 glDrawArrays(strip ? GL_LINE_STRIP : GL_POINTS, GLint(spc.begin_sample), GLsizei(spc.end_sample - spc.begin_sample));
254 }
255}
256vec3 plot_base::world_space_from_plot_space(const vecn& pnt_plot) const
257{
258 vec3 pnt(pnt_plot(0), pnt_plot(1), pnt_plot.size() >= 3 ? pnt_plot(2) : 0.0f);
259 return orientation.apply(pnt) + center_location;
260}
262{
263 unsigned n = pnt_attr.size();
264 vecn pnt_plot(n);
265 const auto& acs = get_domain_config_ptr()->axis_configs;
266 unsigned m = acs.size() < n ? unsigned(acs.size()) : n;
267 for (unsigned ai = 0; ai < m; ++ai) {
268 pnt_plot(ai) =
269 acs[ai].plot_space_from_window_space(
270 acs[ai].window_space_from_tick_space(
271 acs[ai].tick_space_from_attribute_space(pnt_attr[ai])));
272 }
273 return world_space_from_plot_space(pnt_plot);
274}
276{
277 if (font_names.empty()) {
279 if (font_names.empty())
280 return;
281 font_name_enum_def = std::string("enums='") + font_names[0];
282 for (unsigned i = 1; i < font_names.size(); ++i) {
283 font_name_enum_def += ',';
285 }
286 font_name_enum_def += "'";
287 }
288 if (!label_font) {
291 if(font_ptr) {
292 std::string font_name = font_ptr->get_name();
293 for(auto iter = font_names.begin(); iter != font_names.end(); ++iter)
294 if(std::string(*iter) == font_name) {
295 get_domain_config_ptr()->label_font_index = (unsigned)(iter - font_names.begin());
296 break;
297 }
298 }
300 }
301 if (!title_font) {
304 if(font_ptr) {
305 std::string font_name = font_ptr->get_name();
306 for(auto iter = font_names.begin(); iter != font_names.end(); ++iter)
307 if(std::string(*iter) == font_name) {
308 get_domain_config_ptr()->title_font_index = (unsigned)(iter - font_names.begin());
309 break;
310 }
311 }
313 }
314}
315
316void plot_base::on_legend_axis_change(cgv::gui::provider& p, cgv::gui::control<int>& ctrl)
317{
318 if (ctrl.get_old_value() != ctrl.get_value()) {
319 std::swap(legend_extent[0], legend_extent[1]);
320 std::swap(legend_location[0], legend_location[1]);
325 }
326}
328{
329 if (get_domain_config_ptr()->label_font_index != -1)
331 if (get_domain_config_ptr()->title_font_index != -1)
334}
336{
337 if (label_font)
338 label_font_face = label_font->get_font_face(get_domain_config_ptr()->label_ffa);
339 if (title_font)
340 title_font_face = title_font->get_font_face(get_domain_config_ptr()->title_ffa);
341}
342
344{
345 extent = vec3(0.0f);
346 unsigned max_ai = std::min(unsigned(get_domain_config_ptr()->axis_configs.size()), get_dim());
347 unsigned F_count = 0;
348 float F;
349 for (unsigned ai = 0; ai < max_ai; ++ai) {
350 const auto& ac = get_domain_config_ptr()->axis_configs[ai];
351 extent[ai] = ac.extent;
352 if (ac.extent_scaling == 0.0f)
353 continue;
354 // (E1 * ES1) / A1 = (E2 * ES2) / A2 = F
355 // F = E * ES / A;
356 // E = F * A / ES;
357 float f = ac.extent * ac.extent_scaling / ac.get_attribute_extent();
358 if (F_count)
359 F = std::min(F, f);
360 else
361 F = f;
362 ++F_count;
363 }
364 if (F_count > 1) {
365 for (unsigned ai = 0; ai < max_ai; ++ai) {
366 const auto& ac = get_domain_config_ptr()->axis_configs[ai];
367 if (ac.extent_scaling == 0.0f)
368 continue;
369 extent[ai] = F * ac.get_attribute_extent() / ac.extent_scaling;
370 }
371 }
372}
373
375{
376 vecn attribute_min(8u, 0.0f), attribute_max(8u, 1.0f), axis_log_minimum(8u, 0.000001f);
377 cgv::math::vec<int> axis_log_scale(8u, 0);
378 for (unsigned ai = 0; ai < get_domain_config_ptr()->axis_configs.size(); ++ai) {
379 const auto& ac = get_domain_config_ptr()->axis_configs[ai];
380 attribute_min(ai) = ac.get_attribute_min();
381 attribute_max(ai) = ac.get_attribute_max();
382 axis_log_scale(ai) = ac.get_log_scale() ? 1 : 0;
383 axis_log_minimum(ai) = ac.get_log_minimum();
384 }
385 vec3 E(extent.size(), &extent(0));
386 prog.set_uniform(ctx, "extent", E);
387 prog.set_uniform(ctx, "out_of_range_mode", out_of_range_mode);
388 prog.set_uniform_array(ctx, "attribute_min", attribute_min);
389 prog.set_uniform_array(ctx, "attribute_max", attribute_max);
390 prog.set_uniform_array(ctx, "axis_log_scale", axis_log_scale);
391 prog.set_uniform_array(ctx, "axis_log_minimum", axis_log_minimum);
392 prog.set_uniform(ctx, "orientation", orientation);
393 prog.set_uniform(ctx, "center_location", center_location);
394}
396{
397 prog.set_uniform_array(ctx, "color_mapping", color_mapping, MAX_NR_COLOR_MAPPINGS);
398 prog.set_uniform_array(ctx, "opacity_mapping", opacity_mapping, MAX_NR_COLOR_MAPPINGS);
399 prog.set_uniform_array(ctx, "size_mapping", size_mapping, MAX_NR_COLOR_MAPPINGS);
400 if (prog.get_uniform_location(ctx, "color_scale_texture") != -1) {
402 color_scale_adapter.set_uniforms_in_program(ctx, prog, color_scale_texture_unit);
403 }
404 if (prog.get_uniform_location(ctx, "opacity_gamma[0]") != -1) {
405 prog.set_uniform_array(ctx, "opacity_gamma", opacity_gamma, MAX_NR_OPACITY_MAPPINGS);
406 prog.set_uniform_array(ctx, "opacity_min", opacity_min, MAX_NR_OPACITY_MAPPINGS);
407 prog.set_uniform_array(ctx, "opacity_max", opacity_max, MAX_NR_OPACITY_MAPPINGS);
409 for (int oi=0;oi< MAX_NR_OPACITY_MAPPINGS;++oi)
410 opa[oi] = opacity_is_bipolar[oi] ? 1 : 0;
411 prog.set_uniform_array(ctx, "opacity_is_bipolar", opa, MAX_NR_OPACITY_MAPPINGS);
412 prog.set_uniform_array(ctx, "opacity_window_zero_position", opacity_window_zero_position, MAX_NR_OPACITY_MAPPINGS);
413 }
414 if (prog.get_uniform_location(ctx, "size_mapping[0]") != -1) {
415 prog.set_uniform_array(ctx, "size_gamma", size_gamma, MAX_NR_SIZE_MAPPINGS);
416 prog.set_uniform_array(ctx, "size_min", size_min, MAX_NR_SIZE_MAPPINGS);
417 prog.set_uniform_array(ctx, "size_max", size_max, MAX_NR_SIZE_MAPPINGS);
418 }
419}
420
422 const cgv::media::continuous_color_scheme_registry& registry = cgv::media::get_global_continuous_color_scheme_registry();
423 for(size_t i = 0; i < MAX_NR_COLOR_MAPPINGS; ++i) {
424 if(color_scheme_index[i] < registry.size())
425 color_scales[i]->color_scale->set_scheme(registry.get(color_scheme_index[i]));
426 color_scales[i]->color_scale->set_diverging(color_scale_is_bipolar[i]);
427 color_scales[i]->color_scale->set_reversed(reversed[i]);
428 color_scales[i]->color_scale->set_pow_exponent(color_scale_gamma[i]);
429 color_scales[i]->color_scale->set_midpoint(window_zero_position[i]);
430 }
431}
432
433void plot_base::set_sub_plot_attribute(unsigned i, unsigned ai, int subplot_index, size_t aj)
434{
435 assert(attribute_source_arrays.size() > i);
436 auto& ass = attribute_source_arrays[i].attribute_sources;
437 if (ass.size() <= ai)
438 ass.resize(ai + 1);
439 ass[ai] = attribute_source(subplot_index, aj, 0, get_dim() * sizeof(float));
440 attribute_source_arrays[i].sources_out_of_date = true;
441}
442void plot_base::set_sub_plot_attribute(unsigned i, unsigned ai, const float* _pointer, size_t count, size_t stride)
443{
444 assert(attribute_source_arrays.size() > i);
445 auto& ass = attribute_source_arrays[i].attribute_sources;
446 if (ass.size() <= ai)
447 ass.resize(ai + 1);
448 ass[ai] = attribute_source(_pointer, count, stride);
449 attribute_source_arrays[i].sources_out_of_date = true;
450}
451void plot_base::set_sub_plot_attribute(unsigned i, unsigned ai, const cgv::render::vertex_buffer* _vbo_ptr, size_t _offset, size_t _count, size_t _stride)
452{
453 assert(attribute_source_arrays.size() > i);
454 auto& ass = attribute_source_arrays[i].attribute_sources;
455 while (ass.size() <= ai)
456 ass.resize(ai + 1);
457 ass[ai] = attribute_source(_vbo_ptr, _offset, _count, _stride);
458 attribute_source_arrays[i].sources_out_of_date = true;
459}
460
461template <uint32_t N>
463{
464 const std::vector<std::vector<cgv::math::fvec<float, N>>>& samples;
465 vecn_sample_access(const std::vector < std::vector<cgv::math::fvec<float, N>>>& _samples) : samples(_samples) {}
466 size_t size(unsigned i) const { return samples[i].size(); }
467 float operator() (unsigned i, unsigned k, unsigned o) const { return samples[i][k][o]; }
468};
469size_t plot_base::enable_attributes(cgv::render::context& ctx, int i, const sample_access& sa)
470{
471 auto& asa = attribute_source_arrays[i];
472 auto& ass = asa.attribute_sources;
473 // first check whether we need to update vbo
474 unsigned ai = 0, j;
475 bool update_vbo = false;
476 size_t vbo_nr_floats = 0;
477 for (ai = 0; ai < ass.size(); ++ai) {
478 auto& as = ass[ai];
479 switch (as.source) {
480 case AS_SAMPLE_CONTAINER:
481 j = as.sub_plot_index == -1 ? i : as.sub_plot_index;
482 if (attribute_source_arrays[j].samples_out_of_date) {
483 update_vbo = true;
484 as.count = sa.size(j);
485 vbo_nr_floats += as.count;
486 }
487 break;
488 case AS_POINTER:
489 if (asa.samples_out_of_date) {
490 update_vbo = true;
491 vbo_nr_floats += as.count;
492 }
493 break;
494 default:
495 break;
496 }
497 }
498 // update vbo if necessary
499 if (update_vbo) {
500 // copy data into CPU buffer
501 std::vector<float> buffer(vbo_nr_floats);
502 float* dest = buffer.data();
503 for (ai = 0; ai < ass.size(); ++ai) {
504 const auto& as = ass[ai];
505 switch (as.source) {
506 case AS_SAMPLE_CONTAINER:
507 j = as.sub_plot_index == -1 ? i : as.sub_plot_index;
508 if (attribute_source_arrays[j].samples_out_of_date) {
509 for (int k = 0; k < as.count; ++k)
510 *dest++ = sa(j,k,(unsigned)as.offset);
511 }
512 break;
513 case AS_POINTER:
514 if (asa.samples_out_of_date) {
515 const float* src = as.pointer;
516 unsigned stride = unsigned(as.stride/sizeof(float));
517 for (int k = 0; k < as.count; ++k, src += stride)
518 *dest++ = *src;
519 }
520 break;
521 default:
522 break;
523 }
524 }
525 if (asa.vbo.get_size_in_bytes() != vbo_nr_floats * sizeof(float)) {
526 asa.vbo.destruct(ctx);
527 asa.vbo.create(ctx, buffer);
528 }
529 else
530 asa.vbo.replace(ctx, 0, buffer.data(), buffer.size());
531 asa.sources_out_of_date = true;
532 }
533 // update attribute bindings
534 if (!asa.aab.is_created()) {
535 asa.aab.create(ctx);
536 asa.sources_out_of_date = true;
537 }
538 if (asa.sources_out_of_date) {
539 size_t count = -1;
540 size_t vbo_offset = 0;
541 float f;
542 for (ai = 0; ai < ass.size(); ++ai) {
543 const auto& as = ass[ai];
544 switch (as.source) {
545 case AS_SAMPLE_CONTAINER: {
546 j = as.sub_plot_index == -1 ? i : as.sub_plot_index;
547 asa.aab.set_attribute_array(ctx, ai, cgv::render::get_element_type(f), asa.vbo, vbo_offset, sa.size(j), 0);
548 count = std::min(sa.size(j), count);
549 vbo_offset += count * sizeof(float);
550 break;
551 }
552 case AS_POINTER:
553 asa.aab.set_attribute_array(ctx, ai, cgv::render::get_element_type(f), asa.vbo, vbo_offset, as.count, 0);
554 count = std::min(as.count, count);
555 vbo_offset += count * sizeof(float);
556 break;
557 case AS_VBO:
558 asa.aab.set_attribute_array(ctx, ai, cgv::render::get_element_type(f), *as.vbo_ptr, as.count, as.offset, (unsigned)as.stride);
559 count = std::min(as.count, count);
560 break;
561 }
562 }
563 asa.count = count;
564 asa.sources_out_of_date = false;
565 }
566 // enable and return count
567 asa.aab.enable(ctx);
568 return asa.count;
569}
570size_t plot_base::enable_attributes(cgv::render::context& ctx, int i, const std::vector<std::vector<vec2>>& samples)
571{
572 return enable_attributes(ctx, i, vecn_sample_access<2>(samples));
573}
574size_t plot_base::enable_attributes(cgv::render::context& ctx, int i, const std::vector<std::vector<vec3>>& samples)
575{
576 return enable_attributes(ctx, i, vecn_sample_access<3>(samples));
577}
578void plot_base::disable_attributes(cgv::render::context& ctx, int i)
579{
580 attribute_source_arrays[i].aab.disable(ctx);
581}
582void plot_base::update_samples_out_of_date_flag()
583{
584 for (auto& asa : attribute_source_arrays)
585 asa.samples_out_of_date = false;
586}
587
588plot_base::plot_base(unsigned _dim, unsigned _nr_attributes) : dom_cfg(_dim, _nr_attributes),
589 vbo_legend(cgv::render::VBT_VERTICES, cgv::render::VBU_STREAM_DRAW)
590{
591 dim = _dim;
593 view_ptr = 0;
594 nr_attributes = _nr_attributes;
595 layer_depth = 0.00001f;
597 rrs.illumination_mode = cgv::render::IM_OFF;
598 rrs.map_color_to_material = cgv::render::CM_COLOR_AND_OPACITY;
599 legend_components = LC_HIDDEN;
600 legend_location = vec3(0.8f, 0.6f, 0.0f);
601 legend_extent = vec2(0.05f,0.7f);
602 legend_axis = 1;
603 legend_color = rgba(0.3f, 0.2f, 0.8f, 1.0f);
604 orientation = quat(1.0f, 0.0f, 0.0f, 0.0f);
605 center_location = vec3(0.0f);
606
607 for (int ci = 0; ci < MAX_NR_COLOR_MAPPINGS; ++ci) {
608 color_mapping[ci] = -1;
609 color_scheme_index[ci] = -1;
610 color_scales[ci] = std::make_shared<cgv::render::device_continuous_color_scale>();
611 color_scales[ci]->color_scale->set_transform(cgv::media::ContinuousMappingTransform::kPow);
612 color_scale_gamma[ci] = 1;
613 color_scale_is_bipolar[ci] = false;
614 window_zero_position[ci] = 0.5f;
615 }
616 for (int oi = 0; oi < MAX_NR_OPACITY_MAPPINGS; ++oi) {
617 opacity_mapping[oi] = -1;
618 opacity_gamma[oi] = 1.0f;
619 opacity_is_bipolar[oi] = false;
621 opacity_min[oi] = 0.1f;
622 opacity_max[oi] = 1.0f;
623 }
624
625 for (int si = 0; si < MAX_NR_SIZE_MAPPINGS; ++si) {
626 size_mapping[si] = -1;
627 size_min[si] = 0.1f;
628 size_max[si] = 1.0f;
629 size_gamma[si] = 1.0f;
630 }
631}
633{
634 view_ptr = _view_ptr;
635}
636
637bool plot_base::extract_tick_rectangles_and_tick_labels(
638 std::vector<box2>& R, std::vector<rgb>& C, std::vector<float>& D,
639 std::vector<label_info>& tick_labels, int ai, int ci, int ti, float he,
640 float z_plot, float plot_scale, vec2 plot_offset, float d, bool multi_axis)
641{
643 float acw = 1.5f * ac.line_width * get_domain_config_ptr()->reference_size;
644 tick_config& tc = ti == 0 ? ac.primary_ticks : ac.secondary_ticks;
645 if (tc.type == TT_NONE)
646 return false;
647 float min_tick = ac.tick_space_from_attribute_space(ac.get_attribute_min());
648 float max_tick = ac.tick_space_from_attribute_space(ac.get_attribute_max());
649 int min_i = (int)ceil(min_tick / tc.step - std::numeric_limits<float>::epsilon());
650 int max_i = (int)((max_tick - fmod(max_tick, tc.step)) / tc.step);
651 // ignore secondary ticks on domain boundary
652 if (multi_axis) {
653 if (ti == 1 && min_i * tc.step - min_tick < std::numeric_limits<float>::epsilon())
654 ++min_i;
655 if (ti == 1 && max_i * tc.step - max_tick > -std::numeric_limits<float>::epsilon())
656 --max_i;
657 }
658 float lw = 0.5f * get_domain_config_ptr()->reference_size * tc.line_width;
659 float dl = 0.5f * get_domain_config_ptr()->reference_size * tc.length;
660 for (int i = min_i; i <= max_i; ++i) {
661 float c_tick = (float)(i * tc.step);
662 float c_attr = ac.attribute_space_from_tick_space(c_tick);
663 // ignore ticks on axes
664 if (multi_axis && (fabs(c_attr) < std::numeric_limits<float>::epsilon()))
665 continue;
666 // ignore secondary ticks on primary ticks
667 if (ti == 1 && fabs(fmod(c_tick, ac.primary_ticks.step)) < 0.00001f)
668 continue;
669 std::string label_str;
670 if (tc.label)
671 label_str = cgv::utils::to_string(c_attr);
672 float c_plot = plot_scale*ac.plot_space_from_window_space(ac.window_space_from_tick_space(c_tick))+plot_offset(ci);
673 vec2 mn, mx;
674 mn[ci] = c_plot - lw;
675 mx[ci] = c_plot + lw;
676 switch (tc.type) {
677 case TT_DASH:
678 mn[1 - ci] = -he + plot_offset(1-ci);
679 mx[1 - ci] = -he + dl + plot_offset(1 - ci);
680 R.push_back(box2(mn, mx));
681 C.push_back(ac.color);
682 D.push_back(d);
683 if (!label_str.empty()) {
684 mx[1 - ci] += acw;
685 tick_labels.push_back(label_info(mx.to_vec(), label_str, ci == 0 ? cgv::render::TA_BOTTOM : cgv::render::TA_LEFT));
686 if (ti == 1)
687 tick_labels.back().scale = 0.75f;
688 }
689 if (multi_axis) {
690 mn[1 - ci] = he - dl + plot_offset(1 - ci);
691 mx[1 - ci] = he + plot_offset(1 - ci);
692 R.push_back(box2(mn, mx));
693 C.push_back(ac.color);
694 D.push_back(d);
695 if (!label_str.empty()) {
696 mn[1 - ci] -= acw;
697 tick_labels.push_back(label_info(mn.to_vec(), label_str, ci == 0 ? cgv::render::TA_TOP : cgv::render::TA_RIGHT));
698 if (ti == 1)
699 tick_labels.back().scale = 0.75f;
700 }
701 if (z_plot != std::numeric_limits<float>::quiet_NaN()) {
702 mn[1 - ci] = z_plot - dl + plot_offset(1 - ci);
703 mx[1 - ci] = z_plot + dl + plot_offset(1 - ci);
704 R.push_back(box2(mn, mx));
705 C.push_back(ac.color);
706 D.push_back(d);
707 }
708 }
709 break;
710 case TT_LINE:
711 case TT_PLANE:
712 mn[1 - ci] = -he + plot_offset(1-ci);
713 mx[1 - ci] = he + plot_offset(1-ci);
714 R.push_back(box2(mn, mx));
715 C.push_back(ac.color);
716 D.push_back(d);
717 if (!label_str.empty()) {
718 mn[1 - ci] += acw;
719 mx[1 - ci] -= acw;
720 mn[ci] += 2.5f * lw;
721 mx[ci] += 2.5f * lw;
722 if (multi_axis) {
723 tick_labels.push_back(label_info(mx.to_vec(), label_str, cgv::render::TextAlignment(ci == 0 ? cgv::render::TA_TOP + cgv::render::TA_LEFT : cgv::render::TA_RIGHT + cgv::render::TA_BOTTOM)));
724 if (ti == 1)
725 tick_labels.back().scale = 0.75f;
726 }
727 tick_labels.push_back(label_info(mn.to_vec(), label_str, cgv::render::TextAlignment(ci == 0 ? cgv::render::TA_BOTTOM + cgv::render::TA_LEFT : cgv::render::TA_LEFT + cgv::render::TA_BOTTOM)));
728 if (ti == 1)
729 tick_labels.back().scale = 0.75f;
730
731 }
732 break;
733 }
734 }
735 return true;
736}
737
738void plot_base::extract_legend_tick_rectangles_and_tick_labels(
739 std::vector<box2>& R, std::vector<rgb>& C, std::vector<float>& D,
740 std::vector<label_info>& tick_labels, std::vector<tick_batch_info>& tick_batches, float d,
741 bool clear_cache, bool is_first, bool* multi_axis_modes)
742{
743 if (clear_cache) {
744 tick_labels.clear();
745 tick_batches.clear();
746 }
747 const unsigned nr_lcs = 4;
748 static LegendComponent lcs[nr_lcs] = { LC_PRIMARY_COLOR, LC_PRIMARY_OPACITY, LC_SECONDARY_COLOR, LC_SECONDARY_OPACITY };
749 int ai[nr_lcs] = { color_mapping[0], opacity_mapping[0], color_mapping[1], opacity_mapping[1] };
750 const axis_config* acs[2] = { &get_domain_config_ptr()->axis_configs[0], &get_domain_config_ptr()->axis_configs[1] };
751 vec2 loc0(acs[0]->plot_space_from_window_space(legend_location(0)),
752 acs[1]->plot_space_from_window_space(legend_location(1)));
753 int l = 1 - legend_axis;
754 float main_extent = legend_extent[legend_axis] * acs[legend_axis]->extent;
755 float side_extent = legend_extent[l] * acs[l]->extent;
756 for (unsigned ti = 0; ti < 2; ++ti) {
757 vec2 loc = loc0;
758 for (int j = 0; j < nr_lcs; ++j) {
759
760 if ((legend_components & lcs[j]) != 0) {
761 if (ai[j] == -1)
762 continue;
763 if (multi_axis_modes && !is_first && !multi_axis_modes[ai[j]])
764 continue;
765 tick_batch_info tbi(ai[j], 1 - legend_axis, ti == 0, 0, (unsigned)tick_labels.size());
766 if (extract_tick_rectangles_and_tick_labels(R, C, D, tick_labels, ai[j], legend_axis, ti,
767 0.5f*side_extent, std::numeric_limits<float>::quiet_NaN(), main_extent, loc, d, false)) {
768 if ((tbi.label_count = (unsigned)(tick_labels.size() - tbi.first_label)) > 0)
769 tick_batches.push_back(tbi);
770 }
771 loc[l] += 1.2f*side_extent;
772 }
773 }
774 }
775}
776
777void plot_base::draw_title(cgv::render::context& ctx, vec2 pos, float depth, int si)
778{
779 // enable title font face
781 return;
782 cgv::tt_gl_font_face_ptr ff = dynamic_cast<cgv::tt_gl_font_face*>(&(*title_font_face));
783 if (!ff)
784 return;
785 float rs = 0.2f * get_domain_config_ptr()->reference_size;
786 ctx.enable_font_face(ff, 5 * get_domain_config_ptr()->title_font_size);
787
788 // collect all colored quads
789 std::vector<cgv::render::textured_rectangle> Q;
790 std::vector<rgba> C;
791
792 auto* cfg = get_domain_config_ptr();
793 if (si <= 0 && get_domain_config_ptr()->show_title) {
794 vec2 pos_aligned = ff->align_text(pos, cfg->title, cgv::render::TA_NONE, rs);
795 unsigned cnt = ff->text_to_quads(pos_aligned, cfg->title, Q, rs);
796 for (unsigned j = 0; j < cnt; ++j)
797 C.push_back(cfg->title_color);
798 }
799 if(get_domain_config_ptr()->show_sub_plot_names) {
800 pos[1] -= 5.0f * cfg->title_font_size * rs;
801 for(unsigned i = 0; i < get_nr_sub_plots(); ++i) {
802 if(si != -1 && i != si)
803 continue;
804 const auto& spc = ref_sub_plot_config(i);
805 vec2 pos_aligned = ff->align_text(pos, cfg->title, cgv::render::TA_NONE, rs);
806 unsigned cnt = ff->text_to_quads(pos_aligned, spc.name, Q, 0.8f * rs);
807 for(unsigned j = 0; j < cnt; ++j)
808 C.push_back(spc.ref_color.color);
809 pos[1] -= 4.0f * cfg->title_font_size * rs;
810 }
811 }
812 if (Q.empty())
813 return;
814
816 font_rrs.default_depth_offset = depth;
817 rr.set_render_style(font_rrs);
818 rr.enable_attribute_array_manager(ctx, aam_title);
819 rr.set_textured_rectangle_array(ctx, Q);
820 rr.set_color_array(ctx, C);
821 ff->ref_texture(ctx).enable(ctx);
822 rr.render(ctx, 0, Q.size());
823 ff->ref_texture(ctx).disable(ctx);
824 rr.disable_attribute_array_manager(ctx, aam_title);
825}
826
827void plot_base::draw_tick_labels(cgv::render::context& ctx, cgv::render::attribute_array_manager& aam_ticks,
828 std::vector<label_info>& tick_labels, std::vector<tick_batch_info>& tick_batches, float depth)
829{
830 if (tick_labels.empty() || label_font_face.empty())
831 return;
832
833 cgv::tt_gl_font_face_ptr ff = dynamic_cast<cgv::tt_gl_font_face*>(&(*label_font_face));
834 if (!ff) {
836 for (const auto& tbc : tick_batches) if (tbc.label_count > 0) {
837 ctx.set_color(get_domain_config_ptr()->axis_configs[tbc.ai].color);
838 for (unsigned i = tbc.first_label; i < tbc.first_label + tbc.label_count; ++i) {
839 const label_info& li = tick_labels[i];
840 ctx.set_cursor(li.position, li.label, li.align);
841 ctx.output_stream() << li.label;
842 ctx.output_stream().flush();
843 }
844 }
845 return;
846 }
847 else {
848 float rs = 0.2f * get_domain_config_ptr()->reference_size;
849 ctx.enable_font_face(ff, 5 * get_domain_config_ptr()->label_font_size);
850 std::vector<cgv::render::textured_rectangle> Q;
851 std::vector<rgba> C;
852 for (const auto& tbc : tick_batches) if (tbc.label_count > 0) {
853 for (unsigned i = tbc.first_label; i < tbc.first_label + tbc.label_count; ++i) {
854 const label_info& li = tick_labels[i];
855 vec2 pos = vec2::from_vec(li.position);
856 pos = ff->align_text(pos, li.label, li.align, li.scale * rs);
857 unsigned cnt = ff->text_to_quads(pos, li.label, Q, li.scale * rs);
858 for (unsigned i = 0; i < cnt; ++i)
859 C.push_back(get_domain_config_ptr()->axis_configs[tbc.ai].color);
860 }
861 }
862 if (Q.empty())
863 return;
865 font_rrs.default_depth_offset = depth;
866 rr.set_render_style(font_rrs);
867 rr.enable_attribute_array_manager(ctx, aam_ticks);
868 rr.set_textured_rectangle_array(ctx, Q);
869 rr.set_color_array(ctx, C);
870 ff->ref_texture(ctx).enable(ctx);
871 rr.render(ctx, 0, Q.size());
872 ff->ref_texture(ctx).disable(ctx);
873 rr.disable_attribute_array_manager(ctx, aam_ticks);
874 }
875}
876
877void plot_base::draw_legend(cgv::render::context& ctx, int layer_idx, bool is_first, bool* multi_axis_modes)
878{
879 // draw legend rectangles with legend program
881 legend_prog.set_uniform(ctx, "extent", E);
882 vec3 loc = legend_location;
883 legend_prog.set_uniform(ctx, "legend_extent", legend_extent);
884 aab_legend.enable(ctx);
885 legend_prog.enable(ctx);
886 set_mapping_uniforms(ctx, legend_prog);
889 legend_prog.set_uniform(ctx, "depth_offset", -layer_idx * layer_depth);
890 int j = 1 - legend_axis;
891 int off = 4*j;
892 if ((legend_components & LC_PRIMARY_COLOR) != 0) {
893 if (!multi_axis_modes || is_first || color_mapping[0] == -1 || multi_axis_modes[color_mapping[0]]) {
894 legend_prog.set_uniform(ctx, "legend_location", loc);
895 legend_prog.set_uniform(ctx, "color_index", 0);
896 legend_prog.set_uniform(ctx, "opacity_index", -1);
897 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
898 }
899 loc[j] += 1.2f * legend_extent[j];
900 }
901 if ((legend_components & LC_PRIMARY_OPACITY) != 0) {
902 if (!multi_axis_modes || is_first || opacity_mapping[0] == -1 || multi_axis_modes[opacity_mapping[0]]) {
903 legend_prog.set_uniform(ctx, "legend_location", loc);
904 legend_prog.set_uniform(ctx, "color_index", -1);
905 legend_prog.set_uniform(ctx, "opacity_index", 0);
906 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
907 }
908 loc[j] += 1.2f * legend_extent[j];
909 }
910 if ((legend_components & LC_SECONDARY_COLOR) != 0) {
911 if (!multi_axis_modes || is_first || color_mapping[1] == -1 || multi_axis_modes[color_mapping[1]]) {
912 legend_prog.set_uniform(ctx, "legend_location", loc);
913 legend_prog.set_uniform(ctx, "color_index", 1);
914 legend_prog.set_uniform(ctx, "opacity_index", -1);
915 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
916 }
917 loc[j] += 1.2f * legend_extent[j];
918 }
919 if ((legend_components & LC_SECONDARY_OPACITY) != 0) {
920 if (!multi_axis_modes || is_first || opacity_mapping[0] == -1 || multi_axis_modes[opacity_mapping[1]]) {
921 legend_prog.set_uniform(ctx, "legend_location", loc);
922 legend_prog.set_uniform(ctx, "color_index", -1);
923 legend_prog.set_uniform(ctx, "opacity_index", 1);
924 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
925 }
926 loc[j] += 1.2f * legend_extent[j];
927 }
929 legend_prog.disable(ctx);
930 aab_legend.disable(ctx);
931 // extract tickmark information for legend and draw it
932 std::vector<box2> R;
933 std::vector<rgb> C;
934 std::vector<float> D;
935 ++layer_idx;
936 extract_legend_tick_rectangles_and_tick_labels(R, C, D, legend_tick_labels, legend_tick_batches, -layer_idx*layer_depth, true, is_first, multi_axis_modes);
937 if (R.empty())
938 return;
940 ctx.mul_modelview_matrix(cgv::math::translate4<float>(0.0f, 0.0f, E[2] * (legend_location[2] - 0.5f)));
941 draw_rectangles(ctx, aam_legend, R, C, D);
942 std::string title;
943 rgba title_color;
944 ++layer_idx;
945 draw_tick_labels(ctx, aam_legend_ticks, legend_tick_labels, legend_tick_batches, -layer_idx * layer_depth);
947}
948
950{
951 const auto& acs = get_domain_config_ptr()->axis_configs;
952 return box2(vec2(acs[0].get_attribute_min(),acs[1].get_attribute_min()),
953 vec2(acs[0].get_attribute_max(), acs[1].get_attribute_max()));
954}
956{
957 const auto& acs = get_domain_config_ptr()->axis_configs;
958 return box3(vec3(acs[0].get_attribute_min(), acs[1].get_attribute_min(), get_dim() == 2 ? 0 : acs[2].get_attribute_min()),
959 vec3(acs[0].get_attribute_max(), acs[1].get_attribute_max(), get_dim() == 2 ? 0 : acs[2].get_attribute_max()));
960}
962{
963 auto& acs = get_domain_config_ptr()->axis_configs;
964 acs[0].set_attribute_range(dom.get_min_pnt()(0), dom.get_max_pnt()(0));
965 acs[1].set_attribute_range(dom.get_min_pnt()(1), dom.get_max_pnt()(1));
966}
968{
969 auto& acs = get_domain_config_ptr()->axis_configs;
970 unsigned n = std::min(get_dim(), 3u);
971 for (unsigned ai = 0; ai < n; ++ai)
972 acs[ai].set_attribute_range(dom.get_min_pnt()(ai), dom.get_max_pnt()(ai));
973}
975{
976 const auto& acs = get_domain_config_ptr()->axis_configs;
978 for (unsigned ai = 0; ai < get_dim(); ++ai)
979 extent(ai) = acs[ai].extent;
980 return extent;
981}
982void plot_base::set_extent(const vecn& new_extent)
983{
984 auto& acs = get_domain_config_ptr()->axis_configs;
985 unsigned n = std::min(get_dim(), new_extent.size());
986 for (unsigned ai = 0; ai < n; ++ai)
987 acs[ai].extent = new_extent(ai);
988}
989
990void plot_base::set_extent_scaling(float x_scale, float y_scale, float z_scale)
991{
992 auto& acs = get_domain_config_ptr()->axis_configs;
993 acs[0].extent_scaling = x_scale;
994 acs[1].extent_scaling = y_scale;
995 if (get_dim() > 2)
996 acs[2].extent_scaling = z_scale;
997}
998
999void plot_base::set_width(float new_width, bool constrained)
1000{
1001 auto& acs = get_domain_config_ptr()->axis_configs;
1002 acs[0].extent = new_width;
1003 if (constrained) {
1004 acs[1].extent = new_width *
1005 (acs[1].tick_space_from_attribute_space(acs[1].get_attribute_max()) - acs[1].tick_space_from_attribute_space(acs[1].get_attribute_max())) /
1006 (acs[0].tick_space_from_attribute_space(acs[0].get_attribute_max()) - acs[0].tick_space_from_attribute_space(acs[0].get_attribute_max()));
1007 }
1008}
1009void plot_base::set_height(float new_height, bool constrained)
1010{
1011 auto& acs = get_domain_config_ptr()->axis_configs;
1012 acs[1].extent = new_height;
1013 if (constrained) {
1014 acs[0].extent = new_height *
1015 (acs[0].tick_space_from_attribute_space(acs[0].get_attribute_max()) - acs[0].tick_space_from_attribute_space(acs[0].get_attribute_max())) /
1016 (acs[1].tick_space_from_attribute_space(acs[1].get_attribute_max()) - acs[1].tick_space_from_attribute_space(acs[1].get_attribute_max()));
1017 }
1018}
1020{
1021 orientation = q;
1022}
1023void plot_base::place_origin(const vec3& new_origin_location)
1024{
1025 center_location += new_origin_location - get_origin();
1026}
1027void plot_base::place_center(const vec3& new_center_location)
1028{
1029 center_location = new_center_location;
1030}
1031void plot_base::place_corner(unsigned corner_index, const vec3& new_corner_location)
1032{
1033 center_location += new_corner_location - get_corner(corner_index);
1034}
1036{
1037 return transform_to_world(get_domain3().get_min_pnt().to_vec());
1038}
1040{
1041 return orientation;
1042}
1044{
1045 return center_location;
1046}
1048{
1049 box3 B = get_domain3();
1050 vec3 c3 = B.get_corner(i);
1051 vecn c(get_dim());
1052 for (unsigned j = 0; j < get_dim(); ++j)
1053 c(j) = c3(j);
1054 return transform_to_world(c);
1055}
1056const vec3 plot_base::get_axis_direction(unsigned ai) const
1057{
1058 vec3 a(0.0f);
1059 a(ai) = 1.0f;
1060 return orientation.apply(a);
1061}
1062
1063bool plot_base::determine_axis_extent_from_subplot(unsigned ai, unsigned i, float& samples_min, float& samples_max)
1064{
1065 if (attribute_source_arrays.size() <= i)
1066 return false;
1067 if (attribute_source_arrays[i].attribute_sources.size() <= ai)
1068 return false;
1069 const attribute_source& as = attribute_source_arrays[i].attribute_sources[ai];
1070 if (as.source == AS_NONE)
1071 return false;
1072 bool new_found_sample = false;
1073 float new_samples_min, new_samples_max;
1074 switch (as.source) {
1075 case AS_SAMPLE_CONTAINER:
1076 {
1077 int j = as.sub_plot_index == -1 ? i : as.sub_plot_index;
1078 new_found_sample = compute_sample_coordinate_interval(j, (int)as.offset, new_samples_min, new_samples_max);
1079 break;
1080 }
1081 case AS_POINTER:
1082 {
1083 const float* ptr = as.pointer;
1084 for (unsigned j = 0; j < as.count; ++j) {
1085 if (new_found_sample) {
1086 new_samples_min = std::min(new_samples_min, *ptr);
1087 new_samples_max = std::max(new_samples_max, *ptr);
1088 }
1089 else {
1090 new_samples_min = new_samples_max = *ptr;
1091 new_found_sample = true;
1092 }
1093 reinterpret_cast<const char*&>(ptr) += as.stride;
1094 }
1095 break;
1096 }
1097 case AS_VBO:
1098 return false;
1099 }
1100 if (!new_found_sample)
1101 return false;
1102
1103 samples_min = new_samples_min;
1104 samples_max = new_samples_max;
1105 return true;
1106}
1107
1108void plot_base::adjust_domain_axis_to_data(unsigned ai, bool adjust_min, bool adjust_max, bool only_visible)
1109{
1110 bool found_sample = false;
1111 float samples_min, samples_max;
1112 for (unsigned i = 0; i < configs.size(); ++i) {
1113 if (only_visible && !ref_sub_plot_config(i).show_plot)
1114 continue;
1115 float new_samples_min, new_samples_max;
1116 if (determine_axis_extent_from_subplot(ai, i, new_samples_min, new_samples_max)) {
1117 if (found_sample) {
1118 samples_min = std::min(samples_min, new_samples_min);
1119 samples_max = std::max(samples_max, new_samples_max);
1120 }
1121 else {
1122 samples_min = new_samples_min;
1123 samples_max = new_samples_max;
1124 found_sample = true;
1125 }
1126 }
1127 }
1128 auto& acs = get_domain_config_ptr()->axis_configs;
1129 if (!found_sample) {
1130 if (adjust_min)
1131 acs[ai].set_attribute_minimum(0.0f);
1132 if (adjust_max)
1133 acs[ai].set_attribute_maximum(1.0f);
1134 return;
1135 }
1136 if (adjust_min)
1137 acs[ai].set_attribute_minimum(samples_min);
1138 if (adjust_max)
1139 acs[ai].set_attribute_maximum(samples_max);
1140 if (acs[ai].get_attribute_min() == acs[ai].get_attribute_max())
1141 acs[ai].set_attribute_maximum(acs[ai].get_attribute_max() + 1);
1142}
1143
1144void plot_base::adjust_tick_marks(unsigned max_nr_secondary_ticks, bool adjust_to_attribute_ranges)
1145{
1146 auto& acs = get_domain_config_ptr()->axis_configs;
1147 for (unsigned ai = 0; ai < acs.size(); ++ai) {
1148 acs[ai].adjust_tick_marks_to_range(max_nr_secondary_ticks);
1149 if (!adjust_to_attribute_ranges && ai + 1 == get_dim())
1150 break;
1151 }
1152}
1154{
1155 auto& acs = get_domain_config_ptr()->axis_configs;
1156 for (int ai = 0; ai < (int)get_dim(); ++ai) {
1157 if (ai == preserve_ai)
1158 continue;
1159 acs[ai].extent = acs[preserve_ai].extent*acs[ai].get_attribute_extent()/acs[preserve_ai].get_attribute_extent();
1160 }
1161}
1163{
1164 auto& acs = get_domain_config_ptr()->axis_configs;
1165 for (unsigned aj = 0; aj < get_dim(); ++aj) {
1166 if (aj == ai)
1167 continue;
1168 if (acs[aj].get_attribute_min() > 0)
1169 acs[aj].set_attribute_minimum(0);
1170 if (acs[aj].get_attribute_max() < 0)
1171 acs[aj].set_attribute_maximum(0);
1172 }
1173}
1175{
1176 unsigned n = unsigned(get_domain_config_ptr()->axis_configs.size());
1177 for (unsigned ai=0; ai < n; ++ai)
1178 adjust_domain_axis_to_data(ai, true, true, only_visible);
1179}
1180void plot_base::set_label_font(float font_size, cgv::media::font::FontFaceAttributes ffa, const std::string& font_name)
1181{
1184 if (!font_name.empty()) {
1185 for (auto iter = font_names.begin(); iter != font_names.end(); ++iter)
1186 if (font_name == *iter) {
1187 get_domain_config_ptr()->label_font_index = (unsigned)(iter - font_names.begin());
1189 break;
1190 }
1191 }
1192 else
1194}
1195
1197{
1198 return dom_cfg_ptr;
1199}
1205{
1206 if (_new_ptr)
1207 dom_cfg_ptr = _new_ptr;
1208 else
1210}
1212{
1213 return (unsigned) configs.size();
1214}
1216{
1217 return *configs[i];
1218}
1220{
1221 attribute_source_arrays[i].samples_out_of_date = true;
1222}
1223void plot_base::set_sub_plot_colors(unsigned i, const rgb& base_color)
1224{
1225 ref_sub_plot_config(i).set_colors(base_color);
1226}
1227
1228bool plot_base::set_color_scale(int mapping_index, int color_scheme_index)
1229{
1230 bool success = false;
1231 if(mapping_index < MAX_NR_COLOR_MAPPINGS) {
1232 const cgv::media::continuous_color_scheme_registry& registry = cgv::media::get_global_continuous_color_scheme_registry();
1233 if(color_scheme_index > -1 && static_cast<size_t>(color_scheme_index) < registry.size()) {
1234 this->color_scheme_index[mapping_index] = color_scheme_index;
1236 success = true;
1237 } else {
1238 this->color_scheme_index[mapping_index] = -1;
1239 }
1240
1241 // Todo: How to update the GUI? Ideally we would just update the affected member control but we don't have access to the provider. So for now we ignore it.
1242 //update_member(&color_scale_index2[mapping_index]);
1243 }
1244 return success;
1245}
1246
1247bool plot_base::set_color_scale(int mapping_index, const std::string& color_scheme_name)
1248{
1249 const cgv::media::continuous_color_scheme_registry& registry = cgv::media::get_global_continuous_color_scheme_registry();
1250 auto it = registry.find(color_scheme_name);
1251 int index = -1;
1252 if(it != registry.end())
1253 index = std::distance(registry.begin(), it);
1254 return set_color_scale(mapping_index, index);
1255}
1256
1258{
1259 font_rrs = cgv::ref_rectangle_render_style();
1262 aam_title.init(ctx);
1263 aam_legend.init(ctx);
1264 aam_legend_ticks.init(ctx);
1265 if (!legend_prog.build_program(ctx, "plot_legend.glpr", true)) {
1266 std::cerr << "could not build GLSL program from plot_legend.glpr" << std::endl;
1267 return false;
1268 }
1269 // construct legend vbo and aab
1270 std::vector<vec4> P;
1271 P.push_back(vec4(-0.5f, -0.5f, 0.0f, 0.0f));
1272 P.push_back(vec4( 0.5f, -0.5f, 0.0f, 0.0f));
1273 P.push_back(vec4(-0.5f, 0.5f, 0.0f, 1.0f));
1274 P.push_back(vec4( 0.5f, 0.5f, 0.0f, 1.0f));
1275 P.push_back(vec4(-0.5f, -0.5f, 0.0f, 0.0f));
1276 P.push_back(vec4(0.5f, -0.5f, 0.0f, 1.0f));
1277 P.push_back(vec4(-0.5f, 0.5f, 0.0f, 0.0f));
1278 P.push_back(vec4(0.5f, 0.5f, 0.0f, 1.0f));
1279 vbo_legend.create(ctx, P);
1280 aab_legend.create(ctx);
1281 int pos_idx = legend_prog.get_attribute_location(ctx, "position");
1282 int val_idx = legend_prog.get_attribute_location(ctx, "value");
1283 aab_legend.enable_array(ctx, pos_idx);
1284 aab_legend.enable_array(ctx, val_idx);
1285 vec3& p0 = reinterpret_cast<vec3&>(P[0]);
1286 float& v0 = P[0][3];
1287 aab_legend.set_attribute_array(ctx, pos_idx, cgv::render::get_element_type(p0), vbo_legend, 0, P.size(), sizeof(vec4));
1288 aab_legend.set_attribute_array(ctx, val_idx, cgv::render::get_element_type(v0), vbo_legend, sizeof(vec3), P.size(), sizeof(vec4));
1290 return true;
1291}
1292
1294{
1296 aam_title.destruct(ctx);
1297 aam_legend.destruct(ctx);
1298 aam_legend_ticks.destruct(ctx);
1299 aab_legend.destruct(ctx);
1300 vbo_legend.destruct(ctx);
1301 legend_prog.destruct(ctx);
1302 for (unsigned i = 0; i < get_nr_sub_plots(); ++i) {
1303 attribute_source_arrays[i].aab.destruct(ctx);
1304 attribute_source_arrays[i].vbo.destruct(ctx);
1305 }
1307}
1308
1310{
1312 p.add_member_control(bp, "Reference Size", get_domain_config_ptr()->reference_size, "value_slider", "min=0.0001;step=0.00001;max=1;log=true;ticks=true");
1313 p.add_member_control(bp, "Blend Width (px)", get_domain_config_ptr()->blend_width_in_pixel, "value_slider", "min=0.0001;step=0.0;max=3.0;ticks=true");
1314
1315 if (p.begin_tree_node("Visual Variables", dim, false, "level=3")) {
1316 std::string attribute_enums = "off=-1";
1317 for (unsigned ai = 0; ai < get_dim() + nr_attributes; ++ai)
1318 attribute_enums += std::string(",")+get_domain_config_ptr()->axis_configs[ai].name;
1319 std::string dropdown_options("w=92;enums='" + attribute_enums + "'");
1320 p.align("\a");
1321 bool show;
1322 unsigned nr = std::max(MAX_NR_COLOR_MAPPINGS, std::max(MAX_NR_SIZE_MAPPINGS, MAX_NR_OPACITY_MAPPINGS));
1323 static const char* prefixes[] = { "Primary ", "Secondary ", "Ternary " };
1324 for (unsigned idx = 0; idx < nr; ++idx) {
1325 std::string prefix(prefixes[idx]);
1326 if (idx < MAX_NR_COLOR_MAPPINGS) {
1327 show = p.begin_tree_node(prefix + "Color", color_mapping[idx], false, "level=3;align=' ';options='w=100'");
1328 p.add_member_control(bp, "", (cgv::type::DummyEnum&)color_mapping[idx], "dropdown", dropdown_options);
1329 if (show) {
1330 p.align("\a");
1331 const auto& connect_color_scale_callback = [this](auto control) {
1332 cgv::signal::connect_copy(
1333 control->value_change,
1334 cgv::signal::rebind(this, &plot_base::update_color_scales)
1335 );
1336 };
1337 std::string color_scheme_enums = cgv::utils::join(cgv::media::get_global_continuous_color_scheme_registry().get_names(), ",");
1338 connect_color_scale_callback(p.add_member_control(bp, prefix + "Color Scale", reinterpret_cast<cgv::type::DummyEnum&>(color_scheme_index[idx]), "dropdown", "enums='" + color_scheme_enums + "'"));
1339 connect_color_scale_callback(p.add_member_control(bp, prefix + "Color Gamma", color_scale_gamma[idx], "value_slider", "min=0.1;step=0.01;max=10;log=true;ticks=true"));
1340 connect_color_scale_callback(p.add_member_control(bp, prefix + "Reversed", reversed[idx], "check"));
1341 connect_color_scale_callback(p.add_member_control(bp, prefix + "Color Is Bipolar", color_scale_is_bipolar[idx], "check"));
1342 connect_color_scale_callback(p.add_member_control(bp, prefix + "Window Zero Position", window_zero_position[idx], "value_slider", "min=0;max=1;ticks=true"));
1343 p.align("\b");
1345 }
1346 }
1347 if (idx < MAX_NR_OPACITY_MAPPINGS) {
1348 show = p.begin_tree_node(prefix + "Opacity", opacity_mapping[idx], false, "level=3;align=' ';options='w=100'");
1349 p.add_member_control(bp, "", (cgv::type::DummyEnum&)opacity_mapping[idx], "dropdown", dropdown_options);
1350 if (show) {
1351 p.align("\a");
1352 p.add_member_control(bp, prefix + "Opacity Gamma", opacity_gamma[idx], "value_slider", "min=0.1;step=0.01;max=10;log=true;ticks=true");
1353 p.add_member_control(bp, prefix + "Opacity Is Bipolar", opacity_is_bipolar[idx], "check");
1354 p.add_member_control(bp, prefix + "Opacity Window Zero Position", opacity_window_zero_position[idx], "value_slider", "min=0;max=1;ticks=true");
1355 p.add_member_control(bp, prefix + "Opacity Min", opacity_min[idx], "value_slider", "min=0;step=0.01;max=1;ticks=true");
1356 p.add_member_control(bp, prefix + "Opacity Max", opacity_max[idx], "value_slider", "min=0;step=0.01;max=1;ticks=true");
1357 p.align("\b");
1359 }
1360 }
1361 if (idx < MAX_NR_SIZE_MAPPINGS) {
1362 show = p.begin_tree_node(prefix + "Size", size_mapping[idx], false, "level=3;align=' ';options='w=100'");
1363 p.add_member_control(bp, "", (cgv::type::DummyEnum&)size_mapping[idx], "dropdown", dropdown_options);
1364 if (show) {
1365 p.align("\a");
1366 p.add_member_control(bp, prefix + "Size Gamma", size_gamma[idx], "value_slider", "min=0.1;step=0.01;max=10;log=true;ticks=true");
1367 p.add_member_control(bp, prefix + "Size Min", size_min[idx], "value_slider", "min=0.1;step=0.01;max=10;log=true;ticks=true");
1368 p.add_member_control(bp, prefix + "Size Max", size_max[idx], "value_slider", "min=0.1;step=0.01;max=10;log=true;ticks=true");
1369 p.align("\b");
1371 }
1372 }
1373 }
1374 p.align("\b");
1375 p.end_tree_node(dim);
1376 }
1377 if (p.begin_tree_node("Legend", legend_components, false, "level=3")) {
1378 p.align("\a");
1379 p.add_member_control(bp, "Legend Color", legend_color);
1380 p.add_gui("Legend Components", legend_components, "bit_field_control", "enums='Primary Color=1,Secondary Color=2,Primary Opacity=4,Secondary Opacity=8,Primary Size=16,Secondary Size=32'");
1381 p.add_gui("Center", legend_location, "vector", "main_label='heading';gui_type='value_slider';options='min=-1.2;max=1.2;log=true;ticks=true'");
1382 p.add_gui("Extent", legend_extent, "vector", "main_label='heading';gui_type='value_slider';options='min=0.01;max=10;step=0.001;log=true;ticks=true'");
1383 p.add_member_control(bp, "Axis", legend_axis, "value_slider", "min=0;max=1");
1384 connect_copy(p.find_control(legend_axis)->value_change,
1385 cgv::signal::rebind(this, &plot_base::on_legend_axis_change,cgv::signal::_r(p),cgv::signal::_1));
1386
1387 p.align("\b");
1389 }
1390
1391 if (p.begin_tree_node("Placement", center_location, false, "level=3")) {
1392 p.align("\a");
1393 p.add_gui("Center", center_location, "vector", "main_label='heading';gui_type='value_slider';options='min=-100;max=100;log=true;ticks=true'");
1394 p.add_gui("Orientation", reinterpret_cast<vec4&>(orientation), "direction", "main_label='heading';gui_type='value_slider'");
1395 p.align("\b");
1397 }
1398 bool open = p.begin_tree_node("Domain", get_domain_config_ptr()->show_domain, false, "level=3;options='w=107';align=' '");
1399 p.add_member_control(bp, "Fill", get_domain_config_ptr()->fill, "toggle", "w=40", "%x+=1");
1400 p.add_member_control(bp, "Show", get_domain_config_ptr()->show_domain, "toggle", "w=40");
1401 if (open) {
1402 p.align("\a");
1403 p.add_member_control(bp, "Out of Range Mode X", (cgv::type::DummyEnum&)out_of_range_mode[0], "dropdown", "enums='Keep,Discard,Clamp'");
1404 p.add_member_control(bp, "Out of Range Mode Y", (cgv::type::DummyEnum&)out_of_range_mode[1], "dropdown", "enums='Keep,Discard,Clamp'");
1405 if (get_dim() == 2) {
1406 p.add_member_control(bp, "Out of Range Mode A0", (cgv::type::DummyEnum&)out_of_range_mode[2], "dropdown", "enums='Keep,Discard,Clamp'");
1407 p.add_member_control(bp, "Out of Range Mode A1", (cgv::type::DummyEnum&)out_of_range_mode[3], "dropdown", "enums='Keep,Discard,Clamp'");
1408 }
1409 else {
1410 p.add_member_control(bp, "Out of Range Mode Z", (cgv::type::DummyEnum&)out_of_range_mode[2], "dropdown", "enums='Keep,Discard,Clamp'");
1411 p.add_member_control(bp, "Out of Range Mode A", (cgv::type::DummyEnum&)out_of_range_mode[3], "dropdown", "enums='Keep,Discard,Clamp'");
1412 }
1413 p.add_member_control(bp, "Fill Color", get_domain_config_ptr()->color);
1414 for (unsigned i = 0; i < get_domain_config_ptr()->axis_configs.size(); ++i)
1415 get_domain_config_ptr()->axis_configs[i].create_gui(bp, p);
1417 p.add_member_control(bp, "Show Title", get_domain_config_ptr()->show_title, "toggle", "w=99", "%x+=1");
1418 p.add_member_control(bp, "Show Names", get_domain_config_ptr()->show_sub_plot_names, "toggle", "w=100");
1419 p.add_member_control(bp, "Title Pos X", get_domain_config_ptr()->title_pos[0], "value_slider", "min=-1;max=1;step=0.02;ticks=true");
1420 p.add_member_control(bp, "Title Pos Y", get_domain_config_ptr()->title_pos[1], "value_slider", "min=-1;max=1;step=0.02;ticks=true");
1421 if (get_dim() == 3)
1422 p.add_member_control(bp, "Title Pos Z", get_domain_config_ptr()->title_pos[2], "value_slider", "min=-1;max=1;step=0.02;ticks=true");
1423 p.add_member_control(bp, "Title Font Size", get_domain_config_ptr()->title_font_size, "value_slider", "min=8;max=40;log=false;ticks=true");
1425 connect_copy(p.find_control((cgv::type::DummyEnum&)get_domain_config_ptr()->title_font_index)->value_change,
1426 cgv::signal::rebind(this, &plot_base::on_font_selection));
1427 p.add_member_control(bp, "Title Font Face", get_domain_config_ptr()->title_ffa, "dropdown", "enums='Regular,Bold,Italics,Bold Italics'");
1428 connect_copy(p.find_control(get_domain_config_ptr()->title_ffa)->value_change,
1429 cgv::signal::rebind(this, &plot_base::on_font_face_selection));
1430
1431 p.add_member_control(bp, "Label Font Size", get_domain_config_ptr()->label_font_size, "value_slider", "min=8;max=40;log=false;ticks=true");
1432 p.add_member_control(bp, "Label Font", (cgv::type::DummyEnum&)get_domain_config_ptr()->label_font_index, "dropdown", font_name_enum_def);
1433 connect_copy(p.find_control((cgv::type::DummyEnum&)get_domain_config_ptr()->label_font_index)->value_change,
1434 cgv::signal::rebind(this, &plot_base::on_font_selection));
1435 p.add_member_control(bp, "Label Font Face", get_domain_config_ptr()->label_ffa, "dropdown", "enums='Regular,Bold,Italics,Bold Italics'");
1436 connect_copy(p.find_control(get_domain_config_ptr()->label_ffa)->value_change,
1437 cgv::signal::rebind(this, &plot_base::on_font_face_selection));
1438 p.align("\b");
1439 p.end_tree_node(get_domain_config_ptr()->show_domain);
1440 }
1441 if (p.begin_tree_node("Rectangle", rrs, false, "level=3")) {
1442 p.align("\a");
1443 p.add_member_control(bp, "Layer Depth", layer_depth, "value_slider", "min=0.000001;max=0.01;step=0.0000001;log=true;ticks=true");
1444 p.add_gui("Rectangle Style", rrs);
1445 p.align("\b");
1446 p.end_tree_node(rrs);
1447 }
1448}
1449void plot_base::update_ref_opacity(unsigned i, cgv::gui::provider& p)
1450{
1452 pbc.set_opacities(pbc.ref_opacity.opacity);
1453 p.update_member(&pbc.point_color.color.alpha());
1454 p.update_member(&pbc.point_halo_color.color.alpha());
1455 p.update_member(&pbc.line_color.color.alpha());
1456 p.update_member(&pbc.line_halo_color.color.alpha());
1457 p.update_member(&pbc.stick_color.color.alpha());
1458 p.update_member(&pbc.bar_color.color.alpha());
1459 p.update_member(&pbc.bar_outline_color.color.alpha());
1460}
1461void plot_base::update_ref_opacity_index(unsigned i, cgv::gui::provider& p)
1462{
1463 plot_base_config& pbc = ref_sub_plot_config(i);
1464 pbc.set_opacity_indices(pbc.ref_opacity.opacity_idx);
1465 p.update_member(&pbc.point_color.opacity_idx);
1466 p.update_member(&pbc.point_halo_color.opacity_idx);
1467 p.update_member(&pbc.line_color.opacity_idx);
1468 p.update_member(&pbc.line_halo_color.opacity_idx);
1469 p.update_member(&pbc.stick_color.opacity_idx);
1470 p.update_member(&pbc.bar_color.opacity_idx);
1471 p.update_member(&pbc.bar_outline_color.opacity_idx);
1472}
1473void plot_base::update_ref_color(unsigned i, cgv::gui::provider& p)
1474{
1475 plot_base_config& pbc = ref_sub_plot_config(i);
1476 pbc.set_colors(pbc.ref_color.color);
1477 p.update_member(&pbc.point_color.color);
1478 p.update_member(&pbc.point_halo_color.color);
1479 p.update_member(&pbc.line_color.color);
1480 p.update_member(&pbc.line_halo_color.color);
1481 p.update_member(&pbc.stick_color.color);
1482 p.update_member(&pbc.bar_color.color);
1483 p.update_member(&pbc.bar_outline_color.color);
1484}
1485void plot_base::update_ref_color_index(unsigned i, cgv::gui::provider& p)
1486{
1487 plot_base_config& pbc = ref_sub_plot_config(i);
1488 pbc.set_color_indices(pbc.ref_color.color_idx);
1489 p.update_member(&pbc.point_color.color_idx);
1490 p.update_member(&pbc.point_halo_color.color_idx);
1491 p.update_member(&pbc.line_color.color_idx);
1492 p.update_member(&pbc.line_halo_color.color_idx);
1493 p.update_member(&pbc.stick_color.color_idx);
1494 p.update_member(&pbc.bar_color.color_idx);
1495 p.update_member(&pbc.bar_outline_color.color_idx);
1496}
1497void plot_base::update_ref_size(unsigned i, cgv::gui::provider& p)
1498{
1499 plot_base_config& pbc = ref_sub_plot_config(i);
1500 pbc.set_sizes(pbc.ref_size.size);
1501 p.update_member(&pbc.point_size.size);
1502 p.update_member(&pbc.point_halo_width.size);
1503 p.update_member(&pbc.line_width.size);
1504 p.update_member(&pbc.stick_width.size);
1505 p.update_member(&pbc.bar_outline_width.size);
1506}
1507void plot_base::update_ref_size_index(unsigned i, cgv::gui::provider& p)
1508{
1509 plot_base_config& pbc = ref_sub_plot_config(i);
1510 p.update_member(&pbc.point_size.size_idx);
1511 p.update_member(&pbc.point_halo_width.size_idx);
1512 p.update_member(&pbc.line_width.size_idx);
1513 p.update_member(&pbc.line_halo_width.size_idx);
1514 p.update_member(&pbc.stick_width.size_idx);
1515 p.update_member(&pbc.bar_outline_width.size_idx);
1516}
1518{
1520 p.add_member_control(bp, "Name", pbc.name);
1521 p.add_gui("Sub Plot Influence", pbc.sub_plot_influence, "bit_field_control",
1522 "gui_type='toggle';align='%x+=1';options='w=32;x=2';enums='Pnt=1,Halo=2,Line=4,Stk=8,Bar=16,Out=32'");
1523 p.align("\n");
1524 connect_copy(p.add_member_control(bp, "Color", pbc.ref_color.color, "", "w=100", " ")->value_change,
1525 cgv::signal::rebind(this, &plot_base::update_ref_color, cgv::signal::_c(i), cgv::signal::_r(p)));
1526 connect_copy(p.add_member_control(bp, "", (cgv::type::DummyEnum&)pbc.ref_color.color_idx, "dropdown", "w=88;enums='Off=-1,Primary=0,Secondary=1'")->value_change,
1527 cgv::signal::rebind(this, &plot_base::update_ref_color_index, cgv::signal::_c(i), cgv::signal::_r(p)));
1528
1529 connect_copy(p.add_member_control(bp, "Opacity", pbc.ref_opacity.opacity, "value_slider", "min=0;max=1;ticks=true;w=100", " ")->value_change,
1530 cgv::signal::rebind(this, &plot_base::update_ref_opacity, cgv::signal::_c(i), cgv::signal::_r(p)));
1531 connect_copy(p.add_member_control(bp, "", (cgv::type::DummyEnum&)pbc.ref_opacity.opacity_idx, "dropdown", "w=88;enums='Off=-1,Primary=0,Secondary=1'")->value_change,
1532 cgv::signal::rebind(this, &plot_base::update_ref_opacity_index, cgv::signal::_c(i), cgv::signal::_r(p)));
1533
1534 connect_copy(p.add_member_control(bp, "Size", pbc.ref_size.size, "value_slider", "min=1;max=20;log=true;ticks=true;w=100", " ")->value_change,
1535 cgv::signal::rebind(this, &plot_base::update_ref_size, cgv::signal::_c(i), cgv::signal::_r(p)));
1536 connect_copy(p.add_member_control(bp, "", (cgv::type::DummyEnum&)pbc.ref_size.size_idx, "dropdown", "w=88;enums='Off=-1,Primary=0,Secondary=1'")->value_change,
1537 cgv::signal::rebind(this, &plot_base::update_ref_size_index, cgv::signal::_c(i), cgv::signal::_r(p)));
1538
1539 p.add_member_control(bp, "Begin", pbc.begin_sample, "value_slider", "min=0;ticks=true")->set("max", attribute_source_arrays[i].attribute_sources.front().count - 1);
1540 p.add_member_control(bp, "End", pbc.end_sample, "value_slider", "min=-1;ticks=true")->set("max", attribute_source_arrays[i].attribute_sources.front().count - 1);
1541}
1542void add_mapped_size_control(cgv::gui::provider& p, cgv::base::base* bp, const std::string& name, mapped_size& ms, std::string options)
1543{
1544 if (options.empty())
1545 options = "min=1;max=20;log=true;ticks=true;w=120";
1546 else
1547 options += ";w=120";
1548 p.add_member_control(bp, name, ms.size, "value_slider", options, " ");
1549 p.add_member_control(bp, "Si", (cgv::type::DummyEnum&)ms.size_idx, "dropdown", "enums='Off=-1,Primary,Secondary';w=58;tooltip='Size mapping index'");
1550}
1551void add_mapped_rgb_control(cgv::gui::provider& p, cgv::base::base* bp, const std::string& name, mapped_rgb& ms)
1552{
1553 p.add_member_control(bp, name, ms.color, "", "w=80", " ");
1554 p.add_member_control(bp, "Ci", (cgv::type::DummyEnum&)ms.color_idx, "dropdown", "enums='Off=-1,Primary,Secondary';w=58;tooltip='Color mapping index'");
1555}
1556void add_mapped_rgba_control(cgv::gui::provider& p, cgv::base::base* bp, const std::string& name, mapped_rgba& ms)
1557{
1558 p.add_member_control(bp, name, ms.color, "", "w=36", " ");
1559 p.add_member_control(bp, "Ci", (cgv::type::DummyEnum&)ms.color_idx, "dropdown", "enums='Off=-1,Primary,Secondary';w=58;tooltip='Color mapping index'", " ");
1560 p.add_member_control(bp, "Oi", (cgv::type::DummyEnum&)ms.opacity_idx, "dropdown", "enums='Off=-1,Primary,Secondary';w=58;tooltip='Opacity mapping index'");
1561}
1562void add_mapped_opacity_control(cgv::gui::provider& p, cgv::base::base* bp, const std::string& name, mapped_opacity& ms)
1563{
1564 p.add_member_control(bp, name, ms.opacity, "", "w=80", " ");
1565 p.add_member_control(bp, "Oi", (cgv::type::DummyEnum&)ms.opacity_idx, "dropdown", "enums='Off=-1,Primary,Secondary';w=58;tooltip='Opacity mapping index'");
1566}
1568{
1569 add_mapped_rgba_control(p, bp, "Color", pbc.point_color);
1570 add_mapped_rgba_control(p, bp, "Halo Color", pbc.point_halo_color);
1571 add_mapped_size_control(p, bp, "Size", pbc.point_size);
1572 add_mapped_size_control(p, bp, "Halo Width", pbc.point_halo_width, "min=-8;max=8;ticks=true");
1573}
1575{
1576 add_mapped_rgba_control(p, bp, "Color", pbc.line_color);
1577 add_mapped_rgba_control(p, bp, "Halo Color", pbc.line_halo_color);
1578 add_mapped_size_control(p, bp, "Width", pbc.line_width);
1579 add_mapped_size_control(p, bp, "Halo Width", pbc.line_halo_width, "min=0;max=20;log=true;ticks=true");
1580}
1582{
1583 p.add_member_control(bp, "Coordinate Index", pbc.stick_coordinate_index, "value_slider", "min=0;max=1;ticks=true")
1584 ->set("max", get_dim()-1);
1585 p.add_member_control(bp, "Base", pbc.stick_base_window, "value_slider", "min=0;max=1;ticks=true");
1586 add_mapped_rgba_control(p, bp, "Color", pbc.stick_color);
1587 add_mapped_size_control(p, bp, "Width", pbc.stick_width);
1588}
1590{
1591 p.add_member_control(bp, "Coordinate Index", pbc.bar_coordinate_index, "value_slider", "min=0;max=1;ticks=true")
1592 ->set("max", get_dim() - 1);
1593 p.add_member_control(bp, "Base", pbc.bar_base_window, "value_slider", "min=0;max=1;ticks=true");
1594 add_mapped_rgba_control(p, bp, "Color", pbc.bar_color);
1595 add_mapped_rgba_control(p, bp, "Outline", pbc.bar_outline_color);
1596 add_mapped_size_control(p, bp, "Outline Width", pbc.bar_outline_width, "min=0;max=20;log=true;ticks=true");
1597 add_mapped_size_control(p, bp, "Width", pbc.bar_percentual_width, "min=0.0;max=1.05;log=true;ticks=true");
1598}
1600{
1602 bool show = p.begin_tree_node("General", pbc.show_plot, true, "level=3;options='w=142'");
1603 if (show) {
1604 p.align("\a");
1605 create_base_config_gui(bp, p, i);
1606 p.align("\b");
1607 p.end_tree_node(pbc.show_plot);
1608 }
1609 show = p.begin_tree_node("Points", pbc.show_points, false, "level=3;options='w=142';align=' '");
1610 p.add_member_control(bp, "Show", pbc.show_points, "toggle", "w=50");
1611 if (show) {
1612 p.align("\a");
1613 create_point_config_gui(bp, p, pbc);
1614 p.align("\b");
1616 }
1617 show = p.begin_tree_node("Lines", pbc.show_lines, false, "level=3;options='w=142';align=' '");
1618 p.add_member_control(bp, "Show", pbc.show_lines, "toggle", "w=50");
1619 if (show) {
1620 p.align("\a");
1621 create_line_config_gui(bp, p, pbc);
1622 p.align("\b");
1624 }
1625 show = p.begin_tree_node("Sticks", pbc.show_sticks, false, "level=3;options='w=142';align=' '");
1626 p.add_member_control(bp, "Show", pbc.show_sticks, "toggle", "w=50");
1627 if (show) {
1628 p.align("\a");
1629 create_stick_config_gui(bp, p, pbc);
1630 p.align("\b");
1632 }
1633 show = p.begin_tree_node("Bars", pbc.show_bars, false, "level=3;options='w=142';align=' '");
1634 p.add_member_control(bp, "Show", pbc.show_bars, "toggle", "w=50");
1635 if (show) {
1636 p.align("\a");
1637 create_bar_config_gui(bp, p, pbc);
1638 p.align("\b");
1639 p.end_tree_node(pbc.show_bars);
1640 }
1641}
1643{
1644 create_plot_gui(bp, p);
1645 p.add_decorator("Subplots", "heading", "level=3;font_style=regular;align=i", "%y-=8\n");
1646 p.add_decorator("", "separator", "h=2");
1647 for (unsigned i=0; i<get_nr_sub_plots(); ++i) {
1649 bool show = p.begin_tree_node(pbc.name, pbc.name, false, "level=3;options='w=138;font_style=italic';align=' '");
1650 connect_copy(p.add_member_control(bp, "", pbc.ref_color.color, "", "w=10", "")->value_change,
1651 cgv::signal::rebind(this, &plot_base::update_ref_color, cgv::signal::_c(i), cgv::signal::_r(p)));
1652 p.add_member_control(bp, "Show", pbc.show_plot, "toggle", "w=40");
1653 if (show) {
1654 p.align("\a");
1655 create_config_gui(bp, p, i);
1656 p.align("\b");
1657 p.end_tree_node(pbc.name);
1658 }
1659 }
1660}
1661
1662 }
1663}
1664
1665#ifdef REGISTER_SHADER_FILES
1666#include <cgv/base/register.h>
1667#include <plot_shader_inc.h>
1668#endif
base class for all classes that can be registered with support for dynamic properties (see also secti...
Definition base.h:75
An object registry allows registering and querying objects identified by a unique name.
bool empty() const
check if pointer is not yet set
Definition ref_ptr.h:230
const T get_value() const
return a reference to the current value
Definition control.h:143
const T & get_old_value() const
return the old value to the callbacks attached to the change_value signal
Definition control.h:149
derive from this class to provide a gui to the current viewer
Definition provider.h:64
bool add_gui(const std::string &label, T &value, const std::string &gui_type="", const std::string &options="")
Add a composed gui of the given gui_type for the given value.
Definition provider.h:247
cgv::base::base_ptr add_decorator(const std::string &label, const std::string &decorator_type, const std::string &options="", const std::string &align="\n")
add a newly created decorator to the group
Definition provider.cxx:168
void align(const std::string &_align)
send pure alignment information
Definition provider.cxx:36
bool begin_tree_node(const std::string &label, const T &value, bool initial_visibility=false, const std::string &options="", gui_group_ptr ggp=gui_group_ptr())
Begin a sub tree of a tree structured gui.
Definition provider.h:212
virtual void update_member(void *member_ptr)
call this to update all views and controls of a member
Definition provider.cxx:72
data::ref_ptr< control< T > > add_member_control(cgv::base::base *base_ptr, const std::string &label, T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
add control with callback to cgv::base::on_set method on cgv::gui::control::value_change
Definition provider.h:137
void end_tree_node(const T &value)
template specialization that allows to specify value reference plus node_instance by using the result...
Definition provider.h:222
data::ref_ptr< control< T > > find_control(T &value, int *idx_ptr=0)
find a control of a given class member
Definition provider.h:330
static fvec< float, N > from_vec(const vec< float > &)
conversion from vector
Definition fvec.h:752
vec< T > to_vec() const
conversion to vector type
Definition fvec.h:744
static cgv::type::uint32_type size()
return number of components
Definition fvec.h:134
vec_type apply(const vec_type &v) const
rotate vector according to quaternion
Definition quaternion.h:219
unsigned size() const
number of elements
Definition vec.h:59
void zeros()
fill the vector with zeros
Definition vec.h:470
fpnt_type get_corner(int i) const
return the i-th corner where the lower N bits of i are used to select between min (bit = 0) and max (...
const fpnt_type & get_max_pnt() const
return a const reference to corner 7
const fpnt_type & get_min_pnt() const
return a const reference to corner 0
configuration information stored per domain axis
Definition axis_config.h:45
tick_config primary_ticks
configuration of primary tickmarks
float line_width
line width
float get_attribute_max() const
read access to attrbribute maximum value
Definition axis_config.h:72
float tick_space_from_attribute_space(float value) const
perform transformation from attribute space to tick mark space by applying log transformation if acti...
rgb color
color of axis
float plot_space_from_window_space(float value) const
convert from window to plot space
tick_config secondary_ticks
configuration of secondary tickmarks
float get_attribute_min() const
read access to attrbribute minimum value
Definition axis_config.h:70
unsigned get_dim() const
return nr dimensions of plot
Definition plot_base.h:505
cgv::render::rectangle_render_style rrs
render style of rectangles
Definition plot_base.h:466
static const unsigned MAX_NR_SIZE_MAPPINGS
define maximum number of size mappings
Definition plot_base.h:410
int color_mapping[MAX_NR_COLOR_MAPPINGS]
index of attribute mapped to primary and secondary color
Definition plot_base.h:387
const vec3 get_axis_direction(unsigned ai) const
return true world direction of x, y or z axis
void adjust_domain_axis_to_data(unsigned ai, bool adjust_min=true, bool adjust_max=true, bool only_visible=true)
adjust the domain with respect to ai th axis to the visible or all data depending on last parameter
static std::string font_name_enum_def
concatenate font names to enum definition for dropdown control
Definition plot_base.h:334
bool opacity_is_bipolar[MAX_NR_OPACITY_MAPPINGS]
flag whether opacity mapping is bipolar for primary and secondary opacity mapping
Definition plot_base.h:401
int size_mapping[MAX_NR_SIZE_MAPPINGS]
index of attribute mapped to size
Definition plot_base.h:413
bool color_scale_is_bipolar[MAX_NR_COLOR_MAPPINGS]
flag whether color mapping is bipolar for primary and secondary color scale
Definition plot_base.h:389
virtual void create_config_gui(cgv::base::base *bp, cgv::gui::provider &p, unsigned i)
create the gui for a subplot configuration
void on_font_selection()
callback to change fonts
virtual void create_bar_config_gui(cgv::base::base *bp, cgv::gui::provider &p, plot_base_config &pbc)
create the gui for a bar subplot
static std::vector< const char * > font_names
store a vector with all fonts on the system
Definition plot_base.h:332
virtual void create_line_config_gui(cgv::base::base *bp, cgv::gui::provider &p, plot_base_config &pbc)
create the gui for a line subplot
int opacity_mapping[MAX_NR_OPACITY_MAPPINGS]
index of attribute mapped to primary and secondary opacity
Definition plot_base.h:397
const domain_config * get_domain_config_ptr() const
return const pointer to domain configuration
void set_width(float new_width, bool constrained=true)
set the plot width to given value and if constrained == true the height, such that the aspect ration ...
virtual void create_base_config_gui(cgv::base::base *bp, cgv::gui::provider &p, unsigned i)
create the gui for base subplot settings
float size_gamma[MAX_NR_SIZE_MAPPINGS]
and independent gamma adjustments
Definition plot_base.h:415
void set_label_font(float font_size, cgv::media::font::FontFaceAttributes ffa=cgv::media::font::FFA_REGULAR, const std::string &font_name="")
configure the label font
float opacity_window_zero_position[MAX_NR_OPACITY_MAPPINGS]
window space position of zero for primary and secondary opacity mapping
Definition plot_base.h:403
rgba legend_color
color and opacity of legend
Definition plot_base.h:378
void clear(cgv::render::context &ctx)
destruct shader programs
unsigned get_nr_sub_plots() const
return current number of sub plots
LegendComponent legend_components
whether to show legend
Definition plot_base.h:370
void place_origin(const vec3 &new_origin_location)
place the origin of the plot in 3D to the given location
std::vector< attribute_source_array > attribute_source_arrays
attribute sources
Definition plot_base.h:444
void ensure_font_names()
ensure that font names have been enumerate
vecn get_extent() const
query the plot extend in 2D coordinates
void adjust_domain_to_data(bool only_visible=true)
adjust selected axes of domain to the visible or all data depending on last parameter
bool determine_axis_extent_from_subplot(unsigned ai, unsigned i, float &sample_min, float &sample_max)
adjust the domain with respect to ai th axis to the i-th subplot
float opacity_gamma[MAX_NR_OPACITY_MAPPINGS]
gamma adjustments for primary and secondary opacity mapping
Definition plot_base.h:399
bool reversed[2]
whether to reverse the primary or secondary color scales
Definition plot_base.h:429
cgv::render::vertex_buffer vbo_legend
vbo for legend drawing
Definition plot_base.h:440
static const unsigned MAX_NR_OPACITY_MAPPINGS
define maximum number of opacity mappings
Definition plot_base.h:395
float layer_depth
depth offset of a single layer
Definition plot_base.h:327
float size_min[MAX_NR_SIZE_MAPPINGS]
min and max of mapped size
Definition plot_base.h:417
float opacity_max[MAX_NR_OPACITY_MAPPINGS]
maximum opacity value for primary and secondary opacity mapping
Definition plot_base.h:407
void set_view_ptr(cgv::render::view *_view_ptr)
set the view ptr
void on_font_face_selection()
callback to change font face
vec2 legend_extent
width of legend
Definition plot_base.h:374
quat orientation
orientiation quaternion mapping from domain to world coordinates
Definition plot_base.h:358
void set_domain_config_ptr(domain_config *_new_ptr)
set the domain configuration to an external configuration in order to synch several plots,...
unsigned dim
dimension of plot
Definition plot_base.h:344
float window_zero_position[MAX_NR_COLOR_MAPPINGS]
window space position of zero for primary and secondary color mapping
Definition plot_base.h:393
domain_config dom_cfg
domain configuration
Definition plot_base.h:348
vec3 get_corner(unsigned i) const
return the i-th plot corner in 3D coordinates
void set_mapping_uniforms(cgv::render::context &ctx, cgv::render::shader_program &prog)
set the uniforms for defining the mappings to visual variables
vec3 center_location
center location of domain in world coordinates
Definition plot_base.h:360
std::vector< plot_base_config * > configs
store one configuration per sub plot
Definition plot_base.h:352
vec3 transform_to_world(const vecn &pnt_attr) const
transform from attribute space to world space
ivec4 out_of_range_mode
handling of values that are out of range
Definition plot_base.h:383
void place_center(const vec3 &new_center_location)
place the plot extent center in 3D to the given location (this might can change the current origin lo...
float opacity_min[MAX_NR_OPACITY_MAPPINGS]
minimum opacity value for primary and secondary opacity mapping
Definition plot_base.h:405
float color_scale_gamma[MAX_NR_COLOR_MAPPINGS]
gamma adjustments for primary and secondary color mapping
Definition plot_base.h:391
std::vector< label_info > tick_labels
all tick labels
Definition plot_base.h:323
static const unsigned MAX_NR_COLOR_MAPPINGS
define maximum number of color mappings
Definition plot_base.h:385
void set_height(float new_height, bool constrained=true)
set the plot height to given value and if constrained == true the width, such that the aspect ration ...
void adjust_tick_marks(unsigned max_nr_secondary_ticks=20, bool adjust_to_attribute_ranges=true)
adjust tick marks of all axes based on maximum number of secondary ticks and domain min and max in co...
plot_base(unsigned dim, unsigned nr_attributes=0)
construct from plot dimension and number of additional attributes with default parameters
cgv::render::attribute_array_binding aab_legend
manage attributes for legend drawing
Definition plot_base.h:442
void set_samples_out_of_date(unsigned i)
notify plot that samples of given subplot are out of date
domain_config * dom_cfg_ptr
pointer to currently used domain config
Definition plot_base.h:350
plot_base_config & ref_sub_plot_config(unsigned i)
return a reference to the plot base configuration of the i-th plot
void set_orientation(const quat &_orientation)
set new orientation quaternion
vec3 get_origin() const
return the current origin in 3D coordinates
unsigned nr_attributes
number of additional attributes
Definition plot_base.h:346
void prepare_extents()
prepare extents for drawing
cgv::media::font::font_face_ptr title_font_face
store pointer to title font face
Definition plot_base.h:438
int legend_axis
coordinate direction along which to draw legend
Definition plot_base.h:376
virtual void create_gui(cgv::base::base *bp, cgv::gui::provider &p)
create a gui for the plot with gui for all configs
vec3 legend_location
center location of legend in domain coordinates
Definition plot_base.h:372
cgv::media::font::font_ptr title_font
store pointer to title font
Definition plot_base.h:436
int color_scheme_index[MAX_NR_COLOR_MAPPINGS]
color scheme indices of primary and secondary color scales
Definition plot_base.h:427
void set_sub_plot_attribute(unsigned i, unsigned ai, int subplot_index, size_t aj)
define a sub plot attribute ai from coordinate aj of the i-th internal sample container
void set_domain(const box2 &dom)
set the domain for 2d plots
const quat & get_orientation() const
get current orientation quaternion
virtual void create_point_config_gui(cgv::base::base *bp, cgv::gui::provider &p, plot_base_config &pbc)
create the gui for a point subplot
void update_color_scales()
the color scales to match the properties set through the config and gui
virtual void create_plot_gui(cgv::base::base *bp, cgv::gui::provider &p)
create the gui for the plot without gui for sub plots
std::array< std::shared_ptr< cgv::render::device_continuous_color_scale >, MAX_NR_COLOR_MAPPINGS > color_scales
color scales used for primary and secondary color mapping
Definition plot_base.h:423
bool set_color_scale(int mapping_index, int color_scheme_index)
set color scale of primary or secondary color mapping via an index into the global color scheme regis...
std::vector< tick_batch_info > tick_batches
twice number of axis pairs with index of first tick label and number of tick labels for primary and s...
Definition plot_base.h:325
cgv::render::color_scale_adapter color_scale_adapter
adapter to enable using color scales in shader programs
Definition plot_base.h:425
void set_extent(const vecn &new_extent)
set the plot extend in 2D coordinates
const box3 get_domain3() const
return 3d domain shown in plot
cgv::media::font::font_ptr label_font
store pointer to label font
Definition plot_base.h:432
virtual void create_stick_config_gui(cgv::base::base *bp, cgv::gui::provider &p, plot_base_config &pbc)
create the gui for a stick subplot
void include_axis_to_domain(unsigned ai)
extend domain such that given axis is included
const box2 get_domain() const
return 2d domain shown in plot
void set_plot_uniforms(cgv::render::context &ctx, cgv::render::shader_program &prog)
set the uniforms for plot configurations
void adjust_extent_to_domain_aspect_ratio(int preserve_ai=0)
adjust the extent such that it has same aspect ration as domain
void set_domain3(const box3 &dom)
set the domain for 3d plots
void set_sub_plot_colors(unsigned i, const rgb &base_color)
set the colors for all plot features of the i-th sub plot as variation of the given color
bool init(cgv::render::context &ctx)
build legend prog and create aab
void place_corner(unsigned corner_index, const vec3 &new_corner_location)
place a corner (0 .. lower left, 1 .. lower right, 2 .. upper left, 3 .. upper right) to a given 3D l...
const vec3 & get_center() const
return the current plot center in 3D coordinates
cgv::media::font::font_face_ptr label_font_face
store pointer to label font face
Definition plot_base.h:434
void set_extent_scaling(float x_scale, float y_scale, float z_scale=0)
set extent_scaling values for all axes
vec3 extent
extents used for drawing current
Definition plot_base.h:452
bool enable(context &ctx)
enable whole the attribute array binding object
bool create(const context &ctx)
create the attribute array binding object
void destruct(const context &ctx)
destruct attribute array binding object
bool disable(context &ctx)
disable whole attribute array binding object
bool enable_array(const context &ctx, int loc)
enable array for vertex attribute at location loc
bool set_attribute_array(const context &ctx, int loc, const T &array)
set vertex attribute location to given array and enable array
attribute array manager used to upload arrays to gpu
void set_color_scales(const std::vector< std::shared_ptr< const device_color_scale > > &color_scales)
Set a reference to multiple device_color_scales to be managed by this color_scale_adapter.
bool destruct(const context &ctx)
Destruct the color_scale_adapter.
bool disable(const context &ctx)
Disable the managed render resources after rendering.
bool enable(const context &ctx, int texture_unit)
Enable the managed render resources to prepare for rendering.
void set_uniforms_in_program(context &ctx, shader_program &prog, int texture_unit)
Set texture unit and uniform buffer location in the given shader_program and prepare uniform buffer.
bool init(const context &ctx)
Initialize the color_scale_adapter.
base class for all drawables, which is independent of the used rendering API.
Definition context.h:668
virtual std::ostream & output_stream()
returns an output stream whose output is printed at the current cursor location, which is managed by ...
Definition context.cxx:1032
virtual void mul_modelview_matrix(const dmat4 &MV)
multiply given matrix from right to current modelview matrix
Definition context.cxx:1952
virtual void set_color(const rgba &clr)
set the current color
Definition context.cxx:1761
virtual void enable_font_face(media::font::font_face_ptr font_face, float font_size)
enable the given font face with the given size in pixels
Definition context.cxx:1037
virtual void set_cursor(int x, int y)
flush the output_stream and set a new cursor position given in opengl coordinates with (0,...
Definition context.cxx:2102
void pop_modelview_matrix()
see push_V for an explanation
Definition context.cxx:1958
void push_modelview_matrix()
push the current viewing matrix onto a matrix stack for viewing matrices.
Definition context.cxx:1946
void show()
show the drawable
Definition drawable.cxx:26
a shader program combines several shader code fragments to a complete definition of the shading pipel...
bool enable(context &ctx)
enable the shader program
bool disable(context &ctx)
disable shader program and restore fixed functionality
bool set_uniform(const context &ctx, const std::string &name, const T &value, bool generate_error=false)
Set the value of a uniform by name, where the type can be any of int, unsigned, float,...
bool set_uniform_array(const context &ctx, const std::string &name, const T &array)
set uniform array from array array where number elements can be derived from array through array_desc...
void destruct(const context &ctx)
destruct shader program
int get_attribute_location(const context &ctx, const std::string &name) const
query location index of an attribute
bool build_program(const context &ctx, const std::string &file_name, bool show_error=false)
successively calls create, attach_program and link.
int get_uniform_location(const context &ctx, const std::string &name) const
query location index of an uniform
a vertex buffer is an unstructured memory block on the GPU.
bool create(const context &ctx, size_t size_in_bytes)
create empty vertex buffer of size size given in bytes
void destruct(const context &ctx)
destruct the render buffer
defines a symmetric view with the following quantities:
Definition view.h:22
font_ptr find_font(const std::string &font_name)
find an installed font by name
Definition font.cxx:32
FontFaceAttributes
declaration of supported attributes of font faces
Definition font.h:21
font_ptr default_font(bool mono_space)
return platform dependend default font
Definition font.cxx:57
void enumerate_font_names(std::vector< const char * > &font_names)
enumerate the names of all installed fonts
Definition font.cxx:65
TextAlignment
different text alignments
Definition context.h:329
@ TA_TOP
center of top edge of text bounds
Definition context.h:333
@ TA_BOTTOM
center of bottom edge of text bounds
Definition context.h:334
@ TA_NONE
no alignment
Definition context.h:330
@ TA_RIGHT
center of right edge of text bounds
Definition context.h:332
@ TA_LEFT
center of left edge of text bounds
Definition context.h:331
rectangle_renderer & ref_rectangle_renderer(context &ctx, int ref_count_change)
reference to a singleton plane renderer that can be shared among drawables
DummyEnum
some enum to mark an integral parameter to be of enum type
std::string join(const InputIt first, const InputIt last, const std::string &separator, bool trailing_separator=false)
Concatenate elements in the range [first, last) to a std::string.
Definition algorithm.h:146
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
this header is dependency free
Definition print.h:11
cgv::math::fvec< float, 4 > vec4
declare type of 4d single precision floating point vectors (used for homogeneous coordinates)
Definition fvec.h:685
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY > rgba
declare rgba color type with 32 bit components
Definition color.h:898
cgv::math::quaternion< float > quat
declare type of quaternion
Definition quaternion.h:370
cgv::media::axis_aligned_box< float, 3 > box3
declare type of 3d single precision floating point axis-aligned boxes
cgv::math::fvec< int32_t, 4 > ivec4
declare type of 4d 32 bit integer vectors
Definition fvec.h:712
cgv::math::vec< float > vecn
declare type of single precision floating point vector with varying dimension
Definition vec.h:1187
cgv::media::color< float, cgv::media::RGB > rgb
declare rgb color type with 32 bit components
Definition color.h:896
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
Definition fvec.h:681
cgv::media::axis_aligned_box< float, 2 > box2
declare type of 2d single precision floating point axis-aligned boxes
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:683
Helper functions to process strings.
T S() const
convert color to HLS and return S component
Definition color.h:449
store source of a single plot attribute (one coordinate axis or one float attribute)
Definition plot_base.h:232
attribute_source()
construct an empty attribute sources
rgba title_color
color of the title
Definition plot_base.h:54
bool show_domain
whether to show the coordinate axes including tickmarks and labels
Definition plot_base.h:40
unsigned title_font_index
store index of selected title font
Definition plot_base.h:68
float title_font_size
store selected title font size
Definition plot_base.h:70
float reference_size
store size of virtual pixel based measurement
Definition plot_base.h:56
unsigned label_font_index
store index of selected label font
Definition plot_base.h:62
bool fill
whether to fill the domain
Definition plot_base.h:42
std::string title
plot title
Definition plot_base.h:44
vecn title_pos
position of title
Definition plot_base.h:50
cgv::media::font::FontFaceAttributes label_ffa
store selected label font face attributes
Definition plot_base.h:66
std::vector< axis_config > axis_configs
store a vector of axis configurations (2/3 for plot2/3d plus several attribute axes)
Definition plot_base.h:60
cgv::media::font::FontFaceAttributes title_ffa
store selected title font face attributes
Definition plot_base.h:72
rgb color
color of the domain fill
Definition plot_base.h:52
float label_font_size
store selected label font size
Definition plot_base.h:64
float blend_width_in_pixel
store blend width in screen pixels used for antialiasing
Definition plot_base.h:58
bool show_title
whether to show the plot title
Definition plot_base.h:46
bool show_sub_plot_names
whether to show the sub plot names
Definition plot_base.h:48
plot independent configuration parameters of one sub plot in a 2d or 3d plot
Definition plot_base.h:134
mapped_size line_halo_width
width of line halo in pixel
Definition plot_base.h:174
virtual void set_sizes(float _size)
set all sizes from reference size
int bar_coordinate_index
extended bar information
Definition plot_base.h:192
virtual void set_colors(const rgb &base_color)
set all colors from reference color
Definition plot_base.cxx:84
mapped_size line_width
line width
Definition plot_base.h:170
mapped_size bar_percentual_width
percentual width of bar computed assuming a uniform y-sampling distance
Definition plot_base.h:198
virtual void configure_chart(ChartType chart_type)
configure the sub plot to a specific chart type
Definition plot_base.cxx:68
std::string name
name of sub plot
Definition plot_base.h:136
float stick_base_window
base window position of stick
Definition plot_base.h:183
bool show_lines
whether to connect data points with lines
Definition plot_base.h:168
mapped_rgba stick_color
color of the stick line
Definition plot_base.h:187
bool show_bars
whether to show bars
Definition plot_base.h:190
mapped_size bar_outline_width
line width of bar outlines
Definition plot_base.h:196
mapped_opacity ref_opacity
reference opacity, when changed, all opcities are adapted with set_opacity()
Definition plot_base.h:151
bool show_points
whether to show data points
Definition plot_base.h:156
plot_base_config(const std::string &_name, unsigned dim)
set default values
Definition plot_base.cxx:47
mapped_size stick_width
line width of stick
Definition plot_base.h:185
mapped_rgba bar_color
bar fill color
Definition plot_base.h:200
SubPlotInfluence sub_plot_influence
store bit field to define which sub plots are influenced by reference values
Definition plot_base.h:147
mapped_rgba line_halo_color
color of line halo
Definition plot_base.h:176
mapped_rgba point_color
point color
Definition plot_base.h:161
mapped_size ref_size
reference size, when changed, all sizes are adapted with set_size()
Definition plot_base.h:153
size_t begin_sample
offset into samples defaults to 0, if larger than end_sample vector is split into two parts
Definition plot_base.h:139
int stick_coordinate_index
extended stick information
Definition plot_base.h:181
bool show_plot
whether to show sub plot
Definition plot_base.h:144
bool show_sticks
whether to show straight lines to the bottom of the plot, which are called sticks
Definition plot_base.h:179
mapped_rgba line_color
line color
Definition plot_base.h:172
mapped_rgb ref_color
reference color, when changed, all colors are adapted with set_colors()
Definition plot_base.h:149
mapped_size point_halo_width
width of point halo in pixel
Definition plot_base.h:163
virtual ~plot_base_config()
virtual constructor in order to allow to extend the configuration for derived classes
mapped_rgba bar_outline_color
bar outline color
Definition plot_base.h:202
virtual void set_opacities(float _opa)
set all opacities from reference opacity
mapped_size point_size
point size in pixels
Definition plot_base.h:158
mapped_rgba point_halo_color
color of point halo
Definition plot_base.h:165
size_t end_sample
defaults to -1 and effectively is always the end of the sample vector
Definition plot_base.h:141
tickmark configuration of one tickmark type
Definition axis_config.h:24
float line_width
line width
Definition axis_config.h:30
bool label
whether to show text labels at tick
Definition axis_config.h:34
float step
step width between two ticks along axis
Definition axis_config.h:28
float length
tick length relative to domain extent
Definition axis_config.h:32
TickType type
type of tick
Definition axis_config.h:26
float default_depth_offset
default depth offset added to depth value of fragment. (default: 0.0f)
ColorMapping map_color_to_material
material side[s] where color is to be mapped to the diffuse material component, defaults to CM_COLOR ...
IlluminationMode illumination_mode
illumination mode defaults to IM_ONE_SIDED