forked from alandefreitas/matplotplusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.h
More file actions
156 lines (119 loc) 路 4.93 KB
/
Copy pathmatrix.h
File metadata and controls
156 lines (119 loc) 路 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// Created by Alan Freitas on 16/07/20.
//
#ifndef MATPLOTPLUSPLUS_MATRIX_H
#define MATPLOTPLUSPLUS_MATRIX_H
#include <matplot/core/figure_type.h>
#include <matplot/core/axes_object.h>
#include <matplot/core/axis_type.h>
#include <matplot/core/line_spec.h>
#include <matplot/util/common.h>
#include <matplot/util/concepts.h>
#include <matplot/util/handle_types.h>
namespace matplot {
class axes_type;
class matrix : public axes_object {
public:
enum class color_normalization { none, rows, columns };
public:
explicit matrix(class axes_type *parent);
/// Heatmap
/// Matrix of values that can be any double
matrix(class axes_type *parent,
const std::vector<std::vector<double>> &matrix);
/// Matrix with an rgb image
matrix(class axes_type *parent,
const std::vector<std::vector<double>> &red_channel,
const std::vector<std::vector<double>> &green_channel,
const std::vector<std::vector<double>> &blue_channel,
const std::vector<std::vector<double>> &alpha_channel = {});
/// Matrix with a b&w image
matrix(class axes_type *parent, const image_channel_t &gray_image);
/// Matrix with an rgb image
matrix(class axes_type *parent, const image_channel_t &red_channel,
const image_channel_t &green_channel,
const image_channel_t &blue_channel,
const image_channel_t &alpha_channel = {});
/// Matrices with an image
matrix(class axes_type *parent, const image_channels_t &rgb_image);
/// If we receive an axes_handle, we can convert it to a raw
/// pointer because there is no ownership involved here
template <class... Args>
matrix(const axes_handle &parent, Args &&... args)
: matrix(parent.get(), std::forward<Args>(args)...) {}
virtual ~matrix() = default;
public /* mandatory virtual functions */:
// std::string set_variables_string() override;
std::string plot_string() override;
// std::string legend_string(const std::string& title) override;
std::string data_string() override;
// std::string unset_variables_string() override;
double xmax() override;
double xmin() override;
double ymax() override;
double ymin() override;
enum axes_object::axes_category axes_category() override;
public /* getters and setters */:
color_normalization normalization() const;
class matrix &normalization(color_normalization normalization);
const std::vector<std::vector<double>> &matrix_r() const;
class matrix &
matrix_r(const std::vector<std::vector<double>> &matrix_r);
const std::vector<std::vector<double>> &matrix_g() const;
class matrix &
matrix_g(const std::vector<std::vector<double>> &matrix_g);
const std::vector<std::vector<double>> &matrix_b() const;
class matrix &
matrix_b(const std::vector<std::vector<double>> &matrix_b);
const std::vector<std::vector<double>> &matrix_a() const;
class matrix &
matrix_a(const std::vector<std::vector<double>> &matrix_a);
bool always_hide_labels() const;
class matrix &always_hide_labels(bool always_hide_labels);
double x() const;
class matrix &x(double x);
double y() const;
class matrix &y(double y);
double w() const;
class matrix &w(double w);
double h() const;
class matrix &h(double h);
double alpha() const;
class matrix &alpha(double alpha);
public /* functions for matrixes */:
/// Matrix has three channels
bool is_rgb() const;
/// Matrix has 4 channels
bool is_rgba() const;
/// A matrix might have alpha because of an
/// alpha channels or because alpha_ != 0.
/// In both cases we have a rgba matrix
bool has_alpha() const;
private:
bool should_plot_labels();
void setup_axes();
std::string matrix_data_string();
std::string image_data_string();
std::string labels_data_string();
inline double x_width() {
return (w_ - 1) / static_cast<double>(matrices_[0][0].size() - 1);
}
inline double y_width() { return (h_ - 1) / static_cast<double>(matrices_[0].size() - 1); }
protected:
// Main matrix
std::vector<std::vector<std::vector<double>>> matrices_{};
// For heatmaps or 1 matrix
color_normalization normalization_{color_normalization::none};
// Matrix placement
double x_{1};
double y_{1};
double w_{0.};
double h_{0.};
// Style
bool always_hide_labels_{false};
labels_handle labels_;
double alpha_ = 0.0;
bool visible_{true};
};
} // namespace matplot
#endif // MATPLOTPLUSPLUS_MATRIX_H