1#ifndef GUIK_LIGHT_VIEWER_CONTEXT_HPP
2#define GUIK_LIGHT_VIEWER_CONTEXT_HPP
9#include <unordered_map>
50 void set_pos(
const Eigen::Vector2i& pos, ImGuiCond cond = ImGuiCond_FirstUseEver, ImGuiWindowFlags = 0);
104 void set_point_shape(
float point_size = 1.0f,
bool metric =
true,
bool circle =
true);
154 std::unordered_map<std::string, std::pair<ShaderSetting::Ptr, glk::Drawable::ConstPtr>>&
get_drawables();
159 std::pair<ShaderSetting::Ptr, glk::Drawable::ConstPtr>
find_drawable(
const std::string& name);
203 void lookat(
const Eigen::Isometry3f& T_world_sensor);
205 void lookat(
const Eigen::Isometry3d& T_world_sensor);
208 template <
typename Vector>
210 const auto ptf = pt.eval().template cast<float>();
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);
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);
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);
252 Eigen::Vector4i
pick_info(
const Eigen::Vector2i& p,
int window = 2)
const;
258 float pick_depth(
const Eigen::Vector2i& p,
int window = 2)
const;
264 Eigen::Vector3f
unproject(
const Eigen::Vector2i& p,
float depth)
const;
271 std::optional<Eigen::Vector3f>
pick_point(
int button = 0,
int window = 2, Eigen::Vector4i* info =
nullptr)
const;
304 template <
typename Scalar,
int Dim>
307 template <
typename Scalar,
int Dim,
typename Allocator>
308 std::shared_ptr<glk::PointCloudBuffer>
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,
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,
349 const std::string& name,
350 const float* vertices,
353 const unsigned int* indices,
361 const std::string& name,
362 const float* vertices,
365 const unsigned int* indices,
371 template <
typename Scalar,
int Dim>
372 std::shared_ptr<glk::ThinLines>
376 template <
typename ScalarV,
int DimV,
typename ScalarC,
int DimC>
378 const std::string& name,
379 const Eigen::Matrix<ScalarV, DimV, 1>* points,
380 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
386 template <
typename ScalarV,
int DimV,
typename ScalarC,
int DimC>
388 const std::string& name,
389 const Eigen::Matrix<ScalarV, DimV, 1>* points,
390 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
392 const unsigned int* indices,
398 template <
typename Po
int,
typename Alloc>
402 template <
typename Po
int,
typename Alloc>
404 const std::string& name,
405 const std::vector<Point, Alloc>& points,
406 const std::vector<unsigned int>& indices,
411 template <
typename Po
int,
typename AllocP,
typename Color,
typename AllocC>
413 const std::string& name,
414 const std::vector<Point, AllocP>& points,
415 const std::vector<Color, AllocC>& colors,
420 template <
typename Po
int,
typename AllocP,
typename Color,
typename AllocC>
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,
430 template <
typename Scalar,
int Dim>
431 std::shared_ptr<glk::ThinLines>
435 template <
typename ScalarV,
int DimV,
typename ScalarC,
int DimC>
437 const std::string& name,
438 const Eigen::Matrix<ScalarV, DimV, 1>* points,
439 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
446 template <
typename ScalarV,
int DimV,
typename ScalarC,
int DimC>
448 const std::string& name,
449 const Eigen::Matrix<ScalarV, DimV, 1>* points,
450 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
452 const unsigned int* indices,
459 template <
typename Po
int,
typename Alloc>
460 std::shared_ptr<glk::ThinLines>
464 template <
typename Po
int,
typename Alloc>
466 const std::string& name,
467 const std::vector<Point, Alloc>& points,
468 const std::vector<unsigned int>& indices,
474 template <
typename Po
int,
typename AllocP,
typename Color,
typename AllocC>
476 const std::string& name,
477 const std::vector<Point, AllocP>& points,
478 const std::vector<Color, AllocC>& colors,
484 template <
typename Po
int,
typename AllocP,
typename Color,
typename AllocC>
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,
533 std::unordered_map<std::string, std::pair<ShaderSetting::Ptr, glk::Drawable::ConstPtr>>
drawables;
542template <
typename Scalar,
int Dim>
543std::shared_ptr<glk::PointCloudBuffer>
545 if constexpr (std::is_same<Scalar, float>::value) {
553template <
typename Scalar,
int Dim,
typename Allocator>
554std::shared_ptr<glk::PointCloudBuffer>
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,
571template <
typename Scalar,
int Dim>
572std::shared_ptr<glk::ThinLines>
574 if constexpr (std::is_same<Scalar, float>::value && Dim == 3) {
582template <
typename ScalarV,
int DimV,
typename ScalarC,
int DimC>
584 const std::string& name,
585 const Eigen::Matrix<ScalarV, DimV, 1>* points,
586 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
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);
599template <
typename ScalarV,
int DimV,
typename ScalarC,
int DimC>
601 const std::string& name,
602 const Eigen::Matrix<ScalarV, DimV, 1>* points,
603 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
605 const unsigned int* indices,
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);
618template <
typename Po
int,
typename Alloc>
619std::shared_ptr<glk::ThinLines>
624template <
typename Po
int,
typename Alloc>
626 const std::string& name,
627 const std::vector<Point, Alloc>& points,
628 const std::vector<unsigned int>& indices,
631 return update_thin_lines(name, points.data(),
static_cast<const Eigen::Vector4f*
>(
nullptr), points.size(), indices.data(), indices.size(), line_strip,
shader_setting);
634template <
typename Po
int,
typename AllocP,
typename Color,
typename AllocC>
636 const std::string& name,
637 const std::vector<Point, AllocP>& points,
638 const std::vector<Color, AllocC>& colors,
644template <
typename Po
int,
typename AllocP,
typename Color,
typename AllocC>
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,
656template <
typename Scalar,
int Dim>
658 const std::string& name,
659 const Eigen::Matrix<Scalar, Dim, 1>* points,
664 if constexpr (std::is_same<Scalar, float>::value && Dim == 3) {
672template <
typename ScalarV,
int DimV,
typename ScalarC,
int DimC>
674 const std::string& name,
675 const Eigen::Matrix<ScalarV, DimV, 1>* points,
676 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
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);
690template <
typename ScalarV,
int DimV,
typename ScalarC,
int DimC>
692 const std::string& name,
693 const Eigen::Matrix<ScalarV, DimV, 1>* points,
694 const Eigen::Matrix<ScalarC, DimC, 1>* colors,
696 const unsigned int* indices,
701 if constexpr (std::is_same<ScalarV, float>::value && DimV == 3 && std::is_same<ScalarC, float>::value && DimC == 4) {
704 reinterpret_cast<const float*
>(points),
705 reinterpret_cast<const float*
>(colors),
719template <
typename Po
int,
typename Alloc>
720std::shared_ptr<glk::ThinLines>
725template <
typename Po
int,
typename Alloc>
727 const std::string& name,
728 const std::vector<Point, Alloc>& points,
729 const std::vector<unsigned int>& indices,
736 static_cast<const Eigen::Vector4f*
>(
nullptr),
745template <
typename Po
int,
typename AllocP,
typename Color,
typename AllocC>
747 const std::string& name,
748 const std::vector<Point, AllocP>& points,
749 const std::vector<Color, AllocC>& colors,
756template <
typename Po
int,
typename AllocP,
typename Color,
typename AllocC>
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,
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 ®ex)
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.
virtual ~LightViewerContext()
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