|
@@ -12,6 +12,12 @@
|
|
|
#include <imgui_impl_glfw.h>
|
|
#include <imgui_impl_glfw.h>
|
|
|
#include <imgui_impl_opengl3.h>
|
|
#include <imgui_impl_opengl3.h>
|
|
|
|
|
|
|
|
|
|
+#include <ExternalVTKWidget.h>
|
|
|
|
|
+#include <vtkActor.h>
|
|
|
|
|
+#include <vtkMatrix4x4.h>
|
|
|
|
|
+#include <vtkPolyDataMapper.h>
|
|
|
|
|
+#include <vtkSTLReader.h>
|
|
|
|
|
+
|
|
|
#include <glad/gl.h>
|
|
#include <glad/gl.h>
|
|
|
#include <GLFW/glfw3.h>
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
|
|
@@ -22,6 +28,28 @@
|
|
|
#include <cassert>
|
|
#include <cassert>
|
|
|
#include <cstdlib>
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
|
|
+// for debug;
|
|
|
|
|
+#include <ndi/CombinedApi.h>
|
|
|
|
|
+
|
|
|
|
|
+// for debug;
|
|
|
|
|
+Eigen::Isometry3d port_info_to_transform(const Transform &info) {
|
|
|
|
|
+ using namespace Eigen;
|
|
|
|
|
+ auto translate = Translation3d(info.tx, info.ty, info.tz);
|
|
|
|
|
+ auto rotation = Quaterniond(info.q0, info.qx, info.qy, info.qz);
|
|
|
|
|
+ return translate * rotation;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// for debug;
|
|
|
|
|
+void transform_to_vtk_matrix(const Eigen::Isometry3d &trans, vtkMatrix4x4 *matrix) {
|
|
|
|
|
+ if (matrix == nullptr) return;
|
|
|
|
|
+ for (int i = 0; i < 4; ++i) {
|
|
|
|
|
+ for (int j = 0; j < 4; ++j) {
|
|
|
|
|
+ matrix->SetElement(i, j, trans(i, j));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ matrix->Modified();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
CUcontext cuda_ctx;
|
|
CUcontext cuda_ctx;
|
|
|
|
|
|
|
|
int main() {
|
|
int main() {
|
|
@@ -48,6 +76,10 @@ int main() {
|
|
|
assert(version > 0);
|
|
assert(version > 0);
|
|
|
SPDLOG_INFO("Loaded OpenGL {}.{}", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
|
|
SPDLOG_INFO("Loaded OpenGL {}.{}", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
|
|
|
|
|
|
|
|
|
|
+ // enable color blending
|
|
|
|
|
+ glEnable(GL_BLEND);
|
|
|
|
|
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
+
|
|
|
#ifndef NDEBUG
|
|
#ifndef NDEBUG
|
|
|
// log opengl error
|
|
// log opengl error
|
|
|
glEnable(GL_DEBUG_OUTPUT);
|
|
glEnable(GL_DEBUG_OUTPUT);
|
|
@@ -73,6 +105,31 @@ int main() {
|
|
|
cuInit(0);
|
|
cuInit(0);
|
|
|
create_cuda_context(&cuda_ctx);
|
|
create_cuda_context(&cuda_ctx);
|
|
|
|
|
|
|
|
|
|
+ // for debug; setup NDI
|
|
|
|
|
+ auto ref_cam_trans_left = Eigen::Translation3d(0.1829, -38.3006, -34.2251) *
|
|
|
|
|
+ Eigen::Quaterniond(0.3623, 0.6095, 0.3499, -0.6122);
|
|
|
|
|
+ auto ref_cam_trans_right = Eigen::Translation3d(1.0799, -39.7982, -94.8817) *
|
|
|
|
|
+ Eigen::Quaterniond(0.3669, 0.6074, 0.3504, -0.6113);
|
|
|
|
|
+
|
|
|
|
|
+ CombinedApi capi;
|
|
|
|
|
+ ret = capi.connect("10.0.0.5");
|
|
|
|
|
+ assert(ret == 0);
|
|
|
|
|
+ ret = capi.initialize();
|
|
|
|
|
+ assert(ret == 0);
|
|
|
|
|
+ int cam_port, tool_port;
|
|
|
|
|
+ tool_port = capi.portHandleRequest();
|
|
|
|
|
+ capi.loadSromToPort("/home/tpx/data/roms/GlassProbe_4Ball_3ST.rom", tool_port);
|
|
|
|
|
+ cam_port = capi.portHandleRequest();
|
|
|
|
|
+ capi.loadSromToPort("/home/tpx/data/roms/Glass_4Ball_1.rom", cam_port);
|
|
|
|
|
+ auto portHandles = capi.portHandleSearchRequest(PortHandleSearchRequestOption::NotInit);
|
|
|
|
|
+ for (auto &handler: portHandles) {
|
|
|
|
|
+ ret = capi.portHandleInitialize(handler.getPortHandle());
|
|
|
|
|
+ assert(ret == 0);
|
|
|
|
|
+ ret = capi.portHandleEnable(handler.getPortHandle());
|
|
|
|
|
+ assert(ret == 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ capi.startTracking();
|
|
|
|
|
+
|
|
|
// working staffs
|
|
// working staffs
|
|
|
stereo_camera camera;
|
|
stereo_camera camera;
|
|
|
texture_renderer tex_renderer;
|
|
texture_renderer tex_renderer;
|
|
@@ -85,12 +142,53 @@ int main() {
|
|
|
video_encoder encoder;
|
|
video_encoder encoder;
|
|
|
encoder.initialize();
|
|
encoder.initialize();
|
|
|
|
|
|
|
|
|
|
+ auto left_cam_info = augment_renderer::camera_intrinsics{
|
|
|
|
|
+ .focal_length= 8,
|
|
|
|
|
+ .view_angle = 47.6525,
|
|
|
|
|
+ .pixel_size = 0.00345,
|
|
|
|
|
+ .window_center = {
|
|
|
|
|
+ .x = 1.0 * (1238.96436323518 - 1224) / 1224,
|
|
|
|
|
+ .y = -1.0 * (1011.68988239492 - 1024) / 1024
|
|
|
|
|
+ },
|
|
|
|
|
+ .distort = {
|
|
|
|
|
+ .k1 = -0.0716117335673421,
|
|
|
|
|
+ .k2 = 0.0899896700761875
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ auto right_cam_info = augment_renderer::camera_intrinsics{
|
|
|
|
|
+ .focal_length= 8,
|
|
|
|
|
+ .view_angle = 47.6525,
|
|
|
|
|
+ .pixel_size = 0.00345,
|
|
|
|
|
+ .window_center = {
|
|
|
|
|
+ .x = 1.0 * (1238.97798867909 - 1224) / 1224,
|
|
|
|
|
+ .y = -1.0 * (1000.55305718163 - 1024) / 1024
|
|
|
|
|
+ },
|
|
|
|
|
+ .distort = {
|
|
|
|
|
+ .k1 = -0.0716625513187931,
|
|
|
|
|
+ .k2 = 0.0979453312950340
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ auto vtk_external = vtkSmartPointer<ExternalVTKWidget>::New();
|
|
|
|
|
+
|
|
|
augment_renderer left_ar, right_ar;
|
|
augment_renderer left_ar, right_ar;
|
|
|
- left_ar.initialize(&tex_renderer);
|
|
|
|
|
- right_ar.initialize(&tex_renderer);
|
|
|
|
|
|
|
+ left_ar.initialize(&tex_renderer, &left_cam_info);
|
|
|
|
|
+ right_ar.initialize(&tex_renderer, &right_cam_info);
|
|
|
left_ar.set_background(&camera.left_rgb_image);
|
|
left_ar.set_background(&camera.left_rgb_image);
|
|
|
right_ar.set_background(&camera.right_rgb_image);
|
|
right_ar.set_background(&camera.right_rgb_image);
|
|
|
|
|
|
|
|
|
|
+ // for debug; setup VTK scene
|
|
|
|
|
+ vtkNew<vtkSTLReader> reader;
|
|
|
|
|
+ reader->SetFileName("/home/tpx/data/stls/GlassProbe_4Ball_3.STL");
|
|
|
|
|
+ vtkNew<vtkPolyDataMapper> mapper;
|
|
|
|
|
+ mapper->SetInputConnection(reader->GetOutputPort());
|
|
|
|
|
+ vtkNew<vtkActor> actor;
|
|
|
|
|
+ vtkNew<vtkMatrix4x4> tool_matrix;
|
|
|
|
|
+ actor->SetUserMatrix(tool_matrix);
|
|
|
|
|
+ actor->SetMapper(mapper);
|
|
|
|
|
+ left_ar.add_model(actor);
|
|
|
|
|
+ right_ar.add_model(actor);
|
|
|
|
|
+
|
|
|
int camera_fps = default_camera_fps;
|
|
int camera_fps = default_camera_fps;
|
|
|
float exposure_time_ms = default_camera_exposure_time_ms;
|
|
float exposure_time_ms = default_camera_exposure_time_ms;
|
|
|
float analog_gain = default_camera_analog_gain;
|
|
float analog_gain = default_camera_analog_gain;
|
|
@@ -112,14 +210,14 @@ int main() {
|
|
|
ImGui_ImplGlfw_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
|
ImGui::NewFrame();
|
|
ImGui::NewFrame();
|
|
|
|
|
|
|
|
- ImGui::ShowDemoWindow();
|
|
|
|
|
|
|
+ // extra actions to make consistency
|
|
|
|
|
+ if (!camera.is_capturing() && encoder.is_encoding()) {
|
|
|
|
|
+ encoder.stop_encode();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (ImGui::Begin("Remote AR Control")) {
|
|
|
|
|
|
|
+ // ImGui::ShowDemoWindow();
|
|
|
|
|
|
|
|
- // extra actions to make consistency
|
|
|
|
|
- if (!camera.is_capturing() && encoder.is_encoding()) {
|
|
|
|
|
- encoder.stop_encode();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (ImGui::Begin("Remote AR Control")) {
|
|
|
|
|
|
|
|
// camera control
|
|
// camera control
|
|
|
if (ImGui::CollapsingHeader("Camera")) {
|
|
if (ImGui::CollapsingHeader("Camera")) {
|
|
@@ -194,6 +292,7 @@ int main() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ ImGui::SeparatorText("Configs");
|
|
|
if (encoder.is_encoding()) {
|
|
if (encoder.is_encoding()) {
|
|
|
ImGui::BeginDisabled();
|
|
ImGui::BeginDisabled();
|
|
|
}
|
|
}
|
|
@@ -241,6 +340,22 @@ int main() {
|
|
|
ImGui::End();
|
|
ImGui::End();
|
|
|
ImGui::Render();
|
|
ImGui::Render();
|
|
|
|
|
|
|
|
|
|
+ // for debug; NDI work
|
|
|
|
|
+ auto tool_data = capi.getTrackingDataBX();
|
|
|
|
|
+ for (auto &tool: tool_data) {
|
|
|
|
|
+ auto port = tool.transform.toolHandle;
|
|
|
|
|
+ if (port == 65535) continue;
|
|
|
|
|
+ if (tool.transform.isMissing()) continue;
|
|
|
|
|
+ auto trans = port_info_to_transform(tool.transform);
|
|
|
|
|
+ if (port == cam_port) {
|
|
|
|
|
+ left_ar.set_camera_pose(trans * ref_cam_trans_left);
|
|
|
|
|
+ right_ar.set_camera_pose(trans * ref_cam_trans_right);
|
|
|
|
|
+ } else if (port == tool_port) {
|
|
|
|
|
+ transform_to_vtk_matrix(trans, tool_matrix);
|
|
|
|
|
+ actor->Modified();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
std::chrono::high_resolution_clock::time_point start_time;
|
|
std::chrono::high_resolution_clock::time_point start_time;
|
|
|
if (camera.is_capturing()) {
|
|
if (camera.is_capturing()) {
|
|
|
camera.retrieve_raw_images();
|
|
camera.retrieve_raw_images();
|