depth_guide.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "depth_guide.h"
  2. #include "core/image_utility.hpp"
  3. #include "core/imgui_utility.hpp"
  4. app_depth_guide::app_depth_guide(const create_config &_conf) {
  5. conf = _conf;
  6. // initialize object manager
  7. OBJ_SAVE(img_color, image_u8c3());
  8. OBJ_SAVE(img_depth, image_f32c1());
  9. OBJ_SAVE(img_bg, image_u8c3());
  10. OBJ_SAVE(img_out, image_u8c4());
  11. OBJ_SIG(img_color)->connect(INT_MIN, [=](obj_name_type _) {
  12. OBJ_SAVE(img_bg, OBJ_QUERY(image_u8c3, img_color));
  13. });
  14. // initialize modules
  15. auto orb_cam_conf = orb_camera_ui::create_config{
  16. .cf_name = img_color, .df_name = img_depth,
  17. .ctx = conf.asio_ctx, .stream = default_cuda_stream,
  18. };
  19. orb_cam = std::make_unique<orb_camera_ui>(orb_cam_conf);
  20. auto bg_viewer_conf = image_viewer::create_config{
  21. .mode = VIEW_COLOR_DEPTH, .flip_y = true,
  22. .stream = default_cuda_stream,
  23. };
  24. auto &bg_extra_conf = bg_viewer_conf.extra.color_depth;
  25. bg_extra_conf.c_name = img_color;
  26. bg_extra_conf.d_name = img_depth;
  27. bg_viewer = std::make_unique<image_viewer>(bg_viewer_conf);
  28. auto out_down_conf = viewport_downloader::create_config{
  29. .stream = default_cuda_stream
  30. };
  31. out_downloader = std::make_unique<viewport_downloader>(out_down_conf);
  32. auto out_streamer_conf = image_streamer::create_config{
  33. .img_name = img_out, .asio_ctx = conf.asio_ctx,
  34. .cuda_ctx = conf.cuda_ctx, .stream = default_cuda_stream
  35. };
  36. out_streamer = std::make_unique<image_streamer>(out_streamer_conf);
  37. }
  38. void app_depth_guide::show_ui() {
  39. auto ctx = conf.asio_ctx;
  40. if (ImGui::Begin("Depth Guide Control")) {
  41. ImGui::PushItemWidth(200);
  42. if (ImGui::CollapsingHeader("Camera")) {
  43. auto id_guard = imgui_id_guard("camera");
  44. orb_cam->show();
  45. }
  46. if (ImGui::CollapsingHeader("Streamer")) {
  47. auto id_guard = imgui_id_guard("streamer");
  48. out_streamer->show();
  49. }
  50. if (ImGui::CollapsingHeader("Debug")) {
  51. if (ImGui::TreeNode("Background")) {
  52. bg_viewer->show();
  53. ImGui::TreePop();
  54. }
  55. if (ImGui::TreeNode("Memory Pool")) {
  56. if (ImGui::Button("Purge")) {
  57. post(*ctx, [] { global_mp.purge(); });
  58. }
  59. ImGui::TreePop();
  60. }
  61. if (ImGui::TreeNode("Performance")) {
  62. ImGui::Text("UI Refresh Rate: %.2fms", perf_timer.query().interval);
  63. ImGui::TreePop();
  64. }
  65. }
  66. ImGui::PopItemWidth();
  67. }
  68. ImGui::End();
  69. perf_timer.record();
  70. }
  71. void app_depth_guide::render_background() {
  72. bg_viewer->render();
  73. // TODO: for test
  74. auto bg_img = out_downloader->download_argb();
  75. OBJ_SAVE(img_out, bg_img);
  76. }