22 #ifndef KJB_CPP_GUI_CPP_GUI_GRAPH_H
23 #define KJB_CPP_GUI_CPP_GUI_GRAPH_H
25 #ifdef KJB_HAVE_OPENGL
33 #include <boost/array.hpp>
34 #include <boost/optional.hpp>
41 class Plot :
public Overlay
66 void expand(
const Data_range&
r);
68 void expand(
float x,
float y);
71 typedef std::map<double, double> Data_map;
82 template <
class Iterator_x,
class Iterator_y>
83 void set(Iterator_x begin, Iterator_x end, Iterator_y ybegin)
86 Iterator_y it_y = ybegin;
87 for(Iterator_x it = begin; it != end; ++it, ++it_y)
94 template <
class Iterator_y>
95 void set(Iterator_y ybegin, Iterator_y yend)
99 for(Iterator_y it = ybegin; it != yend; ++it)
108 void set(
const Data_map& in)
114 template <
class Iterator_x,
class Iterator_y>
115 void append(Iterator_x begin, Iterator_x end, Iterator_y ybegin)
117 Data_range append_range;
118 Iterator_y it_y = ybegin;
119 for(Iterator_x it = begin; it != end; ++it, ++it_y)
122 append_range.expand(*it, *it_y);
124 expand_data_range_(append_range);
127 template <
class Iterator_y>
128 void append(Iterator_y ybegin, Iterator_y yend)
130 Data_range append_range;
131 Iterator_y it_y = ybegin;
136 i = data.rbegin()->first + 1;
138 for(Iterator_y it = ybegin; it != yend; ++it)
142 append_range.expand(i, *it_y);
144 expand_data_range_(append_range);
147 void append(
const Data_map& in)
149 Data_range append_range;
150 typedef Data_map::const_iterator Iterator;
151 typedef Data_map::value_type Data_pair;
153 for(Iterator it = in.begin(); it != in.end(); ++it)
156 append_range.expand(it->first, it->second);
159 expand_data_range_(append_range);
164 const Data_range& get_data_range()
169 void update_data_range();
176 void expand_data_range_(
const Data_range& range);
178 Data_range data_range_;
183 typedef std::list<Data_set> Data_sets;
196 operator bool()
const
198 return (y_size > 0 && x_size > 0);
204 template <
class Iterator>
205 void update_data_range(Iterator begin, Iterator end)
209 for(Iterator it = begin; it != end; ++it)
211 data_range_.expand(*it);
220 void set(
float x_min_,
float x_max_,
float y_min_,
float y_max_);
228 void auto_set(
bool include_x_origin,
bool include_y_origin);
244 void automatic(
bool include_x_origin,
bool include_y_origin)
247 auto_include_x_ = include_x_origin;
248 auto_include_y_ = include_y_origin;
250 auto_set(auto_include_x_, auto_include_y_);
261 void set_hash_spacing(
float min_width,
float min_height)
265 min_dx_normalized_ = min_width;
266 min_dy_normalized_ = min_height;
269 if(min_dy_normalized_ > 1.0)
270 min_dy_normalized_ = 1.0;
272 if(min_dx_normalized_ > 1.0)
273 min_dx_normalized_ = 1.0;
275 update_ideal_range_x();
276 update_ideal_range_y();
279 void update_real_range()
282 auto_set(auto_include_x_, auto_include_y_);
292 void update_ideal_range_y()
294 if(y_size < SIZE_EPSILON)
298 float min_height = min_dy_normalized_ * y_size;
300 dy = human_quantize_range_(y_min, y_max, auto_, 10, min_height);
305 y_size = y_max - y_min;
308 assert(y_size < DBL_MAX);
310 assert(y_size < 1e15);
322 void update_ideal_range_x()
332 if(x_size < SIZE_EPSILON)
336 float min_width = min_dx_normalized_ * x_size;
343 dx = human_quantize_range_(x_min, x_max, auto_, 10, min_width);
348 x_size = x_max - x_min;
351 assert(x_size < DBL_MAX);
356 static double human_quantize_range_(
float&
xmin,
float&
xmax,
bool quantize_bounds,
size_t max_num_bins,
float min_incr);
362 static void quantize_range_(
float& x_min,
float& x_max,
float incr)
365 x_max = std::ceil(x_max / incr) * incr;
381 float& hash_dy)
const;
385 bool auto_include_x_;
386 bool auto_include_y_;
388 Data_range data_range_;
390 float min_dx_normalized_;
391 float min_dy_normalized_;
404 static const float SIZE_EPSILON;
409 typedef Data_sets::iterator Data_set_iterator;
410 static const Vector3 DEFAULT_COLOR;
416 update_data_pane_geometry();
419 void set_transparent_background()
424 virtual void set_size(
int width,
int height)
426 Base::set_size(width, height);
430 virtual void set_position(
int x,
int y)
432 Base::set_position(x, y);
439 Data_set_iterator add_dataset(
const Vector3& line_color = DEFAULT_COLOR);
444 Data_set_iterator add_dataset(
const Data_map& data,
const Vector3& line_color = DEFAULT_COLOR);
449 void update_dataset(Data_set_iterator data_set,
const Data_map& data)
452 update_axis_data_range();
458 void append_dataset(Data_set_iterator data_set,
const Data_map& data)
460 data_set->append(data);
461 update_axis_data_range();
468 template <
class Iterator_x,
class Iterator_y>
469 Data_set_iterator add_dataset(Iterator_x begin, Iterator_x end, Iterator_y ybegin,
const Vector3& line_color = DEFAULT_COLOR)
472 if(color == DEFAULT_COLOR)
473 color = COLOR_ORDER_[data_sets_.size() % COLOR_ORDER_.size()];
475 data_sets_.push_front(Data_set());
476 Data_set_iterator data_set = data_sets_.begin();
478 data_set->color = color;
479 update_dataset(data_set, begin, end, ybegin);
486 template <
class Iterator_x,
class Iterator_y>
487 void update_dataset(Data_set_iterator data_set, Iterator_x begin, Iterator_x end, Iterator_y ybegin)
489 data_set->set(begin, end, ybegin);
490 update_axis_data_range();
496 template <
class Iterator_x,
class Iterator_y>
497 void append_dataset(Data_set_iterator data_set, Iterator_x begin, Iterator_x end, Iterator_y ybegin)
499 data_set->append(begin, end, ybegin);
500 update_axis_data_range();
506 template <
class Iterator_y>
507 Data_set_iterator add_dataset(Iterator_y ybegin, Iterator_y yend,
const Vector3& line_color = DEFAULT_COLOR)
510 if(color == DEFAULT_COLOR)
511 color = COLOR_ORDER_[data_sets_.size() % COLOR_ORDER_.size()];
513 data_sets_.push_front(Data_set());
514 Data_set_iterator data_set = data_sets_.begin();
516 data_set->color = color;
517 update_dataset(data_set, ybegin, yend);
518 return data_sets_.begin();
524 template <
class Iterator_y>
525 void update_dataset(Data_set_iterator data_set, Iterator_y ybegin, Iterator_y yend)
527 data_set->set(ybegin, yend);
528 update_axis_data_range();
534 template <
class Iterator_y>
535 void append_dataset(Data_set_iterator data_set, Iterator_y ybegin, Iterator_y yend)
537 data_set->append(ybegin, yend);
538 update_axis_data_range();
544 Data_set_iterator get_dataset(
size_t index);
546 void update_axis_data_range();
549 void set_mark(
double x)
568 void axis(
float x_min,
float x_max,
float y_min,
float y_max)
570 axis_.set(x_min, x_max, y_min, y_max);
574 void auto_axis(
bool include_x =
false,
bool include_y =
false)
576 axis_.automatic(include_x, include_y);
580 void title(
const std::string& title)
583 render_title_ =
true;
584 update_data_pane_geometry();
588 void xlabel(
const std::string& label)
590 x_axis_label_ = label;
591 render_x_axis_label_ =
true;
592 update_data_pane_geometry();
596 void ylabel(
const std::string& label)
598 y_axis_label_ = label;
599 render_y_axis_label_ =
true;
600 update_data_pane_geometry();
603 virtual void render()
const;
611 void render_data_frame()
const;
613 void box(
bool enabled)
620 static void draw_mark_(
const Data_set& data_set,
double x);
622 static void draw_circle_(
628 size_t subdivisions = 10);
630 void update_hash_mark_spacing();
632 float data_pane_height()
const
634 return data_pane_height_;
637 float data_pane_width()
const
639 return data_pane_width_;
642 float data_pane_x_offset()
const
644 return data_pane_x_offset_;
647 float data_pane_y_offset()
const
649 return data_pane_y_offset_;
652 void update_geometry_()
654 update_data_pane_geometry();
657 void update_data_pane_geometry();
659 static void centered_text_(
const std::string& str,
float x,
float y) ;
661 static void right_text_(
const std::string& str,
float x,
float y) ;
663 static void centered_vertical_text_(
const std::string& str,
float x,
float y) ;
669 void draw_axes(
const Axis& axis,
bool full_box)
const;
673 boost::optional<Vector3> bg_color_;
674 std::list<Data_set> data_sets_;
676 boost::optional<double> mark_;
682 std::string y_axis_label_;
683 std::string x_axis_label_;
686 bool render_y_axis_label_;
687 bool render_x_axis_label_;
689 float data_pane_x_offset_;
690 float data_pane_y_offset_;
692 float data_pane_height_;
693 float data_pane_width_;
698 static const float CHARACTER_WIDTH;
699 static const float CHARACTER_HEIGHT;
700 static const float DATA_PANE_PADDING;
701 static const float TEXT_PADDING;
702 static const float TITLE_HEIGHT;
703 static const float X_AXIS_LABEL_HEIGHT;
704 static const float Y_AXIS_LABEL_WIDTH;
705 static const float HASH_LABEL_MAX_CHARS;
706 static const float HASH_LABEL_WIDTH;
707 static const float HASH_LABEL_HEIGHT;
710 static const void* CHARACTER_FONT;
713 static const float MIN_HASH_LABEL_WIDTH;
714 static const float MIN_HASH_LABEL_HEIGHT;
715 static const float HASH_MARK_SIZE;
717 static const boost::array<Vector3, 7> COLOR_ORDER_;
Vector_d< 3 > Vector3
Definition: g_quaternion.h:37
height
Definition: APPgetLargeConnectedEdges.m:33
r
Definition: APPgetLargeConnectedEdges.m:127
REAL xmin
Definition: triangle.c:649
Int_matrix floor(const Matrix &m)
Definition: m_matrix.cpp:2026
x
Definition: APPgetLargeConnectedEdges.m:100
void render(const Cuboid &c)
Definition: psi_weighted_box.cpp:56
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
REAL xmax
Definition: triangle.c:649