Skip to content

Commit

Permalink
fixing compiler warning
Browse files Browse the repository at this point in the history
  • Loading branch information
snavely committed Jan 7, 2014
1 parent b4b295d commit 9686d97
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 140 deletions.
2 changes: 1 addition & 1 deletion src/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void PointData::WriteCoordinates(FILE *f)
/* Write the point data in XML */
void PointData::WriteXML(FILE *f)
{
static char *spacer = " ";
static const char *spacer = " ";

/* Position and color */
fprintf(f, "%s<point>\n", spacer);
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ USE_CERES=true

CC=gcc
CXX=g++
OPTFLAGS=-O3 -Wall
OPTFLAGS=-O3 -Wall -Wno-unused-result
OTHERFLAGS=-std=gnu++0x

OS=$(shell uname -o)
Expand Down
130 changes: 12 additions & 118 deletions src/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,112 +298,6 @@ static char *strchrn(char *str, int c, int n) {
return str - 1;
}

#if 0
/* Read keys using MMAP to speed things up */
std::vector<Keypoint> ReadKeysMMAP(FILE *fp)
{
int i, j, num, len, val, n;

std::vector<Keypoint> kps;

struct stat sb;

/* Stat the file */
if (fstat(fileno(fp), &sb) < 0) {
printf("[ReadKeysMMAP] Error: could not stat file\n");
return kps;
}

char *file = (char *)mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED,
fileno(fp), 0);

char *file_start = file;

char string_buf[1024];
char *str = string_buf;

/* Find the first '\n' */
char *newline = strchr(file, '\n');
int pos = (int) (newline - file);

memcpy(str, file, pos);
str[pos] = 0;

if (sscanf(str, "%d %d%n", &num, &len, &n) != 2) {
printf("[ReadKeysMMAP] Invalid keypoint file beginning.");
return kps;
}

#ifdef KEY_LIMIT
num = MIN(num, 65536); // we'll store at most 65536 features per
// image
#endif /* KEY_LIMIT */

file += (pos + 1);

if (len != 128) {
printf("[ReadKeysMMAP] Keypoint descriptor length invalid "
"(should be 128).");
return kps;
}

for (i = 0; i < num; i++) {
str = string_buf;

/* Allocate memory for the keypoint. */
unsigned char *d = new unsigned char[len];
float x, y, scale, ori;

/* Find the first '\n' */
newline = strchr(file, '\n');
pos = (int) (newline - file);

memcpy(str, file, pos);
str[pos] = 0;

if (sscanf(str, "%f %f %f %f%n", &y, &x, &scale, &ori, &n) != 4) {
printf("[ReadKeysMMAP] Invalid keypoint file format.");
return kps;
}

file += (pos + 1);

/* Find the next seven '\n's */
str = string_buf;

char *seventh_newline = strchrn(file, '\n', 7);
pos = (int) (seventh_newline - file);

memcpy(str, file, pos);
str[pos] = 0;

for (j = 0; j < len; j++) {
if (sscanf(str, "%d%n", &val, &n) != 1 || val < 0 || val > 255) {
printf("[ReadKeysMMAP] Invalid keypoint file value.");
return kps;
}
d[j] = (unsigned char) val;
str += n;
}

file += (pos + 1);

if (desc)
kps.Add(Keypoint(x, y, d));
else
kps.Add(Keypoint(x, y));
}

/* Unmap */
if (munmap(file_start, sb.st_size) < 0) {
printf("[ReadKeysMMAP] Error: could not unmap memory\n");
return kps;
}

return kps;
}
#endif

/* Read keypoints from the given file pointer and return the list of
* keypoints. The file format starts with 2 integers giving the total
* number of keypoints and the size of descriptor vector for each
Expand Down Expand Up @@ -865,17 +759,17 @@ std::vector<KeypointMatch> MatchKeys(const std::vector<KeypointWithDesc> &k1,
}
}

clock_t start = clock();
// clock_t start = clock();
/* Create a search tree for k2 */
ann_1_1_char::ANNkd_tree *tree = new ann_1_1_char::ANNkd_tree(pts, num_pts, 128, 4);
clock_t end = clock();
// clock_t end = clock();

// printf("Building tree took %0.3fs\n",
// (end - start) / ((double) CLOCKS_PER_SEC));

/* Now do the search */
ann_1_1_char::ANNpoint query = ann_1_1_char::annAllocPt(128);
start = clock();
// start = clock();
for (int i = 0; i < (int) k1.size(); i++) {
int j;

Expand All @@ -898,7 +792,7 @@ std::vector<KeypointMatch> MatchKeys(const std::vector<KeypointWithDesc> &k1,
}
}
}
end = clock();
// end = clock();
// printf("Searching tree took %0.3fs\n",
// (end - start) / ((double) CLOCKS_PER_SEC));

