Skip to content

Commit 5a23d1d

Browse files
committed
viewer: draw 3D axes
1 parent c5953c0 commit 5a23d1d

File tree

3 files changed

+67
-25
lines changed

3 files changed

+67
-25
lines changed

CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ ENDIF()
2929
# List configuration options
3030
SET(OpenMVS_BUILD_TOOLS ON CACHE BOOL "Build example applications")
3131
SET(OpenMVS_USE_OPENMP ON CACHE BOOL "Enable OpenMP library")
32-
SET(OpenMVS_USE_OPENGL ON CACHE BOOL "Enable OpenGL library")
3332
SET(OpenMVS_USE_BREAKPAD ON CACHE BOOL "Enable BreakPad library")
3433
SET(OpenMVS_USE_PYTHON ON CACHE BOOL "Enable Python library bindings")
3534
SET(OpenMVS_USE_CERES OFF CACHE BOOL "Enable CERES optimization library")
@@ -48,13 +47,13 @@ IF(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{VCPKG_ROOT})
4847
SET(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
4948
ENDIF()
5049
ENDIF()
50+
IF(OpenMVS_USE_CUDA)
51+
LIST(APPEND VCPKG_MANIFEST_FEATURES "cuda")
52+
ENDIF()
5153
IF(OpenMVS_USE_PYTHON)
5254
LIST(APPEND VCPKG_MANIFEST_FEATURES "python")
5355
SET(PARTIAL_BUILD_SHARED_LIBS ON)
5456
ENDIF()
55-
IF(OpenMVS_USE_CUDA)
56-
LIST(APPEND VCPKG_MANIFEST_FEATURES "cuda")
57-
ENDIF()
5857

5958
# Name of the project.
6059
#

apps/Viewer/Scene.cpp

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ bool Scene::Init(const cv::Size& size, LPCTSTR windowName, LPCTSTR fileName, LPC
186186
return false;
187187
if (!window.Init(size, windowName))
188188
return false;
189-
if (gladLoadGL() == 0)
189+
if (gladLoadGL() == GL_FALSE)
190190
return false;
191191
VERBOSE("OpenGL: %s %s", glGetString(GL_RENDERER), glGetString(GL_VERSION));
192192
name = windowName;
@@ -197,10 +197,10 @@ bool Scene::Init(const cv::Size& size, LPCTSTR windowName, LPCTSTR fileName, LPC
197197
glEnable(GL_DEPTH_TEST);
198198
glClearColor(0.f, 0.5f, 0.9f, 1.f);
199199

200-
static const float light0_ambient[] = {0.1f, 0.1f, 0.1f, 1.0f};
201-
static const float light0_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
202-
static const float light0_position[] = {0.0f, 0.0f, 1000.0f, 0.0f};
203-
static const float light0_specular[] = {0.4f, 0.4f, 0.4f, 1.0f};
200+
static const float light0_ambient[] = {0.1f, 0.1f, 0.1f, 1.f};
201+
static const float light0_diffuse[] = {1.f, 1.f, 1.f, 1.f};
202+
static const float light0_position[] = {0.f, 0.f, 1000.f, 0.f};
203+
static const float light0_specular[] = {0.4f, 0.4f, 0.4f, 1.f};
204204

205205
glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
206206
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
@@ -575,14 +575,6 @@ void Scene::Draw()
575575
// change coordinates system to the camera space
576576
glPushMatrix();
577577
glMultMatrixd((GLdouble*)TransL2W((const Matrix3x3::EMat)camera.R, -(const Point3::EVec)camera.C).data());
578-
glPointSize(window.pointSize+1.f);
579-
glDisable(GL_TEXTURE_2D);
580-
// draw camera position and image center
581-
glBegin(GL_POINTS);
582-
glColor3f(1,0,0); glVertex3f(0,0,0); // camera position
583-
glColor3f(0,1,0); glVertex3f(0,0,(float)scaleFocal); // image center
584-
glColor3f(0,0,1); glVertex3d((0.5*imageData.width-pp.x)/focal, cy, scaleFocal); // image up
585-
glEnd();
586578
// draw image thumbnail
587579
const bool bSelectedImage(idx == window.camera.currentCamID);
588580
if (bSelectedImage) {
@@ -615,7 +607,9 @@ void Scene::Draw()
615607
}
616608
}
617609
}
610+
glDisable(GL_TEXTURE_2D);
618611
// draw camera frame
612+
glLineWidth(2.f);
619613
glColor3f(bSelectedImage ? 0.f : 1.f, 1.f, 0.f);
620614
glBegin(GL_LINES);
621615
glVertex3d(0,0,0); glVertex3dv(ic1.ptr());
@@ -627,6 +621,13 @@ void Scene::Draw()
627621
glVertex3dv(ic3.ptr()); glVertex3dv(ic4.ptr());
628622
glVertex3dv(ic4.ptr()); glVertex3dv(ic1.ptr());
629623
glEnd();
624+
// draw camera position and image center
625+
glPointSize(window.pointSize+3.f);
626+
glBegin(GL_POINTS);
627+
glColor3f(1,0,0); glVertex3f(0,0,0); // camera position
628+
glColor3f(0,1,0); glVertex3f(0,0,(float)scaleFocal); // image center
629+
glColor3f(0,0,1); glVertex3d((0.5*imageData.width-pp.x)/focal, cy, scaleFocal); // image up
630+
glEnd();
630631
// restore coordinate system
631632
glPopMatrix();
632633
// render image visibility info
@@ -652,6 +653,7 @@ void Scene::Draw()
652653
}
653654
// render camera trajectory
654655
if (window.bRenderCameraTrajectory && ptrPrevC) {
656+
glLineWidth(1.f);
655657
glBegin(GL_LINES);
656658
glColor3f(1.f,0.5f,0.f);
657659
glVertex3dv(ptrPrevC->ptr());
@@ -674,6 +676,7 @@ void Scene::Draw()
674676
glEnd();
675677
if (window.bRenderViews && window.selectionType == Window::SEL_POINT) {
676678
if (!scene.pointcloud.pointViews.empty()) {
679+
glLineWidth(1.f);
677680
glBegin(GL_LINES);
678681
const MVS::PointCloud::ViewArr& views = scene.pointcloud.pointViews[(MVS::PointCloud::Index)window.selectionIdx];
679682
ASSERT(!views.empty());
@@ -691,6 +694,7 @@ void Scene::Draw()
691694
// render oriented-bounding-box
692695
if (!obbPoints.empty()) {
693696
glDepthMask(GL_FALSE);
697+
glLineWidth(2.f);
694698
glBegin(GL_LINES);
695699
glColor3f(0.5f,0.1f,0.8f);
696700
for (IDX i=0; i<obbPoints.size(); i+=2) {
@@ -700,6 +704,48 @@ void Scene::Draw()
700704
glEnd();
701705
glDepthMask(GL_TRUE);
702706
}
707+
// draw coordinate axes
708+
{
709+
constexpr int axisWindowSize(200);
710+
constexpr float axisLength(1.5f);
711+
GLfloat matrix[16];
712+
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
713+
glPushMatrix();
714+
glPushAttrib(GL_VIEWPORT_BIT);
715+
// draw at bottom-right corner and scale down
716+
glViewport(window.size.width - axisWindowSize, 0, axisWindowSize, axisWindowSize);
717+
glLoadIdentity();
718+
glTranslatef(0.f, 0.f, -3.f);
719+
matrix[12] = matrix[13] = matrix[14] = 0.f;
720+
glMultMatrixf(matrix);
721+
glLineWidth(4.f);
722+
// X axis (Red)
723+
glBegin(GL_LINES);
724+
glColor3f(1.f, 0.f, 0.f);
725+
glVertex3f(0.f, 0.f, 0.f);
726+
glVertex3f(axisLength, 0.f, 0.f);
727+
// Y axis (Green)
728+
glColor3f(0.f, 1.f, 0.f);
729+
glVertex3f(0.f, 0.f, 0.f);
730+
glVertex3f(0.f, axisLength, 0.f);
731+
// Z axis (Blue)
732+
glColor3f(0.f, 0.f, 1.f);
733+
glVertex3f(0.f, 0.f, 0.f);
734+
glVertex3f(0.f, 0.f, axisLength);
735+
glEnd();
736+
// draw small spheres at axis ends for better visibility
737+
glPointSize(10.f);
738+
glBegin(GL_POINTS);
739+
glColor3f(1.f, 0.f, 0.f);
740+
glVertex3f(axisLength, 0.f, 0.f);
741+
glColor3f(0.f, 1.f, 0.f);
742+
glVertex3f(0.f, axisLength, 0.f);
743+
glColor3f(0.f, 0.f, 1.f);
744+
glVertex3f(0.f, 0.f, axisLength);
745+
glEnd();
746+
glPopAttrib();
747+
glPopMatrix();
748+
}
703749
glfwSwapBuffers(window.GetWindow());
704750
}
705751

vcpkg.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,17 @@
2929
"zlib"
3030
],
3131
"features": {
32-
"python": {
33-
"description": "Python bindings for OpenMVS",
34-
"dependencies": [
35-
"boost-python"
36-
]
37-
},
3832
"cuda": {
3933
"description": "CUDA support for OpenMVS",
4034
"dependencies": [
4135
"cuda"
4236
]
4337
},
44-
"openmp": {
45-
"description": "OpenMP support for OpenMVS"
38+
"python": {
39+
"description": "Python bindings for OpenMVS",
40+
"dependencies": [
41+
"boost-python"
42+
]
4643
}
4744
}
4845
}

0 commit comments

Comments
 (0)