depth_guide_controller.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "depth_guide_controller_impl.h"
  2. #include "core/imgui_utility.hpp"
  3. depth_guide_controller::impl::impl(create_config _conf) {
  4. conf = _conf;
  5. }
  6. void depth_guide_controller::impl::build(render_config r_conf) {
  7. auto obj_ts = OBJ_TS(conf.img_in);
  8. if (obj_ts <= last_ts) return;
  9. auto img_in = OBJ_QUERY(image_u8c3, conf.img_in);
  10. auto depth_in = OBJ_QUERY(image_f32c1, conf.depth_in);
  11. if (img_in == nullptr || depth_in == nullptr) return;
  12. img_in->sync_create(r_conf.stream);
  13. depth_in->sync_create(r_conf.stream);
  14. auto out_info = create_image_info<uchar4>(img_in->size(), MEM_CUDA);
  15. auto depth_conf = depth_mask_config{
  16. .lower = depth_range.min * 1000.f, // mm -> m
  17. .upper = depth_range.max * 1000.f,
  18. };
  19. call_depth_mask(
  20. img_in->as_cuda(r_conf.stream), depth_in->as_cuda(r_conf.stream),
  21. out_info.as_cuda(), depth_conf, r_conf.stream->cuda);
  22. out_img = create_image(out_info, r_conf.stream);
  23. if (conf.img_out != invalid_obj_name) {
  24. OBJ_SAVE(conf.img_out, out_img);
  25. }
  26. last_ts = obj_ts;
  27. }
  28. void depth_guide_controller::impl::render(render_config r_conf) {
  29. build(r_conf);
  30. if (out_img == nullptr) return;
  31. auto ren_conf = color_image_render::config_type{
  32. .fmt = COLOR_RGBA, .flip_y = true, .stream = r_conf.stream,
  33. };
  34. ren.render_rgba(out_img->as_info(), ren_conf);
  35. }
  36. void depth_guide_controller::impl::show() {
  37. static constexpr float dep_hard_min = 0.15; // TODO: config value
  38. static constexpr float dep_hard_max = 1.00;
  39. ImGui::DragFloat2("Depth Range (m)", (float *) &depth_range, 0.02f,
  40. dep_hard_min, dep_hard_max, "%.2f");
  41. }
  42. depth_guide_controller::depth_guide_controller(create_config conf)
  43. : pimpl(std::make_unique<impl>(conf)) {
  44. }
  45. depth_guide_controller::~depth_guide_controller() = default;
  46. void depth_guide_controller::render(render_config conf) {
  47. pimpl->render(conf);
  48. }
  49. void depth_guide_controller::show() {
  50. pimpl->show();
  51. }