Skip to content

Commit

Permalink
viewer: draw 3D axes
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcseacave committed Jan 5, 2025
1 parent c5953c0 commit 5a23d1d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 25 deletions.
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ ENDIF()
# List configuration options
SET(OpenMVS_BUILD_TOOLS ON CACHE BOOL "Build example applications")
SET(OpenMVS_USE_OPENMP ON CACHE BOOL "Enable OpenMP library")
SET(OpenMVS_USE_OPENGL ON CACHE BOOL "Enable OpenGL library")
SET(OpenMVS_USE_BREAKPAD ON CACHE BOOL "Enable BreakPad library")
SET(OpenMVS_USE_PYTHON ON CACHE BOOL "Enable Python library bindings")
SET(OpenMVS_USE_CERES OFF CACHE BOOL "Enable CERES optimization library")
Expand All @@ -48,13 +47,13 @@ IF(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{VCPKG_ROOT})
SET(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
ENDIF()
ENDIF()
IF(OpenMVS_USE_CUDA)
LIST(APPEND VCPKG_MANIFEST_FEATURES "cuda")
ENDIF()
IF(OpenMVS_USE_PYTHON)
LIST(APPEND VCPKG_MANIFEST_FEATURES "python")
SET(PARTIAL_BUILD_SHARED_LIBS ON)
ENDIF()
IF(OpenMVS_USE_CUDA)
LIST(APPEND VCPKG_MANIFEST_FEATURES "cuda")
ENDIF()

# Name of the project.
#
Expand Down
72 changes: 59 additions & 13 deletions apps/Viewer/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ bool Scene::Init(const cv::Size& size, LPCTSTR windowName, LPCTSTR fileName, LPC
return false;
if (!window.Init(size, windowName))
return false;
if (gladLoadGL() == 0)
if (gladLoadGL() == GL_FALSE)
return false;
VERBOSE("OpenGL: %s %s", glGetString(GL_RENDERER), glGetString(GL_VERSION));
name = windowName;
Expand All @@ -197,10 +197,10 @@ bool Scene::Init(const cv::Size& size, LPCTSTR windowName, LPCTSTR fileName, LPC
glEnable(GL_DEPTH_TEST);
glClearColor(0.f, 0.5f, 0.9f, 1.f);

static const float light0_ambient[] = {0.1f, 0.1f, 0.1f, 1.0f};
static const float light0_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
static const float light0_position[] = {0.0f, 0.0f, 1000.0f, 0.0f};
static const float light0_specular[] = {0.4f, 0.4f, 0.4f, 1.0f};
static const float light0_ambient[] = {0.1f, 0.1f, 0.1f, 1.f};
static const float light0_diffuse[] = {1.f, 1.f, 1.f, 1.f};
static const float light0_position[] = {0.f, 0.f, 1000.f, 0.f};
static const float light0_specular[] = {0.4f, 0.4f, 0.4f, 1.f};

glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
Expand Down Expand Up @@ -575,14 +575,6 @@ void Scene::Draw()
// change coordinates system to the camera space
glPushMatrix();
glMultMatrixd((GLdouble*)TransL2W((const Matrix3x3::EMat)camera.R, -(const Point3::EVec)camera.C).data());
glPointSize(window.pointSize+1.f);
glDisable(GL_TEXTURE_2D);
// draw camera position and image center
glBegin(GL_POINTS);
glColor3f(1,0,0); glVertex3f(0,0,0); // camera position
glColor3f(0,1,0); glVertex3f(0,0,(float)scaleFocal); // image center
glColor3f(0,0,1); glVertex3d((0.5*imageData.width-pp.x)/focal, cy, scaleFocal); // image up
glEnd();
// draw image thumbnail
const bool bSelectedImage(idx == window.camera.currentCamID);
if (bSelectedImage) {
Expand Down Expand Up @@ -615,7 +607,9 @@ void Scene::Draw()
}
}
}
glDisable(GL_TEXTURE_2D);
// draw camera frame
glLineWidth(2.f);
glColor3f(bSelectedImage ? 0.f : 1.f, 1.f, 0.f);
glBegin(GL_LINES);
glVertex3d(0,0,0); glVertex3dv(ic1.ptr());
Expand All @@ -627,6 +621,13 @@ void Scene::Draw()
glVertex3dv(ic3.ptr()); glVertex3dv(ic4.ptr());
glVertex3dv(ic4.ptr()); glVertex3dv(ic1.ptr());
glEnd();
// draw camera position and image center
glPointSize(window.pointSize+3.f);
glBegin(GL_POINTS);
glColor3f(1,0,0); glVertex3f(0,0,0); // camera position
glColor3f(0,1,0); glVertex3f(0,0,(float)scaleFocal); // image center
glColor3f(0,0,1); glVertex3d((0.5*imageData.width-pp.x)/focal, cy, scaleFocal); // image up
glEnd();
// restore coordinate system
glPopMatrix();
// render image visibility info
Expand All @@ -652,6 +653,7 @@ void Scene::Draw()
}
// render camera trajectory
if (window.bRenderCameraTrajectory && ptrPrevC) {
glLineWidth(1.f);
glBegin(GL_LINES);
glColor3f(1.f,0.5f,0.f);
glVertex3dv(ptrPrevC->ptr());
Expand All @@ -674,6 +676,7 @@ void Scene::Draw()
glEnd();
if (window.bRenderViews && window.selectionType == Window::SEL_POINT) {
if (!scene.pointcloud.pointViews.empty()) {
glLineWidth(1.f);
glBegin(GL_LINES);
const MVS::PointCloud::ViewArr& views = scene.pointcloud.pointViews[(MVS::PointCloud::Index)window.selectionIdx];
ASSERT(!views.empty());
Expand All @@ -691,6 +694,7 @@ void Scene::Draw()
// render oriented-bounding-box
if (!obbPoints.empty()) {
glDepthMask(GL_FALSE);
glLineWidth(2.f);
glBegin(GL_LINES);
glColor3f(0.5f,0.1f,0.8f);
for (IDX i=0; i<obbPoints.size(); i+=2) {
Expand All @@ -700,6 +704,48 @@ void Scene::Draw()
glEnd();
glDepthMask(GL_TRUE);
}
// draw coordinate axes
{
constexpr int axisWindowSize(200);
constexpr float axisLength(1.5f);
GLfloat matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
glPushMatrix();
glPushAttrib(GL_VIEWPORT_BIT);
// draw at bottom-right corner and scale down
glViewport(window.size.width - axisWindowSize, 0, axisWindowSize, axisWindowSize);
glLoadIdentity();
glTranslatef(0.f, 0.f, -3.f);
matrix[12] = matrix[13] = matrix[14] = 0.f;
glMultMatrixf(matrix);
glLineWidth(4.f);
// X axis (Red)
glBegin(GL_LINES);
glColor3f(1.f, 0.f, 0.f);
glVertex3f(0.f, 0.f, 0.f);
glVertex3f(axisLength, 0.f, 0.f);
// Y axis (Green)
glColor3f(0.f, 1.f, 0.f);
glVertex3f(0.f, 0.f, 0.f);
glVertex3f(0.f, axisLength, 0.f);
// Z axis (Blue)
glColor3f(0.f, 0.f, 1.f);
glVertex3f(0.f, 0.f, 0.f);
glVertex3f(0.f, 0.f, axisLength);
glEnd();
// draw small spheres at axis ends for better visibility
glPointSize(10.f);
glBegin(GL_POINTS);
glColor3f(1.f, 0.f, 0.f);
glVertex3f(axisLength, 0.f, 0.f);
glColor3f(0.f, 1.f, 0.f);
glVertex3f(0.f, axisLength, 0.f);
glColor3f(0.f, 0.f, 1.f);
glVertex3f(0.f, 0.f, axisLength);
glEnd();
glPopAttrib();
glPopMatrix();
}
glfwSwapBuffers(window.GetWindow());
}

Expand Down
13 changes: 5 additions & 8 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,17 @@
"zlib"
],
"features": {
"python": {
"description": "Python bindings for OpenMVS",
"dependencies": [
"boost-python"
]
},
"cuda": {
"description": "CUDA support for OpenMVS",
"dependencies": [
"cuda"
]
},
"openmp": {
"description": "OpenMP support for OpenMVS"
"python": {
"description": "Python bindings for OpenMVS",
"dependencies": [
"boost-python"
]
}
}
}

0 comments on commit 5a23d1d

Please sign in to comment.