7#include <unordered_map>
28 static LightViewer*
instance(
const Eigen::Vector2i& size = Eigen::Vector2i(-1, -1),
bool background =
false,
const std::string& title =
"screen");
34 virtual void register_ui_callback(
const std::string& name,
const std::function<
void()>& callback = 0)
override;
37 void invoke(
const std::function<
void()>& func);
41 void invoke_once(
const std::string& label,
const std::function<
void()>& func);
50 void update_image(
const std::string& name,
const std::shared_ptr<glk::Texture>& image,
double scale = -1.0,
int order = -1);
60 void remove_plot(
const std::string& plot_name,
const std::string& label =
"");
61 void setup_plot(
const std::string& plot_name,
int width,
int height,
int plot_flags = 0,
int x_flags = 0,
int y_flags = 0,
int order = -1);
63 void link_plot_axes(
const std::string& plot_name,
int link_id,
int axes = -1);
64 void setup_legend(
const std::string& plot_name,
int loc,
int flags = 0);
68 void update_plot(
const std::string& plot_name,
const std::string& label,
const std::shared_ptr<const PlotData>& plot);
71 void update_plot_line(
const std::string& plot_name,
const std::string& label,
const std::vector<double>& ys,
int line_flags = 0,
size_t max_num_data = 8192 * 12);
73 const std::string& plot_name,
74 const std::string& label,
75 const std::vector<double>& xs,
76 const std::vector<double>& ys,
78 size_t max_num_data = 8192 * 12);
79 void update_plot_scatter(
const std::string& plot_name,
const std::string& label,
const std::vector<double>& ys,
int scatter_flags = 0);
80 void update_plot_scatter(
const std::string& plot_name,
const std::string& label,
const std::vector<double>& xs,
const std::vector<double>& ys,
int scatter_flags = 0);
81 void update_plot_stairs(
const std::string& plot_name,
const std::string& label,
const std::vector<double>& ys,
int stairs_flags = 0);
82 void update_plot_stairs(
const std::string& plot_name,
const std::string& label,
const std::vector<double>& xs,
const std::vector<double>& ys,
int stairs_flags = 0);
84 const std::string& plot_name,
85 const std::string& label,
86 const std::vector<double>& xs,
88 const Eigen::Vector2d& range = Eigen::Vector2d(0.0, 0.0),
89 int histogram_flags = 0);
91 const std::string& plot_name,
92 const std::string& label,
93 const std::vector<double>& xs,
94 const std::vector<double>& ys,
97 const Eigen::Vector2d& x_range = Eigen::Vector2d(0.0, 0.0),
98 const Eigen::Vector2d& y_range = Eigen::Vector2d(0.0, 0.0),
99 int histogram_flags = 0);
102 template <
typename T>
103 auto update_plot_line(
const std::string& plot_name,
const std::string& label,
const std::vector<T>& ys,
int line_flags = 0,
size_t max_num_data = 8192 * 12)
104 -> std::enable_if_t<std::is_arithmetic_v<T>,
void>;
105 template <
typename T1,
typename T2>
107 const std::string& plot_name,
108 const std::string& label,
109 const std::vector<T1>& xs,
110 const std::vector<T2>& ys,
112 size_t max_num_data = 8192 * 12);
113 template <
typename T,
int D,
typename Alloc>
115 const std::string& plot_name,
116 const std::string& label,
117 const std::vector<Eigen::Matrix<T, D, 1>, Alloc>& data,
119 size_t max_num_data = 8192 * 12);
120 template <
typename T,
typename Func>
122 update_plot_line(
const std::string& plot_name,
const std::string& label,
const std::vector<T>& data,
const Func& transform,
int line_flags = 0,
size_t max_num_data = 8192 * 12)
123 -> std::enable_if_t<!std::is_arithmetic_v<
decltype(transform(data[0]))>,
void> {
124 std::vector<double> xs(data.size());
125 std::vector<double> ys(data.size());
126 for (
size_t i = 0; i < data.size(); i++) {
127 const auto pt = transform(data[i]);
133 template <
typename T,
typename Func>
135 update_plot_line(
const std::string& plot_name,
const std::string& label,
const std::vector<T>& data,
const Func& transform,
int line_flags = 0,
size_t max_num_data = 8192 * 12)
136 -> std::enable_if_t<std::is_arithmetic_v<
decltype(transform(data[0]))>,
void> {
137 std::vector<double> xs(data.size());
138 std::vector<double> ys(data.size());
139 for (
size_t i = 0; i < data.size(); i++) {
140 const auto pt = transform(data[i]);
147 template <
typename T>
148 auto update_plot_scatter(
const std::string& plot_name,
const std::string& label,
const std::vector<T>& ys,
int scatter_flags = 0)
149 -> std::enable_if_t<std::is_arithmetic_v<T>,
void>;
150 template <
typename T1,
typename T2>
151 void update_plot_scatter(
const std::string& plot_name,
const std::string& label,
const std::vector<T1>& xs,
const std::vector<T2>& ys,
int scatter_flags = 0);
152 template <
typename T,
int D,
typename Alloc>
153 void update_plot_scatter(
const std::string& plot_name,
const std::string& label,
const std::vector<Eigen::Matrix<T, D, 1>, Alloc>& data,
int scatter_flags = 0);
154 template <
typename T,
typename Func>
156 const std::string& plot_name,
157 const std::string& label,
158 const std::vector<T>& data,
159 const Func& transform,
160 int scatter_flags = 0,
161 size_t max_num_data = 8192 * 12) -> std::enable_if_t<!std::is_arithmetic_v<
decltype(transform(data[0]))>,
void> {
162 std::vector<double> xs(data.size());
163 std::vector<double> ys(data.size());
164 for (
size_t i = 0; i < data.size(); i++) {
165 const auto pt = transform(data[i]);
171 template <
typename T,
typename Func>
173 const std::string& plot_name,
174 const std::string& label,
175 const std::vector<T>& data,
176 const Func& transform,
177 int scatter_flags = 0,
178 size_t max_num_data = 8192 * 12) -> std::enable_if_t<std::is_arithmetic_v<
decltype(transform(data[0]))>,
void> {
179 std::vector<double> xs(data.size());
180 std::vector<double> ys(data.size());
181 for (
size_t i = 0; i < data.size(); i++) {
182 const auto pt = transform(data[i]);
189 template <
typename T>
190 void update_plot_stairs(
const std::string& plot_name,
const std::string& label,
const std::vector<T>& ys,
int stairs_flags = 0);
191 template <
typename T1,
typename T2>
192 void update_plot_stairs(
const std::string& plot_name,
const std::string& label,
const std::vector<T1>& xs,
const std::vector<T2>& ys,
int stairs_flags = 0);
193 template <
typename T,
int D,
typename Alloc>
194 void update_plot_stairs(
const std::string& plot_name,
const std::string& label,
const std::vector<Eigen::Matrix<T, D, 1>, Alloc>& data,
int stairs_flags = 0);
195 template <
typename T,
typename Func>
196 void update_plot_stairs(
const std::string& plot_name,
const std::string& label,
const std::vector<T>& data,
const Func& transform,
int stairs_flags = 0);
198 template <
typename T>
200 const std::string& plot_name,
201 const std::string& label,
202 const std::vector<T>& xs,
204 const Eigen::Vector2d& range = Eigen::Vector2d(0.0, 0.0),
205 int histogram_flags = 0);
206 template <
typename T1,
typename T2>
208 const std::string& plot_name,
209 const std::string& label,
210 const std::vector<T1>& xs,
211 const std::vector<T2>& ys,
214 const Eigen::Vector2d& x_range = Eigen::Vector2d(0.0, 0.0),
215 const Eigen::Vector2d& y_range = Eigen::Vector2d(0.0, 0.0),
216 int histogram_flags = 0);
217 template <
typename T,
int D,
typename Alloc>
219 const std::string& plot_name,
220 const std::string& label,
221 const std::vector<Eigen::Matrix<T, D, 1>, Alloc>& data,
224 const Eigen::Vector2d& x_range = Eigen::Vector2d(0.0, 0.0),
225 const Eigen::Vector2d& y_range = Eigen::Vector2d(0.0, 0.0),
226 int histogram_flags = 0);
227 template <
typename T,
typename Func>
229 const std::string& plot_name,
230 const std::string& label,
231 const std::vector<T>& data,
232 const Func& transform,
235 const Eigen::Vector2d& x_range = Eigen::Vector2d(0.0, 0.0),
236 const Eigen::Vector2d& y_range = Eigen::Vector2d(0.0, 0.0),
237 int histogram_flags = 0);
241 void set_line_style(
const std::string& plot_name,
const std::string& label,
const Eigen::Vector4f& color = Eigen::Vector4f(0, 0, 0, -1),
float weight = -1);
243 const std::string& plot_name,
244 const std::string& label,
247 const Eigen::Vector4f& fill = Eigen::Vector4f(0, 0, 0, -1),
249 const Eigen::Vector4f& outline = Eigen::Vector4f(0, 0, 0, -1));
258 virtual bool init(
const Eigen::Vector2i& size,
const char* glsl_version,
bool background,
const std::string& title)
override;
259 virtual void framebuffer_size_callback(
const Eigen::Vector2i& size)
override;
261 virtual void draw_ui()
override;
262 virtual void draw_gl()
override;
265 static std::unique_ptr<LightViewer> inst;
267 std::unique_ptr<ViewerUI> viewer_ui;
268 std::unique_ptr<InfoWindow> info_window;
270 std::mutex texts_mutex;
272 std::deque<std::string> texts;
274 bool toggle_spin_stop_flag;
276 std::unordered_map<std::string, std::function<void()>> ui_callbacks;
278 std::unordered_map<std::string, std::tuple<double, std::shared_ptr<glk::Texture>,
int>> images;
279 std::vector<std::shared_ptr<glk::Texture>> images_in_rendering;
281 std::unordered_map<int, Eigen::Matrix<double, 6, 2>> plot_linked_axis_limits;
282 std::unordered_map<std::string, PlotSetting> plot_settings;
283 std::unordered_map<std::string, int> plot_group_orders;
284 std::unordered_map<std::string, std::vector<std::pair<PlotStyleConstPtr, PlotDataConstPtr>>> plot_data;
286 std::unordered_map<std::string, std::shared_ptr<LightViewerContext>> sub_contexts;
288 std::mutex invoke_requests_mutex;
289 std::deque<std::function<void()>> invoke_requests;
290 std::unordered_set<std::string> invoke_once_called;
292 std::mutex post_render_invoke_requests_mutex;
293 std::deque<std::function<void()>> post_render_invoke_requests;
296inline LightViewer*
viewer(
const Eigen::Vector2i& size = Eigen::Vector2i(-1, -1),
bool background =
false,
const std::string& title =
"screen") {
300inline LightViewer*
viewer(
const std::string& title,
const Eigen::Vector2i& size = Eigen::Vector2i(-1, -1),
bool background =
false) {
316 -> std::enable_if_t<std::is_arithmetic_v<T>,
void> {
317 std::vector<double> ys_(ys.size());
318 std::copy(ys.begin(), ys.end(), ys_.begin());
319 update_plot_line(plot_name, label, ys_, line_flags, max_num_data);
322template <
typename T1,
typename T2>
324 const std::string& plot_name,
325 const std::string& label,
326 const std::vector<T1>& xs,
327 const std::vector<T2>& ys,
329 size_t max_num_data) {
330 std::vector<double> xs_(xs.size());
331 std::vector<double> ys_(ys.size());
332 std::copy(xs.begin(), xs.end(), xs_.begin());
333 std::copy(ys.begin(), ys.end(), ys_.begin());
337template <
typename T,
int D,
typename Alloc>
339 const std::string& plot_name,
340 const std::string& label,
341 const std::vector<Eigen::Matrix<T, D, 1>, Alloc>& data,
343 size_t max_num_data) {
344 std::vector<double> xs(data.size());
345 std::vector<double> ys(data.size());
346 std::transform(data.begin(), data.end(), xs.begin(), [](
const Eigen::Matrix<T, D, 1>& v) { return v[0]; });
347 std::transform(data.begin(), data.end(), ys.begin(), [](
const Eigen::Matrix<T, D, 1>& v) { return v[1]; });
353 -> std::enable_if_t<std::is_arithmetic_v<T>,
void> {
354 std::vector<double> ys_(ys.size());
355 std::copy(ys.begin(), ys.end(), ys_.begin());
356 update_plot_scatter(plot_name, label, ys_, scatter_flags);
359template <
typename T1,
typename T2>
361 std::vector<double> xs_(xs.size());
362 std::vector<double> ys_(ys.size());
363 std::copy(xs.begin(), xs.end(), xs_.begin());
364 std::copy(ys.begin(), ys.end(), ys_.begin());
368template <
typename T,
int D,
typename Alloc>
370 std::vector<double> xs(data.size());
371 std::vector<double> ys(data.size());
372 std::transform(data.begin(), data.end(), xs.begin(), [](
const Eigen::Matrix<T, D, 1>& v) { return v[0]; });
373 std::transform(data.begin(), data.end(), ys.begin(), [](
const Eigen::Matrix<T, D, 1>& v) { return v[1]; });
379 std::vector<double> ys_(ys.size());
380 std::copy(ys.begin(), ys.end(), ys_.begin());
384template <
typename T1,
typename T2>
386 std::vector<double> xs_(xs.size());
387 std::vector<double> ys_(ys.size());
388 std::copy(xs.begin(), xs.end(), xs_.begin());
389 std::copy(ys.begin(), ys.end(), ys_.begin());
393template <
typename T,
int D,
typename Alloc>
394void LightViewer::update_plot_stairs(
const std::string& plot_name,
const std::string& label,
const std::vector<Eigen::Matrix<T, D, 1>, Alloc>& data,
int stairs_flags) {
395 std::vector<double> xs(data.size());
396 std::vector<double> ys(data.size());
397 std::transform(data.begin(), data.end(), xs.begin(), [](
const Eigen::Matrix<T, D, 1>& v) { return v[0]; });
398 std::transform(data.begin(), data.end(), ys.begin(), [](
const Eigen::Matrix<T, D, 1>& v) { return v[1]; });
402template <
typename T,
typename Func>
404 std::vector<double> xs(data.size());
405 std::vector<double> ys(data.size());
406 for (
size_t i = 0; i < data.size(); i++) {
407 const auto pt = transform(data[i], xs[i], ys[i]);
416 const std::string& plot_name,
417 const std::string& label,
418 const std::vector<T>& xs,
420 const Eigen::Vector2d& range,
421 int histogram_flags) {
422 std::vector<double> xs_(xs.size());
423 std::copy(xs.begin(), xs.end(), xs_.begin());
427template <
typename T1,
typename T2>
429 const std::string& plot_name,
430 const std::string& label,
431 const std::vector<T1>& xs,
432 const std::vector<T2>& ys,
435 const Eigen::Vector2d& x_range,
436 const Eigen::Vector2d& y_range,
437 int histogram_flags) {
438 std::vector<double> xs_(xs.size());
439 std::vector<double> ys_(ys.size());
440 std::copy(xs.begin(), xs.end(), xs_.begin());
441 std::copy(ys.begin(), ys.end(), ys_.begin());
442 update_plot_histogram(plot_name, label, xs_, ys_, x_bins, y_bins, x_range, y_range, histogram_flags);
445template <
typename T,
int D,
typename Alloc>
447 const std::string& plot_name,
448 const std::string& label,
449 const std::vector<Eigen::Matrix<T, D, 1>, Alloc>& data,
452 const Eigen::Vector2d& x_range,
453 const Eigen::Vector2d& y_range,
454 int histogram_flags) {
455 std::vector<double> xs(data.size());
456 std::vector<double> ys(data.size());
457 std::transform(data.begin(), data.end(), xs.begin(), [](
const Eigen::Matrix<T, D, 1>& v) { return v[0]; });
458 std::transform(data.begin(), data.end(), ys.begin(), [](
const Eigen::Matrix<T, D, 1>& v) { return v[1]; });
462template <
typename T,
typename Func>
464 const std::string& plot_name,
465 const std::string& label,
466 const std::vector<T>& data,
467 const Func& transform,
470 const Eigen::Vector2d& x_range,
471 const Eigen::Vector2d& y_range,
472 int histogram_flags) {
473 std::vector<double> xs(data.size());
474 std::vector<double> ys(data.size());
475 for (
size_t i = 0; i < data.size(); i++) {
476 const auto pt = transform(data[i], xs[i], ys[i]);
Definition imgui_application.hpp:12
Definition light_viewer_context.hpp:34
std::string context_name
Definition light_viewer_context.hpp:254
Eigen::Vector2i canvas_size() const
Definition light_viewer_context.hpp:129
Definition info_window.hpp:9
Definition viewer_ui.hpp:11
Definition light_viewer.hpp:23
virtual void clear_text() override
void invoke_after_rendering(const std::function< void()> &func)
auto update_plot_line(const std::string &plot_name, const std::string &label, const std::vector< T > &data, const Func &transform, int line_flags=0, size_t max_num_data=8192 *12) -> std::enable_if_t< std::is_arithmetic_v< decltype(transform(data[0]))>, void >
Definition light_viewer.hpp:135
void update_plot_scatter(const std::string &plot_name, const std::string &label, const std::vector< double > &xs, const std::vector< double > &ys, int scatter_flags=0)
void update_plot_histogram(const std::string &plot_name, const std::string &label, const std::vector< double > &xs, const std::vector< double > &ys, int x_bins=-2, int y_bins=-2, const Eigen::Vector2d &x_range=Eigen::Vector2d(0.0, 0.0), const Eigen::Vector2d &y_range=Eigen::Vector2d(0.0, 0.0), int histogram_flags=0)
void set_line_style(const std::string &plot_name, const std::string &label, const Eigen::Vector4f &color=Eigen::Vector4f(0, 0, 0, -1), float weight=-1)
bool remove_sub_viewer(const std::string &context_name)
void set_scatter_style(const std::string &plot_name, const std::string &label, int marker=0, float size=-1, const Eigen::Vector4f &fill=Eigen::Vector4f(0, 0, 0, -1), float weight=-1, const Eigen::Vector4f &outline=Eigen::Vector4f(0, 0, 0, -1))
std::shared_ptr< LightViewerContext > find_sub_viewer(const std::string &context_name)
void update_plot_line(const std::string &plot_name, const std::string &label, const std::vector< double > &xs, const std::vector< double > &ys, int line_flags=0, size_t max_num_data=8192 *12)
void update_plot_stairs(const std::string &plot_name, const std::string &label, const std::vector< double > &ys, int stairs_flags=0)
void setup_legend(const std::string &plot_name, int loc, int flags=0)
virtual void append_text(const std::string &text) override
void link_plot_axes(const std::string &plot_name, int link_id, int axes=-1)
void invoke_once(const std::string &label, const std::function< void()> &func)
void update_image(const std::string &name, const std::shared_ptr< glk::Texture > &image, double scale=-1.0, int order=-1)
std::shared_ptr< LightViewerContext > sub_viewer(const std::string &context_name, const Eigen::Vector2i &canvas_size=Eigen::Vector2i(-1, -1))
void invoke(const std::function< void()> &func)
void update_plot_line(const std::string &plot_name, const std::string &label, const std::vector< double > &ys, int line_flags=0, size_t max_num_data=8192 *12)
auto update_plot_scatter(const std::string &plot_name, const std::string &label, const std::vector< T > &data, const Func &transform, int scatter_flags=0, size_t max_num_data=8192 *12) -> std::enable_if_t< std::is_arithmetic_v< decltype(transform(data[0]))>, void >
Definition light_viewer.hpp:172
void fit_plot(const std::string &plot_name)
static LightViewer * instance(const Eigen::Vector2i &size=Eigen::Vector2i(-1, -1), bool background=false, const std::string &title="screen")
void setup_plot(const std::string &plot_name, int width, int height, int plot_flags=0, int x_flags=0, int y_flags=0, int order=-1)
void set_max_text_buffer_size(int size)
auto update_plot_line(const std::string &plot_name, const std::string &label, const std::vector< T > &data, const Func &transform, int line_flags=0, size_t max_num_data=8192 *12) -> std::enable_if_t<!std::is_arithmetic_v< decltype(transform(data[0]))>, void >
Definition light_viewer.hpp:122
void clear_plots(bool clear_settings=true)
void update_plot_scatter(const std::string &plot_name, const std::string &label, const std::vector< double > &ys, int scatter_flags=0)
void update_plot_histogram(const std::string &plot_name, const std::string &label, const std::vector< double > &xs, int bins=-2, const Eigen::Vector2d &range=Eigen::Vector2d(0.0, 0.0), int histogram_flags=0)
void remove_plot(const std::string &plot_name, const std::string &label="")
void remove_image(const std::string &name)
auto update_plot_scatter(const std::string &plot_name, const std::string &label, const std::vector< T > &data, const Func &transform, int scatter_flags=0, size_t max_num_data=8192 *12) -> std::enable_if_t<!std::is_arithmetic_v< decltype(transform(data[0]))>, void >
Definition light_viewer.hpp:155
void set_plot_style(const std::string &plot_name, const std::string &label, const PlotStyleConstPtr &style)
void update_plot_stairs(const std::string &plot_name, const std::string &label, const std::vector< double > &xs, const std::vector< double > &ys, int stairs_flags=0)
virtual void register_ui_callback(const std::string &name, const std::function< void()> &callback=0) override
void update_plot(const std::string &plot_name, const std::string &label, const std::shared_ptr< const PlotData > &plot)
virtual void clear() override
void setup_plot_group_order(const std::string &group_name, int order)
void link_plot_axis(const std::string &plot_name, int link_id, int axis)
Definition drawable_container.hpp:9
void destroy()
Definition light_viewer.hpp:304
LightViewer * viewer(const Eigen::Vector2i &size=Eigen::Vector2i(-1, -1), bool background=false, const std::string &title="screen")
Definition light_viewer.hpp:296
std::shared_ptr< const PlotData > PlotDataConstPtr
Definition light_viewer.hpp:20
std::shared_ptr< const PlotStyle > PlotStyleConstPtr
Definition light_viewer.hpp:21
bool running()
Definition light_viewer.hpp:308