Skip to content

Commit d6259c3

Browse files
committed
remove using json=nlohmann::json from header files to avoid pollution
1 parent cb7e32f commit d6259c3

File tree

6 files changed

+25
-17
lines changed

6 files changed

+25
-17
lines changed

modules/core/include/visp3/core/vpCannyEdgeDetection.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
// 3rd parties include
4444
#ifdef VISP_HAVE_NLOHMANN_JSON
4545
#include <nlohmann/json.hpp>
46-
using json = nlohmann::json; //! json namespace shortcut
4746
#endif
4847

4948
class VISP_EXPORT vpCannyEdgeDetection
@@ -213,7 +212,7 @@ class VISP_EXPORT vpCannyEdgeDetection
213212
* \param[in] j : The JSON object, resulting from the parsing of a JSON file.
214213
* \param[out] detector : The detector that will be initialized from the JSON data.
215214
*/
216-
friend inline void from_json(const json &j, vpCannyEdgeDetection &detector)
215+
friend inline void from_json(const nlohmann::json &j, vpCannyEdgeDetection &detector)
217216
{
218217
std::string filteringAndGradientName = vpImageFilter::vpCannyFilteringAndGradientTypeToString(detector.m_filteringAndGradientType);
219218
filteringAndGradientName = j.value("filteringAndGradientType", filteringAndGradientName);
@@ -233,10 +232,10 @@ class VISP_EXPORT vpCannyEdgeDetection
233232
* \param[out] j : A JSON parser object.
234233
* \param[in] detector : The vpCannyEdgeDetection object that must be parsed into JSON format.
235234
*/
236-
friend inline void to_json(json &j, const vpCannyEdgeDetection &detector)
235+
friend inline void to_json(nlohmann::json &j, const vpCannyEdgeDetection &detector)
237236
{
238237
std::string filteringAndGradientName = vpImageFilter::vpCannyFilteringAndGradientTypeToString(detector.m_filteringAndGradientType);
239-
j = json {
238+
j = nlohmann::json {
240239
{"filteringAndGradientType", filteringAndGradientName},
241240
{"gaussianSize", detector.m_gaussianKernelSize},
242241
{"gaussianStdev", detector.m_gaussianStdev},

modules/core/src/image/vpCannyEdgeDetection.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ vpCannyEdgeDetection::vpCannyEdgeDetection(const int &gaussianKernelSize, const
9191
}
9292

9393
#ifdef VISP_HAVE_NLOHMANN_JSON
94+
95+
using json = nlohmann::json;
96+
9497
vpCannyEdgeDetection::vpCannyEdgeDetection(const std::string &jsonPath)
9598
{
9699
initFromJSON(jsonPath);

modules/detection/include/visp3/detection/vpDetectorDNNOpenCV.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
#include <optional>
5555
#ifdef VISP_HAVE_NLOHMANN_JSON
5656
#include <nlohmann/json.hpp>
57-
using json = nlohmann::json; //! json namespace shortcut
5857
#endif
5958

6059
/*!
@@ -201,7 +200,7 @@ class VISP_EXPORT vpDetectorDNNOpenCV
201200
* \param j The JSON object, resulting from the parsing of a JSON file.
202201
* \param config The configuration of the network, that will be initialized from the JSON data.
203202
*/
204-
friend inline void from_json(const json &j, NetConfig &config)
203+
friend inline void from_json(const nlohmann::json &j, NetConfig &config)
205204
{
206205
config.m_confThreshold = j.value("confidenceThreshold", config.m_confThreshold);
207206
if (config.m_confThreshold <= 0) {
@@ -241,11 +240,11 @@ class VISP_EXPORT vpDetectorDNNOpenCV
241240
* \param j A JSON parser object.
242241
* \param config The vpDetectorDNNOpenCV::NetConfig that must be parsed into JSON format.
243242
*/
244-
friend inline void to_json(json &j, const NetConfig &config)
243+
friend inline void to_json(nlohmann::json &j, const NetConfig &config)
245244
{
246245
std::pair<unsigned int, unsigned int> resolution = { config.m_inputSize.width, config.m_inputSize.height };
247246
std::vector<double> v_mean = { config.m_mean[0], config.m_mean[1], config.m_mean[2] };
248-
j = json {
247+
j = nlohmann::json {
249248
{"confidenceThreshold", config.m_confThreshold } ,
250249
{"nmsThreshold" , config.m_nmsThreshold } ,
251250
{"filterSizeRatio" , config.m_filterSizeRatio} ,
@@ -515,7 +514,7 @@ class VISP_EXPORT vpDetectorDNNOpenCV
515514
* \param j The JSON object, resulting from the parsing of a JSON file.
516515
* \param network The network, that will be initialized from the JSON data.
517516
*/
518-
friend inline void from_json(const json &j, vpDetectorDNNOpenCV &network)
517+
friend inline void from_json(const nlohmann::json &j, vpDetectorDNNOpenCV &network)
519518
{
520519
network.m_netConfig = j.value("networkSettings", network.m_netConfig);
521520
}
@@ -526,9 +525,9 @@ class VISP_EXPORT vpDetectorDNNOpenCV
526525
* \param j The JSON parser.
527526
* \param network The network we want to parse the configuration.
528527
*/
529-
friend inline void to_json(json &j, const vpDetectorDNNOpenCV &network)
528+
friend inline void to_json(nlohmann::json &j, const vpDetectorDNNOpenCV &network)
530529
{
531-
j = json {
530+
j = nlohmann::json {
532531
{"networkSettings", network.m_netConfig}
533532
};
534533
}

modules/detection/src/dnn/vpDetectorDNNOpenCV.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ vpDetectorDNNOpenCV::vpDetectorDNNOpenCV(const NetConfig &config, const DNNResul
170170
}
171171

172172
#ifdef VISP_HAVE_NLOHMANN_JSON
173+
174+
using json = nlohmann::json;
175+
173176
/**
174177
* \brief Construct a new vpDetectorDNNOpenCV object from a JSON file and a potential parsing method.
175178
*

modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
// 3rd parties inclue
4646
#ifdef VISP_HAVE_NLOHMANN_JSON
4747
#include <nlohmann/json.hpp>
48-
using json = nlohmann::json;
4948
#endif
5049

5150
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17)
@@ -496,6 +495,8 @@ class VISP_EXPORT vpCircleHoughTransform
496495
*/
497496
inline static vpCircleHoughTransformParameters createFromJSON(const std::string &jsonFile)
498497
{
498+
using json = nlohmann::json;
499+
499500
std::ifstream file(jsonFile);
500501
if (!file.good()) {
501502
std::stringstream ss;
@@ -528,6 +529,7 @@ class VISP_EXPORT vpCircleHoughTransform
528529
*/
529530
inline void saveConfigurationInJSON(const std::string &jsonPath) const
530531
{
532+
using json = nlohmann::json;
531533
std::ofstream file(jsonPath);
532534
const json j = *this;
533535
file << j.dump(4);
@@ -541,7 +543,7 @@ class VISP_EXPORT vpCircleHoughTransform
541543
* \param[in] j : The JSON object, resulting from the parsing of a JSON file.
542544
* \param[out] params : The circle Hough transform parameters that will be initialized from the JSON data.
543545
*/
544-
friend inline void from_json(const json &j, vpCircleHoughTransformParameters &params)
546+
friend inline void from_json(const nlohmann::json &j, vpCircleHoughTransformParameters &params)
545547
{
546548
std::string filteringAndGradientName = vpImageFilter::vpCannyFilteringAndGradientTypeToString(params.m_filteringAndGradientType);
547549
filteringAndGradientName = j.value("filteringAndGradientType", filteringAndGradientName);
@@ -619,11 +621,11 @@ class VISP_EXPORT vpCircleHoughTransform
619621
* \param[out] j : A JSON parser object.
620622
* \param[in] params : The circle Hough transform parameters that will be serialized in the json object.
621623
*/
622-
friend inline void to_json(json &j, const vpCircleHoughTransformParameters &params)
624+
friend inline void to_json(nlohmann::json &j, const vpCircleHoughTransformParameters &params)
623625
{
624626
std::pair<unsigned int, unsigned int> radiusLimits = { params.m_minRadius, params.m_maxRadius };
625627

626-
j = json {
628+
j = nlohmann::json {
627629
{"filteringAndGradientType", vpImageFilter::vpCannyFilteringAndGradientTypeToString(params.m_filteringAndGradientType)},
628630
{"gaussianKernelSize", params.m_gaussianKernelSize},
629631
{"gaussianStdev", params.m_gaussianStdev},
@@ -760,7 +762,7 @@ class VISP_EXPORT vpCircleHoughTransform
760762
* \param[in] j The JSON object, resulting from the parsing of a JSON file.
761763
* \param[out] detector The detector, that will be initialized from the JSON data.
762764
*/
763-
friend inline void from_json(const json &j, vpCircleHoughTransform &detector)
765+
friend inline void from_json(const nlohmann::json &j, vpCircleHoughTransform &detector)
764766
{
765767
detector.m_algoParams = j;
766768
}
@@ -771,7 +773,7 @@ class VISP_EXPORT vpCircleHoughTransform
771773
* \param[out] j A JSON parser object.
772774
* \param[in] detector The vpCircleHoughTransform that must be parsed into JSON format.
773775
*/
774-
friend inline void to_json(json &j, const vpCircleHoughTransform &detector)
776+
friend inline void to_json(nlohmann::json &j, const vpCircleHoughTransform &detector)
775777
{
776778
j = detector.m_algoParams;
777779
}

modules/imgproc/src/vpCircleHoughTransform.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ vpCircleHoughTransform::~vpCircleHoughTransform()
123123
{ }
124124

125125
#ifdef VISP_HAVE_NLOHMANN_JSON
126+
using json = nlohmann::json;
127+
126128
vpCircleHoughTransform::vpCircleHoughTransform(const std::string &jsonPath)
127129
{
128130
initFromJSON(jsonPath);

0 commit comments

Comments
 (0)