Skip to content

Commit

Permalink
call clear buffers at right place
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Jan 17, 2025
1 parent af9184c commit 49020f9
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 35 deletions.
18 changes: 9 additions & 9 deletions 3rd_party/QGLViewer/QGLViewer/qglviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,6 @@ void QGLViewer::initializeGL() {
setForegroundColor(QColor(180, 180, 180));
setBackgroundColor(QColor(51, 51, 51));

// Clear the buffer where we're going to draw
if (format().stereo()) {
glDrawBuffer(GL_BACK_RIGHT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawBuffer(GL_BACK_LEFT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} else
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Calls user defined method. Default emits a signal.
init();

Expand All @@ -295,6 +286,15 @@ camera in the world coordinate system. \arg draw() (or fastDraw() when the
camera is manipulated) : main drawing method. Should be overloaded. \arg
postDraw() : display of visual hints (world axis, FPS...) */
void QGLViewer::paintGL() {
// Clear the buffer where we're going to draw
if (format().stereo()) {
glDrawBuffer(GL_BACK_RIGHT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawBuffer(GL_BACK_LEFT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} else
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

if (displaysInStereo()) {
for (int view = 1; view >= 0; --view) {
// Clears screen, set model view matrix with shifted matrix for ith buffer
Expand Down
15 changes: 12 additions & 3 deletions 3rd_party/SiftGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ if(NOT IS_MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()

set (OpenGL_GL_PREFERENCE GLVND)
# prefer GLVND
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
message(STATUS "OpenGL libraries: ${OPENGL_LIBRARIES}")
if (OPENGL_opengl_LIBRARY)
set(FOUND_GL_LIBRARIES ${OPENGL_opengl_LIBRARY})
else ()
set(FOUND_GL_LIBRARIES ${OPENGL_gl_LIBRARY})
endif ()
if (OPENGL_glx_LIBRARY)
list(APPEND FOUND_GL_LIBRARIES ${OPENGL_glx_LIBRARY})
endif ()
message(STATUS "OpenGL libraries: ${FOUND_GL_LIBRARIES}")

add_definitions("-DSIFTGPU_NO_DEVIL")

Expand Down Expand Up @@ -52,7 +61,7 @@ endif()

target_link_libraries(3rd_sift_gpu
${SIFT_GPU_LIBRARIES}
${OPENGL_LIBRARIES}
${FOUND_GL_LIBRARIES}
)

set(GLEW_INCLUDE_DIR ${MVSTUDIO_THIRD_PARTY}/glew/include)
Expand Down
4 changes: 1 addition & 3 deletions 3rd_party/SiftGPU/GlobalUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ using std::cout;

#endif

#include "LiteWindow.h"

#include "GL/glew.h"
#include "GlobalUtil.h"

#if defined(__APPLE__)
Expand All @@ -56,6 +53,7 @@ using std::cout;
#include <GL/glu.h>
#endif

#include "LiteWindow.h"
//
int GlobalParam::_verbose = 1;
int GlobalParam::_timingS = 1; //print out information of each step
Expand Down
2 changes: 1 addition & 1 deletion MVStudio/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void MainWindow::setBackgroundColor() {
if (color.isValid() && mainCanvas_) {
mainCanvas_->makeCurrent();
mainCanvas_->setBackgroundColor(color);

mainCanvas_->doneCurrent();
mainCanvas_->update_graphics();
}
}
Expand Down
43 changes: 29 additions & 14 deletions libs/algo/image_matching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../basic/progress.h"
#include "../basic/logger.h"
#include "../basic/stop_watch.h"
#include "../opengl/opengl_info.h"

//include the header files for SiftGPU and SiftMatchGPU
#include "../../3rd_party/SiftGPU/SiftGPU.h"
Expand Down Expand Up @@ -43,14 +44,16 @@ void ImageMatching::apply() {

image_features.clear();
StopWatch w;
ogf_check_gl;
Logger::out(title()) << "extracting key points..." << std::endl;
extract_key_points();
Logger::out(title()) << "done. time: " << w.elapsed() << std::endl;

ogf_check_gl;
w.start();
Logger::out(title()) << "matching the images..." << std::endl;
match_key_points();
Logger::out(title()) << "done. time: " << w.elapsed() << std::endl;
ogf_check_gl;
}


Expand All @@ -67,15 +70,17 @@ void ImageMatching::extract_key_points() {
return;
}

ogf_check_gl;
SiftGPU* sift = CreateNewSiftGPU();
ogf_check_gl;
//Create a context for computation, and SiftGPU will be initialized automatically
//The same context can be used by SiftMatchGPU.
// Liangliang: I already have a OpenGL context. Just use it.
if (sift->CreateContextGL() == SiftGPU::SIFTGPU_NOT_SUPPORTED) {
Logger::err(title()) << "SiftGPU not supported" << std::endl;
return;
}

ogf_check_gl;
char * argv[] = { "-fo", "-1", "-v", "0", "-tc2", "7680", "-b", "-nomc" };//
//-fo -1 staring from -1 octave
//-v 1 only print out # feature and overall time
Expand All @@ -85,7 +90,7 @@ void ImageMatching::extract_key_points() {
int argc = sizeof(argv)/sizeof(char*);
sift->ParseParam(argc, argv);
//sift->SetMaxDimension(8000);

ogf_check_gl;
///////////////////////////////////////////////////////////////////////
//Only the following parameters can be changed after initialization (by calling ParseParam).
//-dw, -ofix, -ofix-not, -fo, -unn, -maxd, -b
Expand All @@ -103,25 +108,25 @@ void ImageMatching::extract_key_points() {
}
if (project_->images[i].ignored)
continue;

ogf_check_gl;
//Create a context for computation, and SiftGPU will be initialized automatically
//The same context can be used by SiftMatchGPU.
// Liangliang: I already have a OpenGL context. Just use it.
if (sift->CreateContextGL() == SiftGPU::SIFTGPU_NOT_SUPPORTED) {
Logger::err(title()) << "SiftGPU not supported" << std::endl;
break;
}

ogf_check_gl;
const std::string& name = project_->images[i].file;
if (!sift->RunSIFT(name.c_str())) {
Logger::warn(title()) << "processing image \'" << FileUtils::simple_name(name) << "\' failed" << std::endl;
project_->set_ignore_image(name, true);
continue;
}

ogf_check_gl;
std::string sift_file = project_->sfm_keys_dir + '/' + FileUtils::base_name(name) + ".key";
sift->SaveSIFT(sift_file.c_str());

ogf_check_gl;
int image_width, image_height;
sift->GetImageDimension(image_width, image_height);
float focal_length_in_pixels = 1.2f * std::max(image_width, image_height);
Expand All @@ -131,7 +136,7 @@ void ImageMatching::extract_key_points() {

int num = sift->GetFeatureNum(); // get feature count
Logger::out(title()) << FileUtils::simple_name(name) << ": " << num << " key points" << std::endl;

ogf_check_gl;
std::vector<SiftGPU::SiftKeypoint> keys;
std::vector<float> descriptors;

Expand All @@ -141,17 +146,20 @@ void ImageMatching::extract_key_points() {
//reading back feature vectors is faster than writing files
//if you don't need keys or descriptors, just put NULLs here
sift->GetFeatureVector(&keys[0], &descriptors[0]);
//this can be used to write your own sift file.
//this can be used to write your own sift file.
ogf_check_gl;
}

ImageFeature feature;
ogf_check_gl;
feature.keys = keys;
feature.descriptors = descriptors;
image_features.push_back(feature);

ogf_check_gl;
progress.next();
}

ogf_check_gl;
delete sift;
}

Expand All @@ -169,9 +177,9 @@ void ImageMatching::match_key_points() {
Logger::err(title()) << "could not write matches file \'" << match_table_file << "\'" << std::endl;
return;
}

ogf_check_gl;
SiftMatchGPU* matcher = new SiftMatchGPU;

ogf_check_gl;
//Before initialization, you can choose between GLSL, and CUDA(if compiled).
//matcher->SetLanguage(SiftMatchGPU::SIFTMATCH_CUDA); // +i for the (i+1)-th device

Expand All @@ -189,14 +197,16 @@ void ImageMatching::match_key_points() {
int num1 = (int)keys1.size();
if (num1 == 0)
continue;


ogf_check_gl;
for ( int j = i+1; j < num; ++j) {
const std::vector<SiftGPU::SiftKeypoint>& keys2 = image_features[j].keys;
const std::vector<float>& descriptors2 = image_features[j].descriptors;
int num2 = (int)keys2.size();
if (num2 == 0)
continue;

ogf_check_gl;
if (progress.is_canceled()) {
delete matcher;
return;
Expand All @@ -209,18 +219,20 @@ void ImageMatching::match_key_points() {
Logger::err(title()) << "SiftGPU not supported" << std::endl;
break;
}
ogf_check_gl;

//Set descriptors to match, the first argument must be either 0 or 1
//if you want to use more than 4096 or less than 4096
//call matcher->SetMaxSift() to change the limit before calling setdescriptor
matcher->SetDescriptors(0, num1, &descriptors1[0]); //image 1
matcher->SetDescriptors(1, num2, &descriptors2[0]); //image 2

ogf_check_gl;
//match and get result.
int(*match_buf)[2] = new int[num1][2];
//use the default thresholds. Check the declaration in SiftGPU.h
int num_match = matcher->GetSiftMatch(num1, match_buf);
output << i << " " << j << std::endl << num_match << std::endl;
ogf_check_gl;

//enumerate all the feature matches
for (int k = 0; k < num_match; ++k) {
Expand All @@ -241,11 +253,14 @@ void ImageMatching::match_key_points() {
output << std::endl;

delete[] match_buf;
ogf_check_gl;

progress.next();
}
}

image_features.clear();
ogf_check_gl;
delete matcher;
ogf_check_gl;
}
2 changes: 1 addition & 1 deletion libs/opengl/opengl_info.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "opengl_info.h"
#include <iostream>

#include "GL/glew.h"

static const std::string err_msg = "error(null_string)";

Expand Down
4 changes: 0 additions & 4 deletions libs/opengl/opengl_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
#ifndef _OPENGL_GLINFORMATION_H_
#define _OPENGL_GLINFORMATION_H_

#include "GL/glew.h"

#include <string>



#ifndef NDEBUG
#define ogf_check_gl {\
GLInfo::check_gl(__FILE__, __LINE__) ;\
Expand Down

0 comments on commit 49020f9

Please sign in to comment.