iridescence
Loading...
Searching...
No Matches
light_viewer.hpp
Go to the documentation of this file.
1#ifndef GUIK_VIEWER_HPP
2#define GUIK_VIEWER_HPP
3
4#include <mutex>
5#include <deque>
6#include <memory>
7#include <unordered_map>
8
9#include <glk/drawable.hpp>
10#include <guik/gl_canvas.hpp>
15
16namespace guik {
17
18struct PlotData;
19struct PlotStyle;
20using PlotDataConstPtr = std::shared_ptr<const PlotData>;
21using PlotStyleConstPtr = std::shared_ptr<const PlotStyle>;
22
25public:
28 virtual ~LightViewer();
29
30public:
36 static LightViewer* instance(const Eigen::Vector2i& size = Eigen::Vector2i(-1, -1), bool background = false, const std::string& title = "screen");
38 static void destroy();
40 static bool running();
41
46
50 virtual void register_ui_callback(const std::string& name, const std::function<void()>& callback = 0) override;
51
53 void invoke(const std::function<void()>& func);
55 void invoke_after_rendering(const std::function<void()>& func);
57 void invoke_once(const std::string& label, const std::function<void()>& func);
58
60 virtual void clear() override;
62 virtual void clear_text() override;
64 virtual void append_text(const std::string& text) override;
68
72 void remove_image(const std::string& name);
78 void update_image(const std::string& name, const std::shared_ptr<glk::Texture>& image, double scale = -1.0, int order = -1);
79
84 std::shared_ptr<LightViewerContext> sub_viewer(const std::string& context_name, const Eigen::Vector2i& canvas_size = Eigen::Vector2i(-1, -1));
85
87 void show_sub_viewers(); // Set all sub viewer windows to be opened
89 std::shared_ptr<LightViewerContext> find_sub_viewer(const std::string& context_name); // Returns nullptr if sub viewer does not exist
91 bool remove_sub_viewer(const std::string& context_name); // Returns false if sub viwewer does not exist
92
93 // Plotting methods
96 void clear_plots(bool clear_settings = true);
100 void remove_plot(const std::string& plot_name, const std::string& label = "");
109 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);
114 void link_plot_axis(const std::string& plot_name, int link_id, int axis); // axis = ImAxis_X1 or ImAxis_X2, ...
119 void link_plot_axes(const std::string& plot_name, int link_id, int axes = -1); // axes = (1 << ImAxis_X1) | (1 << ImAxis_X2) ...
124 void setup_legend(const std::string& plot_name, int loc, int flags = 0);
127 void fit_plot(const std::string& plot_name);
133 void setup_plot_group_order(const std::string& group_name, int order);
138 void update_plot(const std::string& plot_name, const std::string& label, const std::shared_ptr<const PlotData>& plot);
139
140 // Plotting update methods
147 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);
156 const std::string& plot_name,
157 const std::string& label,
158 const std::vector<double>& xs,
159 const std::vector<double>& ys,
160 int line_flags = 0,
161 size_t max_num_data = 8192 * 12);
162
168 void update_plot_scatter(const std::string& plot_name, const std::string& label, const std::vector<double>& ys, int scatter_flags = 0);
175 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);
176
182 void update_plot_stairs(const std::string& plot_name, const std::string& label, const std::vector<double>& ys, int stairs_flags = 0);
189 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);
190
199 const std::string& plot_name,
200 const std::string& label,
201 const std::vector<double>& xs,
202 int bins = -2,
203 const Eigen::Vector2d& range = Eigen::Vector2d(0.0, 0.0),
204 int histogram_flags = 0);
207 const std::string& plot_name,
208 const std::string& label,
209 const std::vector<double>& xs,
210 const std::vector<double>& ys,
211 int x_bins = -2,
212 int y_bins = -2,
213 const Eigen::Vector2d& x_range = Eigen::Vector2d(0.0, 0.0),
214 const Eigen::Vector2d& y_range = Eigen::Vector2d(0.0, 0.0),
215 int histogram_flags = 0);
216
217 // Plotting update template methods
219 template <typename T>
220 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)
221 -> std::enable_if_t<std::is_arithmetic_v<T>, void>;
223 template <typename T1, typename T2>
224 void update_plot_line(
225 const std::string& plot_name,
226 const std::string& label,
227 const std::vector<T1>& xs,
228 const std::vector<T2>& ys,
229 int line_flags = 0,
230 size_t max_num_data = 8192 * 12);
232 template <typename T, int D, typename Alloc>
233 void update_plot_line(
234 const std::string& plot_name,
235 const std::string& label,
236 const std::vector<Eigen::Matrix<T, D, 1>, Alloc>& data,
237 int line_flags = 0,
238 size_t max_num_data = 8192 * 12);
240 template <typename T, typename Func>
241 auto
242 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)
243 -> std::enable_if_t<!std::is_arithmetic_v<decltype(transform(data[0]))>, void> {
244 std::vector<double> xs(data.size());
245 std::vector<double> ys(data.size());
246 for (size_t i = 0; i < data.size(); i++) {
247 const auto pt = transform(data[i]);
248 xs[i] = pt[0];
249 ys[i] = pt[1];
250 }
251 update_plot_line(plot_name, label, xs, ys, line_flags, max_num_data);
252 }
253
254 template <typename T, typename Func>
255 auto
256 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)
257 -> std::enable_if_t<std::is_arithmetic_v<decltype(transform(data[0]))>, void> {
258 std::vector<double> xs(data.size());
259 std::vector<double> ys(data.size());
260 for (size_t i = 0; i < data.size(); i++) {
261 const auto pt = transform(data[i]);
262 xs[i] = i;
263 ys[i] = pt;
264 }
265 update_plot_line(plot_name, label, xs, ys, line_flags, max_num_data);
266 }
267
269 template <typename T>
270 auto update_plot_scatter(const std::string& plot_name, const std::string& label, const std::vector<T>& ys, int scatter_flags = 0)
271 -> std::enable_if_t<std::is_arithmetic_v<T>, void>;
273 template <typename T1, typename T2>
274 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);
276 template <typename T, int D, typename Alloc>
277 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);
279 template <typename T, typename Func>
281 const std::string& plot_name,
282 const std::string& label,
283 const std::vector<T>& data,
284 const Func& transform,
285 int scatter_flags = 0,
286 size_t max_num_data = 8192 * 12) -> std::enable_if_t<!std::is_arithmetic_v<decltype(transform(data[0]))>, void> {
287 std::vector<double> xs(data.size());
288 std::vector<double> ys(data.size());
289 for (size_t i = 0; i < data.size(); i++) {
290 const auto pt = transform(data[i]);
291 xs[i] = pt[0];
292 ys[i] = pt[1];
293 }
294 update_plot_scatter(plot_name, label, xs, ys, scatter_flags);
295 }
296
297 template <typename T, typename Func>
299 const std::string& plot_name,
300 const std::string& label,
301 const std::vector<T>& data,
302 const Func& transform,
303 int scatter_flags = 0,
304 size_t max_num_data = 8192 * 12) -> std::enable_if_t<std::is_arithmetic_v<decltype(transform(data[0]))>, void> {
305 std::vector<double> xs(data.size());
306 std::vector<double> ys(data.size());
307 for (size_t i = 0; i < data.size(); i++) {
308 const auto pt = transform(data[i]);
309 xs[i] = i;
310 ys[i] = pt;
311 }
312 update_plot_scatter(plot_name, label, xs, ys, scatter_flags);
313 }
314
316 template <typename T>
317 void update_plot_stairs(const std::string& plot_name, const std::string& label, const std::vector<T>& ys, int stairs_flags = 0);
319 template <typename T1, typename T2>
320 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);
322 template <typename T, int D, typename Alloc>
323 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);
325 template <typename T, typename Func>
326 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);
327
329 template <typename T>
331 const std::string& plot_name,
332 const std::string& label,
333 const std::vector<T>& xs,
334 int bins = -2,
335 const Eigen::Vector2d& range = Eigen::Vector2d(0.0, 0.0),
336 int histogram_flags = 0);
338 template <typename T1, typename T2>
340 const std::string& plot_name,
341 const std::string& label,
342 const std::vector<T1>& xs,
343 const std::vector<T2>& ys,
344 int x_bins = -2,
345 int y_bins = -2,
346 const Eigen::Vector2d& x_range = Eigen::Vector2d(0.0, 0.0),
347 const Eigen::Vector2d& y_range = Eigen::Vector2d(0.0, 0.0),
348 int histogram_flags = 0);
350 template <typename T, int D, typename Alloc>
352 const std::string& plot_name,
353 const std::string& label,
354 const std::vector<Eigen::Matrix<T, D, 1>, Alloc>& data,
355 int x_bins = -2,
356 int y_bins = -2,
357 const Eigen::Vector2d& x_range = Eigen::Vector2d(0.0, 0.0),
358 const Eigen::Vector2d& y_range = Eigen::Vector2d(0.0, 0.0),
359 int histogram_flags = 0);
361 template <typename T, typename Func>
363 const std::string& plot_name,
364 const std::string& label,
365 const std::vector<T>& data,
366 const Func& transform,
367 int x_bins = -2,
368 int y_bins = -2,
369 const Eigen::Vector2d& x_range = Eigen::Vector2d(0.0, 0.0),
370 const Eigen::Vector2d& y_range = Eigen::Vector2d(0.0, 0.0),
371 int histogram_flags = 0);
372
373 // Plotting style methods
378 void set_plot_style(const std::string& plot_name, const std::string& label, const PlotStyleConstPtr& style);
384 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);
394 const std::string& plot_name,
395 const std::string& label,
396 int marker = 0,
397 float size = -1,
398 const Eigen::Vector4f& fill = Eigen::Vector4f(0, 0, 0, -1),
399 float weight = -1,
400 const Eigen::Vector4f& outline = Eigen::Vector4f(0, 0, 0, -1));
401
406
407private:
408 class ViewerUI;
409 class InfoWindow;
410
411 virtual bool init(const Eigen::Vector2i& size, const char* glsl_version, bool background, const std::string& title) override;
412 virtual void framebuffer_size_callback(const Eigen::Vector2i& size) override;
413
414 virtual void draw_ui() override;
415 virtual void draw_gl() override;
416
417private:
418 static std::unique_ptr<LightViewer> inst;
419
420 std::unique_ptr<ViewerUI> viewer_ui;
421 std::unique_ptr<InfoWindow> info_window;
422
423 std::mutex texts_mutex;
424 int max_texts_size;
425 std::deque<std::string> texts;
426
427 bool toggle_spin_stop_flag;
428
429 std::vector<std::pair<std::string, std::function<void()>>> ui_callbacks;
430
431 std::unordered_map<std::string, std::tuple<double, std::shared_ptr<glk::Texture>, int>> images;
432 std::vector<std::shared_ptr<glk::Texture>> images_in_rendering;
433
434 std::unordered_map<int, Eigen::Matrix<double, 6, 2>> plot_linked_axis_limits;
435 std::unordered_map<std::string, PlotSetting> plot_settings;
436 std::unordered_map<std::string, int> plot_group_orders;
437 std::unordered_map<std::string, std::vector<std::pair<PlotStyleConstPtr, PlotDataConstPtr>>> plot_data;
438
439 std::unordered_map<std::string, std::shared_ptr<LightViewerContext>> sub_contexts;
440
441 std::mutex invoke_requests_mutex;
442 std::deque<std::function<void()>> invoke_requests;
443 std::unordered_set<std::string> invoke_once_called;
444
445 std::mutex post_render_invoke_requests_mutex;
446 std::deque<std::function<void()>> post_render_invoke_requests;
447};
448
454inline LightViewer* viewer(const Eigen::Vector2i& size = Eigen::Vector2i(-1, -1), bool background = false, const std::string& title = "screen") {
455 return LightViewer::instance(size, background, title);
456}
457
463inline LightViewer* viewer(const std::string& title, const Eigen::Vector2i& size = Eigen::Vector2i(-1, -1), bool background = false) {
464 return LightViewer::instance(size, background, title);
465}
466
468inline void destroy() {
470}
471
473inline bool running() {
474 return LightViewer::running();
475}
476
477// Template methods
478
479template <typename T>
480auto LightViewer::update_plot_line(const std::string& plot_name, const std::string& label, const std::vector<T>& ys, int line_flags, size_t max_num_data)
481 -> std::enable_if_t<std::is_arithmetic_v<T>, void> {
482 std::vector<double> ys_(ys.size());
483 std::copy(ys.begin(), ys.end(), ys_.begin());
484 update_plot_line(plot_name, label, ys_, line_flags, max_num_data);
485}
486
487template <typename T1, typename T2>
489 const std::string& plot_name,
490 const std::string& label,
491 const std::vector<T1>& xs,
492 const std::vector<T2>& ys,
493 int line_flags,
494 size_t max_num_data) {
495 std::vector<double> xs_(xs.size());
496 std::vector<double> ys_(ys.size());
497 std::copy(xs.begin(), xs.end(), xs_.begin());
498 std::copy(ys.begin(), ys.end(), ys_.begin());
499 update_plot_line(plot_name, label, xs_, ys_, line_flags, max_num_data);
500}
501
502template <typename T, int D, typename Alloc>
504 const std::string& plot_name,
505 const std::string& label,
506 const std::vector<Eigen::Matrix<T, D, 1>, Alloc>& data,
507 int line_flags,
508 size_t max_num_data) {
509 std::vector<double> xs(data.size());
510 std::vector<double> ys(data.size());
511 std::transform(data.begin(), data.end(), xs.begin(), [](const Eigen::Matrix<T, D, 1>& v) { return v[0]; });
512 std::transform(data.begin(), data.end(), ys.begin(), [](const Eigen::Matrix<T, D, 1>& v) { return v[1]; });
513 update_plot_line(plot_name, label, xs, ys, line_flags, max_num_data);
514}
515
516template <typename T>
517auto LightViewer::update_plot_scatter(const std::string& plot_name, const std::string& label, const std::vector<T>& ys, int scatter_flags)
518 -> std::enable_if_t<std::is_arithmetic_v<T>, void> {
519 std::vector<double> ys_(ys.size());
520 std::copy(ys.begin(), ys.end(), ys_.begin());
521 update_plot_scatter(plot_name, label, ys_, scatter_flags);
522}
523
524template <typename T1, typename T2>
525void LightViewer::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) {
526 std::vector<double> xs_(xs.size());
527 std::vector<double> ys_(ys.size());
528 std::copy(xs.begin(), xs.end(), xs_.begin());
529 std::copy(ys.begin(), ys.end(), ys_.begin());
530 update_plot_scatter(plot_name, label, xs_, ys_, scatter_flags);
531}
532
533template <typename T, int D, typename Alloc>
534void LightViewer::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) {
535 std::vector<double> xs(data.size());
536 std::vector<double> ys(data.size());
537 std::transform(data.begin(), data.end(), xs.begin(), [](const Eigen::Matrix<T, D, 1>& v) { return v[0]; });
538 std::transform(data.begin(), data.end(), ys.begin(), [](const Eigen::Matrix<T, D, 1>& v) { return v[1]; });
539 update_plot_scatter(plot_name, label, xs, ys, scatter_flags);
540}
541
542template <typename T>
543void LightViewer::update_plot_stairs(const std::string& plot_name, const std::string& label, const std::vector<T>& ys, int stairs_flags) {
544 std::vector<double> ys_(ys.size());
545 std::copy(ys.begin(), ys.end(), ys_.begin());
546 update_plot_stairs(plot_name, label, ys_, stairs_flags);
547}
548
549template <typename T1, typename T2>
550void LightViewer::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) {
551 std::vector<double> xs_(xs.size());
552 std::vector<double> ys_(ys.size());
553 std::copy(xs.begin(), xs.end(), xs_.begin());
554 std::copy(ys.begin(), ys.end(), ys_.begin());
555 update_plot_stairs(plot_name, label, xs_, ys_, stairs_flags);
556}
557
558template <typename T, int D, typename Alloc>
559void 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) {
560 std::vector<double> xs(data.size());
561 std::vector<double> ys(data.size());
562 std::transform(data.begin(), data.end(), xs.begin(), [](const Eigen::Matrix<T, D, 1>& v) { return v[0]; });
563 std::transform(data.begin(), data.end(), ys.begin(), [](const Eigen::Matrix<T, D, 1>& v) { return v[1]; });
564 update_plot_stairs(plot_name, label, xs, ys, stairs_flags);
565}
566
567template <typename T, typename Func>
568void LightViewer::update_plot_stairs(const std::string& plot_name, const std::string& label, const std::vector<T>& data, const Func& transform, int stairs_flags) {
569 std::vector<double> xs(data.size());
570 std::vector<double> ys(data.size());
571 for (size_t i = 0; i < data.size(); i++) {
572 const auto pt = transform(data[i], xs[i], ys[i]);
573 xs[i] = pt[0];
574 ys[i] = pt[1];
575 }
576 update_plot_stairs(plot_name, label, xs, ys, stairs_flags);
577}
578
579template <typename T>
581 const std::string& plot_name,
582 const std::string& label,
583 const std::vector<T>& xs,
584 int bins,
585 const Eigen::Vector2d& range,
586 int histogram_flags) {
587 std::vector<double> xs_(xs.size());
588 std::copy(xs.begin(), xs.end(), xs_.begin());
589 update_plot_histogram(plot_name, label, xs_, bins, range, histogram_flags);
590}
591
592template <typename T1, typename T2>
594 const std::string& plot_name,
595 const std::string& label,
596 const std::vector<T1>& xs,
597 const std::vector<T2>& ys,
598 int x_bins,
599 int y_bins,
600 const Eigen::Vector2d& x_range,
601 const Eigen::Vector2d& y_range,
602 int histogram_flags) {
603 std::vector<double> xs_(xs.size());
604 std::vector<double> ys_(ys.size());
605 std::copy(xs.begin(), xs.end(), xs_.begin());
606 std::copy(ys.begin(), ys.end(), ys_.begin());
607 update_plot_histogram(plot_name, label, xs_, ys_, x_bins, y_bins, x_range, y_range, histogram_flags);
608}
609
610template <typename T, int D, typename Alloc>
612 const std::string& plot_name,
613 const std::string& label,
614 const std::vector<Eigen::Matrix<T, D, 1>, Alloc>& data,
615 int x_bins,
616 int y_bins,
617 const Eigen::Vector2d& x_range,
618 const Eigen::Vector2d& y_range,
619 int histogram_flags) {
620 std::vector<double> xs(data.size());
621 std::vector<double> ys(data.size());
622 std::transform(data.begin(), data.end(), xs.begin(), [](const Eigen::Matrix<T, D, 1>& v) { return v[0]; });
623 std::transform(data.begin(), data.end(), ys.begin(), [](const Eigen::Matrix<T, D, 1>& v) { return v[1]; });
624 update_plot_histogram(plot_name, label, xs, ys, x_bins, y_bins, x_range, y_range, histogram_flags);
625}
626
627template <typename T, typename Func>
629 const std::string& plot_name,
630 const std::string& label,
631 const std::vector<T>& data,
632 const Func& transform,
633 int x_bins,
634 int y_bins,
635 const Eigen::Vector2d& x_range,
636 const Eigen::Vector2d& y_range,
637 int histogram_flags) {
638 std::vector<double> xs(data.size());
639 std::vector<double> ys(data.size());
640 for (size_t i = 0; i < data.size(); i++) {
641 const auto pt = transform(data[i], xs[i], ys[i]);
642 xs[i] = pt[0];
643 ys[i] = pt[1];
644 }
645 update_plot_histogram(plot_name, label, xs, ys, x_bins, y_bins, x_range, y_range, histogram_flags);
646}
647
648} // namespace guik
649
650#endif
Definition imgui_application.hpp:12
virtual void draw_ui()
virtual void draw_gl()
Viewer context.
Definition light_viewer_context.hpp:37
std::string context_name
Viewer context name.
Definition light_viewer_context.hpp:520
Eigen::Vector2i canvas_size() const
Get canvas size.
Definition light_viewer_context.hpp:242
Definition info_window.hpp:9
Definition viewer_ui.hpp:11
Light viewer. The main visualization class in Iridescence.
Definition light_viewer.hpp:24
virtual void clear_text() override
Clear the text buffer.
void invoke_after_rendering(const std::function< void()> &func)
Invoke a task after rendering in the visualization thread.
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 >
Update a line plot.
Definition light_viewer.hpp:256
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)
Update a scatter plot.
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)
Update a 2D histogram plot.
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)
Set the line style for a plot.
LightViewer()
Constructor. Do not call directly. Use LightViewer::instance() instead.
bool remove_sub_viewer(const std::string &context_name)
Remove a sub viewer context by 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))
Set the scatter style for a plot.
std::shared_ptr< LightViewerContext > find_sub_viewer(const std::string &context_name)
Find a sub viewer context by 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)
Update a line plot.
void update_plot_stairs(const std::string &plot_name, const std::string &label, const std::vector< double > &ys, int stairs_flags=0)
Update a stairs plot.
void setup_legend(const std::string &plot_name, int loc, int flags=0)
Setup the legend for a plot.
virtual void append_text(const std::string &text) override
Append text to the text buffer. This method is thread-safe.
void link_plot_axes(const std::string &plot_name, int link_id, int axes=-1)
Link multiple axes of a plot to a link ID.
void fit_all_plots()
Fit all plots to their data ranges.
void invoke_once(const std::string &label, const std::function< void()> &func)
Invoke a labeled task only once in the life time of the viewer.
void update_image(const std::string &name, const std::shared_ptr< glk::Texture > &image, double scale=-1.0, int order=-1)
Register or update an image.
bool toggle_spin_once()
Spin the viewer until a toggle flag is set to true.
std::shared_ptr< LightViewerContext > sub_viewer(const std::string &context_name, const Eigen::Vector2i &canvas_size=Eigen::Vector2i(-1, -1))
Create or get a sub viewer context.
static void destroy()
Destroy the singleton instance of LightViewer.
static bool running()
Check if the LightViewer instance is running.
void invoke(const std::function< void()> &func)
Invoke a task in the visualization thread.
void show_info_window()
Show the info window.
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)
Update a line plot.
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 >
Update a scatter plot.
Definition light_viewer.hpp:298
void fit_plot(const std::string &plot_name)
Fit the plot view to the data range.
void show_sub_viewers()
Show all sub viewer windows.
static LightViewer * instance(const Eigen::Vector2i &size=Eigen::Vector2i(-1, -1), bool background=false, const std::string &title="screen")
Get the singleton instance of LightViewer. The viewer insatnce is created upon the first call.
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)
Setup a plot.
void set_max_text_buffer_size(int size)
Set the maximum text buffer 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 >
Update a line plot.
Definition light_viewer.hpp:242
void clear_plots(bool clear_settings=true)
Clear all plots.
void update_plot_scatter(const std::string &plot_name, const std::string &label, const std::vector< double > &ys, int scatter_flags=0)
Update a scatter plot.
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)
Update a histogram plot.
void remove_plot(const std::string &plot_name, const std::string &label="")
Remove a plot by name.
void remove_image(const std::string &name)
Remove an image by 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 >
Update a scatter plot.
Definition light_viewer.hpp:280
void set_plot_style(const std::string &plot_name, const std::string &label, const PlotStyleConstPtr &style)
Set the style for a plot.
void clear_images()
Clear all images.
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)
Update a stairs plot.
void show_viewer_ui()
Show the viewer UI.
virtual void register_ui_callback(const std::string &name, const std::function< void()> &callback=0) override
Register a UI callback function.
void update_plot(const std::string &plot_name, const std::string &label, const std::shared_ptr< const PlotData > &plot)
Update a plot with new data.
bool spin_until_click()
Spin the viewer until a mouse click event is received.
virtual ~LightViewer()
virtual void clear() override
Clear everything in the viewer (text, drawables, filters).
void setup_plot_group_order(const std::string &group_name, int order)
Setup the plot group order.
void link_plot_axis(const std::string &plot_name, int link_id, int axis)
Link an axis of a plot to a link ID.
Definition drawable_container.hpp:9
std::shared_ptr< const PlotStyle > PlotStyleConstPtr
Definition light_viewer.hpp:21
std::shared_ptr< const PlotData > PlotDataConstPtr
Definition light_viewer.hpp:20
void destroy()
Destroy the singleton LightViewer instance.
Definition light_viewer.hpp:468
LightViewer * viewer(const Eigen::Vector2i &size=Eigen::Vector2i(-1, -1), bool background=false, const std::string &title="screen")
Create or get the singleton LightViewer instance.
Definition light_viewer.hpp:454
bool running()
Check if the LightViewer instance is running.
Definition light_viewer.hpp:473
Definition plot_data.hpp:11
Definition plot_data.hpp:91