Skip to content

Commit

Permalink
[CORE] Moved back the operators in the visp workspace (see https://st…
Browse files Browse the repository at this point in the history
  • Loading branch information
rlagneau committed May 27, 2024
1 parent d3b2501 commit b0563c2
Show file tree
Hide file tree
Showing 84 changed files with 563 additions and 914 deletions.
141 changes: 63 additions & 78 deletions modules/core/include/visp3/core/vpArray2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ template <typename T> class vpArray2D;
}
#endif

template<class T>
std::ostream &operator<<(std::ostream &s, const VISP_NAMESPACE_ADDRESSING vpArray2D<T> &A);

#ifdef VISP_HAVE_NLOHMANN_JSON
#include <nlohmann/json.hpp>
//template<typename Type>
Expand Down Expand Up @@ -623,7 +620,30 @@ template <class Type> class vpArray2D
Writes the given array to the output stream and returns a reference to the
output stream.
*/
friend std::ostream &::operator<< <>(std::ostream &s, const vpArray2D<Type> &A);
friend std::ostream &operator<<(std::ostream &s, const vpArray2D<Type> &A)
{
if (A.data == nullptr || A.size() == 0) {
return s;
}
std::ios_base::fmtflags original_flags = s.flags();

s.precision(10);
for (unsigned int i = 0; i < A.getRows(); i++) {
for (unsigned int j = 0; j < A.getCols() - 1; j++) {
s << A[i][j] << " ";
}
// We don't add " " after the last row element
s << A[i][A.getCols() - 1];
// We don't add a \n char on the end of the last array line
if (i < A.getRows() - 1) {
s << std::endl;
}
}

s.flags(original_flags); // restore s to standard state

return s;
}

vpArray2D<Type> hadamard(const vpArray2D<Type> &m) const;

Expand Down Expand Up @@ -910,48 +930,49 @@ template <class Type> class vpArray2D
file.close();
return true;
}
/*!
Save an array in a YAML-formatted file.
\param filename : absolute file name.
\param A : array to be saved in the file.
\param header : optional lines that will be saved at the beginning of the
file. Should be YAML-formatted and will adapt to the indentation if any.

\return Returns true if success.
Here is an example of outputs.
\code
vpArray2D<double> M(3,4);
vpArray2D::saveYAML("matrix.yml", M, "example: a YAML-formatted header");
vpArray2D::saveYAML("matrixIndent.yml", M, "example:\n - a YAML-formatted \
header\n - with inner indentation");
\endcode
Content of matrix.yml:
\code
example: a YAML-formatted header
rows: 3
cols: 4
data:
- [0, 0, 0, 0]
- [0, 0, 0, 0]
- [0, 0, 0, 0]
\endcode
Content of matrixIndent.yml:
\code
example:
- a YAML-formatted header
- with inner indentation
rows: 3
cols: 4
data:
/*!
Save an array in a YAML-formatted file.
\param filename : absolute file name.
\param A : array to be saved in the file.
\param header : optional lines that will be saved at the beginning of the
file. Should be YAML-formatted and will adapt to the indentation if any.
\return Returns true if success.
Here is an example of outputs.
\code
vpArray2D<double> M(3,4);
vpArray2D::saveYAML("matrix.yml", M, "example: a YAML-formatted header");
vpArray2D::saveYAML("matrixIndent.yml", M, "example:\n - a YAML-formatted \
header\n - with inner indentation");
\endcode
Content of matrix.yml:
\code
example: a YAML-formatted header
rows: 3
cols: 4
data:
- [0, 0, 0, 0]
- [0, 0, 0, 0]
- [0, 0, 0, 0]
\endcode
\sa loadYAML()
*/
\endcode
Content of matrixIndent.yml:
\code
example:
- a YAML-formatted header
- with inner indentation
rows: 3
cols: 4
data:
- [0, 0, 0, 0]
- [0, 0, 0, 0]
- [0, 0, 0, 0]
\endcode
\sa loadYAML()
*/
static bool saveYAML(const std::string &filename, const vpArray2D<Type> &A, const char *header = "")
{
std::fstream file;
Expand Down Expand Up @@ -1079,42 +1100,6 @@ template <class Type> class vpArray2D
static void insert(const vpArray2D<Type> &A, const vpArray2D<Type> &B, vpArray2D<Type> &C, unsigned int r, unsigned int c);
//@}
};
#if defined(ENABLE_VISP_NAMESPACE)
}
#endif

