Skip to content

Commit

Permalink
various fixes / cleanups to code
Browse files Browse the repository at this point in the history
  • Loading branch information
snavely committed Dec 28, 2013
1 parent b059394 commit 6d4f5be
Show file tree
Hide file tree
Showing 21 changed files with 133 additions and 286 deletions.
3 changes: 1 addition & 2 deletions src/BaseApp.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) 2008-2010 Noah Snavely (snavely (at) cs.cornell.edu)
* and the University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -47,7 +46,7 @@ int BaseApp::GetRegisteredCameraIndex(int cam) {
}
}

printf("[SifterApp::GetRegisteredCameraIndex] "
printf("[GetRegisteredCameraIndex] "
"Error: ran out of cameras\n");

return -1;
Expand Down
18 changes: 8 additions & 10 deletions src/BaseApp.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) 2008-2010 Noah Snavely (snavely (at) cs.cornell.edu)
* and the University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,7 +29,6 @@
#include "ImageData.h"



#ifndef __DEMO__
#include "sfm.h"
#endif /* __DEMO__ */
Expand All @@ -42,8 +40,8 @@
#include <list>

#ifndef WIN32
#include <ext/hash_map>
#include <ext/hash_set>
#include <unordered_map>
#include <unordered_set>
#else
#include <hash_map>
#include <hash_set>
Expand Down Expand Up @@ -104,7 +102,7 @@ namespace stdext {
};
}
#else
namespace __gnu_cxx {
namespace std {
template<>
struct hash<MatchIndex> {
size_t
Expand Down Expand Up @@ -155,7 +153,7 @@ class MatchTable : private stdext::hash_set<MatchIndex>
typedef stdext::hash_map<unsigned int, std::vector<KeypointMatch> >
MatchAdjTable;
#else
typedef __gnu_cxx::hash_map<unsigned int, std::vector<KeypointMatch> >
typedef unordered_map<unsigned int, std::vector<KeypointMatch> >
MatchAdjTable;
#endif

Expand Down Expand Up @@ -417,9 +415,9 @@ class BaseApp
/* Clear the current model */
void ClearModel();

/* Write the match table in Drew's format */
void WriteMatchTableDrew(const char *append = "");
void ReadMatchTableDrew(const char *append = "");
/* Read / write the match table */
void ReadMatchTable(const char *append = "");
void WriteMatchTable(const char *append = "");

/* Initialize images read from a file without performing bundle
* adjustment */
Expand Down Expand Up @@ -559,7 +557,7 @@ class BaseApp
#endif

#ifndef WIN32
__gnu_cxx::hash_map<MatchIndex, TransformInfo> m_transforms;
unordered_map<MatchIndex, TransformInfo> m_transforms;
#else
stdext::hash_map<MatchIndex, TransformInfo> m_transforms;
#endif
Expand Down
20 changes: 9 additions & 11 deletions src/BaseGeometry.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) 2008-2010 Noah Snavely (snavely (at) cs.cornell.edu)
* and the University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -107,7 +106,7 @@ void BaseApp::ReadGeometricConstraints(char *filename) {

fscanf(f, "%d\n", &num_images);
if (num_images != GetNumImages()) {
printf("[SifterApp::ReadGeometricConstraints] Error: number of "
printf("[ReadGeometricConstraints] Error: number of "
"images don't match!\n");
return;
}
Expand Down Expand Up @@ -176,7 +175,7 @@ void BaseApp::ReadGeometricConstraints(char *filename) {
int num_tracks = 0;
fscanf(f, "%d", &num_tracks);

printf("[SifterApp::ReadGeometricConstraints] Reading %d tracks\n",
printf("[ReadGeometricConstraints] Reading %d tracks\n",
num_tracks);

m_track_data.clear();
Expand Down Expand Up @@ -268,7 +267,6 @@ void BaseApp::ReadGeometricConstraints(char *filename) {

// SetMatchesFromTracks();

// WriteMatchTableDrew(".corresp");
// WriteGeometricConstraints("constraints_test.txt");
}

Expand Down Expand Up @@ -526,7 +524,7 @@ void BaseApp::ComputeImageRotations()

int rot;
if (fabs(x_dot) > fabs(y_dot)) {
printf("[SifterApp::ComputeImageRotations] "
printf("[ComputeImageRotations] "
"Rotating image %d [90]\n", i);

if (x_dot > 0.0) {
Expand All @@ -538,7 +536,7 @@ void BaseApp::ComputeImageRotations()
if (y_dot > 0.0) {
rot = 0;
} else {
printf("[SifterApp::ComputeImageRotations] "
printf("[ComputeImageRotations] "
"Rotating image %d [180]\n", i);

rot = 2;
Expand All @@ -553,7 +551,7 @@ void BaseApp::ComputeImageRotations()
/* Estimate the world axes based on the image orientations */
void BaseApp::EstimateAxes(double *xaxis, double *yaxis, double *zaxis)
{
printf("[SifterApp::EstimateAxes] Estimating axes\n");
printf("[EstimateAxes] Estimating axes\n");

double RTR[9] = { 0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
Expand Down Expand Up @@ -674,11 +672,11 @@ void BaseApp::EstimateAxes(double *xaxis, double *yaxis, double *zaxis)
}

if (num_neg > num_pos) {
printf("[SifterApp::EstimateAxes] Flipping y-axis (%d, %d)\n",
printf("[EstimateAxes] Flipping y-axis (%d, %d)\n",
num_pos, num_neg);
matrix_scale(3, 1, yaxis, -1.0, yaxis);
} else {
printf("[SifterApp::EstimateAxes] Not flipping\n");
printf("[EstimateAxes] Not flipping\n");
}

#if 0
Expand Down Expand Up @@ -822,7 +820,7 @@ void BaseApp::SetupSceneGroundPlane(double *center, double *up,
plane[2] /= norm;
} else {
if (!m_image_data[m_up_image].m_camera.m_adjusted) {
printf("[SifterApp::SetupScene] Error: user refered to an "
printf("[SetupScene] Error: user refered to an "
"unadjusted camera\n");
exit(1);
}
Expand Down Expand Up @@ -1024,7 +1022,7 @@ void BaseApp::WritePoints(const char *filename)
void BaseApp::RepositionScene(double *center_out, double *R_out,
double &scale_out)
{
printf("[SifterApp::RepositionScene] Repositioning scene\n");
printf("[RepositionScene] Repositioning scene\n");

double center[3], up[3], x_axis[3], z_axis[3];
double scale;
Expand Down
1 change: 0 additions & 1 deletion src/BoundingBox.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) 2008-2010 Noah Snavely (snavely (at) cs.cornell.edu)
* and the University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
1 change: 0 additions & 1 deletion src/BruteForceSearch.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) 2008-2010 Noah Snavely (snavely (at) cs.cornell.edu)
* and the University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
4 changes: 2 additions & 2 deletions src/Bundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void BundlerApp::ReRunSFM(double *S, double *U, double *V, double *W)
int num_images = GetNumImages();

/* Initialize all keypoints to have not been matched */
printf("[SifterApp::ReRunSFM] Initializing keypoints...\n");
printf("[ReRunSFM] Initializing keypoints...\n");
for (int i = 0; i < num_images; i++) {
int num_keys = GetNumKeys(i);
for (int j = 0; j < num_keys; j++) {
Expand All @@ -305,7 +305,7 @@ void BundlerApp::ReRunSFM(double *S, double *U, double *V, double *W)

camera_params_t *cameras = new camera_params_t[num_images];

printf("[SifterApp::ReRunSFM] Setting up cameras\n");
printf("[ReRunSFM] Setting up cameras\n");
for (int i = 0; i < num_images; i++) {
printf(".");
fflush(stdout);
Expand Down
14 changes: 7 additions & 7 deletions src/BundleAdd.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) 2008-2010 Noah Snavely (snavely (at) cs.cornell.edu)
* and the University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -18,12 +17,12 @@
/* Routines for adding new points into the bundle adjustment */

#include <float.h>
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>

#ifndef WIN32
#include <ext/hash_map>
#include <map>
#else
#include <hash_map>
#endif
Expand All @@ -46,8 +45,10 @@

/* Triangulate a subtrack */
v3_t BundlerApp::TriangulateNViews(const ImageKeyVector &views,
int *added_order, camera_params_t *cameras,
double &error, bool explicit_camera_centers)
int *added_order,
camera_params_t *cameras,
double &error,
bool explicit_camera_centers)
{
int num_views = (int) views.size();

Expand Down Expand Up @@ -202,7 +203,6 @@ BundlerApp::BundleAdjustAddAllNewPoints(int num_points, int num_cameras,
std::vector<int> track_idxs;
std::vector<ImageKeyVector> new_tracks;

// __gnu_cxx::hash_map<int,bool> tracks_seen;
int num_tracks_total = (int) m_track_data.size();
int *tracks_seen = new int[num_tracks_total];
for (int i = 0; i < num_tracks_total; i++) {
Expand Down Expand Up @@ -348,7 +348,7 @@ BundlerApp::BundleAdjustAddAllNewPoints(int num_points, int num_cameras,
error, true);
}

if (isnan(error) || error > max_reprojection_error) {
if (std::isnan(error) || error > max_reprojection_error) {
num_high_reprojection++;
#if 0
printf(">> Reprojection error [%0.3f] is too large\n", error);
Expand Down
24 changes: 12 additions & 12 deletions src/BundleFast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void BundlerApp::BundleAdjustFast()

#if 0
/* Read keypoints */
printf("[SifterApp::BundleAdjust] Reading key colors...\n");
printf("[BundleAdjust] Reading key colors...\n");
ReadKeyColors();
#endif

Expand Down Expand Up @@ -101,7 +101,7 @@ void BundlerApp::BundleAdjustFast()
// good_pair_1 = 0; // i_best;
// good_pair_2 = 1; // j_best;

printf("[SifterApp::BundleAdjust] Adjusting cameras "
printf("[BundleAdjust] Adjusting cameras "
"%d and %d (score = %0.3f)\n",
i_best, j_best, max_score);

Expand Down Expand Up @@ -236,9 +236,9 @@ void BundlerApp::BundleAdjustFast()
} else {
#if 0
if (m_initial_pair[0] == -1 || m_initial_pair[1] == -1) {
printf("[SifterApp::BundleAdjust] Error: initial good pair "
printf("[BundleAdjust] Error: initial good pair "
"not provided!\n");
printf("[SifterApp::BundleAdjust] Please specify a pair of "
printf("[BundleAdjust] Please specify a pair of "
"cameras with medium baseline using\n"
" --init_pair1 <img1> and --init_pair2 <img2>\n");
exit(1);
Expand All @@ -248,9 +248,9 @@ void BundlerApp::BundleAdjustFast()
good_pair_2 = added_order_inv[m_initial_pair[1]];

if (good_pair_1 == -1 || good_pair_2 == -1) {
printf("[SifterApp::BundleAdjust] Error: initial pair haven't "
printf("[BundleAdjust] Error: initial pair haven't "
"been adjusted!\n");
printf("[SifterApp::BundleAdjust] Please specify another pair!\n");
printf("[BundleAdjust] Please specify another pair!\n");
exit(0);
}
#endif
Expand All @@ -267,7 +267,7 @@ void BundlerApp::BundleAdjustFast()
added_order, parent_idx,
max_matches, pt_views);

printf("[SifterApp::BundleAdjust] max_matches = %d\n", max_matches);
printf("[BundleAdjust] max_matches = %d\n", max_matches);

if (max_matches < m_min_max_matches)
break; /* No more connections */
Expand All @@ -288,11 +288,11 @@ void BundlerApp::BundleAdjustFast()

int num_added_images = (int) image_set.size();

printf("[SifterApp::BundleAdjustFast] Registering %d images\n",
printf("[BundleAdjustFast] Registering %d images\n",
num_added_images);

for (int i = 0; i < num_added_images; i++)
printf("[SifterApp::BundleAdjustFast] Adjusting camera %d\n",
printf("[BundleAdjustFast] Adjusting camera %d\n",
image_set[i].first);

/* Now, throw the new cameras into the mix */
Expand All @@ -303,7 +303,7 @@ void BundlerApp::BundleAdjustFast()

added_order[curr_num_cameras + image_count] = next_idx;

printf("[SifterApp::BundleAdjust[%d]] Adjusting camera %d "
printf("[BundleAdjust[%d]] Adjusting camera %d "
"(parent = %d)\n",
round, next_idx,
(parent_idx == -1 ? -1 : added_order[parent_idx]));
Expand Down Expand Up @@ -338,7 +338,7 @@ void BundlerApp::BundleAdjustFast()
double dist0 = 0.0;
#endif

printf("[SifterApp::BundleAdjust] Adding new matches\n");
printf("[BundleAdjust] Adding new matches\n");

pt_count = curr_num_pts;
#if 0
Expand All @@ -363,7 +363,7 @@ void BundlerApp::BundleAdjustFast()

curr_num_pts = pt_count;

printf("[SifterApp::BundleAdjust] Number of points = %d\n", pt_count);
printf("[BundleAdjust] Number of points = %d\n", pt_count);
fflush(stdout);

if (!m_skip_full_bundle) {
Expand Down
Loading

0 comments on commit 6d4f5be

Please sign in to comment.