iridescence
Loading...
Searching...
No Matches
light_viewer_context.hpp
Go to the documentation of this file.
1#ifndef GUIK_LIGHT_VIEWER_CONTEXT_HPP
2#define GUIK_LIGHT_VIEWER_CONTEXT_HPP
3
4#include <mutex>
5#include <deque>
6#include <regex>
7#include <memory>
8#include <optional>
9#include <unordered_map>
10
11#include <glk/drawable.hpp>
12#include <glk/colormap.hpp>
14#include <guik/gl_canvas.hpp>
19
20namespace glk {
21class ThinLines;
23} // namespace glk
24
25namespace guik {
26
35
38public:
39 LightViewerContext(const std::string& context_name);
41
42 void draw_ui();
43 void draw_gl();
44
45 bool init_canvas(const Eigen::Vector2i& size);
46
47 void set_size(const Eigen::Vector2i& size);
48 void set_clear_color(const Eigen::Vector4f& color);
49
50 void set_pos(const Eigen::Vector2i& pos, ImGuiCond cond = ImGuiCond_FirstUseEver, ImGuiWindowFlags = 0);
51 void show();
52 void hide();
53
55 virtual void clear();
57 virtual void clear_text();
58
60 virtual void append_text(const std::string& text);
61
65 virtual void register_ui_callback(const std::string& name, const std::function<void()>& callback = 0);
68 void remove_ui_callback(const std::string& name);
69
74
81
84
86 void set_screen_effect(const std::shared_ptr<glk::ScreenEffect>& effect);
88 const std::shared_ptr<glk::ScreenEffect>& get_screen_effect() const;
90 void set_bg_texture(const std::shared_ptr<glk::Texture>& bg_texture);
91
93 void set_rainbow_range(const Eigen::Vector2f& minmax_z);
95 void set_rainbow_axis(const Eigen::Vector3f& axis);
96
98 void set_colormap_range(const Eigen::Vector2f& minmax);
99
104 void set_point_shape(float point_size = 1.0f, bool metric = true, bool circle = true);
105
110
115 void enable_partial_rendering(double clear_thresh = 1e-6);
124 void set_backface_culling_range(const Eigen::Vector2f& range);
125
134
142 const glk::Texture& info_buffer() const;
145
150 void clear_drawables(const std::function<bool(const std::string&)>& fn);
151
154 std::unordered_map<std::string, std::pair<ShaderSetting::Ptr, glk::Drawable::ConstPtr>>& get_drawables();
155
159 std::pair<ShaderSetting::Ptr, glk::Drawable::ConstPtr> find_drawable(const std::string& name);
160
162 void remove_drawable(const std::string& name);
164 void remove_drawable(const std::regex& regex);
165
170 void update_drawable(const std::string& name, const glk::Drawable::ConstPtr& drawable, const ShaderSetting& shader_setting = ShaderSetting());
171
177 void register_drawable_filter(const std::string& filter_name, const std::function<bool(const std::string&)>& filter = 0);
179 void remove_drawable_filter(const std::string& filter_name);
180
183
185 const std::shared_ptr<CameraControl>& get_camera_control() const;
187 const std::shared_ptr<ProjectionControl>& get_projection_control() const;
189 void set_camera_control(const std::shared_ptr<CameraControl>& camera_control);
191 void set_projection_control(const std::shared_ptr<ProjectionControl>& projection_control);
192
194 bool save_camera_settings(const std::string& path) const;
196 bool load_camera_settings(const std::string& path);
197
201 void lookat(const Eigen::Vector3f& pt);
203 void lookat(const Eigen::Isometry3f& T_world_sensor);
205 void lookat(const Eigen::Isometry3d& T_world_sensor);
206
208 template <typename Vector>
209 void lookat(const Vector& pt) {
210 const auto ptf = pt.eval().template cast<float>();
211 lookat(ptf);
212 }
213
215 std::shared_ptr<OrbitCameraControlXY> use_orbit_camera_control(double distance = 80.0, double theta = 0.0, double phi = -60.0f * M_PI / 180.0f);
217 std::shared_ptr<OrbitCameraControlXZ> use_orbit_camera_control_xz(double distance = 80.0, double theta = 0.0, double phi = 0.0);
219 std::shared_ptr<TopDownCameraControl> use_topdown_camera_control(double distance = 80.0, double theta = 0.0);
221 std::shared_ptr<ArcBallCameraControl> use_arcball_camera_control(double distance = 80.0, double theta = 0.0, double phi = -60.0f * M_PI / 180.0f);
223 std::shared_ptr<FPSCameraControl> use_fps_camera_control(double fovy_deg = 60.0);
225 std::shared_ptr<SensorViewCameraControl> use_sensor_view_camera_control(
226 const Eigen::Isometry3f& T_sensor_camera = Eigen::Translation3f(-5.0f, 0.0f, 0.1f) * Eigen::Isometry3f::Identity(),
227 double smoothing_factor_trans = 0.75,
228 double smoothing_factor_rot = 0.9);
229
231 std::shared_ptr<BasicProjectionControl> use_perspective_projection_control(float fovy_deg = 30.0f, float near_ = 1.0f, float far_ = 1000.0f);
233 std::shared_ptr<BasicProjectionControl> use_orthographic_projection_control(float width = 10.0f, float near_ = 1.0f, float far_ = 1000.0f);
234
237 // @brief Get top left corner of the canvas rectangle.
238 Eigen::Vector2i canvas_tl() const { return canvas_rect_min; }
240 Eigen::Vector2i canvas_br() const { return canvas_rect_max; }
242 Eigen::Vector2i canvas_size() const { return canvas->size; }
244 Eigen::Matrix4f view_matrix() const { return canvas->camera_control->view_matrix(); }
246 Eigen::Matrix4f projection_matrix() const { return canvas->projection_control->projection_matrix(); }
247
252 Eigen::Vector4i pick_info(const Eigen::Vector2i& p, int window = 2) const;
253
258 float pick_depth(const Eigen::Vector2i& p, int window = 2) const;
259
264 Eigen::Vector3f unproject(const Eigen::Vector2i& p, float depth) const;
265
271 std::optional<Eigen::Vector3f> pick_point(int button = 0, int window = 2, Eigen::Vector4i* info = nullptr) const;
272
273 // Buffer read methods
276 std::vector<unsigned char> read_color_buffer() const;
277
281 std::vector<float> read_depth_buffer(bool real_scale = true);
282
284 bool save_color_buffer(const std::string& filename);
286 bool save_depth_buffer(const std::string& filename, bool real_scale = true);
287
288 // Async
291
292 // Utility methods to directly create and update drawables
293 // PointCloudBuffer
294
302 std::shared_ptr<glk::PointCloudBuffer> update_points(const std::string& name, const float* data, int stride, int num_points, const ShaderSetting& shader_setting);
304 template <typename Scalar, int Dim>
305 std::shared_ptr<glk::PointCloudBuffer> update_points(const std::string& name, const Eigen::Matrix<Scalar, Dim, 1>* points, int num_points, const ShaderSetting& shader_setting);
307 template <typename Scalar, int Dim, typename Allocator>
308 std::shared_ptr<glk::PointCloudBuffer>
309 update_points(const std::string& name, const std::vector<Eigen::Matrix<Scalar, Dim, 1>, Allocator>& points, const ShaderSetting& shader_setting);
310
311 // NormalDistributions
319 template <typename Scalar, int Dim>
321 const std::string& name,
322 const Eigen::Matrix<Scalar, Dim, 1>* points,
323 const Eigen::Matrix<Scalar, Dim, Dim>* covs,
324 int num_points,
325 float sigma,
327
329 template <typename Scalar, int Dim, typename Alloc1, typename Alloc2>
331 const std::string& name,
332 const std::vector<Eigen::Matrix<Scalar, Dim, 1>, Alloc1>& points,
333 const std::vector<Eigen::Matrix<Scalar, Dim, Dim>, Alloc2>& covs,
334 float sigma,
336
337 // ThinLines
348 std::shared_ptr<glk::ThinLines> update_thin_lines(
349 const std::string& name,
350 const float* vertices,
351 const float* colors,
352 int num_vertices,
353 const unsigned int* indices,
354 int num_indices,
355 bool line_strip,
356 float line_width,
358
360 std::shared_ptr<glk::ThinLines> update_thin_lines(
361 const std::string& name,
362 const float* vertices,
363 const float* colors,
364 int num_vertices,
365 const unsigned int* indices,
366 int num_indices,
367 bool line_strip,
369
371 template <typename Scalar, int Dim>
372 std::shared_ptr<glk::ThinLines>
373 update_thin_lines(const std::string& name, const Eigen::Matrix<Scalar, Dim, 1>* points, int num_points, bool line_strip, const ShaderSetting& shader_setting);
374
376 template <typename ScalarV, int DimV, typename ScalarC, int DimC>
377 std::shared_ptr<glk::ThinLines> update_thin_lines(
378 const std::string& name,
379 const Eigen::Matrix<ScalarV, DimV, 1>* points,
380 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
381 int num_points,
382 bool line_strip,
384
386 template <typename ScalarV, int DimV, typename ScalarC, int DimC>
387 std::shared_ptr<glk::ThinLines> update_thin_lines(
388 const std::string& name,
389 const Eigen::Matrix<ScalarV, DimV, 1>* points,
390 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
391 int num_points,
392 const unsigned int* indices,
393 int num_indices,
394 bool line_strip,
396
398 template <typename Point, typename Alloc>
399 std::shared_ptr<glk::ThinLines> update_thin_lines(const std::string& name, const std::vector<Point, Alloc>& points, bool line_strip, const ShaderSetting& shader_setting);
400
402 template <typename Point, typename Alloc>
403 std::shared_ptr<glk::ThinLines> update_thin_lines(
404 const std::string& name,
405 const std::vector<Point, Alloc>& points,
406 const std::vector<unsigned int>& indices,
407 bool line_strip,
409
411 template <typename Point, typename AllocP, typename Color, typename AllocC>
412 std::shared_ptr<glk::ThinLines> update_thin_lines(
413 const std::string& name,
414 const std::vector<Point, AllocP>& points,
415 const std::vector<Color, AllocC>& colors,
416 bool line_strip,
418
420 template <typename Point, typename AllocP, typename Color, typename AllocC>
421 std::shared_ptr<glk::ThinLines> update_thin_lines(
422 const std::string& name,
423 const std::vector<Point, AllocP>& points,
424 const std::vector<Color, AllocC>& colors,
425 const std::vector<unsigned int>& indices,
426 bool line_strip,
428
430 template <typename Scalar, int Dim>
431 std::shared_ptr<glk::ThinLines>
432 update_thin_lines(const std::string& name, const Eigen::Matrix<Scalar, Dim, 1>* points, int num_points, bool line_strip, float line_width, const ShaderSetting& shader_setting);
433
435 template <typename ScalarV, int DimV, typename ScalarC, int DimC>
436 std::shared_ptr<glk::ThinLines> update_thin_lines(
437 const std::string& name,
438 const Eigen::Matrix<ScalarV, DimV, 1>* points,
439 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
440 int num_points,
441 bool line_strip,
442 float line_width,
444
446 template <typename ScalarV, int DimV, typename ScalarC, int DimC>
447 std::shared_ptr<glk::ThinLines> update_thin_lines(
448 const std::string& name,
449 const Eigen::Matrix<ScalarV, DimV, 1>* points,
450 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
451 int num_points,
452 const unsigned int* indices,
453 int num_indices,
454 bool line_strip,
455 float line_width,
457
459 template <typename Point, typename Alloc>
460 std::shared_ptr<glk::ThinLines>
461 update_thin_lines(const std::string& name, const std::vector<Point, Alloc>& points, bool line_strip, float line_width, const ShaderSetting& shader_setting);
462
464 template <typename Point, typename Alloc>
465 std::shared_ptr<glk::ThinLines> update_thin_lines(
466 const std::string& name,
467 const std::vector<Point, Alloc>& points,
468 const std::vector<unsigned int>& indices,
469 bool line_strip,
470 float line_width,
472
474 template <typename Point, typename AllocP, typename Color, typename AllocC>
475 std::shared_ptr<glk::ThinLines> update_thin_lines(
476 const std::string& name,
477 const std::vector<Point, AllocP>& points,
478 const std::vector<Color, AllocC>& colors,
479 bool line_strip,
480 float line_width,
482
484 template <typename Point, typename AllocP, typename Color, typename AllocC>
485 std::shared_ptr<glk::ThinLines> update_thin_lines(
486 const std::string& name,
487 const std::vector<Point, AllocP>& points,
488 const std::vector<Color, AllocC>& colors,
489 const std::vector<unsigned int>& indices,
490 bool line_strip,
491 float line_width,
493
494 // Primitives
496 void update_icosahedron(const std::string& name, const ShaderSetting& shader_setting);
498 void update_sphere(const std::string& name, const ShaderSetting& shader_setting);
500 void update_cube(const std::string& name, const ShaderSetting& shader_setting);
502 void update_cone(const std::string& name, const ShaderSetting& shader_setting);
504 void update_frustum(const std::string& name, const ShaderSetting& shader_setting);
506 void update_coord(const std::string& name, const ShaderSetting& shader_setting);
507
509 void update_wire_icosahedron(const std::string& name, const ShaderSetting& shader_setting);
511 void update_wire_sphere(const std::string& name, const ShaderSetting& shader_setting);
513 void update_wire_cube(const std::string& name, const ShaderSetting& shader_setting);
515 void update_wire_cone(const std::string& name, const ShaderSetting& shader_setting);
517 void update_wire_frustum(const std::string& name, const ShaderSetting& shader_setting);
518
519protected:
520 std::string context_name;
521 Eigen::Vector2i canvas_rect_min;
522 Eigen::Vector2i canvas_rect_max;
523 std::unique_ptr<guik::GLCanvas> canvas;
525
529
531
532 std::unordered_map<std::string, std::function<bool(const std::string&)>> drawable_filters;
533 std::unordered_map<std::string, std::pair<ShaderSetting::Ptr, glk::Drawable::ConstPtr>> drawables;
534
535 std::mutex sub_texts_mutex;
536 std::deque<std::string> sub_texts;
537 std::vector<std::pair<std::string, std::function<void()>>> sub_ui_callbacks;
538};
539
540// template methods
541// PointCloud
542template <typename Scalar, int Dim>
543std::shared_ptr<glk::PointCloudBuffer>
544LightViewerContext::update_points(const std::string& name, const Eigen::Matrix<Scalar, Dim, 1>* points, int num_points, const ShaderSetting& shader_setting) {
545 if constexpr (std::is_same<Scalar, float>::value) {
546 return update_points(name, reinterpret_cast<const float*>(points), sizeof(float) * Dim, num_points, shader_setting);
547 } else {
548 const auto points_3f = glk::convert_to_vector<float, 3, 1>(points, num_points);
549 return update_points(name, points_3f.data(), num_points, shader_setting);
550 }
551}
552
553template <typename Scalar, int Dim, typename Allocator>
554std::shared_ptr<glk::PointCloudBuffer>
555LightViewerContext::update_points(const std::string& name, const std::vector<Eigen::Matrix<Scalar, Dim, 1>, Allocator>& points, const ShaderSetting& shader_setting) {
556 return update_points(name, points.data(), points.size(), shader_setting);
557}
558
559// NormalDistributions
560template <typename Scalar, int Dim, typename Alloc1, typename Alloc2>
562 const std::string& name,
563 const std::vector<Eigen::Matrix<Scalar, Dim, 1>, Alloc1>& points,
564 const std::vector<Eigen::Matrix<Scalar, Dim, Dim>, Alloc2>& covs,
565 float sigma,
567 update_normal_dists(name, points.data(), covs.data(), points.size(), sigma, shader_setting);
568}
569
570// ThinLines
571template <typename Scalar, int Dim>
572std::shared_ptr<glk::ThinLines>
573LightViewerContext::update_thin_lines(const std::string& name, const Eigen::Matrix<Scalar, Dim, 1>* points, int num_points, bool line_strip, const ShaderSetting& shader_setting) {
574 if constexpr (std::is_same<Scalar, float>::value && Dim == 3) {
575 return update_thin_lines(name, reinterpret_cast<const float*>(points), nullptr, num_points, nullptr, 0, line_strip, shader_setting);
576 } else {
577 const auto points_3f = glk::convert_to_vector<float, 3, 1>(points, num_points);
578 return update_thin_lines(name, points_3f.data(), num_points, line_strip, shader_setting);
579 }
580}
581
582template <typename ScalarV, int DimV, typename ScalarC, int DimC>
583std::shared_ptr<glk::ThinLines> LightViewerContext::update_thin_lines(
584 const std::string& name,
585 const Eigen::Matrix<ScalarV, DimV, 1>* points,
586 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
587 int num_points,
588 bool line_strip,
590 if constexpr (std::is_same<ScalarV, float>::value && DimV == 3 && std::is_same<ScalarC, float>::value && DimC == 4) {
591 return update_thin_lines(name, reinterpret_cast<const float*>(points), reinterpret_cast<const float*>(colors), num_points, nullptr, 0, line_strip, shader_setting);
592 } else {
593 const auto points_3f = glk::convert_to_vector<float, 3, 1>(points, num_points);
594 const auto colors_4f = glk::convert_to_vector<float, 4, 1>(colors, num_points);
595 return update_thin_lines(name, points_3f.data(), colors_4f.data(), num_points, line_strip, shader_setting);
596 }
597}
598
599template <typename ScalarV, int DimV, typename ScalarC, int DimC>
600std::shared_ptr<glk::ThinLines> LightViewerContext::update_thin_lines(
601 const std::string& name,
602 const Eigen::Matrix<ScalarV, DimV, 1>* points,
603 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
604 int num_points,
605 const unsigned int* indices,
606 int num_indices,
607 bool line_strip,
609 if constexpr (std::is_same<ScalarV, float>::value && DimV == 3 && std::is_same<ScalarC, float>::value && DimC == 4) {
610 return update_thin_lines(name, reinterpret_cast<const float*>(points), reinterpret_cast<const float*>(colors), num_points, indices, num_indices, line_strip, shader_setting);
611 } else {
612 const auto points_3f = glk::convert_to_vector<float, 3, 1>(points, num_points);
613 const auto colors_4f = glk::convert_to_vector<float, 4, 1>(colors, num_points);
614 return update_thin_lines(name, points_3f.data(), colors_4f.data(), num_points, indices, num_indices, line_strip, shader_setting);
615 }
616}
617
618template <typename Point, typename Alloc>
619std::shared_ptr<glk::ThinLines>
620LightViewerContext::update_thin_lines(const std::string& name, const std::vector<Point, Alloc>& points, bool line_strip, const ShaderSetting& shader_setting) {
621 return update_thin_lines(name, points.data(), points.size(), line_strip, shader_setting);
622}
623
624template <typename Point, typename Alloc>
625std::shared_ptr<glk::ThinLines> LightViewerContext::update_thin_lines(
626 const std::string& name,
627 const std::vector<Point, Alloc>& points,
628 const std::vector<unsigned int>& indices,
629 bool line_strip,
631 return update_thin_lines(name, points.data(), static_cast<const Eigen::Vector4f*>(nullptr), points.size(), indices.data(), indices.size(), line_strip, shader_setting);
632}
633
634template <typename Point, typename AllocP, typename Color, typename AllocC>
635std::shared_ptr<glk::ThinLines> LightViewerContext::update_thin_lines(
636 const std::string& name,
637 const std::vector<Point, AllocP>& points,
638 const std::vector<Color, AllocC>& colors,
639 bool line_strip,
641 return update_thin_lines(name, points.data(), colors.data(), points.size(), line_strip, shader_setting);
642}
643
644template <typename Point, typename AllocP, typename Color, typename AllocC>
645std::shared_ptr<glk::ThinLines> LightViewerContext::update_thin_lines(
646 const std::string& name,
647 const std::vector<Point, AllocP>& points,
648 const std::vector<Color, AllocC>& colors,
649 const std::vector<unsigned int>& indices,
650 bool line_strip,
652 return update_thin_lines(name, points.data(), colors.data(), points.size(), indices.data(), indices.size(), line_strip, shader_setting);
653}
654
655// ThinLines (with line_width)
656template <typename Scalar, int Dim>
657std::shared_ptr<glk::ThinLines> LightViewerContext::update_thin_lines(
658 const std::string& name,
659 const Eigen::Matrix<Scalar, Dim, 1>* points,
660 int num_points,
661 bool line_strip,
662 float line_width,
664 if constexpr (std::is_same<Scalar, float>::value && Dim == 3) {
665 return update_thin_lines(name, reinterpret_cast<const float*>(points), nullptr, num_points, nullptr, 0, line_strip, line_width, shader_setting);
666 } else {
667 const auto points_3f = glk::convert_to_vector<float, 3, 1>(points, num_points);
668 return update_thin_lines(name, points_3f.data(), num_points, line_strip, line_width, shader_setting);
669 }
670}
671
672template <typename ScalarV, int DimV, typename ScalarC, int DimC>
673std::shared_ptr<glk::ThinLines> LightViewerContext::update_thin_lines(
674 const std::string& name,
675 const Eigen::Matrix<ScalarV, DimV, 1>* points,
676 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
677 int num_points,
678 bool line_strip,
679 float line_width,
681 if constexpr (std::is_same<ScalarV, float>::value && DimV == 3 && std::is_same<ScalarC, float>::value && DimC == 4) {
682 return update_thin_lines(name, reinterpret_cast<const float*>(points), reinterpret_cast<const float*>(colors), num_points, nullptr, 0, line_strip, line_width, shader_setting);
683 } else {
684 const auto points_3f = glk::convert_to_vector<float, 3, 1>(points, num_points);
685 const auto colors_4f = glk::convert_to_vector<float, 4, 1>(colors, num_points);
686 return update_thin_lines(name, points_3f.data(), colors_4f.data(), num_points, line_strip, line_width, shader_setting);
687 }
688}
689
690template <typename ScalarV, int DimV, typename ScalarC, int DimC>
691std::shared_ptr<glk::ThinLines> LightViewerContext::update_thin_lines(
692 const std::string& name,
693 const Eigen::Matrix<ScalarV, DimV, 1>* points,
694 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
695 int num_points,
696 const unsigned int* indices,
697 int num_indices,
698 bool line_strip,
699 float line_width,
701 if constexpr (std::is_same<ScalarV, float>::value && DimV == 3 && std::is_same<ScalarC, float>::value && DimC == 4) {
702 return update_thin_lines(
703 name,
704 reinterpret_cast<const float*>(points),
705 reinterpret_cast<const float*>(colors),
706 num_points,
707 indices,
708 num_indices,
709 line_strip,
710 line_width,
712 } else {
713 const auto points_3f = glk::convert_to_vector<float, 3, 1>(points, num_points);
714 const auto colors_4f = glk::convert_to_vector<float, 4, 1>(colors, num_points);
715 return update_thin_lines(name, points_3f.data(), colors_4f.data(), num_points, indices, num_indices, line_strip, line_width, shader_setting);
716 }
717}
718
719template <typename Point, typename Alloc>
720std::shared_ptr<glk::ThinLines>
721LightViewerContext::update_thin_lines(const std::string& name, const std::vector<Point, Alloc>& points, bool line_strip, float line_width, const ShaderSetting& shader_setting) {
722 return update_thin_lines(name, points.data(), points.size(), line_strip, line_width, shader_setting);
723}
724
725template <typename Point, typename Alloc>
726std::shared_ptr<glk::ThinLines> LightViewerContext::update_thin_lines(
727 const std::string& name,
728 const std::vector<Point, Alloc>& points,
729 const std::vector<unsigned int>& indices,
730 bool line_strip,
731 float line_width,
733 return update_thin_lines(
734 name,
735 points.data(),
736 static_cast<const Eigen::Vector4f*>(nullptr),
737 points.size(),
738 indices.data(),
739 indices.size(),
740 line_strip,
741 line_width,
743}
744
745template <typename Point, typename AllocP, typename Color, typename AllocC>
746std::shared_ptr<glk::ThinLines> LightViewerContext::update_thin_lines(
747 const std::string& name,
748 const std::vector<Point, AllocP>& points,
749 const std::vector<Color, AllocC>& colors,
750 bool line_strip,
751 float line_width,
753 return update_thin_lines(name, points.data(), colors.data(), points.size(), line_strip, line_width, shader_setting);
754}
755
756template <typename Point, typename AllocP, typename Color, typename AllocC>
757std::shared_ptr<glk::ThinLines> LightViewerContext::update_thin_lines(
758 const std::string& name,
759 const std::vector<Point, AllocP>& points,
760 const std::vector<Color, AllocC>& colors,
761 const std::vector<unsigned int>& indices,
762 bool line_strip,
763 float line_width,
765 return update_thin_lines(name, points.data(), colors.data(), points.size(), indices.data(), indices.size(), line_strip, line_width, shader_setting);
766}
767
768} // namespace guik
769
770#endif
std::shared_ptr< const Drawable > ConstPtr
Definition drawable.hpp:15
Definition pointcloud_buffer.hpp:22
Texture class to wrap OpenGL texture object.
Definition texture.hpp:11
A class to draw a set of GL_LINES.
Definition thin_lines.hpp:19
Definition arcball_camera_control.hpp:8
Async interface to manipulate LightViewerContext. All OpenGL operations will be called in the viewer ...
Definition async_light_viewer_context.hpp:13
Definition basic_projection_control.hpp:8
Definition fps_camera_control.hpp:9
Definition gl_canvas.hpp:17
void set_screen_effect(const std::shared_ptr< glk::ScreenEffect > &effect)
Set screen effect.
std::shared_ptr< TopDownCameraControl > use_topdown_camera_control(double distance=80.0, double theta=0.0)
Use top-down camera control useful for 2D SLAM.
void update_frustum(const std::string &name, const ShaderSetting &shader_setting)
Register or update a frustum primitive.
std::mutex sub_texts_mutex
Definition light_viewer_context.hpp:535
bool normal_buffer_enabled() const
Whether normal buffer is enabled.
void remove_drawable(const std::string &name)
Remove a drawable by name.
std::vector< unsigned char > read_color_buffer() const
Read color buffer values.
std::optional< Eigen::Vector3f > pick_point(int button=0, int window=2, Eigen::Vector4i *info=nullptr) const
Pick a 3D point from the depth buffer.
Eigen::Vector2i canvas_rect_min
Top-left corner of the canvas rectangle.
Definition light_viewer_context.hpp:521
void clear_drawables(const std::function< bool(const std::string &)> &fn)
Clear drawables that satisfy the given condition.
void lookat(const Eigen::Vector3f &pt)
Make the camera look at a point.
Eigen::Matrix4f last_projection_view_matrix
Definition light_viewer_context.hpp:530
const guik::ShaderSetting & shader_setting() const
Global shader setting.
Definition light_viewer_context.hpp:73
Eigen::Matrix4f projection_matrix() const
Get projection matrix.
Definition light_viewer_context.hpp:246
void set_pos(const Eigen::Vector2i &pos, ImGuiCond cond=ImGuiCond_FirstUseEver, ImGuiWindowFlags=0)
Eigen::Vector2i canvas_br() const
Get bottom right corner of the canvas rectangle.
Definition light_viewer_context.hpp:240
AsyncLightViewerContext async()
Get an asynchronous light viewer context.
void clear_drawable_filters()
Clear all drawable filters.
std::shared_ptr< OrbitCameraControlXZ > use_orbit_camera_control_xz(double distance=80.0, double theta=0.0, double phi=0.0)
Use orbit camera control (XZ plane) useful for systems in which XYZ = right-down-forward like visual ...
void update_icosahedron(const std::string &name, const ShaderSetting &shader_setting)
Register or update an icosahedron primitive.
Eigen::Vector3f unproject(const Eigen::Vector2i &p, float depth) const
Unproject a pixel to a 3D point.
virtual void append_text(const std::string &text)
Append debug text to the viewer. This method is thread-safe.
std::shared_ptr< glk::ThinLines > update_thin_lines(const std::string &name, const float *vertices, const float *colors, int num_vertices, const unsigned int *indices, int num_indices, bool line_strip, const ShaderSetting &shader_setting)
Register or update a thin lines drawable.
void disable_backface_culling()
Disable backface culling.
guik::GLCanvas & get_canvas()
Get underlying GLCanvas.
std::shared_ptr< FPSCameraControl > use_fps_camera_control(double fovy_deg=60.0)
Use FPS game-like camera control.
std::vector< std::pair< std::string, std::function< void()> > > sub_ui_callbacks
Definition light_viewer_context.hpp:537
std::string context_name
Viewer context name.
Definition light_viewer_context.hpp:520
std::shared_ptr< BasicProjectionControl > use_orthographic_projection_control(float width=10.0f, float near_=1.0f, float far_=1000.0f)
Use orthographic projection control.
std::unordered_map< std::string, std::pair< ShaderSetting::Ptr, glk::Drawable::ConstPtr > > drawables
Definition light_viewer_context.hpp:533
void remove_drawable(const std::regex &regex)
Remove all drawables that match the given regex.
Eigen::Vector4i pick_info(const Eigen::Vector2i &p, int window=2) const
Pick info from the info buffer.
const std::shared_ptr< glk::ScreenEffect > & get_screen_effect() const
Get screen effect.
const glk::Texture & info_buffer() const
Info buffer.
void update_coord(const std::string &name, const ShaderSetting &shader_setting)
Register or update a coordinate axes primitive.
bool show_window
Definition light_viewer_context.hpp:526
std::shared_ptr< ArcBallCameraControl > use_arcball_camera_control(double distance=80.0, double theta=0.0, double phi=-60.0f *M_PI/180.0f)
Use arcball camera control.
void update_cone(const std::string &name, const ShaderSetting &shader_setting)
Register or update a cone primitive.
void set_size(const Eigen::Vector2i &size)
std::shared_ptr< glk::PointCloudBuffer > update_points(const std::string &name, const float *data, int stride, int num_points, const ShaderSetting &shader_setting)
Register or update a point cloud buffer.
void set_colormap(glk::COLORMAP colormap)
Set colormap used for RAINBOW and VERTEX_COLORMAP modes.
void update_sphere(const std::string &name, const ShaderSetting &shader_setting)
Register or update a sphere primitive.
void set_point_shape(float point_size=1.0f, bool metric=true, bool circle=true)
Set point shape properties.
std::deque< std::string > sub_texts
Definition light_viewer_context.hpp:536
bool save_depth_buffer(const std::string &filename, bool real_scale=true)
Save depth buffer to a file (PNG).
void update_wire_cube(const std::string &name, const ShaderSetting &shader_setting)
Register or update a wireframe cube primitive.
std::vector< float > read_depth_buffer(bool real_scale=true)
Read depth buffer values.
Eigen::Matrix4f view_matrix() const
Get view matrix.
Definition light_viewer_context.hpp:244
bool save_camera_settings(const std::string &path) const
Save camera settings to a file.
void set_colormap_range(const Eigen::Vector2f &minmax)
Set range of color mapping for VERTEX_COLORMAP mode.
void reset_center()
Reset camera center to the center of the screen.
virtual void clear()
Clear everything in the viewer (callbacks, filters, drawables, texts).
Eigen::Vector2i canvas_tl() const
Definition light_viewer_context.hpp:238
void enable_backface_culling()
Enable backface culling. Fragments with back-facing normals will not be rendered.
virtual void clear_text()
Clear texts.
void clear_drawables()
Clear all drawables.
std::shared_ptr< OrbitCameraControlXY > use_orbit_camera_control(double distance=80.0, double theta=0.0, double phi=-60.0f *M_PI/180.0f)
Use orbit camera control (XY plane) useful for systems in which XYZ = front-left-up like LiDAR odomet...
guik::ShaderSetting global_shader_setting
Global shader setting.
Definition light_viewer_context.hpp:524
void enable_normal_buffer()
Enable normal buffer.
void set_bg_texture(const std::shared_ptr< glk::Texture > &bg_texture)
Set background texture.
void update_wire_cone(const std::string &name, const ShaderSetting &shader_setting)
Register or update a wireframe cone primitive.
bool partial_rendering_enabled() const
Whether partial rendering is enabled.
bool backface_culling_enabled() const
Whether backface culling is enabled.
void update_cube(const std::string &name, const ShaderSetting &shader_setting)
Register or update a cube primitive.
void enable_xy_grid()
Enable XY grid drawing.
Definition light_viewer_context.hpp:78
guik::ShaderSetting & shader_setting()
Global shader setting.
Definition light_viewer_context.hpp:71
std::shared_ptr< BasicProjectionControl > use_perspective_projection_control(float fovy_deg=30.0f, float near_=1.0f, float far_=1000.0f)
Use perspective projection control.
std::pair< ShaderSetting::Ptr, glk::Drawable::ConstPtr > find_drawable(const std::string &name)
Find a drawable by name.
void set_clear_color(const Eigen::Vector4f &color)
const glk::Texture & normal_buffer() const
Normal buffer.
void enable_partial_rendering(double clear_thresh=1e-6)
Enable partial rendering.
void set_camera_control(const std::shared_ptr< CameraControl > &camera_control)
Set camera control (model matrix control).
std::unordered_map< std::string, std::pair< ShaderSetting::Ptr, glk::Drawable::ConstPtr > > & get_drawables()
Get all drawables.
std::unordered_map< std::string, std::function< bool(const std::string &)> > drawable_filters
Definition light_viewer_context.hpp:532
void update_drawable(const std::string &name, const glk::Drawable::ConstPtr &drawable, const ShaderSetting &shader_setting=ShaderSetting())
Update a drawable.
void set_backface_culling_range(const Eigen::Vector2f &range)
Set the range of normal.z for backface culling. Fragments with normal.z outside the range will be cul...
std::shared_ptr< glk::ThinLines > update_thin_lines(const std::string &name, const float *vertices, const float *colors, int num_vertices, const unsigned int *indices, int num_indices, bool line_strip, float line_width, const ShaderSetting &shader_setting)
Register or update a thin lines drawable.
void update_normal_dists(const std::string &name, const Eigen::Matrix< Scalar, Dim, 1 > *points, const Eigen::Matrix< Scalar, Dim, Dim > *covs, int num_points, float sigma, const ShaderSetting &shader_setting)
Register or update a normal distribution set.
bool decimal_rendering
Definition light_viewer_context.hpp:528
Eigen::Vector2i canvas_rect_max
Bottom-right corner of the canvas rectangle.
Definition light_viewer_context.hpp:522
void lookat(const Eigen::Isometry3d &T_world_sensor)
Make the camera look at a transform.
bool load_camera_settings(const std::string &path)
Load camera settings from a file.
void clear_partial_rendering()
Clear partial rendering buffer.
float pick_depth(const Eigen::Vector2i &p, int window=2) const
Pick depth from the depth buffer.
void set_draw_xy_grid(bool draw_xy_grid)
Set enable/disable XY grid drawing.
void update_wire_icosahedron(const std::string &name, const ShaderSetting &shader_setting)
Register or update a wireframe icosahedron primitive.
bool save_color_buffer(const std::string &filename)
Save color buffer to an image file (PNG).
void disable_xy_grid()
Disable XY grid drawing.
Definition light_viewer_context.hpp:76
bool draw_xy_grid
Definition light_viewer_context.hpp:527
const std::shared_ptr< ProjectionControl > & get_projection_control() const
Get projection control (projection matrix control).
void disable_partial_rendering()
Disable partial rendering.
LightViewerContext(const std::string &context_name)
bool init_canvas(const Eigen::Vector2i &size)
void remove_drawable_filter(const std::string &filter_name)
Remove a drawable filter.
std::unique_ptr< guik::GLCanvas > canvas
GL canvas.
Definition light_viewer_context.hpp:523
void update_wire_frustum(const std::string &name, const ShaderSetting &shader_setting)
Register or update a wireframe frustum primitive.
void set_rainbow_range(const Eigen::Vector2f &minmax_z)
Set range of color mapping for RAINBOW mode.
bool info_buffer_enabled() const
Whether info buffer is enabled.
void lookat(const Vector &pt)
Make the camera look at a point.
Definition light_viewer_context.hpp:209
const glk::Texture & depth_buffer() const
Depth buffer.
void lookat(const Eigen::Isometry3f &T_world_sensor)
Make the camera look at a transform.
const glk::Texture & color_buffer() const
Color buffer.
void enable_info_buffer()
Enable info buffer.
std::shared_ptr< SensorViewCameraControl > use_sensor_view_camera_control(const Eigen::Isometry3f &T_sensor_camera=Eigen::Translation3f(-5.0f, 0.0f, 0.1f) *Eigen::Isometry3f::Identity(), double smoothing_factor_trans=0.75, double smoothing_factor_rot=0.9)
Use sensor-view camera control that follows a given sensor pose.
void update_wire_sphere(const std::string &name, const ShaderSetting &shader_setting)
Register or update a wireframe sphere primitive.
void enable_decimal_rendering()
Enable partial rendering (This method will be deprecated).
void set_projection_control(const std::shared_ptr< ProjectionControl > &projection_control)
Set projection control (projection matrix control).
void set_rainbow_axis(const Eigen::Vector3f &axis)
Set axis of color mapping for RAINBOW mode.
const glk::Texture & dynamic_flag_buffer() const
Dynamic flag buffer.
void remove_ui_callback(const std::string &name)
Remove a UI callback function.
Eigen::Vector2i canvas_size() const
Get canvas size.
Definition light_viewer_context.hpp:242
void register_drawable_filter(const std::string &filter_name, const std::function< bool(const std::string &)> &filter=0)
Register a drawable filter.
const std::shared_ptr< CameraControl > & get_camera_control() const
Get camera control (model matrix control).
virtual void register_ui_callback(const std::string &name, const std::function< void()> &callback=0)
Register a UI callback function.
Orbit camera control (Up vector is locked to Z axis) Left button: rotate (pan/tilt) Middle or Right b...
Definition orbit_camera_control_xy.hpp:13
Definition orbit_camera_control_xz.hpp:8
Camera control that orbits around a tracked sensor pose. The camera always looks at the sensor positi...
Definition sensor_view_camera_control.hpp:9
Definition topdown_camera_control.hpp:8
Definition async_buffer_copy.hpp:6
std::enable_if_t< std::is_same< Dst_Scalar, Src_Scalar >::value, std::vector< Eigen::Matrix< Dst_Scalar, Dst_Rows, Dst_Cols >, Allocator< Eigen::Matrix< Dst_Scalar, Dst_Rows, Dst_Cols > > > > convert_to_vector(const Eigen::Matrix< Src_Scalar, Src_Rows, Src_Cols > *points, int num_points)
Definition type_conversion.hpp:49
COLORMAP
Definition colormap.hpp:9
Definition drawable_container.hpp:9
Shader setting class that holds rendering settings.
Definition shader_setting.hpp:187