template <class Type>
std::ostream &operator<<(std::ostream &s, const VISP_NAMESPACE_ADDRESSING vpArray2D<Type> &A)
{
if ((A.data == nullptr) || (A.size() == 0)) {
return s;
}
std::ios_base::fmtflags original_flags = s.flags();

s.precision(10);
unsigned int a_rows = A.getRows();
unsigned int a_cols = A.getCols();
for (unsigned int i = 0; i < a_rows; ++i) {
for (unsigned int j = 0; j < (a_cols - 1); ++j) {
s << A[i][j] << " ";
}
// We don't add " " after the last row element
s << A[i][a_cols - 1];
// We don't add a \n char on the end of the last array line
if (i < (a_rows - 1)) {
s << std::endl;
}
}

s.flags(original_flags); // restore s to standard state

return s;
}

#if defined(ENABLE_VISP_NAMESPACE)
namespace VISP_NAMESPACE_NAME
{
#endif

/*!
Return the array min value.
Expand Down
5 changes: 1 addition & 4 deletions modules/core/include/visp3/core/vpCameraParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ class vpCameraParameters;
}
#endif

// Forward declaration to have the operator in the global namespace
std::ostream &operator<<(std::ostream &os, const VISP_NAMESPACE_ADDRESSING vpCameraParameters &cam);

#ifdef VISP_HAVE_NLOHMANN_JSON
#include<nlohmann/json.hpp>
// Forward declaration to have the to_json in the global namespace
Expand Down Expand Up @@ -438,7 +435,7 @@ class VISP_EXPORT
vpMatrix get_K_inverse() const;

void printParameters();
friend VISP_EXPORT std::ostream &::operator<<(std::ostream &os, const vpCameraParameters &cam);
friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpCameraParameters &cam);

private:
static const double DEFAULT_U0_PARAMETER;
Expand Down
10 changes: 6 additions & 4 deletions modules/core/include/visp3/core/vpColVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -1481,17 +1481,19 @@ vpColVector: public vpArray2D<double>
namespace VISP_NAMESPACE_NAME
{
#endif
#if defined(ENABLE_VISP_NAMESPACE)
}
#endif

/*!
* \relates vpColVector
* Allows to multiply a scalar by a column vector.
*/
#ifndef DOXYGEN_SHOULD_SKIP_THIS
VISP_EXPORT
#endif
vpColVector operator*(const double &x, const vpColVector &v);
#if defined(ENABLE_VISP_NAMESPACE)
}
#endif
VISP_NAMESPACE_ADDRESSING vpColVector operator*(const double &x, const VISP_NAMESPACE_ADDRESSING vpColVector &v);


