NeuralEngine
A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes.
FgFigure.h
1
11#pragma once
12
13#include <MachineLearning/FgColor.h>
14#include <MachineLearning/FgWindow.h>
15
16#include <map>
17#include <string>
18#include <vector>
19
20namespace NeuralEngine
21{
22 namespace MachineLearning
23 {
24 struct NE_IMPEXP Point2
25 {
26 float x, y;
27 Point2() : Point2(0, 0) {}
28 Point2(float x, float y) : x(x), y(y) {}
29 };
30
31 struct NE_IMPEXP Point3
32 {
33 float x, y, z;
34 Point3() : Point3(0, 0, 0) {}
35 Point3(float x, float y, float z) : x(x), y(y), z(z) {}
36 };
37
38 enum Type
39 {
40 Line,
41 DotLine,
42 Dots,
43 FillLine,
44 RangeLine,
45 Histogram,
46 Vistogram,
47 Horizontal,
48 Vertical,
49 Range,
50 Circle,
51 };
52
53 class NE_IMPEXP Series
54 {
55 public:
56 Series(const std::string& label, enum Type type, Color color);
57
58 Series& type(enum Type type);
59 Series& color(Color color);
60 Series& dynamicColor(bool dynamic_color);
61 Series& legend(bool legend);
62 Series& add(const cv::Mat& data);
63 Series& add(const std::vector<std::pair<float, float>>& data);
64 Series& add(const std::vector<std::pair<float, Point2>>& data);
65 Series& add(const std::vector<std::pair<float, Point3>>& data);
66 Series& addValue(const std::vector<float>& values);
67 Series& addValue(const std::vector<Point2>& values);
68 Series& addValue(const std::vector<Point3>& values);
69 Series& add(float key, float value);
70 Series& add(float key, Point2 value);
71 Series& add(float key, Point3 value);
72 Series& addValue(float value);
73 Series& addValue(float value_a, float value_b);
74 Series& addValue(float value_a, float value_b, float value_c);
75 Series& set(const cv::Mat& data);
76 Series& set(const std::vector<std::pair<float, float>>& data);
77 Series& set(const std::vector<std::pair<float, Point2>>& data);
78 Series& set(const std::vector<std::pair<float, Point3>>& data);
79 Series& setValue(const std::vector<float>& values);
80 Series& setValue(const std::vector<Point2>& values);
81 Series& setValue(const std::vector<Point3>& values);
82 Series& set(float key, float value);
83 Series& set(float key, float value_a, float value_b);
84 Series& set(float key, float value_a, float value_b, float value_c);
85 Series& setValue(float value);
86 Series& setValue(float value_a, float value_b);
87 Series& setValue(float value_a, float value_b, float value_c);
88 Series& clear();
89
90 const std::string& label() const;
91 bool legend() const;
92 Color color() const;
93 void draw(void* buffer, float x_min, float x_max, float y_min, float y_max,
94 float x_axis, float xs, float xd, float ys, float yd, float y_axis,
95 int unit, float offset) const;
96 bool collides() const;
97 void dot(void* b, int x, int y, int r) const;
98 void bounds(float& x_min, float& x_max, float& y_min, float& y_max,
99 int& n_max, int& p_max) const;
100 void verifyParams() const;
101
102 protected:
103 void ensureDimsDepth(int dims, int depth);
104 bool flipAxis() const;
105
106 protected:
107 std::vector<int> entries_;
108 std::vector<float> data_;
109 enum Type type_;
110 Color color_;
111 std::string label_;
112 int dims_;
113 int depth_;
114 bool legend_;
115 bool dynamic_color_;
116 };
117
118 class NE_IMPEXP Figure
119 {
120 public:
121 Figure(View& view);
122
123 Figure& clear();
124 Figure& origin(bool x, bool y);
125 Figure& square(bool square);
126 Figure& border(int size);
127 Figure& alpha(int alpha);
128 Figure& gridSize(int size);
129 Figure& backgroundColor(Color color);
130 Figure& axisColor(Color color);
131 Figure& subaxisColor(Color color);
132 Figure& textColor(Color color);
133 Color backgroundColor();
134 Color axisColor();
135 Color subaxisColor();
136 Color textColor();
137
138 void draw(void* b, float x_min, float x_max, float y_min, float y_max,
139 int n_max, int p_max) const;
140 void show(bool flush = true) const;
141 Series& series(const std::string& label);
142
143 protected:
144 View& view_;
145 std::vector<Series> series_;
146 int border_size_;
147 Color background_color_;
148 Color axis_color_;
149 Color sub_axis_color_;
150 Color text_color_;
151 bool include_zero_x_;
152 bool include_zero_y_;
153 bool aspect_square_;
154 int grid_size_;
155 int grid_padding_;
156 };
157
158 namespace
159 {
160 std::map<std::string, Figure> shared_figures_;
161 }
162
163 Figure& figure(const std::string& name)
164 {
165 if (shared_figures_.count(name) == 0) {
166 auto& view = Window::current().view(name.c_str());
167 shared_figures_.insert(
168 std::map<std::string, Figure>::value_type(name, Figure(view)));
169 }
170 return shared_figures_.at(name);
171 }
172 }
173}