Skip to content

Commit

Permalink
Start introduction of visp namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed May 21, 2024
1 parent b908bbd commit 796cfac
Show file tree
Hide file tree
Showing 248 changed files with 3,488 additions and 1,377 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ VP_OPTION(ENABLE_MOMENTS_COMBINE_MATRICES "" "" "Use linear combination of matr
VP_OPTION(ENABLE_TEST_WITHOUT_DISPLAY "" "" "Don't use display feature when testing" "" ON)
VP_OPTION(ENABLE_FULL_DOC "" "" "Build doc with internal classes that are by default not part of the doc" "" OFF)

# Allow introduction of "visp" namespace. By default disabled to keep compat with previous versions
VP_OPTION(ENABLE_VISP_NAMESPACE "" "" "Enable visp namespace" "" OFF)

if(ENABLE_SOLUTION_FOLDERS)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
Expand Down Expand Up @@ -1603,6 +1606,7 @@ status(" To be built:" VISP_MODULES_BUILD THEN ${VISP_MOD
status(" Disabled:" VISP_MODULES_DISABLED_USER THEN ${VISP_MODULES_DISABLED_USER_ST} ELSE "-")
status(" Disabled by dependency:" VISP_MODULES_DISABLED_AUTO THEN ${VISP_MODULES_DISABLED_AUTO_ST} ELSE "-")
status(" Unavailable:" VISP_MODULES_DISABLED_FORCE THEN ${VISP_MODULES_DISABLED_FORCE_ST} ELSE "-")
status(" Enable visp namespace:" ENABLE_VISP_NAMESPACE THEN "yes" ELSE "no")

# ========================== Android details ==========================
if(ANDROID)
Expand Down
1 change: 1 addition & 0 deletions cmake/templates/VISPConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ set(VISP_BIN_INSTALL_PATH "@VISP_BIN_INSTALL_PATH@")
#----------------------------------------------------------------------
# Remember VISP third party libs configuration
#----------------------------------------------------------------------
set(ENABLE_VISP_NAMESPACE "@ENABLE_VISP_NAMESPACE@")
set(VISP_HAVE_AFMA4 "@VISP_HAVE_AFMA4@")
set(VISP_HAVE_AFMA6 "@VISP_HAVE_AFMA6@")
set(VISP_HAVE_APRILTAG "@VISP_HAVE_APRILTAG@")
Expand Down
3 changes: 3 additions & 0 deletions cmake/templates/vpConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
VISP_VERSION_MINOR, \
VISP_VERSION_PATCH)

// Defined if the user wants to protect the classes in a dedicated visp namespace
#cmakedefine ENABLE_VISP_NAMESPACE

// Enable debug and trace printings
#cmakedefine VP_TRACE
#cmakedefine VP_DEBUG
Expand Down
54 changes: 47 additions & 7 deletions modules/core/include/visp3/core/vpArray2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,23 @@
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpException.h>

#if defined(ENABLE_VISP_NAMESPACE)
namespace visp
{
template <typename T> class vpArray2D;
}
#endif

#ifdef VISP_HAVE_NLOHMANN_JSON
#include <nlohmann/json.hpp>
#if defined(ENABLE_VISP_NAMESPACE)
//template<typename Type>
template<class T>
void from_json(const nlohmann::json &j, visp::vpArray2D<T> &array);
//template<typename Type>
template<class T>
void to_json(nlohmann::json &j, const visp::vpArray2D<T> &array);
#endif
#endif

/*!
Expand Down Expand Up @@ -122,7 +137,11 @@
* }
* \endcode
*/
template <class Type> class vpArray2D
template <class Type> class
#if defined(ENABLE_VISP_NAMESPACE)
visp::
#endif
vpArray2D
{
protected:
//! Number of rows in the array
Expand Down Expand Up @@ -1018,10 +1037,10 @@ template <class Type> class vpArray2D
#ifdef VISP_HAVE_NLOHMANN_JSON
//template<typename Type>
template<class T>
friend void from_json(const nlohmann::json &j, vpArray2D<T> &array);
friend void ::from_json(const nlohmann::json &j, vpArray2D<T> &array);
//template<typename Type>
template<class T>
friend void to_json(nlohmann::json &j, const vpArray2D<T> &array);
friend void ::to_json(nlohmann::json &j, const vpArray2D<T> &array);
#endif

/*!
Expand Down Expand Up @@ -1082,6 +1101,11 @@ template <class Type> class vpArray2D
//@}
};

#if defined(ENABLE_VISP_NAMESPACE)
namespace visp
{
#endif

/*!
Return the array min value.
*/
Expand Down Expand Up @@ -1323,13 +1347,23 @@ template <> inline bool vpArray2D<float>::operator==(const vpArray2D<float> &A)
* \relates vpArray2D
*/
template <class Type> bool vpArray2D<Type>::operator!=(const vpArray2D<Type> &A) const { return !(*this == A); }
#if defined(ENABLE_VISP_NAMESPACE)
}
#endif

#ifdef VISP_HAVE_NLOHMANN_JSON


template <class Type>
inline void from_json(const nlohmann::json &j, vpArray2D<Type> &array)
inline void from_json(const nlohmann::json &j,
#if defined(ENABLE_VISP_NAMESPACE)
visp::vpArray2D<Type> &array
#else
vpArray2D<Type> &array
#endif
)
{
#if defined(ENABLE_VISP_NAMESPACE)
using namespace visp;
#endif
if (j.is_array()) {
const unsigned int nrows = static_cast<unsigned int>(j.size());
if (nrows == 0) { // Initialize an empty array, Finished
Expand Down Expand Up @@ -1381,7 +1415,13 @@ inline void from_json(const nlohmann::json &j, vpArray2D<Type> &array)


template <class Type>
inline void to_json(nlohmann::json &j, const vpArray2D<Type> &array)
inline void to_json(nlohmann::json &j,
#if defined(ENABLE_VISP_NAMESPACE)
const visp::vpArray2D<Type> &array
#else
const vpArray2D<Type> &array
#endif
)
{
j = {
{"cols", array.colNum},
Expand Down
14 changes: 10 additions & 4 deletions modules/core/include/visp3/core/vpCPUFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@
* CPU features (hardware capabilities).
*/

#ifndef _vpCPUFeatures_h_
#define _vpCPUFeatures_h_

/*!
\file vpCPUFeatures.h
\brief Check CPU features (hardware capabilities).
*/

#ifndef _vpCPUFeatures_h_
#define _vpCPUFeatures_h_

#include <visp3/core/vpConfig.h>

#if defined(ENABLE_VISP_NAMESPACE)
namespace visp
{
#endif
/*!
\ingroup group_core_cpu_features
\brief Check CPU features (hardware capabilities).
Expand Down Expand Up @@ -77,5 +81,7 @@ VISP_EXPORT size_t getCPUCacheL3();
#endif
VISP_EXPORT void printCPUInfo();
} // namespace vpCPUFeatures

#if defined(ENABLE_VISP_NAMESPACE)
}
#endif
#endif
53 changes: 47 additions & 6 deletions modules/core/include/visp3/core/vpCameraParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,19 @@
#include <visp3/core/vpDebug.h>
#include <visp3/core/vpMatrix.h>

#if defined(ENABLE_VISP_NAMESPACE)
namespace visp
{
class vpCameraParameters;
}
#endif

#ifdef VISP_HAVE_NLOHMANN_JSON
#include<nlohmann/json.hpp>
#if defined(ENABLE_VISP_NAMESPACE)
void to_json(nlohmann::json &j, const visp::vpCameraParameters &cam);
void from_json(const nlohmann::json &j, visp::vpCameraParameters &cam);
#endif
#endif

/*!
Expand Down Expand Up @@ -300,7 +311,12 @@
{"model":"perspectiveWithoutDistortion","px":801.0,"py":802.0,"u0":325.0,"v0":245.0}
\endcode
*/
class VISP_EXPORT vpCameraParameters

class VISP_EXPORT
#if defined(ENABLE_VISP_NAMESPACE)
visp::
#endif
vpCameraParameters
{
friend class vpMeterPixelConversion;
friend class vpPixelMeterConversion;
Expand Down Expand Up @@ -442,27 +458,44 @@ class VISP_EXPORT vpCameraParameters

vpCameraParametersProjType m_projModel; //!< used projection model
#ifdef VISP_HAVE_NLOHMANN_JSON
friend void to_json(nlohmann::json &j, const vpCameraParameters &cam);
friend void from_json(const nlohmann::json &j, vpCameraParameters &cam);
friend void ::to_json(nlohmann::json &j, const vpCameraParameters &cam);
friend void ::from_json(const nlohmann::json &j, vpCameraParameters &cam);
#endif
};

#ifdef VISP_HAVE_NLOHMANN_JSON
#include<nlohmann/json.hpp>
#if defined(ENABLE_VISP_NAMESPACE)
NLOHMANN_JSON_SERIALIZE_ENUM(visp::vpCameraParameters::vpCameraParametersProjType, {
{visp::vpCameraParameters::perspectiveProjWithoutDistortion, "perspectiveWithoutDistortion"},
{visp::vpCameraParameters::perspectiveProjWithDistortion, "perspectiveWithDistortion"},
{visp::vpCameraParameters::ProjWithKannalaBrandtDistortion, "kannalaBrandtDistortion"}
});
#else
NLOHMANN_JSON_SERIALIZE_ENUM(vpCameraParameters::vpCameraParametersProjType, {
{vpCameraParameters::perspectiveProjWithoutDistortion, "perspectiveWithoutDistortion"},
{vpCameraParameters::perspectiveProjWithDistortion, "perspectiveWithDistortion"},
{vpCameraParameters::ProjWithKannalaBrandtDistortion, "kannalaBrandtDistortion"}
});
#endif

/**
* \brief Converts camera parameters into a JSON representation.
* \sa from_json() for more information on the content.
* \param j The resulting JSON object.
* \param cam The camera to serialize.
*/
inline void to_json(nlohmann::json &j, const vpCameraParameters &cam)
inline void to_json(nlohmann::json &j,
#if defined(ENABLE_VISP_NAMESPACE)
const visp::vpCameraParameters &cam
#else
const vpCameraParameters &cam
#endif
)
{
#if defined(ENABLE_VISP_NAMESPACE)
using namespace visp;
#endif
j["px"] = cam.m_px;
j["py"] = cam.m_py;
j["u0"] = cam.m_u0;
Expand Down Expand Up @@ -514,8 +547,17 @@ inline void to_json(nlohmann::json &j, const vpCameraParameters &cam)
* \param j The json object to deserialize.
* \param cam The modified camera.
*/
inline void from_json(const nlohmann::json &j, vpCameraParameters &cam)
inline void from_json(const nlohmann::json &j,
#if defined(ENABLE_VISP_NAMESPACE)
visp::vpCameraParameters &cam
#else
vpCameraParameters &cam
#endif
)
{
#if defined(ENABLE_VISP_NAMESPACE)
using namespace visp;
#endif
const double px = j.at("px").get<double>();
const double py = j.at("py").get<double>();
const double u0 = j.at("u0").get<double>();
Expand Down Expand Up @@ -544,5 +586,4 @@ inline void from_json(const nlohmann::json &j, vpCameraParameters &cam)
}
}
#endif

#endif
Loading

0 comments on commit 796cfac

Please sign in to comment.