image_viewer.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include "image_viewer_impl.h"
  2. #include "core/imgui_utility.hpp"
  3. #include "render/render_texture.h"
  4. void image_viewer::impl::show_depth_only() {
  5. {
  6. auto guard = imgui_disable_guard(!depth_conf.manual_depth_range);
  7. static constexpr float dep_hard_min = 0.15; // TODO: config value
  8. static constexpr float dep_hard_max = 10.0;
  9. ImGui::DragFloat2("Depth Range (m)", (float *) &depth_conf.depth_range, 0.05f,
  10. dep_hard_min, dep_hard_max, "%.2f");
  11. }
  12. ImGui::SameLine();
  13. ImGui::Checkbox("##manual_dep_range", &depth_conf.manual_depth_range);
  14. }
  15. void image_viewer::impl::show_color_depth() {
  16. ImGui::RadioButton("Color", &chose_index, 0);
  17. ImGui::SameLine();
  18. ImGui::RadioButton("Depth", &chose_index, 1);
  19. ImGui::SameLine();
  20. ImGui::RadioButton("Both", &chose_index, 2);
  21. if (chose_index == 1 || chose_index == 2) { // depth or both
  22. show_depth_only();
  23. }
  24. ImGui::PushItemWidth(150);
  25. if (chose_index == 2) { // both
  26. ImGui::SliderFloat("Depth Alpha", &depth_overlay_alpha, 0.f, 1.f, "%.2f");
  27. }
  28. }
  29. void image_viewer::impl::show_stereo() {
  30. ImGui::RadioButton("Left", &chose_index, 0);
  31. ImGui::SameLine();
  32. ImGui::RadioButton("Right", &chose_index, 1);
  33. }
  34. void image_viewer::impl::show() {
  35. ImGui::PushItemWidth(150);
  36. switch (conf.mode) {
  37. case VIEW_COLOR_ONLY: {
  38. break;
  39. }
  40. case VIEW_DEPTH_ONLY: {
  41. show_depth_only();
  42. break;
  43. }
  44. case VIEW_COLOR_DEPTH: {
  45. show_color_depth();
  46. break;
  47. }
  48. case VIEW_STEREO: {
  49. show_stereo();
  50. break;
  51. }
  52. default: {
  53. RET_ERROR;
  54. }
  55. }
  56. ImGui::PopItemWidth();
  57. }
  58. void image_viewer::impl::render_color_obj(obj_name_type name) {
  59. color_render.render(name, color_conf);
  60. }
  61. void image_viewer::impl::render_depth_obj(obj_name_type name, float alpha) {
  62. depth_conf.alpha = alpha;
  63. depth_render.render(name, depth_conf);
  64. }
  65. void image_viewer::impl::render_color_depth() {
  66. auto info = conf.extra.color_depth;
  67. if (chose_index == 0 || chose_index == 2) { // color or both
  68. color_conf.fmt = info.c_fmt;
  69. }
  70. switch (chose_index) {
  71. case 0: { // color
  72. render_color_obj(info.c_name);
  73. break;
  74. }
  75. case 1: { // depth
  76. render_depth_obj(info.d_name);
  77. break;
  78. }
  79. case 2: { // both
  80. render_color_obj(info.c_name);
  81. render_depth_obj(info.d_name, depth_overlay_alpha);
  82. break;
  83. }
  84. default: {
  85. RET_ERROR;
  86. }
  87. }
  88. }
  89. void image_viewer::impl::render_stereo() {
  90. auto info = conf.extra.stereo;
  91. color_conf.fmt = info.c_fmt;
  92. switch (chose_index) {
  93. case 0: { // left
  94. render_color_obj(info.left_name);
  95. break;
  96. }
  97. case 1: {
  98. render_color_obj(info.right_name);
  99. break;
  100. }
  101. default: {
  102. RET_ERROR;
  103. }
  104. }
  105. }
  106. void image_viewer::impl::render() {
  107. switch (conf.mode) {
  108. case VIEW_COLOR_ONLY: {
  109. color_conf.fmt = conf.extra.color.fmt;
  110. render_color_obj(conf.extra.color.name);
  111. break;
  112. }
  113. case VIEW_DEPTH_ONLY: {
  114. render_depth_obj(conf.extra.depth.name);
  115. break;
  116. }
  117. case VIEW_COLOR_DEPTH: {
  118. render_color_depth();
  119. break;
  120. }
  121. case VIEW_STEREO: {
  122. render_stereo();
  123. break;
  124. }
  125. default: {
  126. RET_ERROR;
  127. }
  128. }
  129. }
  130. image_viewer::impl::impl(create_config _conf) {
  131. conf = _conf;
  132. color_conf.flip_y = conf.flip_y;
  133. color_conf.stream = conf.stream;
  134. depth_conf.flip_y = conf.flip_y;
  135. depth_conf.stream = conf.stream;
  136. }
  137. image_viewer::image_viewer(create_config conf)
  138. : pimpl(std::make_unique<impl>(conf)) {
  139. }
  140. image_viewer::~image_viewer() = default;
  141. void image_viewer::show() {
  142. pimpl->show();
  143. }
  144. void image_viewer::render() {
  145. pimpl->render();
  146. }