23 #ifndef SRC_OPENGL_VISUALIZATION_WINDOWFLOATCOLLECTORCHART_HPP_
24 #define SRC_OPENGL_VISUALIZATION_WINDOWFLOATCOLLECTORCHART_HPP_
28 #include <types/Color.hpp>
30 #include <utils/DataCollector.hpp>
34 namespace visualization {
42 template <
typename eT=
float>
49 unsigned int position_x_ = 0,
unsigned int position_y_ = 0,
50 unsigned int width_ = 1024,
unsigned int height_ = 256) :
51 Window(name_, position_x_, position_y_, width_, height_),
85 LOG(LTRACE) <<
"WindowFloatCollectorChart::Display handler of window " << glutGetWindow();
87 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
90 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
91 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
100 mic::utils::DataContainers<std::string, eT> containers =
collector_ptr->getContainers();
103 unsigned int label_x_offset = 10;
104 unsigned int label_y_offset = 15;
106 for(mic::utils::DataContainerIt<std::string, eT> it = containers.begin(); it != containers.end(); it++, label_y_offset+=15) {
108 std::string l = it->first;
111 std::vector<eT> vector = (it->second)->data;
113 eT min_value = (it->second)->min_value;
114 eT max_value = (it->second)->max_value;
117 color_rgba c = (it->second)->color;
118 eT line_width = (it->second)->line_width;
126 if (acc_y + acc_h + label_y_offset > (
unsigned int) glutGet((GLenum) GLUT_WINDOW_HEIGHT)) {
128 label_x_offset += 200;
132 redrawSingleContainer(l, vector, min_value, max_value, c, line_width, label_x_offset, label_y_offset);
148 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
158 LOG(LTRACE)<<
"WindowFloatCollectorChart::refreshChart";
167 draw_rectangle(acc_x, acc_y, acc_h, acc_w, 0.7f, 0.7f, 0.7f, 1.0f);
168 draw_rectangle(acc_x, acc_y + acc_h, acc_h, acc_w, 0.7f, 0.7f, 0.7f, 1.0f);
175 sprintf(value,
"%d%%", (
unsigned)(
float)round((100.0 * h)));
176 draw_text(acc_x - 30, acc_y + acc_h - (
int)(h * acc_h) + 2, value, 1.0f, 1.0f, 1.0f, 0.5f, GLUT_BITMAP_HELVETICA_10);
177 draw_text(acc_x + acc_w + 5, acc_y + acc_h - (
int)(h * acc_h) + 2, value, 1.0f, 1.0f, 1.0f, 0.5f, GLUT_BITMAP_HELVETICA_10);
179 glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
181 glVertex2i(acc_x, acc_y + acc_h - (
int)(h * acc_h));
182 glVertex2i(acc_x + acc_w, acc_y + acc_h - (
int)(h * acc_h));
198 void redrawSingleContainer(std:: string & label_, std::vector<eT> & data_, eT min_value_, eT max_value_, mic::types::color_rgba color_, eT line_width_,
unsigned short label_x_offset_,
unsigned short label_y_offset_) {
199 LOG(LTRACE)<<
"WindowFloatCollectorChart::refreshSingleChart";
207 glLineWidth(line_width_);
208 glBegin(GL_LINE_STRIP);
211 eT diff = max_value_ - min_value_;
217 for (
int i = 0; i < chart_width * (
width); i++) {
219 if (data_.size() - 1 - (size_t)round(i *
zoom_factor) < data_.size()) {
220 value = data_[data_.size() - 1 - (size_t)(i * zoom_factor)];
222 value = (value - min_value_)/(diff);
223 glColor4f(color_.r/255.0f, color_.g/255.0f, color_.b/255.0f, color_.a/255.0f);
224 glVertex2i(acc_x + acc_w - (
int)(i), acc_y + acc_h - (
int)(value * acc_h));
231 char str_value[100] =
"-";
232 if (data_.size() > 0) {
233 value = data_[data_.size() - 1];
234 sprintf(str_value,
"%s: %.2f (%.2f : %.2f)", label_.c_str(), value, min_value_, max_value_);
237 sprintf(str_value,
"%s: -", label_.c_str());
239 draw_text(acc_x + label_x_offset_, acc_y + acc_h + label_y_offset_, str_value, color_.r/255.0f, color_.g/255.0f, color_.b/255.0f, color_.a/255.0f, GLUT_BITMAP_HELVETICA_10);
WindowCollectorChart(std::string name_="Chart", unsigned int position_x_=0, unsigned int position_y_=0, unsigned int width_=1024, unsigned int height_=256)
float zoom_factor
Zoom factor - used for zoomin in and out in the chart window.
void setDataCollectorPtr(mic::utils::DataCollectorPtr< std::string, eT > collector_ptr_)
void keyhandlerZoomReset(void)
void draw_text(float x, float y, char *string, float r, float g, float b, float a, void *font)
virtual ~WindowCollectorChart()
void redrawSingleContainer(std::string &label_, std::vector< eT > &data_, eT min_value_, eT max_value_, mic::types::color_rgba color_, eT line_width_, unsigned short label_x_offset_, unsigned short label_y_offset_)
OpenGL-based window responsible for displaying data collected in DataCollector objects in the form of...
void keyhandlerZoomIn(void)
#define VGL_MANAGER
Macro returning OpenGL window manager instance.
double chart_height
Chart width.
double chart_width
Chart width.
void redrawMainChartWindow()
Contains declaration of parent class of all OpenGL-based windows.
mic::utils::DataCollectorPtr< std::string, eT > collector_ptr
Data collector associated with .
void keyhandlerZoomOut(void)
void displayHandler(void)
double label_offset_y
Label offset y.
double label_offset_x
Label offset x.
WindowCollectorChart< float > WindowCollectorFloatChart
Parent class of all OpenGL-based windows (abstract).
void draw_rectangle(float x, float y, float h, float w, float r, float g, float b, float a)
double number_of_horizontal_bars
Number of horizontal bars in chart.