From 9686d976e462067c1cc6615337f93f6bb035e953 Mon Sep 17 00:00:00 2001 From: Noah Snavely Date: Tue, 7 Jan 2014 02:30:05 -0500 Subject: [PATCH] fixing compiler warning --- src/Geometry.cpp | 2 +- src/Makefile | 2 +- src/keys.cpp | 130 +++++------------------------------------------ src/keys.h | 27 +++------- 4 files changed, 21 insertions(+), 140 deletions(-) diff --git a/src/Geometry.cpp b/src/Geometry.cpp index 2adf7d4..fdbe25d 100644 --- a/src/Geometry.cpp +++ b/src/Geometry.cpp @@ -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\n", spacer); diff --git a/src/Makefile b/src/Makefile index 93011e3..34be992 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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) diff --git a/src/keys.cpp b/src/keys.cpp index 9b32f60..b74622d 100644 --- a/src/keys.cpp +++ b/src/keys.cpp @@ -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 ReadKeysMMAP(FILE *fp) -{ - int i, j, num, len, val, n; - - std::vector 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 @@ -865,17 +759,17 @@ std::vector MatchKeys(const std::vector &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; @@ -898,7 +792,7 @@ std::vector MatchKeys(const std::vector &k1, } } } - end = clock(); + // end = clock(); // printf("Searching tree took %0.3fs\n", // (end - start) / ((double) CLOCKS_PER_SEC)); @@ -963,17 +857,17 @@ std::vector } } - 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; @@ -999,7 +893,7 @@ std::vector } } } - end = clock(); + // end = clock(); // printf("Searching tree took %0.3fs\n", // (end - start) / ((double) CLOCKS_PER_SEC)); @@ -1108,18 +1002,18 @@ std::vector } } - 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; @@ -1142,7 +1036,7 @@ std::vector } } } - end = clock(); + // end = clock(); // printf("Searching tree took %0.3fs\n", // (end - start) / ((double) CLOCKS_PER_SEC)); diff --git a/src/keys.h b/src/keys.h index 15adafd..00bd5ca 100644 --- a/src/keys.h +++ b/src/keys.h @@ -37,11 +37,12 @@ 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() {} @@ -49,9 +50,9 @@ class Keypoint { 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 */ @@ -147,14 +148,7 @@ std::vector std::vector 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 ReadKeys(FILE *fp, bool descriptor); /* Read keys more quickly */ @@ -174,15 +168,8 @@ std::vector ReadKeysFastBin(FILE *fp, bool descriptor, std::vector ReadKeysFastBinGzip(gzFile fp, bool descriptor, float **scales = NULL, float **orients = NULL); -/* Read keys using MMAP to speed things up */ -std::vector ReadKeysMMAP(FILE *fp); #ifndef __DEMO__ -/* Create a search tree for the given set of keypoints */ -// ANNkd_tree *CreateSearchTree(const std::vector &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 &k);