Skip to content
Snippets Groups Projects
Commit 6263dcc5 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Switch reconstruct to use new configure code

parent 0cc07689
No related branches found
No related tags found
No related merge requests found
...@@ -4,14 +4,14 @@ include_directories(${PROJECT_SOURCE_DIR}/reconstruct/include) ...@@ -4,14 +4,14 @@ include_directories(${PROJECT_SOURCE_DIR}/reconstruct/include)
set(REPSRC set(REPSRC
../common/cpp/src/config.cpp
src/main.cpp src/main.cpp
) )
add_executable(ftl-reconstruct ${REPSRC}) add_executable(ftl-reconstruct ${REPSRC})
add_dependencies(ftl-reconstruct ftlnet) add_dependencies(ftl-reconstruct ftlnet)
add_dependencies(ftl-reconstruct ftlcommon)
#target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include) #target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(ftl-reconstruct Threads::Threads ZLIB::ZLIB ${OpenCV_LIBS} glog::glog ftlnet ftlrender) target_link_libraries(ftl-reconstruct ftlcommon Threads::Threads ZLIB::ZLIB ${OpenCV_LIBS} glog::glog ftlnet ftlrender)
...@@ -6,13 +6,12 @@ ...@@ -6,13 +6,12 @@
#include <glog/logging.h> #include <glog/logging.h>
#include <ftl/config.h> #include <ftl/config.h>
#include <ftl/configuration.hpp>
#include <zlib.h> #include <zlib.h>
// #include <lz4.h> // #include <lz4.h>
#include <string> #include <string>
#include <map>
#include <vector> #include <vector>
#include <fstream>
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include <mutex> #include <mutex>
...@@ -33,90 +32,17 @@ ...@@ -33,90 +32,17 @@
using ftl::net::Universe; using ftl::net::Universe;
using ftl::Display; using ftl::Display;
using ftl::config;
using std::string; using std::string;
using std::vector; using std::vector;
using std::map;
using cv::Mat; using cv::Mat;
using json = nlohmann::json; using json = nlohmann::json;
using std::ifstream;
using std::this_thread::sleep_for; using std::this_thread::sleep_for;
using std::chrono::milliseconds; using std::chrono::milliseconds;
using std::mutex; using std::mutex;
using std::unique_lock; using std::unique_lock;
// Store loaded configuration static void run() {
static json config;
/**
* Find and load a JSON configuration file
*/
static bool findConfiguration(const string &file) {
ifstream i;
if (file != "") i.open(file);
if (!i.is_open()) i.open("./config.json");
if (!i.is_open()) i.open(FTL_LOCAL_CONFIG_ROOT "/config.json");
if (!i.is_open()) i.open(FTL_GLOBAL_CONFIG_ROOT "/config.json");
if (!i.is_open()) return false;
i >> config;
config = config["representation"];
return true;
}
/**
* Generate a map from command line option to value
*/
map<string, string> read_options(char ***argv, int *argc) {
map<string, string> opts;
while (*argc > 0) {
string cmd((*argv)[0]);
if (cmd[0] != '-') break;
size_t p;
if ((p = cmd.find("=")) == string::npos) {
opts[cmd.substr(2)] = "true";
} else {
opts[cmd.substr(2, p-2)] = cmd.substr(p+1);
}
(*argc)--;
(*argv)++;
}
return opts;
}
/**
* Put command line options into json config. If config element does not exist
* or is of a different type then report an error.
*/
static void process_options(const map<string, string> &opts) {
for (auto opt : opts) {
if (opt.first == "config") continue;
if (opt.first == "version") {
std::cout << "FTL Vision Node - v" << FTL_VERSION << std::endl;
std::cout << FTL_VERSION_LONG << std::endl;
exit(0);
}
try {
auto ptr = json::json_pointer("/"+opt.first);
// TODO(nick) Allow strings without quotes
auto v = json::parse(opt.second);
if (v.type() != config.at(ptr).type()) {
LOG(ERROR) << "Incorrect type for argument " << opt.first;
continue;
}
config.at(ptr) = v;
} catch(...) {
LOG(ERROR) << "Unrecognised option: " << opt.first;
}
}
}
static void run(const string &file) {
Universe net(config["net"]); Universe net(config["net"]);
Mat rgb, depth, Q; Mat rgb, depth, Q;
mutex m; mutex m;
...@@ -188,16 +114,7 @@ static void run(const string &file) { ...@@ -188,16 +114,7 @@ static void run(const string &file) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
argc--; ftl::configure(argc, argv, "representation"); // TODO(nick) change to "reconstruction"
argv++; run();
// Process Arguments
auto options = read_options(&argv, &argc);
if (!findConfiguration(options["config"])) {
LOG(FATAL) << "Could not find any configuration!";
}
process_options(options);
run((argc > 0) ? argv[0] : "");
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment