Skip to content

Commit

Permalink
Embed camera_sensor_database.txt to library. Closes #106
Browse files Browse the repository at this point in the history
  • Loading branch information
KindDragon committed Jul 4, 2017
1 parent a354f02 commit 73a0482
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
18 changes: 18 additions & 0 deletions src/theia/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@
# Please contact the author of this library if you have any questions.
# Author: Chris Sweeney (cmsweeney@cs.ucsb.edu)

function(create_resource_file file output)
# Create empty output file
file(WRITE ${output} "")
# Get short filename
get_filename_component(filename "${file}" NAME)
# Replace filename spaces & extension separator for C compatibility
string(MAKE_C_IDENTIFIER ${filename} filename)
# Read hex data from file
file(READ ${file} filedata HEX)
# Convert hex data for C compatibility
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata})
# Append data to output file
file(WRITE ${output} "const char ${filename}[] = {${filedata}};\nconst size_t ${filename}_size = sizeof(${filename});\n")
endfunction()

create_resource_file("${PROJECT_SOURCE_DIR}/data/camera_sensor_database.txt" "${CMAKE_CURRENT_BINARY_DIR}/camera_sensor_database.h")
include_directories(${CMAKE_CURRENT_BINARY_DIR})

# Add headers
file(GLOB_RECURSE THEIA_HDRS *.h)

Expand Down
12 changes: 4 additions & 8 deletions src/theia/sfm/exif_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
#include "theia/sfm/camera_intrinsics_prior.h"
#include "theia/util/map_util.h"

// Generated file
#include "camera_sensor_database.h"

namespace theia {
namespace {

Expand Down Expand Up @@ -93,14 +96,7 @@ ExifReader::ExifReader() {
}

void ExifReader::LoadSensorWidthDatabase() {
const std::string sensor_width_file =
std::string(THEIA_DATA_DIR) + "/camera_sensor_database.txt";

std::ifstream ifs(sensor_width_file.c_str(), std::ios::in);
if (!ifs.is_open()) {
LOG(FATAL) << "Cannot read the sensor width file from "
<< sensor_width_file;
}
std::stringstream ifs(camera_sensor_database_txt, std::ios::in);

while (!ifs.eof()) {
// Read in the filename.
Expand Down

0 comments on commit 73a0482

Please sign in to comment.