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>
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();
437 if (ass.size() <= ai)
446 if (ass.size() <= ai)
455 while (ass.size() <= ai)
464 const std::vector<std::vector<cgv::math::fvec<float, N>>>& 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]; }
472 auto& ass = asa.attribute_sources;
475 bool update_vbo =
false;
476 size_t vbo_nr_floats = 0;
477 for (ai = 0; ai < ass.size(); ++ai) {
480 case AS_SAMPLE_CONTAINER:
481 j = as.sub_plot_index == -1 ? i : as.sub_plot_index;
484 as.count = sa.size(j);
485 vbo_nr_floats += as.count;
489 if (asa.samples_out_of_date) {
491 vbo_nr_floats += as.count;
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];
506 case AS_SAMPLE_CONTAINER:
507 j = as.sub_plot_index == -1 ? i : as.sub_plot_index;
509 for (
int k = 0; k < as.count; ++k)
510 *dest++ = sa(j,k,(
unsigned)as.offset);
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)
525 if (asa.vbo.get_size_in_bytes() != vbo_nr_floats *
sizeof(
float)) {
526 asa.vbo.destruct(ctx);
527 asa.vbo.create(ctx, buffer);
530 asa.vbo.replace(ctx, 0, buffer.data(), buffer.size());
531 asa.sources_out_of_date =
true;
534 if (!asa.aab.is_created()) {
536 asa.sources_out_of_date =
true;
538 if (asa.sources_out_of_date) {
540 size_t vbo_offset = 0;
542 for (ai = 0; ai < ass.size(); ++ai) {
543 const auto& as = ass[ai];
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);
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);
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);
564 asa.sources_out_of_date =
false;
570size_t plot_base::enable_attributes(
cgv::render::context& ctx,
int i,
const std::vector<std::vector<vec2>>& samples)
574size_t plot_base::enable_attributes(
cgv::render::context& ctx,
int i,
const std::vector<std::vector<vec3>>& samples)
582void plot_base::update_samples_out_of_date_flag()
585 asa.samples_out_of_date = false;
589 vbo_legend(
cgv::render::VBT_VERTICES,
cgv::render::VBU_STREAM_DRAW)
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);
634 view_ptr = _view_ptr;
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)
645 if (tc.
type == TT_NONE)
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);
653 if (ti == 1 && min_i * tc.
step - min_tick < std::numeric_limits<float>::epsilon())
655 if (ti == 1 && max_i * tc.
step - max_tick > -std::numeric_limits<float>::epsilon())
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);
664 if (multi_axis && (fabs(c_attr) < std::numeric_limits<float>::epsilon()))
669 std::string label_str;
674 mn[ci] = c_plot - lw;
675 mx[ci] = c_plot + lw;
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);
683 if (!label_str.empty()) {
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);
695 if (!label_str.empty()) {
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);
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);
717 if (!label_str.empty()) {
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)
747 const unsigned nr_lcs = 4;
748 static LegendComponent lcs[nr_lcs] = { LC_PRIMARY_COLOR, LC_PRIMARY_OPACITY, LC_SECONDARY_COLOR, LC_SECONDARY_OPACITY };
756 for (
unsigned ti = 0; ti < 2; ++ti) {
758 for (
int j = 0; j < nr_lcs; ++j) {
763 if (multi_axis_modes && !is_first && !multi_axis_modes[ai[j]])
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)
771 loc[l] += 1.2f*side_extent;
782 cgv::tt_gl_font_face_ptr ff =
dynamic_cast<cgv::tt_gl_font_face*
>(&(*title_font_face));
789 std::vector<cgv::render::textured_rectangle> Q;
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);
800 pos[1] -= 5.0f * cfg->title_font_size * rs;
802 if(si != -1 && i != si)
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;
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);
828 std::vector<label_info>& tick_labels, std::vector<tick_batch_info>& tick_batches,
float depth)
833 cgv::tt_gl_font_face_ptr ff =
dynamic_cast<cgv::tt_gl_font_face*
>(&(*label_font_face));
836 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) {
840 ctx.
set_cursor(li.position, li.label, li.align);
850 std::vector<cgv::render::textured_rectangle> Q;
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) {
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)
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);
877void plot_base::draw_legend(
cgv::render::context& ctx,
int layer_idx,
bool is_first,
bool* multi_axis_modes)
894 legend_prog.
set_uniform(ctx,
"legend_location", loc);
897 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
903 legend_prog.
set_uniform(ctx,
"legend_location", loc);
906 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
912 legend_prog.
set_uniform(ctx,
"legend_location", loc);
915 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
921 legend_prog.
set_uniform(ctx,
"legend_location", loc);
924 glDrawArrays(GL_TRIANGLE_STRIP, off, 4);
934 std::vector<float> D;
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);
941 draw_rectangles(ctx, aam_legend, R, C, D);
945 draw_tick_labels(ctx, aam_legend_ticks, legend_tick_labels, legend_tick_batches, -layer_idx *
layer_depth);
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()));
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()));
970 unsigned n = std::min(
get_dim(), 3u);
971 for (
unsigned ai = 0; ai < n; ++ai)
978 for (
unsigned ai = 0; ai <
get_dim(); ++ai)
979 extent(ai) = acs[ai].extent;
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);
993 acs[0].extent_scaling = x_scale;
994 acs[1].extent_scaling = y_scale;
996 acs[2].extent_scaling = z_scale;
1002 acs[0].extent = new_width;
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()));
1012 acs[1].extent = new_height;
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()));
1052 for (
unsigned j = 0; j <
get_dim(); ++j)
1070 if (as.source == AS_NONE)
1072 bool new_found_sample =
false;
1073 float new_samples_min, new_samples_max;
1074 switch (as.source) {
1075 case AS_SAMPLE_CONTAINER:
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);
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);
1090 new_samples_min = new_samples_max = *ptr;
1091 new_found_sample =
true;
1093 reinterpret_cast<const char*&
>(ptr) += as.stride;
1100 if (!new_found_sample)
1103 samples_min = new_samples_min;
1104 samples_max = new_samples_max;
1110 bool found_sample =
false;
1111 float samples_min, samples_max;
1112 for (
unsigned i = 0; i <
configs.size(); ++i) {
1115 float new_samples_min, new_samples_max;
1118 samples_min = std::min(samples_min, new_samples_min);
1119 samples_max = std::max(samples_max, new_samples_max);
1122 samples_min = new_samples_min;
1123 samples_max = new_samples_max;
1124 found_sample =
true;
1129 if (!found_sample) {
1131 acs[ai].set_attribute_minimum(0.0f);
1133 acs[ai].set_attribute_maximum(1.0f);
1137 acs[ai].set_attribute_minimum(samples_min);
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);
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())
1156 for (
int ai = 0; ai < (int)
get_dim(); ++ai) {
1157 if (ai == preserve_ai)
1159 acs[ai].extent = acs[preserve_ai].extent*acs[ai].get_attribute_extent()/acs[preserve_ai].get_attribute_extent();
1165 for (
unsigned aj = 0; aj <
get_dim(); ++aj) {
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);
1177 for (
unsigned ai=0; ai < n; ++ai)
1184 if (!font_name.empty()) {
1186 if (font_name == *iter) {
1213 return (
unsigned)
configs.size();
1230 bool success =
false;
1238 this->color_scheme_index[mapping_index] = -1;
1250 auto it = registry.find(color_scheme_name);
1252 if(it != registry.end())
1253 index = std::distance(registry.begin(), it);
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;
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));
1285 vec3& p0 =
reinterpret_cast<vec3&
>(P[0]);
1286 float& v0 = P[0][3];
1296 aam_title.destruct(ctx);
1297 aam_legend.destruct(ctx);
1298 aam_legend_ticks.destruct(ctx);
1316 std::string attribute_enums =
"off=-1";
1319 std::string dropdown_options(
"w=92;enums='" + attribute_enums +
"'");
1323 static const char* prefixes[] = {
"Primary ",
"Secondary ",
"Ternary " };
1324 for (
unsigned idx = 0; idx < nr; ++idx) {
1325 std::string prefix(prefixes[idx]);
1331 const auto& connect_color_scale_callback = [
this](
auto control) {
1332 cgv::signal::connect_copy(
1333 control->value_change,
1337 std::string color_scheme_enums =
cgv::utils::join(cgv::media::get_global_continuous_color_scheme_registry().get_names(),
",");
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");
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'");
1385 cgv::signal::rebind(
this, &plot_base::on_legend_axis_change,cgv::signal::_r(p),cgv::signal::_1));
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'");
1464 pbc.set_opacity_indices(pbc.ref_opacity.opacity_idx);
1476 pbc.set_colors(pbc.ref_color.color);
1488 pbc.set_color_indices(pbc.ref_color.color_idx);
1500 pbc.set_sizes(pbc.ref_size.size);
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'");
1525 cgv::signal::rebind(
this, &plot_base::update_ref_color, cgv::signal::_c(i), cgv::signal::_r(p)));
1527 cgv::signal::rebind(
this, &plot_base::update_ref_color_index, cgv::signal::_c(i), cgv::signal::_r(p)));
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)));
1532 cgv::signal::rebind(
this, &plot_base::update_ref_opacity_index, cgv::signal::_c(i), cgv::signal::_r(p)));
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)));
1537 cgv::signal::rebind(
this, &plot_base::update_ref_size_index, cgv::signal::_c(i), cgv::signal::_r(p)));
1544 if (options.empty())
1545 options =
"min=1;max=20;log=true;ticks=true;w=120";
1547 options +=
";w=120";
1569 add_mapped_rgba_control(p, bp,
"Color", pbc.
point_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");
1576 add_mapped_rgba_control(p, bp,
"Color", pbc.
line_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");
1586 add_mapped_rgba_control(p, bp,
"Color", pbc.
stick_color);
1587 add_mapped_size_control(p, bp,
"Width", pbc.
stick_width);
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);
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");
1645 p.
add_decorator(
"Subplots",
"heading",
"level=3;font_style=regular;align=i",
"%y-=8\n");
1651 cgv::signal::rebind(
this, &plot_base::update_ref_color, cgv::signal::_c(i), cgv::signal::_r(p)));
1665#ifdef REGISTER_SHADER_FILES
1666#include <cgv/base/register.h>
1667#include <plot_shader_inc.h>
base class for all classes that can be registered with support for dynamic properties (see also secti...
An object registry allows registering and querying objects identified by a unique name.
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 components
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
bool color_scale_is_bipolar[MAX_NR_COLOR_MAPPINGS]
flag whether color mapping is bipolar for primary and secondary color scale
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
bool reversed[2]
whether to reverse the primary or secondary color scales
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
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
int color_scheme_index[MAX_NR_COLOR_MAPPINGS]
color scheme indices of primary and secondary color scales
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
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...
cgv::render::color_scale_adapter color_scale_adapter
adapter to enable using color scales in shader programs
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
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.
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
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:
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
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.
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
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
Helper functions to process strings.
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 CM_COLOR ...
IlluminationMode illumination_mode
illumination mode defaults to IM_ONE_SIDED