Skip to content

Commit

Permalink
[TUTO][FIX] Fix to_json compilation error in tutorial-ibvs-4pts-json
Browse files Browse the repository at this point in the history
  • Loading branch information
rlagneau committed May 28, 2024
1 parent eb1e074 commit a004712
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions tutorial/visual-servo/ibvs/tutorial-ibvs-4pts-json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
#include <nlohmann/json.hpp>
using json = nlohmann::json; //! json namespace shortcut


#if defined(ENABLE_VISP_NAMESPACE)
namespace VISP_NAMESPACE_NAME
{
using namespace VISP_NAMESPACE_NAME;
#endif

//! [Enum]
Expand Down Expand Up @@ -75,6 +73,9 @@ class Arguments
// the default value defined in the constructor is kept
void from_json(const json &j, Arguments &a)
{
#ifdef ENABLE_VISP_NAMESPACE
using VISP_NAMESPACE_ADDRESSING from_json;
#endif
a.lambda = j.value("lambda", a.lambda);
if (a.lambda <= 0) {
throw vpException(vpException::badValue, "Lambda should be > 0");
Expand All @@ -101,6 +102,9 @@ void from_json(const json &j, Arguments &a)

void to_json(json &j, const Arguments &a)
{
#ifdef ENABLE_VISP_NAMESPACE
using VISP_NAMESPACE_ADDRESSING to_json;
#endif
j = json {
{"lambda", a.lambda},
{"cMo", a.cMo},
Expand Down Expand Up @@ -147,6 +151,11 @@ Arguments readArguments(const std::string &path)
//! [JSON input conversion]

//! [Custom ViSP object conversion]
#ifdef ENABLE_VISP_NAMESPACE
// Required to have the to_json method in the same namespace than vpFeaturePoint
namespace VISP_NAMESPACE_NAME
{
#endif
void to_json(json &j, const vpFeaturePoint &p)
{
j = json {
Expand All @@ -155,6 +164,9 @@ void to_json(json &j, const vpFeaturePoint &p)
{"z", p.get_Z()}
};
}
#ifdef ENABLE_VISP_NAMESPACE
}
#endif

//! [Custom ViSP object conversion]

Expand Down Expand Up @@ -190,6 +202,9 @@ class ServoingExperimentData

void to_json(json &j, const ServoingExperimentData &res)
{
#ifdef ENABLE_VISP_NAMESPACE
using VISP_NAMESPACE_ADDRESSING to_json;
#endif
j = json {
{"parameters", res.m_arguments},
{"trajectory", res.m_trajectory},
Expand All @@ -211,15 +226,9 @@ void saveResults(const ServoingExperimentData &results, const std::string &path)
file.close();
}
//! [write json to file]
#if defined(ENABLE_VISP_NAMESPACE)
}
#endif

int main(int argc, char *argv[])
{
#if defined(ENABLE_VISP_NAMESPACE)
using namespace VISP_NAMESPACE_NAME;
#endif
//! [Main parsing]
std::string arguments_path = "";
std::string output_path = "";
Expand Down

0 comments on commit a004712

Please sign in to comment.