|
|
@@ -1,11 +1,6 @@
|
|
|
#include "main_impl.h"
|
|
|
-#include "device/orb_camera_ui.h"
|
|
|
-#include "core/event_timer.h"
|
|
|
-#include "core/image_utility.hpp"
|
|
|
-#include "module/image_streamer.h"
|
|
|
-#include "module/image_viewer.h"
|
|
|
-#include "module/viewport_downloader.hpp"
|
|
|
-#include "object_names.h"
|
|
|
+#include "core/object_manager.h"
|
|
|
+#include "impl/apps/depth_guide/depth_guide.h"
|
|
|
|
|
|
#include <boost/asio/io_context.hpp>
|
|
|
#include <boost/asio/post.hpp>
|
|
|
@@ -32,15 +27,11 @@ smart_cuda_stream *default_cuda_stream = nullptr;
|
|
|
io_context *main_ctx;
|
|
|
object_manager *main_ob;
|
|
|
|
|
|
-event_timer perf_timer; // performance timer
|
|
|
+//event_timer perf_timer; // performance timer
|
|
|
std::unique_ptr<steady_timer> ui_timer;
|
|
|
std::chrono::milliseconds ui_interval;
|
|
|
|
|
|
-// modules
|
|
|
-std::unique_ptr<orb_camera_ui> orb_cam;
|
|
|
-std::unique_ptr<image_viewer> bg_viewer; // background viewer
|
|
|
-std::unique_ptr<viewport_downloader> out_downloader;
|
|
|
-std::unique_ptr<image_streamer> out_streamer; // output streamer
|
|
|
+std::unique_ptr<app_base> app;
|
|
|
|
|
|
void init_cuda() {
|
|
|
cuInit(0);
|
|
|
@@ -68,7 +59,8 @@ void init_window() {
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
- window = glfwCreateWindow(800, 600, "DepthGuide V1.-1", nullptr, nullptr); // TODO: select width and height
|
|
|
+ // TODO: select width and height
|
|
|
+ window = glfwCreateWindow(800, 600, "An not simple platform for visual navigation", nullptr, nullptr);
|
|
|
assert(window != nullptr);
|
|
|
glfwMakeContextCurrent(window);
|
|
|
glfwSwapInterval(0);
|
|
|
@@ -114,47 +106,6 @@ void init_window() {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-void init_om() {
|
|
|
- main_ctx = new io_context();
|
|
|
- main_ob = new object_manager({.ctx = main_ctx});
|
|
|
- OBJ_SAVE(img_color, image_u8c3());
|
|
|
- OBJ_SAVE(img_depth, image_f32c1());
|
|
|
- OBJ_SAVE(img_bg, image_u8c3());
|
|
|
- OBJ_SAVE(img_out, image_u8c4());
|
|
|
-
|
|
|
- OBJ_SIG(img_color)->connect(INT_MIN, [=](obj_name_type _) {
|
|
|
- OBJ_SAVE(img_bg, OBJ_QUERY(image_u8c3, img_color));
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-void init_modules() {
|
|
|
- auto orb_cam_conf = orb_camera_ui::create_config{
|
|
|
- .cf_name = img_color, .df_name = img_depth,
|
|
|
- .ctx = main_ctx, .stream = default_cuda_stream,
|
|
|
- };
|
|
|
- orb_cam = std::make_unique<orb_camera_ui>(orb_cam_conf);
|
|
|
-
|
|
|
- auto bg_viewer_conf = image_viewer::create_config{
|
|
|
- .mode = VIEW_COLOR_DEPTH, .flip_y = true,
|
|
|
- .stream = default_cuda_stream,
|
|
|
- };
|
|
|
- auto &bg_extra_conf = bg_viewer_conf.extra.color_depth;
|
|
|
- bg_extra_conf.c_name = img_color;
|
|
|
- bg_extra_conf.d_name = img_depth;
|
|
|
- bg_viewer = std::make_unique<image_viewer>(bg_viewer_conf);
|
|
|
-
|
|
|
- auto out_down_conf = viewport_downloader::create_config{
|
|
|
- .type = PIX_RGBA, .stream = default_cuda_stream
|
|
|
- };
|
|
|
- out_downloader = std::make_unique<viewport_downloader>(out_down_conf);
|
|
|
-
|
|
|
- auto out_streamer_conf = image_streamer::create_config{
|
|
|
- .img_name = img_out, .asio_ctx = main_ctx,
|
|
|
- .cuda_ctx = &cuda_ctx, .stream = default_cuda_stream
|
|
|
- };
|
|
|
- out_streamer = std::make_unique<image_streamer>(out_streamer_conf);
|
|
|
-}
|
|
|
-
|
|
|
void ui_timer_func(error_code ec) {
|
|
|
if (ec == boost::asio::error::operation_aborted) return;
|
|
|
assert(ec == error_code());
|
|
|
@@ -166,9 +117,17 @@ void ui_timer_func(error_code ec) {
|
|
|
void init_all() {
|
|
|
init_cuda();
|
|
|
init_window();
|
|
|
- init_om();
|
|
|
- init_modules();
|
|
|
|
|
|
+ main_ctx = new io_context();
|
|
|
+ main_ob = new object_manager({.ctx = main_ctx});
|
|
|
+
|
|
|
+ auto app_config = app_base::create_config{
|
|
|
+ .asio_ctx = main_ctx, .cuda_ctx = &cuda_ctx
|
|
|
+ };
|
|
|
+ // TODO: switch app here
|
|
|
+ app = std::make_unique<app_depth_guide>(app_config);
|
|
|
+
|
|
|
+ glfwSetWindowTitle(window, app->window_name());
|
|
|
ui_interval = std::chrono::milliseconds(33); // TODO: select refresh rate
|
|
|
ui_timer = std::make_unique<steady_timer>(*main_ctx, ui_interval);
|
|
|
ui_timer->async_wait(ui_timer_func);
|
|
|
@@ -186,39 +145,8 @@ void show_ui() {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (ImGui::Begin("Depth Guide Control")) {
|
|
|
- ImGui::PushItemWidth(200);
|
|
|
-
|
|
|
- if (ImGui::CollapsingHeader("Camera")) {
|
|
|
- auto id_guard = imgui_id_guard("camera");
|
|
|
- orb_cam->show();
|
|
|
- }
|
|
|
-
|
|
|
- if (ImGui::CollapsingHeader("Streamer")) {
|
|
|
- auto id_guard = imgui_id_guard("streamer");
|
|
|
- out_streamer->show();
|
|
|
- }
|
|
|
-
|
|
|
- if (ImGui::CollapsingHeader("Debug")) {
|
|
|
- if (ImGui::TreeNode("Background")) {
|
|
|
- bg_viewer->show();
|
|
|
- ImGui::TreePop();
|
|
|
- }
|
|
|
- if (ImGui::TreeNode("Memory Pool")) {
|
|
|
- if (ImGui::Button("Purge")) {
|
|
|
- post(*main_ctx, [] { global_mp.purge(); });
|
|
|
- }
|
|
|
- ImGui::TreePop();
|
|
|
- }
|
|
|
- if (ImGui::TreeNode("Performance")) {
|
|
|
- ImGui::Text("UI Refresh Rate: %.2fms", perf_timer.query().interval);
|
|
|
- ImGui::TreePop();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- ImGui::PopItemWidth();
|
|
|
- }
|
|
|
- ImGui::End();
|
|
|
+ assert(app != nullptr);
|
|
|
+ app->show_ui();
|
|
|
ImGui::Render();
|
|
|
|
|
|
cv::Size frame_size;
|
|
|
@@ -227,24 +155,15 @@ void show_ui() {
|
|
|
glViewport(0, 0, frame_size.width, frame_size.height);
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
- bg_viewer->render();
|
|
|
-
|
|
|
- // TODO: for test
|
|
|
- auto bg_img = out_downloader->download_rgba();
|
|
|
- OBJ_SAVE(img_out, bg_img);
|
|
|
+ app->render_background();
|
|
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
glfwSwapBuffers(window);
|
|
|
- perf_timer.record();
|
|
|
}
|
|
|
|
|
|
void cleanup() {
|
|
|
+ app = nullptr;
|
|
|
ui_timer = nullptr;
|
|
|
- orb_cam = nullptr;
|
|
|
- bg_viewer = nullptr;
|
|
|
- out_downloader = nullptr;
|
|
|
- out_streamer = nullptr;
|
|
|
-
|
|
|
delete main_ob;
|
|
|
delete main_ctx;
|
|
|
}
|