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);
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);
187 draw_sub_plot_samples(count, spc);
193 disable_attributes(ctx, i);
205 if (spc.show_lines && line_prog.
is_linked()) {
212 line_prog.
set_uniform(ctx,
"halo_width_in_pixel", 0.0f);
213 line_prog.
set_uniform(ctx,
"halo_color_strength", 1.0f);
214 line_prog.
set_uniform(ctx,
"halo_color", spc.line_halo_color.color);
215 line_prog.
set_uniform(ctx,
"percentual_halo_width", spc.line_halo_width.size / spc.line_width.size);
217 line_prog.
set_uniform(ctx,
"measure_line_width_in_pixel",
false);
218 line_prog.
set_uniform(ctx,
"screen_aligned",
false);
219 line_prog.
set_uniform(ctx,
"color_index", spc.line_color.color_idx);
220 line_prog.
set_uniform(ctx,
"secondary_size_index", spc.line_halo_width.size_idx);
221 line_prog.
set_uniform(ctx,
"secondary_color_index", spc.line_halo_color.color_idx);
222 line_prog.
set_uniform(ctx,
"opacity_index", spc.line_color.opacity_idx);
223 line_prog.
set_uniform(ctx,
"secondary_opacity_index", spc.line_halo_color.opacity_idx);
224 line_prog.
set_uniform(ctx,
"size_index", spc.line_width.size_idx);
225 line_prog.
set_attribute(ctx, line_prog.get_color_index(), spc.line_color.color);
226 line_prog.
set_attribute(ctx,
"secondary_color", spc.line_halo_color.color);
231 draw_sub_plot_samples(count, spc,
true);
234 for (
unsigned j = 0; j <
strips[i].size(); ++j) {
235 glDrawArrays(GL_LINE_STRIP, fst,
strips[i][j]);
244 disable_attributes(ctx, i);
256 if (spc.show_sticks && rectangle_prog.
is_linked()) {
259 rectangle_prog.
set_uniform(ctx,
"color_index", spc.stick_color.color_idx);
260 rectangle_prog.
set_uniform(ctx,
"secondary_color_index", -1);
261 rectangle_prog.
set_uniform(ctx,
"opacity_index", spc.stick_color.opacity_idx);
262 rectangle_prog.
set_uniform(ctx,
"secondary_opacity_index", -1);
263 rectangle_prog.
set_uniform(ctx,
"size_index", spc.stick_width.size_idx);
264 rectangle_prog.
set_uniform(ctx,
"secondary_size_index", -1);
265 rectangle_prog.
set_uniform(ctx,
"rectangle_base_window", spc.stick_base_window);
266 rectangle_prog.
set_uniform(ctx,
"rectangle_coordinate_index", spc.stick_coordinate_index);
267 rectangle_prog.
set_uniform(ctx,
"rectangle_border_width", 0.0f);
268 rectangle_prog.
set_attribute(ctx, rectangle_prog.get_color_index(), spc.stick_color.color);
272 rectangle_prog.
set_uniform(ctx,
"border_mode", spc.stick_coordinate_index == 0 ? 2 : 1);
275 rectangle_prog.
enable(ctx);
276 draw_sub_plot_samples(count, spc);
282 disable_attributes(ctx, i);
291 rectangle_prog.
set_uniform(ctx,
"pixel_blend", 2.0f);
294 rectangle_prog.
set_uniform(ctx,
"use_texture",
false);
296 rectangle_prog.
set_uniform(ctx,
"culling_mode", 0);
297 rectangle_prog.
set_uniform(ctx,
"map_color_to_material", 7);
298 rectangle_prog.
set_uniform(ctx,
"illumination_mode", 0);
310 if (spc.show_bars && rectangle_prog.
is_linked()) {
313 rectangle_prog.
set_uniform(ctx,
"color_index", spc.bar_color.color_idx);
314 rectangle_prog.
set_uniform(ctx,
"secondary_color_index", spc.bar_outline_color.color_idx);
315 rectangle_prog.
set_uniform(ctx,
"opacity_index", spc.bar_color.opacity_idx);
316 rectangle_prog.
set_uniform(ctx,
"secondary_opacity_index", spc.bar_outline_color.opacity_idx);
317 rectangle_prog.
set_uniform(ctx,
"size_index", spc.bar_percentual_width.size_idx);
318 rectangle_prog.
set_uniform(ctx,
"secondary_size_index", spc.bar_outline_width.size_idx);
319 rectangle_prog.
set_uniform(ctx,
"rectangle_base_window", spc.bar_base_window);
320 rectangle_prog.
set_uniform(ctx,
"rectangle_coordinate_index", spc.bar_coordinate_index);
322 rectangle_prog.
set_attribute(ctx, rectangle_prog.get_color_index(), spc.bar_color.color);
323 rectangle_prog.
set_attribute(ctx,
"secondary_color", spc.bar_outline_color.color);
324 rectangle_prog.
set_attribute(ctx,
"size", (count > 1 ?
extent[0] / (count - 1) :
extent[0]) * spc.bar_percentual_width.size);
327 rectangle_prog.
set_uniform(ctx,
"border_mode", spc.bar_coordinate_index == 0 ? 2 : 1);
330 rectangle_prog.
enable(ctx);
331 draw_sub_plot_samples(count, spc);
337 disable_attributes(ctx, i);
346 draw_bar_plot(ctx, i, layer_idx);
351 draw_stick_plot(ctx, i, layer_idx);
356 draw_line_plot(ctx, i, layer_idx);
361 draw_point_plot(ctx, i, layer_idx);
367void plot2d::extract_domain_rectangles(std::vector<box2>& R, std::vector<rgb>& C, std::vector<float>& D)
378 for (
unsigned ai = 0; ai < 2; ++ai) {
381 float lw = rs * ac.line_width;
383 vec2 axis_extent(0.0f);
384 axis_extent[ai] =
extent[ai];
385 axis_extent[1 - ai] = lw;
386 box2 axis_box(-0.5f * axis_extent, 0.5f * axis_extent);
387 axis_box.ref_min_pnt()[1 - ai] += 0.5f * (
extent[1 - ai] - lw);
388 axis_box.ref_max_pnt()[1 - ai] += 0.5f * (
extent[1 - ai] - lw);
389 R[2 * ai + 1] = axis_box;
392 axis_box.ref_min_pnt()[1 - ai] -=
extent[1 - ai] - lw;
393 axis_box.ref_max_pnt()[1 - ai] -=
extent[1 - ai] - lw;
394 R[2 * ai + 2] = axis_box;
398 if (ao.get_attribute_min() < 0 && ao.get_attribute_max() > 0) {
399 float axis_plot = ao.plot_space_from_attribute_space(0.0f);
400 axis_box.ref_min_pnt()[1 - ai] = axis_plot - 0.5f * lw;
401 axis_box.ref_max_pnt()[1 - ai] = axis_plot + 0.5f * lw;
402 R.push_back(axis_box);
403 C.push_back(ac.color);
505void plot2d::extract_domain_tick_rectangles_and_tick_labels(
506 std::vector<box2>& R, std::vector<rgb>& C, std::vector<float>& D,
507 std::vector<label_info>& tick_labels, std::vector<tick_batch_info>& tick_batches)
513 for (
unsigned ti = 0; ti < 2; ++ti) {
514 for (
unsigned ai = 0; ai < 2; ++ai) {
517 float z_plot = (ao.get_attribute_min() < 0.0f && ao.get_attribute_max() > 0.0f) ?
518 ao.plot_space_from_attribute_space(0.0f) : std::numeric_limits<float>::quiet_NaN();
519 tick_batch_info tbi(ai, 1 - ai, ti == 0, 0, (
unsigned)
tick_labels.size());
520 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)) {
521 if ((tbi.label_count = (
unsigned)(
tick_labels.size() - tbi.first_label)) > 0)
533 std::vector<float> D;
534 extract_domain_rectangles(R, C, D);
561 configure_bar_plot(ctx);
568 if (disable_depth_mask)
572 draw_sub_plots_jointly(ctx, 8);
573 if (disable_depth_mask)
581 double plot_pos_eye_z = M(2, 3);
582 double plot_z_eye_z = M(2, 2);
597 for (
int i = i_begin; i != i_end; i += i_delta) {
602 float min_val, max_val;
603 ac.put_backup_attribute_range(min_val, max_val);
605 if (fabs(max_val - min_val) < 10.0f * std::numeric_limits<float>::epsilon())
606 max_val = min_val + 1;
607 ac.set_attribute_range(min_val, max_val);
613 draw_domain(ctx, i, !fst);
616 if (disable_depth_mask)
620 draw_bar_plot(ctx, i, 8);
621 draw_stick_plot(ctx, i, 9);
622 draw_line_plot(ctx, i, 10);
623 draw_point_plot(ctx, i, 11);
624 if (disable_depth_mask)
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...
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
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
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.
base class for all drawables, which is independent of the used rendering API.
void set_blend_func_back_to_front()
set the default blend function for back to front blending (source = BF_SRC_ALPHA, destination = BF_ON...
virtual void mul_modelview_matrix(const dmat4 &MV)
multiply given matrix from right to current modelview matrix
void pop_buffer_mask()
pop the top of the current buffer mask from the stack
void push_depth_test_state()
push a copy of the current depth test state onto the stack saved attributes: depth test enablement,...
void push_blend_state()
push a copy of the current blend state onto the stack saved attributes: blend enablement,...
void pop_blend_state()
pop the top of the current culling state from the stack
void pop_depth_test_state()
pop the top of the current depth test state from the stack
virtual unsigned int get_height() const =0
return the height of the window
void push_cull_state()
push a copy of the current culling state onto the stack saved attributes: cull face enablement,...
virtual void set_cull_state(CullingMode culling_mode)
set the culling state
virtual void set_depth_func(CompareFunction func)
set the depth test function
virtual void enable_blending()
enable blending
virtual dmat4 get_modelview_matrix() const =0
return homogeneous 4x4 viewing matrix, which transforms from world to eye space
void pop_cull_state()
pop the top of the current culling state from the stack
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 push_buffer_mask()
push a copy of the current buffer mask onto the stack saved attributes: depth mask,...
virtual void set_depth_mask(bool flag)
set the depth buffer mask
Stores preprocessor options used for conditionally compiling shader programs.
void define_macro(const std::string &identifier)
Define a macro as identifier and no replacement text.
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.
this header is dependency free
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