diff --git a/modules/python/config/rbt.json b/modules/python/config/rbt.json index fb024e4adc..2e32af4ce1 100644 --- a/modules/python/config/rbt.json +++ b/modules/python/config/rbt.json @@ -26,6 +26,18 @@ ] } ], + "methods": [ + { + "static": false, + "signature": "void registerTypeRaw(const std::string&, const std::function(const std::string &)>)", + "keep_alive": [ + [ + 1, + 3 + ] + ] + } + ], "acknowledge_pointer_or_ref_fields": [ "std::map(const nlohmann::json&)>>", "std::function" @@ -222,12 +234,6 @@ "static": true, "signature": "vpRBDriftDetectorFactory& getFactory()", "return_policy": "reference", - "keep_alive": [ - [ - 1, - 0 - ] - ], "returns_ref_ok": true } ] @@ -238,12 +244,6 @@ "static": true, "signature": "vpObjectMaskFactory& getFactory()", "return_policy": "reference", - "keep_alive": [ - [ - 1, - 0 - ] - ], "returns_ref_ok": true } ] @@ -254,12 +254,6 @@ "static": true, "signature": "vpRBFeatureTrackerFactory& getFactory()", "return_policy": "reference", - "keep_alive": [ - [ - 1, - 0 - ] - ], "returns_ref_ok": true } ] diff --git a/modules/tracker/rbt/include/visp3/rbt/vpDynamicFactory.h b/modules/tracker/rbt/include/visp3/rbt/vpDynamicFactory.h index 56d8f2cab6..52404f3ccf 100644 --- a/modules/tracker/rbt/include/visp3/rbt/vpDynamicFactory.h +++ b/modules/tracker/rbt/include/visp3/rbt/vpDynamicFactory.h @@ -53,12 +53,23 @@ class VISP_EXPORT vpDynamicFactory #if defined(VISP_HAVE_NLOHMANN_JSON) void registerType(const std::string &key, const std::function(const nlohmann::json &)> &function) { - if (m_jsonBuilders.find(key) != m_jsonBuilders.end()) { + if (m_jsonBuilders.find(key) != m_jsonBuilders.end() || m_jsonRawBuilders.find(key) != m_jsonRawBuilders.end()) { throw vpException(vpException::badValue, "Type %s was already registered in the factory", key.c_str()); } m_jsonBuilders[key] = function; } + void registerTypeRaw(const std::string &key, const std::function(const std::string &)> function) + { + if (m_jsonBuilders.find(key) != m_jsonBuilders.end() || m_jsonRawBuilders.find(key) != m_jsonRawBuilders.end()) { + throw vpException(vpException::badValue, "Type %s was already registered in the factory", key.c_str()); + } + std::cout << "IN REGISTERING RAW TYPE" << std::endl; + m_jsonRawBuilders[key] = function; + std::cout << "IN REGISTERING RAW TYPE END" << std::endl; + + } + std::shared_ptr buildFromJson(const nlohmann::json &j) { const std::string key = m_keyFinder(j); @@ -66,6 +77,9 @@ class VISP_EXPORT vpDynamicFactory if (m_jsonBuilders.find(key) != m_jsonBuilders.end()) { return m_jsonBuilders[key](j); } + else if (m_jsonRawBuilders.find(key) != m_jsonRawBuilders.end()) { + return m_jsonRawBuilders[key](j.dump()); + } else { return nullptr; } @@ -82,6 +96,8 @@ class VISP_EXPORT vpDynamicFactory #if defined(VISP_HAVE_NLOHMANN_JSON) std::map(const nlohmann::json &)>> m_jsonBuilders; + std::map(const std::string &)>> m_jsonRawBuilders; + std::function m_keyFinder; //! Function to retrieve the key from a json object #endif };