2#include <libs/cgv_gl/gl/gl.h>
3#include <cgv/media/color_scale.h>
4#include <cgv/render/attribute_array_binding.h>
5#include <cgv/math/ftransform.h>
29 disable_depth_mask =
false;
44bool plot2d::compute_sample_coordinate_interval(
int i,
int ai,
float& samples_min,
float& samples_max)
47 bool found_sample =
false;
48 float min_value, max_value;
49 for (
unsigned j = 0; j <
samples[i].size(); ++j) {
51 min_value = std::min(min_value,
samples[i][j](ai));
52 max_value = std::max(max_value,
samples[i][j](ai));
82 samples.push_back(std::vector<vec2>());
83 strips.push_back(std::vector<unsigned>());
120 aam_domain_tick_labels.init(ctx);
121 if (!line_prog.
build_program(ctx,
"plot2d_line.glpr",
true)) {
122 std::cerr <<
"could not build GLSL program from plot2d_line.glpr" << std::endl;
126 line_prog.allow_context_to_set_color(
false);
127 if (!point_prog.
build_program(ctx,
"plot2d_point.glpr",
true)) {
128 std::cerr <<
"could not build GLSL program from plot2d_point.glpr" << std::endl;
132 point_prog.allow_context_to_set_color(
false);
135 options.
defines[
"PLOT_MODE"] =
"1";
136 if (!rectangle_prog.
build_program(ctx,
"plot2d_rect.glpr", options,
true)) {
137 std::cerr <<
"could not build GLSL program from plot2d_rect.glpr" << std::endl;
141 rectangle_prog.allow_context_to_set_color(
false);
148 aam_domain_tick_labels.destruct(ctx);
160 GLsizei count = (GLsizei)enable_attributes(ctx, i,
samples);
171 point_prog.
set_uniform(ctx,
"halo_width_in_pixel", 0.0f);
174 point_prog.
set_uniform(ctx,
"measure_point_size_in_pixel",
false);
175 point_prog.
set_uniform(ctx,
"screen_aligned",
false);
186 draw_sub_plot_samples(count, spc);
191 disable_attributes(ctx, i);
203 if (spc.show_lines && line_prog.
is_linked()) {
210 line_prog.
set_uniform(ctx,
"halo_width_in_pixel", 0.0f);
211 line_prog.
set_uniform(ctx,
"halo_color_strength", 1.0f);
212 line_prog.
set_uniform(ctx,
"halo_color", spc.line_halo_color.color);
213 line_prog.
set_uniform(ctx,
"percentual_halo_width", spc.line_halo_width.size / spc.line_width.size);
215 line_prog.
set_uniform(ctx,
"measure_line_width_in_pixel",
false);
216 line_prog.
set_uniform(ctx,
"screen_aligned",
false);
217 line_prog.
set_uniform(ctx,
"color_index", spc.line_color.color_idx);
218 line_prog.
set_uniform(ctx,
"secondary_size_index", spc.line_halo_width.size_idx);
219 line_prog.
set_uniform(ctx,
"secondary_color_index", spc.line_halo_color.color_idx);
220 line_prog.
set_uniform(ctx,
"opacity_index", spc.line_color.opacity_idx);
221 line_prog.
set_uniform(ctx,
"secondary_opacity_index", spc.line_halo_color.opacity_idx);
222 line_prog.
set_uniform(ctx,
"size_index", spc.line_width.size_idx);
223 line_prog.
set_attribute(ctx, line_prog.get_color_index(), spc.line_color.color);
224 line_prog.
set_attribute(ctx,
"secondary_color", spc.line_halo_color.color);
228 draw_sub_plot_samples(count, spc,
true);
231 for (
unsigned j = 0; j <
strips[i].size(); ++j) {
232 glDrawArrays(GL_LINE_STRIP, fst,
strips[i][j]);
240 disable_attributes(ctx, i);
252 if (spc.show_sticks && rectangle_prog.
is_linked()) {
255 rectangle_prog.
set_uniform(ctx,
"color_index", spc.stick_color.color_idx);
256 rectangle_prog.
set_uniform(ctx,
"secondary_color_index", -1);
257 rectangle_prog.
set_uniform(ctx,
"opacity_index", spc.stick_color.opacity_idx);
258 rectangle_prog.
set_uniform(ctx,
"secondary_opacity_index", -1);
259 rectangle_prog.
set_uniform(ctx,
"size_index", spc.stick_width.size_idx);
260 rectangle_prog.
set_uniform(ctx,
"secondary_size_index", -1);
261 rectangle_prog.
set_uniform(ctx,
"rectangle_base_window", spc.stick_base_window);
262 rectangle_prog.
set_uniform(ctx,
"rectangle_coordinate_index", spc.stick_coordinate_index);
263 rectangle_prog.
set_uniform(ctx,
"rectangle_border_width", 0.0f);
264 rectangle_prog.
set_attribute(ctx, rectangle_prog.get_color_index(), spc.stick_color.color);
268 rectangle_prog.
set_uniform(ctx,
"border_mode", spc.stick_coordinate_index == 0 ? 2 : 1);
270 rectangle_prog.
enable(ctx);
271 draw_sub_plot_samples(count, spc);
276 disable_attributes(ctx, i);
285 rectangle_prog.
set_uniform(ctx,
"pixel_blend", 2.0f);
288 rectangle_prog.
set_uniform(ctx,
"use_texture",
false);
290 rectangle_prog.
set_uniform(ctx,
"culling_mode", 0);
291 rectangle_prog.
set_uniform(ctx,
"map_color_to_material", 7);
292 rectangle_prog.
set_uniform(ctx,
"illumination_mode", 0);
304 if (spc.show_bars && rectangle_prog.
is_linked()) {
307 rectangle_prog.
set_uniform(ctx,
"color_index", spc.bar_color.color_idx);
308 rectangle_prog.
set_uniform(ctx,
"secondary_color_index", spc.bar_outline_color.color_idx);
309 rectangle_prog.
set_uniform(ctx,
"opacity_index", spc.bar_color.opacity_idx);
310 rectangle_prog.
set_uniform(ctx,
"secondary_opacity_index", spc.bar_outline_color.opacity_idx);
311 rectangle_prog.
set_uniform(ctx,
"size_index", spc.bar_percentual_width.size_idx);
312 rectangle_prog.
set_uniform(ctx,
"secondary_size_index", spc.bar_outline_width.size_idx);
313 rectangle_prog.
set_uniform(ctx,
"rectangle_base_window", spc.bar_base_window);
314 rectangle_prog.
set_uniform(ctx,
"rectangle_coordinate_index", spc.bar_coordinate_index);
316 rectangle_prog.
set_attribute(ctx, rectangle_prog.get_color_index(), spc.bar_color.color);
317 rectangle_prog.
set_attribute(ctx,
"secondary_color", spc.bar_outline_color.color);
318 rectangle_prog.
set_attribute(ctx,
"size", (count > 1 ?
extent[0] / (count - 1) :
extent[0]) * spc.bar_percentual_width.size);
321 rectangle_prog.
set_uniform(ctx,
"border_mode", spc.bar_coordinate_index == 0 ? 2 : 1);
323 rectangle_prog.
enable(ctx);
324 draw_sub_plot_samples(count, spc);
329 disable_attributes(ctx, i);
338 draw_bar_plot(ctx, i, layer_idx);
343 draw_stick_plot(ctx, i, layer_idx);
348 draw_line_plot(ctx, i, layer_idx);
353 draw_point_plot(ctx, i, layer_idx);
359void plot2d::extract_domain_rectangles(std::vector<box2>& R, std::vector<rgb>& C, std::vector<float>& D)
370 for (
unsigned ai = 0; ai < 2; ++ai) {
373 float lw = rs * ac.line_width;
375 vec2 axis_extent(0.0f);
376 axis_extent[ai] =
extent[ai];
377 axis_extent[1 - ai] = lw;
378 box2 axis_box(-0.5f * axis_extent, 0.5f * axis_extent);
379 axis_box.ref_min_pnt()[1 - ai] += 0.5f * (
extent[1 - ai] - lw);
380 axis_box.ref_max_pnt()[1 - ai] += 0.5f * (
extent[1 - ai] - lw);
381 R[2 * ai + 1] = axis_box;
384 axis_box.ref_min_pnt()[1 - ai] -=
extent[1 - ai] - lw;
385 axis_box.ref_max_pnt()[1 - ai] -=
extent[1 - ai] - lw;
386 R[2 * ai + 2] = axis_box;
390 if (ao.get_attribute_min() < 0 && ao.get_attribute_max() > 0) {
391 float axis_plot = ao.plot_space_from_attribute_space(0.0f);
392 axis_box.ref_min_pnt()[1 - ai] = axis_plot - 0.5f * lw;
393 axis_box.ref_max_pnt()[1 - ai] = axis_plot + 0.5f * lw;
394 R.push_back(axis_box);
395 C.push_back(ac.color);
497void plot2d::extract_domain_tick_rectangles_and_tick_labels(
498 std::vector<box2>& R, std::vector<rgb>& C, std::vector<float>& D,
499 std::vector<label_info>& tick_labels, std::vector<tick_batch_info>& tick_batches)
505 for (
unsigned ti = 0; ti < 2; ++ti) {
506 for (
unsigned ai = 0; ai < 2; ++ai) {
509 float z_plot = (ao.get_attribute_min() < 0.0f && ao.get_attribute_max() > 0.0f) ?
510 ao.plot_space_from_attribute_space(0.0f) : std::numeric_limits<float>::quiet_NaN();
511 tick_batch_info tbi(ai, 1 - ai, ti == 0, 0, (
unsigned)
tick_labels.size());
512 if (extract_tick_rectangles_and_tick_labels(R, C, D,
tick_labels, ai, ai, ti, 0.5f * ao.extent, z_plot, 1.0f,
vec2(0.0f), -3 *
layer_depth, ac.multi_axis_ticks)) {
513 if ((tbi.label_count = (
unsigned)(
tick_labels.size() - tbi.first_label)) > 0)
525 std::vector<float> D;
526 extract_domain_rectangles(R, C, D);
538 GLboolean line_smooth = glIsEnabled(GL_LINE_SMOOTH);
539 GLboolean blend = glIsEnabled(GL_BLEND);
540 GLboolean cull_face = glIsEnabled(GL_CULL_FACE);
541 GLenum blend_src, blend_dst, depth;
542 glGetIntegerv(GL_BLEND_DST,
reinterpret_cast<GLint*
>(&blend_dst));
543 glGetIntegerv(GL_BLEND_SRC,
reinterpret_cast<GLint*
>(&blend_src));
544 glGetIntegerv(GL_DEPTH_FUNC,
reinterpret_cast<GLint*
>(&depth));
547 glEnable(GL_LINE_SMOOTH);
548 glDisable(GL_CULL_FACE);
550 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
551 glDepthFunc(GL_LEQUAL);
560 configure_bar_plot(ctx);
567 if (disable_depth_mask)
568 glDepthMask(GL_FALSE);
570 glDepthFunc(GL_LEQUAL);
571 draw_sub_plots_jointly(ctx, 8);
572 if (disable_depth_mask)
573 glDepthMask(GL_TRUE);
575 glDepthFunc(GL_LESS);
580 double plot_pos_eye_z = M(2, 3);
581 double plot_z_eye_z = M(2, 2);
596 for (
int i = i_begin; i != i_end; i += i_delta) {
601 float min_val, max_val;
602 ac.put_backup_attribute_range(min_val, max_val);
604 if (fabs(max_val - min_val) < 10.0f * std::numeric_limits<float>::epsilon())
605 max_val = min_val + 1;
606 ac.set_attribute_range(min_val, max_val);
612 draw_domain(ctx, i, !fst);
615 if (disable_depth_mask)
616 glDepthMask(GL_FALSE);
618 glDepthFunc(GL_LEQUAL);
619 draw_bar_plot(ctx, i, 8);
620 draw_stick_plot(ctx, i, 9);
621 draw_line_plot(ctx, i, 10);
622 draw_point_plot(ctx, i, 11);
623 if (disable_depth_mask)
624 glDepthMask(GL_TRUE);
626 glDepthFunc(GL_LESS);
639 glDisable(GL_LINE_SMOOTH);
643 glEnable(GL_CULL_FACE);
645 glBlendFunc(blend_src, blend_dst);
base class for all classes that can be registered with support for dynamic properties (see also secti...
derive from this class to provide a gui to the current viewer
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.
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...
static fvec< float, N > from_vec(const vec< float > &)
conversion from vector
void put_homogeneous_matrix(hmat_type &M) const
compute equivalent homogeneous 4x4 rotation matrix
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 clear(cgv::render::context &ctx)
destruct shader programs
std::vector< std::vector< unsigned > > strips
allow to split series into connected strips that are represented by the number of contained samples
void create_point_config_gui(cgv::base::base *bp, cgv::gui::provider &p, plot_base_config &pbc)
create the gui for a point subplot
std::vector< vec2 > & ref_sub_plot_samples(unsigned i=0)
return the samples of the i-th sub plot
void create_gui(cgv::base::base *bp, cgv::gui::provider &p)
create a gui for the plot with gui for all configs
cgv::render::attribute_array_manager aam_domain
attribute managers for domain rectangles and domain tick labels
void delete_sub_plot(unsigned i)
delete the i-th sub plot
void create_bar_config_gui(cgv::base::base *bp, cgv::gui::provider &p, plot_base_config &pbc)
create the gui for a bar subplot
void draw(cgv::render::context &ctx)
draw plot
std::vector< unsigned > & ref_sub_plot_strips(unsigned i=0)
return the strip definition of the i-th sub plot
plot2d_config & ref_sub_plot2d_config(unsigned i=0)
return a reference to the plot1d configuration of the i-th plot
bool * multi_axis_modes
whether to manage separate axes for each sub plot
vec3 sub_plot_delta
offset in between sub plots in x, y and z direction
void create_config_gui(cgv::base::base *bp, cgv::gui::provider &p, unsigned i)
create the gui for a subplot configuration
unsigned add_sub_plot(const std::string &name)
add sub plot and return sub plot index
plot2d(const std::string &title, unsigned nr_attributes=0)
construct 2D plot with given number of additional attributes and default parameters
std::vector< std::vector< vec2 > > samples
store 2d samples for data series
bool init(cgv::render::context &ctx)
construct shader programs
base class for plot2d and plot3d, which can have several sub plots each
cgv::render::rectangle_render_style rrs
render style of rectangles
virtual void create_config_gui(cgv::base::base *bp, cgv::gui::provider &p, unsigned i)
create the gui for a subplot configuration
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
const domain_config * get_domain_config_ptr() const
return const pointer to domain configuration
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
std::vector< attribute_source_array > attribute_source_arrays
attribute sources
vecn get_extent() const
query the plot extend in 2D coordinates
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 layer_depth
depth offset of a single layer
quat orientation
orientiation quaternion mapping from domain to world 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
std::vector< label_info > tick_labels
all tick labels
plot_base_config & ref_sub_plot_config(unsigned i)
return a reference to the plot base configuration of the i-th plot
unsigned nr_attributes
number of additional attributes
void prepare_extents()
prepare extents for drawing
virtual void create_gui(cgv::base::base *bp, cgv::gui::provider &p)
create a gui for the plot with gui for all configs
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
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
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 set_plot_uniforms(cgv::render::context &ctx, cgv::render::shader_program &prog)
set the uniforms for plot configurations
size_t enable_attributes(cgv::render::context &ctx, int i, const std::vector< std::vector< vec2 > > &samples)
set vertex shader input attributes based on attribute source information
bool init(cgv::render::context &ctx)
build legend prog and create aab
vec3 extent
extents used for drawing current
base class for all drawables, which is independent of the used rendering API.
virtual void mul_modelview_matrix(const dmat4 &MV)
multiply given matrix from right to current modelview matrix
virtual unsigned int get_height() const =0
return the height of the window
virtual dmat4 get_modelview_matrix() const =0
return homogeneous 4x4 viewing matrix, which transforms from world to eye space
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.
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,...
void destruct(const context &ctx)
destruct shader program
bool is_linked() const
return whether program is linked
bool set_attribute(const context &ctx, const std::string &name, const T &value)
set constant default value of a vertex attribute by attribute name, if name does not specify an attri...
bool build_program(const context &ctx, const std::string &file_name, bool show_error=false)
successively calls create, attach_program and link.
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
T min_value(ForwardIt first, ForwardIt last, T fallback)
Find the minimum value in the range [first, last) or return fallback if the range is empty.
T max_value(ForwardIt first, ForwardIt last, T fallback)
Find the maximum value in the range [first, last) or return fallback if the range is empty.
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
struct that manages attribute sources and corresponding gpu objects per subplot
store source of a single plot attribute (one coordinate axis or one float attribute)
float reference_size
store size of virtual pixel based measurement
bool fill
whether to fill the domain
std::string title
plot title
std::vector< axis_config > axis_configs
store a vector of axis configurations (2/3 for plot2/3d plus several attribute axes)
rgb color
color of the domain fill
extend common plot configuration with parameters specific to 2d plot
void configure_chart(ChartType chart_type)
configure the sub plot to a specific chart type
plot2d_config(const std::string &_name)
set default values
plot independent configuration parameters of one sub plot in a 2d or 3d plot
virtual void configure_chart(ChartType chart_type)
configure the sub plot to a specific chart type
std::string name
name of sub plot
bool show_lines
whether to connect data points with lines
bool show_points
whether to show data points
mapped_rgba point_color
point color
mapped_size point_halo_width
width of point halo in pixel
mapped_size point_size
point size in pixels
mapped_rgba point_halo_color
color of point halo
holds options applied before and during shader compilation, such as preprocessor defines and code sni...
shader_define_map defines
map of pre-processor define names to values