#ifdef VISP_HAVE_NLOHMANN_JSON
inline void to_json(nlohmann::json &j,
Expand Down
17 changes: 2 additions & 15 deletions modules/core/include/visp3/core/vpColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpRGBa.h>

#if defined(ENABLE_VISP_NAMESPACE)
namespace VISP_NAMESPACE_NAME
{
#endif
class vpColor;
#if defined(ENABLE_VISP_NAMESPACE)
}
#endif

// Forward declaration to ensure that the operators are in the global namespace
bool operator==(const VISP_NAMESPACE_ADDRESSING vpColor &c1, const VISP_NAMESPACE_ADDRESSING vpColor &c2);
bool operator!=(const VISP_NAMESPACE_ADDRESSING vpColor &c1, const VISP_NAMESPACE_ADDRESSING vpColor &c2);

#if defined(ENABLE_VISP_NAMESPACE)
namespace VISP_NAMESPACE_NAME
{
Expand Down Expand Up @@ -291,8 +278,8 @@ class VISP_EXPORT vpColor : public vpRGBa
/*! Default destructor. */
inline virtual ~vpColor() { }

friend VISP_EXPORT bool ::operator==(const vpColor &c1, const vpColor &c2);
friend VISP_EXPORT bool ::operator!=(const vpColor &c1, const vpColor &c2);
friend VISP_EXPORT bool operator==(const vpColor &c1, const vpColor &c2);
friend VISP_EXPORT bool operator!=(const vpColor &c1, const vpColor &c2);
/*!
Set a color from its RGB values.
Expand Down
13 changes: 1 addition & 12 deletions modules/core/include/visp3/core/vpException.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@
#include <stdarg.h>
#include <string>

#if defined(ENABLE_VISP_NAMESPACE)
namespace VISP_NAMESPACE_NAME
{
#endif
class vpException;
#if defined(ENABLE_VISP_NAMESPACE)
}
#endif

// Forward declaration to ensure that the operator is in the global namespace
std::ostream &operator<<(std::ostream &os, const VISP_NAMESPACE_ADDRESSING vpException &art);
#if defined(ENABLE_VISP_NAMESPACE)
namespace VISP_NAMESPACE_NAME
{
Expand Down Expand Up @@ -144,7 +133,7 @@ class VISP_EXPORT vpException : public std::exception
/*!
* Print the error structure.
*/
friend VISP_EXPORT std::ostream &::operator<<(std::ostream &os, const vpException &art);
friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpException &art);

protected:
//! Contains the error code, see the errorCodeEnum table for details.
Expand Down
13 changes: 1 addition & 12 deletions modules/core/include/visp3/core/vpHistogramPeak.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@

#include <ostream>

#if defined(ENABLE_VISP_NAMESPACE)
namespace VISP_NAMESPACE_NAME
{
#endif
class vpHistogramPeak;
#if defined(ENABLE_VISP_NAMESPACE)
}
#endif

std::ostream &operator<<(std::ostream &s, const VISP_NAMESPACE_ADDRESSING vpHistogramPeak &p);

#if defined(ENABLE_VISP_NAMESPACE)
namespace VISP_NAMESPACE_NAME
{
Expand Down Expand Up @@ -148,7 +137,7 @@ class VISP_EXPORT vpHistogramPeak
//---------------------------------
// Printing
//---------------------------------
friend VISP_EXPORT std::ostream &::operator<<(std::ostream &s, const vpHistogramPeak &p);
friend VISP_EXPORT std::ostream &operator<<(std::ostream &s, const vpHistogramPeak &p);

protected:
unsigned char level; //! Gray level ot the peak.
Expand Down
13 changes: 1 addition & 12 deletions modules/core/include/visp3/core/vpHistogramValey.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@

#include <visp3/core/vpHistogramPeak.h>

#if defined(ENABLE_VISP_NAMESPACE)
namespace VISP_NAMESPACE_NAME
{
#endif
class vpHistogramValey;
#if defined(ENABLE_VISP_NAMESPACE)
}
#endif

std::ostream &operator<<(std::ostream &s, const VISP_NAMESPACE_ADDRESSING vpHistogramValey &v);

#if defined(ENABLE_VISP_NAMESPACE)
namespace VISP_NAMESPACE_NAME
{
Expand Down Expand Up @@ -146,7 +135,7 @@ class VISP_EXPORT vpHistogramValey : vpHistogramPeak
//---------------------------------
// Printing
//---------------------------------
friend VISP_EXPORT std::ostream &::operator<<(std::ostream &s, const vpHistogramValey &v);
friend VISP_EXPORT std::ostream &operator<<(std::ostream &s, const vpHistogramValey &v);
};

/*
Expand Down
Loading

0 comments on commit b0563c2

Please sign in to comment.