diff --git a/components/rgbd-sources/include/ftl/rgbd_source.hpp b/components/rgbd-sources/include/ftl/rgbd_source.hpp index c43a1aaf2b4fe98b335c6654c4074ff7c4da69f6..43cce5090ef0727ccb3a8d350b1df9a4684089d1 100644 --- a/components/rgbd-sources/include/ftl/rgbd_source.hpp +++ b/components/rgbd-sources/include/ftl/rgbd_source.hpp @@ -66,6 +66,8 @@ class RGBDSource : public ftl::Configurable { * used as the instance name to construct. */ static RGBDSource *create(nlohmann::json &config, ftl::net::Universe *net); + + static void init(); protected: static void _register(const std::string &n, std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)> f); @@ -78,7 +80,7 @@ class RGBDSource : public ftl::Configurable { Eigen::Matrix4f pose_; private: - static std::map<std::string,std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)>> sources__; + static std::map<std::string,std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)>> *sources__; }; }; diff --git a/components/rgbd-sources/src/disparity.cpp b/components/rgbd-sources/src/disparity.cpp index 76558a133eef9388d48a6e08643e9130a30e2deb..5141d438fd3eb299ae2f010373fdd6b46458f0a7 100644 --- a/components/rgbd-sources/src/disparity.cpp +++ b/components/rgbd-sources/src/disparity.cpp @@ -9,7 +9,7 @@ using ftl::Disparity; std::map<std::string, std::function<Disparity*(nlohmann::json&)>> - Disparity::algorithms__; + *Disparity::algorithms__ = nullptr; Disparity::Disparity(nlohmann::json &config) : config_(config), @@ -17,14 +17,15 @@ Disparity::Disparity(nlohmann::json &config) max_disp_(config["maximum"]) {} Disparity *Disparity::create(nlohmann::json &config) { - if (algorithms__.count(config["algorithm"]) != 1) return nullptr; - return algorithms__[config["algorithm"]](config); + if (algorithms__->count(config["algorithm"]) != 1) return nullptr; + return (*algorithms__)[config["algorithm"]](config); } void Disparity::_register(const std::string &n, std::function<Disparity*(nlohmann::json&)> f) { + if (!algorithms__) algorithms__ = new std::map<std::string, std::function<Disparity*(nlohmann::json&)>>; LOG(INFO) << "Register disparity algorithm: " << n; - algorithms__[n] = f; + (*algorithms__)[n] = f; } // TODO(Nick) Add remaining algorithms diff --git a/components/rgbd-sources/src/disparity.hpp b/components/rgbd-sources/src/disparity.hpp index ed7f6b70fcacfefa76f5dd05aa081c9569507fc7..d7f24d583357e4d8c2640c2eae9ef42873c3f214 100644 --- a/components/rgbd-sources/src/disparity.hpp +++ b/components/rgbd-sources/src/disparity.hpp @@ -54,7 +54,7 @@ class Disparity { size_t max_disp_; private: - static std::map<std::string,std::function<Disparity*(nlohmann::json&)>> algorithms__; + static std::map<std::string,std::function<Disparity*(nlohmann::json&)>> *algorithms__; }; }; diff --git a/components/rgbd-sources/src/rgbd_source.cpp b/components/rgbd-sources/src/rgbd_source.cpp index 5423600283ab201f3edeb6092f58d32305aa45e3..9738c313ef0243448c3f2f1ceb27b0f12efd621b 100644 --- a/components/rgbd-sources/src/rgbd_source.cpp +++ b/components/rgbd-sources/src/rgbd_source.cpp @@ -3,8 +3,7 @@ using ftl::rgbd::RGBDSource; using ftl::Configurable; -std::map<std::string, std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)>> - RGBDSource::sources__; +std::map<std::string, std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)>> *RGBDSource::sources__ = nullptr; RGBDSource::RGBDSource(nlohmann::json &config) : Configurable(config), net_(nullptr) { @@ -36,14 +35,15 @@ bool RGBDSource::snapshot(const std::string &fileprefix) { RGBDSource *RGBDSource::create(nlohmann::json &config, ftl::net::Universe *net) { if (config["type"].type_name() != "string") return nullptr; - if (sources__.count(config["type"]) != 1) return nullptr; - return sources__[config["type"]](config, net); + if (sources__->count(config["type"]) != 1) return nullptr; + return (*sources__)[config["type"]](config, net); } void RGBDSource::_register(const std::string &n, std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)> f) { + if (!sources__) sources__ = new std::map<std::string, std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)>>; LOG(INFO) << "Register RGB-D Source: " << n; - sources__[n] = f; + (*sources__)[n] = f; } #include <ftl/net_source.hpp>