Skip to content

Commit 04b792e

Browse files
committed
viewer: add UI camera size
1 parent ff890b1 commit 04b792e

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

apps/Viewer/Renderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ void Renderer::UploadCameras(const Window& window) {
748748
return;
749749

750750
// Generate camera frustum geometry
751-
const float depth = window.GetCamera().GetSceneSize().norm() * 0.01f; // Camera scale factor
751+
const float depth = window.GetCamera().GetSceneSize().norm() * window.cameraSize;
752752
cameraIndexCount = 0;
753753
std::vector<float> cameraVertices;
754754
std::vector<float> cameraColors;
@@ -789,7 +789,7 @@ void Renderer::UploadImageOverlays(const Window& window) {
789789
return;
790790

791791
// Calculate camera frustum depth (same as used in UploadCameras)
792-
const float depth = window.GetCamera().GetSceneSize().norm() * 0.01f;
792+
const float depth = window.GetCamera().GetSceneSize().norm() * window.cameraSize;
793793

794794
// Collect all overlay geometry for images with valid textures
795795
std::vector<float> allVertices;

apps/Viewer/UI.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ void UI::ShowMainMenuBar(Window& window) {
230230
ImGui::MenuItem("Scene Info", nullptr, &showSceneInfo);
231231
ImGui::MenuItem("Camera Info", nullptr, &showCameraInfoDialog);
232232
ImGui::MenuItem("Camera Controls", nullptr, &showCameraControls);
233-
ImGui::MenuItem("Selection Controls", nullptr, &showSelectionControls);
233+
ImGui::MenuItem("Selection Dialog", nullptr, &showSelectionDialog);
234234
ImGui::MenuItem("Render Settings", nullptr, &showRenderSettings);
235235
ImGui::MenuItem("Performance Overlay", nullptr, &showPerformanceOverlay);
236236
ImGui::MenuItem("Viewport Overlay", nullptr, &showViewportOverlay);
@@ -376,6 +376,10 @@ void UI::ShowCameraControls(Window& window) {
376376
window.RequestRedraw();
377377
if (ImGui::IsItemHovered())
378378
ImGui::SetTooltip("Toggle camera frustum display (C key)");
379+
if (ImGui::SliderFloat("Camera Size", &window.cameraSize, 0.0001f, 0.1f, "%.4f"))
380+
window.GetRenderer().UploadCameras(window);
381+
if (ImGui::IsItemHovered())
382+
ImGui::SetTooltip("Adjust camera size");
379383

380384
// Arcball sensitivity controls (only show when in arcball mode)
381385
if (window.GetControlMode() == Window::CONTROL_ARCBALL) {
@@ -828,6 +832,7 @@ void UI::ShowHelpDialog() {
828832
ImGui::Text(" Single click Select point/face/camera");
829833
ImGui::Text(" Double-click Focus on selection");
830834
ImGui::Text(" (or enter camera view for cameras)");
835+
ImGui::Text(" Selection Dialog Select point/face/camera by index");
831836
ImGui::Separator();
832837

833838
// Selection Tools
@@ -1065,6 +1070,24 @@ void UI::ShowCameraInfoDialog(Window& window) {
10651070
window.selectedNeighborCamera == NO_ID ? "NA" : String::FormatString("%.2f", R2D(ACOS(ComputeAngle(
10661071
mvs_scene.images[images[window.selectionIdx].idx].camera.Direction().ptr(),
10671072
mvs_scene.images[images[window.selectedNeighborCamera].idx].camera.Direction().ptr())))).c_str());
1073+
if (window.selectedNeighborCamera != NO_ID && window.selectionType == Window::SEL_CAMERA) {
1074+
// Compute and display relative pose if a neighbor camera is selected
1075+
const Image& mainView = images[window.selectionIdx];
1076+
const Image& neighView = images[window.selectedNeighborCamera];
1077+
const MVS::Camera& camMain = mvs_scene.images[mainView.idx].camera;
1078+
const MVS::Camera& camNeigh = mvs_scene.images[neighView.idx].camera;
1079+
RMatrix poseR;
1080+
CMatrix poseC;
1081+
ComputeRelativePose(camMain.R, camMain.C, camNeigh.R, camNeigh.C, poseR, poseC);
1082+
Point3 eulerAngles;
1083+
poseR.GetRotationAnglesZYX(eulerAngles.x, eulerAngles.y, eulerAngles.z);
1084+
ImGui::Separator();
1085+
ImGui::Text("Relative Pose (Neighbor wrt Main)");
1086+
ImGui::Text(" Position: %.3g, %.3g, %.3g (%.3g distance)",
1087+
poseC.x, poseC.y, poseC.z, norm(poseC));
1088+
ImGui::Text(" Rotation (ZYX): %.1f°, %.1f°, %.1f°",
1089+
R2D(eulerAngles.x), R2D(eulerAngles.y), R2D(eulerAngles.z));
1090+
}
10681091
if (!imageData.neighbors.empty()) {
10691092
// Create a scrollable region for the neighbors list
10701093
ImGui::BeginChild("NeighborsScrollRegion", ImVec2(0, 220), true, ImGuiWindowFlags_HorizontalScrollbar);
@@ -1520,7 +1543,7 @@ void UI::ShowSelectionOverlay(const Window& window) {
15201543
ImGui::Text(" image size: %ux%u", imageData.width, imageData.height);
15211544
ImGui::Text(" intrinsics: fx %.1f, fy %.1f", camera.K(0, 0), camera.K(1, 1));
15221545
ImGui::Text(" cx %.1f, cy %.1f", camera.K(0, 2), camera.K(1, 2));
1523-
ImGui::Text(" position: %.3f, %.3f, %.3f", camera.C.x, camera.C.y, camera.C.z);
1546+
ImGui::Text(" position: %.3g, %.3g, %.3g", camera.C.x, camera.C.y, camera.C.z);
15241547
ImGui::Text(" rotation: %.1f°, %.1f°, %.1f°",
15251548
R2D(eulerAngles.x), R2D(eulerAngles.y), R2D(eulerAngles.z));
15261549
ImGui::Text(" avg depth: %.2g", imageData.avgDepth);
@@ -1684,6 +1707,9 @@ void SettingsReadLine(ImGuiContext*, ImGuiSettingsHandler* handler, void* entry,
16841707
else if (sscanf(line, "ClearColor=%f,%f,%f,%f", &x, &y, &z, &w) == 4) {
16851708
window.clearColor = Eigen::Vector4f(x, y, z, w);
16861709
}
1710+
else if (sscanf(line, "CameraSize=%f", &x) == 1) {
1711+
window.cameraSize = x;
1712+
}
16871713
else if (sscanf(line, "PointSize=%f", &x) == 1) {
16881714
window.pointSize = x;
16891715
}
@@ -1729,6 +1755,7 @@ void SettingsWriteAll(ImGuiContext*, ImGuiSettingsHandler* handler, ImGuiTextBuf
17291755
buf->appendf("ClearColor=%f,%f,%f,%f\n",
17301756
window.clearColor[0], window.clearColor[1],
17311757
window.clearColor[2], window.clearColor[3]);
1758+
buf->appendf("CameraSize=%f\n", window.cameraSize);
17321759
buf->appendf("PointSize=%f\n", window.pointSize);
17331760
buf->appendf("EstimateSfMNormals=%d\n",
17341761
window.GetScene().estimateSfMNormals ? 1 : 0);

apps/Viewer/Window.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Window::Window()
5757
, selectedNeighborCamera(NO_ID)
5858
, clearColor(0.3f, 0.4f, 0.5f, 1.f)
5959
, minViews(2)
60+
, cameraSize(0.01f)
6061
, pointSize(3.f)
6162
, pointNormalLength(0.02f)
6263
, imageOverlayOpacity(0.5f)

apps/Viewer/Window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class Window {
100100
// Settings
101101
Eigen::Vector4f clearColor;
102102
MVS::IIndex minViews;
103+
float cameraSize;
103104
float pointSize;
104105
float pointNormalLength;
105106
float imageOverlayOpacity;

0 commit comments

Comments
 (0)