Forráskód Böngészése

Move point cloud upload function to generic_pc.

jcsyshc 1 éve
szülő
commit
d83aa18a9f

+ 1 - 0
CMakeLists.txt

@@ -44,6 +44,7 @@ add_executable(${PROJECT_NAME} src/main.cpp
         src/render_v3/scene_render.cpp
         src/render/impl/render_mesh.cpp
         src/render/impl/render_pc.cpp
+        src/render/impl/render_scene.cpp
         src/render/impl/render_texture.cpp
         src/render/impl/render_tools.cpp
         src/render/impl/render_utility.cpp)

+ 48 - 0
src/core/impl/pc_utility.cpp

@@ -114,6 +114,49 @@ pc_type_v1<PointT> generic_pc::impl::get_pc_type_v1(smart_cuda_stream *stream) {
     return pc_type_v1<PointT>((PointT *) store_cuda.ptr.get(), size);
 }
 
+generic_pc::impl::gl_store_info::~gl_store_info() {
+    glDeleteVertexArrays(1, &vao);
+}
+
+void generic_pc::impl::create_gl_info(smart_cuda_stream *stream) {
+    assert(gl_info == nullptr);
+    gl_info = std::make_unique<gl_store_info>();
+
+    // upload to VBO
+    gl_info->vbo.upload(q_this->shared_from_this(), stream);
+    // TODO: chose upload source (HOST or CUDA)
+
+    GLuint vao = 0;
+    glGenVertexArrays(1, &vao);
+    glBindVertexArray(vao);
+    switch (fmt) {
+        case PC_XYZ_RGB: {
+            glEnableVertexAttribArray(0);
+            glEnableVertexAttribArray(1);
+            glVertexAttribPointer(0, 3, GL_FLOAT, false,
+                                  sizeof(pc_xyz_rgb_type), (void *) offsetof(pc_xyz_rgb_type, x));
+            glVertexAttribPointer(1, 3, GL_UNSIGNED_BYTE, true,
+                                  sizeof(pc_xyz_rgb_type), (void *) offsetof(pc_xyz_rgb_type, r));
+            break;
+        }
+        default: {
+            RET_ERROR;
+        }
+    }
+    gl_info->vao = vao;
+}
+
+generic_pc::gl_info_type
+generic_pc::impl::get_gl_info(smart_cuda_stream *stream) {
+    if (gl_info == nullptr) [[unlikely]] {
+        create_gl_info(stream);
+    }
+    assert(gl_info != nullptr);
+    return {.vao = gl_info->vao,
+            .vbo = gl_info->vbo.id,
+            .num_points = (GLuint) size};
+}
+
 void generic_pc::impl::host_modified(smart_cuda_stream *stream) {
     assert(store_host.ptr != nullptr);
     store_cuda.reset();
@@ -173,6 +216,11 @@ template pc_type_v1<pc_xyz_type> generic_pc::cuda(smart_cuda_stream *stream);
 template pc_type_v1<pc_xyz_rgb_type> generic_pc::cuda(smart_cuda_stream *stream);
 // @formatter:on
 
+generic_pc::gl_info_type
+generic_pc::get_gl_info(smart_cuda_stream *stream) {
+    return pimpl->get_gl_info(stream);
+}
+
 void generic_pc::host_modified(smart_cuda_stream *stream) {
     pimpl->host_modified(stream);
 }

+ 14 - 0
src/core/impl/pc_utility_impl.h

@@ -2,6 +2,7 @@
 #define DEPTHGUIDE_PC_UTILITY_IMPL_H
 
 #include "core/pc_utility.h"
+#include "render/render_utility.h"
 
 #include <typeindex>
 
@@ -29,6 +30,15 @@ struct generic_pc::impl : public meta_base::impl {
     size_t size;
     pc_format_enum fmt;
 
+    struct gl_store_info : boost::noncopyable {
+        GLuint vao;
+        smart_opengl_buffer vbo;
+
+        ~gl_store_info();
+    };
+
+    std::unique_ptr<gl_store_info> gl_info;
+
     explicit impl(create_config conf);
 
     size_t elem_bytes() const;
@@ -47,6 +57,10 @@ struct generic_pc::impl : public meta_base::impl {
     template<typename PointT>
     pc_type_v1<PointT> get_pc_type_v1(smart_cuda_stream *stream);
 
+    void create_gl_info(smart_cuda_stream *stream);
+
+    gl_info_type get_gl_info(smart_cuda_stream *stream);
+
     void host_modified(smart_cuda_stream *stream);
 
     void cuda_modified(smart_cuda_stream *stream);

+ 10 - 0
src/core/pc_utility.h

@@ -6,6 +6,8 @@
 #include "core/meta_helper.hpp"
 #include "image_process/cuda_impl/pc_utility.cuh"
 
+#include <glad/gl.h>
+
 #include <memory>
 
 enum pc_format_enum {
@@ -63,6 +65,14 @@ public:
     template<typename PointT>
     pc_type_v1<PointT> cuda(smart_cuda_stream *stream = nullptr);
 
+    struct gl_info_type {
+        GLuint vao = 0; // Vertex Array Object
+        GLuint vbo = 0; // Vertex Buffer Object
+        GLuint num_points = 0; // number of points
+    };
+
+    gl_info_type get_gl_info(smart_cuda_stream *stream);
+
     void host_modified(smart_cuda_stream *stream = nullptr);
 
     void cuda_modified(smart_cuda_stream *stream = nullptr);

+ 1 - 1
src/device/impl/orb_camera.cpp

@@ -245,7 +245,7 @@ bool orb_camera::impl::start(start_config conf) {
     }
 
     // open a new thread to do the time-consuming calculation work
-    aux_thread = std::make_unique<std::thread>(
+    aux_thread = std::make_unique<std::jthread>(
             [this] { generate_undistort_map(); });
 
     return true;

+ 1 - 1
src/device/impl/orb_camera_impl.h

@@ -49,7 +49,7 @@ struct orb_camera::impl {
     obj_name_type pc_name = invalid_obj_name;
 
     obj_name_type remap_name = invalid_obj_name;
-    std::unique_ptr<std::thread> aux_thread;
+    std::unique_ptr<std::jthread> aux_thread;
 
     static constexpr auto align_mode = ALIGN_D2C_HW_MODE;
 

+ 1 - 1
src/impl/apps/depth_guide/depth_guide.cpp

@@ -85,7 +85,7 @@ app_depth_guide::app_depth_guide(const create_config &_conf) {
     out_saver = std::make_unique<image_saver>(saver_conf);
 
     auto pc_conf = pc_viewer::create_config{
-            .name = pc_obj, .stream = default_cuda_stream,
+            .name = pc_raw, .stream = default_cuda_stream,
     };
     scene_viewer = std::make_unique<pc_viewer>(pc_conf);
 }

+ 1 - 0
src/render/impl/render_scene.cpp

@@ -0,0 +1 @@
+#include "render_scene_impl.h"

+ 6 - 0
src/render/impl/render_scene_impl.h

@@ -0,0 +1,6 @@
+#ifndef DEPTHGUIDE_RENDER_SCENE_IMPL_H
+#define DEPTHGUIDE_RENDER_SCENE_IMPL_H
+
+#include "render/render_scene.h"
+
+#endif //DEPTHGUIDE_RENDER_SCENE_IMPL_H

+ 3 - 36
src/render/impl/render_tools.cpp

@@ -141,45 +141,12 @@ void depth_image_render::render(obj_name_type name, config_type conf) {
 void pc_render::render(obj_name_type name, const pc_render::config_type &conf) {
     auto pc = OBJ_QUERY(pc_ptr, name);
     if (pc == nullptr) [[unlikely]] return;
-    vbo.upload(pc, conf.stream);
-
-    // create vao if needed
-    if (vao == 0
-        || last_vbo != vbo.id
-        || last_fmt != pc->format()) {
-
-        last_vbo = vbo.id;
-        last_fmt = pc->format();
-
-        glBindBuffer(GL_ARRAY_BUFFER, last_vbo);
-
-        if (vao != 0) {
-            glDeleteVertexArrays(1, &vao);
-        }
-        glGenVertexArrays(1, &vao);
-        glBindVertexArray(vao);
-
-        switch (last_fmt) {
-            case PC_XYZ_RGB: {
-                glEnableVertexAttribArray(0);
-                glEnableVertexAttribArray(1);
-                glVertexAttribPointer(0, 3, GL_FLOAT, false,
-                                      sizeof(pc_xyz_rgb_type), (void *) offsetof(pc_xyz_rgb_type, x));
-                glVertexAttribPointer(1, 3, GL_UNSIGNED_BYTE, true,
-                                      sizeof(pc_xyz_rgb_type), (void *) offsetof(pc_xyz_rgb_type, r));
-                break;
-            }
-            default: {
-                RET_ERROR;
-            }
-        }
-    }
-    assert(vao != 0);
 
+    auto gl_info = pc->get_gl_info(conf.stream);
     auto ren_info = pc_render_info();
     ren_info.pc.format = pc->format();
-    ren_info.pc.vao = vao;
-    ren_info.pc.vbo = vbo.id;
+    ren_info.pc.vao = gl_info.vao;
+    ren_info.pc.vbo = gl_info.vbo;
     ren_info.pc.num = pc->size();
     ren_info.pc.transform = conf.pc.transform;
     ren_info.pc.color = conf.pc.color;

+ 30 - 0
src/render/render_scene.h

@@ -0,0 +1,30 @@
+#ifndef DEPTHGUIDE_RENDER_SCENE_H
+#define DEPTHGUIDE_RENDER_SCENE_H
+
+#include "core/image_utility_v2.h"
+#include "render_mesh.h"
+
+struct scene_render_info {
+
+    image_ptr background_img = nullptr;
+
+    enum item_type {
+        ITEM_MESH,
+        ITEM_PC,
+    };
+
+    struct mesh_info {
+        mesh_type *mesh = nullptr;
+        struct material_type {
+            glm::vec3 ambient;
+            glm::vec3 diffuse;
+        } material = {};
+    };
+
+    struct pc_info {
+
+    };
+
+};
+
+#endif //DEPTHGUIDE_RENDER_SCENE_H

+ 0 - 7
src/render/render_tools.h

@@ -88,13 +88,6 @@ public:
     };
 
     void render(obj_name_type name, const config_type &conf);
-
-private:
-    smart_opengl_buffer vbo;
-
-    GLuint vao = 0;
-    GLuint last_vbo = 0;
-    pc_format_enum last_fmt;
 };
 
 #endif //DEPTHGUIDE_RENDER_TOOLS_H