Expand Down Expand Up @@ -963,17 +857,17 @@ std::vector<KeypointMatchWithScore>
}
}

clock_t start = clock();
// clock_t start = clock();
/* Create a search tree for k2 */
ann_1_1_char::ANNkd_tree *tree = new ann_1_1_char::ANNkd_tree(pts, num_pts, 128, 4);
clock_t end = clock();
// clock_t end = clock();

// printf("Building tree took %0.3fs\n",
// (end - start) / ((double) CLOCKS_PER_SEC));

/* Now do the search */
ann_1_1_char::ANNpoint query = ann_1_1_char::annAllocPt(128);
start = clock();
// start = clock();
for (int i = 0; i < (int) k1.size(); i++) {
int j;

Expand All @@ -999,7 +893,7 @@ std::vector<KeypointMatchWithScore>
}
}
}
end = clock();
// end = clock();
// printf("Searching tree took %0.3fs\n",
// (end - start) / ((double) CLOCKS_PER_SEC));

Expand Down Expand Up @@ -1108,18 +1002,18 @@ std::vector<KeypointMatch>
}
}

clock_t start = clock();
// clock_t start = clock();
/* Create a search tree for k2 */
ann_1_1_char::ANNkd_tree *tree =
new ann_1_1_char::ANNkd_tree(pts, num_pts, 128, 4);
clock_t end = clock();
// clock_t end = clock();

// printf("Building tree took %0.3fs\n",
// (end - start) / ((double) CLOCKS_PER_SEC));

/* Now do the search */
ann_1_1_char::ANNpoint query = ann_1_1_char::annAllocPt(128);
start = clock();
// start = clock();
for (int i = 0; i < (int) k1.size(); i++) {
int j;

Expand All @@ -1142,7 +1036,7 @@ std::vector<KeypointMatch>
}
}
}
end = clock();
// end = clock();
// printf("Searching tree took %0.3fs\n",
// (end - start) / ((double) CLOCKS_PER_SEC));

Expand Down
27 changes: 7 additions & 20 deletions src/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@
class Keypoint {
public:
Keypoint()
{ m_x = 0.0; m_y = 0.0; m_extra = -1; m_track = -1; }
{ m_x = 0.0; m_y = 0.0; m_extra = -1; m_track = -1;
m_r = m_g = m_b = 0; }

Keypoint(float x, float y) :
m_x(x), m_y(y)
{ m_r = 0; m_g = 0; m_b = 0; }
{ m_extra = -1; m_track = -1; m_r = 0; m_g = 0; m_b = 0; }

virtual ~Keypoint() {}

virtual unsigned char *GetDesc() {
return NULL;
}

float m_x, m_y; /* Subpixel location of keypoint. */
// float m_scale, m_ori; /* Scale and orientation (range [-PI,PI]) */
unsigned char m_r, m_g, m_b; /* Color of this key */
float m_x, m_y; /* Subpixel location of keypoint. */
// float m_scale, m_ori; /* Scale and orientation (range [-PI,PI]) */
unsigned char m_r, m_g, m_b; /* Color of this key */

int m_extra; /* 4 bytes of extra storage */
int m_track; /* Track index this point corresponds to */
Expand Down Expand Up @@ -147,14 +148,7 @@ std::vector<KeypointWithDesc>
std::vector<KeypointWithScaleRot>
ReadKeyFileWithScaleRot(const char *filename, bool descriptor);

/* Read keypoints from the given file pointer and return the list of
* keypoints. The file format starts with 2 integers giving the total
* number of keypoints and the size of descriptor vector for each
* keypoint (currently assumed to be 128). Then each keypoint is
* specified by 4 floating point numbers giving subpixel row and
* column location, scale, and orientation (in radians from -PI to
* PI). Then the descriptor vector for each keypoint is given as a
* list of integers in range [0,255]. */
/* Read keypoints from the given file pointer */
std::vector<Keypoint> ReadKeys(FILE *fp, bool descriptor);

/* Read keys more quickly */
Expand All @@ -174,15 +168,8 @@ std::vector<KeypointWithDesc> ReadKeysFastBin(FILE *fp, bool descriptor,
std::vector<KeypointWithDesc> ReadKeysFastBinGzip(gzFile fp, bool descriptor,
float **scales = NULL,
float **orients = NULL);
/* Read keys using MMAP to speed things up */
std::vector<Keypoint> ReadKeysMMAP(FILE *fp);

#ifndef __DEMO__
/* Create a search tree for the given set of keypoints */
// ANNkd_tree *CreateSearchTree(const std::vector<KeypointWithDesc> &k,
// bool spatial = false,
// double alpha = 0.0);

/* Create a search tree for the given set of keypoints */
ann_1_1_char::ANNkd_tree
*CreateSearchTreeChar(const std::vector<KeypointWithDesc> &k);
Expand Down

0 comments on commit 9686d97

Please sign in to comment.