5#include <cgv/math/ftransform.h>
6#include <cgv/media/color_scale.h>
7#include <cgv/render/attribute_array_binding.h>
8#include <cgv/render/color_scale.h>
9#include <cgv/render/shader_program.h>
10#include <cgv/signal/rebind.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>
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)
29domain_config::domain_config(
unsigned dim,
unsigned nr_attrs) : color(0.85f,0.85f,0.85f), axis_configs(dim+nr_attrs)
37 label_ffa = cgv::media::font::FFA_REGULAR;
43 title_ffa = cgv::media::font::FFA_REGULAR;
61 bar_base_window = 0.0;
104 bar_color.color = 0.5f *
rgb(1, 1, 1) + 0.5f * base_color;
108void plot_base_config::set_color_indices(
int idx)
141void plot_base_config::set_size_indices(
int idx)
172 bar_color.color.alpha() = pow(_opa, 0.7f);
174void plot_base_config::set_opacity_indices(
int idx)
198 source(AS_SAMPLE_CONTAINER), sub_plot_index(_sub_plot_index), offset(ai), count(_count), stride(_stride) {}
200 source(AS_POINTER), pointer(_pointer), offset(0), count(_count), stride(_stride) {}
202source(AS_VBO), vbo_ptr(_vbo_ptr), offset(_offset), count(_count), stride(_stride) {}
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;
216attribute_source_array::attribute_source_array() : vbo(
cgv::render::VBT_VERTICES,
cgv::render::VBU_STREAM_DRAW)
218 samples_out_of_date =
true;
219 sources_out_of_date =
true;
224 std::vector<box2>& R, std::vector<rgb>& C, std::vector<float>& D,
size_t offset)
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);
237void plot_base::draw_sub_plot_samples(
int count,
const plot_base_config& spc,
bool strip)
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));
242 GLint indices[2] = { count - 1, 0 };
243 glDrawElements(GL_LINES, 2, GL_UNSIGNED_INT, indices);
245 if (spc.end_sample > 0)
246 glDrawArrays(strip ? GL_LINE_STRIP : GL_POINTS, 0, GLsizei(spc.end_sample));
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));
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));
256vec3 plot_base::world_space_from_plot_space(
const vecn& pnt_plot)
const
258 vec3 pnt(pnt_plot(0), pnt_plot(1), pnt_plot.size() >= 3 ? pnt_plot(2) : 0.0f);
263 unsigned n = pnt_attr.
size();
266 unsigned m = acs.size() < n ? unsigned(acs.size()) : n;
267 for (
unsigned ai = 0; ai < m; ++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])));
273 return world_space_from_plot_space(pnt_plot);
282 for (
unsigned i = 1; i <
font_names.size(); ++i) {
292 std::string font_name = font_ptr->get_name();
294 if(std::string(*iter) == font_name) {
305 std::string font_name = font_ptr->get_name();
307 if(std::string(*iter) == font_name) {
347 unsigned F_count = 0;
349 for (
unsigned ai = 0; ai < max_ai; ++ai) {
352 if (ac.extent_scaling == 0.0f)
357 float f = ac.extent * ac.extent_scaling / ac.get_attribute_extent();
365 for (
unsigned ai = 0; ai < max_ai; ++ai) {
367 if (ac.extent_scaling == 0.0f)
369 extent[ai] = F * ac.get_attribute_extent() / ac.extent_scaling;
376 vecn attribute_min(8u, 0.0f), attribute_max(8u, 1.0f), axis_log_minimum(8u, 0.000001f);
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();
425 if (ass.size() <= ai)
434 if (ass.size() <= ai)
443 while (ass.size() <= ai)
452 const std::vector<std::vector<cgv::math::fvec<float, N>>>& samples;
454 size_t size(
unsigned i)
const {
return samples[i].size(); }
455 float operator() (
unsigned i,
unsigned k,
unsigned o)
const {
return samples[i][k][o]; }
460 auto& ass = asa.attribute_sources;
463 bool update_vbo =
false;
464 size_t vbo_nr_floats = 0;
465 for (ai = 0; ai < ass.size(); ++ai) {
468 case AS_SAMPLE_CONTAINER:
469 j = as.sub_plot_index == -1 ? i : as.sub_plot_index;
472 as.count = sa.size(j);
473 vbo_nr_floats += as.count;
477 if (asa.samples_out_of_date) {
479 vbo_nr_floats += as.count;
489 std::vector<float> buffer(vbo_nr_floats);
490 float* dest = buffer.data();
491 for (ai = 0; ai < ass.size(); ++ai) {
492 const auto& as = ass[ai];
494 case AS_SAMPLE_CONTAINER:
495 j = as.sub_plot_index == -1 ? i : as.sub_plot_index;
497 for (
int k = 0; k < as.count; ++k)
498 *dest++ = sa(j,k,(
unsigned)as.offset);
502 if (asa.samples_out_of_date) {
503 const float* src = as.pointer;
504 unsigned stride = unsigned(as.stride/
sizeof(
float));
505 for (
int k = 0; k < as.count; ++k, src += stride)
513 if (asa.vbo.get_size_in_bytes() != vbo_nr_floats *
sizeof(
float)) {
514 asa.vbo.destruct(ctx);
515 asa.vbo.create(ctx, buffer);
518 asa.vbo.replace(ctx, 0, buffer.data(), buffer.size());
519 asa.sources_out_of_date =
true;
522 if (!asa.aab.is_created()) {
524 asa.sources_out_of_date =
true;
526 if (asa.sources_out_of_date) {
528 size_t vbo_offset = 0;
530 for (ai = 0; ai < ass.size(); ++ai) {
531 const auto& as = ass[ai];
533 case AS_SAMPLE_CONTAINER: {
534 j = as.sub_plot_index == -1 ? i : as.sub_plot_index;
535 asa.aab.set_attribute_array(ctx, ai, cgv::render::get_element_type(f), asa.vbo, vbo_offset, sa.size(j), 0);
536 count = std::min(sa.size(j), count);
537 vbo_offset += count *
sizeof(float);
541 asa.aab.set_attribute_array(ctx, ai, cgv::render::get_element_type(f), asa.vbo, vbo_offset, as.count, 0);
542 count = std::min(as.count, count);
543 vbo_offset += count *
sizeof(float);
546 asa.aab.set_attribute_array(ctx, ai, cgv::render::get_element_type(f), *as.vbo_ptr, as.count, as.offset, (unsigned)as.stride);
547 count = std::min(as.count, count);
552 asa.sources_out_of_date =
false;
558size_t plot_base::enable_attributes(
cgv::render::context& ctx,
int i,
const std::vector<std::vector<vec2>>& samples)
562size_t plot_base::enable_attributes(
cgv::render::context& ctx,
int i,
const std::vector<std::vector<vec3>>& samples)
570void plot_base::update_samples_out_of_date_flag()
573 asa.samples_out_of_date = false;
577 vbo_legend(
cgv::render::VBT_VERTICES,
cgv::render::VBU_STREAM_DRAW)
619 view_ptr = _view_ptr;
622bool plot_base::extract_tick_rectangles_and_tick_labels(
623 std::vector<box2>& R, std::vector<rgb>& C, std::vector<float>& D,
624 std::vector<label_info>& tick_labels,
int ai,
int ci,
int ti,
float he,
625 float z_plot,
float plot_scale,
vec2 plot_offset,
float d,
bool multi_axis)
630 if (tc.
type == TT_NONE)
634 int min_i = (int)ceil(min_tick / tc.
step - std::numeric_limits<float>::epsilon());
635 int max_i = (int)((max_tick - fmod(max_tick, tc.
step)) / tc.
step);
638 if (ti == 1 && min_i * tc.
step - min_tick < std::numeric_limits<float>::epsilon())
640 if (ti == 1 && max_i * tc.
step - max_tick > -std::numeric_limits<float>::epsilon())
645 for (
int i = min_i; i <= max_i; ++i) {
646 float c_tick = (float)(i * tc.
step);
647 float c_attr = ac.attribute_space_from_tick_space(c_tick);
649 if (multi_axis && (fabs(c_attr) < std::numeric_limits<float>::epsilon()))
654 std::string label_str;
659 mn[ci] = c_plot - lw;
660 mx[ci] = c_plot + lw;
663 mn[1 - ci] = -he + plot_offset(1-ci);
664 mx[1 - ci] = -he + dl + plot_offset(1 - ci);
665 R.push_back(
box2(mn, mx));
666 C.push_back(ac.
color);
668 if (!label_str.empty()) {
675 mn[1 - ci] = he - dl + plot_offset(1 - ci);
676 mx[1 - ci] = he + plot_offset(1 - ci);
677 R.push_back(
box2(mn, mx));
678 C.push_back(ac.
color);
680 if (!label_str.empty()) {
686 if (z_plot != std::numeric_limits<float>::quiet_NaN()) {
687 mn[1 - ci] = z_plot - dl + plot_offset(1 - ci);
688 mx[1 - ci] = z_plot + dl + plot_offset(1 - ci);
689 R.push_back(
box2(mn, mx));
690 C.push_back(ac.
color);
697 mn[1 - ci] = -he + plot_offset(1-ci);
698 mx[1 - ci] = he + plot_offset(1-ci);
699 R.push_back(
box2(mn, mx));
700 C.push_back(ac.
color);
702 if (!label_str.empty()) {
723void plot_base::extract_legend_tick_rectangles_and_tick_labels(
724 std::vector<box2>& R, std::vector<rgb>& C, std::vector<float>& D,
725 std::vector<label_info>& tick_labels, std::vector<tick_batch_info>& tick_batches,
float d,
726 bool clear_cache,
bool is_first,
bool* multi_axis_modes)
732 const unsigned nr_lcs = 4;
733 static LegendComponent lcs[nr_lcs] = { LC_PRIMARY_COLOR, LC_PRIMARY_OPACITY, LC_SECONDARY_COLOR, LC_SECONDARY_OPACITY };
741 for (
unsigned ti = 0; ti < 2; ++ti) {
743 for (
int j = 0; j < nr_lcs; ++j) {
748 if (multi_axis_modes && !is_first && !multi_axis_modes[ai[j]])
752 0.5f*side_extent, std::numeric_limits<float>::quiet_NaN(), main_extent, loc, d,
false)) {
753 if ((tbi.label_count = (
unsigned)(
tick_labels.size() - tbi.first_label)) > 0)
756 loc[l] += 1.2f*side_extent;
767 cgv::tt_gl_font_face_ptr ff =
dynamic_cast<cgv::tt_gl_font_face*
>(&(*title_font_face));
774 std::vector<cgv::render::textured_rectangle> Q;
780 unsigned cnt = ff->text_to_quads(pos_aligned, cfg->title, Q, rs);
781 for (
unsigned j = 0; j < cnt; ++j)
782 C.push_back(cfg->title_color);
785 pos[1] -= 5.0f * cfg->title_font_size * rs;
787 if(si != -1 && i != si)
791 unsigned cnt = ff->text_to_quads(pos_aligned, spc.name, Q, 0.8f * rs);
792 for(
unsigned j = 0; j < cnt; ++j)
793 C.push_back(spc.ref_color.color);
794 pos[1] -= 4.0f * cfg->title_font_size * rs;
802 rr.set_render_style(font_rrs);
803 rr.enable_attribute_array_manager(ctx, aam_title);
804 rr.set_textured_rectangle_array(ctx, Q);
805 rr.set_color_array(ctx, C);
806 ff->ref_texture(ctx).enable(ctx);
807 rr.render(ctx, 0, Q.size());
808 ff->ref_texture(ctx).disable(ctx);
809 rr.disable_attribute_array_manager(ctx, aam_title);
813 std::vector<label_info>& tick_labels, std::vector<tick_batch_info>& tick_batches,
float depth)
818 cgv::tt_gl_font_face_ptr ff =
dynamic_cast<cgv::tt_gl_font_face*
>(&(*label_font_face));
821 for (
const auto& tbc :
tick_batches) if (tbc.label_count > 0) {
823 for (
unsigned i = tbc.first_label; i < tbc.first_label + tbc.label_count; ++i) {
825 ctx.
set_cursor(li.position, li.label, li.align);
835 std::vector<cgv::render::textured_rectangle> Q;
837 for (
const auto& tbc :
tick_batches) if (tbc.label_count > 0) {
838 for (
unsigned i = tbc.first_label; i < tbc.first_label + tbc.label_count; ++i) {
841 pos = ff->align_text(pos, li.label, li.align, li.scale * rs);
842 unsigned cnt = ff->text_to_quads(pos, li.label, Q, li.scale * rs);
843 for (
unsigned i = 0; i < cnt; ++i)
851 rr.set_render_style(font_rrs);
852 rr.enable_attribute_array_manager(ctx, aam_ticks);
853 rr.set_textured_rectangle_array(ctx, Q);
854 rr.set_color_array(ctx, C);
855 ff->ref_texture(ctx).enable(ctx);
856 rr.render(ctx, 0, Q.size());
857 ff->ref_texture(ctx).disable(ctx);
858 rr.disable_attribute_array_manager(ctx, aam_ticks);
862void plot_base::draw_legend(
cgv::render::context& ctx,
int layer_idx,
bool is_first,
bool* multi_axis_modes)
879 legend_prog.
set_uniform(ctx,
"legend_location", loc);
882 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
888 legend_prog.
set_uniform(ctx,
"legend_location", loc);
891 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
897 legend_prog.
set_uniform(ctx,
"legend_location", loc);
900 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
906 legend_prog.
set_uniform(ctx,
"legend_location", loc);
909 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
918 std::vector<float> D;
920 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);
925 draw_rectangles(ctx, aam_legend, R, C, D);
929 draw_tick_labels(ctx, aam_legend_ticks, legend_tick_labels, legend_tick_batches, -layer_idx *
layer_depth);
936 return box2(
vec2(acs[0].get_attribute_min(),acs[1].get_attribute_min()),
937 vec2(acs[0].get_attribute_max(), acs[1].get_attribute_max()));
942 return box3(
vec3(acs[0].get_attribute_min(), acs[1].get_attribute_min(),
get_dim() == 2 ? 0 : acs[2].get_attribute_min()),
943 vec3(acs[0].get_attribute_max(), acs[1].get_attribute_max(),
get_dim() == 2 ? 0 : acs[2].get_attribute_max()));
954 unsigned n = std::min(
get_dim(), 3u);
955 for (
unsigned ai = 0; ai < n; ++ai)
962 for (
unsigned ai = 0; ai <
get_dim(); ++ai)
963 extent(ai) = acs[ai].extent;
969 unsigned n = std::min(
get_dim(), new_extent.
size());
970 for (
unsigned ai = 0; ai < n; ++ai)
971 acs[ai].
extent = new_extent(ai);
977 acs[0].extent_scaling = x_scale;
978 acs[1].extent_scaling = y_scale;
980 acs[2].extent_scaling = z_scale;
986 acs[0].extent = new_width;
988 acs[1].extent = new_width *
989 (acs[1].tick_space_from_attribute_space(acs[1].get_attribute_max()) - acs[1].tick_space_from_attribute_space(acs[1].get_attribute_max())) /
990 (acs[0].tick_space_from_attribute_space(acs[0].get_attribute_max()) - acs[0].tick_space_from_attribute_space(acs[0].get_attribute_max()));
996 acs[1].extent = new_height;
998 acs[0].extent = new_height *
999 (acs[0].tick_space_from_attribute_space(acs[0].get_attribute_max()) - acs[0].tick_space_from_attribute_space(acs[0].get_attribute_max())) /
1000 (acs[1].tick_space_from_attribute_space(acs[1].get_attribute_max()) - acs[1].tick_space_from_attribute_space(acs[1].get_attribute_max()));
1036 for (
unsigned j = 0; j <
get_dim(); ++j)
1054 if (as.source == AS_NONE)
1056 bool new_found_sample =
false;
1057 float new_samples_min, new_samples_max;
1058 switch (as.source) {
1059 case AS_SAMPLE_CONTAINER:
1061 int j = as.sub_plot_index == -1 ? i : as.sub_plot_index;
1062 new_found_sample = compute_sample_coordinate_interval(j, (
int)as.offset, new_samples_min, new_samples_max);
1067 const float* ptr = as.pointer;
1068 for (
unsigned j = 0; j < as.count; ++j) {
1069 if (new_found_sample) {
1070 new_samples_min = std::min(new_samples_min, *ptr);
1071 new_samples_max = std::max(new_samples_max, *ptr);
1074 new_samples_min = new_samples_max = *ptr;
1075 new_found_sample =
true;
1077 reinterpret_cast<const char*&
>(ptr) += as.stride;
1084 if (!new_found_sample)
1087 samples_min = new_samples_min;
1088 samples_max = new_samples_max;
1094 bool found_sample =
false;
1095 float samples_min, samples_max;
1096 for (
unsigned i = 0; i <
configs.size(); ++i) {
1099 float new_samples_min, new_samples_max;
1102 samples_min = std::min(samples_min, new_samples_min);
1103 samples_max = std::max(samples_max, new_samples_max);
1106 samples_min = new_samples_min;
1107 samples_max = new_samples_max;
1108 found_sample =
true;
1113 if (!found_sample) {
1115 acs[ai].set_attribute_minimum(0.0f);
1117 acs[ai].set_attribute_maximum(1.0f);
1121 acs[ai].set_attribute_minimum(samples_min);
1123 acs[ai].set_attribute_maximum(samples_max);
1124 if (acs[ai].get_attribute_min() == acs[ai].get_attribute_max())
1125 acs[ai].set_attribute_maximum(acs[ai].get_attribute_max() + 1);
1131 for (
unsigned ai = 0; ai < acs.size(); ++ai) {
1132 acs[ai].adjust_tick_marks_to_range(max_nr_secondary_ticks);
1133 if (!adjust_to_attribute_ranges && ai + 1 ==
get_dim())
1140 for (
int ai = 0; ai < (int)
get_dim(); ++ai) {
1141 if (ai == preserve_ai)
1143 acs[ai].extent = acs[preserve_ai].extent*acs[ai].get_attribute_extent()/acs[preserve_ai].get_attribute_extent();
1149 for (
unsigned aj = 0; aj <
get_dim(); ++aj) {
1152 if (acs[aj].get_attribute_min() > 0)
1153 acs[aj].set_attribute_minimum(0);
1154 if (acs[aj].get_attribute_max() < 0)
1155 acs[aj].set_attribute_maximum(0);
1161 for (
unsigned ai=0; ai < n; ++ai)
1168 if (!font_name.empty()) {
1170 if (font_name == *iter) {
1197 return (
unsigned)
configs.size();
1214 font_rrs = cgv::ref_rectangle_render_style();
1217 aam_title.init(ctx);
1218 aam_legend.init(ctx);
1219 aam_legend_ticks.init(ctx);
1220 if (!legend_prog.
build_program(ctx,
"plot_legend.glpr",
true)) {
1221 std::cerr <<
"could not build GLSL program from plot_legend.glpr" << std::endl;
1225 std::vector<vec4> P;
1226 P.push_back(
vec4(-0.5f, -0.5f, 0.0f, 0.0f));
1227 P.push_back(
vec4( 0.5f, -0.5f, 0.0f, 0.0f));
1228 P.push_back(
vec4(-0.5f, 0.5f, 0.0f, 1.0f));
1229 P.push_back(
vec4( 0.5f, 0.5f, 0.0f, 1.0f));
1230 P.push_back(
vec4(-0.5f, -0.5f, 0.0f, 0.0f));
1231 P.push_back(
vec4(0.5f, -0.5f, 0.0f, 1.0f));
1232 P.push_back(
vec4(-0.5f, 0.5f, 0.0f, 0.0f));
1233 P.push_back(
vec4(0.5f, 0.5f, 0.0f, 1.0f));
1240 vec3& p0 =
reinterpret_cast<vec3&
>(P[0]);
1241 float& v0 = P[0][3];
1250 aam_title.destruct(ctx);
1251 aam_legend.destruct(ctx);
1252 aam_legend_ticks.destruct(ctx);
1269 std::string attribute_enums =
"off=-1";
1272 std::string dropdown_options(
"w=92;enums='" + attribute_enums +
"'");
1276 static const char* prefixes[] = {
"Primary ",
"Secondary ",
"Ternary " };
1277 for (
unsigned idx = 0; idx < nr; ++idx) {
1278 std::string prefix(prefixes[idx]);
1311 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");
1312 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");
1324 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'");
1325 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'");
1326 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'");
1329 cgv::signal::rebind(
this, &plot_base::on_legend_axis_change,cgv::signal::_r(p),cgv::signal::_1));
1337 p.
add_gui(
"Center",
center_location,
"vector",
"main_label='heading';gui_type='value_slider';options='min=-100;max=100;log=true;ticks=true'");
1338 p.
add_gui(
"Orientation",
reinterpret_cast<vec4&
>(
orientation),
"direction",
"main_label='heading';gui_type='value_slider'");
1408 pbc.set_opacity_indices(pbc.ref_opacity.opacity_idx);
1420 pbc.set_colors(pbc.ref_color.color);
1432 pbc.set_color_indices(pbc.ref_color.color_idx);
1444 pbc.set_sizes(pbc.ref_size.size);
1466 "gui_type='toggle';align='%x+=1';options='w=32;x=2';enums='Pnt=1,Halo=2,Line=4,Stk=8,Bar=16,Out=32'");
1469 cgv::signal::rebind(
this, &plot_base::update_ref_color, cgv::signal::_c(i), cgv::signal::_r(p)));
1471 cgv::signal::rebind(
this, &plot_base::update_ref_color_index, cgv::signal::_c(i), cgv::signal::_r(p)));
1473 connect_copy(p.
add_member_control(bp,
"Opacity", pbc.
ref_opacity.opacity,
"value_slider",
"min=0;max=1;ticks=true;w=100",
" ")->value_change,
1474 cgv::signal::rebind(
this, &plot_base::update_ref_opacity, cgv::signal::_c(i), cgv::signal::_r(p)));
1476 cgv::signal::rebind(
this, &plot_base::update_ref_opacity_index, cgv::signal::_c(i), cgv::signal::_r(p)));
1478 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,
1479 cgv::signal::rebind(
this, &plot_base::update_ref_size, cgv::signal::_c(i), cgv::signal::_r(p)));
1481 cgv::signal::rebind(
this, &plot_base::update_ref_size_index, cgv::signal::_c(i), cgv::signal::_r(p)));
1488 if (options.empty())
1489 options =
"min=1;max=20;log=true;ticks=true;w=120";
1491 options +=
";w=120";
1513 add_mapped_rgba_control(p, bp,
"Color", pbc.
point_color);
1515 add_mapped_size_control(p, bp,
"Size", pbc.
point_size);
1516 add_mapped_size_control(p, bp,
"Halo Width", pbc.
point_halo_width,
"min=-8;max=8;ticks=true");
1520 add_mapped_rgba_control(p, bp,
"Color", pbc.
line_color);
1522 add_mapped_size_control(p, bp,
"Width", pbc.
line_width);
1523 add_mapped_size_control(p, bp,
"Halo Width", pbc.
line_halo_width,
"min=0;max=20;log=true;ticks=true");
1530 add_mapped_rgba_control(p, bp,
"Color", pbc.
stick_color);
1531 add_mapped_size_control(p, bp,
"Width", pbc.
stick_width);
1537 p.
add_member_control(bp,
"Base", pbc.bar_base_window,
"value_slider",
"min=0;max=1;ticks=true");
1538 add_mapped_rgba_control(p, bp,
"Color", pbc.
bar_color);
1540 add_mapped_size_control(p, bp,
"Outline Width", pbc.
bar_outline_width,
"min=0;max=20;log=true;ticks=true");
1541 add_mapped_size_control(p, bp,
"Width", pbc.
bar_percentual_width,
"min=0.0;max=1.05;log=true;ticks=true");
1589 p.
add_decorator(
"Subplots",
"heading",
"level=3;font_style=regular;align=i",
"%y-=8\n");
1595 cgv::signal::rebind(
this, &plot_base::update_ref_color, cgv::signal::_c(i), cgv::signal::_r(p)));
1609#ifdef REGISTER_SHADER_FILES
1610#include <cgv/base/register.h>
1611#include <plot_shader_inc.h>
base class for all classes that can be registered with support for dynamic properties (see also secti...
bool empty() const
check if pointer is not yet set
const T get_value() const
return a reference to the current value
const T & get_old_value() const
return the old value to the callbacks attached to the change_value signal
derive from this class to provide a gui to the current viewer
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.
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
void align(const std::string &_align)
send pure alignment information
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.
virtual void update_member(void *member_ptr)
call this to update all views and controls of a member
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
void end_tree_node(const T &value)
template specialization that allows to specify value reference plus node_instance by using the result...
data::ref_ptr< control< T > > find_control(T &value, int *idx_ptr=0)
find a control of a given class member
static fvec< float, N > from_vec(const vec< float > &)
conversion from vector
vec< T > to_vec() const
conversion to vector type
static cgv::type::uint32_type size()
return number of elements
vec_type apply(const vec_type &v) const
rotate vector according to quaternion
unsigned size() const
number of elements
void zeros()
fill the vector with zeros
configuration information stored per domain axis
tick_config primary_ticks
configuration of primary tickmarks
float line_width
line width
float get_attribute_max() const
read access to attrbribute maximum value
float tick_space_from_attribute_space(float value) const
perform transformation from attribute space to tick mark space by applying log transformation if acti...
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
unsigned get_dim() const
return nr dimensions of plot
cgv::render::rectangle_render_style rrs
render style of rectangles
static const unsigned MAX_NR_SIZE_MAPPINGS
define maximum number of size mappings
int color_mapping[MAX_NR_COLOR_MAPPINGS]
index of attribute mapped to primary and secondary color
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
bool opacity_is_bipolar[MAX_NR_OPACITY_MAPPINGS]
flag whether opacity mapping is bipolar for primary and secondary opacity mapping
int size_mapping[MAX_NR_SIZE_MAPPINGS]
index of attribute mapped to size
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
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
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
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
rgba legend_color
color and opacity of legend
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
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
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
cgv::render::vertex_buffer vbo_legend
vbo for legend drawing
static const unsigned MAX_NR_OPACITY_MAPPINGS
define maximum number of opacity mappings
float layer_depth
depth offset of a single layer
float size_min[MAX_NR_SIZE_MAPPINGS]
min and max of mapped size
float opacity_max[MAX_NR_OPACITY_MAPPINGS]
maximum opacity value for primary and secondary opacity mapping
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
quat orientation
orientiation quaternion mapping from domain to world coordinates
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
float window_zero_position[MAX_NR_COLOR_MAPPINGS]
window space position of zero for primary and secondary color mapping
domain_config dom_cfg
domain configuration
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
std::vector< plot_base_config * > configs
store one configuration per sub plot
vec3 transform_to_world(const vecn &pnt_attr) const
transform from attribute space to world space
cgv::media::ColorScale color_scale_index[MAX_NR_COLOR_MAPPINGS]
color scale indices of primary and secondary color mapping
ivec4 out_of_range_mode
handling of values that are out of range
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
float color_scale_gamma[MAX_NR_COLOR_MAPPINGS]
gamma adjustments for primary and secondary color mapping
std::vector< label_info > tick_labels
all tick labels
static const unsigned MAX_NR_COLOR_MAPPINGS
define maximum number of color mappings
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
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
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
void prepare_extents()
prepare extents for drawing
cgv::media::font::font_face_ptr title_font_face
store pointer to title font face
int legend_axis
coordinate direction along which to draw legend
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
cgv::media::font::font_ptr title_font
store pointer to title font
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
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::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...
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
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
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
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
base class for all drawables, which is independent of the used rendering API.
virtual std::ostream & output_stream()
returns an output stream whose output is printed at the current cursor location, which is managed by ...
virtual void mul_modelview_matrix(const dmat4 &MV)
multiply given matrix from right to current modelview matrix
virtual void set_color(const rgba &clr)
set the current color
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
virtual void set_cursor(int x, int y)
flush the output_stream and set a new cursor position given in opengl coordinates with (0,...
void pop_modelview_matrix()
see push_V for an explanation
void push_modelview_matrix()
push the current viewing matrix onto a matrix stack for viewing matrices.
void show()
show the drawable
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
int get_uniform_location(const context &ctx, const std::string &name) const
query location index of an uniform
bool build_program(const context &ctx, const std::string &file_name, bool show_error=false, const shader_define_map &defines=shader_define_map())
successively calls create, attach_program and link.
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:
TextAlignment
different text alignments
@ TA_TOP
center of top edge of text bounds
@ TA_BOTTOM
center of bottom edge of text bounds
@ TA_RIGHT
center of right edge of text bounds
@ TA_LEFT
center of left edge of text bounds
rectangle_renderer & ref_rectangle_renderer(context &ctx, int ref_count_change)
reference to a singleton plane renderer that can be shared among drawables
void configure_color_scale(cgv::render::context &ctx, cgv::render::shader_program &prog, cgv::media::ColorScale cs, float window_zero_position)
convenience function to configure a shader that uses color_scale.glsl with a single color scale
DummyEnum
some enum to mark an integral parameter to be of enum type
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
cgv::math::fvec< float, 4 > vec4
declare type of 4d single precision floating point vectors (used for homogeneous coordinates)
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY > rgba
declare rgba color type with 32 bit components
cgv::math::quaternion< float > quat
declare type of quaternion
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
cgv::math::vec< float > vecn
declare type of single precision floating point vector with varying dimension
cgv::media::color< float, cgv::media::RGB > rgb
declare rgb color type with 32 bit components
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
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
store source of a single plot attribute (one coordinate axis or one float attribute)
attribute_source()
construct an empty attribute sources
rgba title_color
color of the title
bool show_domain
whether to show the coordinate axes including tickmarks and labels
unsigned title_font_index
store index of selected title font
float title_font_size
store selected title font size
float reference_size
store size of virtual pixel based measurement
unsigned label_font_index
store index of selected label font
bool fill
whether to fill the domain
std::string title
plot title
vecn title_pos
position of title
cgv::media::font::FontFaceAttributes label_ffa
store selected label font face attributes
std::vector< axis_config > axis_configs
store a vector of axis configurations (2/3 for plot2/3d plus several attribute axes)
cgv::media::font::FontFaceAttributes title_ffa
store selected title font face attributes
rgb color
color of the domain fill
float label_font_size
store selected label font size
float blend_width_in_pixel
store blend width in screen pixels used for antialiasing
bool show_title
whether to show the plot title
bool show_sub_plot_names
whether to show the sub plot names
plot independent configuration parameters of one sub plot in a 2d or 3d plot
mapped_size line_halo_width
width of line halo in pixel
virtual void set_sizes(float _size)
set all sizes from reference size
int bar_coordinate_index
extended bar information
virtual void set_colors(const rgb &base_color)
set all colors from reference color
mapped_size line_width
line width
mapped_size bar_percentual_width
percentual width of bar computed assuming a uniform y-sampling distance
virtual void configure_chart(ChartType chart_type)
configure the sub plot to a specific chart type
std::string name
name of sub plot
float stick_base_window
base window position of stick
bool show_lines
whether to connect data points with lines
mapped_rgba stick_color
color of the stick line
bool show_bars
whether to show bars
mapped_size bar_outline_width
line width of bar outlines
mapped_opacity ref_opacity
reference opacity, when changed, all opcities are adapted with set_opacity()
bool show_points
whether to show data points
plot_base_config(const std::string &_name, unsigned dim)
set default values
mapped_size stick_width
line width of stick
mapped_rgba bar_color
bar fill color
SubPlotInfluence sub_plot_influence
store bit field to define which sub plots are influenced by reference values
mapped_rgba line_halo_color
color of line halo
mapped_rgba point_color
point color
mapped_size ref_size
reference size, when changed, all sizes are adapted with set_size()
size_t begin_sample
offset into samples defaults to 0, if larger than end_sample vector is split into two parts
int stick_coordinate_index
extended stick information
bool show_plot
whether to show sub plot
bool show_sticks
whether to show straight lines to the bottom of the plot, which are called sticks
mapped_rgba line_color
line color
mapped_rgb ref_color
reference color, when changed, all colors are adapted with set_colors()
mapped_size point_halo_width
width of point halo in pixel
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
virtual void set_opacities(float _opa)
set all opacities from reference opacity
mapped_size point_size
point size in pixels
mapped_rgba point_halo_color
color of point halo
size_t end_sample
defaults to -1 and effectively is always the end of the sample vector
tickmark configuration of one tickmark type
float line_width
line width
bool label
whether to show text labels at tick
float step
step width between two ticks along axis
float length
tick length relative to domain extent
TickType type
type of tick
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 MS_FRONT_...
IlluminationMode illumination_mode
illumination mode defaults to IM_ONE_SIDED