diff --git a/src/theia/CMakeLists.txt b/src/theia/CMakeLists.txt index 07c54a421..2029dcdd6 100644 --- a/src/theia/CMakeLists.txt +++ b/src/theia/CMakeLists.txt @@ -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) diff --git a/src/theia/sfm/exif_reader.cc b/src/theia/sfm/exif_reader.cc index 48c049a9e..6a5c708da 100644 --- a/src/theia/sfm/exif_reader.cc +++ b/src/theia/sfm/exif_reader.cc @@ -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 { @@ -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.