camera_augment_helper_v2_impl.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #ifndef DEPTHGUIDE_CAMERA_AUGMENT_HELPER_V2_IMPL_H
  2. #define DEPTHGUIDE_CAMERA_AUGMENT_HELPER_V2_IMPL_H
  3. #include "module/camera_augment_helper_v2.h"
  4. #include "core/math_helper.hpp"
  5. #include "module/viewport_downloader.hpp"
  6. struct camera_augment_helper_v2::impl {
  7. camera_augment_helper_v2 *q_this = nullptr;
  8. std::string transform_var; // sophiar
  9. std::optional<glm::mat4> tracked_transform; // transform matrix from sophiar
  10. bool is_missing = false;
  11. int time_offset = -76000; // -76ms
  12. transform_buffer track_pool;
  13. augment_manager_v2 *manager = nullptr;
  14. sophiar_conn_type *sophiar_conn = nullptr;
  15. using io_context = boost::asio::io_context;
  16. io_context *ctx = nullptr;
  17. struct ui_conf {
  18. bool ignore_missing = false;
  19. bool enable_active_guide = false;
  20. float near = 10.0f;
  21. float far = 1000.0f; // clip range (mm)
  22. };
  23. std::shared_ptr<ui_conf> ui =
  24. std::make_shared<ui_conf>();
  25. // for all
  26. float fov = 60.0f; // field of view
  27. glm::mat4 transform; // standard camera transform
  28. struct fixed_info_type {
  29. glm::vec3 extra_offset = glm::vec3();
  30. glm::vec3 extra_rotation = glm::vec3();
  31. glm::mat4 extra_transform() const;
  32. } fixed_info;
  33. struct freedom_info_type {
  34. glm::vec3 eye = glm::vec3();
  35. glm::vec3 center = glm::vec3(0.0f, 0.0f, 100.0f); // focus
  36. glm::vec3 view_up = glm::vec3(0.0f, -1.0f, 0.0f);
  37. float angle_speed = 5.0f; // degree
  38. float linear_speed = 20.0f; // mm
  39. impl *pimpl = nullptr;
  40. void reset();
  41. glm::vec3 view_dir() const;
  42. float view_dis() const;
  43. void translate(glm::vec3 offset);
  44. void forward(float dis);
  45. void move_right(float dis);
  46. void move_up(float dis);
  47. void center_forward(float dis);
  48. void roll(float deg);
  49. void yaw(float deg);
  50. void pitch(float deg);
  51. glm::mat4 to_transform();
  52. } freedom_info;
  53. struct {
  54. impl *parent;
  55. glm::mat4 transform;
  56. } relative_info;
  57. enum {
  58. MODE_FIXED,
  59. MODE_RELATIVE,
  60. MODE_FREEDOM
  61. } mode;
  62. // for off-screen rendering
  63. smart_frame_buffer::create_config fbo_conf = {};
  64. smart_frame_buffer fbo;
  65. std::unique_ptr<viewport_downloader> img_downloader;
  66. // for interaction
  67. using conn_type = boost::signals2::connection;
  68. conn_type pre_render_conn;
  69. camera_info last_camera;
  70. cv::Size last_vp_size;
  71. // active guidance
  72. bool allow_active_guide = false;
  73. cursor_guide *act_guide;
  74. // passive guidance
  75. bool enable_passive_guide = false;
  76. guide_info pas_info;
  77. // cursor_guide pas_guide;
  78. explicit impl(const create_config &conf);
  79. ~impl();
  80. void update_tracked_transform();
  81. void update_freedom();
  82. void update_fixed();
  83. void update_relative();
  84. void update_transform();
  85. void update_camera();
  86. void render();
  87. void render_image(output_config conf);
  88. void show_freedom();
  89. void show_fixed();
  90. void show();
  91. // get cursor position in world coordinate
  92. // must be called during rendering process
  93. // s_pos: mouse position in screen
  94. std::optional<glm::vec3> get_cursor_coordinate(glm::vec2 s_pos);
  95. void pre_render_slot(const scene_ptr &info);
  96. };
  97. #endif //DEPTHGUIDE_CAMERA_AUGMENT_HELPER_V2_IMPL_H