Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cerr with cout where not necessary #16

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added 0
Empty file.
27 changes: 27 additions & 0 deletions program/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ INCLUDE_DIRECTORIES(
FIND_PACKAGE(Threads REQUIRED)
SET(PMVS_LIBRARIES ${PMVS_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})

# OPTIONS
OPTION(CIMG_USE_OPENMP "Enable OpenMP parallelization in cimg" ON)

# Eigen
SET( EIGEN3_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/thirdParty/Eigen )
SET( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${EIGEN3_INCLUDE_DIR}/cmake" )
Expand Down Expand Up @@ -95,6 +98,30 @@ IF(PMVS_USE_TIFF)
ENDIF(TIFF_FOUND)
ENDIF(PMVS_USE_TIFF)

# OpenMP
# ==============================================================================
# OpenMP detection
# ==============================================================================
IF(CIMG_USE_OPENMP)
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
OPTION(CIMG_USE_OPENMP "Use OpenMP for parallelization in cimg" ON)
ADD_DEFINITIONS(-DCIMG_USE_OPENMP)
IF (NOT MSVC)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# for those using the clang with OpenMP support
LIST(APPEND OPENMVG_LIBRARY_DEPENDENCIES iomp)
ELSE()
LIST(APPEND OPENMVG_LIBRARY_DEPENDENCIES gomp)
ENDIF()
ENDIF(NOT MSVC)
ENDIF(OPENMP_FOUND)
ELSE(CIMG_USE_OPENMP)
OPTION(OpenMVG_USE_OPENMP "Use OpenMP for parallelization in cimg" OFF)
UPDATE_CACHE_VARIABLE(CIMG_USE_OPENMP OFF)
REMOVE_DEFINITIONS(-DCIMG_USE_OPENMP)
ENDIF(CIMG_USE_OPENMP)

ADD_SUBDIRECTORY(base)
ADD_SUBDIRECTORY(main)
Expand Down
84 changes: 42 additions & 42 deletions program/base/cmvs/bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ void Cbundle::prep(const std::string prefix, const int imageThreshold,

char buffer[1024];
sprintf(buffer, "%sbundle.rd.out", prefix.c_str());
cerr << "Reading bundle..." << flush;
cout << "Reading bundle..." << flush;
readBundle(buffer);
cerr << endl;
cout << endl;

vector<int> images;
for (int c = 0; c < m_cnum; ++c)
Expand All @@ -71,9 +71,9 @@ void Cbundle::prep(const std::string prefix, const int imageThreshold,
m_maxLevel = 12;
m_pss.init(images, prefix, m_maxLevel + 1, 5, 0);

cerr << "Set widths/heights..." << flush;
cout << "Set widths/heights..." << flush;
setWidthsHeightsLevels();
cerr << "done" << flush;
cout << "done" << flush;
}

void Cbundle::prep2(void) {
Expand All @@ -83,40 +83,40 @@ void Cbundle::prep2(void) {
m_sfms2.resize((int)m_coords.size());
startTimer();
setScoreThresholds();
cerr << "done\t" << curTimer()/CLOCKS_PER_SEC << " secs" << endl;
cout << "done\t" << curTimer()/CLOCKS_PER_SEC << " secs" << endl;
startTimer();
cerr << "slimNeighborsSetLinks..." << flush;
cout << "slimNeighborsSetLinks..." << flush;
slimNeighborsSetLinks();
cerr << "done\t" << curTimer()/CLOCKS_PER_SEC << " secs" << endl;
cout << "done\t" << curTimer()/CLOCKS_PER_SEC << " secs" << endl;
}

// Improve visibility by using texture analysis
startTimer();
cerr << "mergeSFM..." << flush;
cout << "mergeSFM..." << flush;
mergeSfMP();
cerr << '\t' << curTimer()/CLOCKS_PER_SEC << " secs" << endl;
cout << '\t' << curTimer()/CLOCKS_PER_SEC << " secs" << endl;

m_sfms2.clear();
m_sfms2.resize((int)m_coords.size());
cerr << "setScoreThresholds..." << flush;
cout << "setScoreThresholds..." << flush;
startTimer();
setScoreThresholds();
cerr << "done\t" << curTimer()/CLOCKS_PER_SEC << " secs" << endl;
cout << "done\t" << curTimer()/CLOCKS_PER_SEC << " secs" << endl;

// Remove redundant images first
cerr << "sRemoveImages... " << flush;
cout << "sRemoveImages... " << flush;
startTimer();

sRemoveImages();
cerr << '\t' << curTimer()/CLOCKS_PER_SEC << " secs" << endl;
cout << '\t' << curTimer()/CLOCKS_PER_SEC << " secs" << endl;

// use m_removed to change m_visibles and update m_neighbors
startTimer();
resetVisibles();
setNeighbors();
cerr << "slimNeighborsSetLinks..." << flush;
cout << "slimNeighborsSetLinks..." << flush;
slimNeighborsSetLinks();
cerr << "done\t" << curTimer()/CLOCKS_PER_SEC << " secs" << endl;
cout << "done\t" << curTimer()/CLOCKS_PER_SEC << " secs" << endl;

// Init m_timages by mutually exclusive clustering
setTimages();
Expand All @@ -132,12 +132,12 @@ void Cbundle::run(const std::string prefix, const int imageThreshold,
prep(prefix, imageThreshold, tau, scoreRatioThreshold,
coverageThreshold, pnumThreshold, CPU);

cerr << '\t' << curTimer()/CLOCKS_PER_SEC << " secs" << endl;
cout << '\t' << curTimer()/CLOCKS_PER_SEC << " secs" << endl;

prep2();

// Assumed variables that must be set properly here
cerr << "Adding images: " << endl;
cout << "Adding images: " << endl;
startTimer();
// Add images
// Repeat until all the clusters become at most m_imageThreshold.
Expand Down Expand Up @@ -170,7 +170,7 @@ void Cbundle::run(const std::string prefix, const int imageThreshold,
if (change == 0)
break;
}
cerr << "done\t" << curTimer()/CLOCKS_PER_SEC << " secs" << endl;
cout << "done\t" << curTimer()/CLOCKS_PER_SEC << " secs" << endl;

m_oimages.resize((int)m_timages.size());

Expand Down Expand Up @@ -265,28 +265,28 @@ void Cbundle::sRemoveImages(void) {
const int tenth = max(1, m_cnum / 10);
for (int i = 0; i < (int)vvi.size(); ++i) {
if (i % tenth == 0)
cerr << '*' << flush;
cout << '*' << flush;
const int image = vvi[i][1];
checkImage(image);
}
cerr << endl;
cout << endl;

cerr << "Kept: ";
cout << "Kept: ";
int kept = 0;
for (int c = 0; c < m_cnum; ++c)
if (m_removed[c] == 0) {
++kept;
cerr << c << ' ';
cout << c << ' ';
}
cerr << endl << endl;
cout << endl << endl;

cerr << "Removed: ";
cout << "Removed: ";
for (int c = 0; c < m_cnum; ++c)
if (m_removed[c]) {
cerr << c << ' ';
cout << c << ' ';
}
cerr << endl;
cerr << "sRemoveImages: " << m_cnum << " -> " << kept << flush;
cout << endl;
cout << "sRemoveImages: " << m_cnum << " -> " << kept << flush;
}

void Cbundle::resetVisibles(void) {
Expand Down Expand Up @@ -448,10 +448,10 @@ void Cbundle::setTimages(void) {
else
divideImages(lhs, m_timages);

cerr << endl << "Cluster sizes: " << endl;
cout << endl << "Cluster sizes: " << endl;
for (int i = 0; i < (int)m_timages.size(); ++i)
cerr << (int)m_timages[i].size() << ' ';
cerr << endl;
cout << (int)m_timages[i].size() << ' ';
cout << endl;
}

void Cbundle::divideImages(const std::vector<int>& lhs,
Expand Down Expand Up @@ -515,7 +515,7 @@ void Cbundle::divideImages(const std::vector<int>& lhs,
}

if (cand1.empty() || cand2.empty()) {
cerr << "Error. Normalized cuts produced an empty cluster: "
cout << "Error. Normalized cuts produced an empty cluster: "
<< (int)part.size() << " -> "
<< (int)cand1.size() << ' '
<< (int)cand2.size() << endl;
Expand Down Expand Up @@ -558,7 +558,7 @@ void Cbundle::readBundle(const std::string file) {
int cnum, pnum;
ifstr >> cnum >> pnum;
vector<int> ids; ids.resize(cnum);
cerr << cnum << " cameras -- " << pnum << " points in bundle file" << endl;
cout << cnum << " cameras -- " << pnum << " points in bundle file" << endl;
m_cnum = 0;
for (int c = 0; c < cnum; ++c) {
ids[c] = -1;
Expand All @@ -577,7 +577,7 @@ void Cbundle::readBundle(const std::string file) {
const int tenth = max(1, pnum / 10);
for (int p = 0; p < pnum; ++p) {
if (p % tenth == 0)
cerr << '*' << flush;
cout << '*' << flush;
int num; Vec3f color;
Vec4f coord;
ifstr >> coord[0] >> coord[1] >> coord[2]
Expand Down Expand Up @@ -621,7 +621,7 @@ void Cbundle::readBundle(const std::string file) {
ifstr.close();
setNeighbors();

cerr << endl << m_cnum << " cameras -- " << m_pnum << " points" << flush;
cout << endl << m_cnum << " cameras -- " << m_pnum << " points" << flush;
}

void Cbundle::findPNeighbors(sfcnn<const float*, 3, float>& tree,
Expand Down Expand Up @@ -673,7 +673,7 @@ void Cbundle::mergeSfMPThread(void) {
if (pid != -1 && m_merged[pid])
pid = -2;
if (m_count % tenth == 0)
cerr << '*' << flush;
cout << '*' << flush;
++m_count;
mtx_unlock(&m_lock);
if (pid == -2)
Expand Down Expand Up @@ -786,17 +786,17 @@ void Cbundle::mergeSfMP(void) {
}

// Based on m_puf, reset m_coords, m_coords, m_visibles, m_vpoints
cerr << "resetPoints..." << flush;
cout << "resetPoints..." << flush;
resetPoints();
cerr << "done" << endl;
cout << "done" << endl;

delete m_puf;
m_puf = NULL;
delete m_ptree;
m_ptree = NULL;

const int npnum = (int)m_coords.size();
cerr << "Rep counts: " << cpnum << " -> " << npnum << " " << flush;
cout << "Rep counts: " << cpnum << " -> " << npnum << " " << flush;
}

// Based on m_puf, reset m_coords, m_coords, m_visibles, m_vpoints
Expand Down Expand Up @@ -998,8 +998,8 @@ void Cbundle::addImagesP(void) {
}

for (int i = 0; i < (int)m_addnums.size(); ++i)
cerr << m_addnums[i] << ' ';
cerr << endl;
cout << m_addnums[i] << ' ';
cout << endl;

int totalnum = 0;
for (int c = 0; c < (int)m_timages.size(); ++c)
Expand All @@ -1009,7 +1009,7 @@ void Cbundle::addImagesP(void) {
if (m_removed[c] == 0)
++beforenum;

cerr << "Image nums: "
cout << "Image nums: "
<< m_cnum << " -> " << beforenum << " -> " << totalnum << endl;
}

Expand Down Expand Up @@ -1389,7 +1389,7 @@ void Cbundle::writeVis(void) {
ofstr.close();


cerr << numer / (float)denom << " images in vis on the average" << endl;
cout << numer / (float)denom << " images in vis on the average" << endl;

}

Expand Down
10 changes: 5 additions & 5 deletions program/base/image/photoSetS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void CphotoSetS::init(const std::vector<int>& images, const std::string prefix,
m_prefix = prefix;
m_maxLevel = max(1, maxLevel);
m_photos.resize(m_num);
cerr << "Reading images: " << flush;
cout << "Reading images: " << flush;
for (int index = 0; index < m_num; ++index) {
const int image = m_images[index];

Expand Down Expand Up @@ -56,7 +56,7 @@ void CphotoSetS::init(const std::vector<int>& images, const std::string prefix,
m_photos[index].alloc();
else
m_photos[index].alloc(1);
cerr << '*' << flush;
cout << '*' << flush;
}
// try 4 digits
else {
Expand All @@ -73,7 +73,7 @@ void CphotoSetS::init(const std::vector<int>& images, const std::string prefix,
m_photos[index].alloc();
else
m_photos[index].alloc(1);
cerr << '*' << flush;
cout << '*' << flush;
}

/*
Expand All @@ -91,10 +91,10 @@ void CphotoSetS::init(const std::vector<int>& images, const std::string prefix,
m_photos[index].alloc();
else
m_photos[index].alloc(1);
cerr << '*' << flush;
cout << '*' << flush;
*/
}
cerr << endl;
cout << endl;
const int margin = size / 2;
m_size = 2 * margin + 1;
}
Expand Down
4 changes: 2 additions & 2 deletions program/base/pmvs/detectFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void CdetectFeatures::run(const CphotoSetS& pss, const int num,
for (int i = 0; i < m_CPU; ++i)
thrd_join(threads[i], NULL);
//----------------------------------------------------------------------
cerr << "done" << endl;
cout << "done" << endl;
}

int CdetectFeatures::runThreadTmp(void* arg) {
Expand All @@ -61,7 +61,7 @@ void CdetectFeatures::runThread(void) {
break;

const int image = m_ppss->m_images[index];
cerr << image << ' ' << flush;
cout << image << ' ' << flush;

//????????????? May need file lock, because targetting images
//should not overlap among multiple processors.
Expand Down
4 changes: 2 additions & 2 deletions program/base/pmvs/dog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void Cdog::run(const std::vector<unsigned char>& image,
const float firstScale, // 1.4f
const float lastScale, // 4.0f
std::multiset<Cpoint> & result) {
cerr << "DoG running..." << flush;
cout << "DoG running..." << flush;
m_width = width;
m_height = height;

Expand Down Expand Up @@ -221,7 +221,7 @@ void Cdog::run(const std::vector<unsigned char>& image,
}
}

cerr << (int)result.size() << " dog done" << endl;
cout << (int)result.size() << " dog done" << endl;
}

void Cdog::setRes(const float sigma,
Expand Down
8 changes: 4 additions & 4 deletions program/base/pmvs/expand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ void Cexpand::run(void) {
// set queue
m_fm.m_pos.collectPatches(m_queue);

cerr << "Expanding patches..." << flush;
cout << "Expanding patches..." << flush;
vector<thrd_t> threads(m_fm.m_CPU);
for (int c = 0; c < m_fm.m_CPU; ++c)
thrd_create(&threads[c], &expandThreadTmp, (void*)this);
for (int c = 0; c < m_fm.m_CPU; ++c)
thrd_join(threads[c], NULL);

cerr << endl
cout << endl
<< "---- EXPANSION: " << (time(NULL) - starttime) << " secs ----" << endl;

const int trial = accumulate(m_ecounts.begin(), m_ecounts.end(), 0);
const int fail0 = accumulate(m_fcounts0.begin(), m_fcounts0.end(), 0);
const int fail1 = accumulate(m_fcounts1.begin(), m_fcounts1.end(), 0);
const int pass = accumulate(m_pcounts.begin(), m_pcounts.end(), 0);
cerr << "Total pass fail0 fail1 refinepatch: "
cout << "Total pass fail0 fail1 refinepatch: "
<< trial << ' ' << pass << ' '
<< fail0 << ' ' << fail1 << ' ' << pass + fail1 << endl;
cerr << "Total pass fail0 fail1 refinepatch: "
cout << "Total pass fail0 fail1 refinepatch: "
<< 100 * trial / (float)trial << ' '
<< 100 * pass / (float)trial << ' '
<< 100 * fail0 / (float)trial << ' '
Expand Down
Loading