瀏覽代碼

Enabled opacity rendering.

jcsyshc 2 年之前
父節點
當前提交
3136603fb9
共有 4 個文件被更改,包括 27 次插入5 次删除
  1. 4 0
      src/augment_renderer.cpp
  2. 2 2
      src/config.h
  3. 8 3
      src/frame_buffer_helper.hpp
  4. 13 0
      src/main.cpp

+ 4 - 0
src/augment_renderer.cpp

@@ -64,6 +64,7 @@ struct augment_renderer::impl {
         vtk_cam->SetClippingRange(default_len_focus, 2000);
         if (vtk_window == nullptr) {
             vtk_render = vtkSmartPointer<vtkRenderer>::New();
+            vtk_render->SetUseDepthPeeling(true);
             vtk_window = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
             vtk_window->InitializeFromCurrentContext();
             vtk_window->SetSize(cam_info->width, cam_info->height);
@@ -122,10 +123,13 @@ struct augment_renderer::impl {
     }
 
     void render_vtk() {
+        glEnable(GL_DEPTH_TEST);
+        glClear(GL_DEPTH_BUFFER_BIT);
         vtk_render->SetActiveCamera(vtk_cam);
         vtk_render->Modified();
         vtk_window->SetIsCurrent(true);
         vtk_window->Render();
+        glDisable(GL_DEPTH_TEST);
         auto vtk_tex = vtk_window->GetDisplayFramebuffer()
                 ->GetColorAttachmentAsTextureObject(0)->GetHandle();
         texture_renderer::render_config tex_config{

+ 2 - 2
src/config.h

@@ -20,8 +20,8 @@ static constexpr auto right_camera_name = "RightEye";
 
 static constexpr auto default_len_focus = 8; // 8mm, maybe not useful
 
-static constexpr auto default_camera_exposure_time_ms = 7; // 5ms
-static constexpr auto default_camera_analog_gain = 20; // 20dB
+static constexpr auto default_camera_exposure_time_ms = 0.4; // 5ms
+static constexpr auto default_camera_analog_gain = 15; // 20dB
 static constexpr auto default_camera_fps = 30; // 30 fps
 
 static constexpr auto default_time_out = std::chrono::milliseconds(50); // 50ms

+ 8 - 3
src/frame_buffer_helper.hpp

@@ -11,7 +11,7 @@
 struct frame_buffer_helper {
 
     int tex_width = 2 * image_width, tex_height = image_height;
-    GLuint tex = 0, fbo = 0, pbo = 0;
+    GLuint tex = 0, depth_tex = 0, fbo = 0, pbo = 0;
     cudaGraphicsResource *pbo_res = nullptr;
 
     ~frame_buffer_helper() {
@@ -19,7 +19,7 @@ struct frame_buffer_helper {
         cudaGraphicsUnregisterResource(pbo_res);
         glDeleteBuffers(1, &pbo);
         glDeleteFramebuffers(1, &fbo);
-        glDeleteTextures(1, &tex);
+        glDeleteTextures(2, &tex);
     }
 
     bool initialize(int width, int height) {
@@ -27,17 +27,22 @@ struct frame_buffer_helper {
         tex_height = height;
 
         // create and allocate tex
-        glGenTextures(1, &tex);
+        glGenTextures(2, &tex);
         glBindTexture(GL_TEXTURE_2D, tex);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
         glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, tex_width, tex_height);
 
+        glBindTexture(GL_TEXTURE_2D, depth_tex);
+        glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT16, tex_width, tex_height);
+
         // create and config fbo
         glGenFramebuffers(1, &fbo);
         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
         glBindTexture(GL_TEXTURE_2D, tex);
         glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
+        glBindTexture(GL_TEXTURE_2D, depth_tex);
+        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_tex, 0);
         CALL_CHECK(check_frame_buffer());
 
         // create and config pbo

+ 13 - 0
src/main.cpp

@@ -284,6 +284,19 @@ int main() {
                 ImGui::PopID();
             }
 
+            if (camera.is_capturing() && ImGui::CollapsingHeader("AR Config")) {
+                ImGui::PushID("AR");
+
+                static int femur_opacity = 100;
+                static int tibia_opacity = 100;
+                ImGui::DragInt("Femur Transparency", &femur_opacity, 1, 0, 100);
+                ImGui::DragInt("Tibia Transparency", &tibia_opacity, 1, 0, 100);
+                femur_actor->GetProperty()->SetOpacity(0.01 * femur_opacity);
+                tibia_actor->GetProperty()->SetOpacity(0.01 * tibia_opacity);
+
+                ImGui::PopID();
+            }
+
             // video streamer control
             if (camera.is_capturing() && ImGui::CollapsingHeader("Video Encoder")) {
                 ImGui::PushID("Encoder");