From d53670c1b9a5246c21942c483241a72033790a3f Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Fri, 21 Jun 2024 11:46:26 +0200 Subject: [PATCH 01/11] Reduce file length to comply with misra c++ quality rules --- modules/core/include/visp3/core/vpImage.h | 1659 +----- .../core/include/visp3/core/vpImageFilter.h | 304 +- .../core/include/visp3/core/vpImageTools.h | 755 +-- .../include/visp3/core/vpImageTools_warp.h | 729 +++ .../core/include/visp3/core/vpImage_getters.h | 1097 ++++ modules/core/include/visp3/core/vpImage_lut.h | 347 ++ .../include/visp3/core/vpImage_operators.h | 278 + modules/core/src/image/vpImageConvert.cpp | 763 --- .../core/src/image/vpImageConvert_opencv.cpp | 519 ++ .../core/src/image/vpImageConvert_yarp.cpp | 327 ++ modules/core/src/image/vpImageFilter.cpp | 466 +- .../core/src/image/vpImageFilter_canny.cpp | 486 ++ modules/core/src/image/vpImageFilter_xy.cpp | 314 ++ .../matrix/private/vpMatrix_pseudo_inverse.h | 51 + .../src/math/matrix/vpEigenConversion.cpp | 3 +- modules/core/src/math/matrix/vpMatrix.cpp | 4984 +---------------- modules/core/src/math/matrix/vpMatrix_lu.cpp | 3 +- modules/core/src/math/matrix/vpMatrix_mul.cpp | 3 +- .../src/math/matrix/vpMatrix_operations.cpp | 890 +++ .../src/math/matrix/vpMatrix_operators.cpp | 668 +++ .../math/matrix/vpMatrix_pseudo_inverse.cpp | 973 ++++ .../matrix/vpMatrix_pseudo_inverse_eigen.cpp | 670 +++ .../matrix/vpMatrix_pseudo_inverse_lapack.cpp | 685 +++ .../matrix/vpMatrix_pseudo_inverse_opencv.cpp | 672 +++ .../core/src/math/matrix/vpMatrix_stack.cpp | 357 ++ modules/core/src/math/matrix/vpMatrix_svd.cpp | 191 +- modules/core/src/math/matrix/vpRowVector.cpp | 3 +- modules/core/src/tools/endian/vpEndian.cpp | 18 +- modules/core/src/tools/file/vpIoTools.cpp | 1134 +--- .../src/tools/file/vpIoTools_config_file.cpp | 643 +++ modules/core/src/tools/file/vpIoTools_npy.cpp | 437 ++ .../core/src/tools/histogram/vpHistogram.cpp | 4 +- modules/core/test/image/testImageGetValue.cpp | 8 +- modules/tracker/blob/src/dots/vpDot2.cpp | 719 +-- .../tracker/blob/src/dots/vpDot2_freeman.cpp | 472 ++ .../tracker/blob/src/dots/vpDot2_search.cpp | 307 + .../me/src/moving-edges/vpMeEllipse.cpp | 495 -- .../moving-edges/vpMeEllipse_least_square.cpp | 533 ++ 38 files changed, 11932 insertions(+), 11035 deletions(-) create mode 100644 modules/core/include/visp3/core/vpImageTools_warp.h create mode 100644 modules/core/include/visp3/core/vpImage_getters.h create mode 100644 modules/core/include/visp3/core/vpImage_lut.h create mode 100644 modules/core/include/visp3/core/vpImage_operators.h create mode 100644 modules/core/src/image/vpImageConvert_opencv.cpp create mode 100644 modules/core/src/image/vpImageConvert_yarp.cpp create mode 100644 modules/core/src/image/vpImageFilter_canny.cpp create mode 100644 modules/core/src/image/vpImageFilter_xy.cpp create mode 100644 modules/core/src/math/matrix/private/vpMatrix_pseudo_inverse.h create mode 100644 modules/core/src/math/matrix/vpMatrix_operations.cpp create mode 100644 modules/core/src/math/matrix/vpMatrix_operators.cpp create mode 100644 modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp create mode 100644 modules/core/src/math/matrix/vpMatrix_pseudo_inverse_eigen.cpp create mode 100644 modules/core/src/math/matrix/vpMatrix_pseudo_inverse_lapack.cpp create mode 100644 modules/core/src/math/matrix/vpMatrix_pseudo_inverse_opencv.cpp create mode 100644 modules/core/src/math/matrix/vpMatrix_stack.cpp create mode 100644 modules/core/src/tools/file/vpIoTools_config_file.cpp create mode 100644 modules/core/src/tools/file/vpIoTools_npy.cpp create mode 100644 modules/tracker/blob/src/dots/vpDot2_freeman.cpp create mode 100644 modules/tracker/blob/src/dots/vpDot2_search.cpp create mode 100644 modules/tracker/me/src/moving-edges/vpMeEllipse_least_square.cpp diff --git a/modules/core/include/visp3/core/vpImage.h b/modules/core/include/visp3/core/vpImage.h index 71db936cbe..313740cafa 100644 --- a/modules/core/include/visp3/core/vpImage.h +++ b/modules/core/include/visp3/core/vpImage.h @@ -361,273 +361,9 @@ template class vpImage bool hasOwnership; ///! true if this instance owns the bitmap, false otherwise (e.g. copyData=false) }; -template std::ostream &operator<<(std::ostream &s, const vpImage &I) -{ - if (I.bitmap == nullptr) { - return s; - } - - unsigned int i_height = I.getHeight(); - unsigned int i_width = I.getWidth(); - for (unsigned int i = 0; i < i_height; ++i) { - for (unsigned int j = 0; j < (i_width - 1); ++j) { - s << I[i][j] << " "; - } - - // We don't add " " after the last column element - s << I[i][i_width - 1]; - - // We don't add a \n character at the end of the last row line - if (i < (i_height - 1)) { - s << std::endl; - } - } - - return s; -} - -inline std::ostream &operator<<(std::ostream &s, const vpImage &I) -{ - if (I.bitmap == nullptr) { - return s; - } - - std::ios_base::fmtflags original_flags = s.flags(); - - unsigned int i_height = I.getHeight(); - unsigned int i_width = I.getWidth(); - for (unsigned int i = 0; i < i_height; ++i) { - for (unsigned int j = 0; j < (i_width - 1); ++j) { - s << std::setw(3) << static_cast(I[i][j]) << " "; - } - - // We don't add " " after the last column element - s << std::setw(3) << static_cast(I[i][I.getWidth() - 1]); - - // We don't add a \n character at the end of the last row line - if (i < (i_height - 1)) { - s << std::endl; - } - } - - s.flags(original_flags); // restore s to standard state - return s; -} - -inline std::ostream &operator<<(std::ostream &s, const vpImage &I) -{ - if (I.bitmap == nullptr) { - return s; - } - - std::ios_base::fmtflags original_flags = s.flags(); - - unsigned int i_height = I.getHeight(); - unsigned int i_width = I.getWidth(); - for (unsigned int i = 0; i < i_height; ++i) { - for (unsigned int j = 0; j < (i_width - 1); ++j) { - s << std::setw(4) << static_cast(I[i][j]) << " "; - } - - // We don't add " " after the last column element - s << std::setw(4) << static_cast(I[i][i_width - 1]); - - // We don't add a \n character at the end of the last row line - if (i < (i_height - 1)) { - s << std::endl; - } - } - - s.flags(original_flags); // restore s to standard state - return s; -} - -inline std::ostream &operator<<(std::ostream &s, const vpImage &I) -{ - if (I.bitmap == nullptr) { - return s; - } - - std::ios_base::fmtflags original_flags = s.flags(); - s.precision(9); // http://en.cppreference.com/w/cpp/types/numeric_limits/max_digits10 - - unsigned int i_height = I.getHeight(); - unsigned int i_width = I.getWidth(); - for (unsigned int i = 0; i < i_height; ++i) { - for (unsigned int j = 0; j < (i_width - 1); ++j) { - s << I[i][j] << " "; - } - - // We don't add " " after the last column element - s << I[i][i_width - 1]; - - // We don't add a \n character at the end of the last row line - if (i < (i_height - 1)) { - s << std::endl; - } - } - - s.flags(original_flags); // restore s to standard state - return s; -} - -inline std::ostream &operator<<(std::ostream &s, const vpImage &I) -{ - if (I.bitmap == nullptr) { - return s; - } - - std::ios_base::fmtflags original_flags = s.flags(); - s.precision(17); // http://en.cppreference.com/w/cpp/types/numeric_limits/max_digits10 - - unsigned int i_height = I.getHeight(); - unsigned int i_width = I.getWidth(); - for (unsigned int i = 0; i < i_height; ++i) { - for (unsigned int j = 0; j < (i_width - 1); ++j) { - s << I[i][j] << " "; - } - - // We don't add " " after the last column element - s << I[i][i_width - 1]; - - // We don't add a \n character at the end of the last row line - if (i < (i_height - 1)) { - s << std::endl; - } - } - - s.flags(original_flags); // restore s to standard state - return s; -} - -#if defined(VISP_HAVE_THREADS) -namespace -{ -struct vpImageLut_Param_t -{ - unsigned int m_start_index; - unsigned int m_end_index; - - unsigned char m_lut[256]; - unsigned char *m_bitmap; - - vpImageLut_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(nullptr) { } - - vpImageLut_Param_t(unsigned int start_index, unsigned int end_index, unsigned char *bitmap) - : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap) - { } -}; - -void performLutThread(vpImageLut_Param_t *imageLut_param) -{ - unsigned int start_index = imageLut_param->m_start_index; - unsigned int end_index = imageLut_param->m_end_index; - - unsigned char *bitmap = imageLut_param->m_bitmap; - - unsigned char *ptrStart = bitmap + start_index; - unsigned char *ptrEnd = bitmap + end_index; - unsigned char *ptrCurrent = ptrStart; - - if (end_index - start_index >= 8) { - // Unroll loop version - for (; ptrCurrent <= ptrEnd - 8;) { - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; - ++ptrCurrent; - - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; - ++ptrCurrent; - - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; - ++ptrCurrent; - - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; - ++ptrCurrent; - - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; - ++ptrCurrent; - - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; - ++ptrCurrent; - - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; - ++ptrCurrent; - - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; - ++ptrCurrent; - } - } - - for (; ptrCurrent != ptrEnd; ++ptrCurrent) { - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; - } -} - -struct vpImageLutRGBa_Param_t -{ - unsigned int m_start_index; - unsigned int m_end_index; - - VISP_NAMESPACE_ADDRESSING vpRGBa m_lut[256]; - unsigned char *m_bitmap; - - vpImageLutRGBa_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(nullptr) { } - - vpImageLutRGBa_Param_t(unsigned int start_index, unsigned int end_index, unsigned char *bitmap) - : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap) - { } -}; - -void performLutRGBaThread(vpImageLutRGBa_Param_t *imageLut_param) -{ - unsigned int start_index = imageLut_param->m_start_index; - unsigned int end_index = imageLut_param->m_end_index; - - unsigned char *bitmap = imageLut_param->m_bitmap; - - unsigned char *ptrStart = bitmap + start_index * 4; - unsigned char *ptrEnd = bitmap + end_index * 4; - unsigned char *ptrCurrent = ptrStart; - - if (end_index - start_index >= 4 * 2) { - // Unroll loop version - for (; ptrCurrent <= ptrEnd - 4 * 2;) { - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R; - ptrCurrent++; - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G; - ptrCurrent++; - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B; - ptrCurrent++; - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A; - ptrCurrent++; - - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R; - ptrCurrent++; - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G; - ptrCurrent++; - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B; - ptrCurrent++; - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A; - ptrCurrent++; - } - } - - while (ptrCurrent != ptrEnd) { - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R; - ptrCurrent++; - - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G; - ptrCurrent++; - - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B; - ptrCurrent++; - - *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A; - ptrCurrent++; - } -} -} // namespace -#endif +#include +#include +#include /*! \relates vpImage @@ -860,746 +596,30 @@ template vpImage::vpImage(const vpImage &I) : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true) { - resize(I.getHeight(), I.getWidth()); - if (bitmap) { - memcpy(static_cast(bitmap), static_cast(I.bitmap), I.npixels * sizeof(Type)); - } -} - -#if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher -/*! - \relates vpImage -*/ -template -vpImage::vpImage(vpImage &&I) - : bitmap(I.bitmap), display(I.display), npixels(I.npixels), width(I.width), height(I.height), row(I.row), - hasOwnership(I.hasOwnership) -{ - I.bitmap = nullptr; - I.display = nullptr; - I.npixels = 0; - I.width = 0; - I.height = 0; - I.row = nullptr; - I.hasOwnership = false; -} -#endif - -/*! - * \brief Return the maximum value within the bitmap - * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. - * If true, consider only finite values. - * - * \sa getMinValue() - */ -template Type vpImage::getMaxValue(bool onlyFiniteVal) const -{ - if (npixels == 0) { - throw(vpException(vpException::fatalError, "Cannot compute maximum value of an empty image")); - } - Type m = bitmap[0]; - for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] > m) { - m = bitmap[i]; - } - } - (void)onlyFiniteVal; - return m; -} - -/*! - * \relates vpImage - * \brief Return the maximum value within the double bitmap. - * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. - * If true, consider only finite values. - * - * \sa getMinValue() - */ -template <> inline double vpImage::getMaxValue(bool onlyFiniteVal) const -{ - if (npixels == 0) { - throw(vpException(vpException::fatalError, "Cannot compute maximum value of an empty image")); - } - double m = bitmap[0]; - if (onlyFiniteVal) { - for (unsigned int i = 0; i < npixels; ++i) { - if ((bitmap[i] > m) && (vpMath::isFinite(bitmap[i]))) { - m = bitmap[i]; - } - } - } - else { - for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] > m) { - m = bitmap[i]; - } - } - } - return m; -} - -/*! - * \relates vpImage - * \brief Return the maximum value within the float bitmap. - * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. - * If true, consider only finite values. - * - * \sa getMinValue() - */ -template <> inline float vpImage::getMaxValue(bool onlyFiniteVal) const -{ - if (npixels == 0) { - throw(vpException(vpException::fatalError, "Cannot compute maximum value of an empty image")); - } - float m = bitmap[0]; - if (onlyFiniteVal) { - for (unsigned int i = 0; i < npixels; ++i) { - if ((bitmap[i] > m) && (vpMath::isFinite(bitmap[i]))) { - m = bitmap[i]; - } - } - } - else { - for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] > m) { - m = bitmap[i]; - } - } - } - return m; -} - -/*! - * \brief Return the mean value of the bitmap. - * - * For vpRGBa and vpRGBf image types, the sum of image intensities is computed by (R+G+B). - * - * \param[in] p_mask Optional parameter. If not set to nullptr, a boolean mask that indicates which points must be - * considered, if set to true. - * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are - * valid according to the boolean mask or image size when `p_mask` is set to nullptr. - */ -template double vpImage::getMeanValue(const vpImage *p_mask, unsigned int *nbValidPoints) const -{ - if ((height == 0) || (width == 0)) { - return 0.0; - } - unsigned int nbPointsInMask = 0; - double sum = getSum(p_mask, &nbPointsInMask); - if (nbPointsInMask == 0) { - throw(vpException(vpException::divideByZeroError, "Division by zero in vpImage::getMeanValue()")); - } - if (nbValidPoints) { - *nbValidPoints = nbPointsInMask; - } - return sum / nbPointsInMask; -} - -/*! -* \brief Return the standard deviation of the bitmap -* -* - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: -* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] -* - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: -* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] -* -* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ -* is the number of pixels to consider in the mask. -* -* \param[in] p_mask A boolean mask that indicates which points must be considered, if set to true. -* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are -* valid according to the boolean mask or image size when `p_mask` is set to nullptr. -*/ -template double vpImage::getStdev(const vpImage *p_mask, unsigned int *nbValidPoints) const -{ - double mean = getMeanValue(p_mask, nbValidPoints); - return getStdev(mean, p_mask); -} - -/*! -* \brief Return the standard deviation of the bitmap -* -* - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: -* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] -* - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: -* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] -* -* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ -* is the number of pixels to consider in the mask. -* -* \param[in] mean The mean of the image. -* \param[in] p_mask Optional parameter. When different from nullptr, a boolean mask that indicates which pixels must -* be considered, if set to true. -* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are -* valid according to the boolean mask or image size when `p_mask` is set to nullptr. -* \return double The standard deviation taking into account only the points for which the mask is true. -*/ -template double vpImage::getStdev(const double &mean, const vpImage *p_mask, unsigned int *nbValidPoints) const -{ - if ((height == 0) || (width == 0)) { - return 0.0; - } - const unsigned int size = width * height; - double sum = 0.; - unsigned int nbPointsInMask = 0; - if (p_mask) { - if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { - throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); - } - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { - sum += (bitmap[i] - mean) * (bitmap[i] - mean); - ++nbPointsInMask; - } - } - } - else { - for (unsigned int i = 0; i < size; ++i) { - sum += (bitmap[i] - mean) * (bitmap[i] - mean); - } - nbPointsInMask = size; - } - sum /= static_cast(nbPointsInMask); - if (nbValidPoints) { - *nbValidPoints = nbPointsInMask; - } - return std::sqrt(sum); -} - -#ifndef DOXYGEN_SHOULD_SKIP_THIS -/*! -* \brief Return the standard deviation of the bitmap -* -* - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: -* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] -* - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: -* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] -* -* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ -* is the number of pixels to consider in the mask. -* -* \param[in] mean The mean of the image. -* \param[in] p_mask Optional parameter. When different from nullptr, a boolean mask that indicates which pixels must -* be considered, if set to true. -* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are -* valid according to the boolean mask or image size when `p_mask` is set to nullptr. -* \return double The standard deviation taking into account only the points for which the mask is true. -*/ -template <> inline double vpImage::getStdev(const double &mean, const vpImage *p_mask, unsigned int *nbValidPoints) const -{ - if ((height == 0) || (width == 0)) { - return 0.0; - } - const unsigned int size = width * height; - double sum = 0.; - unsigned int nbPointsInMask = 0; - if (p_mask) { - if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { - throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); - } - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { - double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - sum += (val - mean) * (val - mean); - ++nbPointsInMask; - } - } - } - else { - for (unsigned int i = 0; i < size; ++i) { - double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - sum += (val - mean) * (val - mean); - } - nbPointsInMask = size; - } - sum /= static_cast(nbPointsInMask); - if (nbValidPoints) { - *nbValidPoints = nbPointsInMask; - } - return std::sqrt(sum); -} - -/*! -* \brief Return the standard deviation of the bitmap -* -* - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: -* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] -* - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: -* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] -* -* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ -* is the number of pixels to consider in the mask. -* -* \param[in] mean The mean of the image. -* \param[in] p_mask Optional parameter. When different from nullptr, a boolean mask that indicates which pixels must -* be considered, if set to true. -* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are -* valid according to the boolean mask or image size when `p_mask` is set to nullptr. -* \return double The standard deviation taking into account only the points for which the mask is true. -*/ -template <> inline double vpImage::getStdev(const double &mean, const vpImage *p_mask, unsigned int *nbValidPoints) const -{ - if ((height == 0) || (width == 0)) { - return 0.0; - } - const unsigned int size = width * height; - double sum = 0.; - unsigned int nbPointsInMask = 0; - if (p_mask) { - if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { - throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); - } - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { - double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - sum += (val - mean) * (val - mean); - ++nbPointsInMask; - } - } - } - else { - for (unsigned int i = 0; i < size; ++i) { - double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - sum += (val - mean) * (val - mean); - } - nbPointsInMask = size; - } - sum /= static_cast(nbPointsInMask); - if (nbValidPoints) { - *nbValidPoints = nbPointsInMask; - } - return std::sqrt(sum); -} -#endif // DOXYGEN_SHOULD_SKIP_THIS - -/*! - * \brief Return the minimum value within the bitmap - * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. - * If true, consider only finite values. - * - * \sa getMaxValue() - */ -template Type vpImage::getMinValue(bool onlyFiniteVal) const -{ - if (npixels == 0) { - throw(vpException(vpException::fatalError, "Cannot compute minimum value of an empty image")); - } - Type m = bitmap[0]; - for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] < m) { - m = bitmap[i]; - } - } - (void)onlyFiniteVal; - return m; -} - -/*! - * \relates vpImage - * \brief Return the minimum value within the double bitmap. - * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. - * If true, consider only finite values. - * - * \sa getMaxValue() - */ -template <> inline double vpImage::getMinValue(bool onlyFiniteVal) const -{ - if (npixels == 0) { - throw(vpException(vpException::fatalError, "Cannot compute minimum value of an empty image")); - } - double m = bitmap[0]; - if (onlyFiniteVal) { - for (unsigned int i = 0; i < npixels; ++i) { - if ((bitmap[i] < m) && (vpMath::isFinite(bitmap[i]))) { - m = bitmap[i]; - } - } - } - else { - for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] < m) { - m = bitmap[i]; - } - } - } - return m; -} - -/*! - * \relates vpImage - * \brief Return the minimum value within the float bitmap. - * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. - * If true, consider only finite values. - * - * \sa getMaxValue() - */ -template <> inline float vpImage::getMinValue(bool onlyFiniteVal) const -{ - if (npixels == 0) { - throw(vpException(vpException::fatalError, "Cannot compute minimum value of an empty image")); - } - float m = bitmap[0]; - if (onlyFiniteVal) { - for (unsigned int i = 0; i < npixels; ++i) { - if ((bitmap[i] < m) && (vpMath::isFinite(bitmap[i]))) { - m = bitmap[i]; - } - } - } - else { - for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] < m) { - m = bitmap[i]; - } - } - } - return m; -} - -/*! - * \brief Look for the minimum and the maximum value within the bitmap - * \param min : The minimal value within the bitmap. - * \param max : The maximal value within the bitmap. - * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. - * - * \sa getMaxValue() - * \sa getMinValue() - * \sa getMinMaxLoc() - */ -template void vpImage::getMinMaxValue(Type &min, Type &max, bool onlyFiniteVal) const -{ - if (npixels == 0) { - throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); - } - - min = bitmap[0]; - max = bitmap[0]; - for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] < min) { - min = bitmap[i]; - } - if (bitmap[i] > max) { - max = bitmap[i]; - } - } - (void)onlyFiniteVal; -} - -/*! - * \relates vpImage - * \brief Look for the minimum and the maximum value within the double bitmap - * \param min : The minimal value within the bitmap. - * \param max : The maximal value within the bitmap. - * \param onlyFiniteVal : If true, consider only finite values. - * - * \sa getMaxValue() - * \sa getMinValue() - * \sa getMinMaxLoc() - */ -template <> inline void vpImage::getMinMaxValue(double &min, double &max, bool onlyFiniteVal) const -{ - if (npixels == 0) { - throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); - } - - min = bitmap[0]; - max = bitmap[0]; - if (onlyFiniteVal) { - for (unsigned int i = 0; i < npixels; ++i) { - if (vpMath::isFinite(bitmap[i])) { - if (bitmap[i] < min) { - min = bitmap[i]; - } - if (bitmap[i] > max) { - max = bitmap[i]; - } - } - } - } - else { - for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] < min) { - min = bitmap[i]; - } - if (bitmap[i] > max) { - max = bitmap[i]; - } - } - } -} - -/*! - * \relates vpImage - * \brief Look for the minimum and the maximum value within the float bitmap - * \param min : The minimal value within the bitmap. - * \param max : The maximal value within the bitmap. - * \param onlyFiniteVal : If true, consider only finite values. - * - * \sa getMaxValue() - * \sa getMinValue() - * \sa getMinMaxLoc() - */ -template <> inline void vpImage::getMinMaxValue(float &min, float &max, bool onlyFiniteVal) const -{ - if (npixels == 0) { - throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); - } - - min = bitmap[0]; - max = bitmap[0]; - if (onlyFiniteVal) { - for (unsigned int i = 0; i < npixels; ++i) { - if (vpMath::isFinite(bitmap[i])) { - if (bitmap[i] < min) { - min = bitmap[i]; - } - if (bitmap[i] > max) { - max = bitmap[i]; - } - } - } - } - else { - for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] < min) { - min = bitmap[i]; - } - if (bitmap[i] > max) { - max = bitmap[i]; - } - } - } -} - -/*! - \brief Look for the minimum and the maximum value within the 3-channels float bitmap - \param min : The minimal values within the bitmap. - \param max : The maximal values within the bitmap. - \param onlyFiniteVal : If true, consider only finite values. - - \sa getMaxValue() - \sa getMinValue() - \sa getMinMaxLoc() -*/ -template <> inline void vpImage::getMinMaxValue(vpRGBf &min, vpRGBf &max, bool onlyFiniteVal) const -{ - if (npixels == 0) { - throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); - } - - min = bitmap[0]; - max = bitmap[0]; - if (onlyFiniteVal) { - for (unsigned int i = 0; i < npixels; ++i) { - if (vpMath::isFinite(bitmap[i].R)) { - if (bitmap[i].R < min.R) { - min.R = bitmap[i].R; - } - if (bitmap[i].R > max.R) { - max.R = bitmap[i].R; - } - } - if (vpMath::isFinite(bitmap[i].G)) { - if (bitmap[i].G < min.G) { - min.G = bitmap[i].G; - } - if (bitmap[i].G > max.G) { - max.G = bitmap[i].G; - } - } - if (vpMath::isFinite(bitmap[i].B)) { - if (bitmap[i].B < min.B) { - min.B = bitmap[i].B; - } - if (bitmap[i].B > max.B) { - max.B = bitmap[i].B; - } - } - } - } - else { - for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i].R < min.R) { - min.R = bitmap[i].R; - } - if (bitmap[i].R > max.R) { - max.R = bitmap[i].R; - } - - if (bitmap[i].G < min.G) { - min.G = bitmap[i].G; - } - if (bitmap[i].G > max.G) { - max.G = bitmap[i].G; - } - - if (bitmap[i].B < min.B) { - min.B = bitmap[i].B; - } - if (bitmap[i].B > max.B) { - max.B = bitmap[i].B; - } - } - } -} - -/*! - \brief Get the position of the minimum and/or the maximum pixel value within the bitmap and - the corresponding value. - Following code allows retrieving only minimum value and position: - \code - vpImage I(h, w); - //[...] Fill I - vpImagePoint min_loc; - double min_val = 0.0; - I.getMinMaxLoc(&min_loc, nullptr, &min_val, nullptr); - \endcode - - \param minLoc : Position of the pixel with minimum value if not nullptr. - \param maxLoc : Position of the pixel with maximum value if not nullptr. - \param minVal : Minimum pixel value if not nullptr. - \param maxVal : Maximum pixel value if not nullptr. - - \sa getMaxValue() - \sa getMinValue() - \sa getMinMaxValue() -*/ -template -void vpImage::getMinMaxLoc(vpImagePoint *minLoc, vpImagePoint *maxLoc, Type *minVal, Type *maxVal) const -{ - if (npixels == 0) { - throw(vpException(vpException::fatalError, "Cannot get location of minimum/maximum " - "values of an empty image")); - } - - Type min = bitmap[0], max = bitmap[0]; - vpImagePoint minLoc_, maxLoc_; - for (unsigned int i = 0; i < height; ++i) { - for (unsigned int j = 0; j < width; ++j) { - if (row[i][j] < min) { - min = row[i][j]; - minLoc_.set_ij(i, j); - } - - if (row[i][j] > max) { - max = row[i][j]; - maxLoc_.set_ij(i, j); - } - } - } - - if (minLoc != nullptr) { - *minLoc = minLoc_; - } - - if (maxLoc != nullptr) { - *maxLoc = maxLoc_; - } - - if (minVal != nullptr) { - *minVal = min; - } - - if (maxVal != nullptr) { - *maxVal = max; - } -} - -/*! - \brief Copy operator -*/ -template vpImage &vpImage::operator=(vpImage other) -{ - swap(*this, other); - if (other.display != nullptr) { - display = other.display; - } - - return *this; -} - -/*! - \brief = operator : Set all the element of the bitmap to a given value \e - v. \f$ A = v <=> A[i][j] = v \f$ - - \warning = must be defined for \f$ <\f$ Type \f$ > \f$ -*/ -template vpImage &vpImage::operator=(const Type &v) -{ - for (unsigned int i = 0; i < npixels; ++i) { - bitmap[i] = v; - } - - return *this; -} - -/*! - Compare two images. - - \return true if the images are the same, false otherwise. -*/ -template bool vpImage::operator==(const vpImage &I) const -{ - if (this->width != I.getWidth()) { - return false; - } - if (this->height != I.getHeight()) { - return false; - } - - /* - // printf("wxh: %dx%d bitmap: %p I.bitmap %p\n", width, height, bitmap, - // I.bitmap); - */ - for (unsigned int i = 0; i < npixels; ++i) { - if (bitmap[i] != I.bitmap[i]) { - /* - // std::cout << "differ for pixel " << i << " (" << i%this->height - // << ", " << i - i%this->height << ")" << std::endl; - */ - return false; - } - } - return true; -} -/*! - Compare two images. - - \return true if the images are different, false if they are the same. -*/ -template bool vpImage::operator!=(const vpImage &I) const { return !(*this == I); } - -/*! - Operation A - B (A is unchanged). - - \code -#include - -int main() -{ - vpImage A(288, 384); - vpImage B(288, 384); - vpImage C; - - A = 128; - B = 120; - - // operator-() : C = A - B - C = A - B; - - return 0; + resize(I.getHeight(), I.getWidth()); + if (bitmap) { + memcpy(static_cast(bitmap), static_cast(I.bitmap), I.npixels * sizeof(Type)); + } } - \endcode - \sa sub(const vpImage &, const vpImage &, vpImage &) to - avoid matrix allocation for each use. +#if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher +/*! + \relates vpImage */ -template vpImage vpImage::operator-(const vpImage &B) const +template +vpImage::vpImage(vpImage &&I) + : bitmap(I.bitmap), display(I.display), npixels(I.npixels), width(I.width), height(I.height), row(I.row), + hasOwnership(I.hasOwnership) { - vpImage C; - sub(*this, B, C); - return C; + I.bitmap = nullptr; + I.display = nullptr; + I.npixels = 0; + I.width = 0; + I.height = 0; + I.row = nullptr; + I.hasOwnership = false; } +#endif /*! Insert an image into another one. @@ -1731,7 +751,7 @@ template void vpImage::subsample(unsigned int v_scale, unsigned int h_scale, vpImage &sampled) const { if ((v_scale == 1) && (h_scale == 1)) { - sampled = (*this); + sampled = *this; return; } unsigned int h = height / v_scale; @@ -1770,10 +790,11 @@ template void vpImage::quarterSizeImage(vpImage &res) c { unsigned int h = height / 4; unsigned int w = width / 4; + const unsigned int magic_2 = 2; res.resize(h, w); for (unsigned int i = 0; i < h; ++i) { for (unsigned int j = 0; j < w; ++j) { - res[i][j] = (*this)[i << 2][j << 2]; + res[i][j] = (*this)[i << magic_2][j << magic_2]; } } } @@ -1794,7 +815,6 @@ template void vpImage::quarterSizeImage(vpImage &res) c B E G I are interpolated pixels \endcode - \warning Operator = must be defined for Type. \param res [out] : Image that is double size of the current image. @@ -1812,8 +832,9 @@ template void vpImage::quarterSizeImage(vpImage &res) c */ template void vpImage::doubleSizeImage(vpImage &res) { - unsigned int h = height * 2; - unsigned int w = width * 2; + const unsigned int magic_2 = 2; + unsigned int h = height * magic_2; + unsigned int w = width * magic_2; res.resize(h, w); @@ -1832,462 +853,28 @@ template void vpImage::doubleSizeImage(vpImage &res) */ // interpolate pixels B and I - for (unsigned int i = 0; i < h; i += 2) { - for (unsigned int j = 1; j < (w - 1); j += 2) { + for (unsigned int i = 0; i < h; i += magic_2) { + for (unsigned int j = 1; j < (w - 1); j += magic_2) { res[i][j] = static_cast(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1])); } } // interpolate pixels E and G - for (unsigned int i = 1; i < (h - 1); i += 2) { - for (unsigned int j = 0; j < w; j += 2) { + for (unsigned int i = 1; i < (h - 1); i += magic_2) { + for (unsigned int j = 0; j < w; j += magic_2) { res[i][j] = static_cast(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[(i >> 1) + 1][j >> 1])); } } // interpolate pixel F - for (unsigned int i = 1; i < (h - 1); i += 2) { - for (unsigned int j = 1; j < (w - 1); j += 2) { + for (unsigned int i = 1; i < (h - 1); i += magic_2) { + for (unsigned int j = 1; j < (w - 1); j += magic_2) { res[i][j] = static_cast(0.25 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1] + (*this)[(i >> 1) + 1][j >> 1] + (*this)[(i >> 1) + 1][(j >> 1) + 1])); } } } -/*! - Retrieves pixel value from an image containing values of type `Type`. - - Gets the value of a sub-pixel with coordinates (i,j). - - \param i : Pixel coordinate along the rows. - \param j : Pixel coordinate along the columns. - - \return Pixel value. - - \exception vpImageException::notInTheImage : If (i,j) is out of the image. -*/ -template inline Type vpImage::getValue(unsigned int i, unsigned int j) const -{ - if ((i >= height) || (j >= width)) { - throw(vpException(vpImageException::notInTheImage, "Pixel outside the image")); - } - - return row[i][j]; -} - -/*! - Retrieves pixel value from an image containing values of type `Type` with - sub-pixel accuracy. - - Gets the value of a sub-pixel with coordinates (i,j) with bilinear - interpolation. - - See also vpImageTools::interpolate() for a similar result, but with a choice of the interpolation method. - - \param i : Sub-pixel coordinate along the rows. - \param j : Sub-pixel coordinate along the columns. - - \return Interpolated sub-pixel value from the four neighbours. - - \exception vpImageException::notInTheImage : If (i,j) is out of the image. -*/ -template Type vpImage::getValue(double i, double j) const -{ - if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { - throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); - } - if ((height * width) == 0) { - throw vpException(vpImageException::notInitializedError, "Empty image!"); - } - - unsigned int iround = static_cast(floor(i)); - unsigned int jround = static_cast(floor(j)); - - double rratio = i - static_cast(iround); - double cratio = j - static_cast(jround); - - double rfrac = 1.0 - rratio; - double cfrac = 1.0 - cratio; - - unsigned int iround_1 = std::min(height - 1, iround + 1); - unsigned int jround_1 = std::min(width - 1, jround + 1); - - double value = - (((static_cast(row[iround][jround]) * rfrac) + (static_cast(row[iround_1][jround]) * rratio)) * cfrac) + - (((static_cast(row[iround][jround_1]) * rfrac) + (static_cast(row[iround_1][jround_1]) * rratio)) * - cratio); - - return static_cast(vpMath::round(value)); -} - -/*! - \relates vpImage -*/ -template <> inline double vpImage::getValue(double i, double j) const -{ - if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { - throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); - } - if ((height * width) == 0) { - throw vpException(vpImageException::notInitializedError, "Empty image!"); - } - - unsigned int iround = static_cast(floor(i)); - unsigned int jround = static_cast(floor(j)); - - double rratio = i - static_cast(iround); - double cratio = j - static_cast(jround); - - double rfrac = 1.0 - rratio; - double cfrac = 1.0 - cratio; - - unsigned int iround_1 = std::min(height - 1, iround + 1); - unsigned int jround_1 = std::min(width - 1, jround + 1); - - return (((row[iround][jround] * rfrac) + (row[iround_1][jround] * rratio)) * cfrac) + - (((row[iround][jround_1] * rfrac) + (row[iround_1][jround_1] * rratio)) * cratio); -} - -/*! - \relates vpImage - */ -template <> inline unsigned char vpImage::getValue(double i, double j) const -{ - if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { - throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); - } - if ((height * width) == 0) { - throw vpException(vpImageException::notInitializedError, "Empty image!"); - } - - // alpha architecture is bi-endianness. The following optimization makes testImageGetValue failing -#if (defined(VISP_LITTLE_ENDIAN) || defined(VISP_BIG_ENDIAN)) && !(defined(__alpha__) || defined(_M_ALPHA)) - // Fixed-point arithmetic - const uint32_t precision = 1U << 16; - uint64_t y = static_cast(i * precision); - uint64_t x = static_cast(j * precision); - - uint64_t iround = y & (~0xFFFFU); - uint64_t jround = x & (~0xFFFFU); - - uint64_t rratio = y - iround; - uint64_t cratio = x - jround; - - uint64_t rfrac = precision - rratio; - uint64_t cfrac = precision - cratio; - - uint64_t x_ = x >> 16; - uint64_t y_ = y >> 16; - - if (((y_ + 1) < height) && ((x_ + 1) < width)) { - uint16_t up = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + (y_ * width) + x_); - uint16_t down = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + ((y_ + 1) * width) + x_); - - return static_cast((((up & 0x00FF) * rfrac + (down & 0x00FF) * rratio) * cfrac + - ((up >> 8) * rfrac + (down >> 8) * rratio) * cratio) >> - 32); - } - else if ((y_ + 1) < height) { - return static_cast((row[y_][x_] * rfrac + row[y_ + 1][x_] * rratio) >> 16); - } - else if ((x_ + 1) < width) { - uint16_t up = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + (y_ * width) + x_); - return static_cast(((up & 0x00FF) * cfrac + (up >> 8) * cratio) >> 16); - } - else { - return row[y_][x_]; - } -#else - unsigned int iround = static_cast(floor(i)); - unsigned int jround = static_cast(floor(j)); - - if (iround >= height || jround >= width) { - throw(vpException(vpImageException::notInTheImage, "Pixel outside the image")); - } - - double rratio = i - static_cast(iround); - double cratio = j - static_cast(jround); - - double rfrac = 1.0 - rratio; - double cfrac = 1.0 - cratio; - - unsigned int iround_1 = std::min(height - 1, iround + 1); - unsigned int jround_1 = std::min(width - 1, jround + 1); - - double value = - (static_cast(row[iround][jround]) * rfrac + static_cast(row[iround_1][jround]) * rratio) * cfrac + - (static_cast(row[iround][jround_1]) * rfrac + static_cast(row[iround_1][jround_1]) * rratio) * - cratio; - return static_cast(vpMath::round(value)); -#endif -} - -/*! - \relates vpImage - */ -template <> inline vpRGBa vpImage::getValue(double i, double j) const -{ - if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { - throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); - } - if ((height * width) == 0) { - throw vpException(vpImageException::notInitializedError, "Empty image!"); - } - - unsigned int iround = static_cast(floor(i)); - unsigned int jround = static_cast(floor(j)); - - double rratio = i - static_cast(iround); - double cratio = j - static_cast(jround); - - double rfrac = 1.0 - rratio; - double cfrac = 1.0 - cratio; - - unsigned int iround_1 = std::min(height - 1, iround + 1); - unsigned int jround_1 = std::min(width - 1, jround + 1); - - double valueR = - (((static_cast(row[iround][jround].R) * rfrac) + (static_cast(row[iround_1][jround].R) * rratio)) * - cfrac) + - (((static_cast(row[iround][jround_1].R) * rfrac) + (static_cast(row[iround_1][jround_1].R) * rratio)) * - cratio); - double valueG = - (((static_cast(row[iround][jround].G) * rfrac) + (static_cast(row[iround_1][jround].G) * rratio)) * - cfrac) + - (((static_cast(row[iround][jround_1].G) * rfrac) + (static_cast(row[iround_1][jround_1].G) * rratio)) * - cratio); - double valueB = - (((static_cast(row[iround][jround].B) * rfrac) + (static_cast(row[iround_1][jround].B) * rratio)) * - cfrac) + - (((static_cast(row[iround][jround_1].B) * rfrac) + (static_cast(row[iround_1][jround_1].B) * rratio)) * - cratio); - - return vpRGBa(static_cast(vpMath::round(valueR)), static_cast(vpMath::round(valueG)), - static_cast(vpMath::round(valueB))); -} - -/*! - \relates vpImage - */ -template <> inline vpRGBf vpImage::getValue(double i, double j) const -{ - if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { - throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); - } - if ((height * width) == 0) { - throw vpException(vpImageException::notInitializedError, "Empty image!"); - } - - unsigned int iround = static_cast(floor(i)); - unsigned int jround = static_cast(floor(j)); - - double rratio = i - static_cast(iround); - double cratio = j - static_cast(jround); - - double rfrac = 1.0 - rratio; - double cfrac = 1.0 - cratio; - - unsigned int iround_1 = std::min(height - 1, iround + 1); - unsigned int jround_1 = std::min(width - 1, jround + 1); - - double valueR = - (((static_cast(row[iround][jround].R) * rfrac) + (static_cast(row[iround_1][jround].R) * rratio)) * - cfrac) + - (((static_cast(row[iround][jround_1].R) * rfrac) + (static_cast(row[iround_1][jround_1].R) * rratio)) * - cratio); - double valueG = - (((static_cast(row[iround][jround].G) * rfrac) + (static_cast(row[iround_1][jround].G) * rratio)) * - cfrac) + - (((static_cast(row[iround][jround_1].G) * rfrac) + (static_cast(row[iround_1][jround_1].G) * rratio)) * - cratio); - double valueB = - (((static_cast(row[iround][jround].B) * rfrac) + (static_cast(row[iround_1][jround].B) * rratio)) * - cfrac) + - (((static_cast(row[iround][jround_1].B) * rfrac) + (static_cast(row[iround_1][jround_1].B) * rratio)) * - cratio); - - return vpRGBf(static_cast(valueR), static_cast(valueG), static_cast(valueB)); -} - -/*! - Retrieves pixel value from an image containing values of type \e Type with - sub-pixel accuracy. - - Gets the value of a sub-pixel with coordinates (i,j) with bilinear - interpolation. - - See also vpImageTools::interpolate() for a similar result, but with a choice of the interpolation method. - - \param ip : Sub-pixel coordinates of a point in the image. - - \return Interpolated sub-pixel value from the four neighbours. - - \exception vpImageException::notInTheImage : If the image point \e ip is out - of the image. -*/ -template inline Type vpImage::getValue(const vpImagePoint &ip) const -{ - return getValue(ip.get_i(), ip.get_j()); -} - -/*! - \relates vpImage - */ -template <> inline double vpImage::getValue(const vpImagePoint &ip) const -{ - return getValue(ip.get_i(), ip.get_j()); -} - -/*! - \relates vpImage - */ -template <> inline unsigned char vpImage::getValue(const vpImagePoint &ip) const -{ - return getValue(ip.get_i(), ip.get_j()); -} - -/*! - \relates vpImage - */ -template <> inline vpRGBa vpImage::getValue(const vpImagePoint &ip) const -{ - return getValue(ip.get_i(), ip.get_j()); -} - -/** - * \brief Compute the sum of image intensities. - * - For unary image types (unsigned char, float, double), compute the sum of image intensities. - * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. - * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. - * - * \param[in] p_mask Optional parameter. If not set to nullptr, pointer to a boolean mask that indicates the valid - * points by a true flag. - * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are - * valid according to the boolean mask or image size when `p_mask` is set to nullptr. - */ -template inline double vpImage::getSum(const vpImage *p_mask, unsigned int *nbValidPoints) const -{ - if ((height == 0) || (width == 0)) { - if (nbValidPoints) { - *nbValidPoints = 0; - } - return 0.0; - } - if (p_mask) { - if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { - throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); - } - } - double res = 0.0; - unsigned int nbPointsInMask = 0; - unsigned int size = height * width; - if (p_mask) { - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { - res += static_cast(bitmap[i]); - ++nbPointsInMask; - } - } - } - else { - for (unsigned int i = 0; i < size; ++i) { - res += static_cast(bitmap[i]); - } - nbPointsInMask = size; - } - if (nbValidPoints) { - *nbValidPoints = nbPointsInMask; - } - - return res; -} - -#ifndef DOXYGEN_SHOULD_SKIP_THIS -/** - * \brief Compute the sum of image intensities. - * - For unary image types (unsigned char, float, double), compute the sum of image intensities. - * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. - * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. - * - * \param[in] p_mask Optional parameter. If not set to nullptr, pointer to a boolean mask that indicates the valid - * points by a true flag. - * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are - * valid according to the boolean mask or image size when `p_mask` is set to nullptr. - */ -template <> inline double vpImage::getSum(const vpImage *p_mask, unsigned int *nbValidPoints) const -{ - if ((height == 0) || (width == 0)) { - return 0.0; - } - double res = 0.0; - unsigned int nbPointsInMask = 0; - unsigned int size = height * width; - if (p_mask) { - if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { - throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); - } - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { - res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - ++nbPointsInMask; - } - } - } - else { - for (unsigned int i = 0; i < (height * width); ++i) { - res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - } - nbPointsInMask = size; - } - if (nbValidPoints) { - *nbValidPoints = nbPointsInMask; - } - return res; -} - -/** - * \brief Compute the sum of image intensities. - * - For unary image types (unsigned char, float, double), compute the sum of image intensities. - * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. - * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. - * - * \param[in] p_mask Optional parameter. If not set to nullptr, pointer to a boolean mask that indicates the valid - * points by a true flag. - * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are - * valid according to the boolean mask or image size when `p_mask` is set to nullptr. - */ -template <> inline double vpImage::getSum(const vpImage *p_mask, unsigned int *nbValidPoints) const -{ - if ((height == 0) || (width == 0)) { - return 0.0; - } - double res = 0.0; - unsigned int nbPointsInMask = 0; - unsigned int size = height * width; - if (p_mask) { - if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { - throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); - } - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { - res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - ++nbPointsInMask; - } - } - } - else { - for (unsigned int i = 0; i < (height * width); ++i) { - res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - } - nbPointsInMask = size; - } - if (nbValidPoints) { - *nbValidPoints = nbPointsInMask; - } - return res; -} -#endif // DOXYGEN_SHOULD_SKIP_THIS - /*! Operation C = *this - B. @@ -2376,183 +963,5 @@ template void vpImage::sub(const vpImage &A, const vpIm } } -/*! - \warning This generic method is not implemented. You should rather use the - instantiated methods for unsigned char and vpRGBa images. - - \sa vpImage::performLut(const unsigned char (&lut)[256], unsigned int nbThreads) - \sa vpImage::performLut(const vpRGBa (&lut)[256], unsigned int nbThreads) - -*/ -template void vpImage::performLut(const Type(&)[256], unsigned int) -{ - std::cerr << "Not implemented !" << std::endl; -} - -/*! - \relates vpImage - - Modify the intensities of a grayscale image using the look-up table passed - in parameter. - - \param lut : Look-up table (unsigned char array of size=256) which maps each - intensity to his new value. - \param nbThreads : Number of threads to use for the computation. -*/ -template <> inline void vpImage::performLut(const unsigned char(&lut)[256], unsigned int nbThreads) -{ - unsigned int size = getWidth() * getHeight(); - unsigned char *ptrStart = static_cast(bitmap); - unsigned char *ptrEnd = ptrStart + size; - unsigned char *ptrCurrent = ptrStart; - - bool use_single_thread = ((nbThreads == 0) || (nbThreads == 1)); -#if !defined(VISP_HAVE_THREADS) - use_single_thread = true; -#endif - - if ((!use_single_thread) && (getSize() <= nbThreads)) { - use_single_thread = true; - } - - if (use_single_thread) { - // Single thread - - while (ptrCurrent != ptrEnd) { - *ptrCurrent = lut[*ptrCurrent]; - ++ptrCurrent; - } - } - else { -#if defined(VISP_HAVE_THREADS) - // Multi-threads - std::vector threadpool; - std::vector imageLutParams; - - unsigned int image_size = getSize(); - unsigned int step = image_size / nbThreads; - unsigned int last_step = image_size - step * (nbThreads - 1); - - for (unsigned int index = 0; index < nbThreads; ++index) { - unsigned int start_index = index * step; - unsigned int end_index = (index + 1) * step; - - if (index == nbThreads - 1) { - end_index = start_index + last_step; - } - - vpImageLut_Param_t *imageLut_param = new vpImageLut_Param_t(start_index, end_index, bitmap); - memcpy(imageLut_param->m_lut, lut, 256 * sizeof(unsigned char)); - - imageLutParams.push_back(imageLut_param); - - // Start the threads - std::thread *imageLut_thread = new std::thread(&performLutThread, imageLut_param); - threadpool.push_back(imageLut_thread); - } - - for (size_t cpt = 0; cpt < threadpool.size(); ++cpt) { - // Wait until thread ends up - threadpool[cpt]->join(); - } - - // Delete - for (size_t cpt = 0; cpt < threadpool.size(); ++cpt) { - delete threadpool[cpt]; - } - - for (size_t cpt = 0; cpt < imageLutParams.size(); ++cpt) { - delete imageLutParams[cpt]; - } -#endif - } -} - -/*! - \relates vpImage - - Modify the intensities of a color image using the look-up table passed in - parameter. - - \param lut : Look-up table (vpRGBa array of size=256) which maps each - intensity to his new value. - \param nbThreads : Number of threads to use for the computation. -*/ -template <> inline void vpImage::performLut(const vpRGBa(&lut)[256], unsigned int nbThreads) -{ - unsigned int size = getWidth() * getHeight(); - unsigned char *ptrStart = reinterpret_cast(bitmap); - unsigned char *ptrEnd = ptrStart + (size * 4); - unsigned char *ptrCurrent = ptrStart; - - bool use_single_thread = ((nbThreads == 0) || (nbThreads == 1)); -#if !defined(VISP_HAVE_THREADS) - use_single_thread = true; -#endif - - if ((!use_single_thread) && (getSize() <= nbThreads)) { - use_single_thread = true; - } - - if (use_single_thread) { - // Single thread - while (ptrCurrent != ptrEnd) { - *ptrCurrent = lut[*ptrCurrent].R; - ++ptrCurrent; - - *ptrCurrent = lut[*ptrCurrent].G; - ++ptrCurrent; - - *ptrCurrent = lut[*ptrCurrent].B; - ++ptrCurrent; - - *ptrCurrent = lut[*ptrCurrent].A; - ++ptrCurrent; - } - } - else { -#if defined(VISP_HAVE_THREADS) - // Multi-threads - std::vector threadpool; - std::vector imageLutParams; - - unsigned int image_size = getSize(); - unsigned int step = image_size / nbThreads; - unsigned int last_step = image_size - step * (nbThreads - 1); - - for (unsigned int index = 0; index < nbThreads; ++index) { - unsigned int start_index = index * step; - unsigned int end_index = (index + 1) * step; - - if (index == nbThreads - 1) { - end_index = start_index + last_step; - } - - vpImageLutRGBa_Param_t *imageLut_param = new vpImageLutRGBa_Param_t(start_index, end_index, (unsigned char *)bitmap); - memcpy(static_cast(imageLut_param->m_lut), lut, 256 * sizeof(vpRGBa)); - - imageLutParams.push_back(imageLut_param); - - // Start the threads - std::thread *imageLut_thread = new std::thread(&performLutRGBaThread, imageLut_param); - threadpool.push_back(imageLut_thread); - } - - for (size_t cpt = 0; cpt < threadpool.size(); ++cpt) { - // Wait until thread ends up - threadpool[cpt]->join(); - } - - // Delete - for (size_t cpt = 0; cpt < threadpool.size(); ++cpt) { - delete threadpool[cpt]; - } - - for (size_t cpt = 0; cpt < imageLutParams.size(); ++cpt) { - delete imageLutParams[cpt]; - } -#endif - } -} END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpImageFilter.h b/modules/core/include/visp3/core/vpImageFilter.h index fef7930875..f373011ff9 100644 --- a/modules/core/include/visp3/core/vpImageFilter.h +++ b/modules/core/include/visp3/core/vpImageFilter.h @@ -721,12 +721,6 @@ class VISP_EXPORT vpImageFilter static void filterX(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size, const vpImage *p_mask = nullptr); -#ifdef DOXYGEN_SHOULD_SKIP_THIS - static void filterXR(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); - static void filterXG(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); - static void filterXB(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); -#endif - template static inline FilterType filterX(const vpImage &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size) { @@ -740,37 +734,20 @@ class VISP_EXPORT vpImageFilter } #ifndef DOXYGEN_SHOULD_SKIP_THIS - static inline double filterXR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; - for (unsigned int i = 1; i <= stop; ++i) { - result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); - } - return result + (filter[0] * static_cast(I[r][c].R)); - } - - static inline double filterXG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); - } - return result + (filter[0] * static_cast(I[r][c].G)); - } + static void filterXR(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); + static void filterXG(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); + static void filterXB(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); - static inline double filterXB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; + static double filterXR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterXG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterXB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); - for (unsigned int i = 1; i <= stop; ++i) { - result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); - } - return result + (filter[0] * static_cast(I[r][c].B)); - } + static double filterXLeftBorderR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterXLeftBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterXLeftBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterXRightBorderR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterXRightBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterXRightBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); template static inline FilterType filterXLeftBorder(const vpImage &I, unsigned int r, unsigned int c, @@ -790,57 +767,6 @@ class VISP_EXPORT vpImageFilter return result + (filter[0] * static_cast(I[r][c])); } - static inline double filterXLeftBorderR(const vpImage &I, unsigned int r, unsigned int c, - const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if (c > i) { - result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); - } - else { - result += filter[i] * static_cast(I[r][c + i].R + I[r][i - c].R); - } - } - return result + (filter[0] * static_cast(I[r][c].R)); - } - - static inline double filterXLeftBorderG(const vpImage &I, unsigned int r, unsigned int c, - const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if (c > i) { - result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); - } - else { - result += filter[i] * static_cast(I[r][c + i].G + I[r][i - c].G); - } - } - return result + (filter[0] * static_cast(I[r][c].G)); - } - - static inline double filterXLeftBorderB(const vpImage &I, unsigned int r, unsigned int c, - const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if (c > i) { - result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); - } - else { - result += filter[i] * static_cast(I[r][c + i].B + I[r][i - c].B); - } - } - return result + (filter[0] * static_cast(I[r][c].B)); - } - template static inline FilterType filterXRightBorder(const vpImage &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size) @@ -859,71 +785,10 @@ class VISP_EXPORT vpImageFilter } return result + (filter[0] * static_cast(I[r][c])); } - - static inline double filterXRightBorderR(const vpImage &I, unsigned int r, unsigned int c, - const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - const unsigned int width = I.getWidth(); - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if ((c + i) < width) { - result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); - } - else { - result += filter[i] * static_cast(I[r][((2 * width) - c) - i - 1].R + I[r][c - i].R); - } - } - return result + (filter[0] * static_cast(I[r][c].R)); - } - - static inline double filterXRightBorderG(const vpImage &I, unsigned int r, unsigned int c, - const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - const unsigned int width = I.getWidth(); - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if ((c + i) < width) { - result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); - } - else { - result += filter[i] * static_cast(I[r][((2 * width) - c) - i - 1].G + I[r][c - i].G); - } - } - return result + (filter[0] * static_cast(I[r][c].G)); - } - - static inline double filterXRightBorderB(const vpImage &I, unsigned int r, unsigned int c, - const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - const unsigned int width = I.getWidth(); - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if ((c + i) < width) { - result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); - } - else { - result += filter[i] * static_cast(I[r][(2 * width) - c - i - 1].B + I[r][c - i].B); - } - } - return result + (filter[0] * static_cast(I[r][c].B)); - } #endif - static void filterY(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size, const vpImage *p_mask = nullptr); -#ifndef DOXYGEN_SHOULD_SKIP_THIS - static void filterYR(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); - static void filterYG(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); - static void filterYB(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); -#endif - template static void filterY(const vpImage &I, vpImage &dIy, const FilterType *filter, unsigned int size, const vpImage *p_mask = nullptr) @@ -977,37 +842,20 @@ class VISP_EXPORT vpImageFilter return result + (filter[0] * static_cast(I[r][c])); } #ifndef DOXYGEN_SHOULD_SKIP_THIS - static inline double filterYR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); - } - return result + (filter[0] * static_cast(I[r][c].R)); - } - static inline double filterYG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); - } - return result + (filter[0] * static_cast(I[r][c].G)); - } + static void filterYR(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); + static void filterYG(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); + static void filterYB(const vpImage &I, vpImage &dIx, const double *filter, unsigned int size); - static inline double filterYB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; + static double filterYR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterYG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterYB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); - for (unsigned int i = 1; i <= stop; ++i) { - result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); - } - return result + (filter[0] * static_cast(I[r][c].B)); - } + static double filterYTopBorderR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterYTopBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterYTopBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterYBottomBorderR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterYBottomBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); + static double filterYBottomBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size); template static inline FilterType filterYTopBorder(const vpImage &I, unsigned int r, unsigned int c, @@ -1027,54 +875,6 @@ class VISP_EXPORT vpImageFilter return result + (filter[0] * static_cast(I[r][c])); } - double static inline filterYTopBorderR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if (r > i) { - result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); - } - else { - result += filter[i] * static_cast(I[r + i][c].R + I[i - r][c].R); - } - } - return result + (filter[0] * static_cast(I[r][c].R)); - } - - double static inline filterYTopBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if (r > i) { - result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); - } - else { - result += filter[i] * static_cast(I[r + i][c].G + I[i - r][c].G); - } - } - return result + (filter[0] * static_cast(I[r][c].G)); - } - - double static inline filterYTopBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) - { - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if (r > i) { - result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); - } - else { - result += filter[i] * static_cast(I[r + i][c].B + I[i - r][c].B); - } - } - return result + (filter[0] * static_cast(I[r][c].B)); - } - template static inline FilterType filterYBottomBorder(const vpImage &I, unsigned int r, unsigned int c, const FilterType *filter, unsigned int size) @@ -1093,60 +893,6 @@ class VISP_EXPORT vpImageFilter } return result + (filter[0] * static_cast(I[r][c])); } - - double static inline filterYBottomBorderR(const vpImage &I, unsigned int r, unsigned int c, - const double *filter, unsigned int size) - { - const unsigned int height = I.getHeight(); - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if ((r + i) < height) { - result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); - } - else { - result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].R + I[r - i][c].R); - } - } - return result + (filter[0] * static_cast(I[r][c].R)); - } - - double static inline filterYBottomBorderG(const vpImage &I, unsigned int r, unsigned int c, - const double *filter, unsigned int size) - { - const unsigned int height = I.getHeight(); - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if ((r + i) < height) { - result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); - } - else { - result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].G + I[r - i][c].G); - } - } - return result + (filter[0] * static_cast(I[r][c].G)); - } - - double static inline filterYBottomBorderB(const vpImage &I, unsigned int r, unsigned int c, - const double *filter, unsigned int size) - { - const unsigned int height = I.getHeight(); - const unsigned int stop = (size - 1) / 2; - double result = 0.; - - for (unsigned int i = 1; i <= stop; ++i) { - if ((r + i) < height) { - result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); - } - else { - result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].B + I[r - i][c].B); - } - } - return result + (filter[0] * static_cast(I[r][c].B)); - } #endif @@ -1660,7 +1406,7 @@ class VISP_EXPORT vpImageFilter } } -/** + /** * \brief Indicates if the boolean mask is true at the desired coordinates. * * \param[in] p_mask Pointer towards the boolean mask if any or nullptr. diff --git a/modules/core/include/visp3/core/vpImageTools.h b/modules/core/include/visp3/core/vpImageTools.h index 2c060cf468..d3ce6aecf8 100644 --- a/modules/core/include/visp3/core/vpImageTools.h +++ b/modules/core/include/visp3/core/vpImageTools.h @@ -796,36 +796,6 @@ void vpImageTools::undistort(const vpImage &I, const vpCameraParameters &c } } #endif // VISP_HAVE_THREADS - -#if 0 - // non optimized version - int width = I.getWidth(); - int height = I.getHeight(); - - undistI.resize(height, width); - - double u0 = cam.get_u0(); - double v0 = cam.get_v0(); - double px = cam.get_px(); - double py = cam.get_py(); - double kd = cam.get_kud(); - - if (kd == 0) { - // There is no need to undistort the image - undistI = I; - return; - } - - for (int v = 0; v < height; ++v) { - for (int u = 0; u < height; ++u) { - double r2 = vpMath::sqr((static_cast(u) - u0) / px) + - vpMath::sqr((static_cast(v) - v0) / py); - double u_double = (static_cast(u) - u0) * (1.0 + kd * r2) + u0; - double v_double = (static_cast(v) - v0) * (1.0 + kd * r2) + v0; - undistI[v][u] = I.getPixelBI((float)u_double, (float)v_double); - } - } -#endif } /*! @@ -872,28 +842,28 @@ template void vpImageTools::flip(const vpImage &I, vpImage -#include -#include + #include + #include + #include -int main() -{ - vpImage I; -#ifdef _WIN32 - std::string filename("C:/Temp/visp-images/Klimt/Klimt.ppm"); -#else - std::string filename("/local/soft/ViSP/ViSP-images/Klimt/Klimt.ppm"); -#endif + int main() + { + vpImage I; + #ifdef _WIN32 + std::string filename("C:/Temp/visp-images/Klimt/Klimt.ppm"); + #else + std::string filename("/local/soft/ViSP/ViSP-images/Klimt/Klimt.ppm"); + #endif - // Read an image from the disk - vpImageIo::read(I, filename); + // Read an image from the disk + vpImageIo::read(I, filename); - // Flip the image - vpImageTools::flip(I); + // Flip the image + vpImageTools::flip(I); - // Write the image in a PGM P5 image file format - vpImageIo::write(I, "Klimt-flip.ppm"); -} + // Write the image in a PGM P5 image file format + vpImageIo::write(I, "Klimt-flip.ppm"); + } \endcode */ template void vpImageTools::flip(vpImage &I) @@ -1275,694 +1245,7 @@ inline void vpImageTools::resize(const vpImage &I, vpImage &Ires } #endif -/*! - Apply a warping (affine or perspective) transformation to an image. - - \param src : Input image. - \param T : Transformation / warping matrix, a `2x3` matrix for an affine transformation - or a `3x3` matrix for a perspective transformation (homography). - \param dst : Output image, if empty it will be of the same size than src and zero-initialized. - \param interpolation : Interpolation method (only INTERPOLATION_NEAREST and INTERPOLATION_LINEAR - are accepted, if INTERPOLATION_CUBIC is passed, INTERPOLATION_NEAREST will be used instead). - \param fixedPointArithmetic : If true and if `pixelCenter` is false, fixed-point arithmetic is used if - possible. Otherwise (e.g. the input image is too big) it fallbacks to the default implementation. - \param pixelCenter : If true, pixel coordinates are at (0.5, 0.5), otherwise at (0,0). Fixed-point - arithmetic cannot be used with `pixelCenter` option. -*/ -template -void vpImageTools::warpImage(const vpImage &src, const vpMatrix &T, vpImage &dst, - const vpImageInterpolationType &interpolation, bool fixedPointArithmetic, bool pixelCenter) -{ - if (((T.getRows() != 2) && (T.getRows() != 3)) || (T.getCols() != 3)) { - std::cerr << "Input transformation must be a (2x3) or (3x3) matrix." << std::endl; - return; - } - - if (src.getSize() == 0) { - return; - } - - const bool affine = (T.getRows() == 2); - const bool interp_NN = (interpolation == INTERPOLATION_NEAREST) || (interpolation == INTERPOLATION_CUBIC); - - if (dst.getSize() == 0) { - dst.resize(src.getHeight(), src.getWidth(), Type(0)); - } - - vpMatrix M = T; - if (affine) { - const unsigned int index_0 = 0; - const unsigned int index_1 = 1; - const unsigned int index_2 = 2; - double D = (M[index_0][index_0] * M[index_1][index_1]) - (M[index_0][index_1] * M[index_1][index_0]); - D = !vpMath::nul(D, std::numeric_limits::epsilon()) ? (1.0 / D) : 0; - double A11 = M[index_1][index_1] * D, A22 = M[index_0][index_0] * D; - M[index_0][index_0] = A11; - M[index_0][index_1] *= -D; - M[index_1][index_0] *= -D; - M[index_1][index_1] = A22; - double b1 = (-M[index_0][index_0] * M[index_0][index_2]) - (M[index_0][index_1] * M[index_1][index_2]); - double b2 = (-M[index_1][index_0] * M[index_0][index_2]) - (M[index_1][index_1] * M[index_1][index_2]); - M[index_0][index_2] = b1; - M[index_1][index_2] = b2; - } - else { - M = T.inverseByLU(); - } - - if (fixedPointArithmetic && (!pixelCenter)) { - fixedPointArithmetic = checkFixedPoint(0, 0, M, affine) && checkFixedPoint(dst.getWidth() - 1, 0, M, affine) && - checkFixedPoint(0, dst.getHeight() - 1, M, affine) && - checkFixedPoint(dst.getWidth() - 1, dst.getHeight() - 1, M, affine); - } - - if (interp_NN) { - // nearest neighbor interpolation - warpNN(src, M, dst, affine, pixelCenter, fixedPointArithmetic); - } - else { - // bilinear interpolation - warpLinear(src, M, dst, affine, pixelCenter, fixedPointArithmetic); - } -} - -template -void vpImageTools::warpNN(const vpImage &src, const vpMatrix &T, vpImage &dst, bool affine, - bool centerCorner, bool fixedPoint) -{ - if (fixedPoint && (!centerCorner)) { - const int nbits = 16; - const int32_t precision = 1 << nbits; - const float precision_1 = 1 / static_cast(precision); - const unsigned int index_0 = 0; - const unsigned int index_1 = 1; - const unsigned int index_2 = 2; - int32_t a0_i32 = static_cast(T[index_0][index_0] * precision); - int32_t a1_i32 = static_cast(T[index_0][index_1] * precision); - int32_t a2_i32 = static_cast(T[index_0][index_2] * precision); - int32_t a3_i32 = static_cast(T[index_1][index_0] * precision); - int32_t a4_i32 = static_cast(T[index_1][index_1] * precision); - int32_t a5_i32 = static_cast(T[index_1][index_2] * precision); - int32_t a6_i32 = T.getRows() == 3 ? static_cast(T[index_2][index_0] * precision) : 0; - int32_t a7_i32 = T.getRows() == 3 ? static_cast(T[index_2][index_1] * precision) : 0; - int32_t a8_i32 = T.getRows() == 3 ? static_cast(T[index_2][index_2] * precision) : 1; - - int32_t height_1_i32 = static_cast((src.getHeight() - 1) * precision) + 0x8000; - int32_t width_1_i32 = static_cast((src.getWidth() - 1) * precision) + 0x8000; - - if (affine) { - unsigned int dst_height = dst.getHeight(); - unsigned int dst_width = dst.getWidth(); - for (unsigned int i = 0; i < dst_height; ++i) { - int32_t xi = a2_i32; - int32_t yi = a5_i32; - - for (unsigned int j = 0; j < dst_width; ++j) { - if ((yi >= 0) && (yi < height_1_i32) && (xi >= 0) && (xi < width_1_i32)) { - float x_ = (xi >> nbits) + ((xi & 0xFFFF) * precision_1); - float y_ = (yi >> nbits) + ((yi & 0xFFFF) * precision_1); - - int x = vpMath::round(x_); - int y = vpMath::round(y_); - dst[i][j] = src[y][x]; - } - - xi += a0_i32; - yi += a3_i32; - } - - a2_i32 += a1_i32; - a5_i32 += a4_i32; - } - } - else { - unsigned int dst_height = dst.getHeight(); - unsigned int dst_width = dst.getWidth(); - int src_height = static_cast(src.getHeight()); - int src_width = static_cast(src.getWidth()); - for (unsigned int i = 0; i < dst_height; ++i) { - int64_t xi = a2_i32; - int64_t yi = a5_i32; - int64_t wi = a8_i32; - - for (unsigned int j = 0; j < dst_width; ++j) { - bool cond_on_y = (yi >= 0) && (yi <= ((src_height - 1) * wi)); - bool cond_on_x = (xi >= 0) && (xi <= ((src_width - 1) * wi)); - if ((wi != 0) && cond_on_y && cond_on_x) { - float w_ = (wi >> nbits) + ((wi & 0xFFFF) * precision_1); - float x_ = ((xi >> nbits) + ((xi & 0xFFFF) * precision_1)) / w_; - float y_ = ((yi >> nbits) + ((yi & 0xFFFF) * precision_1)) / w_; - - int x = vpMath::round(x_); - int y = vpMath::round(y_); - - dst[i][j] = src[y][x]; - } - - xi += a0_i32; - yi += a3_i32; - wi += a6_i32; - } - - a2_i32 += a1_i32; - a5_i32 += a4_i32; - a8_i32 += a7_i32; - } - } - } - else { - const unsigned int index_0 = 0; - const unsigned int index_1 = 1; - const unsigned int index_2 = 2; - double a0 = T[index_0][index_0]; - double a1 = T[index_0][index_1]; - double a2 = T[index_0][index_2]; - double a3 = T[index_1][index_0]; - double a4 = T[index_1][index_1]; - double a5 = T[index_1][index_2]; - double a6 = affine ? 0.0 : T[index_2][index_0]; - double a7 = affine ? 0.0 : T[index_2][index_1]; - double a8 = affine ? 1.0 : T[index_2][index_2]; - - unsigned int dst_height = dst.getHeight(); - unsigned int dst_width = dst.getWidth(); - for (unsigned int i = 0; i < dst_height; ++i) { - for (unsigned int j = 0; j < dst_width; ++j) { - double x = ((a0 * (centerCorner ? j + 0.5 : j)) + (a1 * (centerCorner ? i + 0.5 : i))) + a2; - double y = ((a3 * (centerCorner ? j + 0.5 : j)) + (a4 * (centerCorner ? i + 0.5 : i))) + a5; - double w = ((a6 * (centerCorner ? j + 0.5 : j)) + (a7 * (centerCorner ? i + 0.5 : i))) + a8; - - if (vpMath::nul(w, std::numeric_limits::epsilon())) { - w = 1.0; - } - - int x_ = centerCorner ? coordCast(x / w) : vpMath::round(x / w); - int y_ = centerCorner ? coordCast(y / w) : vpMath::round(y / w); - - if ((x_ >= 0) && (x_ < static_cast(src.getWidth())) && (y_ >= 0) && (y_ < static_cast(src.getHeight()))) { - dst[i][j] = src[y_][x_]; - } - } - } - } -} - -template -void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpImage &dst, bool affine, - bool centerCorner, bool fixedPoint) -{ - if (fixedPoint && (!centerCorner)) { - const int nbits = 16; - const uint64_t precision = 1 << nbits; - const float precision_1 = 1 / static_cast(precision); - const uint64_t precision2 = 1ULL << (2 * nbits); - const float precision_2 = 1 / static_cast(precision2); - const unsigned int index_0 = 0; - const unsigned int index_1 = 1; - const unsigned int index_2 = 2; - - int64_t a0_i64 = static_cast(T[index_0][index_0] * precision); - int64_t a1_i64 = static_cast(T[index_0][index_1] * precision); - int64_t a2_i64 = static_cast(T[index_0][index_2] * precision); - int64_t a3_i64 = static_cast(T[index_1][index_0] * precision); - int64_t a4_i64 = static_cast(T[index_1][index_1] * precision); - int64_t a5_i64 = static_cast(T[index_1][index_2] * precision); - int64_t a6_i64 = T.getRows() == 3 ? static_cast(T[index_2][index_0] * precision) : 0; - int64_t a7_i64 = T.getRows() == 3 ? static_cast(T[index_2][index_1] * precision) : 0; - int64_t a8_i64 = T.getRows() == 3 ? static_cast(T[index_2][index_2] * precision) : 1; - - int64_t height_i64 = static_cast(src.getHeight() * precision); - int64_t width_i64 = static_cast(src.getWidth() * precision); - - if (affine) { - unsigned int dst_height = dst.getHeight(); - unsigned int dst_width = dst.getWidth(); - for (unsigned int i = 0; i < dst_height; ++i) { - int64_t xi_ = a2_i64; - int64_t yi_ = a5_i64; - - for (unsigned int j = 0; j < dst_width; ++j) { - if ((yi_ >= 0) && (yi_ < height_i64) && (xi_ >= 0) && (xi_ < width_i64)) { - const int64_t xi_lower = xi_ & (~0xFFFF); - const int64_t yi_lower = yi_ & (~0xFFFF); - - const int64_t t = yi_ - yi_lower; - const int64_t t_1 = precision - t; - const int64_t s = xi_ - xi_lower; - const int64_t s_1 = precision - s; - - const int x_ = static_cast(xi_ >> nbits); - const int y_ = static_cast(yi_ >> nbits); - - if ((y_ < (static_cast(src.getHeight()) - 1)) && (x_ < (static_cast(src.getWidth()) - 1))) { - const Type val00 = src[y_][x_]; - const Type val01 = src[y_][x_ + 1]; - const Type val10 = src[y_ + 1][x_]; - const Type val11 = src[y_ + 1][x_ + 1]; - const int64_t interp_i64 = - static_cast(s_1 * t_1 * val00 + s * t_1 * val01 + s_1 * t * val10 + s * t * val11); - const float interp = (interp_i64 >> (nbits * 2)) + (interp_i64 & 0xFFFFFFFF) * precision_2; - dst[i][j] = vpMath::saturate(interp); - } - else if (y_ < (static_cast(src.getHeight()) - 1)) { - const Type val00 = src[y_][x_]; - const Type val10 = src[y_ + 1][x_]; - const int64_t interp_i64 = static_cast(t_1 * val00 + t * val10); - const float interp = (interp_i64 >> nbits) + (interp_i64 & 0xFFFF) * precision_1; - dst[i][j] = vpMath::saturate(interp); - } - else if (x_ < (static_cast(src.getWidth()) - 1)) { - const Type val00 = src[y_][x_]; - const Type val01 = src[y_][x_ + 1]; - const int64_t interp_i64 = static_cast(s_1 * val00 + s * val01); - const float interp = (interp_i64 >> nbits) + (interp_i64 & 0xFFFF) * precision_1; - dst[i][j] = vpMath::saturate(interp); - } - else { - dst[i][j] = src[y_][x_]; - } - } - - xi_ += a0_i64; - yi_ += a3_i64; - } - - a2_i64 += a1_i64; - a5_i64 += a4_i64; - } - } - else { - unsigned int dst_height = dst.getHeight(); - unsigned int dst_width = dst.getWidth(); - int src_height = static_cast(src.getHeight()); - int src_width = static_cast(src.getWidth()); - for (unsigned int i = 0; i < dst_height; ++i) { - int64_t xi = a2_i64; - int64_t yi = a5_i64; - int64_t wi = a8_i64; - - for (unsigned int j = 0; j < dst_width; ++j) { - bool cond_on_y = (yi >= 0) && (yi <= ((src_height - 1) * wi)); - bool cond_on_x = (xi >= 0) && (xi <= ((src_width - 1) * wi)); - if ((wi != 0) && cond_on_y && cond_on_x) { - const float wi_ = (wi >> nbits) + ((wi & 0xFFFF) * precision_1); - const float xi_ = ((xi >> nbits) + ((xi & 0xFFFF) * precision_1)) / wi_; - const float yi_ = ((yi >> nbits) + ((yi & 0xFFFF) * precision_1)) / wi_; - - const int x_ = static_cast(xi_); - const int y_ = static_cast(yi_); - - const float t = yi_ - y_; - const float s = xi_ - x_; - - if ((y_ < (src_height - 1)) && (x_ < (src_width - 1))) { - const float val00 = static_cast(src[y_][x_]); - const float val01 = static_cast(src[y_][x_ + 1]); - const float val10 = static_cast(src[y_ + 1][x_]); - const float val11 = static_cast(src[y_ + 1][x_ + 1]); - const float col0 = lerp(val00, val01, s); - const float col1 = lerp(val10, val11, s); - const float interp = lerp(col0, col1, t); - dst[i][j] = vpMath::saturate(interp); - } - else if (y_ < (src_height - 1)) { - const float val00 = static_cast(src[y_][x_]); - const float val10 = static_cast(src[y_ + 1][x_]); - const float interp = lerp(val00, val10, t); - dst[i][j] = vpMath::saturate(interp); - } - else if (x_ < (src_width - 1)) { - const float val00 = static_cast(src[y_][x_]); - const float val01 = static_cast(src[y_][x_ + 1]); - const float interp = lerp(val00, val01, s); - dst[i][j] = vpMath::saturate(interp); - } - else { - dst[i][j] = src[y_][x_]; - } - } - - xi += a0_i64; - yi += a3_i64; - wi += a6_i64; - } - - a2_i64 += a1_i64; - a5_i64 += a4_i64; - a8_i64 += a7_i64; - } - } - } - else { - const unsigned int index_0 = 0; - const unsigned int index_1 = 1; - const unsigned int index_2 = 2; - double a0 = T[index_0][index_0]; - double a1 = T[index_0][index_1]; - double a2 = T[index_0][index_2]; - double a3 = T[index_1][index_0]; - double a4 = T[index_1][index_1]; - double a5 = T[index_1][index_2]; - double a6 = affine ? 0.0 : T[index_2][index_0]; - double a7 = affine ? 0.0 : T[index_2][index_1]; - double a8 = affine ? 1.0 : T[index_2][index_2]; - - unsigned int dst_height = dst.getHeight(); - unsigned int dst_width = dst.getWidth(); - int src_height = static_cast(src.getHeight()); - int src_width = static_cast(src.getWidth()); - for (unsigned int i = 0; i < dst_height; ++i) { - for (unsigned int j = 0; j < dst_width; ++j) { - double x = (a0 * (centerCorner ? (j + 0.5) : j)) + (a1 * (centerCorner ? (i + 0.5) : i)) + a2; - double y = (a3 * (centerCorner ? (j + 0.5) : j)) + (a4 * (centerCorner ? (i + 0.5) : i)) + a5; - double w = (a6 * (centerCorner ? (j + 0.5) : j)) + (a7 * (centerCorner ? (i + 0.5) : i)) + a8; - if (vpMath::nul(w, std::numeric_limits::epsilon())) { - w = 1; - } - - x = (x / w) - (centerCorner ? 0.5 : 0); - y = (y / w) - (centerCorner ? 0.5 : 0); +#include - int x_lower = static_cast(x); - int y_lower = static_cast(y); - bool stop_for_loop = false; - if ((y_lower >= src_height) || (x_lower >= src_width) || (y < 0) || (x < 0)) { - stop_for_loop = true; - } - if (!stop_for_loop) { - double s = x - x_lower; - double t = y - y_lower; - - if ((y_lower < (src_height - 1)) && (x_lower < (src_width - 1))) { - const double val00 = static_cast(src[y_lower][x_lower]); - const double val01 = static_cast(src[y_lower][x_lower + 1]); - const double val10 = static_cast(src[y_lower + 1][x_lower]); - const double val11 = static_cast(src[y_lower + 1][x_lower + 1]); - const double col0 = lerp(val00, val01, s); - const double col1 = lerp(val10, val11, s); - const double interp = lerp(col0, col1, t); - dst[i][j] = vpMath::saturate(interp); - } - else if (y_lower < (src_height - 1)) { - const double val00 = static_cast(src[y_lower][x_lower]); - const double val10 = static_cast(src[y_lower + 1][x_lower]); - const double interp = lerp(val00, val10, t); - dst[i][j] = vpMath::saturate(interp); - } - else if (x_lower < (src_width - 1)) { - const double val00 = static_cast(src[y_lower][x_lower]); - const double val01 = static_cast(src[y_lower][x_lower + 1]); - const double interp = lerp(val00, val01, s); - dst[i][j] = vpMath::saturate(interp); - } - else { - dst[i][j] = src[y_lower][x_lower]; - } - } - } - } - } -} - -inline void vpImageTools::warpLinearFixedPointNotCenter(const vpImage &src, const vpMatrix &T, - vpImage &dst, bool affine) -{ - const unsigned int index_0 = 0, index_1 = 1, index_2 = 2; - const int nbits = 16; - const int64_t precision = 1 << nbits; - const float precision_1 = 1.f / static_cast(precision); - const int64_t precision2 = 1ULL << (2 * nbits); - const float precision_2 = 1.f / static_cast(precision2); - - int64_t a0_i64 = static_cast(T[index_0][index_0] * precision); - int64_t a1_i64 = static_cast(T[index_0][index_1] * precision); - int64_t a2_i64 = static_cast(T[index_0][index_2] * precision); - int64_t a3_i64 = static_cast(T[index_1][index_0] * precision); - int64_t a4_i64 = static_cast(T[index_1][index_1] * precision); - int64_t a5_i64 = static_cast(T[index_1][index_2] * precision); - int64_t a6_i64 = T.getRows() == 3 ? static_cast(T[index_2][index_0] * precision) : 0; - int64_t a7_i64 = T.getRows() == 3 ? static_cast(T[index_2][index_1] * precision) : 0; - int64_t a8_i64 = precision; - - int64_t height_i64 = static_cast(src.getHeight() * precision); - int64_t width_i64 = static_cast(src.getWidth() * precision); - - if (affine) { - unsigned int dst_height = dst.getHeight(); - unsigned int dst_width = dst.getWidth(); - int src_height = static_cast(src.getHeight()); - int src_width = static_cast(src.getWidth()); - for (unsigned int i = 0; i < dst_height; ++i) { - int64_t xi = a2_i64; - int64_t yi = a5_i64; - - for (unsigned int j = 0; j < dst_width; ++j) { - if ((yi >= 0) && (yi < height_i64) && (xi >= 0) && (xi < width_i64)) { - const int64_t xi_lower = xi & (~0xFFFF); - const int64_t yi_lower = yi & (~0xFFFF); - - const int64_t t = yi - yi_lower; - const int64_t t_1 = precision - t; - const int64_t s = xi - xi_lower; - const int64_t s_1 = precision - s; - - const int x_ = static_cast(xi >> nbits); - const int y_ = static_cast(yi >> nbits); - - if ((y_ < (src_height - 1)) && (x_ < (src_width - 1))) { - const vpRGBa val00 = src[y_][x_]; - const vpRGBa val01 = src[y_][x_ + 1]; - const vpRGBa val10 = src[y_ + 1][x_]; - const vpRGBa val11 = src[y_ + 1][x_ + 1]; - const int64_t interpR_i64 = - static_cast((s_1 * t_1 * val00.R) + (s * t_1 * val01.R) + (s_1 * t * val10.R) + (s * t * val11.R)); - const float interpR = (interpR_i64 >> (nbits * 2)) + ((interpR_i64 & 0xFFFFFFFF) * precision_2); - - const int64_t interpG_i64 = - static_cast((s_1 * t_1 * val00.G) + (s * t_1 * val01.G) + (s_1 * t * val10.G) + (s * t * val11.G)); - const float interpG = (interpG_i64 >> (nbits * 2)) + ((interpG_i64 & 0xFFFFFFFF) * precision_2); - - const int64_t interpB_i64 = - static_cast((s_1 * t_1 * val00.B) + (s * t_1 * val01.B) + (s_1 * t * val10.B) + (s * t * val11.B)); - const float interpB = (interpB_i64 >> (nbits * 2)) + ((interpB_i64 & 0xFFFFFFFF) * precision_2); - - dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), - vpMath::saturate(interpB), 255); - } - else if (y_ < (src_height - 1)) { - const vpRGBa val00 = src[y_][x_]; - const vpRGBa val10 = src[y_ + 1][x_]; - const int64_t interpR_i64 = static_cast(t_1 * val00.R + t * val10.R); - const float interpR = (interpR_i64 >> nbits) + ((interpR_i64 & 0xFFFF) * precision_1); - - const int64_t interpG_i64 = static_cast((t_1 * val00.G) + (t * val10.G)); - const float interpG = (interpG_i64 >> nbits) + ((interpG_i64 & 0xFFFF) * precision_1); - - const int64_t interpB_i64 = static_cast((t_1 * val00.B) + (t * val10.B)); - const float interpB = (interpB_i64 >> nbits) + ((interpB_i64 & 0xFFFF) * precision_1); - - dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), - vpMath::saturate(interpB), 255); - } - else if (x_ < (src_width - 1)) { - const vpRGBa val00 = src[y_][x_]; - const vpRGBa val01 = src[y_][x_ + 1]; - const int64_t interpR_i64 = static_cast((s_1 * val00.R) + (s * val01.R)); - const float interpR = (interpR_i64 >> nbits) + ((interpR_i64 & 0xFFFF) * precision_1); - - const int64_t interpG_i64 = static_cast((s_1 * val00.G) + (s * val01.G)); - const float interpG = (interpG_i64 >> nbits) + ((interpG_i64 & 0xFFFF) * precision_1); - - const int64_t interpB_i64 = static_cast((s_1 * val00.B) + (s * val01.B)); - const float interpB = (interpB_i64 >> nbits) + ((interpB_i64 & 0xFFFF) * precision_1); - - dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), - vpMath::saturate(interpB), 255); - } - else { - dst[i][j] = src[y_][x_]; - } - } - - xi += a0_i64; - yi += a3_i64; - } - - a2_i64 += a1_i64; - a5_i64 += a4_i64; - } - } - else { - unsigned int dst_height = dst.getHeight(); - unsigned int dst_width = dst.getWidth(); - int src_height = static_cast(src.getHeight()); - int src_width = static_cast(src.getWidth()); - for (unsigned int i = 0; i < dst_height; ++i) { - int64_t xi = a2_i64; - int64_t yi = a5_i64; - int64_t wi = a8_i64; - - for (unsigned int j = 0; j < dst_width; ++j) { - if ((yi >= 0) && (yi <= ((src_height - 1) * wi)) && (xi >= 0) && - (xi <= ((src_width - 1) * wi))) { - const float wi_ = (wi >> nbits) + ((wi & 0xFFFF) * precision_1); - const float xi_ = ((xi >> nbits) + ((xi & 0xFFFF) * precision_1)) / wi_; - const float yi_ = ((yi >> nbits) + ((yi & 0xFFFF) * precision_1)) / wi_; - - const int x_ = static_cast(xi_); - const int y_ = static_cast(yi_); - - const float t = yi_ - y_; - const float s = xi_ - x_; - - if ((y_ < (src_height - 1)) && (x_ < (src_width - 1))) { - const vpRGBa val00 = src[y_][x_]; - const vpRGBa val01 = src[y_][x_ + 1]; - const vpRGBa val10 = src[y_ + 1][x_]; - const vpRGBa val11 = src[y_ + 1][x_ + 1]; - const float colR0 = lerp(val00.R, val01.R, s); - const float colR1 = lerp(val10.R, val11.R, s); - const float interpR = lerp(colR0, colR1, t); - - const float colG0 = lerp(val00.G, val01.G, s); - const float colG1 = lerp(val10.G, val11.G, s); - const float interpG = lerp(colG0, colG1, t); - - const float colB0 = lerp(val00.B, val01.B, s); - const float colB1 = lerp(val10.B, val11.B, s); - const float interpB = lerp(colB0, colB1, t); - - dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), - vpMath::saturate(interpB), 255); - } - else if (y_ < (src_height - 1)) { - const vpRGBa val00 = src[y_][x_]; - const vpRGBa val10 = src[y_ + 1][x_]; - const float interpR = lerp(val00.R, val10.R, t); - const float interpG = lerp(val00.G, val10.G, t); - const float interpB = lerp(val00.B, val10.B, t); - - dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), - vpMath::saturate(interpB), 255); - } - else if (x_ < (src_width - 1)) { - const vpRGBa val00 = src[y_][x_]; - const vpRGBa val01 = src[y_][x_ + 1]; - const float interpR = lerp(val00.R, val01.R, s); - const float interpG = lerp(val00.G, val01.G, s); - const float interpB = lerp(val00.B, val01.B, s); - - dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), - vpMath::saturate(interpB), 255); - } - else { - dst[i][j] = src[y_][x_]; - } - } - - xi += a0_i64; - yi += a3_i64; - wi += a6_i64; - } - - a2_i64 += a1_i64; - a5_i64 += a4_i64; - a8_i64 += a7_i64; - } - } - -} - -template <> -inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpImage &dst, bool affine, - bool centerCorner, bool fixedPoint) -{ - const unsigned int index_0 = 0, index_1 = 1, index_2 = 2; - if (fixedPoint && (!centerCorner)) { - warpLinearFixedPointNotCenter(src, T, dst, affine); - } - else { - double a0 = T[index_0][index_0]; - double a1 = T[index_0][index_1]; - double a2 = T[index_0][index_2]; - double a3 = T[index_1][index_0]; - double a4 = T[index_1][index_1]; - double a5 = T[index_1][index_2]; - double a6 = affine ? 0.0 : T[index_2][index_0]; - double a7 = affine ? 0.0 : T[index_2][index_1]; - double a8 = affine ? 1.0 : T[index_2][index_2]; - - unsigned int dst_height = dst.getHeight(); - unsigned int dst_width = dst.getWidth(); - int src_height = static_cast(src.getHeight()); - int src_width = static_cast(src.getWidth()); - for (unsigned int i = 0; i < dst_height; ++i) { - for (unsigned int j = 0; j < dst_width; ++j) { - double x = (a0 * (centerCorner ? (j + 0.5) : j)) + (a1 * (centerCorner ? (i + 0.5) : i)) + a2; - double y = (a3 * (centerCorner ? (j + 0.5) : j)) + (a4 * (centerCorner ? (i + 0.5) : i)) + a5; - double w = (a6 * (centerCorner ? (j + 0.5) : j)) + (a7 * (centerCorner ? (i + 0.5) : i)) + a8; - - x = (x / w) - (centerCorner ? 0.5 : 0); - y = (y / w) - (centerCorner ? 0.5 : 0); - - int x_lower = static_cast(x); - int y_lower = static_cast(y); - - bool stop_for_loop = false; - if ((y_lower >= src_height) || (x_lower >= src_width) || (y < 0) || (x < 0)) { - stop_for_loop = true; - } - if (!stop_for_loop) { - double s = x - x_lower; - double t = y - y_lower; - - if ((y_lower < (src_height - 1)) && (x_lower < (src_width - 1))) { - const vpRGBa val00 = src[y_lower][x_lower]; - const vpRGBa val01 = src[y_lower][x_lower + 1]; - const vpRGBa val10 = src[y_lower + 1][x_lower]; - const vpRGBa val11 = src[y_lower + 1][x_lower + 1]; - const double colR0 = lerp(val00.R, val01.R, s); - const double colR1 = lerp(val10.R, val11.R, s); - const double interpR = lerp(colR0, colR1, t); - - const double colG0 = lerp(val00.G, val01.G, s); - const double colG1 = lerp(val10.G, val11.G, s); - const double interpG = lerp(colG0, colG1, t); - - const double colB0 = lerp(val00.B, val01.B, s); - const double colB1 = lerp(val10.B, val11.B, s); - const double interpB = lerp(colB0, colB1, t); - - dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), - vpMath::saturate(interpB), 255); - } - else if (y_lower < (src_height - 1)) { - const vpRGBa val00 = src[y_lower][x_lower]; - const vpRGBa val10 = src[y_lower + 1][x_lower]; - const double interpR = lerp(val00.R, val10.R, t); - const double interpG = lerp(val00.G, val10.G, t); - const double interpB = lerp(val00.B, val10.B, t); - - dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), - vpMath::saturate(interpB), 255); - } - else if (x_lower < (src_width - 1)) { - const vpRGBa val00 = src[y_lower][x_lower]; - const vpRGBa val01 = src[y_lower][x_lower + 1]; - const double interpR = lerp(val00.R, val01.R, s); - const double interpG = lerp(val00.G, val01.G, s); - const double interpB = lerp(val00.B, val01.B, s); - - dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), - vpMath::saturate(interpB), 255); - } - else { - dst[i][j] = src[y_lower][x_lower]; - } - } - } - } - } -} END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpImageTools_warp.h b/modules/core/include/visp3/core/vpImageTools_warp.h new file mode 100644 index 0000000000..af7c152d30 --- /dev/null +++ b/modules/core/include/visp3/core/vpImageTools_warp.h @@ -0,0 +1,729 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Image handling. + */ + +#ifndef VP_IMAGE_TOOLS_WARP_H +#define VP_IMAGE_TOOLS_WARP_H + +// Warning: this file shouldn't be included by the user. Internal usage only to reduce length of vpImage.h + +/*! + Apply a warping (affine or perspective) transformation to an image. + + \param src : Input image. + \param T : Transformation / warping matrix, a `2x3` matrix for an affine transformation + or a `3x3` matrix for a perspective transformation (homography). + \param dst : Output image, if empty it will be of the same size than src and zero-initialized. + \param interpolation : Interpolation method (only INTERPOLATION_NEAREST and INTERPOLATION_LINEAR + are accepted, if INTERPOLATION_CUBIC is passed, INTERPOLATION_NEAREST will be used instead). + \param fixedPointArithmetic : If true and if `pixelCenter` is false, fixed-point arithmetic is used if + possible. Otherwise (e.g. the input image is too big) it fallbacks to the default implementation. + \param pixelCenter : If true, pixel coordinates are at (0.5, 0.5), otherwise at (0,0). Fixed-point + arithmetic cannot be used with `pixelCenter` option. +*/ +template +void vpImageTools::warpImage(const vpImage &src, const vpMatrix &T, vpImage &dst, + const vpImageInterpolationType &interpolation, bool fixedPointArithmetic, bool pixelCenter) +{ + if (((T.getRows() != 2) && (T.getRows() != 3)) || (T.getCols() != 3)) { + std::cerr << "Input transformation must be a (2x3) or (3x3) matrix." << std::endl; + return; + } + + if (src.getSize() == 0) { + return; + } + + const bool affine = (T.getRows() == 2); + const bool interp_NN = (interpolation == INTERPOLATION_NEAREST) || (interpolation == INTERPOLATION_CUBIC); + + if (dst.getSize() == 0) { + dst.resize(src.getHeight(), src.getWidth(), Type(0)); + } + + vpMatrix M = T; + if (affine) { + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + double D = (M[index_0][index_0] * M[index_1][index_1]) - (M[index_0][index_1] * M[index_1][index_0]); + D = !vpMath::nul(D, std::numeric_limits::epsilon()) ? (1.0 / D) : 0; + double A11 = M[index_1][index_1] * D, A22 = M[index_0][index_0] * D; + M[index_0][index_0] = A11; + M[index_0][index_1] *= -D; + M[index_1][index_0] *= -D; + M[index_1][index_1] = A22; + double b1 = (-M[index_0][index_0] * M[index_0][index_2]) - (M[index_0][index_1] * M[index_1][index_2]); + double b2 = (-M[index_1][index_0] * M[index_0][index_2]) - (M[index_1][index_1] * M[index_1][index_2]); + M[index_0][index_2] = b1; + M[index_1][index_2] = b2; + } + else { + M = T.inverseByLU(); + } + + if (fixedPointArithmetic && (!pixelCenter)) { + fixedPointArithmetic = checkFixedPoint(0, 0, M, affine) && checkFixedPoint(dst.getWidth() - 1, 0, M, affine) && + checkFixedPoint(0, dst.getHeight() - 1, M, affine) && + checkFixedPoint(dst.getWidth() - 1, dst.getHeight() - 1, M, affine); + } + + if (interp_NN) { + // nearest neighbor interpolation + warpNN(src, M, dst, affine, pixelCenter, fixedPointArithmetic); + } + else { + // bilinear interpolation + warpLinear(src, M, dst, affine, pixelCenter, fixedPointArithmetic); + } +} + +template +void vpImageTools::warpNN(const vpImage &src, const vpMatrix &T, vpImage &dst, bool affine, + bool centerCorner, bool fixedPoint) +{ + if (fixedPoint && (!centerCorner)) { + const int nbits = 16; + const int32_t precision = 1 << nbits; + const float precision_1 = 1 / static_cast(precision); + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + int32_t a0_i32 = static_cast(T[index_0][index_0] * precision); + int32_t a1_i32 = static_cast(T[index_0][index_1] * precision); + int32_t a2_i32 = static_cast(T[index_0][index_2] * precision); + int32_t a3_i32 = static_cast(T[index_1][index_0] * precision); + int32_t a4_i32 = static_cast(T[index_1][index_1] * precision); + int32_t a5_i32 = static_cast(T[index_1][index_2] * precision); + int32_t a6_i32 = T.getRows() == 3 ? static_cast(T[index_2][index_0] * precision) : 0; + int32_t a7_i32 = T.getRows() == 3 ? static_cast(T[index_2][index_1] * precision) : 0; + int32_t a8_i32 = T.getRows() == 3 ? static_cast(T[index_2][index_2] * precision) : 1; + + int32_t height_1_i32 = static_cast((src.getHeight() - 1) * precision) + 0x8000; + int32_t width_1_i32 = static_cast((src.getWidth() - 1) * precision) + 0x8000; + + if (affine) { + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + for (unsigned int i = 0; i < dst_height; ++i) { + int32_t xi = a2_i32; + int32_t yi = a5_i32; + + for (unsigned int j = 0; j < dst_width; ++j) { + if ((yi >= 0) && (yi < height_1_i32) && (xi >= 0) && (xi < width_1_i32)) { + float x_ = (xi >> nbits) + ((xi & 0xFFFF) * precision_1); + float y_ = (yi >> nbits) + ((yi & 0xFFFF) * precision_1); + + int x = vpMath::round(x_); + int y = vpMath::round(y_); + dst[i][j] = src[y][x]; + } + + xi += a0_i32; + yi += a3_i32; + } + + a2_i32 += a1_i32; + a5_i32 += a4_i32; + } + } + else { + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + int src_height = static_cast(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { + int64_t xi = a2_i32; + int64_t yi = a5_i32; + int64_t wi = a8_i32; + + for (unsigned int j = 0; j < dst_width; ++j) { + bool cond_on_y = (yi >= 0) && (yi <= ((src_height - 1) * wi)); + bool cond_on_x = (xi >= 0) && (xi <= ((src_width - 1) * wi)); + if ((wi != 0) && cond_on_y && cond_on_x) { + float w_ = (wi >> nbits) + ((wi & 0xFFFF) * precision_1); + float x_ = ((xi >> nbits) + ((xi & 0xFFFF) * precision_1)) / w_; + float y_ = ((yi >> nbits) + ((yi & 0xFFFF) * precision_1)) / w_; + + int x = vpMath::round(x_); + int y = vpMath::round(y_); + + dst[i][j] = src[y][x]; + } + + xi += a0_i32; + yi += a3_i32; + wi += a6_i32; + } + + a2_i32 += a1_i32; + a5_i32 += a4_i32; + a8_i32 += a7_i32; + } + } + } + else { + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + double a0 = T[index_0][index_0]; + double a1 = T[index_0][index_1]; + double a2 = T[index_0][index_2]; + double a3 = T[index_1][index_0]; + double a4 = T[index_1][index_1]; + double a5 = T[index_1][index_2]; + double a6 = affine ? 0.0 : T[index_2][index_0]; + double a7 = affine ? 0.0 : T[index_2][index_1]; + double a8 = affine ? 1.0 : T[index_2][index_2]; + + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + for (unsigned int i = 0; i < dst_height; ++i) { + for (unsigned int j = 0; j < dst_width; ++j) { + double x = ((a0 * (centerCorner ? j + 0.5 : j)) + (a1 * (centerCorner ? i + 0.5 : i))) + a2; + double y = ((a3 * (centerCorner ? j + 0.5 : j)) + (a4 * (centerCorner ? i + 0.5 : i))) + a5; + double w = ((a6 * (centerCorner ? j + 0.5 : j)) + (a7 * (centerCorner ? i + 0.5 : i))) + a8; + + if (vpMath::nul(w, std::numeric_limits::epsilon())) { + w = 1.0; + } + + int x_ = centerCorner ? coordCast(x / w) : vpMath::round(x / w); + int y_ = centerCorner ? coordCast(y / w) : vpMath::round(y / w); + + if ((x_ >= 0) && (x_ < static_cast(src.getWidth())) && (y_ >= 0) && (y_ < static_cast(src.getHeight()))) { + dst[i][j] = src[y_][x_]; + } + } + } + } +} + +template +void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpImage &dst, bool affine, + bool centerCorner, bool fixedPoint) +{ + if (fixedPoint && (!centerCorner)) { + const int nbits = 16; + const uint64_t precision = 1 << nbits; + const float precision_1 = 1 / static_cast(precision); + const uint64_t precision2 = 1ULL << (2 * nbits); + const float precision_2 = 1 / static_cast(precision2); + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + + int64_t a0_i64 = static_cast(T[index_0][index_0] * precision); + int64_t a1_i64 = static_cast(T[index_0][index_1] * precision); + int64_t a2_i64 = static_cast(T[index_0][index_2] * precision); + int64_t a3_i64 = static_cast(T[index_1][index_0] * precision); + int64_t a4_i64 = static_cast(T[index_1][index_1] * precision); + int64_t a5_i64 = static_cast(T[index_1][index_2] * precision); + int64_t a6_i64 = T.getRows() == 3 ? static_cast(T[index_2][index_0] * precision) : 0; + int64_t a7_i64 = T.getRows() == 3 ? static_cast(T[index_2][index_1] * precision) : 0; + int64_t a8_i64 = T.getRows() == 3 ? static_cast(T[index_2][index_2] * precision) : 1; + + int64_t height_i64 = static_cast(src.getHeight() * precision); + int64_t width_i64 = static_cast(src.getWidth() * precision); + + if (affine) { + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + for (unsigned int i = 0; i < dst_height; ++i) { + int64_t xi_ = a2_i64; + int64_t yi_ = a5_i64; + + for (unsigned int j = 0; j < dst_width; ++j) { + if ((yi_ >= 0) && (yi_ < height_i64) && (xi_ >= 0) && (xi_ < width_i64)) { + const int64_t xi_lower = xi_ & (~0xFFFF); + const int64_t yi_lower = yi_ & (~0xFFFF); + + const int64_t t = yi_ - yi_lower; + const int64_t t_1 = precision - t; + const int64_t s = xi_ - xi_lower; + const int64_t s_1 = precision - s; + + const int x_ = static_cast(xi_ >> nbits); + const int y_ = static_cast(yi_ >> nbits); + + if ((y_ < (static_cast(src.getHeight()) - 1)) && (x_ < (static_cast(src.getWidth()) - 1))) { + const Type val00 = src[y_][x_]; + const Type val01 = src[y_][x_ + 1]; + const Type val10 = src[y_ + 1][x_]; + const Type val11 = src[y_ + 1][x_ + 1]; + const int64_t interp_i64 = + static_cast(s_1 * t_1 * val00 + s * t_1 * val01 + s_1 * t * val10 + s * t * val11); + const float interp = (interp_i64 >> (nbits * 2)) + (interp_i64 & 0xFFFFFFFF) * precision_2; + dst[i][j] = vpMath::saturate(interp); + } + else if (y_ < (static_cast(src.getHeight()) - 1)) { + const Type val00 = src[y_][x_]; + const Type val10 = src[y_ + 1][x_]; + const int64_t interp_i64 = static_cast(t_1 * val00 + t * val10); + const float interp = (interp_i64 >> nbits) + (interp_i64 & 0xFFFF) * precision_1; + dst[i][j] = vpMath::saturate(interp); + } + else if (x_ < (static_cast(src.getWidth()) - 1)) { + const Type val00 = src[y_][x_]; + const Type val01 = src[y_][x_ + 1]; + const int64_t interp_i64 = static_cast(s_1 * val00 + s * val01); + const float interp = (interp_i64 >> nbits) + (interp_i64 & 0xFFFF) * precision_1; + dst[i][j] = vpMath::saturate(interp); + } + else { + dst[i][j] = src[y_][x_]; + } + } + + xi_ += a0_i64; + yi_ += a3_i64; + } + + a2_i64 += a1_i64; + a5_i64 += a4_i64; + } + } + else { + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + int src_height = static_cast(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { + int64_t xi = a2_i64; + int64_t yi = a5_i64; + int64_t wi = a8_i64; + + for (unsigned int j = 0; j < dst_width; ++j) { + bool cond_on_y = (yi >= 0) && (yi <= ((src_height - 1) * wi)); + bool cond_on_x = (xi >= 0) && (xi <= ((src_width - 1) * wi)); + if ((wi != 0) && cond_on_y && cond_on_x) { + const float wi_ = (wi >> nbits) + ((wi & 0xFFFF) * precision_1); + const float xi_ = ((xi >> nbits) + ((xi & 0xFFFF) * precision_1)) / wi_; + const float yi_ = ((yi >> nbits) + ((yi & 0xFFFF) * precision_1)) / wi_; + + const int x_ = static_cast(xi_); + const int y_ = static_cast(yi_); + + const float t = yi_ - y_; + const float s = xi_ - x_; + + if ((y_ < (src_height - 1)) && (x_ < (src_width - 1))) { + const float val00 = static_cast(src[y_][x_]); + const float val01 = static_cast(src[y_][x_ + 1]); + const float val10 = static_cast(src[y_ + 1][x_]); + const float val11 = static_cast(src[y_ + 1][x_ + 1]); + const float col0 = lerp(val00, val01, s); + const float col1 = lerp(val10, val11, s); + const float interp = lerp(col0, col1, t); + dst[i][j] = vpMath::saturate(interp); + } + else if (y_ < (src_height - 1)) { + const float val00 = static_cast(src[y_][x_]); + const float val10 = static_cast(src[y_ + 1][x_]); + const float interp = lerp(val00, val10, t); + dst[i][j] = vpMath::saturate(interp); + } + else if (x_ < (src_width - 1)) { + const float val00 = static_cast(src[y_][x_]); + const float val01 = static_cast(src[y_][x_ + 1]); + const float interp = lerp(val00, val01, s); + dst[i][j] = vpMath::saturate(interp); + } + else { + dst[i][j] = src[y_][x_]; + } + } + + xi += a0_i64; + yi += a3_i64; + wi += a6_i64; + } + + a2_i64 += a1_i64; + a5_i64 += a4_i64; + a8_i64 += a7_i64; + } + } + } + else { + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + double a0 = T[index_0][index_0]; + double a1 = T[index_0][index_1]; + double a2 = T[index_0][index_2]; + double a3 = T[index_1][index_0]; + double a4 = T[index_1][index_1]; + double a5 = T[index_1][index_2]; + double a6 = affine ? 0.0 : T[index_2][index_0]; + double a7 = affine ? 0.0 : T[index_2][index_1]; + double a8 = affine ? 1.0 : T[index_2][index_2]; + + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + int src_height = static_cast(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { + for (unsigned int j = 0; j < dst_width; ++j) { + double x = (a0 * (centerCorner ? (j + 0.5) : j)) + (a1 * (centerCorner ? (i + 0.5) : i)) + a2; + double y = (a3 * (centerCorner ? (j + 0.5) : j)) + (a4 * (centerCorner ? (i + 0.5) : i)) + a5; + double w = (a6 * (centerCorner ? (j + 0.5) : j)) + (a7 * (centerCorner ? (i + 0.5) : i)) + a8; + if (vpMath::nul(w, std::numeric_limits::epsilon())) { + w = 1; + } + + x = (x / w) - (centerCorner ? 0.5 : 0); + y = (y / w) - (centerCorner ? 0.5 : 0); + + int x_lower = static_cast(x); + int y_lower = static_cast(y); + bool stop_for_loop = false; + if ((y_lower >= src_height) || (x_lower >= src_width) || (y < 0) || (x < 0)) { + stop_for_loop = true; + } + if (!stop_for_loop) { + double s = x - x_lower; + double t = y - y_lower; + + if ((y_lower < (src_height - 1)) && (x_lower < (src_width - 1))) { + const double val00 = static_cast(src[y_lower][x_lower]); + const double val01 = static_cast(src[y_lower][x_lower + 1]); + const double val10 = static_cast(src[y_lower + 1][x_lower]); + const double val11 = static_cast(src[y_lower + 1][x_lower + 1]); + const double col0 = lerp(val00, val01, s); + const double col1 = lerp(val10, val11, s); + const double interp = lerp(col0, col1, t); + dst[i][j] = vpMath::saturate(interp); + } + else if (y_lower < (src_height - 1)) { + const double val00 = static_cast(src[y_lower][x_lower]); + const double val10 = static_cast(src[y_lower + 1][x_lower]); + const double interp = lerp(val00, val10, t); + dst[i][j] = vpMath::saturate(interp); + } + else if (x_lower < (src_width - 1)) { + const double val00 = static_cast(src[y_lower][x_lower]); + const double val01 = static_cast(src[y_lower][x_lower + 1]); + const double interp = lerp(val00, val01, s); + dst[i][j] = vpMath::saturate(interp); + } + else { + dst[i][j] = src[y_lower][x_lower]; + } + } + } + } + } +} + +inline void vpImageTools::warpLinearFixedPointNotCenter(const vpImage &src, const vpMatrix &T, + vpImage &dst, bool affine) +{ + const unsigned int index_0 = 0, index_1 = 1, index_2 = 2; + const int nbits = 16; + const int64_t precision = 1 << nbits; + const float precision_1 = 1.f / static_cast(precision); + const int64_t precision2 = 1ULL << (2 * nbits); + const float precision_2 = 1.f / static_cast(precision2); + + int64_t a0_i64 = static_cast(T[index_0][index_0] * precision); + int64_t a1_i64 = static_cast(T[index_0][index_1] * precision); + int64_t a2_i64 = static_cast(T[index_0][index_2] * precision); + int64_t a3_i64 = static_cast(T[index_1][index_0] * precision); + int64_t a4_i64 = static_cast(T[index_1][index_1] * precision); + int64_t a5_i64 = static_cast(T[index_1][index_2] * precision); + int64_t a6_i64 = T.getRows() == 3 ? static_cast(T[index_2][index_0] * precision) : 0; + int64_t a7_i64 = T.getRows() == 3 ? static_cast(T[index_2][index_1] * precision) : 0; + int64_t a8_i64 = precision; + + int64_t height_i64 = static_cast(src.getHeight() * precision); + int64_t width_i64 = static_cast(src.getWidth() * precision); + + if (affine) { + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + int src_height = static_cast(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { + int64_t xi = a2_i64; + int64_t yi = a5_i64; + + for (unsigned int j = 0; j < dst_width; ++j) { + if ((yi >= 0) && (yi < height_i64) && (xi >= 0) && (xi < width_i64)) { + const int64_t xi_lower = xi & (~0xFFFF); + const int64_t yi_lower = yi & (~0xFFFF); + + const int64_t t = yi - yi_lower; + const int64_t t_1 = precision - t; + const int64_t s = xi - xi_lower; + const int64_t s_1 = precision - s; + + const int x_ = static_cast(xi >> nbits); + const int y_ = static_cast(yi >> nbits); + + if ((y_ < (src_height - 1)) && (x_ < (src_width - 1))) { + const vpRGBa val00 = src[y_][x_]; + const vpRGBa val01 = src[y_][x_ + 1]; + const vpRGBa val10 = src[y_ + 1][x_]; + const vpRGBa val11 = src[y_ + 1][x_ + 1]; + const int64_t interpR_i64 = + static_cast((s_1 * t_1 * val00.R) + (s * t_1 * val01.R) + (s_1 * t * val10.R) + (s * t * val11.R)); + const float interpR = (interpR_i64 >> (nbits * 2)) + ((interpR_i64 & 0xFFFFFFFF) * precision_2); + + const int64_t interpG_i64 = + static_cast((s_1 * t_1 * val00.G) + (s * t_1 * val01.G) + (s_1 * t * val10.G) + (s * t * val11.G)); + const float interpG = (interpG_i64 >> (nbits * 2)) + ((interpG_i64 & 0xFFFFFFFF) * precision_2); + + const int64_t interpB_i64 = + static_cast((s_1 * t_1 * val00.B) + (s * t_1 * val01.B) + (s_1 * t * val10.B) + (s * t * val11.B)); + const float interpB = (interpB_i64 >> (nbits * 2)) + ((interpB_i64 & 0xFFFFFFFF) * precision_2); + + dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), + vpMath::saturate(interpB), 255); + } + else if (y_ < (src_height - 1)) { + const vpRGBa val00 = src[y_][x_]; + const vpRGBa val10 = src[y_ + 1][x_]; + const int64_t interpR_i64 = static_cast(t_1 * val00.R + t * val10.R); + const float interpR = (interpR_i64 >> nbits) + ((interpR_i64 & 0xFFFF) * precision_1); + + const int64_t interpG_i64 = static_cast((t_1 * val00.G) + (t * val10.G)); + const float interpG = (interpG_i64 >> nbits) + ((interpG_i64 & 0xFFFF) * precision_1); + + const int64_t interpB_i64 = static_cast((t_1 * val00.B) + (t * val10.B)); + const float interpB = (interpB_i64 >> nbits) + ((interpB_i64 & 0xFFFF) * precision_1); + + dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), + vpMath::saturate(interpB), 255); + } + else if (x_ < (src_width - 1)) { + const vpRGBa val00 = src[y_][x_]; + const vpRGBa val01 = src[y_][x_ + 1]; + const int64_t interpR_i64 = static_cast((s_1 * val00.R) + (s * val01.R)); + const float interpR = (interpR_i64 >> nbits) + ((interpR_i64 & 0xFFFF) * precision_1); + + const int64_t interpG_i64 = static_cast((s_1 * val00.G) + (s * val01.G)); + const float interpG = (interpG_i64 >> nbits) + ((interpG_i64 & 0xFFFF) * precision_1); + + const int64_t interpB_i64 = static_cast((s_1 * val00.B) + (s * val01.B)); + const float interpB = (interpB_i64 >> nbits) + ((interpB_i64 & 0xFFFF) * precision_1); + + dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), + vpMath::saturate(interpB), 255); + } + else { + dst[i][j] = src[y_][x_]; + } + } + + xi += a0_i64; + yi += a3_i64; + } + + a2_i64 += a1_i64; + a5_i64 += a4_i64; + } + } + else { + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + int src_height = static_cast(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { + int64_t xi = a2_i64; + int64_t yi = a5_i64; + int64_t wi = a8_i64; + + for (unsigned int j = 0; j < dst_width; ++j) { + if ((yi >= 0) && (yi <= ((src_height - 1) * wi)) && (xi >= 0) && + (xi <= ((src_width - 1) * wi))) { + const float wi_ = (wi >> nbits) + ((wi & 0xFFFF) * precision_1); + const float xi_ = ((xi >> nbits) + ((xi & 0xFFFF) * precision_1)) / wi_; + const float yi_ = ((yi >> nbits) + ((yi & 0xFFFF) * precision_1)) / wi_; + + const int x_ = static_cast(xi_); + const int y_ = static_cast(yi_); + + const float t = yi_ - y_; + const float s = xi_ - x_; + + if ((y_ < (src_height - 1)) && (x_ < (src_width - 1))) { + const vpRGBa val00 = src[y_][x_]; + const vpRGBa val01 = src[y_][x_ + 1]; + const vpRGBa val10 = src[y_ + 1][x_]; + const vpRGBa val11 = src[y_ + 1][x_ + 1]; + const float colR0 = lerp(val00.R, val01.R, s); + const float colR1 = lerp(val10.R, val11.R, s); + const float interpR = lerp(colR0, colR1, t); + + const float colG0 = lerp(val00.G, val01.G, s); + const float colG1 = lerp(val10.G, val11.G, s); + const float interpG = lerp(colG0, colG1, t); + + const float colB0 = lerp(val00.B, val01.B, s); + const float colB1 = lerp(val10.B, val11.B, s); + const float interpB = lerp(colB0, colB1, t); + + dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), + vpMath::saturate(interpB), 255); + } + else if (y_ < (src_height - 1)) { + const vpRGBa val00 = src[y_][x_]; + const vpRGBa val10 = src[y_ + 1][x_]; + const float interpR = lerp(val00.R, val10.R, t); + const float interpG = lerp(val00.G, val10.G, t); + const float interpB = lerp(val00.B, val10.B, t); + + dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), + vpMath::saturate(interpB), 255); + } + else if (x_ < (src_width - 1)) { + const vpRGBa val00 = src[y_][x_]; + const vpRGBa val01 = src[y_][x_ + 1]; + const float interpR = lerp(val00.R, val01.R, s); + const float interpG = lerp(val00.G, val01.G, s); + const float interpB = lerp(val00.B, val01.B, s); + + dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), + vpMath::saturate(interpB), 255); + } + else { + dst[i][j] = src[y_][x_]; + } + } + + xi += a0_i64; + yi += a3_i64; + wi += a6_i64; + } + + a2_i64 += a1_i64; + a5_i64 += a4_i64; + a8_i64 += a7_i64; + } + } + +} + +template <> +inline void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpImage &dst, bool affine, + bool centerCorner, bool fixedPoint) +{ + const unsigned int index_0 = 0, index_1 = 1, index_2 = 2; + if (fixedPoint && (!centerCorner)) { + warpLinearFixedPointNotCenter(src, T, dst, affine); + } + else { + double a0 = T[index_0][index_0]; + double a1 = T[index_0][index_1]; + double a2 = T[index_0][index_2]; + double a3 = T[index_1][index_0]; + double a4 = T[index_1][index_1]; + double a5 = T[index_1][index_2]; + double a6 = affine ? 0.0 : T[index_2][index_0]; + double a7 = affine ? 0.0 : T[index_2][index_1]; + double a8 = affine ? 1.0 : T[index_2][index_2]; + + unsigned int dst_height = dst.getHeight(); + unsigned int dst_width = dst.getWidth(); + int src_height = static_cast(src.getHeight()); + int src_width = static_cast(src.getWidth()); + for (unsigned int i = 0; i < dst_height; ++i) { + for (unsigned int j = 0; j < dst_width; ++j) { + double x = (a0 * (centerCorner ? (j + 0.5) : j)) + (a1 * (centerCorner ? (i + 0.5) : i)) + a2; + double y = (a3 * (centerCorner ? (j + 0.5) : j)) + (a4 * (centerCorner ? (i + 0.5) : i)) + a5; + double w = (a6 * (centerCorner ? (j + 0.5) : j)) + (a7 * (centerCorner ? (i + 0.5) : i)) + a8; + + x = (x / w) - (centerCorner ? 0.5 : 0); + y = (y / w) - (centerCorner ? 0.5 : 0); + + int x_lower = static_cast(x); + int y_lower = static_cast(y); + + bool stop_for_loop = false; + if ((y_lower >= src_height) || (x_lower >= src_width) || (y < 0) || (x < 0)) { + stop_for_loop = true; + } + if (!stop_for_loop) { + double s = x - x_lower; + double t = y - y_lower; + + if ((y_lower < (src_height - 1)) && (x_lower < (src_width - 1))) { + const vpRGBa val00 = src[y_lower][x_lower]; + const vpRGBa val01 = src[y_lower][x_lower + 1]; + const vpRGBa val10 = src[y_lower + 1][x_lower]; + const vpRGBa val11 = src[y_lower + 1][x_lower + 1]; + const double colR0 = lerp(val00.R, val01.R, s); + const double colR1 = lerp(val10.R, val11.R, s); + const double interpR = lerp(colR0, colR1, t); + + const double colG0 = lerp(val00.G, val01.G, s); + const double colG1 = lerp(val10.G, val11.G, s); + const double interpG = lerp(colG0, colG1, t); + + const double colB0 = lerp(val00.B, val01.B, s); + const double colB1 = lerp(val10.B, val11.B, s); + const double interpB = lerp(colB0, colB1, t); + + dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), + vpMath::saturate(interpB), 255); + } + else if (y_lower < (src_height - 1)) { + const vpRGBa val00 = src[y_lower][x_lower]; + const vpRGBa val10 = src[y_lower + 1][x_lower]; + const double interpR = lerp(val00.R, val10.R, t); + const double interpG = lerp(val00.G, val10.G, t); + const double interpB = lerp(val00.B, val10.B, t); + + dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), + vpMath::saturate(interpB), 255); + } + else if (x_lower < (src_width - 1)) { + const vpRGBa val00 = src[y_lower][x_lower]; + const vpRGBa val01 = src[y_lower][x_lower + 1]; + const double interpR = lerp(val00.R, val01.R, s); + const double interpG = lerp(val00.G, val01.G, s); + const double interpB = lerp(val00.B, val01.B, s); + + dst[i][j] = vpRGBa(vpMath::saturate(interpR), vpMath::saturate(interpG), + vpMath::saturate(interpB), 255); + } + else { + dst[i][j] = src[y_lower][x_lower]; + } + } + } + } + } +} + +#endif diff --git a/modules/core/include/visp3/core/vpImage_getters.h b/modules/core/include/visp3/core/vpImage_getters.h new file mode 100644 index 0000000000..d1e9e3e4ad --- /dev/null +++ b/modules/core/include/visp3/core/vpImage_getters.h @@ -0,0 +1,1097 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Image handling. + */ + +#ifndef VP_IMAGE_GETTERS_H +#define VP_IMAGE_GETTERS_H + +// Warning: this file shouldn't be included by the user. Internal usage only to reduce length of vpImage.h + +/*! + Retrieves pixel value from an image containing values of type `Type`. + + Gets the value of a sub-pixel with coordinates (i,j). + + \param i : Pixel coordinate along the rows. + \param j : Pixel coordinate along the columns. + + \return Pixel value. + + \exception vpImageException::notInTheImage : If (i,j) is out of the image. +*/ +template inline Type vpImage::getValue(unsigned int i, unsigned int j) const +{ + if ((i >= height) || (j >= width)) { + throw(vpException(vpImageException::notInTheImage, "Pixel outside the image")); + } + + return row[i][j]; +} + +/*! + Retrieves pixel value from an image containing values of type `Type` with + sub-pixel accuracy. + + Gets the value of a sub-pixel with coordinates (i,j) with bilinear + interpolation. + + See also vpImageTools::interpolate() for a similar result, but with a choice of the interpolation method. + + \param i : Sub-pixel coordinate along the rows. + \param j : Sub-pixel coordinate along the columns. + + \return Interpolated sub-pixel value from the four neighbours. + + \exception vpImageException::notInTheImage : If (i,j) is out of the image. +*/ +template Type vpImage::getValue(double i, double j) const +{ + if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { + throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); + } + if ((height * width) == 0) { + throw vpException(vpImageException::notInitializedError, "Empty image!"); + } + + unsigned int iround = static_cast(floor(i)); + unsigned int jround = static_cast(floor(j)); + + double rratio = i - static_cast(iround); + double cratio = j - static_cast(jround); + + double rfrac = 1.0 - rratio; + double cfrac = 1.0 - cratio; + + unsigned int iround_1 = std::min(height - 1, iround + 1); + unsigned int jround_1 = std::min(width - 1, jround + 1); + + double value = + (((static_cast(row[iround][jround]) * rfrac) + (static_cast(row[iround_1][jround]) * rratio)) * cfrac) + + (((static_cast(row[iround][jround_1]) * rfrac) + (static_cast(row[iround_1][jround_1]) * rratio)) * + cratio); + + return static_cast(vpMath::round(value)); +} + +/*! + \relates vpImage +*/ +template <> inline double vpImage::getValue(double i, double j) const +{ + if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { + throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); + } + if ((height * width) == 0) { + throw vpException(vpImageException::notInitializedError, "Empty image!"); + } + + unsigned int iround = static_cast(floor(i)); + unsigned int jround = static_cast(floor(j)); + + double rratio = i - static_cast(iround); + double cratio = j - static_cast(jround); + + double rfrac = 1.0 - rratio; + double cfrac = 1.0 - cratio; + + unsigned int iround_1 = std::min(height - 1, iround + 1); + unsigned int jround_1 = std::min(width - 1, jround + 1); + + return (((row[iround][jround] * rfrac) + (row[iround_1][jround] * rratio)) * cfrac) + + (((row[iround][jround_1] * rfrac) + (row[iround_1][jround_1] * rratio)) * cratio); +} + +/*! + \relates vpImage + */ +template <> inline unsigned char vpImage::getValue(double i, double j) const +{ + if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { + throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); + } + if ((height * width) == 0) { + throw vpException(vpImageException::notInitializedError, "Empty image!"); + } + + // alpha architecture is bi-endianness. The following optimization makes testImageGetValue failing +#if (defined(VISP_LITTLE_ENDIAN) || defined(VISP_BIG_ENDIAN)) && !(defined(__alpha__) || defined(_M_ALPHA)) + // Fixed-point arithmetic + const uint32_t magic_8 = 8; + const uint32_t magic_16 = 16; + const uint32_t magic_32 = 32; + const uint32_t magic_0x00FF = 0x00FF; + const uint32_t precision = 1U << magic_16; + uint64_t y = static_cast(i * precision); + uint64_t x = static_cast(j * precision); + + uint64_t iround = y & (~0xFFFFU); + uint64_t jround = x & (~0xFFFFU); + + uint64_t rratio = y - iround; + uint64_t cratio = x - jround; + + uint64_t rfrac = precision - rratio; + uint64_t cfrac = precision - cratio; + + uint64_t x_ = x >> magic_16; + uint64_t y_ = y >> magic_16; + + if (((y_ + 1) < height) && ((x_ + 1) < width)) { + uint16_t up = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + (y_ * width) + x_); + uint16_t down = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + ((y_ + 1) * width) + x_); + + return static_cast(((((up & magic_0x00FF) * rfrac) + ((down & magic_0x00FF) * rratio)) * cfrac + + (((up >> magic_8) * rfrac) + ((down >> 8) * rratio)) * cratio) >> + magic_32); + } + else if ((y_ + 1) < height) { + return static_cast(((row[y_][x_] * rfrac) + (row[y_ + 1][x_] * rratio)) >> 16); + } + else if ((x_ + 1) < width) { + uint16_t up = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + (y_ * width) + x_); + return static_cast((((up & 0x00FF) * cfrac) + ((up >> 8) * cratio)) >> magic_16); + } + else { + return row[y_][x_]; + } +#else + unsigned int iround = static_cast(floor(i)); + unsigned int jround = static_cast(floor(j)); + + if (iround >= height || jround >= width) { + throw(vpException(vpImageException::notInTheImage, "Pixel outside the image")); + } + + double rratio = i - static_cast(iround); + double cratio = j - static_cast(jround); + + double rfrac = 1.0 - rratio; + double cfrac = 1.0 - cratio; + + unsigned int iround_1 = std::min(height - 1, iround + 1); + unsigned int jround_1 = std::min(width - 1, jround + 1); + + double value = + (static_cast(row[iround][jround]) * rfrac + static_cast(row[iround_1][jround]) * rratio) * cfrac + + (static_cast(row[iround][jround_1]) * rfrac + static_cast(row[iround_1][jround_1]) * rratio) * + cratio; + return static_cast(vpMath::round(value)); +#endif +} + +/*! + \relates vpImage + */ +template <> inline vpRGBa vpImage::getValue(double i, double j) const +{ + if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { + throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); + } + if ((height * width) == 0) { + throw vpException(vpImageException::notInitializedError, "Empty image!"); + } + + unsigned int iround = static_cast(floor(i)); + unsigned int jround = static_cast(floor(j)); + + double rratio = i - static_cast(iround); + double cratio = j - static_cast(jround); + + double rfrac = 1.0 - rratio; + double cfrac = 1.0 - cratio; + + unsigned int iround_1 = std::min(height - 1, iround + 1); + unsigned int jround_1 = std::min(width - 1, jround + 1); + + double valueR = + (((static_cast(row[iround][jround].R) * rfrac) + (static_cast(row[iround_1][jround].R) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].R) * rfrac) + (static_cast(row[iround_1][jround_1].R) * rratio)) * + cratio); + double valueG = + (((static_cast(row[iround][jround].G) * rfrac) + (static_cast(row[iround_1][jround].G) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].G) * rfrac) + (static_cast(row[iround_1][jround_1].G) * rratio)) * + cratio); + double valueB = + (((static_cast(row[iround][jround].B) * rfrac) + (static_cast(row[iround_1][jround].B) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].B) * rfrac) + (static_cast(row[iround_1][jround_1].B) * rratio)) * + cratio); + + return vpRGBa(static_cast(vpMath::round(valueR)), static_cast(vpMath::round(valueG)), + static_cast(vpMath::round(valueB))); +} + +/*! + \relates vpImage + */ +template <> inline vpRGBf vpImage::getValue(double i, double j) const +{ + if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) { + throw(vpException(vpImageException::notInTheImage, "Pixel outside of the image")); + } + if ((height * width) == 0) { + throw vpException(vpImageException::notInitializedError, "Empty image!"); + } + + unsigned int iround = static_cast(floor(i)); + unsigned int jround = static_cast(floor(j)); + + double rratio = i - static_cast(iround); + double cratio = j - static_cast(jround); + + double rfrac = 1.0 - rratio; + double cfrac = 1.0 - cratio; + + unsigned int iround_1 = std::min(height - 1, iround + 1); + unsigned int jround_1 = std::min(width - 1, jround + 1); + + double valueR = + (((static_cast(row[iround][jround].R) * rfrac) + (static_cast(row[iround_1][jround].R) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].R) * rfrac) + (static_cast(row[iround_1][jround_1].R) * rratio)) * + cratio); + double valueG = + (((static_cast(row[iround][jround].G) * rfrac) + (static_cast(row[iround_1][jround].G) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].G) * rfrac) + (static_cast(row[iround_1][jround_1].G) * rratio)) * + cratio); + double valueB = + (((static_cast(row[iround][jround].B) * rfrac) + (static_cast(row[iround_1][jround].B) * rratio)) * + cfrac) + + (((static_cast(row[iround][jround_1].B) * rfrac) + (static_cast(row[iround_1][jround_1].B) * rratio)) * + cratio); + + return vpRGBf(static_cast(valueR), static_cast(valueG), static_cast(valueB)); +} + +/*! + Retrieves pixel value from an image containing values of type \e Type with + sub-pixel accuracy. + + Gets the value of a sub-pixel with coordinates (i,j) with bilinear + interpolation. + + See also vpImageTools::interpolate() for a similar result, but with a choice of the interpolation method. + + \param ip : Sub-pixel coordinates of a point in the image. + + \return Interpolated sub-pixel value from the four neighbors. + + \exception vpImageException::notInTheImage : If the image point \e ip is out + of the image. +*/ +template inline Type vpImage::getValue(const vpImagePoint &ip) const +{ + return getValue(ip.get_i(), ip.get_j()); +} + +/*! + \relates vpImage + */ +template <> inline double vpImage::getValue(const vpImagePoint &ip) const +{ + return getValue(ip.get_i(), ip.get_j()); +} + +/*! + \relates vpImage + */ +template <> inline unsigned char vpImage::getValue(const vpImagePoint &ip) const +{ + return getValue(ip.get_i(), ip.get_j()); +} + +/*! + \relates vpImage + */ +template <> inline vpRGBa vpImage::getValue(const vpImagePoint &ip) const +{ + return getValue(ip.get_i(), ip.get_j()); +} + +/*! + * \brief Return the maximum value within the bitmap + * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. + * If true, consider only finite values. + * + * \sa getMinValue() + */ +template Type vpImage::getMaxValue(bool onlyFiniteVal) const +{ + if (npixels == 0) { + throw(vpException(vpException::fatalError, "Cannot compute maximum value of an empty image")); + } + Type m = bitmap[0]; + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] > m) { + m = bitmap[i]; + } + } + (void)onlyFiniteVal; + return m; +} + +/*! + * \relates vpImage + * \brief Return the maximum value within the double bitmap. + * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. + * If true, consider only finite values. + * + * \sa getMinValue() + */ +template <> inline double vpImage::getMaxValue(bool onlyFiniteVal) const +{ + if (npixels == 0) { + throw(vpException(vpException::fatalError, "Cannot compute maximum value of an empty image")); + } + double m = bitmap[0]; + if (onlyFiniteVal) { + for (unsigned int i = 0; i < npixels; ++i) { + if ((bitmap[i] > m) && (vpMath::isFinite(bitmap[i]))) { + m = bitmap[i]; + } + } + } + else { + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] > m) { + m = bitmap[i]; + } + } + } + return m; +} + +/*! + * \relates vpImage + * \brief Return the maximum value within the float bitmap. + * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. + * If true, consider only finite values. + * + * \sa getMinValue() + */ +template <> inline float vpImage::getMaxValue(bool onlyFiniteVal) const +{ + if (npixels == 0) { + throw(vpException(vpException::fatalError, "Cannot compute maximum value of an empty image")); + } + float m = bitmap[0]; + if (onlyFiniteVal) { + for (unsigned int i = 0; i < npixels; ++i) { + if ((bitmap[i] > m) && (vpMath::isFinite(bitmap[i]))) { + m = bitmap[i]; + } + } + } + else { + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] > m) { + m = bitmap[i]; + } + } + } + return m; +} + +/*! + * \brief Return the minimum value within the bitmap + * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. + * If true, consider only finite values. + * + * \sa getMaxValue() + */ +template Type vpImage::getMinValue(bool onlyFiniteVal) const +{ + if (npixels == 0) { + throw(vpException(vpException::fatalError, "Cannot compute minimum value of an empty image")); + } + Type m = bitmap[0]; + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] < m) { + m = bitmap[i]; + } + } + (void)onlyFiniteVal; + return m; +} + +/*! + * \relates vpImage + * \brief Return the minimum value within the double bitmap. + * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. + * If true, consider only finite values. + * + * \sa getMaxValue() + */ +template <> inline double vpImage::getMinValue(bool onlyFiniteVal) const +{ + if (npixels == 0) { + throw(vpException(vpException::fatalError, "Cannot compute minimum value of an empty image")); + } + double m = bitmap[0]; + if (onlyFiniteVal) { + for (unsigned int i = 0; i < npixels; ++i) { + if ((bitmap[i] < m) && (vpMath::isFinite(bitmap[i]))) { + m = bitmap[i]; + } + } + } + else { + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] < m) { + m = bitmap[i]; + } + } + } + return m; +} + +/*! + * \relates vpImage + * \brief Return the minimum value within the float bitmap. + * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. + * If true, consider only finite values. + * + * \sa getMaxValue() + */ +template <> inline float vpImage::getMinValue(bool onlyFiniteVal) const +{ + if (npixels == 0) { + throw(vpException(vpException::fatalError, "Cannot compute minimum value of an empty image")); + } + float m = bitmap[0]; + if (onlyFiniteVal) { + for (unsigned int i = 0; i < npixels; ++i) { + if ((bitmap[i] < m) && (vpMath::isFinite(bitmap[i]))) { + m = bitmap[i]; + } + } + } + else { + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] < m) { + m = bitmap[i]; + } + } + } + return m; +} + +/*! + * \brief Look for the minimum and the maximum value within the bitmap + * \param min : The minimal value within the bitmap. + * \param max : The maximal value within the bitmap. + * \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap. + * + * \sa getMaxValue() + * \sa getMinValue() + * \sa getMinMaxLoc() + */ +template void vpImage::getMinMaxValue(Type &min, Type &max, bool onlyFiniteVal) const +{ + if (npixels == 0) { + throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); + } + + min = bitmap[0]; + max = bitmap[0]; + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] < min) { + min = bitmap[i]; + } + if (bitmap[i] > max) { + max = bitmap[i]; + } + } + (void)onlyFiniteVal; +} + +/*! + * \relates vpImage + * \brief Look for the minimum and the maximum value within the double bitmap + * \param min : The minimal value within the bitmap. + * \param max : The maximal value within the bitmap. + * \param onlyFiniteVal : If true, consider only finite values. + * + * \sa getMaxValue() + * \sa getMinValue() + * \sa getMinMaxLoc() + */ +template <> inline void vpImage::getMinMaxValue(double &min, double &max, bool onlyFiniteVal) const +{ + if (npixels == 0) { + throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); + } + + min = bitmap[0]; + max = bitmap[0]; + if (onlyFiniteVal) { + for (unsigned int i = 0; i < npixels; ++i) { + if (vpMath::isFinite(bitmap[i])) { + if (bitmap[i] < min) { + min = bitmap[i]; + } + if (bitmap[i] > max) { + max = bitmap[i]; + } + } + } + } + else { + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] < min) { + min = bitmap[i]; + } + if (bitmap[i] > max) { + max = bitmap[i]; + } + } + } +} + +/*! + * \relates vpImage + * \brief Look for the minimum and the maximum value within the float bitmap + * \param min : The minimal value within the bitmap. + * \param max : The maximal value within the bitmap. + * \param onlyFiniteVal : If true, consider only finite values. + * + * \sa getMaxValue() + * \sa getMinValue() + * \sa getMinMaxLoc() + */ +template <> inline void vpImage::getMinMaxValue(float &min, float &max, bool onlyFiniteVal) const +{ + if (npixels == 0) { + throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); + } + + min = bitmap[0]; + max = bitmap[0]; + if (onlyFiniteVal) { + for (unsigned int i = 0; i < npixels; ++i) { + if (vpMath::isFinite(bitmap[i])) { + if (bitmap[i] < min) { + min = bitmap[i]; + } + if (bitmap[i] > max) { + max = bitmap[i]; + } + } + } + } + else { + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] < min) { + min = bitmap[i]; + } + if (bitmap[i] > max) { + max = bitmap[i]; + } + } + } +} + +/*! + \brief Look for the minimum and the maximum value within the 3-channels float bitmap + \param min : The minimal values within the bitmap. + \param max : The maximal values within the bitmap. + \param onlyFiniteVal : If true, consider only finite values. + + \sa getMaxValue() + \sa getMinValue() + \sa getMinMaxLoc() +*/ +template <> inline void vpImage::getMinMaxValue(vpRGBf &min, vpRGBf &max, bool onlyFiniteVal) const +{ + if (npixels == 0) { + throw(vpException(vpException::fatalError, "Cannot get minimum/maximum values of an empty image")); + } + + min = bitmap[0]; + max = bitmap[0]; + if (onlyFiniteVal) { + for (unsigned int i = 0; i < npixels; ++i) { + if (vpMath::isFinite(bitmap[i].R)) { + if (bitmap[i].R < min.R) { + min.R = bitmap[i].R; + } + if (bitmap[i].R > max.R) { + max.R = bitmap[i].R; + } + } + if (vpMath::isFinite(bitmap[i].G)) { + if (bitmap[i].G < min.G) { + min.G = bitmap[i].G; + } + if (bitmap[i].G > max.G) { + max.G = bitmap[i].G; + } + } + if (vpMath::isFinite(bitmap[i].B)) { + if (bitmap[i].B < min.B) { + min.B = bitmap[i].B; + } + if (bitmap[i].B > max.B) { + max.B = bitmap[i].B; + } + } + } + } + else { + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i].R < min.R) { + min.R = bitmap[i].R; + } + if (bitmap[i].R > max.R) { + max.R = bitmap[i].R; + } + + if (bitmap[i].G < min.G) { + min.G = bitmap[i].G; + } + if (bitmap[i].G > max.G) { + max.G = bitmap[i].G; + } + + if (bitmap[i].B < min.B) { + min.B = bitmap[i].B; + } + if (bitmap[i].B > max.B) { + max.B = bitmap[i].B; + } + } + } +} + +/*! + \brief Get the position of the minimum and/or the maximum pixel value within the bitmap and + the corresponding value. + Following code allows retrieving only minimum value and position: + \code + vpImage I(h, w); + //[...] Fill I + vpImagePoint min_loc; + double min_val = 0.0; + I.getMinMaxLoc(&min_loc, nullptr, &min_val, nullptr); + \endcode + + \param minLoc : Position of the pixel with minimum value if not nullptr. + \param maxLoc : Position of the pixel with maximum value if not nullptr. + \param minVal : Minimum pixel value if not nullptr. + \param maxVal : Maximum pixel value if not nullptr. + + \sa getMaxValue() + \sa getMinValue() + \sa getMinMaxValue() +*/ +template +void vpImage::getMinMaxLoc(vpImagePoint *minLoc, vpImagePoint *maxLoc, Type *minVal, Type *maxVal) const +{ + if (npixels == 0) { + throw(vpException(vpException::fatalError, "Cannot get location of minimum/maximum " + "values of an empty image")); + } + + Type min = bitmap[0], max = bitmap[0]; + vpImagePoint minLoc_, maxLoc_; + for (unsigned int i = 0; i < height; ++i) { + for (unsigned int j = 0; j < width; ++j) { + if (row[i][j] < min) { + min = row[i][j]; + minLoc_.set_ij(i, j); + } + + if (row[i][j] > max) { + max = row[i][j]; + maxLoc_.set_ij(i, j); + } + } + } + + if (minLoc != nullptr) { + *minLoc = minLoc_; + } + + if (maxLoc != nullptr) { + *maxLoc = maxLoc_; + } + + if (minVal != nullptr) { + *minVal = min; + } + + if (maxVal != nullptr) { + *maxVal = max; + } +} + +/*! + * \brief Return the mean value of the bitmap. + * + * For vpRGBa and vpRGBf image types, the sum of image intensities is computed by (R+G+B). + * + * \param[in] p_mask Optional parameter. If not set to nullptr, a boolean mask that indicates which points must be + * considered, if set to true. + * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are + * valid according to the boolean mask or image size when `p_mask` is set to nullptr. + */ +template double vpImage::getMeanValue(const vpImage *p_mask, unsigned int *nbValidPoints) const +{ + if ((height == 0) || (width == 0)) { + return 0.0; + } + unsigned int nbPointsInMask = 0; + double sum = getSum(p_mask, &nbPointsInMask); + if (nbPointsInMask == 0) { + throw(vpException(vpException::divideByZeroError, "Division by zero in vpImage::getMeanValue()")); + } + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; + } + return sum / nbPointsInMask; +} + +/*! +* \brief Return the standard deviation of the bitmap +* +* - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: +* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] +* - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: +* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] +* +* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ +* is the number of pixels to consider in the mask. +* +* \param[in] p_mask A boolean mask that indicates which points must be considered, if set to true. +* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are +* valid according to the boolean mask or image size when `p_mask` is set to nullptr. +*/ +template double vpImage::getStdev(const vpImage *p_mask, unsigned int *nbValidPoints) const +{ + double mean = getMeanValue(p_mask, nbValidPoints); + return getStdev(mean, p_mask); +} + +/*! +* \brief Return the standard deviation of the bitmap +* +* - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: +* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] +* - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: +* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] +* +* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ +* is the number of pixels to consider in the mask. +* +* \param[in] mean The mean of the image. +* \param[in] p_mask Optional parameter. When different from nullptr, a boolean mask that indicates which pixels must +* be considered, if set to true. +* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are +* valid according to the boolean mask or image size when `p_mask` is set to nullptr. +* \return double The standard deviation taking into account only the points for which the mask is true. +*/ +template double vpImage::getStdev(const double &mean, const vpImage *p_mask, unsigned int *nbValidPoints) const +{ + if ((height == 0) || (width == 0)) { + return 0.0; + } + const unsigned int size = width * height; + double sum = 0.; + unsigned int nbPointsInMask = 0; + if (p_mask) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { + throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); + } + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + sum += (bitmap[i] - mean) * (bitmap[i] - mean); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < size; ++i) { + sum += (bitmap[i] - mean) * (bitmap[i] - mean); + } + nbPointsInMask = size; + } + sum /= static_cast(nbPointsInMask); + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; + } + return std::sqrt(sum); +} + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +/*! +* \brief Return the standard deviation of the bitmap +* +* - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: +* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] +* - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: +* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] +* +* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ +* is the number of pixels to consider in the mask. +* +* \param[in] mean The mean of the image. +* \param[in] p_mask Optional parameter. When different from nullptr, a boolean mask that indicates which pixels must +* be considered, if set to true. +* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are +* valid according to the boolean mask or image size when `p_mask` is set to nullptr. +* \return double The standard deviation taking into account only the points for which the mask is true. +*/ +template <> inline double vpImage::getStdev(const double &mean, const vpImage *p_mask, unsigned int *nbValidPoints) const +{ + if ((height == 0) || (width == 0)) { + return 0.0; + } + const unsigned int size = width * height; + double sum = 0.; + unsigned int nbPointsInMask = 0; + if (p_mask) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { + throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); + } + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + sum += (val - mean) * (val - mean); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < size; ++i) { + double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + sum += (val - mean) * (val - mean); + } + nbPointsInMask = size; + } + sum /= static_cast(nbPointsInMask); + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; + } + return std::sqrt(sum); +} + +/*! +* \brief Return the standard deviation of the bitmap +* +* - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: +* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] +* - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: +* \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] +* +* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ +* is the number of pixels to consider in the mask. +* +* \param[in] mean The mean of the image. +* \param[in] p_mask Optional parameter. When different from nullptr, a boolean mask that indicates which pixels must +* be considered, if set to true. +* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are +* valid according to the boolean mask or image size when `p_mask` is set to nullptr. +* \return double The standard deviation taking into account only the points for which the mask is true. +*/ +template <> inline double vpImage::getStdev(const double &mean, const vpImage *p_mask, unsigned int *nbValidPoints) const +{ + if ((height == 0) || (width == 0)) { + return 0.0; + } + const unsigned int size = width * height; + double sum = 0.; + unsigned int nbPointsInMask = 0; + if (p_mask) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { + throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); + } + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + sum += (val - mean) * (val - mean); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < size; ++i) { + double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + sum += (val - mean) * (val - mean); + } + nbPointsInMask = size; + } + sum /= static_cast(nbPointsInMask); + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; + } + return std::sqrt(sum); +} +#endif // DOXYGEN_SHOULD_SKIP_THIS + +/** + * \brief Compute the sum of image intensities. + * - For unary image types (unsigned char, float, double), compute the sum of image intensities. + * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. + * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. + * + * \param[in] p_mask Optional parameter. If not set to nullptr, pointer to a boolean mask that indicates the valid + * points by a true flag. + * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are + * valid according to the boolean mask or image size when `p_mask` is set to nullptr. + */ +template inline double vpImage::getSum(const vpImage *p_mask, unsigned int *nbValidPoints) const +{ + if ((height == 0) || (width == 0)) { + if (nbValidPoints) { + *nbValidPoints = 0; + } + return 0.0; + } + if (p_mask) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { + throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); + } + } + double res = 0.0; + unsigned int nbPointsInMask = 0; + unsigned int size = height * width; + if (p_mask) { + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + res += static_cast(bitmap[i]); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < size; ++i) { + res += static_cast(bitmap[i]); + } + nbPointsInMask = size; + } + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; + } + + return res; +} + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +/** + * \brief Compute the sum of image intensities. + * - For unary image types (unsigned char, float, double), compute the sum of image intensities. + * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. + * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. + * + * \param[in] p_mask Optional parameter. If not set to nullptr, pointer to a boolean mask that indicates the valid + * points by a true flag. + * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are + * valid according to the boolean mask or image size when `p_mask` is set to nullptr. + */ +template <> inline double vpImage::getSum(const vpImage *p_mask, unsigned int *nbValidPoints) const +{ + if ((height == 0) || (width == 0)) { + return 0.0; + } + double res = 0.0; + unsigned int nbPointsInMask = 0; + unsigned int size = height * width; + if (p_mask) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { + throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); + } + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < (height * width); ++i) { + res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + } + nbPointsInMask = size; + } + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; + } + return res; +} + +/** + * \brief Compute the sum of image intensities. + * - For unary image types (unsigned char, float, double), compute the sum of image intensities. + * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. + * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. + * + * \param[in] p_mask Optional parameter. If not set to nullptr, pointer to a boolean mask that indicates the valid + * points by a true flag. + * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are + * valid according to the boolean mask or image size when `p_mask` is set to nullptr. + */ +template <> inline double vpImage::getSum(const vpImage *p_mask, unsigned int *nbValidPoints) const +{ + if ((height == 0) || (width == 0)) { + return 0.0; + } + double res = 0.0; + unsigned int nbPointsInMask = 0; + unsigned int size = height * width; + if (p_mask) { + if ((p_mask->getWidth() != width) || (p_mask->getHeight() != height)) { + throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); + } + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < (height * width); ++i) { + res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + } + nbPointsInMask = size; + } + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; + } + return res; +} +#endif // DOXYGEN_SHOULD_SKIP_THIS + +#endif diff --git a/modules/core/include/visp3/core/vpImage_lut.h b/modules/core/include/visp3/core/vpImage_lut.h new file mode 100644 index 0000000000..77248e06b2 --- /dev/null +++ b/modules/core/include/visp3/core/vpImage_lut.h @@ -0,0 +1,347 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Image handling. + */ + +#ifndef VP_IMAGE_LUT_H +#define VP_IMAGE_LUT_H + +// Warning: this file shouldn't be included by the user. Internal usage only to reduce length of vpImage.h + +#if defined(VISP_HAVE_THREADS) +namespace +{ +struct vpImageLut_Param_t +{ + unsigned int m_start_index; + unsigned int m_end_index; + + unsigned char m_lut[256]; + unsigned char *m_bitmap; + + vpImageLut_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(nullptr) { } + + vpImageLut_Param_t(unsigned int start_index, unsigned int end_index, unsigned char *bitmap) + : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap) + { } +}; + +void performLutThread(vpImageLut_Param_t *imageLut_param) +{ + unsigned int start_index = imageLut_param->m_start_index; + unsigned int end_index = imageLut_param->m_end_index; + + unsigned char *bitmap = imageLut_param->m_bitmap; + + unsigned char *ptrStart = bitmap + start_index; + unsigned char *ptrEnd = bitmap + end_index; + unsigned char *ptrCurrent = ptrStart; + + if (end_index - start_index >= 8) { + // Unroll loop version + for (; ptrCurrent <= ptrEnd - 8;) { + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; + ++ptrCurrent; + + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; + ++ptrCurrent; + + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; + ++ptrCurrent; + + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; + ++ptrCurrent; + + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; + ++ptrCurrent; + + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; + ++ptrCurrent; + + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; + ++ptrCurrent; + + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; + ++ptrCurrent; + } + } + + for (; ptrCurrent != ptrEnd; ++ptrCurrent) { + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent]; + } +} + +struct vpImageLutRGBa_Param_t +{ + unsigned int m_start_index; + unsigned int m_end_index; + + VISP_NAMESPACE_ADDRESSING vpRGBa m_lut[256]; + unsigned char *m_bitmap; + + vpImageLutRGBa_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(nullptr) { } + + vpImageLutRGBa_Param_t(unsigned int start_index, unsigned int end_index, unsigned char *bitmap) + : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap) + { } +}; + +void performLutRGBaThread(vpImageLutRGBa_Param_t *imageLut_param) +{ + unsigned int start_index = imageLut_param->m_start_index; + unsigned int end_index = imageLut_param->m_end_index; + + unsigned char *bitmap = imageLut_param->m_bitmap; + + unsigned char *ptrStart = bitmap + start_index * 4; + unsigned char *ptrEnd = bitmap + end_index * 4; + unsigned char *ptrCurrent = ptrStart; + + if (end_index - start_index >= 4 * 2) { + // Unroll loop version + for (; ptrCurrent <= ptrEnd - 4 * 2;) { + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R; + ptrCurrent++; + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G; + ptrCurrent++; + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B; + ptrCurrent++; + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A; + ptrCurrent++; + + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R; + ptrCurrent++; + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G; + ptrCurrent++; + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B; + ptrCurrent++; + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A; + ptrCurrent++; + } + } + + while (ptrCurrent != ptrEnd) { + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R; + ptrCurrent++; + + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G; + ptrCurrent++; + + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B; + ptrCurrent++; + + *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A; + ptrCurrent++; + } +} +} // namespace +#endif + +/*! + \warning This generic method is not implemented. You should rather use the + instantiated methods for unsigned char and vpRGBa images. + + \sa vpImage::performLut(const unsigned char (&lut)[256], unsigned int nbThreads) + \sa vpImage::performLut(const vpRGBa (&lut)[256], unsigned int nbThreads) + +*/ +template void vpImage::performLut(const Type(&)[256], unsigned int) +{ + std::cerr << "Not implemented !" << std::endl; +} + +/*! + \relates vpImage + + Modify the intensities of a grayscale image using the look-up table passed + in parameter. + + \param lut : Look-up table (unsigned char array of size=256) which maps each + intensity to his new value. + \param nbThreads : Number of threads to use for the computation. +*/ +template <> inline void vpImage::performLut(const unsigned char(&lut)[256], unsigned int nbThreads) +{ + unsigned int size = getWidth() * getHeight(); + unsigned char *ptrStart = static_cast(bitmap); + unsigned char *ptrEnd = ptrStart + size; + unsigned char *ptrCurrent = ptrStart; + + bool use_single_thread = ((nbThreads == 0) || (nbThreads == 1)); +#if !defined(VISP_HAVE_THREADS) + use_single_thread = true; +#endif + + if ((!use_single_thread) && (getSize() <= nbThreads)) { + use_single_thread = true; + } + + if (use_single_thread) { + // Single thread + + while (ptrCurrent != ptrEnd) { + *ptrCurrent = lut[*ptrCurrent]; + ++ptrCurrent; + } + } + else { +#if defined(VISP_HAVE_THREADS) + // Multi-threads + std::vector threadpool; + std::vector imageLutParams; + + unsigned int image_size = getSize(); + unsigned int step = image_size / nbThreads; + unsigned int last_step = image_size - step * (nbThreads - 1); + + for (unsigned int index = 0; index < nbThreads; ++index) { + unsigned int start_index = index * step; + unsigned int end_index = (index + 1) * step; + + if (index == nbThreads - 1) { + end_index = start_index + last_step; + } + + vpImageLut_Param_t *imageLut_param = new vpImageLut_Param_t(start_index, end_index, bitmap); + memcpy(imageLut_param->m_lut, lut, 256 * sizeof(unsigned char)); + + imageLutParams.push_back(imageLut_param); + + // Start the threads + std::thread *imageLut_thread = new std::thread(&performLutThread, imageLut_param); + threadpool.push_back(imageLut_thread); + } + + for (size_t cpt = 0; cpt < threadpool.size(); ++cpt) { + // Wait until thread ends up + threadpool[cpt]->join(); + } + + // Delete + for (size_t cpt = 0; cpt < threadpool.size(); ++cpt) { + delete threadpool[cpt]; + } + + for (size_t cpt = 0; cpt < imageLutParams.size(); ++cpt) { + delete imageLutParams[cpt]; + } +#endif + } +} + +/*! + \relates vpImage + + Modify the intensities of a color image using the look-up table passed in + parameter. + + \param lut : Look-up table (vpRGBa array of size=256) which maps each + intensity to his new value. + \param nbThreads : Number of threads to use for the computation. +*/ +template <> inline void vpImage::performLut(const vpRGBa(&lut)[256], unsigned int nbThreads) +{ + unsigned int size = getWidth() * getHeight(); + unsigned char *ptrStart = reinterpret_cast(bitmap); + unsigned char *ptrEnd = ptrStart + (size * 4); + unsigned char *ptrCurrent = ptrStart; + + bool use_single_thread = ((nbThreads == 0) || (nbThreads == 1)); +#if !defined(VISP_HAVE_THREADS) + use_single_thread = true; +#endif + + if ((!use_single_thread) && (getSize() <= nbThreads)) { + use_single_thread = true; + } + + if (use_single_thread) { + // Single thread + while (ptrCurrent != ptrEnd) { + *ptrCurrent = lut[*ptrCurrent].R; + ++ptrCurrent; + + *ptrCurrent = lut[*ptrCurrent].G; + ++ptrCurrent; + + *ptrCurrent = lut[*ptrCurrent].B; + ++ptrCurrent; + + *ptrCurrent = lut[*ptrCurrent].A; + ++ptrCurrent; + } + } + else { +#if defined(VISP_HAVE_THREADS) + // Multi-threads + std::vector threadpool; + std::vector imageLutParams; + + unsigned int image_size = getSize(); + unsigned int step = image_size / nbThreads; + unsigned int last_step = image_size - step * (nbThreads - 1); + + for (unsigned int index = 0; index < nbThreads; ++index) { + unsigned int start_index = index * step; + unsigned int end_index = (index + 1) * step; + + if (index == nbThreads - 1) { + end_index = start_index + last_step; + } + + vpImageLutRGBa_Param_t *imageLut_param = new vpImageLutRGBa_Param_t(start_index, end_index, (unsigned char *)bitmap); + memcpy(static_cast(imageLut_param->m_lut), lut, 256 * sizeof(vpRGBa)); + + imageLutParams.push_back(imageLut_param); + + // Start the threads + std::thread *imageLut_thread = new std::thread(&performLutRGBaThread, imageLut_param); + threadpool.push_back(imageLut_thread); + } + + for (size_t cpt = 0; cpt < threadpool.size(); ++cpt) { + // Wait until thread ends up + threadpool[cpt]->join(); + } + + // Delete + for (size_t cpt = 0; cpt < threadpool.size(); ++cpt) { + delete threadpool[cpt]; + } + + for (size_t cpt = 0; cpt < imageLutParams.size(); ++cpt) { + delete imageLutParams[cpt]; + } +#endif + } +} + +#endif diff --git a/modules/core/include/visp3/core/vpImage_operators.h b/modules/core/include/visp3/core/vpImage_operators.h new file mode 100644 index 0000000000..7d8d15f6b8 --- /dev/null +++ b/modules/core/include/visp3/core/vpImage_operators.h @@ -0,0 +1,278 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Image handling. + */ + +#ifndef VP_IMAGE_OPERATOR_H +#define VP_IMAGE_OPERATOR_H + +// Warning: this file shouldn't be included by the user. Internal usage only to reduce length of vpImage.h + +template std::ostream &operator<<(std::ostream &s, const vpImage &I) +{ + if (I.bitmap == nullptr) { + return s; + } + + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < (i_width - 1); ++j) { + s << I[i][j] << " "; + } + + // We don't add " " after the last column element + s << I[i][i_width - 1]; + + // We don't add a \n character at the end of the last row line + if (i < (i_height - 1)) { + s << std::endl; + } + } + + return s; +} + +inline std::ostream &operator<<(std::ostream &s, const vpImage &I) +{ + if (I.bitmap == nullptr) { + return s; + } + + std::ios_base::fmtflags original_flags = s.flags(); + const unsigned int magic_3 = 3; + + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < (i_width - 1); ++j) { + s << std::setw(magic_3) << static_cast(I[i][j]) << " "; + } + + // We don't add " " after the last column element + s << std::setw(magic_3) << static_cast(I[i][I.getWidth() - 1]); + + // We don't add a \n character at the end of the last row line + if (i < (i_height - 1)) { + s << std::endl; + } + } + + s.flags(original_flags); // restore s to standard state + return s; +} + +inline std::ostream &operator<<(std::ostream &s, const vpImage &I) +{ + if (I.bitmap == nullptr) { + return s; + } + + std::ios_base::fmtflags original_flags = s.flags(); + const unsigned int magic_4 = 4; + + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < (i_width - 1); ++j) { + s << std::setw(magic_4) << static_cast(I[i][j]) << " "; + } + + // We don't add " " after the last column element + s << std::setw(magic_4) << static_cast(I[i][i_width - 1]); + + // We don't add a \n character at the end of the last row line + if (i < (i_height - 1)) { + s << std::endl; + } + } + + s.flags(original_flags); // restore s to standard state + return s; +} + +inline std::ostream &operator<<(std::ostream &s, const vpImage &I) +{ + if (I.bitmap == nullptr) { + return s; + } + + std::ios_base::fmtflags original_flags = s.flags(); + const unsigned int magic_9 = 9; + s.precision(magic_9); // http://en.cppreference.com/w/cpp/types/numeric_limits/max_digits10 + + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < (i_width - 1); ++j) { + s << I[i][j] << " "; + } + + // We don't add " " after the last column element + s << I[i][i_width - 1]; + + // We don't add a \n character at the end of the last row line + if (i < (i_height - 1)) { + s << std::endl; + } + } + + s.flags(original_flags); // restore s to standard state + return s; +} + +inline std::ostream &operator<<(std::ostream &s, const vpImage &I) +{ + if (I.bitmap == nullptr) { + return s; + } + + std::ios_base::fmtflags original_flags = s.flags(); + const unsigned int magic_17 = 17; + s.precision(magic_17); // http://en.cppreference.com/w/cpp/types/numeric_limits/max_digits10 + + unsigned int i_height = I.getHeight(); + unsigned int i_width = I.getWidth(); + for (unsigned int i = 0; i < i_height; ++i) { + for (unsigned int j = 0; j < (i_width - 1); ++j) { + s << I[i][j] << " "; + } + + // We don't add " " after the last column element + s << I[i][i_width - 1]; + + // We don't add a \n character at the end of the last row line + if (i < (i_height - 1)) { + s << std::endl; + } + } + + s.flags(original_flags); // restore s to standard state + return s; +} + +/*! + \brief Copy operator +*/ +template vpImage &vpImage::operator=(vpImage other) +{ + swap(*this, other); + if (other.display != nullptr) { + display = other.display; + } + + return *this; +} + +/*! + \brief = operator : Set all the element of the bitmap to a given value \e + v. \f$ A = v <=> A[i][j] = v \f$ + + \warning = must be defined for \f$ <\f$ Type \f$ > \f$ +*/ +template vpImage &vpImage::operator=(const Type &v) +{ + for (unsigned int i = 0; i < npixels; ++i) { + bitmap[i] = v; + } + + return *this; +} + +/*! + Compare two images. + + \return true if the images are the same, false otherwise. +*/ +template bool vpImage::operator==(const vpImage &I) const +{ + if (this->width != I.getWidth()) { + return false; + } + if (this->height != I.getHeight()) { + return false; + } + + /* + // printf("wxh: %dx%d bitmap: %p I.bitmap %p\n", width, height, bitmap, + // I.bitmap); + */ + for (unsigned int i = 0; i < npixels; ++i) { + if (bitmap[i] != I.bitmap[i]) { + /* + // std::cout << "differ for pixel " << i << " (" << i%this->height + // << ", " << i - i%this->height << ")" << std::endl; + */ + return false; + } + } + return true; +} +/*! + Compare two images. + + \return true if the images are different, false if they are the same. +*/ +template bool vpImage::operator!=(const vpImage &I) const { return !(*this == I); } + +/*! + Operation A - B (A is unchanged). + + \code + #include + + int main() + { + vpImage A(288, 384); + vpImage B(288, 384); + vpImage C; + + A = 128; + B = 120; + + // operator-() : C = A - B + C = A - B; + + return 0; + } + \endcode + + \sa sub(const vpImage &, const vpImage &, vpImage &) to + avoid matrix allocation for each use. +*/ +template vpImage vpImage::operator-(const vpImage &B) const +{ + vpImage C; + sub(*this, B, C); + return C; +} + +#endif diff --git a/modules/core/src/image/vpImageConvert.cpp b/modules/core/src/image/vpImageConvert.cpp index cf26d19791..7965426978 100644 --- a/modules/core/src/image/vpImageConvert.cpp +++ b/modules/core/src/image/vpImageConvert.cpp @@ -289,769 +289,6 @@ void vpImageConvert::createDepthHistogram(const vpImage &src_depth, vpIma vp_createDepthHistogram(src_depth, dest_depth); } -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) - -/*! - Convert a cv::Mat to a vpImage\. - - A cv::Mat is an OpenCV image class. - - If the input image is of type CV_8UC1 or CV_8UC3, the alpha channel is set - to vpRGBa::alpha_default, or 0 in certain case (see the warning below). - - \warning This function is only available if OpenCV (version 2.1.0 or - greater) was detected during the configuration step. - - \warning If ViSP is built with SSSE3 flag and the CPU supports this intrinsics set, - alpha channel will be set to 0, otherwise it will be set to vpRGBa::alpha_default (255). - - \param[in] src : Source image in OpenCV format. - \param[out] dest : Destination image in ViSP format. - \param[in] flip : Set to true to vertically flip the converted image. - - \code - #include - #include - #include - #include - - int main() - { - #if defined(VISP_HAVE_OPENCV) - vpImage Ic; // A color image - cv::Mat Ip; - - // Read an image on a disk with openCV library - Ip = cv::imread("image.pgm", cv::IMREAD_COLOR); // Second parameter for a BGR encoding. - // Convert the grayscale cv::Mat into vpImage - vpImageConvert::convert(Ip, Ic); - - // ... - #endif - } - \endcode -*/ -void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip) -{ - dest.resize(static_cast(src.rows), static_cast(src.cols)); - unsigned int destRows = dest.getRows(); - unsigned int destCols = dest.getCols(); - const unsigned int index_0 = 0; - const unsigned int index_1 = 1; - const unsigned int index_2 = 2; - const unsigned int index_3 = 3; - if (src.type() == CV_8UC4) { - vpRGBa rgbaVal; - for (unsigned int i = 0; i < destRows; ++i) - for (unsigned int j = 0; j < destCols; ++j) { - cv::Vec4b tmp = src.at(static_cast(i), static_cast(j)); - rgbaVal.R = tmp[index_2]; - rgbaVal.G = tmp[index_1]; - rgbaVal.B = tmp[index_0]; - rgbaVal.A = tmp[index_3]; - if (flip) { - dest[destRows - i - 1][j] = rgbaVal; - } - else { - dest[i][j] = rgbaVal; - } - } - } - else if (src.type() == CV_8UC3) { -#if defined(VISP_HAVE_SIMDLIB) - if (src.isContinuous() && (!flip)) { - SimdRgbToBgra(src.data, src.cols, src.rows, src.step[0], reinterpret_cast(dest.bitmap), - dest.getWidth() * sizeof(vpRGBa), vpRGBa::alpha_default); - } - else { -#endif - vpRGBa rgbaVal; - rgbaVal.A = vpRGBa::alpha_default; - for (unsigned int i = 0; i < destRows; ++i) { - for (unsigned int j = 0; j < destCols; ++j) { - cv::Vec3b tmp = src.at(static_cast(i), static_cast(j)); - rgbaVal.R = tmp[index_2]; - rgbaVal.G = tmp[index_1]; - rgbaVal.B = tmp[index_0]; - if (flip) { - dest[destRows - i - 1][j] = rgbaVal; - } - else { - dest[i][j] = rgbaVal; - } - } - } -#if defined(VISP_HAVE_SIMDLIB) - } -#endif - } - else if (src.type() == CV_8UC1) { -#if defined(VISP_HAVE_SIMDLIB) - if (src.isContinuous() && (!flip)) { - SimdGrayToBgra(src.data, src.cols, src.rows, src.step[0], reinterpret_cast(dest.bitmap), - dest.getWidth() * sizeof(vpRGBa), vpRGBa::alpha_default); - } - else { -#endif - vpRGBa rgbaVal; - for (unsigned int i = 0; i < destRows; ++i) { - for (unsigned int j = 0; j < destCols; ++j) { - rgbaVal = src.at(static_cast(i), static_cast(j)); - rgbaVal.A = vpRGBa::alpha_default; - if (flip) { - dest[destRows - i - 1][j] = rgbaVal; - } - else { - dest[i][j] = rgbaVal; - } - } - } -#if defined(VISP_HAVE_SIMDLIB) - } -#endif - } -} - -/*! - Convert a cv::Mat to a vpImage\. - - A cv::Mat is an OpenCV image class. - - \warning This function is only available if OpenCV was detected during - the configuration step. - - \param[in] src : Source image in OpenCV format. - \param[out] dest : Destination image in ViSP format. - \param[in] flip : Set to true to vertically flip the converted image. - \param[in] nThreads : number of threads to use if OpenMP is available. If 0 is passed, - OpenMP will choose the number of threads. - - \code - #include - #include - #include - - int main() - { - #if defined(VISP_HAVE_OPENCV) - vpImage Ig; // A grayscale image - cv::Mat Ip; - - // Read an image on a disk with openCV library - Ip = cv::imread("image.pgm", cv::IMREAD_GRAYSCALE); // Second parameter for a gray level. - // Convert the grayscale cv::Mat into vpImage - vpImageConvert::convert(Ip, Ig); - - // ... - #endif - } - \endcode -*/ -void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip, unsigned int nThreads) -{ - if (src.type() == CV_8UC1) { - dest.resize(static_cast(src.rows), static_cast(src.cols)); - unsigned int destRows = dest.getRows(); - unsigned int destCols = dest.getCols(); - if (src.isContinuous() && (!flip)) { - memcpy(dest.bitmap, src.data, static_cast(src.rows * src.cols)); - } - else { - if (flip) { - for (unsigned int i = 0; i < destRows; ++i) { - memcpy(dest.bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1()), static_cast(src.step)); - } - } - else { - for (unsigned int i = 0; i < destRows; ++i) { - memcpy(dest.bitmap + (i * destCols), src.data + (i * src.step1()), static_cast(src.step)); - } - } - } - } - else if (src.type() == CV_8UC3) { - dest.resize(static_cast(src.rows), static_cast(src.cols)); - unsigned int destRows = dest.getRows(); - unsigned int destCols = dest.getCols(); - if (src.isContinuous()) { - BGRToGrey((unsigned char *)src.data, (unsigned char *)dest.bitmap, static_cast(src.cols), static_cast(src.rows), - flip, nThreads); - } - else { - if (flip) { - for (unsigned int i = 0; i < destRows; ++i) { - BGRToGrey((unsigned char *)src.data + (i * src.step1()), - (unsigned char *)dest.bitmap + ((destRows - i - 1) * destCols), - static_cast(destCols), 1, false); - } - } - else { - for (unsigned int i = 0; i < destRows; ++i) { - BGRToGrey((unsigned char *)src.data + (i * src.step1()), (unsigned char *)dest.bitmap + (i * destCols), - static_cast(destCols), 1, false); - } - } - } - } - else if (src.type() == CV_8UC4) { - dest.resize(static_cast(src.rows), static_cast(src.cols)); - unsigned int destRows = dest.getRows(); - unsigned int destCols = dest.getCols(); - if (src.isContinuous()) { - BGRaToGrey((unsigned char *)src.data, (unsigned char *)dest.bitmap, static_cast(src.cols), - static_cast(src.rows), flip, nThreads); - } - else { - if (flip) { - for (unsigned int i = 0; i < destRows; ++i) { - BGRaToGrey((unsigned char *)src.data + (i * src.step1()), - (unsigned char *)dest.bitmap + ((destRows - i - 1) * destCols), - static_cast(destCols), 1, false); - } - } - else { - for (unsigned int i = 0; i < destRows; ++i) { - BGRaToGrey((unsigned char *)src.data + (i * src.step1()), (unsigned char *)dest.bitmap + (i * destCols), - static_cast(destCols), 1, false); - } - } - } - } -} - -/*! - * Converts cv::Mat CV_32FC1 format to ViSP vpImage. - * - * \param[in] src : OpenCV image in CV_32FC1 format. - * \param[out] dest : ViSP image in float format. - * \param[in] flip : When true during conversion flip image vertically. - */ -void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip) -{ - dest.resize(static_cast(src.rows), static_cast(src.cols)); - unsigned int destRows = dest.getRows(); - unsigned int destCols = dest.getCols(); - - if (src.type() == CV_32FC1) { - for (unsigned int i = 0; i < destRows; ++i) - for (unsigned int j = 0; j < destCols; ++j) { - if (flip) { - dest[dest.getRows() - i - 1][j] = src.at(static_cast(i), static_cast(j)); - } - else { - dest[i][j] = src.at(static_cast(i), static_cast(j)); - } - } - } - else { - throw vpException(vpException::badValue, "cv::Mat type is not supported!"); - } -} - -/*! - * Converts cv::Mat CV_32FC1 format to ViSP vpImage. - * - * \param[in] src : OpenCV image in CV_32FC1 format. - * \param[out] dest : ViSP image in double format. - * \param[in] flip : When true during conversion flip image vertically. - */ -void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip) -{ - vpImage I_float; - convert(src, I_float, flip); - unsigned int nbRows = static_cast(src.rows); - unsigned int nbCols = static_cast(src.cols); - dest.resize(nbRows, nbCols); - for (unsigned int i = 0; i < nbRows; ++i) { - for (unsigned int j = 0; j < nbCols; ++j) { - dest[i][j] = I_float[i][j]; - } - } -} - -/*! - * Converts cv::Mat CV_16UC1 format to ViSP vpImage. - * - * \param[in] src : OpenCV image in CV_16UC1 format. - * \param[out] dest : ViSP image in uint16_t format. - * \param[in] flip : When true during conversion flip image vertically. - */ -void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip) -{ - dest.resize(static_cast(src.rows), static_cast(src.cols)); - unsigned int destRows = dest.getRows(); - unsigned int destCols = dest.getCols(); - - if (src.type() == CV_16UC1) { - if (src.isContinuous()) { - memcpy(dest.bitmap, src.data, static_cast(src.rows * src.cols) * sizeof(uint16_t)); - } - else { - if (flip) { - for (unsigned int i = 0; i < destRows; ++i) { - memcpy(dest.bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1() * sizeof(uint16_t)), static_cast(src.step)); - } - } - else { - for (unsigned int i = 0; i < destRows; ++i) { - memcpy(dest.bitmap + (i * destCols), src.data + (i * src.step1() * sizeof(uint16_t)), static_cast(src.step)); - } - } - } - } - else { - throw(vpException(vpException::fatalError, "cv:Mat format not supported for conversion into vpImage")); - } -} - -/*! - * Converts cv::Mat CV_32FC3 format to ViSP vpImage. - * - * \param[in] src : OpenCV image in CV_32FC3 format. - * \param[out] dest : ViSP image in vpRGBf format. - * \param[in] flip : When true during conversion flip image vertically. - */ -void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip) -{ - dest.resize(static_cast(src.rows), static_cast(src.cols)); - unsigned int destRows = dest.getRows(); - unsigned int destCols = dest.getCols(); - const unsigned int index_0 = 0; - const unsigned int index_1 = 1; - const unsigned int index_2 = 2; - - if (src.type() == CV_32FC3) { - vpRGBf rgbVal; - for (unsigned int i = 0; i < destRows; ++i) - for (unsigned int j = 0; j < destCols; ++j) { - cv::Vec3f tmp = src.at(static_cast(i), static_cast(j)); - rgbVal.R = tmp[index_2]; - rgbVal.G = tmp[index_1]; - rgbVal.B = tmp[index_0]; - if (flip) { - dest[destRows - i - 1][j] = rgbVal; - } - else { - dest[i][j] = rgbVal; - } - } - } - else { - throw vpException(vpException::badValue, "cv::Mat type is not supported!"); - } -} - -/*! - Convert a vpImage\ to a cv::Mat color image. - - A cv::Mat is an OpenCV image class. See http://opencv.willowgarage.com for - the general OpenCV documentation, or - http://opencv.willowgarage.com/documentation/cpp/core_basic_structures.html - for the specific Mat structure documentation. - - \warning This function is only available if OpenCV version 2.1.0 or greater - was detected during the configuration step. - - \param[in] src : Source image (vpRGBa format). - \param[out] dest : Destination image (BGR format). - - \code -#include -#include - -int main() -{ -#if defined(VISP_HAVE_OPENCV) - vpImage I; // A color image - cv::Mat Icv; - - // Read an image on a disk - vpImageIo::read(I, "image.ppm"); - // Convert the image into color cv::Mat. - vpImageConvert::convert(I, Icv); - // Treatments on cv::Mat Icv - //... - // Save the cv::Mat on the disk - cv::imwrite("image-cv.ppm", Icv); -#endif -} - \endcode -*/ -void vpImageConvert::convert(const vpImage &src, cv::Mat &dest) -{ - cv::Mat vpToMat(static_cast(src.getRows()), static_cast(src.getCols()), CV_8UC4, (void *)src.bitmap); - cv::cvtColor(vpToMat, dest, cv::COLOR_RGBA2BGR); -} - -/*! - Convert a vpImage\ to a cv::Mat grey level image. - - A cv::Mat is an OpenCV image class. See http://opencv.willowgarage.com for - the general OpenCV documentation, or - http://opencv.willowgarage.com/documentation/cpp/core_basic_structures.html - for the specific Mat structure documentation. - - \warning This function is only available if OpenCV version 2.1.0 or greater - was detected during the configuration step. - - \param[in] src : Source image. - \param[out] dest : Destination image. - \param[in] copyData : If true, the image is copied and modification in one - object will not modified the other. - - \code -#include -#include - -int main() -{ -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_IMGCODECS) - vpImage Ig; // A grayscale image - cv::Mat Ip; - - // Read an image on a disk - vpImageIo::read(Ig, "image.pgm"); - // Convert the vpImage in to grayscale cv::Mat - vpImageConvert::convert(Ig, Ip); - // Treatments on cv::Mat Ip - //... - // Save the cv::Mat on the disk - cv::imwrite("image-cv.pgm", Ip); -#endif -} - \endcode -*/ -void vpImageConvert::convert(const vpImage &src, cv::Mat &dest, bool copyData) -{ - if (copyData) { - cv::Mat tmpMap(static_cast(src.getRows()), static_cast(src.getCols()), CV_8UC1, (void *)src.bitmap); - dest = tmpMap.clone(); - } - else { - dest = cv::Mat(static_cast(src.getRows()), static_cast(src.getCols()), CV_8UC1, (void *)src.bitmap); - } -} - -void vpImageConvert::convert(const vpImage &src, cv::Mat &dest, bool copyData) -{ - if (copyData) { - cv::Mat tmpMap(static_cast(src.getRows()), static_cast(src.getCols()), CV_32FC1, (void *)src.bitmap); - dest = tmpMap.clone(); - } - else { - dest = cv::Mat(static_cast(src.getRows()), static_cast(src.getCols()), CV_32FC1, (void *)src.bitmap); - } -} - -void vpImageConvert::convert(const vpImage &src, cv::Mat &dest, bool copyData) -{ - unsigned int nbRows = src.getRows(); - unsigned int nbCols = src.getCols(); - vpImage I_float(nbRows, nbCols); - for (unsigned int i = 0; i < nbRows; ++i) { - for (unsigned int j = 0; j < nbCols; ++j) { - I_float[i][j] = static_cast(src[i][j]); - } - } - convert(I_float, dest, copyData); -} - -void vpImageConvert::convert(const vpImage &src, cv::Mat &dest) -{ - cv::Mat vpToMat(static_cast(src.getRows()), static_cast(src.getCols()), CV_32FC3, (void *)src.bitmap); - cv::cvtColor(vpToMat, dest, cv::COLOR_RGB2BGR); -} - -#endif - -#ifdef VISP_HAVE_YARP -/*! - Convert a vpImage\ to a yarp::sig::ImageOf\ - - A yarp::sig::Image is a YARP image class. See - http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the - YARP image class documentation. - - \param[in] src : Source image in ViSP format. - \param[out] dest : Destination image in YARP format. - \param[in] copyData : Set to true to copy all the image content. If false we - only update the image pointer. - - \code -#include -#include -#include - -int main() -{ -#if defined(VISP_HAVE_YARP) - vpImage I; // A mocochrome image - // Read an image on a disk - vpImageIo::read(I, "image.pgm"); - - yarp::sig::ImageOf< yarp::sig::PixelMono > *Iyarp = new yarp::sig::ImageOf(); - // Convert the vpImage\ to a yarp::sig::ImageOf\ - vpImageConvert::convert(I, Iyarp); - - // ... -#endif -} - \endcode -*/ -void vpImageConvert::convert(const vpImage &src, yarp::sig::ImageOf *dest, - bool copyData) -{ - if (copyData) { - dest->resize(src.getWidth(), src.getHeight()); - memcpy(dest->getRawImage(), src.bitmap, src.getHeight() * src.getWidth()); - } - else { - dest->setExternal(src.bitmap, static_cast(src.getCols()), static_cast(src.getRows())); - } -} - -/*! - Convert a yarp::sig::ImageOf\ to a vpImage\ - - A yarp::sig::Image is a YARP image class. See - http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the - YARP image class documentation. - - \param[in] src : Source image in YARP format. - \param[out] dest : Destination image in ViSP format. - \param[in] copyData : Set to true to copy all the image content. If false we - only update the image pointer. - - \code -#include -#include -#include - -#if defined(VISP_HAVE_YARP) - #include -#endif - -int main() -{ -#if defined(VISP_HAVE_YARP) - yarp::sig::ImageOf< yarp::sig::PixelMono > *Iyarp = new yarp::sig::ImageOf(); - // Read an image on a disk - yarp::sig::file::read(*Iyarp, "image.pgm"); - - // Convert the yarp::sig::ImageOf to a vpImage - vpImage I; - vpImageConvert::convert(Iyarp, I); - - // ... -#endif -} - \endcode -*/ -void vpImageConvert::convert(const yarp::sig::ImageOf *src, vpImage &dest, - bool copyData) -{ - dest.resize(src->height(), src->width()); - if (copyData) { - memcpy(dest.bitmap, src->getRawImage(), src->height() * src->width() * sizeof(yarp::sig::PixelMono)); - } - else { - dest.bitmap = src->getRawImage(); - } -} - -/*! - Convert a vpImage\ to a yarp::sig::ImageOf\ - - A yarp::sig::Image is a YARP image class. See - http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the - YARP image class documentation. - - \param[in] src : Source image in ViSP format. - \param[in] dest : Destination image in YARP format. - \param[in] copyData : Set to true to copy all the image content. If false we - only update the image pointer. - - \code -#include -#include -#include -#include - -int main() -{ -#if defined(VISP_HAVE_YARP) - vpImage I; // A color image - // Read an image on a disk - vpImageIo::read(I,"image.jpg"); - - yarp::sig::ImageOf< yarp::sig::PixelRgba > *Iyarp = new yarp::sig::ImageOf(); - // Convert the vpImage to a yarp::sig::ImageOf - vpImageConvert::convert(I,Iyarp); - - // ... -#endif -} - \endcode -*/ -void vpImageConvert::convert(const vpImage &src, yarp::sig::ImageOf *dest, bool copyData) -{ - if (copyData) { - dest->resize(src.getWidth(), src.getHeight()); - memcpy(dest->getRawImage(), src.bitmap, src.getHeight() * src.getWidth() * sizeof(vpRGBa)); - } - else { - dest->setExternal(src.bitmap, static_cast(src.getCols()), static_cast(src.getRows())); - } -} - -/*! - Convert a yarp::sig::ImageOf\ to a vpImage\ - - A yarp::sig::Image is a YARP image class. See - http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the - YARP image class documentation. - - \param[in] src : Source image in YARP format. - \param[out] dest : Destination image in ViSP format. - \param[in] copyData : Set to true to copy all the image content. If false we - only update the image pointer. - - \code -#include -#include -#include -#include - -#if defined(VISP_HAVE_YARP) - #include -#endif - -int main() -{ -#if defined(VISP_HAVE_YARP) - yarp::sig::ImageOf< yarp::sig::PixelRgba > *Iyarp = new yarp::sig::ImageOf(); - // Read an image on a disk - yarp::sig::file::read(*Iyarp,"image.pgm"); - - // Convert the yarp::sig::ImageOf to a vpImage - vpImage I; - vpImageConvert::convert(Iyarp,I); - - // ... -#endif -} - \endcode -*/ -void vpImageConvert::convert(const yarp::sig::ImageOf *src, vpImage &dest, bool copyData) -{ - dest.resize(src->height(), src->width()); - if (copyData) - memcpy(dest.bitmap, src->getRawImage(), src->height() * src->width() * sizeof(yarp::sig::PixelRgba)); - else { - dest.bitmap = static_cast(src->getRawImage()); - } -} - -/*! - Convert a vpImage\ to a yarp::sig::ImageOf\ - - A yarp::sig::Image is a YARP image class. See - http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the - YARP image class documentation. - - \param[in] src : Source image in ViSP format. - \param[out] dest : Destination image in YARP format. - - \code -#include -#include -#include -#include - -int main() -{ -#if defined(VISP_HAVE_YARP) - vpImage I; // A color image - // Read an image on a disk - vpImageIo::read(I,"image.jpg"); - - yarp::sig::ImageOf< yarp::sig::PixelRgb > *Iyarp = new yarp::sig::ImageOf(); - // Convert the vpImage to a yarp::sig::ImageOf - vpImageConvert::convert(I,Iyarp); - - // ... -#endif -} - \endcode -*/ -void vpImageConvert::convert(const vpImage &src, yarp::sig::ImageOf *dest) -{ - const unsigned int srcRows = src.getRows(), srcWidth = src.getWidth(); - dest->resize(src.getWidth(), src.getHeight()); - for (unsigned int i = 0; i < srcRows; ++i) { - for (unsigned int j = 0; j < srcWidth; ++j) { - dest->pixel(j, i).r = src[i][j].R; - dest->pixel(j, i).g = src[i][j].G; - dest->pixel(j, i).b = src[i][j].B; - } - } -} - -/*! - Convert a yarp::sig::ImageOf\ to a vpImage\ - - A yarp::sig::Image is a YARP image class. See - http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the - YARP image class documentation. - - The alpha component of the resulting image is set to vpRGBa::alpha_default. - - \param[in] src : Source image in YARP format. - \param[out] dest : Destination image in ViSP format. - - \code -#include -#include -#include -#include - -#if defined(VISP_HAVE_YARP) - #include -#endif - -int main() -{ -#if defined(VISP_HAVE_YARP) - yarp::sig::ImageOf< yarp::sig::PixelRgb > *Iyarp = new yarp::sig::ImageOf(); - // Read an image on a disk - yarp::sig::file::read(*Iyarp,"image.pgm"); - - // Convert the yarp::sig::ImageOf to a vpImage - vpImage I; - vpImageConvert::convert(Iyarp,I); - - // ... -#endif -} - \endcode -*/ -void vpImageConvert::convert(const yarp::sig::ImageOf *src, vpImage &dest) -{ - const int srcHeight = src->height(), srcWidth = src->width(); - dest.resize(srcHeight, srcWidth); - for (int i = 0; i < srcHeight; ++i) { - for (int j = 0; j < srcWidth; ++j) { - dest[i][j].R = src->pixel(j, i).r; - dest[i][j].G = src->pixel(j, i).g; - dest[i][j].B = src->pixel(j, i).b; - dest[i][j].A = vpRGBa::alpha_default; - } - } -} - -#endif - /*! Convert RGB into RGBa. diff --git a/modules/core/src/image/vpImageConvert_opencv.cpp b/modules/core/src/image/vpImageConvert_opencv.cpp new file mode 100644 index 0000000000..d9630da13e --- /dev/null +++ b/modules/core/src/image/vpImageConvert_opencv.cpp @@ -0,0 +1,519 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Convert image types. + * +*****************************************************************************/ + +/*! + \file vpImageConvert_opencv.cpp +*/ + +#include +#include + +#if defined(VISP_HAVE_SIMDLIB) +#include +#endif + +#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) + +/*! + Convert a cv::Mat to a vpImage\. + + A cv::Mat is an OpenCV image class. + + If the input image is of type CV_8UC1 or CV_8UC3, the alpha channel is set + to vpRGBa::alpha_default, or 0 in certain case (see the warning below). + + \warning This function is only available if OpenCV (version 2.1.0 or + greater) was detected during the configuration step. + + \warning If ViSP is built with SSSE3 flag and the CPU supports this intrinsics set, + alpha channel will be set to 0, otherwise it will be set to vpRGBa::alpha_default (255). + + \param[in] src : Source image in OpenCV format. + \param[out] dest : Destination image in ViSP format. + \param[in] flip : Set to true to vertically flip the converted image. + + \code + #include + #include + #include + #include + + int main() + { + #if defined(VISP_HAVE_OPENCV) + vpImage Ic; // A color image + cv::Mat Ip; + + // Read an image on a disk with openCV library + Ip = cv::imread("image.pgm", cv::IMREAD_COLOR); // Second parameter for a BGR encoding. + // Convert the grayscale cv::Mat into vpImage + vpImageConvert::convert(Ip, Ic); + + // ... + #endif + } + \endcode +*/ +void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip) +{ + dest.resize(static_cast(src.rows), static_cast(src.cols)); + unsigned int destRows = dest.getRows(); + unsigned int destCols = dest.getCols(); + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + const unsigned int index_3 = 3; + if (src.type() == CV_8UC4) { + vpRGBa rgbaVal; + for (unsigned int i = 0; i < destRows; ++i) + for (unsigned int j = 0; j < destCols; ++j) { + cv::Vec4b tmp = src.at(static_cast(i), static_cast(j)); + rgbaVal.R = tmp[index_2]; + rgbaVal.G = tmp[index_1]; + rgbaVal.B = tmp[index_0]; + rgbaVal.A = tmp[index_3]; + if (flip) { + dest[destRows - i - 1][j] = rgbaVal; + } + else { + dest[i][j] = rgbaVal; + } + } + } + else if (src.type() == CV_8UC3) { +#if defined(VISP_HAVE_SIMDLIB) + if (src.isContinuous() && (!flip)) { + SimdRgbToBgra(src.data, src.cols, src.rows, src.step[0], reinterpret_cast(dest.bitmap), + dest.getWidth() * sizeof(vpRGBa), vpRGBa::alpha_default); + } + else { +#endif + vpRGBa rgbaVal; + rgbaVal.A = vpRGBa::alpha_default; + for (unsigned int i = 0; i < destRows; ++i) { + for (unsigned int j = 0; j < destCols; ++j) { + cv::Vec3b tmp = src.at(static_cast(i), static_cast(j)); + rgbaVal.R = tmp[index_2]; + rgbaVal.G = tmp[index_1]; + rgbaVal.B = tmp[index_0]; + if (flip) { + dest[destRows - i - 1][j] = rgbaVal; + } + else { + dest[i][j] = rgbaVal; + } + } + } +#if defined(VISP_HAVE_SIMDLIB) + } +#endif + } + else if (src.type() == CV_8UC1) { +#if defined(VISP_HAVE_SIMDLIB) + if (src.isContinuous() && (!flip)) { + SimdGrayToBgra(src.data, src.cols, src.rows, src.step[0], reinterpret_cast(dest.bitmap), + dest.getWidth() * sizeof(vpRGBa), vpRGBa::alpha_default); + } + else { +#endif + vpRGBa rgbaVal; + for (unsigned int i = 0; i < destRows; ++i) { + for (unsigned int j = 0; j < destCols; ++j) { + rgbaVal = src.at(static_cast(i), static_cast(j)); + rgbaVal.A = vpRGBa::alpha_default; + if (flip) { + dest[destRows - i - 1][j] = rgbaVal; + } + else { + dest[i][j] = rgbaVal; + } + } + } +#if defined(VISP_HAVE_SIMDLIB) + } +#endif + } +} + +/*! + Convert a cv::Mat to a vpImage\. + + A cv::Mat is an OpenCV image class. + + \warning This function is only available if OpenCV was detected during + the configuration step. + + \param[in] src : Source image in OpenCV format. + \param[out] dest : Destination image in ViSP format. + \param[in] flip : Set to true to vertically flip the converted image. + \param[in] nThreads : number of threads to use if OpenMP is available. If 0 is passed, + OpenMP will choose the number of threads. + + \code + #include + #include + #include + + int main() + { + #if defined(VISP_HAVE_OPENCV) + vpImage Ig; // A grayscale image + cv::Mat Ip; + + // Read an image on a disk with openCV library + Ip = cv::imread("image.pgm", cv::IMREAD_GRAYSCALE); // Second parameter for a gray level. + // Convert the grayscale cv::Mat into vpImage + vpImageConvert::convert(Ip, Ig); + + // ... + #endif + } + \endcode +*/ +void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip, unsigned int nThreads) +{ + if (src.type() == CV_8UC1) { + dest.resize(static_cast(src.rows), static_cast(src.cols)); + unsigned int destRows = dest.getRows(); + unsigned int destCols = dest.getCols(); + if (src.isContinuous() && (!flip)) { + memcpy(dest.bitmap, src.data, static_cast(src.rows * src.cols)); + } + else { + if (flip) { + for (unsigned int i = 0; i < destRows; ++i) { + memcpy(dest.bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1()), static_cast(src.step)); + } + } + else { + for (unsigned int i = 0; i < destRows; ++i) { + memcpy(dest.bitmap + (i * destCols), src.data + (i * src.step1()), static_cast(src.step)); + } + } + } + } + else if (src.type() == CV_8UC3) { + dest.resize(static_cast(src.rows), static_cast(src.cols)); + unsigned int destRows = dest.getRows(); + unsigned int destCols = dest.getCols(); + if (src.isContinuous()) { + BGRToGrey((unsigned char *)src.data, (unsigned char *)dest.bitmap, static_cast(src.cols), static_cast(src.rows), + flip, nThreads); + } + else { + if (flip) { + for (unsigned int i = 0; i < destRows; ++i) { + BGRToGrey((unsigned char *)src.data + (i * src.step1()), + (unsigned char *)dest.bitmap + ((destRows - i - 1) * destCols), + static_cast(destCols), 1, false); + } + } + else { + for (unsigned int i = 0; i < destRows; ++i) { + BGRToGrey((unsigned char *)src.data + (i * src.step1()), (unsigned char *)dest.bitmap + (i * destCols), + static_cast(destCols), 1, false); + } + } + } + } + else if (src.type() == CV_8UC4) { + dest.resize(static_cast(src.rows), static_cast(src.cols)); + unsigned int destRows = dest.getRows(); + unsigned int destCols = dest.getCols(); + if (src.isContinuous()) { + BGRaToGrey((unsigned char *)src.data, (unsigned char *)dest.bitmap, static_cast(src.cols), + static_cast(src.rows), flip, nThreads); + } + else { + if (flip) { + for (unsigned int i = 0; i < destRows; ++i) { + BGRaToGrey((unsigned char *)src.data + (i * src.step1()), + (unsigned char *)dest.bitmap + ((destRows - i - 1) * destCols), + static_cast(destCols), 1, false); + } + } + else { + for (unsigned int i = 0; i < destRows; ++i) { + BGRaToGrey((unsigned char *)src.data + (i * src.step1()), (unsigned char *)dest.bitmap + (i * destCols), + static_cast(destCols), 1, false); + } + } + } + } +} + +/*! + * Converts cv::Mat CV_32FC1 format to ViSP vpImage. + * + * \param[in] src : OpenCV image in CV_32FC1 format. + * \param[out] dest : ViSP image in float format. + * \param[in] flip : When true during conversion flip image vertically. + */ +void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip) +{ + dest.resize(static_cast(src.rows), static_cast(src.cols)); + unsigned int destRows = dest.getRows(); + unsigned int destCols = dest.getCols(); + + if (src.type() == CV_32FC1) { + for (unsigned int i = 0; i < destRows; ++i) + for (unsigned int j = 0; j < destCols; ++j) { + if (flip) { + dest[dest.getRows() - i - 1][j] = src.at(static_cast(i), static_cast(j)); + } + else { + dest[i][j] = src.at(static_cast(i), static_cast(j)); + } + } + } + else { + throw vpException(vpException::badValue, "cv::Mat type is not supported!"); + } +} + +/*! + * Converts cv::Mat CV_32FC1 format to ViSP vpImage. + * + * \param[in] src : OpenCV image in CV_32FC1 format. + * \param[out] dest : ViSP image in double format. + * \param[in] flip : When true during conversion flip image vertically. + */ +void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip) +{ + vpImage I_float; + convert(src, I_float, flip); + unsigned int nbRows = static_cast(src.rows); + unsigned int nbCols = static_cast(src.cols); + dest.resize(nbRows, nbCols); + for (unsigned int i = 0; i < nbRows; ++i) { + for (unsigned int j = 0; j < nbCols; ++j) { + dest[i][j] = I_float[i][j]; + } + } +} + +/*! + * Converts cv::Mat CV_16UC1 format to ViSP vpImage. + * + * \param[in] src : OpenCV image in CV_16UC1 format. + * \param[out] dest : ViSP image in uint16_t format. + * \param[in] flip : When true during conversion flip image vertically. + */ +void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip) +{ + dest.resize(static_cast(src.rows), static_cast(src.cols)); + unsigned int destRows = dest.getRows(); + unsigned int destCols = dest.getCols(); + + if (src.type() == CV_16UC1) { + if (src.isContinuous()) { + memcpy(dest.bitmap, src.data, static_cast(src.rows * src.cols) * sizeof(uint16_t)); + } + else { + if (flip) { + for (unsigned int i = 0; i < destRows; ++i) { + memcpy(dest.bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1() * sizeof(uint16_t)), static_cast(src.step)); + } + } + else { + for (unsigned int i = 0; i < destRows; ++i) { + memcpy(dest.bitmap + (i * destCols), src.data + (i * src.step1() * sizeof(uint16_t)), static_cast(src.step)); + } + } + } + } + else { + throw(vpException(vpException::fatalError, "cv:Mat format not supported for conversion into vpImage")); + } +} + +/*! + * Converts cv::Mat CV_32FC3 format to ViSP vpImage. + * + * \param[in] src : OpenCV image in CV_32FC3 format. + * \param[out] dest : ViSP image in vpRGBf format. + * \param[in] flip : When true during conversion flip image vertically. + */ +void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip) +{ + dest.resize(static_cast(src.rows), static_cast(src.cols)); + unsigned int destRows = dest.getRows(); + unsigned int destCols = dest.getCols(); + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + + if (src.type() == CV_32FC3) { + vpRGBf rgbVal; + for (unsigned int i = 0; i < destRows; ++i) + for (unsigned int j = 0; j < destCols; ++j) { + cv::Vec3f tmp = src.at(static_cast(i), static_cast(j)); + rgbVal.R = tmp[index_2]; + rgbVal.G = tmp[index_1]; + rgbVal.B = tmp[index_0]; + if (flip) { + dest[destRows - i - 1][j] = rgbVal; + } + else { + dest[i][j] = rgbVal; + } + } + } + else { + throw vpException(vpException::badValue, "cv::Mat type is not supported!"); + } +} + +/*! + Convert a vpImage\ to a cv::Mat color image. + + A cv::Mat is an OpenCV image class. See http://opencv.willowgarage.com for + the general OpenCV documentation, or + http://opencv.willowgarage.com/documentation/cpp/core_basic_structures.html + for the specific Mat structure documentation. + + \warning This function is only available if OpenCV version 2.1.0 or greater + was detected during the configuration step. + + \param[in] src : Source image (vpRGBa format). + \param[out] dest : Destination image (BGR format). + + \code + #include + #include + + int main() + { + #if defined(VISP_HAVE_OPENCV) + vpImage I; // A color image + cv::Mat Icv; + + // Read an image on a disk + vpImageIo::read(I, "image.ppm"); + // Convert the image into color cv::Mat. + vpImageConvert::convert(I, Icv); + // Treatments on cv::Mat Icv + //... + // Save the cv::Mat on the disk + cv::imwrite("image-cv.ppm", Icv); + #endif + } + \endcode +*/ +void vpImageConvert::convert(const vpImage &src, cv::Mat &dest) +{ + cv::Mat vpToMat(static_cast(src.getRows()), static_cast(src.getCols()), CV_8UC4, (void *)src.bitmap); + cv::cvtColor(vpToMat, dest, cv::COLOR_RGBA2BGR); +} + +/*! + Convert a vpImage\ to a cv::Mat grey level image. + + A cv::Mat is an OpenCV image class. See http://opencv.willowgarage.com for + the general OpenCV documentation, or + http://opencv.willowgarage.com/documentation/cpp/core_basic_structures.html + for the specific Mat structure documentation. + + \warning This function is only available if OpenCV version 2.1.0 or greater + was detected during the configuration step. + + \param[in] src : Source image. + \param[out] dest : Destination image. + \param[in] copyData : If true, the image is copied and modification in one + object will not modified the other. + + \code + #include + #include + + int main() + { + #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_IMGCODECS) + vpImage Ig; // A grayscale image + cv::Mat Ip; + + // Read an image on a disk + vpImageIo::read(Ig, "image.pgm"); + // Convert the vpImage in to grayscale cv::Mat + vpImageConvert::convert(Ig, Ip); + // Treatments on cv::Mat Ip + //... + // Save the cv::Mat on the disk + cv::imwrite("image-cv.pgm", Ip); + #endif + } + \endcode +*/ +void vpImageConvert::convert(const vpImage &src, cv::Mat &dest, bool copyData) +{ + if (copyData) { + cv::Mat tmpMap(static_cast(src.getRows()), static_cast(src.getCols()), CV_8UC1, (void *)src.bitmap); + dest = tmpMap.clone(); + } + else { + dest = cv::Mat(static_cast(src.getRows()), static_cast(src.getCols()), CV_8UC1, (void *)src.bitmap); + } +} + +void vpImageConvert::convert(const vpImage &src, cv::Mat &dest, bool copyData) +{ + if (copyData) { + cv::Mat tmpMap(static_cast(src.getRows()), static_cast(src.getCols()), CV_32FC1, (void *)src.bitmap); + dest = tmpMap.clone(); + } + else { + dest = cv::Mat(static_cast(src.getRows()), static_cast(src.getCols()), CV_32FC1, (void *)src.bitmap); + } +} + +void vpImageConvert::convert(const vpImage &src, cv::Mat &dest, bool copyData) +{ + unsigned int nbRows = src.getRows(); + unsigned int nbCols = src.getCols(); + vpImage I_float(nbRows, nbCols); + for (unsigned int i = 0; i < nbRows; ++i) { + for (unsigned int j = 0; j < nbCols; ++j) { + I_float[i][j] = static_cast(src[i][j]); + } + } + convert(I_float, dest, copyData); +} + +void vpImageConvert::convert(const vpImage &src, cv::Mat &dest) +{ + cv::Mat vpToMat(static_cast(src.getRows()), static_cast(src.getCols()), CV_32FC3, (void *)src.bitmap); + cv::cvtColor(vpToMat, dest, cv::COLOR_RGB2BGR); +} + +#endif diff --git a/modules/core/src/image/vpImageConvert_yarp.cpp b/modules/core/src/image/vpImageConvert_yarp.cpp new file mode 100644 index 0000000000..2173f17829 --- /dev/null +++ b/modules/core/src/image/vpImageConvert_yarp.cpp @@ -0,0 +1,327 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Convert image types. + * +*****************************************************************************/ + +/*! + \file vpImageConvert_yarp.cpp +*/ + +#include + +#ifdef VISP_HAVE_YARP +/*! + Convert a vpImage\ to a yarp::sig::ImageOf\ + + A yarp::sig::Image is a YARP image class. See + http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the + YARP image class documentation. + + \param[in] src : Source image in ViSP format. + \param[out] dest : Destination image in YARP format. + \param[in] copyData : Set to true to copy all the image content. If false we + only update the image pointer. + + \code + #include + #include + #include + + int main() + { + #if defined(VISP_HAVE_YARP) + vpImage I; // A mocochrome image + // Read an image on a disk + vpImageIo::read(I, "image.pgm"); + + yarp::sig::ImageOf< yarp::sig::PixelMono > *Iyarp = new yarp::sig::ImageOf(); + // Convert the vpImage\ to a yarp::sig::ImageOf\ + vpImageConvert::convert(I, Iyarp); + + // ... + #endif + } + \endcode +*/ +void vpImageConvert::convert(const vpImage &src, yarp::sig::ImageOf *dest, + bool copyData) +{ + if (copyData) { + dest->resize(src.getWidth(), src.getHeight()); + memcpy(dest->getRawImage(), src.bitmap, src.getHeight() * src.getWidth()); + } + else { + dest->setExternal(src.bitmap, static_cast(src.getCols()), static_cast(src.getRows())); + } +} + +/*! + Convert a yarp::sig::ImageOf\ to a vpImage\ + + A yarp::sig::Image is a YARP image class. See + http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the + YARP image class documentation. + + \param[in] src : Source image in YARP format. + \param[out] dest : Destination image in ViSP format. + \param[in] copyData : Set to true to copy all the image content. If false we + only update the image pointer. + + \code + #include + #include + #include + + #if defined(VISP_HAVE_YARP) + #include + #endif + + int main() + { + #if defined(VISP_HAVE_YARP) + yarp::sig::ImageOf< yarp::sig::PixelMono > *Iyarp = new yarp::sig::ImageOf(); + // Read an image on a disk + yarp::sig::file::read(*Iyarp, "image.pgm"); + + // Convert the yarp::sig::ImageOf to a vpImage + vpImage I; + vpImageConvert::convert(Iyarp, I); + + // ... + #endif + } + \endcode +*/ +void vpImageConvert::convert(const yarp::sig::ImageOf *src, vpImage &dest, + bool copyData) +{ + dest.resize(src->height(), src->width()); + if (copyData) { + memcpy(dest.bitmap, src->getRawImage(), src->height() * src->width() * sizeof(yarp::sig::PixelMono)); + } + else { + dest.bitmap = src->getRawImage(); + } +} + +/*! + Convert a vpImage\ to a yarp::sig::ImageOf\ + + A yarp::sig::Image is a YARP image class. See + http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the + YARP image class documentation. + + \param[in] src : Source image in ViSP format. + \param[in] dest : Destination image in YARP format. + \param[in] copyData : Set to true to copy all the image content. If false we + only update the image pointer. + + \code + #include + #include + #include + #include + + int main() + { + #if defined(VISP_HAVE_YARP) + vpImage I; // A color image + // Read an image on a disk + vpImageIo::read(I,"image.jpg"); + + yarp::sig::ImageOf< yarp::sig::PixelRgba > *Iyarp = new yarp::sig::ImageOf(); + // Convert the vpImage to a yarp::sig::ImageOf + vpImageConvert::convert(I,Iyarp); + + // ... + #endif + } + \endcode +*/ +void vpImageConvert::convert(const vpImage &src, yarp::sig::ImageOf *dest, bool copyData) +{ + if (copyData) { + dest->resize(src.getWidth(), src.getHeight()); + memcpy(dest->getRawImage(), src.bitmap, src.getHeight() * src.getWidth() * sizeof(vpRGBa)); + } + else { + dest->setExternal(src.bitmap, static_cast(src.getCols()), static_cast(src.getRows())); + } +} + +/*! + Convert a yarp::sig::ImageOf\ to a vpImage\ + + A yarp::sig::Image is a YARP image class. See + http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the + YARP image class documentation. + + \param[in] src : Source image in YARP format. + \param[out] dest : Destination image in ViSP format. + \param[in] copyData : Set to true to copy all the image content. If false we + only update the image pointer. + + \code + #include + #include + #include + #include + + #if defined(VISP_HAVE_YARP) + #include + #endif + + int main() + { + #if defined(VISP_HAVE_YARP) + yarp::sig::ImageOf< yarp::sig::PixelRgba > *Iyarp = new yarp::sig::ImageOf(); + // Read an image on a disk + yarp::sig::file::read(*Iyarp,"image.pgm"); + + // Convert the yarp::sig::ImageOf to a vpImage + vpImage I; + vpImageConvert::convert(Iyarp,I); + + // ... + #endif + } + \endcode +*/ +void vpImageConvert::convert(const yarp::sig::ImageOf *src, vpImage &dest, bool copyData) +{ + dest.resize(src->height(), src->width()); + if (copyData) + memcpy(dest.bitmap, src->getRawImage(), src->height() * src->width() * sizeof(yarp::sig::PixelRgba)); + else { + dest.bitmap = static_cast(src->getRawImage()); + } +} + +/*! + Convert a vpImage\ to a yarp::sig::ImageOf\ + + A yarp::sig::Image is a YARP image class. See + http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the + YARP image class documentation. + + \param[in] src : Source image in ViSP format. + \param[out] dest : Destination image in YARP format. + + \code + #include + #include + #include + #include + + int main() + { + #if defined(VISP_HAVE_YARP) + vpImage I; // A color image + // Read an image on a disk + vpImageIo::read(I,"image.jpg"); + + yarp::sig::ImageOf< yarp::sig::PixelRgb > *Iyarp = new yarp::sig::ImageOf(); + // Convert the vpImage to a yarp::sig::ImageOf + vpImageConvert::convert(I,Iyarp); + + // ... + #endif + } + \endcode +*/ +void vpImageConvert::convert(const vpImage &src, yarp::sig::ImageOf *dest) +{ + const unsigned int srcRows = src.getRows(), srcWidth = src.getWidth(); + dest->resize(src.getWidth(), src.getHeight()); + for (unsigned int i = 0; i < srcRows; ++i) { + for (unsigned int j = 0; j < srcWidth; ++j) { + dest->pixel(j, i).r = src[i][j].R; + dest->pixel(j, i).g = src[i][j].G; + dest->pixel(j, i).b = src[i][j].B; + } + } +} + +/*! + Convert a yarp::sig::ImageOf\ to a vpImage\ + + A yarp::sig::Image is a YARP image class. See + http://eris.liralab.it/yarpdoc/df/d15/classyarp_1_1sig_1_1Image.html for the + YARP image class documentation. + + The alpha component of the resulting image is set to vpRGBa::alpha_default. + + \param[in] src : Source image in YARP format. + \param[out] dest : Destination image in ViSP format. + + \code + #include + #include + #include + #include + + #if defined(VISP_HAVE_YARP) + #include + #endif + + int main() + { + #if defined(VISP_HAVE_YARP) + yarp::sig::ImageOf< yarp::sig::PixelRgb > *Iyarp = new yarp::sig::ImageOf(); + // Read an image on a disk + yarp::sig::file::read(*Iyarp,"image.pgm"); + + // Convert the yarp::sig::ImageOf to a vpImage + vpImage I; + vpImageConvert::convert(Iyarp,I); + + // ... + #endif + } + \endcode +*/ +void vpImageConvert::convert(const yarp::sig::ImageOf *src, vpImage &dest) +{ + const int srcHeight = src->height(), srcWidth = src->width(); + dest.resize(srcHeight, srcWidth); + for (int i = 0; i < srcHeight; ++i) { + for (int j = 0; j < srcWidth; ++j) { + dest[i][j].R = src->pixel(j, i).r; + dest[i][j].G = src->pixel(j, i).g; + dest[i][j].B = src->pixel(j, i).b; + dest[i][j].A = vpRGBa::alpha_default; + } + } +} + +#endif diff --git a/modules/core/src/image/vpImageFilter.cpp b/modules/core/src/image/vpImageFilter.cpp index 5b5df75963..299ddcc732 100644 --- a/modules/core/src/image/vpImageFilter.cpp +++ b/modules/core/src/image/vpImageFilter.cpp @@ -31,168 +31,30 @@ * Various image tools, convolution, ... */ -#include #include #include #include BEGIN_VISP_NAMESPACE - /** - * \brief Get the list of available vpCannyBackendType. - * - * \param[in] pref The prefix of the list. - * \param[in] sep The separator between two elements of the list. - * \param[in] suf The suffix of the list. - * \return std::string The list of available items. - */ - std::string vpImageFilter::vpCannyBackendTypeList(const std::string &pref, const std::string &sep, - const std::string &suf) -{ - std::string list(pref); - for (unsigned int i = 0; i < (CANNY_COUNT_BACKEND - 1); ++i) { - vpCannyBackendType type = static_cast(i); - list += vpCannyBackendTypeToString(type); - list += sep; - } - vpCannyBackendType type = static_cast(CANNY_COUNT_BACKEND - 1); - list += vpCannyBackendTypeToString(type); - list += suf; - return list; -} - -/** - * \brief Cast a \b vpImageFilter::vpCannyBackendTypeToString into a string, to know its name. - * - * \param[in] type The type that must be casted into a string. - * \return std::string The corresponding name. - */ -std::string vpImageFilter::vpCannyBackendTypeToString(const vpImageFilter::vpCannyBackendType &type) -{ - std::string name; - switch (type) { - case CANNY_OPENCV_BACKEND: - name = "opencv-backend"; - break; - case CANNY_VISP_BACKEND: - name = "visp-backend"; - break; - case CANNY_COUNT_BACKEND: - default: - return "unknown-backend"; - } - return name; -} - -/** - * \brief Cast a string into a \b vpImageFilter::vpCannyBackendTypeToString. - * - * \param[in] name The name of the backend. - * \return vpImageFilter::vpCannyBackendTypeToString The corresponding enumeration value. - */ -vpImageFilter::vpCannyBackendType vpImageFilter::vpCannyBackendTypeFromString(const std::string &name) -{ - vpCannyBackendType type(CANNY_COUNT_BACKEND); - std::string nameLowerCase = vpIoTools::toLowerCase(name); - unsigned int count = static_cast(CANNY_COUNT_BACKEND); - bool notFound = true; - unsigned int i = 0; - while ((i < count) && notFound) { - vpCannyBackendType temp = static_cast(i); - if (nameLowerCase == vpCannyBackendTypeToString(temp)) { - type = temp; - notFound = false; - } - ++i; - } - return type; -} - -/** - * \brief Get the list of available vpCannyFilteringAndGradientType. - * - * \param[in] pref The prefix of the list. - * \param[in] sep The separator between two elements of the list. - * \param[in] suf The suffix of the list. - * \return std::string The list of available items. - */ -std::string vpImageFilter::vpGetCannyFiltAndGradTypes(const std::string &pref, const std::string &sep, - const std::string &suf) -{ - std::string list(pref); - for (unsigned int i = 0; i < (CANNY_COUNT_FILTERING - 1); ++i) { - vpCannyFilteringAndGradientType type = static_cast(i); - list += vpCannyFiltAndGradTypeToStr(type); - list += sep; - } - vpCannyFilteringAndGradientType type = static_cast(CANNY_COUNT_FILTERING - 1); - list += vpCannyFiltAndGradTypeToStr(type); - list += suf; - return list; -} - -/** - * \brief Cast a \b vpImageFilter::vpCannyFilteringAndGradientType into a string, to know its name. - * - * \param[in] type The type that must be casted into a string. - * \return std::string The corresponding name. - */ -std::string vpImageFilter::vpCannyFiltAndGradTypeToStr(const vpImageFilter::vpCannyFilteringAndGradientType &type) -{ - std::string name; - switch (type) { - case CANNY_GBLUR_SOBEL_FILTERING: - name = "gaussianblur+sobel-filtering"; - break; - case CANNY_GBLUR_SCHARR_FILTERING: - name = "gaussianblur+scharr-filtering"; - break; - case CANNY_COUNT_FILTERING: - default: - return "unknown-filtering"; - } - return name; -} - -/** - * \brief Cast a string into a \b vpImageFilter::vpCannyFilteringAndGradientType. - * - * \param[in] name The name of the backend. - * \return vpImageFilter::vpCannyFilteringAndGradientType The corresponding enumeration value. - */ -vpImageFilter::vpCannyFilteringAndGradientType vpImageFilter::vpCannyFiltAndGradTypeFromStr(const std::string &name) -{ - vpCannyFilteringAndGradientType type(CANNY_COUNT_FILTERING); - std::string nameLowerCase = vpIoTools::toLowerCase(name); - unsigned int count = static_cast(CANNY_COUNT_FILTERING); - bool notFound = true; - unsigned int i = 0; - while ((i < count) && notFound) { - vpCannyFilteringAndGradientType temp = static_cast(i); - if (nameLowerCase == vpCannyFiltAndGradTypeToStr(temp)) { - type = temp; - notFound = false; - } - ++i; - } - return type; -} /** - * \cond DO_NOT_DOCUMENT - */ +* \cond DO_NOT_DOCUMENT +*/ template -void vpImageFilter::filter(const vpImage &I, vpImage &If, const vpArray2D &M, bool convolve, const vpImage *p_mask); +void vpImageFilter::filter(const vpImage &I, vpImage &If, + const vpArray2D &M, bool convolve, const vpImage *p_mask); template -void vpImageFilter::filter(const vpImage &I, vpImage &If, const vpArray2D &M, bool convolve, const vpImage *p_mask); +void vpImageFilter::filter(const vpImage &I, vpImage &If, + const vpArray2D &M, bool convolve, const vpImage *p_mask); template -void vpImageFilter::filter(const vpImage &I, vpImage &Iu, vpImage &Iv, const vpArray2D &M, - bool convolve, const vpImage *p_mask); +void vpImageFilter::filter(const vpImage &I, vpImage &Iu, vpImage &Iv, + const vpArray2D &M, bool convolve, const vpImage *p_mask); template -void vpImageFilter::filter(const vpImage &I, vpImage &Iu, vpImage &Iv, const vpArray2D &M, - bool convolve, const vpImage *p_mask); +void vpImageFilter::filter(const vpImage &I, vpImage &Iu, vpImage &Iv, + const vpArray2D &M, bool convolve, const vpImage *p_mask); template void vpImageFilter::filter(const vpImage &I, vpImage &GI, const float *filter, @@ -203,13 +65,15 @@ void vpImageFilter::filter(const vpImage & unsigned int size, const vpImage *p_mask); template -void vpImageFilter::filter(const vpImage &I, vpImage &GI, const float *filter, unsigned int size, const vpImage *p_mask); +void vpImageFilter::filter(const vpImage &I, vpImage &GI, const float *filter, + unsigned int size, const vpImage *p_mask); template -void vpImageFilter::filter(const vpImage &I, vpImage &GI, const double *filter, unsigned int size, const vpImage *p_mask); +void vpImageFilter::filter(const vpImage &I, vpImage &GI, const double *filter, + unsigned int size, const vpImage *p_mask); /** * \endcond -*/ + */ /*! Apply a filter to an image using two separable kernels. For instance, @@ -691,75 +555,6 @@ std::vector vpImageFilter::median(const vpImage &Isrc) return meds; } -/** - * \brief Compute the upper Canny edge filter threshold, using Gaussian blur + Sobel or + Scharr operators to compute - * the gradient of the image. - * - * \param[in] cv_I : The image, in cv format. - * \param[in] p_cv_dIx : If different from nullptr, the gradient of cv_I with regard to the horizontal axis. - * \param[in] p_cv_dIy : If different from nullptr, the gradient of cv_I with regard to the vertical axis. - * \param[out] lowerThresh : The lower threshold for the Canny edge filter. - * \param[in] gaussianKernelSize : The size of the mask of the Gaussian filter to apply (an odd number). - * \param[in] gaussianStdev : The standard deviation of the Gaussian filter to apply. - * \param[in] apertureGradient : Size of the mask for the Sobel operator (odd number). - * \param[in] lowerThresholdRatio : The ratio of the upper threshold the lower threshold must be equal to. - * \param[in] upperThresholdRatio : The ratio of pixels whose absolute gradient Gabs is lower or equal to to define - * \param[in] filteringType : The gradient filter to apply to compute the gradient, if \b p_cv_dIx and \b p_cv_dIy are - * nullptr. - * the upper threshold. - * \return The upper Canny edge filter threshold. - */ -float vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p_cv_dIx, const cv::Mat *p_cv_dIy, - float &lowerThresh, const unsigned int &gaussianKernelSize, - const float &gaussianStdev, const unsigned int &apertureGradient, - const float &lowerThresholdRatio, const float &upperThresholdRatio, - const vpImageFilter::vpCannyFilteringAndGradientType &filteringType) -{ - double w = cv_I.cols; - double h = cv_I.rows; - int bins = 256; - cv::Mat dI, dIx, dIy, dIx_abs, dIy_abs; - - if ((p_cv_dIx == nullptr) || (p_cv_dIy == nullptr)) { - computePartialDerivatives(cv_I, dIx, dIy, true, true, true, gaussianKernelSize, gaussianStdev, apertureGradient, - filteringType); - } - else { - dIx = *p_cv_dIx; - dIy = *p_cv_dIy; - } - - // Compute the absolute gradient of the blurred image G = |dIx| + |dIy| - cv::convertScaleAbs(dIx, dIx_abs); - cv::convertScaleAbs(dIy, dIy_abs); - cv::addWeighted(dIx_abs, 1, dIy_abs, 1, 0, dI); - dI.convertTo(dI, CV_8U); - - // Compute the upper threshold from the equalized histogram - cv::Mat hist; - const float range[] = { 0.f, 256.f }; // The upper boundary is exclusive - const float *ranges[] = { range }; - int channels[] = { 0 }; - int dims = 1; // The number of dimensions of the histogram - int histSize[] = { bins }; - bool uniform = true; - bool accumulate = false; // Clear the histogram at the beginning of calcHist if false, does not clear it otherwise - cv::calcHist(&dI, 1, channels, cv::Mat(), hist, dims, histSize, ranges, uniform, accumulate); - float accu = 0; - float t = static_cast(upperThresholdRatio * w * h); - float bon = 0; - for (int i = 0; i < bins; ++i) { - float tf = hist.at(i); - accu = accu + tf; - if (accu > t) { - bon = static_cast(i); - break; - } - } - float upperThresh = std::max(bon, 1.f); - lowerThresh = lowerThresholdRatio * bon; - return upperThresh; -} /** * \brief Compute the partial derivatives (i.e. horizontal and vertical gradients) of the input image. @@ -901,235 +696,4 @@ float vpImageFilter::computeCannyThreshold(const vpImage & * \endcond */ -/*! - Apply the Canny edge operator on the image \e Isrc and return the resulting - image \e Ires. - - The following example shows how to use the method: - - \code -#include -#include - -int main() -{ - // Constants for the Canny operator. - const unsigned int gaussianFilterSize = 5; - const double thresholdCanny = 15; - const unsigned int apertureSobel = 3; - - // Image for the Canny edge operator - vpImage Isrc; - vpImage Icanny; - - // First grab the source image Isrc. - - // Apply the Canny edge operator and set the Icanny image. - vpImageFilter::canny(Isrc, Icanny, gaussianFilterSize, thresholdCanny, apertureSobel); - return (0); -} - \endcode - - \param[in] Isrc : Image to apply the Canny edge detector to. - \param[out] Ires : Filtered image (255 means an edge, 0 otherwise). - \param[in] gaussianFilterSize : The size of the mask of the Gaussian filter to - apply (an odd number). - \param[in] thresholdCanny : The upper threshold for the Canny operator. Only value - greater than this value are marked as an edge. If negative, it will be automatically - computed, along with the lower threshold. Otherwise, the lower threshold will be set to one third - of the thresholdCanny . - \param[in] apertureSobel : Size of the mask for the Sobel operator (odd number). -*/ -void vpImageFilter::canny(const vpImage &Isrc, vpImage &Ires, - const unsigned int &gaussianFilterSize, const float &thresholdCanny, - const unsigned int &apertureSobel) -{ - vpImageFilter::canny(Isrc, Ires, gaussianFilterSize, thresholdCanny / 3.f, thresholdCanny, apertureSobel); -} - -/*! - Apply the Canny edge operator on the image \e Isrc and return the resulting - image \e Ires. - - The following example shows how to use the method: - - \code -#include -#include - -int main() -{ - // Constants for the Canny operator. - const unsigned int gaussianFilterSize = 5; - const float upperThresholdCanny = 15; - const float lowerThresholdCanny = 5; - const unsigned int apertureSobel = 3; - - // Image for the Canny edge operator - vpImage Isrc; - vpImage Icanny; - - // First grab the source image Isrc. - - // Apply the Canny edge operator and set the Icanny image. - vpImageFilter::canny(Isrc, Icanny, gaussianFilterSize, lowerThresholdCanny, upperThresholdCanny, apertureSobel); - return (0); -} - \endcode - - \param[in] Isrc : Image to apply the Canny edge detector to. - \param[out] Ires : Filtered image (255 means an edge, 0 otherwise). - \param[in] gaussianFilterSize : The size of the mask of the Gaussian filter to - apply (an odd number). - \param[in] lowerThreshold : The lower threshold for the Canny operator. Values lower - than this value are rejected. If negative, it will be set to one third - of the thresholdCanny . - \param[in] upperThreshold : The upper threshold for the Canny operator. Only value - greater than this value are marked as an edge. If negative, it will be automatically - computed, along with the lower threshold. Otherwise, the lower threshold will be set to one third - of the thresholdCanny . - \param[in] apertureSobel : Size of the mask for the Sobel operator (odd number). -*/ -void vpImageFilter::canny(const vpImage &Isrc, vpImage &Ires, - const unsigned int &gaussianFilterSize, - const float &lowerThreshold, const float &upperThreshold, - const unsigned int &apertureSobel) -{ - const float gaussianStdev = 2.f; - const float upperThresholdRatio = 0.8f; - const float lowerThresholdRatio = 0.6f; -#if defined(HAVE_OPENCV_IMGPROC) - const vpCannyBackendType cannyBackend = CANNY_OPENCV_BACKEND; -#else - const vpCannyBackendType cannyBackend = CANNY_VISP_BACKEND; -#endif - const vpCannyFilteringAndGradientType cannyFilteringSteps = CANNY_GBLUR_SOBEL_FILTERING; - canny(Isrc, Ires, gaussianFilterSize, lowerThreshold, upperThreshold, apertureSobel, - gaussianStdev, lowerThresholdRatio, upperThresholdRatio, false, cannyBackend, cannyFilteringSteps); -} - -/*! - * Apply the Canny edge operator on the image \e Isrc and return the resulting - * image \e Ires. - * - * The following example shows how to use the method: - * - * \code - * #include - * #include - * - * int main() - * { - * // Constants for the Canny operator. - * const unsigned int gaussianFilterSize = 5; - * const float gaussianStdev = 2.0f; - * const float upperThresholdCanny = 15.f; - * const float lowerThresholdCanny = 5.f; - * const float upperThresholdRatio = 0.8f; - * const float lowerThresholdRatio = 0.6f; - * const unsigned int apertureSobel = 3; - * const bool normalizeGradient = true; - * const vpCannyBackendType cannyBackend = CANNY_OPENCV_BACKEND; // or CANNY_VISP_BACKEND; - * const vpCannyFilteringAndGradientType filteringType = CANNY_GBLUR_SOBEL_FILTERING; // or CANNY_GBLUR_SCHARR_FILTERING - * - * // Image for the Canny edge operator - * vpImage Isrc; - * vpImage Icanny; - * - * // First grab the source image Isrc. - * - * // Apply the Canny edge operator and set the Icanny image. - * vpImageFilter::canny(Isrc, Icanny, gaussianFilterSize, lowerThresholdCanny, upperThresholdCanny, apertureSobel, - * gaussianStdev, lowerThresholdRatio, upperThresholdRatio, normalizeGradient, - * cannyBackend, filteringType); - * return (0); - * } - * \endcode - * - * \param[in] Isrc : Image to apply the Canny edge detector to. - * \param[out] Ires : Filtered image (255 means an edge, 0 otherwise). - * \param[in] gaussianFilterSize : The size of the mask of the Gaussian filter to - * apply (an odd number). - * \param[in] lowerThreshold : The lower threshold for the Canny operator. Values lower - * than this value are rejected. If negative, it will be set to one third - * of the thresholdCanny. - * \param[in] upperThreshold : The upper threshold for the Canny operator. Only value - * greater than this value are marked as an edge. If negative, it will be automatically - * computed, along with the lower threshold. Otherwise, the lower threshold will be set to one third - * of the upper threshold. - * \param[in] apertureGradient : Size of the mask for the gradient (Sobel or Scharr) operator (odd number). - * \param[in] gaussianStdev : The standard deviation of the Gaussian filter to apply. - * If it is non-positive, it is computed from kernel size (`gaussianKernelSize` parameter) as - * \f$\sigma = 0.3*((gaussianKernelSize-1)*0.5 - 1) + 0.8\f$. - * \param[in] lowerThresholdRatio : The ratio of the upper threshold the lower threshold must be equal to. - * It is used only if the user asks to compute the Canny thresholds. - * \param[in] upperThresholdRatio : The ratio of pixels whose absolute gradient is lower or equal to define - * the upper threshold. It is used only if the user asks to compute the Canny thresholds. - * \param[in] normalizeGradients : Needs to be true if asking to compute the \b upperThreshold, otherwise it depends on - * the user application and user-defined thresholds. - * \param[in] cannyBackend : The backend to use to perform the Canny edge filtering. - * \param[in] cannyFilteringSteps : The filtering + gradient operators to apply to compute the gradient in the early - * stage of the Canny algorithm. - * \param[in] p_mask : Optional image mask that indicates where Canny edge detection has to be computed. - */ -void vpImageFilter::canny(const vpImage &Isrc, vpImage &Ires, - const unsigned int &gaussianFilterSize, - const float &lowerThreshold, const float &upperThreshold, const unsigned int &apertureGradient, - const float &gaussianStdev, const float &lowerThresholdRatio, const float &upperThresholdRatio, - const bool &normalizeGradients, - const vpCannyBackendType &cannyBackend, const vpCannyFilteringAndGradientType &cannyFilteringSteps, - const vpImage *p_mask) -{ - if (cannyBackend == CANNY_OPENCV_BACKEND) { -#if defined(HAVE_OPENCV_IMGPROC) - cv::Mat img_cvmat, cv_dx, cv_dy, edges_cvmat; - vpImageConvert::convert(Isrc, img_cvmat); - computePartialDerivatives(img_cvmat, cv_dx, cv_dy, true, true, normalizeGradients, gaussianFilterSize, - gaussianStdev, apertureGradient, cannyFilteringSteps); - float upperCannyThresh = upperThreshold; - float lowerCannyThresh = lowerThreshold; - if (upperCannyThresh < 0.f) { - upperCannyThresh = computeCannyThreshold(img_cvmat, &cv_dx, &cv_dy, lowerCannyThresh, gaussianFilterSize, - gaussianStdev, apertureGradient, lowerThresholdRatio, upperThresholdRatio, - cannyFilteringSteps); - } - else if (lowerCannyThresh < 0.f) { - lowerCannyThresh = upperCannyThresh / 3.f; - } -#if (VISP_HAVE_OPENCV_VERSION >= 0x030200) - cv::Canny(cv_dx, cv_dy, edges_cvmat, lowerCannyThresh, upperCannyThresh, false); -#else - cv::GaussianBlur(img_cvmat, img_cvmat, cv::Size((int)gaussianFilterSize, (int)gaussianFilterSize), - gaussianStdev, gaussianStdev); - cv::Canny(img_cvmat, edges_cvmat, lowerCannyThresh, upperCannyThresh); -#endif - vpImageConvert::convert(edges_cvmat, Ires); -#else - std::string errMsg("[vpImageFilter::canny]You asked for CANNY_OPENCV_BACKEND but ViSP has not been compiled with OpenCV"); - throw(vpException(vpException::badValue, errMsg)); -#endif - } - else if (cannyBackend == CANNY_VISP_BACKEND) { - float upperCannyThresh = upperThreshold; - float lowerCannyThresh = lowerThreshold; - - vpImage dIx, dIy; - computePartialDerivatives(Isrc, dIx, dIy, true, true, normalizeGradients, gaussianFilterSize, - gaussianStdev, apertureGradient, cannyFilteringSteps, cannyBackend, p_mask); - - if (upperCannyThresh < 0.f) { - upperCannyThresh = computeCannyThreshold(Isrc, lowerCannyThresh, &dIx, &dIy, gaussianFilterSize, gaussianStdev, - apertureGradient, lowerThresholdRatio, upperThresholdRatio, - cannyFilteringSteps, p_mask); - } - else if (lowerCannyThresh < 0.f) { - lowerCannyThresh = upperCannyThresh / 3.f; - } - vpCannyEdgeDetection edgeDetector(gaussianFilterSize, gaussianStdev, apertureGradient, lowerCannyThresh, upperCannyThresh, - lowerThresholdRatio, upperThresholdRatio, cannyFilteringSteps); - edgeDetector.setGradients(dIx, dIy); - edgeDetector.setMask(p_mask); - Ires = edgeDetector.detect(Isrc); - } -} END_VISP_NAMESPACE diff --git a/modules/core/src/image/vpImageFilter_canny.cpp b/modules/core/src/image/vpImageFilter_canny.cpp new file mode 100644 index 0000000000..f98930a072 --- /dev/null +++ b/modules/core/src/image/vpImageFilter_canny.cpp @@ -0,0 +1,486 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Image Canny filtering. + */ + +#include +#include +#include +#include + +BEGIN_VISP_NAMESPACE + +/** +* \brief Get the list of available vpCannyBackendType. +* +* \param[in] pref The prefix of the list. +* \param[in] sep The separator between two elements of the list. +* \param[in] suf The suffix of the list. +* \return std::string The list of available items. +*/ +std::string vpImageFilter::vpCannyBackendTypeList(const std::string &pref, const std::string &sep, + const std::string &suf) +{ + std::string list(pref); + for (unsigned int i = 0; i < (CANNY_COUNT_BACKEND - 1); ++i) { + vpCannyBackendType type = static_cast(i); + list += vpCannyBackendTypeToString(type); + list += sep; + } + vpCannyBackendType type = static_cast(CANNY_COUNT_BACKEND - 1); + list += vpCannyBackendTypeToString(type); + list += suf; + return list; +} + +/** + * \brief Cast a \b vpImageFilter::vpCannyBackendTypeToString into a string, to know its name. + * + * \param[in] type The type that must be casted into a string. + * \return std::string The corresponding name. + */ +std::string vpImageFilter::vpCannyBackendTypeToString(const vpImageFilter::vpCannyBackendType &type) +{ + std::string name; + switch (type) { + case CANNY_OPENCV_BACKEND: + name = "opencv-backend"; + break; + case CANNY_VISP_BACKEND: + name = "visp-backend"; + break; + case CANNY_COUNT_BACKEND: + default: + return "unknown-backend"; + } + return name; +} + +/** + * \brief Cast a string into a \b vpImageFilter::vpCannyBackendTypeToString. + * + * \param[in] name The name of the backend. + * \return vpImageFilter::vpCannyBackendTypeToString The corresponding enumeration value. + */ +vpImageFilter::vpCannyBackendType vpImageFilter::vpCannyBackendTypeFromString(const std::string &name) +{ + vpCannyBackendType type(CANNY_COUNT_BACKEND); + std::string nameLowerCase = vpIoTools::toLowerCase(name); + unsigned int count = static_cast(CANNY_COUNT_BACKEND); + bool notFound = true; + unsigned int i = 0; + while ((i < count) && notFound) { + vpCannyBackendType temp = static_cast(i); + if (nameLowerCase == vpCannyBackendTypeToString(temp)) { + type = temp; + notFound = false; + } + ++i; + } + return type; +} + +/** + * \brief Get the list of available vpCannyFilteringAndGradientType. + * + * \param[in] pref The prefix of the list. + * \param[in] sep The separator between two elements of the list. + * \param[in] suf The suffix of the list. + * \return std::string The list of available items. + */ +std::string vpImageFilter::vpGetCannyFiltAndGradTypes(const std::string &pref, const std::string &sep, + const std::string &suf) +{ + std::string list(pref); + for (unsigned int i = 0; i < (CANNY_COUNT_FILTERING - 1); ++i) { + vpCannyFilteringAndGradientType type = static_cast(i); + list += vpCannyFiltAndGradTypeToStr(type); + list += sep; + } + vpCannyFilteringAndGradientType type = static_cast(CANNY_COUNT_FILTERING - 1); + list += vpCannyFiltAndGradTypeToStr(type); + list += suf; + return list; +} + +/** + * \brief Cast a \b vpImageFilter::vpCannyFilteringAndGradientType into a string, to know its name. + * + * \param[in] type The type that must be casted into a string. + * \return std::string The corresponding name. + */ +std::string vpImageFilter::vpCannyFiltAndGradTypeToStr(const vpImageFilter::vpCannyFilteringAndGradientType &type) +{ + std::string name; + switch (type) { + case CANNY_GBLUR_SOBEL_FILTERING: + name = "gaussianblur+sobel-filtering"; + break; + case CANNY_GBLUR_SCHARR_FILTERING: + name = "gaussianblur+scharr-filtering"; + break; + case CANNY_COUNT_FILTERING: + default: + return "unknown-filtering"; + } + return name; +} + +/** + * \brief Cast a string into a \b vpImageFilter::vpCannyFilteringAndGradientType. + * + * \param[in] name The name of the backend. + * \return vpImageFilter::vpCannyFilteringAndGradientType The corresponding enumeration value. + */ +vpImageFilter::vpCannyFilteringAndGradientType vpImageFilter::vpCannyFiltAndGradTypeFromStr(const std::string &name) +{ + vpCannyFilteringAndGradientType type(CANNY_COUNT_FILTERING); + std::string nameLowerCase = vpIoTools::toLowerCase(name); + unsigned int count = static_cast(CANNY_COUNT_FILTERING); + bool notFound = true; + unsigned int i = 0; + while ((i < count) && notFound) { + vpCannyFilteringAndGradientType temp = static_cast(i); + if (nameLowerCase == vpCannyFiltAndGradTypeToStr(temp)) { + type = temp; + notFound = false; + } + ++i; + } + return type; +} + +#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) +/** + * \brief Compute the upper Canny edge filter threshold, using Gaussian blur + Sobel or + Scharr operators to compute + * the gradient of the image. + * + * \param[in] cv_I : The image, in cv format. + * \param[in] p_cv_dIx : If different from nullptr, the gradient of cv_I with regard to the horizontal axis. + * \param[in] p_cv_dIy : If different from nullptr, the gradient of cv_I with regard to the vertical axis. + * \param[out] lowerThresh : The lower threshold for the Canny edge filter. + * \param[in] gaussianKernelSize : The size of the mask of the Gaussian filter to apply (an odd number). + * \param[in] gaussianStdev : The standard deviation of the Gaussian filter to apply. + * \param[in] apertureGradient : Size of the mask for the Sobel operator (odd number). + * \param[in] lowerThresholdRatio : The ratio of the upper threshold the lower threshold must be equal to. + * \param[in] upperThresholdRatio : The ratio of pixels whose absolute gradient Gabs is lower or equal to to define + * \param[in] filteringType : The gradient filter to apply to compute the gradient, if \b p_cv_dIx and \b p_cv_dIy are + * nullptr. + * the upper threshold. + * \return The upper Canny edge filter threshold. + */ +float vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p_cv_dIx, const cv::Mat *p_cv_dIy, + float &lowerThresh, const unsigned int &gaussianKernelSize, + const float &gaussianStdev, const unsigned int &apertureGradient, + const float &lowerThresholdRatio, const float &upperThresholdRatio, + const vpImageFilter::vpCannyFilteringAndGradientType &filteringType) +{ + double w = cv_I.cols; + double h = cv_I.rows; + int bins = 256; + cv::Mat dI, dIx, dIy, dIx_abs, dIy_abs; + + if ((p_cv_dIx == nullptr) || (p_cv_dIy == nullptr)) { + computePartialDerivatives(cv_I, dIx, dIy, true, true, true, gaussianKernelSize, gaussianStdev, apertureGradient, + filteringType); + } + else { + dIx = *p_cv_dIx; + dIy = *p_cv_dIy; + } + + // Compute the absolute gradient of the blurred image G = |dIx| + |dIy| + cv::convertScaleAbs(dIx, dIx_abs); + cv::convertScaleAbs(dIy, dIy_abs); + cv::addWeighted(dIx_abs, 1, dIy_abs, 1, 0, dI); + dI.convertTo(dI, CV_8U); + + // Compute the upper threshold from the equalized histogram + cv::Mat hist; + const float range[] = { 0.f, 256.f }; // The upper boundary is exclusive + const float *ranges[] = { range }; + int channels[] = { 0 }; + int dims = 1; // The number of dimensions of the histogram + int histSize[] = { bins }; + bool uniform = true; + bool accumulate = false; // Clear the histogram at the beginning of calcHist if false, does not clear it otherwise + cv::calcHist(&dI, 1, channels, cv::Mat(), hist, dims, histSize, ranges, uniform, accumulate); + float accu = 0; + float t = static_cast(upperThresholdRatio * w * h); + float bon = 0; + for (int i = 0; i < bins; ++i) { + float tf = hist.at(i); + accu = accu + tf; + if (accu > t) { + bon = static_cast(i); + break; + } + } + float upperThresh = std::max(bon, 1.f); + lowerThresh = lowerThresholdRatio * bon; + return upperThresh; +} +#endif + +/*! + Apply the Canny edge operator on the image \e Isrc and return the resulting + image \e Ires. + + The following example shows how to use the method: + + \code + #include + #include + + int main() + { + // Constants for the Canny operator. + const unsigned int gaussianFilterSize = 5; + const double thresholdCanny = 15; + const unsigned int apertureSobel = 3; + + // Image for the Canny edge operator + vpImage Isrc; + vpImage Icanny; + + // First grab the source image Isrc. + + // Apply the Canny edge operator and set the Icanny image. + vpImageFilter::canny(Isrc, Icanny, gaussianFilterSize, thresholdCanny, apertureSobel); + return (0); + } + \endcode + + \param[in] Isrc : Image to apply the Canny edge detector to. + \param[out] Ires : Filtered image (255 means an edge, 0 otherwise). + \param[in] gaussianFilterSize : The size of the mask of the Gaussian filter to + apply (an odd number). + \param[in] thresholdCanny : The upper threshold for the Canny operator. Only value + greater than this value are marked as an edge. If negative, it will be automatically + computed, along with the lower threshold. Otherwise, the lower threshold will be set to one third + of the thresholdCanny . + \param[in] apertureSobel : Size of the mask for the Sobel operator (odd number). +*/ +void vpImageFilter::canny(const vpImage &Isrc, vpImage &Ires, + const unsigned int &gaussianFilterSize, const float &thresholdCanny, + const unsigned int &apertureSobel) +{ + vpImageFilter::canny(Isrc, Ires, gaussianFilterSize, thresholdCanny / 3.f, thresholdCanny, apertureSobel); +} + +/*! + Apply the Canny edge operator on the image \e Isrc and return the resulting + image \e Ires. + + The following example shows how to use the method: + + \code + #include + #include + + int main() + { + // Constants for the Canny operator. + const unsigned int gaussianFilterSize = 5; + const float upperThresholdCanny = 15; + const float lowerThresholdCanny = 5; + const unsigned int apertureSobel = 3; + + // Image for the Canny edge operator + vpImage Isrc; + vpImage Icanny; + + // First grab the source image Isrc. + + // Apply the Canny edge operator and set the Icanny image. + vpImageFilter::canny(Isrc, Icanny, gaussianFilterSize, lowerThresholdCanny, upperThresholdCanny, apertureSobel); + return (0); + } + \endcode + + \param[in] Isrc : Image to apply the Canny edge detector to. + \param[out] Ires : Filtered image (255 means an edge, 0 otherwise). + \param[in] gaussianFilterSize : The size of the mask of the Gaussian filter to + apply (an odd number). + \param[in] lowerThreshold : The lower threshold for the Canny operator. Values lower + than this value are rejected. If negative, it will be set to one third + of the thresholdCanny . + \param[in] upperThreshold : The upper threshold for the Canny operator. Only value + greater than this value are marked as an edge. If negative, it will be automatically + computed, along with the lower threshold. Otherwise, the lower threshold will be set to one third + of the thresholdCanny . + \param[in] apertureSobel : Size of the mask for the Sobel operator (odd number). +*/ +void vpImageFilter::canny(const vpImage &Isrc, vpImage &Ires, + const unsigned int &gaussianFilterSize, + const float &lowerThreshold, const float &upperThreshold, + const unsigned int &apertureSobel) +{ + const float gaussianStdev = 2.f; + const float upperThresholdRatio = 0.8f; + const float lowerThresholdRatio = 0.6f; +#if defined(HAVE_OPENCV_IMGPROC) + const vpCannyBackendType cannyBackend = CANNY_OPENCV_BACKEND; +#else + const vpCannyBackendType cannyBackend = CANNY_VISP_BACKEND; +#endif + const vpCannyFilteringAndGradientType cannyFilteringSteps = CANNY_GBLUR_SOBEL_FILTERING; + canny(Isrc, Ires, gaussianFilterSize, lowerThreshold, upperThreshold, apertureSobel, + gaussianStdev, lowerThresholdRatio, upperThresholdRatio, false, cannyBackend, cannyFilteringSteps); +} + +/*! + * Apply the Canny edge operator on the image \e Isrc and return the resulting + * image \e Ires. + * + * The following example shows how to use the method: + * + * \code + * #include + * #include + * + * int main() + * { + * // Constants for the Canny operator. + * const unsigned int gaussianFilterSize = 5; + * const float gaussianStdev = 2.0f; + * const float upperThresholdCanny = 15.f; + * const float lowerThresholdCanny = 5.f; + * const float upperThresholdRatio = 0.8f; + * const float lowerThresholdRatio = 0.6f; + * const unsigned int apertureSobel = 3; + * const bool normalizeGradient = true; + * const vpCannyBackendType cannyBackend = CANNY_OPENCV_BACKEND; // or CANNY_VISP_BACKEND; + * const vpCannyFilteringAndGradientType filteringType = CANNY_GBLUR_SOBEL_FILTERING; // or CANNY_GBLUR_SCHARR_FILTERING + * + * // Image for the Canny edge operator + * vpImage Isrc; + * vpImage Icanny; + * + * // First grab the source image Isrc. + * + * // Apply the Canny edge operator and set the Icanny image. + * vpImageFilter::canny(Isrc, Icanny, gaussianFilterSize, lowerThresholdCanny, upperThresholdCanny, apertureSobel, + * gaussianStdev, lowerThresholdRatio, upperThresholdRatio, normalizeGradient, + * cannyBackend, filteringType); + * return (0); + * } + * \endcode + * + * \param[in] Isrc : Image to apply the Canny edge detector to. + * \param[out] Ires : Filtered image (255 means an edge, 0 otherwise). + * \param[in] gaussianFilterSize : The size of the mask of the Gaussian filter to + * apply (an odd number). + * \param[in] lowerThreshold : The lower threshold for the Canny operator. Values lower + * than this value are rejected. If negative, it will be set to one third + * of the thresholdCanny. + * \param[in] upperThreshold : The upper threshold for the Canny operator. Only value + * greater than this value are marked as an edge. If negative, it will be automatically + * computed, along with the lower threshold. Otherwise, the lower threshold will be set to one third + * of the upper threshold. + * \param[in] apertureGradient : Size of the mask for the gradient (Sobel or Scharr) operator (odd number). + * \param[in] gaussianStdev : The standard deviation of the Gaussian filter to apply. + * If it is non-positive, it is computed from kernel size (`gaussianKernelSize` parameter) as + * \f$\sigma = 0.3*((gaussianKernelSize-1)*0.5 - 1) + 0.8\f$. + * \param[in] lowerThresholdRatio : The ratio of the upper threshold the lower threshold must be equal to. + * It is used only if the user asks to compute the Canny thresholds. + * \param[in] upperThresholdRatio : The ratio of pixels whose absolute gradient is lower or equal to define + * the upper threshold. It is used only if the user asks to compute the Canny thresholds. + * \param[in] normalizeGradients : Needs to be true if asking to compute the \b upperThreshold, otherwise it depends on + * the user application and user-defined thresholds. + * \param[in] cannyBackend : The backend to use to perform the Canny edge filtering. + * \param[in] cannyFilteringSteps : The filtering + gradient operators to apply to compute the gradient in the early + * stage of the Canny algorithm. + * \param[in] p_mask : Optional image mask that indicates where Canny edge detection has to be computed. + */ +void vpImageFilter::canny(const vpImage &Isrc, vpImage &Ires, + const unsigned int &gaussianFilterSize, + const float &lowerThreshold, const float &upperThreshold, const unsigned int &apertureGradient, + const float &gaussianStdev, const float &lowerThresholdRatio, const float &upperThresholdRatio, + const bool &normalizeGradients, + const vpCannyBackendType &cannyBackend, const vpCannyFilteringAndGradientType &cannyFilteringSteps, + const vpImage *p_mask) +{ + if (cannyBackend == CANNY_OPENCV_BACKEND) { +#if defined(HAVE_OPENCV_IMGPROC) + cv::Mat img_cvmat, cv_dx, cv_dy, edges_cvmat; + vpImageConvert::convert(Isrc, img_cvmat); + computePartialDerivatives(img_cvmat, cv_dx, cv_dy, true, true, normalizeGradients, gaussianFilterSize, + gaussianStdev, apertureGradient, cannyFilteringSteps); + float upperCannyThresh = upperThreshold; + float lowerCannyThresh = lowerThreshold; + if (upperCannyThresh < 0.f) { + upperCannyThresh = computeCannyThreshold(img_cvmat, &cv_dx, &cv_dy, lowerCannyThresh, gaussianFilterSize, + gaussianStdev, apertureGradient, lowerThresholdRatio, upperThresholdRatio, + cannyFilteringSteps); + } + else if (lowerCannyThresh < 0.f) { + lowerCannyThresh = upperCannyThresh / 3.f; + } +#if (VISP_HAVE_OPENCV_VERSION >= 0x030200) + cv::Canny(cv_dx, cv_dy, edges_cvmat, lowerCannyThresh, upperCannyThresh, false); +#else + cv::GaussianBlur(img_cvmat, img_cvmat, cv::Size((int)gaussianFilterSize, (int)gaussianFilterSize), + gaussianStdev, gaussianStdev); + cv::Canny(img_cvmat, edges_cvmat, lowerCannyThresh, upperCannyThresh); +#endif + vpImageConvert::convert(edges_cvmat, Ires); +#else + std::string errMsg("[vpImageFilter::canny]You asked for CANNY_OPENCV_BACKEND but ViSP has not been compiled with OpenCV"); + throw(vpException(vpException::badValue, errMsg)); +#endif + } + else if (cannyBackend == CANNY_VISP_BACKEND) { + float upperCannyThresh = upperThreshold; + float lowerCannyThresh = lowerThreshold; + + vpImage dIx, dIy; + computePartialDerivatives(Isrc, dIx, dIy, true, true, normalizeGradients, gaussianFilterSize, + gaussianStdev, apertureGradient, cannyFilteringSteps, cannyBackend, p_mask); + + if (upperCannyThresh < 0.f) { + upperCannyThresh = computeCannyThreshold(Isrc, lowerCannyThresh, &dIx, &dIy, gaussianFilterSize, gaussianStdev, + apertureGradient, lowerThresholdRatio, upperThresholdRatio, + cannyFilteringSteps, p_mask); + } + else if (lowerCannyThresh < 0.f) { + lowerCannyThresh = upperCannyThresh / 3.f; + } + vpCannyEdgeDetection edgeDetector(gaussianFilterSize, gaussianStdev, apertureGradient, lowerCannyThresh, upperCannyThresh, + lowerThresholdRatio, upperThresholdRatio, cannyFilteringSteps); + edgeDetector.setGradients(dIx, dIy); + edgeDetector.setMask(p_mask); + Ires = edgeDetector.detect(Isrc); + } +} + + +END_VISP_NAMESPACE diff --git a/modules/core/src/image/vpImageFilter_xy.cpp b/modules/core/src/image/vpImageFilter_xy.cpp new file mode 100644 index 0000000000..fd1f946a07 --- /dev/null +++ b/modules/core/src/image/vpImageFilter_xy.cpp @@ -0,0 +1,314 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Image XY filtering. + */ + +#include +#include + +BEGIN_VISP_NAMESPACE + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +double vpImageFilter::filterXR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + for (unsigned int i = 1; i <= stop; ++i) { + result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); + } + return result + (filter[0] * static_cast(I[r][c].R)); +} + +double vpImageFilter::filterXG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); + } + return result + (filter[0] * static_cast(I[r][c].G)); +} + +double vpImageFilter::filterXB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); + } + return result + (filter[0] * static_cast(I[r][c].B)); +} + +double vpImageFilter::filterXLeftBorderR(const vpImage &I, unsigned int r, unsigned int c, + const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if (c > i) { + result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); + } + else { + result += filter[i] * static_cast(I[r][c + i].R + I[r][i - c].R); + } + } + return result + (filter[0] * static_cast(I[r][c].R)); +} + +double vpImageFilter::filterXLeftBorderG(const vpImage &I, unsigned int r, unsigned int c, + const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if (c > i) { + result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); + } + else { + result += filter[i] * static_cast(I[r][c + i].G + I[r][i - c].G); + } + } + return result + (filter[0] * static_cast(I[r][c].G)); +} + +double vpImageFilter::filterXLeftBorderB(const vpImage &I, unsigned int r, unsigned int c, + const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if (c > i) { + result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); + } + else { + result += filter[i] * static_cast(I[r][c + i].B + I[r][i - c].B); + } + } + return result + (filter[0] * static_cast(I[r][c].B)); +} + +double vpImageFilter::filterXRightBorderR(const vpImage &I, unsigned int r, unsigned int c, + const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + const unsigned int width = I.getWidth(); + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if ((c + i) < width) { + result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); + } + else { + result += filter[i] * static_cast(I[r][((2 * width) - c) - i - 1].R + I[r][c - i].R); + } + } + return result + (filter[0] * static_cast(I[r][c].R)); +} + +double vpImageFilter::filterXRightBorderG(const vpImage &I, unsigned int r, unsigned int c, + const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + const unsigned int width = I.getWidth(); + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if ((c + i) < width) { + result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); + } + else { + result += filter[i] * static_cast(I[r][((2 * width) - c) - i - 1].G + I[r][c - i].G); + } + } + return result + (filter[0] * static_cast(I[r][c].G)); +} + +double vpImageFilter::filterXRightBorderB(const vpImage &I, unsigned int r, unsigned int c, + const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + const unsigned int width = I.getWidth(); + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if ((c + i) < width) { + result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); + } + else { + result += filter[i] * static_cast(I[r][(2 * width) - c - i - 1].B + I[r][c - i].B); + } + } + return result + (filter[0] * static_cast(I[r][c].B)); +} + +double vpImageFilter::filterYR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); + } + return result + (filter[0] * static_cast(I[r][c].R)); +} + +double vpImageFilter::filterYG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); + } + return result + (filter[0] * static_cast(I[r][c].G)); +} + +double vpImageFilter::filterYB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); + } + return result + (filter[0] * static_cast(I[r][c].B)); +} + +double vpImageFilter::filterYTopBorderR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if (r > i) { + result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); + } + else { + result += filter[i] * static_cast(I[r + i][c].R + I[i - r][c].R); + } + } + return result + (filter[0] * static_cast(I[r][c].R)); +} + +double vpImageFilter::filterYTopBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if (r > i) { + result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); + } + else { + result += filter[i] * static_cast(I[r + i][c].G + I[i - r][c].G); + } + } + return result + (filter[0] * static_cast(I[r][c].G)); +} + +double vpImageFilter::filterYTopBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) +{ + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if (r > i) { + result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); + } + else { + result += filter[i] * static_cast(I[r + i][c].B + I[i - r][c].B); + } + } + return result + (filter[0] * static_cast(I[r][c].B)); +} + +double vpImageFilter::filterYBottomBorderR(const vpImage &I, unsigned int r, unsigned int c, + const double *filter, unsigned int size) +{ + const unsigned int height = I.getHeight(); + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if ((r + i) < height) { + result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); + } + else { + result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].R + I[r - i][c].R); + } + } + return result + (filter[0] * static_cast(I[r][c].R)); +} + +double vpImageFilter::filterYBottomBorderG(const vpImage &I, unsigned int r, unsigned int c, + const double *filter, unsigned int size) +{ + const unsigned int height = I.getHeight(); + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if ((r + i) < height) { + result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); + } + else { + result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].G + I[r - i][c].G); + } + } + return result + (filter[0] * static_cast(I[r][c].G)); +} + +double vpImageFilter::filterYBottomBorderB(const vpImage &I, unsigned int r, unsigned int c, + const double *filter, unsigned int size) +{ + const unsigned int height = I.getHeight(); + const unsigned int stop = (size - 1) / 2; + double result = 0.; + + for (unsigned int i = 1; i <= stop; ++i) { + if ((r + i) < height) { + result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); + } + else { + result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].B + I[r - i][c].B); + } + } + return result + (filter[0] * static_cast(I[r][c].B)); +} + +#endif + +END_VISP_NAMESPACE diff --git a/modules/core/src/math/matrix/private/vpMatrix_pseudo_inverse.h b/modules/core/src/math/matrix/private/vpMatrix_pseudo_inverse.h new file mode 100644 index 0000000000..56eee395f8 --- /dev/null +++ b/modules/core/src/math/matrix/private/vpMatrix_pseudo_inverse.h @@ -0,0 +1,51 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Pseudo inverse computation. + */ + +#ifndef VP_MATRIX_PSEUDO_INVERSE_H +#define VP_MATRIX_PSEUDO_INVERSE_H + +#include +#include + +BEGIN_VISP_NAMESPACE + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + +void compute_pseudo_inverse(const vpMatrix &U, const vpColVector &sv, const vpMatrix &V, unsigned int nrows, + unsigned int ncols, double svThreshold, vpMatrix &Ap, int &rank_out, int *rank_in, + vpMatrix *imA, vpMatrix *imAt, vpMatrix *kerAt); +#endif + +END_VISP_NAMESPACE + +#endif diff --git a/modules/core/src/math/matrix/vpEigenConversion.cpp b/modules/core/src/math/matrix/vpEigenConversion.cpp index 3a179cbae3..f79a3510c5 100644 --- a/modules/core/src/math/matrix/vpEigenConversion.cpp +++ b/modules/core/src/math/matrix/vpEigenConversion.cpp @@ -29,8 +29,7 @@ * * Description: * ViSP <--> Eigen conversion. - * -*****************************************************************************/ + */ #include diff --git a/modules/core/src/math/matrix/vpMatrix.cpp b/modules/core/src/math/matrix/vpMatrix.cpp index 58607ae527..14d87bb11f 100644 --- a/modules/core/src/math/matrix/vpMatrix.cpp +++ b/modules/core/src/math/matrix/vpMatrix.cpp @@ -121,73 +121,6 @@ unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default; // Prototypes of specific functions vpMatrix subblock(const vpMatrix &M, unsigned int col, unsigned int row); -void compute_pseudo_inverse(const vpMatrix &U, const vpColVector &sv, const vpMatrix &V, unsigned int nrows, - unsigned int ncols, double svThreshold, vpMatrix &Ap, int &rank_out, int *rank_in, - vpMatrix *imA, vpMatrix *imAt, vpMatrix *kerAt) -{ - Ap.resize(ncols, nrows, true, false); - - // compute the highest singular value and the rank of h - double maxsv = sv[0]; - - rank_out = 0; - - unsigned int sv_size = sv.size(); - for (unsigned int i = 0; i < sv_size; ++i) { - if (sv[i] >(maxsv * svThreshold)) { - ++rank_out; - } - } - - unsigned int rank = static_cast(rank_out); - if (rank_in) { - rank = static_cast(*rank_in); - } - - for (unsigned int i = 0; i < ncols; ++i) { - for (unsigned int j = 0; j < nrows; ++j) { - for (unsigned int k = 0; k < rank; ++k) { - Ap[i][j] += (V[i][k] * U[j][k]) / sv[k]; - } - } - } - - // Compute im(A) - if (imA) { - imA->resize(nrows, rank); - - for (unsigned int i = 0; i < nrows; ++i) { - for (unsigned int j = 0; j < rank; ++j) { - (*imA)[i][j] = U[i][j]; - } - } - } - - // Compute im(At) - if (imAt) { - imAt->resize(ncols, rank); - for (unsigned int i = 0; i < ncols; ++i) { - for (unsigned int j = 0; j < rank; ++j) { - (*imAt)[i][j] = V[i][j]; - } - } - } - - // Compute ker(At) - if (kerAt) { - kerAt->resize(ncols - rank, ncols); - if (rank != ncols) { - unsigned int v_rows = V.getRows(); - for (unsigned int k = 0; k < (ncols - rank); ++k) { - unsigned j = k + rank; - for (unsigned int i = 0; i < v_rows; ++i) { - (*kerAt)[k][i] = V[i][j]; - } - } - } - } -} - /*! Construct a matrix as a sub-matrix of the input matrix \e M. \sa init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int @@ -359,4506 +292,74 @@ void vpMatrix::init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned resize(nrows, ncols, false, false); if (this->rowPtrs == nullptr) { // Fix coverity scan: explicit null dereferenced - return; // Noting to do - } - for (unsigned int i = 0; i < nrows; ++i) { - memcpy((*this)[i], &M[i + r][c], ncols * sizeof(double)); - } -} - -/*! - Extract a sub matrix from a matrix \e M. - - \param r : row index in matrix \e M. - \param c : column index in matrix \e M. - \param nrows : Number of rows of the matrix that should be extracted. - \param ncols : Number of columns of the matrix that should be extracted. - - The following code shows how to use this function: - \code - #include - - int main() - { - vpMatrix M(4,5); - int val = 0; - for(size_t i=0; i getRows()) { - throw(vpException(vpException::dimensionError, "Bad row dimension (%d > %d) used to initialize vpMatrix", rnrows, - getRows())); - } - if (cncols > getCols()) { - throw(vpException(vpException::dimensionError, "Bad column dimension (%d > %d) used to initialize vpMatrix", cncols, - getCols())); - } - - vpMatrix M; - M.resize(nrows, ncols, false, false); - for (unsigned int i = 0; i < nrows; ++i) { - memcpy(M[i], &(*this)[i + r][c], ncols * sizeof(double)); - } - - return M; -} - -/*! - Set an n-by-n matrix to identity with ones on the diagonal and zeros - else where. -*/ -void vpMatrix::eye(unsigned int n) { eye(n, n); } - -/*! - Set an m-by-n matrix to identity with ones on the diagonal and zeros - else where. -*/ -void vpMatrix::eye(unsigned int m, unsigned int n) -{ - resize(m, n); - - eye(); -} - -/*! - Set an m-by-n matrix to identity with ones on the diagonal and zeros - else where. -*/ -void vpMatrix::eye() -{ - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - if (i == j) { - (*this)[i][j] = 1.0; - } - else { - (*this)[i][j] = 0; - } - } - } -} - -/*! - Compute and return the transpose of the matrix. -*/ -vpMatrix vpMatrix::t() const { return transpose(); } - -/*! - Compute and return the transpose of the matrix. - - \sa t() -*/ -vpMatrix vpMatrix::transpose() const -{ - vpMatrix At; - transpose(At); - return At; -} - -/*! - Compute \e At the transpose of the matrix. - \param At (output) : Resulting transpose matrix. - \sa t() -*/ -void vpMatrix::transpose(vpMatrix &At) const -{ - At.resize(colNum, rowNum, false, false); - - if ((rowNum <= 16) || (colNum <= 16)) { - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - At[j][i] = (*this)[i][j]; - } - } - } - else { -#if defined(VISP_HAVE_SIMDLIB) - SimdMatTranspose(data, rowNum, colNum, At.data); -#else - // https://stackoverflow.com/a/21548079 - const int tileSize = 32; - for (unsigned int i = 0; i < rowNum; i += tileSize) { - for (unsigned int j = 0; j < colNum; ++j) { - for (unsigned int b = 0; ((b < static_cast(tileSize)) && ((i + b) < rowNum)); ++b) { - At[j][i + b] = (*this)[i + b][j]; - } - } - } -#endif - } -} - -/*! - Computes the \f$AA^T\f$ operation \f$B = A*A^T\f$ - \return \f$A*A^T\f$ - \sa AAt(vpMatrix &) const -*/ -vpMatrix vpMatrix::AAt() const -{ - vpMatrix B; - - AAt(B); - - return B; -} - -/*! - Compute the AAt operation such as \f$B = A*A^T\f$. - - The result is placed in the parameter \e B and not returned. - - A new matrix won't be allocated for every use of the function. This - results in a speed gain if used many times with the same result - matrix size. - - \sa AAt() -*/ -void vpMatrix::AAt(vpMatrix &B) const -{ - if ((B.rowNum != rowNum) || (B.colNum != rowNum)) { - B.resize(rowNum, rowNum, false, false); - } - - // If available use Lapack only for large matrices - bool useLapack = ((rowNum > vpMatrix::m_lapack_min_size) || (colNum > vpMatrix::m_lapack_min_size)); -#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) - useLapack = false; -#endif - - if (useLapack) { -#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) - const double alpha = 1.0; - const double beta = 0.0; - const char transa = 't'; - const char transb = 'n'; - - vpMatrix::blas_dgemm(transa, transb, rowNum, rowNum, colNum, alpha, data, colNum, data, colNum, beta, B.data, - rowNum); -#endif - } - else { - // compute A*A^T - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = i; j < rowNum; ++j) { - double *pi = rowPtrs[i]; // row i - double *pj = rowPtrs[j]; // row j - - // sum (row i .* row j) - double ssum = 0; - for (unsigned int k = 0; k < colNum; ++k) { - ssum += *(pi++) * *(pj++); - } - - B[i][j] = ssum; // upper triangle - if (i != j) { - B[j][i] = ssum; // lower triangle - } - } - } - } -} - -/*! - Compute the AtA operation such as \f$B = A^T*A\f$. - - The result is placed in the parameter \e B and not returned. - - A new matrix won't be allocated for every use of the function. This - results in a speed gain if used many times with the same result matrix - size. - - \sa AtA() -*/ -void vpMatrix::AtA(vpMatrix &B) const -{ - if ((B.rowNum != colNum) || (B.colNum != colNum)) { - B.resize(colNum, colNum, false, false); - } - - // If available use Lapack only for large matrices - bool useLapack = ((rowNum > vpMatrix::m_lapack_min_size) || (colNum > vpMatrix::m_lapack_min_size)); -#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) - useLapack = false; -#endif - - if (useLapack) { -#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) - const double alpha = 1.0; - const double beta = 0.0; - const char transa = 'n'; - const char transb = 't'; - - vpMatrix::blas_dgemm(transa, transb, colNum, colNum, rowNum, alpha, data, colNum, data, colNum, beta, B.data, - colNum); -#endif - } - else { - for (unsigned int i = 0; i < colNum; ++i) { - double *Bi = B[i]; - for (unsigned int j = 0; j < i; ++j) { - double *ptr = data; - double s = 0; - for (unsigned int k = 0; k < rowNum; ++k) { - s += (*(ptr + i)) * (*(ptr + j)); - ptr += colNum; - } - *Bi++ = s; - B[j][i] = s; - } - double *ptr = data; - double s = 0; - for (unsigned int k = 0; k < rowNum; ++k) { - s += (*(ptr + i)) * (*(ptr + i)); - ptr += colNum; - } - *Bi = s; - } - } -} - -/*! - Compute the AtA operation such as \f$B = A^T*A\f$ - \return \f$A^T*A\f$ - \sa AtA(vpMatrix &) const -*/ -vpMatrix vpMatrix::AtA() const -{ - vpMatrix B; - - AtA(B); - - return B; -} - -/*! - Copy operator that allows to convert on of the following container that - inherit from vpArray2D such as vpMatrix, vpRotationMatrix, - vpHomogeneousMatrix, vpPoseVector, vpColVector, vpRowVector... into a - vpMatrix. - - \param A : 2D array to be copied. - - The following example shows how to create a matrix from an homogeneous - matrix: - \code - vpRotationMatrix R; - vpMatrix M = R; - \endcode - -*/ -vpMatrix &vpMatrix::operator=(const vpArray2D &A) -{ - resize(A.getRows(), A.getCols(), false, false); - - if ((data != nullptr) && (A.data != nullptr) && (data != A.data)) { - memcpy(data, A.data, dsize * sizeof(double)); - } - - return *this; -} - -vpMatrix &vpMatrix::operator=(const vpMatrix &A) -{ - resize(A.getRows(), A.getCols(), false, false); - - if ((data != nullptr) && (A.data != nullptr) && (data != A.data)) { - memcpy(data, A.data, dsize * sizeof(double)); - } - - return *this; -} - -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) -vpMatrix &vpMatrix::operator=(vpMatrix &&other) -{ - if (this != &other) { - if (data) { - free(data); - } - if (rowPtrs) { - free(rowPtrs); - } - - rowNum = other.rowNum; - colNum = other.colNum; - rowPtrs = other.rowPtrs; - dsize = other.dsize; - data = other.data; - - other.rowNum = 0; - other.colNum = 0; - other.rowPtrs = nullptr; - other.dsize = 0; - other.data = nullptr; - } - - return *this; -} - -/*! - Set matrix elements from a list of values. - \param list : List of double. Matrix size (number of columns multiplied by number of columns) should match the number - of elements. - - \return The modified Matrix. The following example shows how to set each element of a 2-by-3 matrix. - - \code - #include - - int main() - { - vpMatrix M; - M = { -1, -2, -3, -4, -5, -6 }; - M.reshape(2, 3); - std::cout << "M:\n" << M << std::endl; - } - \endcode - It produces the following printings: - \code - M: - -1 -2 -3 - -4 -5 -6 - \endcode - \sa operator<<() - */ -vpMatrix &vpMatrix::operator=(const std::initializer_list &list) -{ - if (dsize != static_cast(list.size())) { - resize(1, static_cast(list.size()), false, false); - } - - std::copy(list.begin(), list.end(), data); - - return *this; -} - -/*! - Set matrix elements from a list of values. - \param lists : List of double. - \return The modified Matrix. - The following example shows how to set each element of a 2-by-3 matrix. - \code - #include - - int main() - { - vpMatrix M; - M = { {-1, -2, -3}, {-4, -5, -6} }; - std::cout << "M:\n" << M << std::endl; - } - \endcode - It produces the following printings: - \code - M: - -1 -2 -3 - -4 -5 -6 - \endcode - \sa operator<<() - */ -vpMatrix &vpMatrix::operator=(const std::initializer_list > &lists) -{ - unsigned int nrows = static_cast(lists.size()), ncols = 0; - for (auto &l : lists) { - if (static_cast(l.size()) > ncols) { - ncols = static_cast(l.size()); - } - } - - resize(nrows, ncols, false, false); - auto it = lists.begin(); - for (unsigned int i = 0; i < rowNum; ++i, ++it) { - std::copy(it->begin(), it->end(), rowPtrs[i]); - } - - return *this; -} -#endif - -//! Set all the element of the matrix A to \e x. -vpMatrix &vpMatrix::operator=(double x) -{ - std::fill(data, data + (rowNum * colNum), x); - return *this; -} - -/*! - Assignment from an array of double. This method has to be used carefully - since the array allocated behind \e x pointer should have the same dimension - than the matrix. -*/ -vpMatrix &vpMatrix::operator<<(double *x) -{ - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - rowPtrs[i][j] = *x++; - } - } - return *this; -} - -vpMatrix &vpMatrix::operator<<(double val) -{ - resize(1, 1, false, false); - rowPtrs[0][0] = val; - return *this; -} - -vpMatrix &vpMatrix::operator,(double val) -{ - resize(1, colNum + 1, false, false); - rowPtrs[0][colNum - 1] = val; - return *this; -} - -/*! - Create a diagonal matrix with the element of a vector. - - \param A : Vector which element will be put in the diagonal. - - \sa createDiagonalMatrix() - - \code - #include - - #include - #include - - int main() - { - vpMatrix A; - vpColVector v(3); - - v[0] = 1; - v[1] = 2; - v[2] = 3; - - A.diag(v); - - std::cout << "A:\n" << A << std::endl; - } - \endcode - - Matrix A is now equal to: - \code - 1 0 0 - 0 2 0 - 0 0 3 - \endcode -*/ -void vpMatrix::diag(const vpColVector &A) -{ - unsigned int rows = A.getRows(); - this->resize(rows, rows); - - (*this) = 0; - for (unsigned int i = 0; i < rows; ++i) { - (*this)[i][i] = A[i]; - } -} - -/*! - Set the matrix as a diagonal matrix where each element on the diagonal is - set to \e val. Elements that are not on the diagonal are set to 0. - - \param val : Value to set. - - \sa eye() - - \code - #include - - #include - - int main() - { - vpMatrix A(3, 4); - - A.diag(2); - - std::cout << "A:\n" << A << std::endl; - } - \endcode - - Matrix A is now equal to: - \code - 2 0 0 0 - 0 2 0 0 - 0 0 2 0 - \endcode -*/ -void vpMatrix::diag(const double &val) -{ - (*this) = 0; - unsigned int min_ = (rowNum < colNum) ? rowNum : colNum; - for (unsigned int i = 0; i < min_; ++i) { - (*this)[i][i] = val; - } -} - -/*! - Create a diagonal matrix with the element of a vector \f$ DA_{ii} = A_i \f$. - - \param A : Vector which element will be put in the diagonal. - - \param DA : Diagonal matrix DA[i][i] = A[i] - - \sa diag() -*/ - -void vpMatrix::createDiagonalMatrix(const vpColVector &A, vpMatrix &DA) -{ - unsigned int rows = A.getRows(); - DA.resize(rows, rows, true); - - for (unsigned int i = 0; i < rows; ++i) { - DA[i][i] = A[i]; - } -} - -/*! - Operator that allows to multiply a matrix by a translation vector. - The matrix should be of dimension (3x3) -*/ -vpTranslationVector vpMatrix::operator*(const vpTranslationVector &tv) const -{ - vpTranslationVector t_out; - - if ((rowNum != 3) || (colNum != 3)) { - throw(vpException(vpException::dimensionError, "Cannot multiply a (%dx%d) matrix by a (%dx%d) translation vector", - rowNum, colNum, tv.getRows(), tv.getCols())); - } - - const unsigned int val_3 = 3; - for (unsigned int j = 0; j < val_3; ++j) { - t_out[j] = 0; - } - - for (unsigned int j = 0; j < val_3; ++j) { - double tj = tv[j]; // optimization em 5/12/2006 - for (unsigned int i = 0; i < val_3; ++i) { - t_out[i] += rowPtrs[i][j] * tj; - } - } - return t_out; -} - -/*! - Operation w = A * v (matrix A is unchanged, v and w are column vectors). - \sa multMatrixVector() to avoid matrix allocation for each use. -*/ -vpColVector vpMatrix::operator*(const vpColVector &v) const -{ - vpColVector v_out; - vpMatrix::multMatrixVector(*this, v, v_out); - return v_out; -} - -/*! - Operation w = A * v (v and w are vectors). - - A new matrix won't be allocated for every use of the function - (Speed gain if used many times with the same result matrix size). - - \sa operator*(const vpColVector &v) const -*/ -void vpMatrix::multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w) -{ - if (A.colNum != v.getRows()) { - throw(vpException(vpException::dimensionError, "Cannot multiply a (%dx%d) matrix by a (%d) column vector", - A.getRows(), A.getCols(), v.getRows())); - } - - if (A.rowNum != w.rowNum) { - w.resize(A.rowNum, false); - } - - // If available use Lapack only for large matrices - bool useLapack = ((A.rowNum > vpMatrix::m_lapack_min_size) || (A.colNum > vpMatrix::m_lapack_min_size)); -#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) - useLapack = false; -#endif - - if (useLapack) { -#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) - double alpha = 1.0; - double beta = 0.0; - char trans = 't'; - int incr = 1; - - vpMatrix::blas_dgemv(trans, A.colNum, A.rowNum, alpha, A.data, A.colNum, v.data, incr, beta, w.data, incr); -#endif - } - else { - w = 0.0; - for (unsigned int j = 0; j < A.colNum; ++j) { - double vj = v[j]; // optimization em 5/12/2006 - for (unsigned int i = 0; i < A.rowNum; ++i) { - w[i] += A.rowPtrs[i][j] * vj; - } - } - } -} - -//--------------------------------- -// Matrix operations. -//--------------------------------- - -/*! - Operation C = A * B. - - The result is placed in the third parameter C and not returned. - A new matrix won't be allocated for every use of the function - (speed gain if used many times with the same result matrix size). - - \sa operator*() -*/ -void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) -{ - if ((A.rowNum != C.rowNum) || (B.colNum != C.colNum)) { - C.resize(A.rowNum, B.colNum, false, false); - } - - if (A.colNum != B.rowNum) { - throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (%dx%d) matrix", A.getRows(), - A.getCols(), B.getRows(), B.getCols())); - } - - // If available use Lapack only for large matrices - bool useLapack = ((A.rowNum > vpMatrix::m_lapack_min_size) || (A.colNum > vpMatrix::m_lapack_min_size) || - (B.colNum > vpMatrix::m_lapack_min_size)); -#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) - useLapack = false; -#endif - - if (useLapack) { -#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) - const double alpha = 1.0; - const double beta = 0.0; - const char trans = 'n'; - vpMatrix::blas_dgemm(trans, trans, B.colNum, A.rowNum, A.colNum, alpha, B.data, B.colNum, A.data, A.colNum, beta, - C.data, B.colNum); -#endif - } - else { - // 5/12/06 some "very" simple optimization to avoid indexation - const unsigned int BcolNum = B.colNum; - const unsigned int BrowNum = B.rowNum; - double **BrowPtrs = B.rowPtrs; - for (unsigned int i = 0; i < A.rowNum; ++i) { - const double *rowptri = A.rowPtrs[i]; - double *ci = C[i]; - for (unsigned int j = 0; j < BcolNum; ++j) { - double s = 0; - for (unsigned int k = 0; k < BrowNum; ++k) { - s += rowptri[k] * BrowPtrs[k][j]; - } - ci[j] = s; - } - } - } -} - -/*! - \warning This function is provided for compat with previous releases. You - should rather use the functionalities provided in vpRotationMatrix class. - - Operation C = A * B. - - The result is placed in the third parameter C and not returned. - A new matrix won't be allocated for every use of the function - (speed gain if used many times with the same result matrix size). - - \exception vpException::dimensionError If matrices are not 3-by-3 dimension. -*/ -void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C) -{ - if ((A.colNum != 3) || (A.rowNum != 3) || (B.colNum != 3) || (B.rowNum != 3)) { - throw(vpException(vpException::dimensionError, - "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a " - "rotation matrix", - A.getRows(), A.getCols(), B.getRows(), B.getCols())); - } - // 5/12/06 some "very" simple optimization to avoid indexation - const unsigned int BcolNum = B.colNum; - const unsigned int BrowNum = B.rowNum; - double **BrowPtrs = B.rowPtrs; - for (unsigned int i = 0; i < A.rowNum; ++i) { - const double *rowptri = A.rowPtrs[i]; - double *ci = C[i]; - for (unsigned int j = 0; j < BcolNum; ++j) { - double s = 0; - for (unsigned int k = 0; k < BrowNum; ++k) { - s += rowptri[k] * BrowPtrs[k][j]; - } - ci[j] = s; - } - } -} - -/*! - \warning This function is provided for compat with previous releases. You - should rather use the functionalities provided in vpHomogeneousMatrix class. - - Operation C = A * B. - - The result is placed in the third parameter C and not returned. - A new matrix won't be allocated for every use of the function - (speed gain if used many times with the same result matrix size). - - \exception vpException::dimensionError If matrices are not 4-by-4 dimension. -*/ -void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C) -{ - if ((A.colNum != 4) || (A.rowNum != 4) || (B.colNum != 4) || (B.rowNum != 4)) { - throw(vpException(vpException::dimensionError, - "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a " - "rotation matrix", - A.getRows(), A.getCols(), B.getRows(), B.getCols())); - } - // Considering perfMatrixMultiplication.cpp benchmark, - // using either MKL, OpenBLAS, or Netlib can slow down this function with respect to the naive code. - // Lapack usage needs to be validated again. - // If available use Lapack only for large matrices. - // Using SSE2 doesn't speed up. - bool useLapack = ((A.rowNum > vpMatrix::m_lapack_min_size) || (A.colNum > vpMatrix::m_lapack_min_size) || - (B.colNum > vpMatrix::m_lapack_min_size)); -#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) - useLapack = false; -#endif - - if (useLapack) { -#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) - const double alpha = 1.0; - const double beta = 0.0; - const char trans = 'n'; - vpMatrix::blas_dgemm(trans, trans, B.colNum, A.rowNum, A.colNum, alpha, B.data, B.colNum, A.data, A.colNum, beta, - C.data, B.colNum); -#endif - } - else { - // 5/12/06 some "very" simple optimization to avoid indexation - const unsigned int BcolNum = B.colNum; - const unsigned int BrowNum = B.rowNum; - double **BrowPtrs = B.rowPtrs; - for (unsigned int i = 0; i < A.rowNum; ++i) { - const double *rowptri = A.rowPtrs[i]; - double *ci = C[i]; - for (unsigned int j = 0; j < BcolNum; ++j) { - double s = 0; - for (unsigned int k = 0; k < BrowNum; ++k) { - s += rowptri[k] * BrowPtrs[k][j]; - } - ci[j] = s; - } - } - } -} - -/*! - \warning This function is provided for compat with previous releases. You - should rather use multMatrixVector() that is more explicit. - - Operation C = A * B. - - The result is placed in the third parameter C and not returned. - A new matrix won't be allocated for every use of the function - (speed gain if used many times with the same result matrix size). - - \sa multMatrixVector() -*/ -void vpMatrix::mult2Matrices(const vpMatrix &A, const vpColVector &B, vpColVector &C) -{ - vpMatrix::multMatrixVector(A, B, C); -} - -/*! - Operation C = A * B (A is unchanged). - \sa mult2Matrices() to avoid matrix allocation for each use. -*/ -vpMatrix vpMatrix::operator*(const vpMatrix &B) const -{ - vpMatrix C; - - vpMatrix::mult2Matrices(*this, B, C); - - return C; -} - -/*! - Operator that allow to multiply a matrix by a rotation matrix. - The matrix should be of dimension m-by-3. -*/ -vpMatrix vpMatrix::operator*(const vpRotationMatrix &R) const -{ - if (colNum != R.getRows()) { - throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (3x3) rotation matrix", rowNum, - colNum)); - } - vpMatrix C; - C.resize(rowNum, 3, false, false); - - unsigned int RcolNum = R.getCols(); - unsigned int RrowNum = R.getRows(); - for (unsigned int i = 0; i < rowNum; ++i) { - double *rowptri = rowPtrs[i]; - double *ci = C[i]; - for (unsigned int j = 0; j < RcolNum; ++j) { - double s = 0; - for (unsigned int k = 0; k < RrowNum; ++k) { - s += rowptri[k] * R[k][j]; - } - ci[j] = s; - } - } - - return C; -} - -/*! - Operator that allow to multiply a matrix by a homogeneous matrix. - The matrix should be of dimension m-by-4. -*/ -vpMatrix vpMatrix::operator*(const vpHomogeneousMatrix &M) const -{ - if (colNum != M.getRows()) { - throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (3x3) rotation matrix", rowNum, - colNum)); - } - vpMatrix C; - C.resize(rowNum, 4, false, false); - - const unsigned int McolNum = M.getCols(); - const unsigned int MrowNum = M.getRows(); - for (unsigned int i = 0; i < rowNum; ++i) { - const double *rowptri = rowPtrs[i]; - double *ci = C[i]; - for (unsigned int j = 0; j < McolNum; ++j) { - double s = 0; - for (unsigned int k = 0; k < MrowNum; ++k) { - s += rowptri[k] * M[k][j]; - } - ci[j] = s; - } - } - - return C; -} - -/*! - Operator that allow to multiply a matrix by a velocity twist matrix. - The matrix should be of dimension m-by-6. -*/ -vpMatrix vpMatrix::operator*(const vpVelocityTwistMatrix &V) const -{ - if (colNum != V.getRows()) { - throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (6x6) velocity twist matrix", - rowNum, colNum)); - } - vpMatrix M; - M.resize(rowNum, 6, false, false); - - // Considering perfMatrixMultiplication.cpp benchmark, - // using either MKL, OpenBLAS, or Netlib can slow down this function with respect to the naive code. - // Lapack usage needs to be validated again. - // If available use Lapack only for large matrices. - // Speed up obtained using SSE2. - bool useLapack = ((rowNum > vpMatrix::m_lapack_min_size) || (colNum > vpMatrix::m_lapack_min_size) || - (V.colNum > vpMatrix::m_lapack_min_size)); -#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) - useLapack = false; -#endif - - if (useLapack) { -#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) - const double alpha = 1.0; - const double beta = 0.0; - const char trans = 'n'; - vpMatrix::blas_dgemm(trans, trans, V.colNum, rowNum, colNum, alpha, V.data, V.colNum, data, colNum, beta, M.data, - M.colNum); -#endif - } - else { -#if defined(VISP_HAVE_SIMDLIB) - SimdMatMulTwist(data, rowNum, V.data, M.data); -#else - unsigned int VcolNum = V.getCols(); - unsigned int VrowNum = V.getRows(); - for (unsigned int i = 0; i < rowNum; ++i) { - double *rowptri = rowPtrs[i]; - double *ci = M[i]; - for (unsigned int j = 0; j < VcolNum; ++j) { - double s = 0; - for (unsigned int k = 0; k < VrowNum; ++k) { - s += rowptri[k] * V[k][j]; - } - ci[j] = s; - } - } -#endif - } - - return M; -} - -/*! - Operator that allow to multiply a matrix by a force/torque twist matrix. - The matrix should be of dimension m-by-6. -*/ -vpMatrix vpMatrix::operator*(const vpForceTwistMatrix &V) const -{ - if (colNum != V.getRows()) { - throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (6x6) force/torque twist matrix", - rowNum, colNum)); - } - vpMatrix M; - M.resize(rowNum, 6, false, false); - - // Considering perfMatrixMultiplication.cpp benchmark, - // using either MKL, OpenBLAS, or Netlib can slow down this function with respect to the naive code. - // Lapack usage needs to be validated again. - // If available use Lapack only for large matrices. - // Speed up obtained using SSE2. - bool useLapack = ((rowNum > vpMatrix::m_lapack_min_size) || (colNum > vpMatrix::m_lapack_min_size) || - (V.getCols() > vpMatrix::m_lapack_min_size)); -#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) - useLapack = false; -#endif - - if (useLapack) { -#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) - const double alpha = 1.0; - const double beta = 0.0; - const char trans = 'n'; - vpMatrix::blas_dgemm(trans, trans, V.getCols(), rowNum, colNum, alpha, V.data, V.getCols(), data, colNum, beta, - M.data, M.colNum); -#endif - } - else { -#if defined(VISP_HAVE_SIMDLIB) - SimdMatMulTwist(data, rowNum, V.data, M.data); -#else - unsigned int VcolNum = V.getCols(); - unsigned int VrowNum = V.getRows(); - for (unsigned int i = 0; i < rowNum; ++i) { - double *rowptri = rowPtrs[i]; - double *ci = M[i]; - for (unsigned int j = 0; j < VcolNum; ++j) { - double s = 0; - for (unsigned int k = 0; k < VrowNum; ++k) { - s += rowptri[k] * V[k][j]; - } - ci[j] = s; - } - } -#endif - } - - return M; -} - -/*! - Operation C = A*wA + B*wB - - The result is placed in the third parameter C and not returned. - A new matrix won't be allocated for every use of the function - (Speed gain if used many times with the same result matrix size). - - \sa operator+() -*/ - -void vpMatrix::add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB, - vpMatrix &C) -{ - if ((A.rowNum != C.rowNum) || (B.colNum != C.colNum)) { - C.resize(A.rowNum, B.colNum, false, false); - } - - if ((A.colNum != B.getCols()) || (A.rowNum != B.getRows())) { - throw(vpException(vpException::dimensionError, "Cannot add (%dx%d) matrix with (%dx%d) matrix", A.getRows(), - A.getCols(), B.getRows(), B.getCols())); - } - - double **ArowPtrs = A.rowPtrs; - double **BrowPtrs = B.rowPtrs; - double **CrowPtrs = C.rowPtrs; - - for (unsigned int i = 0; i < A.rowNum; ++i) { - for (unsigned int j = 0; j < A.colNum; ++j) { - CrowPtrs[i][j] = (wB * BrowPtrs[i][j]) + (wA * ArowPtrs[i][j]); - } - } -} - -/*! - Operation C = A + B. - - The result is placed in the third parameter C and not returned. - A new matrix won't be allocated for every use of the function - (speed gain if used many times with the same result matrix size). - - \sa operator+() -*/ -void vpMatrix::add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) -{ - if ((A.rowNum != C.rowNum) || (B.colNum != C.colNum)) { - C.resize(A.rowNum, B.colNum, false, false); - } - - if ((A.colNum != B.getCols()) || (A.rowNum != B.getRows())) { - throw(vpException(vpException::dimensionError, "Cannot add (%dx%d) matrix with (%dx%d) matrix", A.getRows(), - A.getCols(), B.getRows(), B.getCols())); - } - - double **ArowPtrs = A.rowPtrs; - double **BrowPtrs = B.rowPtrs; - double **CrowPtrs = C.rowPtrs; - - for (unsigned int i = 0; i < A.rowNum; ++i) { - for (unsigned int j = 0; j < A.colNum; ++j) { - CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j]; - } - } -} - -/*! - \warning This function is provided for compat with previous releases. You - should rather use the functionalities provided in vpColVector class. - - Operation C = A + B. - - The result is placed in the third parameter C and not returned. - A new vector won't be allocated for every use of the function - (speed gain if used many times with the same result matrix size). - - \sa vpColVector::operator+() -*/ -void vpMatrix::add2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C) -{ - if ((A.rowNum != C.rowNum) || (B.colNum != C.colNum)) { - C.resize(A.rowNum); - } - - if ((A.colNum != B.getCols()) || (A.rowNum != B.getRows())) { - throw(vpException(vpException::dimensionError, "Cannot add (%dx%d) matrix with (%dx%d) matrix", A.getRows(), - A.getCols(), B.getRows(), B.getCols())); - } - - double **ArowPtrs = A.rowPtrs; - double **BrowPtrs = B.rowPtrs; - double **CrowPtrs = C.rowPtrs; - - for (unsigned int i = 0; i < A.rowNum; ++i) { - for (unsigned int j = 0; j < A.colNum; ++j) { - CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j]; - } - } -} - -/*! - Operation C = A + B (A is unchanged). - \sa add2Matrices() to avoid matrix allocation for each use. -*/ -vpMatrix vpMatrix::operator+(const vpMatrix &B) const -{ - vpMatrix C; - vpMatrix::add2Matrices(*this, B, C); - return C; -} - -/*! - \warning This function is provided for compat with previous releases. You - should rather use the functionalities provided in vpColVector class. - - Operation C = A - B on column vectors. - - The result is placed in the third parameter C and not returned. - A new vector won't be allocated for every use of the function - (speed gain if used many times with the same result matrix size). - - \exception vpException::dimensionError If A and B vectors have not the same - size. - - \sa vpColVector::operator-() -*/ -void vpMatrix::sub2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C) -{ - if ((A.rowNum != C.rowNum) || (A.colNum != C.colNum)) { - C.resize(A.rowNum); - } - - if ((A.colNum != B.getCols()) || (A.rowNum != B.getRows())) { - throw(vpException(vpException::dimensionError, "Cannot subtract (%dx%d) matrix to (%dx%d) matrix", A.getRows(), - A.getCols(), B.getRows(), B.getCols())); - } - - double **ArowPtrs = A.rowPtrs; - double **BrowPtrs = B.rowPtrs; - double **CrowPtrs = C.rowPtrs; - - for (unsigned int i = 0; i < A.rowNum; ++i) { - for (unsigned int j = 0; j < A.colNum; ++j) { - CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j]; - } - } -} - -/*! - Operation C = A - B. - - The result is placed in the third parameter C and not returned. - A new matrix won't be allocated for every use of the function - (speed gain if used many times with the same result matrix size). - - \exception vpException::dimensionError If A and B matrices have not the same - size. - - \sa operator-() -*/ -void vpMatrix::sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) -{ - if ((A.rowNum != C.rowNum) || (A.colNum != C.colNum)) { - C.resize(A.rowNum, A.colNum, false, false); - } - - if ((A.colNum != B.getCols()) || (A.rowNum != B.getRows())) { - throw(vpException(vpException::dimensionError, "Cannot subtract (%dx%d) matrix to (%dx%d) matrix", A.getRows(), - A.getCols(), B.getRows(), B.getCols())); - } - - double **ArowPtrs = A.rowPtrs; - double **BrowPtrs = B.rowPtrs; - double **CrowPtrs = C.rowPtrs; - - for (unsigned int i = 0; i < A.rowNum; ++i) { - for (unsigned int j = 0; j < A.colNum; ++j) { - CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j]; - } - } -} - -/*! - Operation C = A - B (A is unchanged). - \sa sub2Matrices() to avoid matrix allocation for each use. -*/ -vpMatrix vpMatrix::operator-(const vpMatrix &B) const -{ - vpMatrix C; - vpMatrix::sub2Matrices(*this, B, C); - return C; -} - -//! Operation A = A + B - -vpMatrix &vpMatrix::operator+=(const vpMatrix &B) -{ - if ((colNum != B.getCols()) || (rowNum != B.getRows())) { - throw(vpException(vpException::dimensionError, "Cannot add (%dx%d) matrix to (%dx%d) matrix", rowNum, colNum, - B.getRows(), B.getCols())); - } - - double **BrowPtrs = B.rowPtrs; - - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - rowPtrs[i][j] += BrowPtrs[i][j]; - } - } - - return *this; -} - -//! Operation A = A - B -vpMatrix &vpMatrix::operator-=(const vpMatrix &B) -{ - if ((colNum != B.getCols()) || (rowNum != B.getRows())) { - throw(vpException(vpException::dimensionError, "Cannot subtract (%dx%d) matrix to (%dx%d) matrix", rowNum, colNum, - B.getRows(), B.getCols())); - } - - double **BrowPtrs = B.rowPtrs; - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - rowPtrs[i][j] -= BrowPtrs[i][j]; - } - } - - return *this; -} - -/*! - Operation C = -A. - - The result is placed in the second parameter C and not returned. - A new matrix won't be allocated for every use of the function - (Speed gain if used many times with the same result matrix size). - - \sa operator-(void) -*/ -void vpMatrix::negateMatrix(const vpMatrix &A, vpMatrix &C) -{ - if ((A.rowNum != C.rowNum) || (A.colNum != C.colNum)) { - C.resize(A.rowNum, A.colNum, false, false); - } - - double **ArowPtrs = A.rowPtrs; - double **CrowPtrs = C.rowPtrs; - - for (unsigned int i = 0; i < A.rowNum; ++i) { - for (unsigned int j = 0; j < A.colNum; ++j) { - CrowPtrs[i][j] = -ArowPtrs[i][j]; - } - } -} - -/*! - Operation C = -A (A is unchanged). - \sa negateMatrix() to avoid matrix allocation for each use. -*/ -vpMatrix vpMatrix::operator-() const // negate -{ - vpMatrix C; - vpMatrix::negateMatrix(*this, C); - return C; -} - -double vpMatrix::sum() const -{ - double s = 0.0; - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - s += rowPtrs[i][j]; - } - } - - return s; -} - -//--------------------------------- -// Matrix/vector operations. -//--------------------------------- - -//--------------------------------- -// Matrix/real operations. -//--------------------------------- - -/*! - Operator that allows to multiply all the elements of a matrix - by a scalar. - */ -vpMatrix vpMatrix::operator*(double x) const -{ - if (std::fabs(x - 1.) < std::numeric_limits::epsilon()) { - return *this; - } - - vpMatrix M; - M.resize(rowNum, colNum, false, false); - - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - M[i][j] = rowPtrs[i][j] * x; - } - } - - return M; -} - -//! Cij = Aij / x (A is unchanged) -vpMatrix vpMatrix::operator/(double x) const -{ - if (std::fabs(x - 1.) < std::numeric_limits::epsilon()) { - return *this; - } - - if (std::fabs(x) < std::numeric_limits::epsilon()) { - throw vpException(vpException::divideByZeroError, "Divide matrix by zero scalar"); - } - - vpMatrix C; - C.resize(rowNum, colNum, false, false); - - double xinv = 1 / x; - - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - C[i][j] = rowPtrs[i][j] * xinv; - } - } - - return C; -} - -//! Add x to all the element of the matrix : Aij = Aij + x -vpMatrix &vpMatrix::operator+=(double x) -{ - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - rowPtrs[i][j] += x; - } - } - - return *this; -} - -//! subtract x to all the element of the matrix : Aij = Aij - x -vpMatrix &vpMatrix::operator-=(double x) -{ - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - rowPtrs[i][j] -= x; - } - } - - return *this; -} - -/*! - Operator that allows to multiply all the elements of a matrix - by a scalar. - */ -vpMatrix &vpMatrix::operator*=(double x) -{ - if (std::fabs(x - 1.) < std::numeric_limits::epsilon()) { - return *this; - } - - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - rowPtrs[i][j] *= x; - } - } - - return *this; -} - -//! Divide all the element of the matrix by x : Aij = Aij / x -vpMatrix &vpMatrix::operator/=(double x) -{ - if (std::fabs(x - 1.) < std::numeric_limits::epsilon()) { - return *this; - } - - if (std::fabs(x) < std::numeric_limits::epsilon()) { - throw vpException(vpException::divideByZeroError, "Divide matrix by zero scalar"); - } - - double xinv = 1 / x; - - for (unsigned int i = 0; i < rowNum; ++i) { - for (unsigned int j = 0; j < colNum; ++j) { - rowPtrs[i][j] *= xinv; - } - } - - return *this; -} - -//---------------------------------------------------------------- -// Matrix Operation -//---------------------------------------------------------------- - -/*! - Stacks columns of a matrix in a vector. - \param out : a vpColVector. -*/ -void vpMatrix::stackColumns(vpColVector &out) -{ - if ((out.rowNum != (colNum * rowNum)) || (out.colNum != 1)) { - out.resize(colNum * rowNum, false, false); - } - - double *optr = out.data; - for (unsigned int j = 0; j < colNum; ++j) { - for (unsigned int i = 0; i < rowNum; ++i) { - *(optr++) = rowPtrs[i][j]; - } - } -} - -/*! - Stacks columns of a matrix in a vector. - \return a vpColVector. -*/ -vpColVector vpMatrix::stackColumns() -{ - vpColVector out(colNum * rowNum); - stackColumns(out); - return out; -} - -/*! - Stacks rows of a matrix in a vector - \param out : a vpRowVector. -*/ -void vpMatrix::stackRows(vpRowVector &out) -{ - if ((out.getRows() != 1) || (out.getCols() != (colNum * rowNum))) { - out.resize(colNum * rowNum, false, false); - } - - memcpy(out.data, data, sizeof(double) * out.getCols()); -} -/*! - Stacks rows of a matrix in a vector. - \return a vpRowVector. -*/ -vpRowVector vpMatrix::stackRows() -{ - vpRowVector out(colNum * rowNum); - stackRows(out); - return out; -} - -/*! - Compute the Hadamard product (element wise matrix multiplication). - \param m : Second matrix; - \return m1.hadamard(m2) The Hadamard product : - \f$ m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j} \f$ -*/ -vpMatrix vpMatrix::hadamard(const vpMatrix &m) const -{ - if ((m.getRows() != rowNum) || (m.getCols() != colNum)) { - throw(vpException(vpException::dimensionError, "In Hadamard product: bad dimension of input matrix")); - } - - vpMatrix out; - out.resize(rowNum, colNum, false, false); - -#if defined(VISP_HAVE_SIMDLIB) - SimdVectorHadamard(data, m.data, dsize, out.data); -#else - for (unsigned int i = 0; i < dsize; ++i) { - out.data[i] = data[i] * m.data[i]; - } -#endif - - return out; -} - -/*! - Compute Kronecker product matrix. - \param m1 : vpMatrix; - \param m2 : vpMatrix; - \param out : The kronecker product : \f$ m1 \otimes m2 \f$ -*/ -void vpMatrix::kron(const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out) -{ - unsigned int r1 = m1.getRows(); - unsigned int c1 = m1.getCols(); - unsigned int r2 = m2.getRows(); - unsigned int c2 = m2.getCols(); - - out.resize(r1 * r2, c1 * c2, false, false); - - for (unsigned int r = 0; r < r1; ++r) { - for (unsigned int c = 0; c < c1; ++c) { - double alpha = m1[r][c]; - double *m2ptr = m2[0]; - unsigned int roffset = r * r2; - unsigned int coffset = c * c2; - for (unsigned int rr = 0; rr < r2; ++rr) { - for (unsigned int cc = 0; cc < c2; ++cc) { - out[roffset + rr][coffset + cc] = alpha * *(m2ptr++); - } - } - } - } -} - -/*! - Compute Kronecker product matrix. - \param m : vpMatrix. - \param out : If m1.kron(m2) out contains the kronecker product's result : - \f$ m1 \otimes m2 \f$. -*/ -void vpMatrix::kron(const vpMatrix &m, vpMatrix &out) const { kron(*this, m, out); } - -/*! - Compute Kronecker product matrix. - \param m1 : vpMatrix; - \param m2 : vpMatrix; - \return The kronecker product : \f$ m1 \otimes m2 \f$ -*/ -vpMatrix vpMatrix::kron(const vpMatrix &m1, const vpMatrix &m2) -{ - unsigned int r1 = m1.getRows(); - unsigned int c1 = m1.getCols(); - unsigned int r2 = m2.getRows(); - unsigned int c2 = m2.getCols(); - - vpMatrix out; - out.resize(r1 * r2, c1 * c2, false, false); - - for (unsigned int r = 0; r < r1; ++r) { - for (unsigned int c = 0; c < c1; ++c) { - double alpha = m1[r][c]; - double *m2ptr = m2[0]; - unsigned int roffset = r * r2; - unsigned int coffset = c * c2; - for (unsigned int rr = 0; rr < r2; ++rr) { - for (unsigned int cc = 0; cc < c2; ++cc) { - out[roffset + rr][coffset + cc] = alpha * *(m2ptr++); - } - } - } - } - return out; -} - -/*! - Compute Kronecker product matrix. - \param m : vpMatrix; - \return m1.kron(m2) The kronecker product : \f$ m1 \otimes m2 \f$ -*/ -vpMatrix vpMatrix::kron(const vpMatrix &m) const { return kron(*this, m); } - -/*! - - Solve a linear system \f$ A X = B \f$ using Singular Value - Decomposition (SVD). - - Non destructive wrt. A and B. - - \param b : Vector\f$ B \f$. - - \param x : Vector \f$ X \f$. - - Here an example: - \code - #include - #include - - int main() - { - vpMatrix A(3,3); - - A[0][0] = 4.64; - A[0][1] = 0.288; - A[0][2] = -0.384; - - A[1][0] = 0.288; - A[1][1] = 7.3296; - A[1][2] = 2.2272; - - A[2][0] = -0.384; - A[2][1] = 2.2272; - A[2][2] = 6.0304; - - vpColVector X(3), B(3); - B[0] = 1; - B[1] = 2; - B[2] = 3; - - A.solveBySVD(B, X); - - // Obtained values of X - // X[0] = 0.2468; - // X[1] = 0.120782; - // X[2] = 0.468587; - - std::cout << "X:\n" << X << std::endl; - } - \endcode - - \sa solveBySVD(const vpColVector &) -*/ -void vpMatrix::solveBySVD(const vpColVector &b, vpColVector &x) const { x = pseudoInverse(1e-6) * b; } - -/*! - - Solve a linear system \f$ A X = B \f$ using Singular Value - Decomposition (SVD). - - Non destructive wrt. A and B. - - \param B : Vector\f$ B \f$. - - \return Vector \f$ X \f$. - - Here an example: - \code - #include - #include - - int main() - { - vpMatrix A(3,3); - - A[0][0] = 4.64; - A[0][1] = 0.288; - A[0][2] = -0.384; - - A[1][0] = 0.288; - A[1][1] = 7.3296; - A[1][2] = 2.2272; - - A[2][0] = -0.384; - A[2][1] = 2.2272; - A[2][2] = 6.0304; - - vpColVector X(3), B(3); - B[0] = 1; - B[1] = 2; - B[2] = 3; - - X = A.solveBySVD(B); - // Obtained values of X - // X[0] = 0.2468; - // X[1] = 0.120782; - // X[2] = 0.468587; - - std::cout << "X:\n" << X << std::endl; - } - \endcode - - \sa solveBySVD(const vpColVector &, vpColVector &) -*/ -vpColVector vpMatrix::solveBySVD(const vpColVector &B) const -{ - vpColVector X(colNum); - - solveBySVD(B, X); - return X; -} - -/*! - - Matrix singular value decomposition (SVD). - - This function calls the first following function that is available: - - svdLapack() if Lapack 3rd party is installed - - svdEigen3() if Eigen3 3rd party is installed - - svdOpenCV() if OpenCV 3rd party is installed. - - If none of these previous 3rd parties is installed, we use by default - svdLapack() with a Lapack built-in version. - - Given matrix \f$M\f$, this function computes it singular value decomposition - such as - - \f[ M = U \Sigma V^{\top} \f] - - \warning This method is destructive wrt. to the matrix \f$ M \f$ to - decompose. You should make a COPY of that matrix if needed. - - \param w : Vector of singular values: \f$ \Sigma = diag(w) \f$. - - \param V : Matrix \f$ V \f$. - - The matrix object `(*this) is updated with \f$ U \f$. - - \note The singular values are ordered in decreasing - fashion in \e w. It means that the highest singular value is in \e w[0]. - - Here an example of SVD decomposition of a non square Matrix M. - - \code - #include - - int main() - { - vpMatrix M(3,2); - M[0][0] = 1; M[0][1] = 6; - M[1][0] = 2; M[1][1] = 8; - M[2][0] = 0.5; M[2][1] = 9; - - vpColVector w; - vpMatrix V, Sigma, U = M; - - U.svd(w, V); - - // Construct the diagonal matrix from the singular values - Sigma.diag(w); - - // Reconstruct the initial matrix using the decomposition - vpMatrix Mrec = U * Sigma * V.t(); - - // Here, Mrec is obtained equal to the initial value of M - // Mrec[0][0] = 1; Mrec[0][1] = 6; - // Mrec[1][0] = 2; Mrec[1][1] = 8; - // Mrec[2][0] = 0.5; Mrec[2][1] = 9; - - std::cout << "Reconstructed M matrix: \n" << Mrec << std::endl; - } - \endcode - - \sa svdLapack(), svdEigen3(), svdOpenCV() -*/ -void vpMatrix::svd(vpColVector &w, vpMatrix &V) -{ -#if defined(VISP_HAVE_LAPACK) - svdLapack(w, V); -#elif defined(VISP_HAVE_EIGEN3) - svdEigen3(w, V); -#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 - svdOpenCV(w, V); -#else - (void)w; - (void)V; - throw(vpException(vpException::fatalError, "Cannot compute SVD. Install Lapack, Eigen3 or OpenCV 3rd party")); -#endif -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ and return the rank of the matrix. - - \note By default, this function uses Lapack 3rd party. It is also possible - to use a specific 3rd party suffixing this function name with one of the - following 3rd party names (Lapack, Eigen3 or OpenCV). - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The rank of the matrix. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - unsigned int rank = A.pseudoInverse(A_p); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank: " << rank << std::endl; - } - \endcode - - Once build, the previous example produces the following output: - \code - A: [2,3]= - 2 3 5 - -4 2 3 - A^+ (pseudo-inverse): [3,2]= - 0.117899 -0.190782 - 0.065380 0.039657 - 0.113612 0.052518 - Rank: 2 - \endcode -*/ -unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, double svThreshold) const -{ -#if defined(VISP_HAVE_LAPACK) - return pseudoInverseLapack(Ap, svThreshold); -#elif defined(VISP_HAVE_EIGEN3) - return pseudoInverseEigen3(Ap, svThreshold); -#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 - return pseudoInverseOpenCV(Ap, svThreshold); -#else - (void)Ap; - (void)svThreshold; - throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " - "Install Lapack, Eigen3 or OpenCV 3rd party")); -#endif -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ and return the rank of the matrix. - - \note By default, this function uses Lapack 3rd party. It is also possible - to use a specific 3rd party suffixing this function name with one of the - following 3rd party names (Lapack, Eigen3 or OpenCV). - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param[in] rank_in : Known rank of the matrix. - - \return The rank of the matrix. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - // This matrix rank is 2 - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - int rank_in = 2; - int rank_out = A.pseudoInverse(A_p, rank_in); - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - } - \endcode - - Once build, the previous example produces the following output: - \code - A: [2,3]= - 2 3 5 - -4 2 3 - A^+ (pseudo-inverse): [3,2]= - 0.117899 -0.190782 - 0.065380 0.039657 - 0.113612 0.052518 - Rank in : 2 - Rank out: 2 - \endcode -*/ -int vpMatrix::pseudoInverse(vpMatrix &Ap, int rank_in) const -{ -#if defined(VISP_HAVE_LAPACK) - return pseudoInverseLapack(Ap, rank_in); -#elif defined(VISP_HAVE_EIGEN3) - return pseudoInverseEigen3(Ap, rank_in); -#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 - return pseudoInverseOpenCV(Ap, rank_in); -#else - (void)Ap; - (void)rank_in; - throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " - "Install Lapack, Eigen3 or OpenCV 3rd party")); -#endif -} - -/*! - Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n - matrix \f$\bf A\f$. - - \note By default, this function uses Lapack 3rd party. It is also possible - to use a specific 3rd party suffixing this function name with one of the - following 3rd party names (Lapack, Eigen3 or OpenCV). - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The Moore-Penros pseudo inverse \f$ A^+ \f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p = A.pseudoInverse(); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - } - \endcode - - Once build, the previous example produces the following output: - \code - A: [2,3]= - 2 3 5 - -4 2 3 - A^+ (pseudo-inverse): [3,2]= - 0.117899 -0.190782 - 0.065380 0.039657 - 0.113612 0.052518 - \endcode - -*/ -vpMatrix vpMatrix::pseudoInverse(double svThreshold) const -{ -#if defined(VISP_HAVE_LAPACK) - return pseudoInverseLapack(svThreshold); -#elif defined(VISP_HAVE_EIGEN3) - return pseudoInverseEigen3(svThreshold); -#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 - return pseudoInverseOpenCV(svThreshold); -#else - (void)svThreshold; - throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " - "Install Lapack, Eigen3 or OpenCV 3rd party")); -#endif -} - -/*! - Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n - matrix \f$\bf A\f$. - - \note By default, this function uses Lapack 3rd party. It is also possible - to use a specific 3rd party suffixing this function name with one of the - following 3rd party names (Lapack, Eigen3 or OpenCV). - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param[in] rank_in : Known rank of the matrix. - - \return The Moore-Penros pseudo inverse \f$ A^+ \f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - // This matrix rank is 2 - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - int rank_in = 2; - vpMatrix A_p = A.pseudoInverseLapack(rank_in); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - } - \endcode - - Once build, the previous example produces the following output: - \code - A: [2,3]= - 2 3 5 - -4 2 3 - A^+ (pseudo-inverse): [3,2]= - 0.117899 -0.190782 - 0.065380 0.039657 - 0.113612 0.052518 - \endcode - -*/ -vpMatrix vpMatrix::pseudoInverse(int rank_in) const -{ -#if defined(VISP_HAVE_LAPACK) - return pseudoInverseLapack(rank_in); -#elif defined(VISP_HAVE_EIGEN3) - return pseudoInverseEigen3(rank_in); -#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 - return pseudoInverseOpenCV(rank_in); -#else - (void)rank_in; - throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " - "Install Lapack, Eigen3 or OpenCV 3rd party")); -#endif -} - -#ifndef DOXYGEN_SHOULD_SKIP_THIS -#if defined(VISP_HAVE_LAPACK) -/*! - Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n - matrix \f$\bf A\f$ using Lapack 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The Moore-Penros pseudo inverse \f$ A^+ \f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p = A.pseudoInverseLapack(); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - } - \endcode - - \sa pseudoInverse(double) const -*/ -vpMatrix vpMatrix::pseudoInverseLapack(double svThreshold) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - - vpMatrix U, V, Ap; - vpColVector sv; - - U = *this; - U.svdLapack(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); - - return Ap; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ and return the rank of the matrix using Lapack 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The rank of the matrix. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - unsigned int rank = A.pseudoInverseLapack(A_p); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank: " << rank << std::endl; - } - \endcode - - \sa pseudoInverse(vpMatrix &, double) const -*/ -unsigned int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, double svThreshold) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - - vpMatrix U, V; - vpColVector sv; - - U = *this; - U.svdLapack(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); - - return static_cast(rank_out); -} -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values and return the rank of the matrix using - Lapack 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - vpColVector sv; - unsigned int rank = A.pseudoInverseLapack(A_p, sv); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - - std::cout << "Rank: " << rank << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, double) const -*/ -unsigned int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - - vpMatrix U, V; - - Ap.resize(ncols, nrows, false, false); - - U = *this; - U.svdLapack(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); - - return static_cast(rank_out); -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and - \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using Lapack 3rd - party. - - \warning To inverse a square n-by-n matrix, you have to use rather - inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. - - Using singular value decomposition, we have: - - \f[ - {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf - V^\top}_{n\times n} \f] \f[ - {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & - \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix - \f$A\f$ singular values. - - This equation could be reformulated in a minimal way: - \f[ - {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix - \f$A\f$ first r singular values. - - The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) - = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. - - \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param svThreshold: Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. - - \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. - - \param kerAt: The matrix that contains the null space (kernel) of \f$\bf - A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full - rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, - n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpColVector sv; - vpMatrix A_p, imA, imAt, kerAt; - unsigned int rank = A.pseudoInverseLapack(A_p, sv, 1e-6, imA, imAt, kerAt); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank: " << rank << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - imA.print(std::cout, 10, "Im(A): "); - imAt.print(std::cout, 10, "Im(A^T): "); - - if (kerAt.size()) { - kerAt.t().print(std::cout, 10, "Ker(A): "); - } - else { - std::cout << "Ker(A) empty " << std::endl; - } - - // Reconstruct matrix A from ImA, ImAt, KerAt - vpMatrix S(rank, A.getCols()); - for(unsigned int i = 0; i< rank; i++) - S[i][i] = sv[i]; - vpMatrix Vt(A.getCols(), A.getCols()); - Vt.insert(imAt.t(), 0, 0); - Vt.insert(kerAt, rank, 0); - (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const -*/ -unsigned int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, - vpMatrix &imAt, vpMatrix &kerAt) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - vpMatrix U, V; - - if (nrows < ncols) { - U.resize(ncols, ncols, true); - U.insert(*this, 0, 0); - } - else { - U = *this; - } - - U.svdLapack(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, &imA, &imAt, &kerAt); - - return static_cast(rank_out); -} - -/*! - Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n - matrix \f$\bf A\f$ using Lapack 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param[in] rank_in : Known rank of the matrix. - \return The Moore-Penros pseudo inverse \f$ A^+ \f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - // This matrix rank is 2 - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - int rank_in = 2; - vpMatrix A_p = A.pseudoInverseLapack(rank_in); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - return 0; - } - \endcode - - \sa pseudoInverse(int) const -*/ -vpMatrix vpMatrix::pseudoInverseLapack(int rank_in) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - - vpMatrix U, V, Ap; - vpColVector sv; - - U = *this; - U.svdLapack(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); - - return Ap; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ and return the rank of the matrix using Lapack 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param[out] Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param[in] rank_in : Known rank of the matrix. - - \return The computed rank of the matrix. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - // This matrix rank is 2 - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - int rank_in = 2; - int rank_out = A.pseudoInverseLapack(A_p, rank_in); - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - return 0; - } - \endcode - - \sa pseudoInverse(vpMatrix &, int) const -*/ -int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, int rank_in) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - - vpMatrix U, V; - vpColVector sv; - - U = *this; - U.svdLapack(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); - - return rank_out; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values and return the rank of the matrix using - Lapack 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param[in] rank_in : Known rank of the matrix. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - // This matrix rank is 2 - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - vpColVector sv; - int rank_in = 2; - - int rank_out = A.pseudoInverseLapack(A_p, sv, rank_in); - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - return 0; - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, int) const -*/ -int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - vpMatrix U, V; - - Ap.resize(ncols, nrows, false, false); - - U = *this; - U.svdLapack(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); - - return rank_out; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and - \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using Lapack 3rd - party. - - \warning To inverse a square n-by-n matrix, you have to use rather - inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. - - Using singular value decomposition, we have: - - \f[ - {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf - V^\top}_{n\times n} \f] \f[ - {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & - \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix - \f$A\f$ singular values. - - This equation could be reformulated in a minimal way: - \f[ - {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix - \f$A\f$ first r singular values. - - The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) - = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. - - \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param[in] rank_in : Known rank of the matrix. - - \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. - - \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. - - \param kerAt: The matrix that contains the null space (kernel) of \f$\bf - A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full - rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, - n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpColVector sv; - vpMatrix A_p, imA, imAt, kerAt; - int rank_in = 2; - int rank_out = A.pseudoInverseLapack(A_p, sv, rank_in, imA, imAt, kerAt); - - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - imA.print(std::cout, 10, "Im(A): "); - imAt.print(std::cout, 10, "Im(A^T): "); - - if (kerAt.size()) { - kerAt.t().print(std::cout, 10, "Ker(A): "); - } - else { - std::cout << "Ker(A) empty " << std::endl; - } - - // Reconstruct matrix A from ImA, ImAt, KerAt - vpMatrix S(rank_in, A.getCols()); - for(unsigned int i = 0; i< rank_in; i++) - S[i][i] = sv[i]; - vpMatrix Vt(A.getCols(), A.getCols()); - Vt.insert(imAt.t(), 0, 0); - Vt.insert(kerAt, rank_in, 0); - (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, int, vpMatrix &, vpMatrix &, vpMatrix &) const -*/ -int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, - vpMatrix &kerAt) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - vpMatrix U, V; - - if (nrows < ncols) { - U.resize(ncols, ncols, true); - U.insert(*this, 0, 0); - } - else { - U = *this; - } - - U.svdLapack(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt); - - return rank_out; -} - -#endif -#if defined(VISP_HAVE_EIGEN3) -/*! - Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n - matrix \f$\bf A\f$ using Eigen3 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The Moore-Penros pseudo inverse \f$ A^+ \f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p = A.pseudoInverseEigen3(); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - } - \endcode - - \sa pseudoInverse(double) -*/ -vpMatrix vpMatrix::pseudoInverseEigen3(double svThreshold) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - vpMatrix U, V, Ap; - vpColVector sv; - - U = *this; - U.svdEigen3(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); - - return Ap; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ and return the rank of the matrix using Eigen3 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The rank of the matrix. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - unsigned int rank = A.pseudoInverseEigen3(A_p); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank: " << rank << std::endl; - } - \endcode - - \sa pseudoInverse(vpMatrix &, double) const -*/ -unsigned int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, double svThreshold) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - vpMatrix U, V; - vpColVector sv; - - U = *this; - U.svdEigen3(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); - - return static_cast(rank_out); -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values and return the rank of the matrix using - Eigen3 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - vpColVector sv; - unsigned int rank = A.pseudoInverseEigen3(A_p, sv); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - - std::cout << "Rank: " << rank << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, double) const -*/ -unsigned int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - vpMatrix U, V; - - Ap.resize(ncols, nrows, false, false); - - U = *this; - U.svdEigen3(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); - - return static_cast(rank_out); -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and - \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using Eigen3 3rd - party. - - \warning To inverse a square n-by-n matrix, you have to use rather - inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. - - Using singular value decomposition, we have: - - \f[ - {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf - V^\top}_{n\times n} \f] \f[ - {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & - \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix - \f$A\f$ singular values. - - This equation could be reformulated in a minimal way: - \f[ - {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix - \f$A\f$ first r singular values. - - The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) - = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. - - \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param svThreshold: Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. - - \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. - - \param kerAt: The matrix that contains the null space (kernel) of \f$\bf - A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full - rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, - n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpColVector sv; - vpMatrix A_p, imA, imAt, kerAt; - unsigned int rank = A.pseudoInverseEigen3(A_p, sv, 1e-6, imA, imAt, kerAt); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank: " << rank << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - imA.print(std::cout, 10, "Im(A): "); - imAt.print(std::cout, 10, "Im(A^T): "); - - if (kerAt.size()) { - kerAt.t().print(std::cout, 10, "Ker(A): "); - } - else { - std::cout << "Ker(A) empty " << std::endl; - } - - // Reconstruct matrix A from ImA, ImAt, KerAt - vpMatrix S(rank, A.getCols()); - for(unsigned int i = 0; i< rank; i++) - S[i][i] = sv[i]; - vpMatrix Vt(A.getCols(), A.getCols()); - Vt.insert(imAt.t(), 0, 0); - Vt.insert(kerAt, rank, 0); - (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const -*/ -unsigned int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, - vpMatrix &imAt, vpMatrix &kerAt) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - vpMatrix U, V; - - if (nrows < ncols) { - U.resize(ncols, ncols, true); - U.insert(*this, 0, 0); - } - else { - U = *this; - } - - U.svdEigen3(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, &imA, &imAt, &kerAt); - - return static_cast(rank_out); -} - -/*! - Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n - matrix \f$\bf A\f$ using Eigen3 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param[in] rank_in : Known rank of the matrix. - \return The Moore-Penros pseudo inverse \f$ A^+ \f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - // This matrix rank is 2 - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - int rank_in = 2; - vpMatrix A_p = A.pseudoInverseEigen3(rank_in); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - return 0; - } - \endcode - - \sa pseudoInverse(int) const -*/ -vpMatrix vpMatrix::pseudoInverseEigen3(int rank_in) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - vpMatrix U, V, Ap; - vpColVector sv; - - U = *this; - U.svdEigen3(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); - - return Ap; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ and return the rank of the matrix using Eigen3 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param[out] Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param[in] rank_in : Known rank of the matrix. - - \return The computed rank of the matrix. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - // This matrix rank is 2 - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - int rank_in = 2; - int rank_out = A.pseudoInverseEigen3(A_p, rank_in); - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - return 0; - } - \endcode - - \sa pseudoInverse(vpMatrix &, int) const -*/ -int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - vpMatrix U, V; - vpColVector sv; - - Ap.resize(ncols, nrows, false, false); - - U = *this; - U.svdEigen3(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); - - return rank_out; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values and return the rank of the matrix using - Eigen3 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param[in] rank_in : Known rank of the matrix. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - // This matrix rank is 2 - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - vpColVector sv; - int rank_in = 2; - - int rank_out = A.pseudoInverseEigen3(A_p, sv, rank_in); - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - return 0; - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, int) const -*/ -int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - vpMatrix U, V; - - Ap.resize(ncols, nrows, false, false); - - U = *this; - U.svdEigen3(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); - - return rank_out; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and - \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using Eigen3 3rd - party. - - \warning To inverse a square n-by-n matrix, you have to use rather - inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. - - Using singular value decomposition, we have: - - \f[ - {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf - V^\top}_{n\times n} \f] \f[ - {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & - \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix - \f$A\f$ singular values. - - This equation could be reformulated in a minimal way: - \f[ - {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix - \f$A\f$ first r singular values. - - The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) - = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. - - \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param[in] rank_in : Known rank of the matrix. - - \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. - - \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. - - \param kerAt: The matrix that contains the null space (kernel) of \f$\bf - A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full - rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, - n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpColVector sv; - vpMatrix A_p, imA, imAt, kerAt; - int rank_in = 2; - int rank_out = A.pseudoInverseEigen3(A_p, sv, rank_in, imA, imAt, kerAt); - - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - imA.print(std::cout, 10, "Im(A): "); - imAt.print(std::cout, 10, "Im(A^T): "); - - if (kerAt.size()) { - kerAt.t().print(std::cout, 10, "Ker(A): "); - } - else { - std::cout << "Ker(A) empty " << std::endl; - } - - // Reconstruct matrix A from ImA, ImAt, KerAt - vpMatrix S(rank_in, A.getCols()); - for(unsigned int i = 0; i< rank_in; i++) - S[i][i] = sv[i]; - vpMatrix Vt(A.getCols(), A.getCols()); - Vt.insert(imAt.t(), 0, 0); - Vt.insert(kerAt, rank_in, 0); - (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, int, vpMatrix &, vpMatrix &, vpMatrix &) const -*/ -int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, - vpMatrix &kerAt) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - vpMatrix U, V; - - if (nrows < ncols) { - U.resize(ncols, ncols, true); - U.insert(*this, 0, 0); - } - else { - U = *this; - } - U.svdEigen3(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt); - - return rank_out; -} - -#endif -#if defined(VISP_HAVE_OPENCV) -/*! - Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n - matrix \f$\bf A\f$ using OpenCV 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The Moore-Penros pseudo inverse \f$ A^+ \f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p = A.pseudoInverseEigen3(); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - } - \endcode - - \sa pseudoInverse(double) const -*/ -vpMatrix vpMatrix::pseudoInverseOpenCV(double svThreshold) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - vpMatrix U, V, Ap; - vpColVector sv; - - U = *this; - U.svdOpenCV(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); - - return Ap; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ and return the rank of the matrix using OpenCV 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The rank of the matrix. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - unsigned int rank = A.pseudoInverseOpenCV(A_p); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank: " << rank << std::endl; - } - \endcode - - \sa pseudoInverse(vpMatrix &, double) const -*/ -unsigned int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - vpMatrix U, V; - vpColVector sv; - - Ap.resize(ncols, nrows, false, false); - - U = *this; - U.svdOpenCV(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); - - return static_cast(rank_out); -} -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values and return the rank of the matrix using - OpenCV 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - vpColVector sv; - unsigned int rank = A.pseudoInverseOpenCV(A_p, sv); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - - std::cout << "Rank: " << rank << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, double) const -*/ -unsigned int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - vpMatrix U, V; - - Ap.resize(ncols, nrows, false, false); - - U = *this; - U.svdOpenCV(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); - - return static_cast(rank_out); -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and - \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using OpenCV 3rd - party. - - \warning To inverse a square n-by-n matrix, you have to use rather - inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. - - Using singular value decomposition, we have: - - \f[ - {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf - V^\top}_{n\times n} \f] \f[ - {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & - \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix - \f$A\f$ singular values. - - This equation could be reformulated in a minimal way: - \f[ - {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix - \f$A\f$ first r singular values. - - The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) - = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. - - \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param svThreshold: Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. - - \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. - - \param kerAt: The matrix that contains the null space (kernel) of \f$\bf - A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full - rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, - n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpColVector sv; - vpMatrix A_p, imA, imAt, kerAt; - unsigned int rank = A.pseudoInverseOpenCV(A_p, sv, 1e-6, imA, imAt, kerAt); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank: " << rank << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - imA.print(std::cout, 10, "Im(A): "); - imAt.print(std::cout, 10, "Im(A^T): "); - - if (kerAt.size()) { - kerAt.t().print(std::cout, 10, "Ker(A): "); - } - else { - std::cout << "Ker(A) empty " << std::endl; - } - - // Reconstruct matrix A from ImA, ImAt, KerAt - vpMatrix S(rank, A.getCols()); - for(unsigned int i = 0; i< rank; i++) - S[i][i] = sv[i]; - vpMatrix Vt(A.getCols(), A.getCols()); - Vt.insert(imAt.t(), 0, 0); - Vt.insert(kerAt, rank, 0); - (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const -*/ -unsigned int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, - vpMatrix &imAt, vpMatrix &kerAt) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - vpMatrix U, V; - - if (nrows < ncols) { - U.resize(ncols, ncols, true); - U.insert(*this, 0, 0); - } - else { - U = *this; - } - - U.svdOpenCV(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, &imA, &imAt, &kerAt); - - return static_cast(rank_out); -} - -/*! - Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n - matrix \f$\bf A\f$ using OpenCV 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param[in] rank_in : Known rank of the matrix. - \return The Moore-Penros pseudo inverse \f$ A^+ \f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - // This matrix rank is 2 - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - int rank_in = 2; - vpMatrix A_p = A.pseudoInverseOpenCV(rank_in); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - return 0; - } - \endcode - - \sa pseudoInverse(int) const -*/ -vpMatrix vpMatrix::pseudoInverseOpenCV(int rank_in) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - vpMatrix U, V, Ap; - vpColVector sv; - - U = *this; - U.svdOpenCV(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); - - return Ap; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ and return the rank of the matrix using OpenCV 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param[out] Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param[in] rank_in : Known rank of the matrix. - - \return The computed rank of the matrix. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - // This matrix rank is 2 - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - int rank_in = 2; - int rank_out = A.pseudoInverseOpenCV(A_p, rank_in); - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - return 0; - } - \endcode - - \sa pseudoInverse(vpMatrix &, int) const -*/ -int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - vpMatrix U, V; - vpColVector sv; - - Ap.resize(ncols, nrows, false, false); - - U = *this; - U.svdOpenCV(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); - - return rank_out; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values and return the rank of the matrix using - OpenCV 3rd party. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param[in] rank_in : Known rank of the matrix. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - // This matrix rank is 2 - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - vpColVector sv; - int rank_in = 2; - - int rank_out = A.pseudoInverseOpenCV(A_p, sv, rank_in); - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - return 0; - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, int) const -*/ -int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - vpMatrix U, V; - - Ap.resize(ncols, nrows, false, false); - - U = *this; - U.svdOpenCV(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); - - return rank_out; -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and - \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using OpenCV 3rd - party. - - \warning To inverse a square n-by-n matrix, you have to use rather - inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. - - Using singular value decomposition, we have: - - \f[ - {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf - V^\top}_{n\times n} \f] \f[ - {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & - \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix - \f$A\f$ singular values. - - This equation could be reformulated in a minimal way: - \f[ - {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} - \left[ - \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ - \\ - \hline \\ - \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] - \f] - - where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix - \f$A\f$ first r singular values. - - The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) - = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. - - \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param[in] rank_in : Known rank of the matrix. - - \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. - - \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. - - \param kerAt: The matrix that contains the null space (kernel) of \f$\bf - A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full - rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, - n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpColVector sv; - vpMatrix A_p, imA, imAt, kerAt; - int rank_in = 2; - int rank_out = A.pseudoInverseOpenCV(A_p, sv, rank_in, imA, imAt, kerAt); - - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - imA.print(std::cout, 10, "Im(A): "); - imAt.print(std::cout, 10, "Im(A^T): "); - - if (kerAt.size()) { - kerAt.t().print(std::cout, 10, "Ker(A): "); - } - else { - std::cout << "Ker(A) empty " << std::endl; - } - - // Reconstruct matrix A from ImA, ImAt, KerAt - vpMatrix S(rank_in, A.getCols()); - for(unsigned int i = 0; i< rank_in; i++) - S[i][i] = sv[i]; - vpMatrix Vt(A.getCols(), A.getCols()); - Vt.insert(imAt.t(), 0, 0); - Vt.insert(kerAt, rank_in, 0); - (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); - } - \endcode - - \sa pseudoInverse(vpMatrix &, vpColVector &, int, vpMatrix &, vpMatrix &, vpMatrix &) const -*/ -int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, - vpMatrix &kerAt) const -{ - unsigned int nrows = getRows(); - unsigned int ncols = getCols(); - int rank_out; - double svThreshold = 1e-26; - vpMatrix U, V; - - if (nrows < ncols) { - U.resize(ncols, ncols, true); - U.insert(*this, 0, 0); - } - else { - U = *this; - } - - U.svdOpenCV(sv, V); - - compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt); - - return rank_out; -} - -#endif -#endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values and return the rank of the matrix. - - \note By default, this function uses Lapack 3rd party. It is also possible - to use a specific 3rd party suffixing this function name with one of the - following 3rd party names (Lapack, Eigen3 or OpenCV). - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - vpColVector sv; - unsigned int rank = A.pseudoInverse(A_p, sv); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - - std::cout << "Rank: " << rank << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - } - \endcode - - Once build, the previous example produces the following output: - \code - A: [2,3]= - 2 3 5 - -4 2 3 - A^+ (pseudo-inverse): [3,2]= - 0.117899 -0.190782 - 0.065380 0.039657 - 0.113612 0.052518 - Rank: 2 - Singular values: 6.874359351 4.443330227 - \endcode -*/ -unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold) const -{ -#if defined(VISP_HAVE_LAPACK) - return pseudoInverseLapack(Ap, sv, svThreshold); -#elif defined(VISP_HAVE_EIGEN3) - return pseudoInverseEigen3(Ap, sv, svThreshold); -#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 - return pseudoInverseOpenCV(Ap, sv, svThreshold); -#else - (void)Ap; - (void)sv; - (void)svThreshold; - throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " - "Install Lapack, Eigen3 or OpenCV 3rd party")); -#endif -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values and return the rank of the matrix. - - \note By default, this function uses Lapack 3rd party. It is also possible - to use a specific 3rd party suffixing this function name with one of the - following 3rd party names (Lapack, Eigen3 or OpenCV). - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param[in] rank_in : Known rank of the matrix. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - vpColVector sv; - int rank_in = 2; - int rank_out = A.pseudoInverse(A_p, sv, rank_in); - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - } - \endcode - - Once build, the previous example produces the following output: - \code - A: [2,3]= - 2 3 5 - -4 2 3 - A^+ (pseudo-inverse): [3,2]= - 0.117899 -0.190782 - 0.065380 0.039657 - 0.113612 0.052518 - Rank in : 2 - Rank out: 2 - Singular values: 6.874359351 4.443330227 - \endcode -*/ -int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in) const -{ -#if defined(VISP_HAVE_LAPACK) - return pseudoInverseLapack(Ap, sv, rank_in); -#elif defined(VISP_HAVE_EIGEN3) - return pseudoInverseEigen3(Ap, sv, rank_in); -#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 - return pseudoInverseOpenCV(Ap, sv, rank_in); -#else - (void)Ap; - (void)sv; - (void)rank_in; - throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " - "Install Lapack, Eigen3 or OpenCV 3rd party")); -#endif -} -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values, \f$\mbox{Im}(A)\f$ and \f$\mbox{Im}(A^T)\f$ - and return the rank of the matrix. - - See pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const - for a complete description of this function. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param svThreshold : Threshold used to test the singular values. If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. - - \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - vpColVector sv; - vpMatrix imA, imAt; - unsigned int rank = A.pseudoInverse(A_p, sv, 1e-6, imA, imAt); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank: " << rank << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - imA.print(std::cout, 10, "Im(A): "); - imAt.print(std::cout, 10, "Im(A^T): "); - } - \endcode - - Once build, the previous example produces the following output: - \code - A: [2,3]= - 2 3 5 - -4 2 3 - A^+ (pseudo-inverse): [3,2]= - 0.117899 -0.190782 - 0.065380 0.039657 - 0.113612 0.052518 - Rank: 2 - Singular values: 6.874359351 4.443330227 - Im(A): [2,2]= - 0.81458 -0.58003 - 0.58003 0.81458 - Im(A^T): [3,2]= - -0.100515 -0.994397 - 0.524244 -0.024967 - 0.845615 -0.102722 - \endcode -*/ -unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt) const -{ - vpMatrix kerAt; - return pseudoInverse(Ap, sv, svThreshold, imA, imAt, kerAt); -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values, \f$\mbox{Im}(A)\f$ and \f$\mbox{Im}(A^T)\f$ - and return the rank of the matrix. - - See pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const - for a complete description of this function. - - \warning To inverse a square n-by-n matrix, you have to use rather one of - the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that - are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. - - \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size - of this vector is equal to min(m, n). - - \param[in] rank_in : Known rank of the matrix. - - \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. - - \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpMatrix A_p; - vpColVector sv; - vpMatrix imA, imAt; - int rank_in = 2; - int rank_out = A.pseudoInverse(A_p, sv, rank_in, imA, imAt); - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_in << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - imA.print(std::cout, 10, "Im(A): "); - imAt.print(std::cout, 10, "Im(A^T): "); - } - \endcode - - Once build, the previous example produces the following output: - \code - A: [2,3]= - 2 3 5 - -4 2 3 - A^+ (pseudo-inverse): [3,2]= - 0.117899 -0.190782 - 0.065380 0.039657 - 0.113612 0.052518 - Rank: 2 - Singular values: 6.874359351 4.443330227 - Im(A): [2,2]= - 0.81458 -0.58003 - 0.58003 0.81458 - Im(A^T): [3,2]= - -0.100515 -0.994397 - 0.524244 -0.024967 - 0.845615 -0.102722 - \endcode -*/ -int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt) const -{ - vpMatrix kerAt; - return pseudoInverse(Ap, sv, rank_in, imA, imAt, kerAt); -} - -/*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and - \f$\mbox{Ker}(A)\f$ and return the rank of the matrix. - - \note By default, this function uses Lapack 3rd party. It is also possible - to use a specific 3rd party suffixing this function name with one of the - following 3rd party names (Lapack, Eigen3 or OpenCV). - - \warning To inverse a square n-by-n matrix, you have to use rather - inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. - - \param Ap : The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. - - \param sv : Vector corresponding to matrix A singular values. The size of this vector is equal to min(m, n). - - \param svThreshold : Threshold used to test the singular values.If - a singular value is lower than this threshold we consider that the - matrix is not full rank. - - \param imA : \f$\mbox { Im }({ \bf A })\f$ that is a m - by - r matrix. - - \param imAt : \f$\mbox { Im }({ \bf A } ^ T)\f$ that is n - by - r matrix. - - \param kerAt : The matrix that contains the null space(kernel) of \f$\bf - A\f$ defined by the matrix \f$ { \bf X } ^ T\f$.If matrix \f$\bf A\f$ is full - rank, the dimension of \c kerAt is(0, n), otherwise the dimension is (n - r, n). - This matrix is thus the transpose of \f$\mbox { Ker }({ \bf A })\f$. - - \return The rank of the matrix \f$\bf A\f$. - - Here an example to compute the pseudo - inverse of a 2 - by - 3 matrix that is rank 2. - - \code - #include - - int main() - { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpColVector sv; - vpMatrix A_p, imA, imAt, kerAt; - unsigned int rank = A.pseudoInverse(A_p, sv, 1e-6, imA, imAt, kerAt); - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank: " << rank << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - imA.print(std::cout, 10, "Im(A): "); - imAt.print(std::cout, 10, "Im(A^T): "); - - if (kerAt.size()) { - kerAt.t().print(std::cout, 10, "Ker(A): "); - } - else { - std::cout << "Ker(A) empty " << std::endl; - } - - // Reconstruct matrix A from ImA, ImAt, KerAt - vpMatrix S(rank, A.getCols()); - for (unsigned int i = 0; i< rank; i++) - S[i][i] = sv[i]; - vpMatrix Vt(A.getCols(), A.getCols()); - Vt.insert(imAt.t(), 0, 0); - Vt.insert(kerAt, rank, 0); - (imA *S *Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); - } - \endcode - - Once build, the previous example produces the following output : - - \code{.sh} - A: [2,3] = - 2 3 5 - -4 2 3 - A^+(pseudo-inverse): [3,2]= - 0.117899 -0.190782 - 0.065380 0.039657 - 0.113612 0.052518 - Rank: 2 - Singular values: 6.874359351 4.443330227 - Im(A): [2,2]= - 0.81458 -0.58003 - 0.58003 0.81458 - Im(A^T): [3,2] = - -0.100515 -0.994397 - 0.524244 -0.024967 - 0.845615 -0.102722 - Ker(A): [3,1]= - -0.032738 - -0.851202 - 0.523816 - Im(A) * S * [Im(A^T) | Ker(A)]^T: [2,3]= - 2 3 5 - -4 2 3 - \endcode -*/ -unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, - vpMatrix &kerAt) const -{ -#if defined(VISP_HAVE_LAPACK) - return pseudoInverseLapack(Ap, sv, svThreshold, imA, imAt, kerAt); -#elif defined(VISP_HAVE_EIGEN3) - return pseudoInverseEigen3(Ap, sv, svThreshold, imA, imAt, kerAt); -#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 - return pseudoInverseOpenCV(Ap, sv, svThreshold, imA, imAt, kerAt); -#else - (void)Ap; - (void)sv; - (void)svThreshold; - (void)imA; - (void)imAt; - (void)kerAt; - throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " - "Install Lapack, Eigen3 or OpenCV 3rd party")); -#endif + return; // Noting to do + } + for (unsigned int i = 0; i < nrows; ++i) { + memcpy((*this)[i], &M[i + r][c], ncols * sizeof(double)); + } } /*! - Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf - A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and - \f$\mbox { Ker }(A)\f$ and return the rank of the matrix. - - \note By default, this function uses Lapack 3rd party.It is also possible - to use a specific 3rd party suffixing this function name with one of the - following 3rd party names(Lapack, Eigen3 or OpenCV). - - \warning To inverse a square n - by - n matrix, you have to use rather - inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. - - \param Ap : The Moore - Penros pseudo inverse \f$ { \bf A } ^ +\f$. - - \param sv : Vector corresponding to matrix \f$A\f$ singular values.The size - of this vector is equal to min(m, n). - - \param[in] rank_in : Known rank of the matrix. - - \param imA : \f$\mbox { Im }({ \bf A })\f$ that is a m - by - r matrix. - - \param imAt : \f$\mbox { Im }({ \bf A } ^T)\f$ that is n - by - r matrix. - - \param kerAt : The matrix that contains the null space(kernel) of \f$\bf - A\f$ defined by the matrix \f$ { \bf X } ^ T\f$.If matrix \f$\bf A\f$ is full - rank, the dimension of \c kerAt is(0, n), otherwise the dimension is(n - r, - n).This matrix is thus the transpose of \f$\mbox { Ker }({ \bf A })\f$. - - \return The rank of the matrix \f$\bf A\f$. + Extract a sub matrix from a matrix \e M. - Here an example to compute the pseudo - inverse of a 2 - by - 3 matrix that is rank 2. + \param r : row index in matrix \e M. + \param c : column index in matrix \e M. + \param nrows : Number of rows of the matrix that should be extracted. + \param ncols : Number of columns of the matrix that should be extracted. + The following code shows how to use this function: \code #include int main() { - vpMatrix A(2, 3); - - A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; - A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; - - A.print(std::cout, 10, "A: "); - - vpColVector sv; - vpMatrix A_p, imA, imAt, kerAt; - int rank_in = 2; - int rank_out = A.pseudoInverse(A_p, sv, rank_in, imA, imAt, kerAt); - if (rank_out != rank_in) { - std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; - std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; - } - - A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); - std::cout << "Rank in : " << rank_in << std::endl; - std::cout << "Rank out: " << rank_out << std::endl; - std::cout << "Singular values: " << sv.t() << std::endl; - imA.print(std::cout, 10, "Im(A): "); - imAt.print(std::cout, 10, "Im(A^T): "); - - if (kerAt.size()) { - kerAt.t().print(std::cout, 10, "Ker(A): "); - } - else { - std::cout << "Ker(A) empty " << std::endl; + vpMatrix M(4,5); + int val = 0; + for(size_t i=0; i= 2.1.1 - return pseudoInverseOpenCV(Ap, sv, rank_in, imA, imAt, kerAt); -#else - (void)Ap; - (void)sv; - (void)rank_in; - (void)imA; - (void)imAt; - (void)kerAt; - throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " - "Install Lapack, Eigen3 or OpenCV 3rd party")); -#endif + unsigned int rnrows = r + nrows; + unsigned int cncols = c + ncols; + + if (rnrows > getRows()) { + throw(vpException(vpException::dimensionError, "Bad row dimension (%d > %d) used to initialize vpMatrix", rnrows, + getRows())); + } + if (cncols > getCols()) { + throw(vpException(vpException::dimensionError, "Bad column dimension (%d > %d) used to initialize vpMatrix", cncols, + getCols())); + } + + vpMatrix M; + M.resize(nrows, ncols, false, false); + for (unsigned int i = 0; i < nrows; ++i) { + memcpy(M[i], &(*this)[i + r][c], ncols * sizeof(double)); + } + + return M; } /*! @@ -4963,7 +464,7 @@ vpColVector vpMatrix::getCol(unsigned int j) const { return getCol(j, 0, rowNum) \return The extracted row vector. The following example shows how to use this function: - \code + \code #include #include @@ -4977,61 +478,61 @@ vpColVector vpMatrix::getCol(unsigned int j) const { return getCol(j, 0, rowNum) A.print(std::cout, 4); -vpRowVector rv = A.getRow(1); -std::cout << "Row vector: \n" << rv << std::endl; + vpRowVector rv = A.getRow(1); + std::cout << "Row vector: \n" << rv << std::endl; } -\endcode -It produces the following output : -\code -[4, 4] = -0 1 2 3 -4 5 6 7 -8 9 10 11 -12 13 14 15 -Row vector : -4 5 6 7 -\endcode + \endcode + It produces the following output : + \code + [4, 4] = + 0 1 2 3 + 4 5 6 7 + 8 9 10 11 + 12 13 14 15 + Row vector : + 4 5 6 7 + \endcode */ vpRowVector vpMatrix::getRow(unsigned int i) const { return getRow(i, 0, colNum); } /*! -Extract a row vector from a matrix. -\warning All the indexes start from 0 in this function. -\param i : Index of the row to extract.If i = 0, the first row is extracted. -\param j_begin : Index of the column that gives the location of the first -element of the row vector to extract. -\param row_size : Size of the row vector to extract. -\return The extracted row vector. - -The following example shows how to use this function: -\code -#include -#include + Extract a row vector from a matrix. + \warning All the indexes start from 0 in this function. + \param i : Index of the row to extract.If i = 0, the first row is extracted. + \param j_begin : Index of the column that gives the location of the first + element of the row vector to extract. + \param row_size : Size of the row vector to extract. + \return The extracted row vector. -int main() -{ - vpMatrix A(4, 4); + The following example shows how to use this function: + \code + #include + #include + + int main() + { + vpMatrix A(4, 4); - for (unsigned int i = 0; i < A.getRows(); i++) - for (unsigned int j = 0; j < A.getCols(); j++) - A[i][j] = i*A.getCols()+j; + for (unsigned int i = 0; i < A.getRows(); i++) + for (unsigned int j = 0; j < A.getCols(); j++) + A[i][j] = i*A.getCols()+j; - A.print(std::cout, 4); + A.print(std::cout, 4); - vpRowVector rv = A.getRow(1, 1, 3); - std::cout << "Row vector: \n" << rv << std::endl; -} -\endcode -It produces the following output : -\code -[4, 4] = -0 1 2 3 -4 5 6 7 -8 9 10 11 -12 13 14 15 -Row vector : -5 6 7 -\endcode + vpRowVector rv = A.getRow(1, 1, 3); + std::cout << "Row vector: \n" << rv << std::endl; + } + \endcode + It produces the following output : + \code + [4, 4] = + 0 1 2 3 + 4 5 6 7 + 8 9 10 11 + 12 13 14 15 + Row vector : + 5 6 7 + \endcode */ vpRowVector vpMatrix::getRow(unsigned int i, unsigned int j_begin, unsigned int row_size) const { @@ -5097,149 +598,6 @@ vpColVector vpMatrix::getDiag() const return diag; } -/*! - Stack matrix \e B to the end of matrix \e A and return the resulting matrix - [ A B ]^T - - \param A : Upper matrix. - \param B : Lower matrix. - \return Stacked matrix [ A B ]^T - - \warning A and B must have the same number of columns. -*/ -vpMatrix vpMatrix::stack(const vpMatrix &A, const vpMatrix &B) -{ - vpMatrix C; - - vpMatrix::stack(A, B, C); - - return C; -} - -/*! - Stack matrix \e B to the end of matrix \e A and return the resulting matrix - in \e C. - - \param A : Upper matrix. - \param B : Lower matrix. - \param C : Stacked matrix C = [ A B ]^T - - \warning A and B must have the same number of columns. A and C, B and C must - be two different objects. -*/ -void vpMatrix::stack(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) -{ - unsigned int nra = A.getRows(); - unsigned int nrb = B.getRows(); - - if (nra != 0) { - if (A.getCols() != B.getCols()) { - throw(vpException(vpException::dimensionError, "Cannot stack (%dx%d) matrix with (%dx%d) matrix", A.getRows(), - A.getCols(), B.getRows(), B.getCols())); - } - } - - if ((A.data != nullptr) && (A.data == C.data)) { - std::cerr << "A and C must be two different objects!" << std::endl; - return; - } - - if ((B.data != nullptr) && (B.data == C.data)) { - std::cerr << "B and C must be two different objects!" << std::endl; - return; - } - - C.resize(nra + nrb, B.getCols(), false, false); - - if ((C.data != nullptr) && (A.data != nullptr) && (A.size() > 0)) { - // Copy A in C - memcpy(C.data, A.data, sizeof(double) * A.size()); - } - - if ((C.data != nullptr) && (B.data != nullptr) && (B.size() > 0)) { - // Copy B in C - memcpy(C.data + A.size(), B.data, sizeof(double) * B.size()); - } -} - -/*! - Stack row vector \e r to matrix \e A and return the resulting matrix [ A r ]^T - - \param A : Upper matrix. - \param r : Lower row vector. - \return Stacked matrix [ A r ]^T - - \warning \e A and \e r must have the same number of columns. -*/ -vpMatrix vpMatrix::stack(const vpMatrix &A, const vpRowVector &r) -{ - vpMatrix C; - vpMatrix::stack(A, r, C); - - return C; -} - -/*! - Stack row vector \e r to the end of matrix \e A and return the resulting - matrix in \e C. - - \param A : Upper matrix. - \param r : Lower row vector. - \param C : Stacked matrix C = [ A r ]^T - - \warning A and r must have the same number of columns. A and C must be two - different objects. -*/ -void vpMatrix::stack(const vpMatrix &A, const vpRowVector &r, vpMatrix &C) -{ - if ((A.data != nullptr) && (A.data == C.data)) { - std::cerr << "A and C must be two different objects!" << std::endl; - return; - } - - C = A; - C.stack(r); -} - -/*! - Stack column vector \e c to matrix \e A and return the resulting matrix [ A c ] - - \param A : Left matrix. - \param c : Right column vector. - \return Stacked matrix [ A c ] - - \warning \e A and \e c must have the same number of rows. -*/ -vpMatrix vpMatrix::stack(const vpMatrix &A, const vpColVector &c) -{ - vpMatrix C; - vpMatrix::stack(A, c, C); - - return C; -} - -/*! - Stack column vector \e c to the end of matrix \e A and return the resulting - matrix in \e C. - - \param A : Left matrix. - \param c : Right column vector. - \param C : Stacked matrix C = [ A c ] - - \warning A and c must have the same number of rows. A and C must be two - different objects. -*/ -void vpMatrix::stack(const vpMatrix &A, const vpColVector &c, vpMatrix &C) -{ - if ((A.data != nullptr) && (A.data == C.data)) { - std::cerr << "A and C must be two different objects!" << std::endl; - return; - } - - C = A; - C.stack(c); -} - /*! Insert matrix B in matrix A at the given position. @@ -5644,112 +1002,6 @@ std::ostream &vpMatrix::cppPrint(std::ostream &os, const std::string &matrixName return os; } -/*! - Stack A at the end of the current matrix, or copy if the matrix has no - dimensions : this = [ this A ]^T. -*/ -void vpMatrix::stack(const vpMatrix &A) -{ - if (rowNum == 0) { - *this = A; - } - else if (A.getRows() > 0) { - if (colNum != A.getCols()) { - throw(vpException(vpException::dimensionError, "Cannot stack (%dx%d) matrix with (%dx%d) matrix", rowNum, colNum, - A.getRows(), A.getCols())); - } - - unsigned int rowNumOld = rowNum; - resize(rowNum + A.getRows(), colNum, false, false); - insert(A, rowNumOld, 0); - } -} - -/*! - Stack row vector \e r at the end of the current matrix, or copy if the - matrix has no dimensions: this = [ this r ]^T. - - Here an example for a robot velocity log : - \code - vpMatrix A; - vpColVector v(6); - for(unsigned int i = 0;i<100;i++) - { - robot.getVelocity(vpRobot::ARTICULAR_FRAME, v); - Velocities.stack(v.t()); - } - \endcode -*/ -void vpMatrix::stack(const vpRowVector &r) -{ - if (rowNum == 0) { - *this = r; - } - else { - if (colNum != r.getCols()) { - throw(vpException(vpException::dimensionError, "Cannot stack (%dx%d) matrix with (1x%d) row vector", rowNum, - colNum, r.getCols())); - } - - if (r.size() == 0) { - return; - } - - unsigned int oldSize = size(); - resize(rowNum + 1, colNum, false, false); - - if ((data != nullptr) && (r.data != nullptr) && (data != r.data)) { - // Copy r in data - memcpy(data + oldSize, r.data, sizeof(double) * r.size()); - } - } -} - -/*! - Stack column vector \e c at the right of the current matrix, or copy if the - matrix has no dimensions: this = [ this c ]. - - Here an example for a robot velocity log matrix: - \code - vpMatrix log; - vpColVector v(6); - for(unsigned int i = 0; i<100;i++) - { - robot.getVelocity(vpRobot::ARTICULAR_FRAME, v); - log.stack(v); - } - \endcode - Here the log matrix has size 6 rows by 100 columns. -*/ -void vpMatrix::stack(const vpColVector &c) -{ - if (colNum == 0) { - *this = c; - } - else { - if (rowNum != c.getRows()) { - throw(vpException(vpException::dimensionError, "Cannot stack (%dx%d) matrix with (%dx1) column vector", rowNum, - colNum, c.getRows())); - } - - if (c.size() == 0) { - return; - } - - vpMatrix tmp = *this; - unsigned int oldColNum = colNum; - resize(rowNum, colNum + 1, false, false); - - if ((data != nullptr) && (tmp.data != nullptr) && (data != tmp.data)) { - // Copy c in data - for (unsigned int i = 0; i < rowNum; ++i) { - memcpy(data + (i * colNum), tmp.data + (i * oldColNum), sizeof(double) * oldColNum); - rowPtrs[i][oldColNum] = c[i]; - } - } - } -} - /*! Insert matrix A at the given position in the current matrix. @@ -6614,20 +1866,6 @@ double vpMatrix::sumSquare() const */ double vpMatrix::euclideanNorm() const { return frobeniusNorm(); } -vpMatrix vpMatrix::stackMatrices(const vpColVector &A, const vpColVector &B) -{ - return (vpMatrix)(vpColVector::stack(A, B)); -} - -void vpMatrix::stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C) -{ - vpColVector::stack(A, B, C); -} - -vpMatrix vpMatrix::stackMatrices(const vpMatrix &A, const vpRowVector &B) { return vpMatrix::stack(A, B); } - -void vpMatrix::stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C) { vpMatrix::stack(A, B, C); } - /*! \deprecated This method is deprecated. You should rather use getRow(). More precisely, the following code: @@ -6705,28 +1943,4 @@ void vpMatrix::setIdentity(const double &val) #endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) -/*! - \relates vpMatrix - Allow to multiply a scalar by a matrix. -*/ -vpMatrix operator*(const double &x, const vpMatrix &B) -{ - if (std::fabs(x - 1.) < std::numeric_limits::epsilon()) { - return B; - } - - unsigned int Brow = B.getRows(); - unsigned int Bcol = B.getCols(); - - VISP_NAMESPACE_ADDRESSING vpMatrix C; - C.resize(Brow, Bcol, false, false); - - for (unsigned int i = 0; i < Brow; ++i) { - for (unsigned int j = 0; j < Bcol; ++j) { - C[i][j] = B[i][j] * x; - } - } - - return C; -} END_VISP_NAMESPACE diff --git a/modules/core/src/math/matrix/vpMatrix_lu.cpp b/modules/core/src/math/matrix/vpMatrix_lu.cpp index b5d9b1564f..99f5cc6c65 100644 --- a/modules/core/src/math/matrix/vpMatrix_lu.cpp +++ b/modules/core/src/math/matrix/vpMatrix_lu.cpp @@ -29,8 +29,7 @@ * * Description: * Matrix LU decomposition. - * -*****************************************************************************/ + */ #include diff --git a/modules/core/src/math/matrix/vpMatrix_mul.cpp b/modules/core/src/math/matrix/vpMatrix_mul.cpp index 64c42b397f..fb54a085a2 100644 --- a/modules/core/src/math/matrix/vpMatrix_mul.cpp +++ b/modules/core/src/math/matrix/vpMatrix_mul.cpp @@ -29,8 +29,7 @@ * * Description: * BLAS subroutines. - * -*****************************************************************************/ + */ #include #include diff --git a/modules/core/src/math/matrix/vpMatrix_operations.cpp b/modules/core/src/math/matrix/vpMatrix_operations.cpp new file mode 100644 index 0000000000..7686e8cd57 --- /dev/null +++ b/modules/core/src/math/matrix/vpMatrix_operations.cpp @@ -0,0 +1,890 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Stack matrix. + */ + +#include +#include + +#if defined(VISP_HAVE_SIMDLIB) +#include +#endif + +BEGIN_VISP_NAMESPACE + +/*! + Compute and return the transpose of the matrix. +*/ +vpMatrix vpMatrix::t() const { return transpose(); } + +/*! + Compute and return the transpose of the matrix. + + \sa t() +*/ +vpMatrix vpMatrix::transpose() const +{ + vpMatrix At; + transpose(At); + return At; +} + +/*! + Compute \e At the transpose of the matrix. + \param At (output) : Resulting transpose matrix. + \sa t() +*/ +void vpMatrix::transpose(vpMatrix &At) const +{ + At.resize(colNum, rowNum, false, false); + + if ((rowNum <= 16) || (colNum <= 16)) { + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + At[j][i] = (*this)[i][j]; + } + } + } + else { +#if defined(VISP_HAVE_SIMDLIB) + SimdMatTranspose(data, rowNum, colNum, At.data); +#else + // https://stackoverflow.com/a/21548079 + const int tileSize = 32; + for (unsigned int i = 0; i < rowNum; i += tileSize) { + for (unsigned int j = 0; j < colNum; ++j) { + for (unsigned int b = 0; ((b < static_cast(tileSize)) && ((i + b) < rowNum)); ++b) { + At[j][i + b] = (*this)[i + b][j]; + } + } + } +#endif + } +} + +/*! + Operation w = A * v (v and w are vectors). + + A new matrix won't be allocated for every use of the function + (Speed gain if used many times with the same result matrix size). + + \sa operator*(const vpColVector &v) const +*/ +void vpMatrix::multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w) +{ + if (A.colNum != v.getRows()) { + throw(vpException(vpException::dimensionError, "Cannot multiply a (%dx%d) matrix by a (%d) column vector", + A.getRows(), A.getCols(), v.getRows())); + } + + if (A.rowNum != w.rowNum) { + w.resize(A.rowNum, false); + } + + // If available use Lapack only for large matrices + bool useLapack = ((A.rowNum > vpMatrix::m_lapack_min_size) || (A.colNum > vpMatrix::m_lapack_min_size)); +#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) + useLapack = false; +#endif + + if (useLapack) { +#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) + double alpha = 1.0; + double beta = 0.0; + char trans = 't'; + int incr = 1; + + vpMatrix::blas_dgemv(trans, A.colNum, A.rowNum, alpha, A.data, A.colNum, v.data, incr, beta, w.data, incr); +#endif + } + else { + w = 0.0; + for (unsigned int j = 0; j < A.colNum; ++j) { + double vj = v[j]; // optimization em 5/12/2006 + for (unsigned int i = 0; i < A.rowNum; ++i) { + w[i] += A.rowPtrs[i][j] * vj; + } + } + } +} + +//--------------------------------- +// Matrix operations. +//--------------------------------- + +/*! + Operation C = A * B. + + The result is placed in the third parameter C and not returned. + A new matrix won't be allocated for every use of the function + (speed gain if used many times with the same result matrix size). + + \sa operator*() +*/ +void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) +{ + if ((A.rowNum != C.rowNum) || (B.colNum != C.colNum)) { + C.resize(A.rowNum, B.colNum, false, false); + } + + if (A.colNum != B.rowNum) { + throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (%dx%d) matrix", A.getRows(), + A.getCols(), B.getRows(), B.getCols())); + } + + // If available use Lapack only for large matrices + bool useLapack = ((A.rowNum > vpMatrix::m_lapack_min_size) || (A.colNum > vpMatrix::m_lapack_min_size) || + (B.colNum > vpMatrix::m_lapack_min_size)); +#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) + useLapack = false; +#endif + + if (useLapack) { +#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) + const double alpha = 1.0; + const double beta = 0.0; + const char trans = 'n'; + vpMatrix::blas_dgemm(trans, trans, B.colNum, A.rowNum, A.colNum, alpha, B.data, B.colNum, A.data, A.colNum, beta, + C.data, B.colNum); +#endif + } + else { + // 5/12/06 some "very" simple optimization to avoid indexation + const unsigned int BcolNum = B.colNum; + const unsigned int BrowNum = B.rowNum; + double **BrowPtrs = B.rowPtrs; + for (unsigned int i = 0; i < A.rowNum; ++i) { + const double *rowptri = A.rowPtrs[i]; + double *ci = C[i]; + for (unsigned int j = 0; j < BcolNum; ++j) { + double s = 0; + for (unsigned int k = 0; k < BrowNum; ++k) { + s += rowptri[k] * BrowPtrs[k][j]; + } + ci[j] = s; + } + } + } +} + +/*! + \warning This function is provided for compat with previous releases. You + should rather use the functionalities provided in vpRotationMatrix class. + + Operation C = A * B. + + The result is placed in the third parameter C and not returned. + A new matrix won't be allocated for every use of the function + (speed gain if used many times with the same result matrix size). + + \exception vpException::dimensionError If matrices are not 3-by-3 dimension. +*/ +void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C) +{ + if ((A.colNum != 3) || (A.rowNum != 3) || (B.colNum != 3) || (B.rowNum != 3)) { + throw(vpException(vpException::dimensionError, + "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a " + "rotation matrix", + A.getRows(), A.getCols(), B.getRows(), B.getCols())); + } + // 5/12/06 some "very" simple optimization to avoid indexation + const unsigned int BcolNum = B.colNum; + const unsigned int BrowNum = B.rowNum; + double **BrowPtrs = B.rowPtrs; + for (unsigned int i = 0; i < A.rowNum; ++i) { + const double *rowptri = A.rowPtrs[i]; + double *ci = C[i]; + for (unsigned int j = 0; j < BcolNum; ++j) { + double s = 0; + for (unsigned int k = 0; k < BrowNum; ++k) { + s += rowptri[k] * BrowPtrs[k][j]; + } + ci[j] = s; + } + } +} + +/*! + \warning This function is provided for compat with previous releases. You + should rather use the functionalities provided in vpHomogeneousMatrix class. + + Operation C = A * B. + + The result is placed in the third parameter C and not returned. + A new matrix won't be allocated for every use of the function + (speed gain if used many times with the same result matrix size). + + \exception vpException::dimensionError If matrices are not 4-by-4 dimension. +*/ +void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C) +{ + if ((A.colNum != 4) || (A.rowNum != 4) || (B.colNum != 4) || (B.rowNum != 4)) { + throw(vpException(vpException::dimensionError, + "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a " + "rotation matrix", + A.getRows(), A.getCols(), B.getRows(), B.getCols())); + } + // Considering perfMatrixMultiplication.cpp benchmark, + // using either MKL, OpenBLAS, or Netlib can slow down this function with respect to the naive code. + // Lapack usage needs to be validated again. + // If available use Lapack only for large matrices. + // Using SSE2 doesn't speed up. + bool useLapack = ((A.rowNum > vpMatrix::m_lapack_min_size) || (A.colNum > vpMatrix::m_lapack_min_size) || + (B.colNum > vpMatrix::m_lapack_min_size)); +#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) + useLapack = false; +#endif + + if (useLapack) { +#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) + const double alpha = 1.0; + const double beta = 0.0; + const char trans = 'n'; + vpMatrix::blas_dgemm(trans, trans, B.colNum, A.rowNum, A.colNum, alpha, B.data, B.colNum, A.data, A.colNum, beta, + C.data, B.colNum); +#endif + } + else { + // 5/12/06 some "very" simple optimization to avoid indexation + const unsigned int BcolNum = B.colNum; + const unsigned int BrowNum = B.rowNum; + double **BrowPtrs = B.rowPtrs; + for (unsigned int i = 0; i < A.rowNum; ++i) { + const double *rowptri = A.rowPtrs[i]; + double *ci = C[i]; + for (unsigned int j = 0; j < BcolNum; ++j) { + double s = 0; + for (unsigned int k = 0; k < BrowNum; ++k) { + s += rowptri[k] * BrowPtrs[k][j]; + } + ci[j] = s; + } + } + } +} + +/*! + \warning This function is provided for compat with previous releases. You + should rather use multMatrixVector() that is more explicit. + + Operation C = A * B. + + The result is placed in the third parameter C and not returned. + A new matrix won't be allocated for every use of the function + (speed gain if used many times with the same result matrix size). + + \sa multMatrixVector() +*/ +void vpMatrix::mult2Matrices(const vpMatrix &A, const vpColVector &B, vpColVector &C) +{ + vpMatrix::multMatrixVector(A, B, C); +} + +/*! + Operation C = A*wA + B*wB + + The result is placed in the third parameter C and not returned. + A new matrix won't be allocated for every use of the function + (Speed gain if used many times with the same result matrix size). + + \sa operator+() +*/ + +void vpMatrix::add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB, + vpMatrix &C) +{ + if ((A.rowNum != C.rowNum) || (B.colNum != C.colNum)) { + C.resize(A.rowNum, B.colNum, false, false); + } + + if ((A.colNum != B.getCols()) || (A.rowNum != B.getRows())) { + throw(vpException(vpException::dimensionError, "Cannot add (%dx%d) matrix with (%dx%d) matrix", A.getRows(), + A.getCols(), B.getRows(), B.getCols())); + } + + double **ArowPtrs = A.rowPtrs; + double **BrowPtrs = B.rowPtrs; + double **CrowPtrs = C.rowPtrs; + + for (unsigned int i = 0; i < A.rowNum; ++i) { + for (unsigned int j = 0; j < A.colNum; ++j) { + CrowPtrs[i][j] = (wB * BrowPtrs[i][j]) + (wA * ArowPtrs[i][j]); + } + } +} + +/*! + Operation C = A + B. + + The result is placed in the third parameter C and not returned. + A new matrix won't be allocated for every use of the function + (speed gain if used many times with the same result matrix size). + + \sa operator+() +*/ +void vpMatrix::add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) +{ + if ((A.rowNum != C.rowNum) || (B.colNum != C.colNum)) { + C.resize(A.rowNum, B.colNum, false, false); + } + + if ((A.colNum != B.getCols()) || (A.rowNum != B.getRows())) { + throw(vpException(vpException::dimensionError, "Cannot add (%dx%d) matrix with (%dx%d) matrix", A.getRows(), + A.getCols(), B.getRows(), B.getCols())); + } + + double **ArowPtrs = A.rowPtrs; + double **BrowPtrs = B.rowPtrs; + double **CrowPtrs = C.rowPtrs; + + for (unsigned int i = 0; i < A.rowNum; ++i) { + for (unsigned int j = 0; j < A.colNum; ++j) { + CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j]; + } + } +} + +/*! + \warning This function is provided for compat with previous releases. You + should rather use the functionalities provided in vpColVector class. + + Operation C = A + B. + + The result is placed in the third parameter C and not returned. + A new vector won't be allocated for every use of the function + (speed gain if used many times with the same result matrix size). + + \sa vpColVector::operator+() +*/ +void vpMatrix::add2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C) +{ + if ((A.rowNum != C.rowNum) || (B.colNum != C.colNum)) { + C.resize(A.rowNum); + } + + if ((A.colNum != B.getCols()) || (A.rowNum != B.getRows())) { + throw(vpException(vpException::dimensionError, "Cannot add (%dx%d) matrix with (%dx%d) matrix", A.getRows(), + A.getCols(), B.getRows(), B.getCols())); + } + + double **ArowPtrs = A.rowPtrs; + double **BrowPtrs = B.rowPtrs; + double **CrowPtrs = C.rowPtrs; + + for (unsigned int i = 0; i < A.rowNum; ++i) { + for (unsigned int j = 0; j < A.colNum; ++j) { + CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j]; + } + } +} + +/*! + \warning This function is provided for compat with previous releases. You + should rather use the functionalities provided in vpColVector class. + + Operation C = A - B on column vectors. + + The result is placed in the third parameter C and not returned. + A new vector won't be allocated for every use of the function + (speed gain if used many times with the same result matrix size). + + \exception vpException::dimensionError If A and B vectors have not the same + size. + + \sa vpColVector::operator-() +*/ +void vpMatrix::sub2Matrices(const vpColVector &A, const vpColVector &B, vpColVector &C) +{ + if ((A.rowNum != C.rowNum) || (A.colNum != C.colNum)) { + C.resize(A.rowNum); + } + + if ((A.colNum != B.getCols()) || (A.rowNum != B.getRows())) { + throw(vpException(vpException::dimensionError, "Cannot subtract (%dx%d) matrix to (%dx%d) matrix", A.getRows(), + A.getCols(), B.getRows(), B.getCols())); + } + + double **ArowPtrs = A.rowPtrs; + double **BrowPtrs = B.rowPtrs; + double **CrowPtrs = C.rowPtrs; + + for (unsigned int i = 0; i < A.rowNum; ++i) { + for (unsigned int j = 0; j < A.colNum; ++j) { + CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j]; + } + } +} + +/*! + Operation C = A - B. + + The result is placed in the third parameter C and not returned. + A new matrix won't be allocated for every use of the function + (speed gain if used many times with the same result matrix size). + + \exception vpException::dimensionError If A and B matrices have not the same + size. + + \sa operator-() +*/ +void vpMatrix::sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) +{ + if ((A.rowNum != C.rowNum) || (A.colNum != C.colNum)) { + C.resize(A.rowNum, A.colNum, false, false); + } + + if ((A.colNum != B.getCols()) || (A.rowNum != B.getRows())) { + throw(vpException(vpException::dimensionError, "Cannot subtract (%dx%d) matrix to (%dx%d) matrix", A.getRows(), + A.getCols(), B.getRows(), B.getCols())); + } + + double **ArowPtrs = A.rowPtrs; + double **BrowPtrs = B.rowPtrs; + double **CrowPtrs = C.rowPtrs; + + for (unsigned int i = 0; i < A.rowNum; ++i) { + for (unsigned int j = 0; j < A.colNum; ++j) { + CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j]; + } + } +} + +/*! + Operation C = -A. + + The result is placed in the second parameter C and not returned. + A new matrix won't be allocated for every use of the function + (Speed gain if used many times with the same result matrix size). + + \sa operator-(void) +*/ +void vpMatrix::negateMatrix(const vpMatrix &A, vpMatrix &C) +{ + if ((A.rowNum != C.rowNum) || (A.colNum != C.colNum)) { + C.resize(A.rowNum, A.colNum, false, false); + } + + double **ArowPtrs = A.rowPtrs; + double **CrowPtrs = C.rowPtrs; + + for (unsigned int i = 0; i < A.rowNum; ++i) { + for (unsigned int j = 0; j < A.colNum; ++j) { + CrowPtrs[i][j] = -ArowPtrs[i][j]; + } + } +} + +/*! + Computes the \f$AA^T\f$ operation \f$B = A*A^T\f$ + \return \f$A*A^T\f$ + \sa AAt(vpMatrix &) const +*/ +vpMatrix vpMatrix::AAt() const +{ + vpMatrix B; + + AAt(B); + + return B; +} + +/*! + Compute the AAt operation such as \f$B = A*A^T\f$. + + The result is placed in the parameter \e B and not returned. + + A new matrix won't be allocated for every use of the function. This + results in a speed gain if used many times with the same result + matrix size. + + \sa AAt() +*/ +void vpMatrix::AAt(vpMatrix &B) const +{ + if ((B.rowNum != rowNum) || (B.colNum != rowNum)) { + B.resize(rowNum, rowNum, false, false); + } + + // If available use Lapack only for large matrices + bool useLapack = ((rowNum > vpMatrix::m_lapack_min_size) || (colNum > vpMatrix::m_lapack_min_size)); +#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) + useLapack = false; +#endif + + if (useLapack) { +#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) + const double alpha = 1.0; + const double beta = 0.0; + const char transa = 't'; + const char transb = 'n'; + + vpMatrix::blas_dgemm(transa, transb, rowNum, rowNum, colNum, alpha, data, colNum, data, colNum, beta, B.data, + rowNum); +#endif + } + else { + // compute A*A^T + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = i; j < rowNum; ++j) { + double *pi = rowPtrs[i]; // row i + double *pj = rowPtrs[j]; // row j + + // sum (row i .* row j) + double ssum = 0; + for (unsigned int k = 0; k < colNum; ++k) { + ssum += *(pi++) * *(pj++); + } + + B[i][j] = ssum; // upper triangle + if (i != j) { + B[j][i] = ssum; // lower triangle + } + } + } + } +} + +/*! + Compute the AtA operation such as \f$B = A^T*A\f$. + + The result is placed in the parameter \e B and not returned. + + A new matrix won't be allocated for every use of the function. This + results in a speed gain if used many times with the same result matrix + size. + + \sa AtA() +*/ +void vpMatrix::AtA(vpMatrix &B) const +{ + if ((B.rowNum != colNum) || (B.colNum != colNum)) { + B.resize(colNum, colNum, false, false); + } + + // If available use Lapack only for large matrices + bool useLapack = ((rowNum > vpMatrix::m_lapack_min_size) || (colNum > vpMatrix::m_lapack_min_size)); +#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) + useLapack = false; +#endif + + if (useLapack) { +#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) + const double alpha = 1.0; + const double beta = 0.0; + const char transa = 'n'; + const char transb = 't'; + + vpMatrix::blas_dgemm(transa, transb, colNum, colNum, rowNum, alpha, data, colNum, data, colNum, beta, B.data, + colNum); +#endif + } + else { + for (unsigned int i = 0; i < colNum; ++i) { + double *Bi = B[i]; + for (unsigned int j = 0; j < i; ++j) { + double *ptr = data; + double s = 0; + for (unsigned int k = 0; k < rowNum; ++k) { + s += (*(ptr + i)) * (*(ptr + j)); + ptr += colNum; + } + *Bi++ = s; + B[j][i] = s; + } + double *ptr = data; + double s = 0; + for (unsigned int k = 0; k < rowNum; ++k) { + s += (*(ptr + i)) * (*(ptr + i)); + ptr += colNum; + } + *Bi = s; + } + } +} + +/*! + Compute the AtA operation such as \f$B = A^T*A\f$ + \return \f$A^T*A\f$ + \sa AtA(vpMatrix &) const +*/ +vpMatrix vpMatrix::AtA() const +{ + vpMatrix B; + + AtA(B); + + return B; +} + +/*! + Create a diagonal matrix with the element of a vector. + + \param A : Vector which element will be put in the diagonal. + + \sa createDiagonalMatrix() + + \code + #include + + #include + #include + + int main() + { + vpMatrix A; + vpColVector v(3); + + v[0] = 1; + v[1] = 2; + v[2] = 3; + + A.diag(v); + + std::cout << "A:\n" << A << std::endl; + } + \endcode + + Matrix A is now equal to: + \code + 1 0 0 + 0 2 0 + 0 0 3 + \endcode +*/ +void vpMatrix::diag(const vpColVector &A) +{ + unsigned int rows = A.getRows(); + this->resize(rows, rows); + + (*this) = 0; + for (unsigned int i = 0; i < rows; ++i) { + (*this)[i][i] = A[i]; + } +} + +/*! + Set the matrix as a diagonal matrix where each element on the diagonal is + set to \e val. Elements that are not on the diagonal are set to 0. + + \param val : Value to set. + + \sa eye() + + \code + #include + + #include + + int main() + { + vpMatrix A(3, 4); + + A.diag(2); + + std::cout << "A:\n" << A << std::endl; + } + \endcode + + Matrix A is now equal to: + \code + 2 0 0 0 + 0 2 0 0 + 0 0 2 0 + \endcode +*/ +void vpMatrix::diag(const double &val) +{ + (*this) = 0; + unsigned int min_ = (rowNum < colNum) ? rowNum : colNum; + for (unsigned int i = 0; i < min_; ++i) { + (*this)[i][i] = val; + } +} + +/*! + Create a diagonal matrix with the element of a vector \f$ DA_{ii} = A_i \f$. + + \param A : Vector which element will be put in the diagonal. + + \param DA : Diagonal matrix DA[i][i] = A[i] + + \sa diag() +*/ + +void vpMatrix::createDiagonalMatrix(const vpColVector &A, vpMatrix &DA) +{ + unsigned int rows = A.getRows(); + DA.resize(rows, rows, true); + + for (unsigned int i = 0; i < rows; ++i) { + DA[i][i] = A[i]; + } +} + +/*! + Set an n-by-n matrix to identity with ones on the diagonal and zeros + else where. +*/ +void vpMatrix::eye(unsigned int n) { eye(n, n); } + +/*! + Set an m-by-n matrix to identity with ones on the diagonal and zeros + else where. +*/ +void vpMatrix::eye(unsigned int m, unsigned int n) +{ + resize(m, n); + + eye(); +} + +/*! + Set an m-by-n matrix to identity with ones on the diagonal and zeros + else where. +*/ +void vpMatrix::eye() +{ + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + if (i == j) { + (*this)[i][j] = 1.0; + } + else { + (*this)[i][j] = 0; + } + } + } +} + +/*! + Compute the Hadamard product (element wise matrix multiplication). + \param m : Second matrix; + \return m1.hadamard(m2) The Hadamard product : + \f$ m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j} \f$ +*/ +vpMatrix vpMatrix::hadamard(const vpMatrix &m) const +{ + if ((m.getRows() != rowNum) || (m.getCols() != colNum)) { + throw(vpException(vpException::dimensionError, "In Hadamard product: bad dimension of input matrix")); + } + + vpMatrix out; + out.resize(rowNum, colNum, false, false); + +#if defined(VISP_HAVE_SIMDLIB) + SimdVectorHadamard(data, m.data, dsize, out.data); +#else + for (unsigned int i = 0; i < dsize; ++i) { + out.data[i] = data[i] * m.data[i]; + } +#endif + + return out; +} + +/*! + Compute Kronecker product matrix. + \param m1 : vpMatrix; + \param m2 : vpMatrix; + \param out : The kronecker product : \f$ m1 \otimes m2 \f$ +*/ +void vpMatrix::kron(const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out) +{ + unsigned int r1 = m1.getRows(); + unsigned int c1 = m1.getCols(); + unsigned int r2 = m2.getRows(); + unsigned int c2 = m2.getCols(); + + out.resize(r1 * r2, c1 * c2, false, false); + + for (unsigned int r = 0; r < r1; ++r) { + for (unsigned int c = 0; c < c1; ++c) { + double alpha = m1[r][c]; + double *m2ptr = m2[0]; + unsigned int roffset = r * r2; + unsigned int coffset = c * c2; + for (unsigned int rr = 0; rr < r2; ++rr) { + for (unsigned int cc = 0; cc < c2; ++cc) { + out[roffset + rr][coffset + cc] = alpha * *(m2ptr++); + } + } + } + } +} + +/*! + Compute Kronecker product matrix. + \param m : vpMatrix. + \param out : If m1.kron(m2) out contains the kronecker product's result : + \f$ m1 \otimes m2 \f$. +*/ +void vpMatrix::kron(const vpMatrix &m, vpMatrix &out) const { kron(*this, m, out); } + +/*! + Compute Kronecker product matrix. + \param m1 : vpMatrix; + \param m2 : vpMatrix; + \return The kronecker product : \f$ m1 \otimes m2 \f$ +*/ +vpMatrix vpMatrix::kron(const vpMatrix &m1, const vpMatrix &m2) +{ + unsigned int r1 = m1.getRows(); + unsigned int c1 = m1.getCols(); + unsigned int r2 = m2.getRows(); + unsigned int c2 = m2.getCols(); + + vpMatrix out; + out.resize(r1 * r2, c1 * c2, false, false); + + for (unsigned int r = 0; r < r1; ++r) { + for (unsigned int c = 0; c < c1; ++c) { + double alpha = m1[r][c]; + double *m2ptr = m2[0]; + unsigned int roffset = r * r2; + unsigned int coffset = c * c2; + for (unsigned int rr = 0; rr < r2; ++rr) { + for (unsigned int cc = 0; cc < c2; ++cc) { + out[roffset + rr][coffset + cc] = alpha * *(m2ptr++); + } + } + } + } + return out; +} + +/*! + Compute Kronecker product matrix. + \param m : vpMatrix; + \return m1.kron(m2) The kronecker product : \f$ m1 \otimes m2 \f$ +*/ +vpMatrix vpMatrix::kron(const vpMatrix &m) const { return kron(*this, m); } + +END_VISP_NAMESPACE diff --git a/modules/core/src/math/matrix/vpMatrix_operators.cpp b/modules/core/src/math/matrix/vpMatrix_operators.cpp new file mode 100644 index 0000000000..bd575192ff --- /dev/null +++ b/modules/core/src/math/matrix/vpMatrix_operators.cpp @@ -0,0 +1,668 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Stack matrix. + */ + +#include +#include + +#if defined(VISP_HAVE_SIMDLIB) +#include +#endif + +BEGIN_VISP_NAMESPACE + +/*! + Copy operator that allows to convert on of the following container that + inherit from vpArray2D such as vpMatrix, vpRotationMatrix, + vpHomogeneousMatrix, vpPoseVector, vpColVector, vpRowVector... into a + vpMatrix. + + \param A : 2D array to be copied. + + The following example shows how to create a matrix from an homogeneous + matrix: + \code + vpRotationMatrix R; + vpMatrix M = R; + \endcode + +*/ +vpMatrix &vpMatrix::operator=(const vpArray2D &A) +{ + resize(A.getRows(), A.getCols(), false, false); + + if ((data != nullptr) && (A.data != nullptr) && (data != A.data)) { + memcpy(data, A.data, dsize * sizeof(double)); + } + + return *this; +} + +vpMatrix &vpMatrix::operator=(const vpMatrix &A) +{ + resize(A.getRows(), A.getCols(), false, false); + + if ((data != nullptr) && (A.data != nullptr) && (data != A.data)) { + memcpy(data, A.data, dsize * sizeof(double)); + } + + return *this; +} + +#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) +vpMatrix &vpMatrix::operator=(vpMatrix &&other) +{ + if (this != &other) { + if (data) { + free(data); + } + if (rowPtrs) { + free(rowPtrs); + } + + rowNum = other.rowNum; + colNum = other.colNum; + rowPtrs = other.rowPtrs; + dsize = other.dsize; + data = other.data; + + other.rowNum = 0; + other.colNum = 0; + other.rowPtrs = nullptr; + other.dsize = 0; + other.data = nullptr; + } + + return *this; +} + +/*! + Set matrix elements from a list of values. + \param list : List of double. Matrix size (number of columns multiplied by number of columns) should match the number + of elements. + + \return The modified Matrix. The following example shows how to set each element of a 2-by-3 matrix. + + \code + #include + + int main() + { + vpMatrix M; + M = { -1, -2, -3, -4, -5, -6 }; + M.reshape(2, 3); + std::cout << "M:\n" << M << std::endl; + } + \endcode + It produces the following printings: + \code + M: + -1 -2 -3 + -4 -5 -6 + \endcode + \sa operator<<() + */ +vpMatrix &vpMatrix::operator=(const std::initializer_list &list) +{ + if (dsize != static_cast(list.size())) { + resize(1, static_cast(list.size()), false, false); + } + + std::copy(list.begin(), list.end(), data); + + return *this; +} + +/*! + Set matrix elements from a list of values. + \param lists : List of double. + \return The modified Matrix. + The following example shows how to set each element of a 2-by-3 matrix. + \code + #include + + int main() + { + vpMatrix M; + M = { {-1, -2, -3}, {-4, -5, -6} }; + std::cout << "M:\n" << M << std::endl; + } + \endcode + It produces the following printings: + \code + M: + -1 -2 -3 + -4 -5 -6 + \endcode + \sa operator<<() + */ +vpMatrix &vpMatrix::operator=(const std::initializer_list > &lists) +{ + unsigned int nrows = static_cast(lists.size()), ncols = 0; + for (auto &l : lists) { + if (static_cast(l.size()) > ncols) { + ncols = static_cast(l.size()); + } + } + + resize(nrows, ncols, false, false); + auto it = lists.begin(); + for (unsigned int i = 0; i < rowNum; ++i, ++it) { + std::copy(it->begin(), it->end(), rowPtrs[i]); + } + + return *this; +} +#endif + +//! Set all the element of the matrix A to \e x. +vpMatrix &vpMatrix::operator=(double x) +{ + std::fill(data, data + (rowNum * colNum), x); + return *this; +} + +/*! + Assignment from an array of double. This method has to be used carefully + since the array allocated behind \e x pointer should have the same dimension + than the matrix. +*/ +vpMatrix &vpMatrix::operator<<(double *x) +{ + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + rowPtrs[i][j] = *x++; + } + } + return *this; +} + +vpMatrix &vpMatrix::operator<<(double val) +{ + resize(1, 1, false, false); + rowPtrs[0][0] = val; + return *this; +} + +vpMatrix &vpMatrix::operator,(double val) +{ + resize(1, colNum + 1, false, false); + rowPtrs[0][colNum - 1] = val; + return *this; +} + +/*! + Operator that allows to multiply a matrix by a translation vector. + The matrix should be of dimension (3x3) +*/ +vpTranslationVector vpMatrix::operator*(const vpTranslationVector &tv) const +{ + vpTranslationVector t_out; + + if ((rowNum != 3) || (colNum != 3)) { + throw(vpException(vpException::dimensionError, "Cannot multiply a (%dx%d) matrix by a (%dx%d) translation vector", + rowNum, colNum, tv.getRows(), tv.getCols())); + } + + const unsigned int val_3 = 3; + for (unsigned int j = 0; j < val_3; ++j) { + t_out[j] = 0; + } + + for (unsigned int j = 0; j < val_3; ++j) { + double tj = tv[j]; // optimization em 5/12/2006 + for (unsigned int i = 0; i < val_3; ++i) { + t_out[i] += rowPtrs[i][j] * tj; + } + } + return t_out; +} + +/*! + Operation w = A * v (matrix A is unchanged, v and w are column vectors). + \sa multMatrixVector() to avoid matrix allocation for each use. +*/ +vpColVector vpMatrix::operator*(const vpColVector &v) const +{ + vpColVector v_out; + vpMatrix::multMatrixVector(*this, v, v_out); + return v_out; +} + +/*! + Operation C = A * B (A is unchanged). + \sa mult2Matrices() to avoid matrix allocation for each use. +*/ +vpMatrix vpMatrix::operator*(const vpMatrix &B) const +{ + vpMatrix C; + + vpMatrix::mult2Matrices(*this, B, C); + + return C; +} + +/*! + Operator that allow to multiply a matrix by a rotation matrix. + The matrix should be of dimension m-by-3. +*/ +vpMatrix vpMatrix::operator*(const vpRotationMatrix &R) const +{ + if (colNum != R.getRows()) { + throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (3x3) rotation matrix", rowNum, + colNum)); + } + vpMatrix C; + C.resize(rowNum, 3, false, false); + + unsigned int RcolNum = R.getCols(); + unsigned int RrowNum = R.getRows(); + for (unsigned int i = 0; i < rowNum; ++i) { + double *rowptri = rowPtrs[i]; + double *ci = C[i]; + for (unsigned int j = 0; j < RcolNum; ++j) { + double s = 0; + for (unsigned int k = 0; k < RrowNum; ++k) { + s += rowptri[k] * R[k][j]; + } + ci[j] = s; + } + } + + return C; +} + +/*! + Operator that allow to multiply a matrix by a homogeneous matrix. + The matrix should be of dimension m-by-4. +*/ +vpMatrix vpMatrix::operator*(const vpHomogeneousMatrix &M) const +{ + if (colNum != M.getRows()) { + throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (3x3) rotation matrix", rowNum, + colNum)); + } + vpMatrix C; + C.resize(rowNum, 4, false, false); + + const unsigned int McolNum = M.getCols(); + const unsigned int MrowNum = M.getRows(); + for (unsigned int i = 0; i < rowNum; ++i) { + const double *rowptri = rowPtrs[i]; + double *ci = C[i]; + for (unsigned int j = 0; j < McolNum; ++j) { + double s = 0; + for (unsigned int k = 0; k < MrowNum; ++k) { + s += rowptri[k] * M[k][j]; + } + ci[j] = s; + } + } + + return C; +} + + +/*! + Operator that allow to multiply a matrix by a velocity twist matrix. + The matrix should be of dimension m-by-6. +*/ +vpMatrix vpMatrix::operator*(const vpVelocityTwistMatrix &V) const +{ + if (colNum != V.getRows()) { + throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (6x6) velocity twist matrix", + rowNum, colNum)); + } + vpMatrix M; + M.resize(rowNum, 6, false, false); + + // Considering perfMatrixMultiplication.cpp benchmark, + // using either MKL, OpenBLAS, or Netlib can slow down this function with respect to the naive code. + // Lapack usage needs to be validated again. + // If available use Lapack only for large matrices. + // Speed up obtained using SSE2. + bool useLapack = ((rowNum > vpMatrix::m_lapack_min_size) || (colNum > vpMatrix::m_lapack_min_size) || + (V.colNum > vpMatrix::m_lapack_min_size)); +#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) + useLapack = false; +#endif + + if (useLapack) { +#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) + const double alpha = 1.0; + const double beta = 0.0; + const char trans = 'n'; + vpMatrix::blas_dgemm(trans, trans, V.colNum, rowNum, colNum, alpha, V.data, V.colNum, data, colNum, beta, M.data, + M.colNum); +#endif + } + else { +#if defined(VISP_HAVE_SIMDLIB) + SimdMatMulTwist(data, rowNum, V.data, M.data); +#else + unsigned int VcolNum = V.getCols(); + unsigned int VrowNum = V.getRows(); + for (unsigned int i = 0; i < rowNum; ++i) { + double *rowptri = rowPtrs[i]; + double *ci = M[i]; + for (unsigned int j = 0; j < VcolNum; ++j) { + double s = 0; + for (unsigned int k = 0; k < VrowNum; ++k) { + s += rowptri[k] * V[k][j]; + } + ci[j] = s; + } + } +#endif + } + + return M; +} + +/*! + Operator that allow to multiply a matrix by a force/torque twist matrix. + The matrix should be of dimension m-by-6. +*/ +vpMatrix vpMatrix::operator*(const vpForceTwistMatrix &V) const +{ + if (colNum != V.getRows()) { + throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (6x6) force/torque twist matrix", + rowNum, colNum)); + } + vpMatrix M; + M.resize(rowNum, 6, false, false); + + // Considering perfMatrixMultiplication.cpp benchmark, + // using either MKL, OpenBLAS, or Netlib can slow down this function with respect to the naive code. + // Lapack usage needs to be validated again. + // If available use Lapack only for large matrices. + // Speed up obtained using SSE2. + bool useLapack = ((rowNum > vpMatrix::m_lapack_min_size) || (colNum > vpMatrix::m_lapack_min_size) || + (V.getCols() > vpMatrix::m_lapack_min_size)); +#if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) + useLapack = false; +#endif + + if (useLapack) { +#if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) + const double alpha = 1.0; + const double beta = 0.0; + const char trans = 'n'; + vpMatrix::blas_dgemm(trans, trans, V.getCols(), rowNum, colNum, alpha, V.data, V.getCols(), data, colNum, beta, + M.data, M.colNum); +#endif + } + else { +#if defined(VISP_HAVE_SIMDLIB) + SimdMatMulTwist(data, rowNum, V.data, M.data); +#else + unsigned int VcolNum = V.getCols(); + unsigned int VrowNum = V.getRows(); + for (unsigned int i = 0; i < rowNum; ++i) { + double *rowptri = rowPtrs[i]; + double *ci = M[i]; + for (unsigned int j = 0; j < VcolNum; ++j) { + double s = 0; + for (unsigned int k = 0; k < VrowNum; ++k) { + s += rowptri[k] * V[k][j]; + } + ci[j] = s; + } + } +#endif + } + + return M; +} + +/*! + Operation C = A + B (A is unchanged). + \sa add2Matrices() to avoid matrix allocation for each use. +*/ +vpMatrix vpMatrix::operator+(const vpMatrix &B) const +{ + vpMatrix C; + vpMatrix::add2Matrices(*this, B, C); + return C; +} + +/*! + Operation C = A - B (A is unchanged). + \sa sub2Matrices() to avoid matrix allocation for each use. +*/ +vpMatrix vpMatrix::operator-(const vpMatrix &B) const +{ + vpMatrix C; + vpMatrix::sub2Matrices(*this, B, C); + return C; +} + +//! Operation A = A + B + +vpMatrix &vpMatrix::operator+=(const vpMatrix &B) +{ + if ((colNum != B.getCols()) || (rowNum != B.getRows())) { + throw(vpException(vpException::dimensionError, "Cannot add (%dx%d) matrix to (%dx%d) matrix", rowNum, colNum, + B.getRows(), B.getCols())); + } + + double **BrowPtrs = B.rowPtrs; + + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + rowPtrs[i][j] += BrowPtrs[i][j]; + } + } + + return *this; +} + +//! Operation A = A - B +vpMatrix &vpMatrix::operator-=(const vpMatrix &B) +{ + if ((colNum != B.getCols()) || (rowNum != B.getRows())) { + throw(vpException(vpException::dimensionError, "Cannot subtract (%dx%d) matrix to (%dx%d) matrix", rowNum, colNum, + B.getRows(), B.getCols())); + } + + double **BrowPtrs = B.rowPtrs; + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + rowPtrs[i][j] -= BrowPtrs[i][j]; + } + } + + return *this; +} + +/*! + Operation C = -A (A is unchanged). + \sa negateMatrix() to avoid matrix allocation for each use. +*/ +vpMatrix vpMatrix::operator-() const // negate +{ + vpMatrix C; + vpMatrix::negateMatrix(*this, C); + return C; +} + +double vpMatrix::sum() const +{ + double s = 0.0; + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + s += rowPtrs[i][j]; + } + } + + return s; +} + +/*! + Operator that allows to multiply all the elements of a matrix + by a scalar. + */ +vpMatrix vpMatrix::operator*(double x) const +{ + if (std::fabs(x - 1.) < std::numeric_limits::epsilon()) { + return *this; + } + + vpMatrix M; + M.resize(rowNum, colNum, false, false); + + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + M[i][j] = rowPtrs[i][j] * x; + } + } + + return M; +} + + +//! Cij = Aij / x (A is unchanged) +vpMatrix vpMatrix::operator/(double x) const +{ + if (std::fabs(x - 1.) < std::numeric_limits::epsilon()) { + return *this; + } + + if (std::fabs(x) < std::numeric_limits::epsilon()) { + throw vpException(vpException::divideByZeroError, "Divide matrix by zero scalar"); + } + + vpMatrix C; + C.resize(rowNum, colNum, false, false); + + double xinv = 1 / x; + + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + C[i][j] = rowPtrs[i][j] * xinv; + } + } + + return C; +} + +//! Add x to all the element of the matrix : Aij = Aij + x +vpMatrix &vpMatrix::operator+=(double x) +{ + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + rowPtrs[i][j] += x; + } + } + + return *this; +} + +//! subtract x to all the element of the matrix : Aij = Aij - x +vpMatrix &vpMatrix::operator-=(double x) +{ + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + rowPtrs[i][j] -= x; + } + } + + return *this; +} + +/*! + Operator that allows to multiply all the elements of a matrix + by a scalar. + */ +vpMatrix &vpMatrix::operator*=(double x) +{ + if (std::fabs(x - 1.) < std::numeric_limits::epsilon()) { + return *this; + } + + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + rowPtrs[i][j] *= x; + } + } + + return *this; +} + +//! Divide all the element of the matrix by x : Aij = Aij / x +vpMatrix &vpMatrix::operator/=(double x) +{ + if (std::fabs(x - 1.) < std::numeric_limits::epsilon()) { + return *this; + } + + if (std::fabs(x) < std::numeric_limits::epsilon()) { + throw vpException(vpException::divideByZeroError, "Divide matrix by zero scalar"); + } + + double xinv = 1 / x; + + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < colNum; ++j) { + rowPtrs[i][j] *= xinv; + } + } + + return *this; +} + +/*! + \relates vpMatrix + Allow to multiply a scalar by a matrix. +*/ +vpMatrix operator*(const double &x, const vpMatrix &B) +{ + if (std::fabs(x - 1.) < std::numeric_limits::epsilon()) { + return B; + } + + unsigned int Brow = B.getRows(); + unsigned int Bcol = B.getCols(); + + VISP_NAMESPACE_ADDRESSING vpMatrix C; + C.resize(Brow, Bcol, false, false); + + for (unsigned int i = 0; i < Brow; ++i) { + for (unsigned int j = 0; j < Bcol; ++j) { + C[i][j] = B[i][j] * x; + } + } + + return C; +} + +END_VISP_NAMESPACE diff --git a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp new file mode 100644 index 0000000000..50df681246 --- /dev/null +++ b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp @@ -0,0 +1,973 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Pseudo inverse computation. + */ + +#include +#include + +#if defined(VISP_HAVE_SIMDLIB) +#include +#endif + +#ifdef VISP_HAVE_LAPACK +#ifdef VISP_HAVE_GSL +#include +#include +#include +#elif defined(VISP_HAVE_MKL) +#include +#endif +#endif + +BEGIN_VISP_NAMESPACE + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + +void compute_pseudo_inverse(const vpMatrix &U, const vpColVector &sv, const vpMatrix &V, unsigned int nrows, + unsigned int ncols, double svThreshold, vpMatrix &Ap, int &rank_out, int *rank_in, + vpMatrix *imA, vpMatrix *imAt, vpMatrix *kerAt) +{ + Ap.resize(ncols, nrows, true, false); + + // compute the highest singular value and the rank of h + double maxsv = sv[0]; + + rank_out = 0; + + unsigned int sv_size = sv.size(); + for (unsigned int i = 0; i < sv_size; ++i) { + if (sv[i] >(maxsv * svThreshold)) { + ++rank_out; + } + } + + unsigned int rank = static_cast(rank_out); + if (rank_in) { + rank = static_cast(*rank_in); + } + + for (unsigned int i = 0; i < ncols; ++i) { + for (unsigned int j = 0; j < nrows; ++j) { + for (unsigned int k = 0; k < rank; ++k) { + Ap[i][j] += (V[i][k] * U[j][k]) / sv[k]; + } + } + } + + // Compute im(A) + if (imA) { + imA->resize(nrows, rank); + + for (unsigned int i = 0; i < nrows; ++i) { + for (unsigned int j = 0; j < rank; ++j) { + (*imA)[i][j] = U[i][j]; + } + } + } + + // Compute im(At) + if (imAt) { + imAt->resize(ncols, rank); + for (unsigned int i = 0; i < ncols; ++i) { + for (unsigned int j = 0; j < rank; ++j) { + (*imAt)[i][j] = V[i][j]; + } + } + } + + // Compute ker(At) + if (kerAt) { + kerAt->resize(ncols - rank, ncols); + if (rank != ncols) { + unsigned int v_rows = V.getRows(); + for (unsigned int k = 0; k < (ncols - rank); ++k) { + unsigned j = k + rank; + for (unsigned int i = 0; i < v_rows; ++i) { + (*kerAt)[k][i] = V[i][j]; + } + } + } + } +} + +#endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ and return the rank of the matrix. + + \note By default, this function uses Lapack 3rd party. It is also possible + to use a specific 3rd party suffixing this function name with one of the + following 3rd party names (Lapack, Eigen3 or OpenCV). + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The rank of the matrix. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + unsigned int rank = A.pseudoInverse(A_p); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank: " << rank << std::endl; + } + \endcode + + Once build, the previous example produces the following output: + \code + A: [2,3]= + 2 3 5 + -4 2 3 + A^+ (pseudo-inverse): [3,2]= + 0.117899 -0.190782 + 0.065380 0.039657 + 0.113612 0.052518 + Rank: 2 + \endcode +*/ +unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, double svThreshold) const +{ +#if defined(VISP_HAVE_LAPACK) + return pseudoInverseLapack(Ap, svThreshold); +#elif defined(VISP_HAVE_EIGEN3) + return pseudoInverseEigen3(Ap, svThreshold); +#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 + return pseudoInverseOpenCV(Ap, svThreshold); +#else + (void)Ap; + (void)svThreshold; + throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " + "Install Lapack, Eigen3 or OpenCV 3rd party")); +#endif +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ and return the rank of the matrix. + + \note By default, this function uses Lapack 3rd party. It is also possible + to use a specific 3rd party suffixing this function name with one of the + following 3rd party names (Lapack, Eigen3 or OpenCV). + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param[in] rank_in : Known rank of the matrix. + + \return The rank of the matrix. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + // This matrix rank is 2 + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + int rank_in = 2; + int rank_out = A.pseudoInverse(A_p, rank_in); + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + } + \endcode + + Once build, the previous example produces the following output: + \code + A: [2,3]= + 2 3 5 + -4 2 3 + A^+ (pseudo-inverse): [3,2]= + 0.117899 -0.190782 + 0.065380 0.039657 + 0.113612 0.052518 + Rank in : 2 + Rank out: 2 + \endcode +*/ +int vpMatrix::pseudoInverse(vpMatrix &Ap, int rank_in) const +{ +#if defined(VISP_HAVE_LAPACK) + return pseudoInverseLapack(Ap, rank_in); +#elif defined(VISP_HAVE_EIGEN3) + return pseudoInverseEigen3(Ap, rank_in); +#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 + return pseudoInverseOpenCV(Ap, rank_in); +#else + (void)Ap; + (void)rank_in; + throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " + "Install Lapack, Eigen3 or OpenCV 3rd party")); +#endif +} + +/*! + Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n + matrix \f$\bf A\f$. + + \note By default, this function uses Lapack 3rd party. It is also possible + to use a specific 3rd party suffixing this function name with one of the + following 3rd party names (Lapack, Eigen3 or OpenCV). + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The Moore-Penros pseudo inverse \f$ A^+ \f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p = A.pseudoInverse(); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + } + \endcode + + Once build, the previous example produces the following output: + \code + A: [2,3]= + 2 3 5 + -4 2 3 + A^+ (pseudo-inverse): [3,2]= + 0.117899 -0.190782 + 0.065380 0.039657 + 0.113612 0.052518 + \endcode + +*/ +vpMatrix vpMatrix::pseudoInverse(double svThreshold) const +{ +#if defined(VISP_HAVE_LAPACK) + return pseudoInverseLapack(svThreshold); +#elif defined(VISP_HAVE_EIGEN3) + return pseudoInverseEigen3(svThreshold); +#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 + return pseudoInverseOpenCV(svThreshold); +#else + (void)svThreshold; + throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " + "Install Lapack, Eigen3 or OpenCV 3rd party")); +#endif +} + +/*! + Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n + matrix \f$\bf A\f$. + + \note By default, this function uses Lapack 3rd party. It is also possible + to use a specific 3rd party suffixing this function name with one of the + following 3rd party names (Lapack, Eigen3 or OpenCV). + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param[in] rank_in : Known rank of the matrix. + + \return The Moore-Penros pseudo inverse \f$ A^+ \f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + // This matrix rank is 2 + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + int rank_in = 2; + vpMatrix A_p = A.pseudoInverseLapack(rank_in); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + } + \endcode + + Once build, the previous example produces the following output: + \code + A: [2,3]= + 2 3 5 + -4 2 3 + A^+ (pseudo-inverse): [3,2]= + 0.117899 -0.190782 + 0.065380 0.039657 + 0.113612 0.052518 + \endcode + +*/ +vpMatrix vpMatrix::pseudoInverse(int rank_in) const +{ +#if defined(VISP_HAVE_LAPACK) + return pseudoInverseLapack(rank_in); +#elif defined(VISP_HAVE_EIGEN3) + return pseudoInverseEigen3(rank_in); +#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 + return pseudoInverseOpenCV(rank_in); +#else + (void)rank_in; + throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " + "Install Lapack, Eigen3 or OpenCV 3rd party")); +#endif +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values and return the rank of the matrix. + + \note By default, this function uses Lapack 3rd party. It is also possible + to use a specific 3rd party suffixing this function name with one of the + following 3rd party names (Lapack, Eigen3 or OpenCV). + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + vpColVector sv; + unsigned int rank = A.pseudoInverse(A_p, sv); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + + std::cout << "Rank: " << rank << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + } + \endcode + + Once build, the previous example produces the following output: + \code + A: [2,3]= + 2 3 5 + -4 2 3 + A^+ (pseudo-inverse): [3,2]= + 0.117899 -0.190782 + 0.065380 0.039657 + 0.113612 0.052518 + Rank: 2 + Singular values: 6.874359351 4.443330227 + \endcode +*/ +unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold) const +{ +#if defined(VISP_HAVE_LAPACK) + return pseudoInverseLapack(Ap, sv, svThreshold); +#elif defined(VISP_HAVE_EIGEN3) + return pseudoInverseEigen3(Ap, sv, svThreshold); +#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 + return pseudoInverseOpenCV(Ap, sv, svThreshold); +#else + (void)Ap; + (void)sv; + (void)svThreshold; + throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " + "Install Lapack, Eigen3 or OpenCV 3rd party")); +#endif +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values and return the rank of the matrix. + + \note By default, this function uses Lapack 3rd party. It is also possible + to use a specific 3rd party suffixing this function name with one of the + following 3rd party names (Lapack, Eigen3 or OpenCV). + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param[in] rank_in : Known rank of the matrix. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + vpColVector sv; + int rank_in = 2; + int rank_out = A.pseudoInverse(A_p, sv, rank_in); + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + } + \endcode + + Once build, the previous example produces the following output: + \code + A: [2,3]= + 2 3 5 + -4 2 3 + A^+ (pseudo-inverse): [3,2]= + 0.117899 -0.190782 + 0.065380 0.039657 + 0.113612 0.052518 + Rank in : 2 + Rank out: 2 + Singular values: 6.874359351 4.443330227 + \endcode +*/ +int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in) const +{ +#if defined(VISP_HAVE_LAPACK) + return pseudoInverseLapack(Ap, sv, rank_in); +#elif defined(VISP_HAVE_EIGEN3) + return pseudoInverseEigen3(Ap, sv, rank_in); +#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 + return pseudoInverseOpenCV(Ap, sv, rank_in); +#else + (void)Ap; + (void)sv; + (void)rank_in; + throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " + "Install Lapack, Eigen3 or OpenCV 3rd party")); +#endif +} +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values, \f$\mbox{Im}(A)\f$ and \f$\mbox{Im}(A^T)\f$ + and return the rank of the matrix. + + See pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const + for a complete description of this function. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. + + \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + vpColVector sv; + vpMatrix imA, imAt; + unsigned int rank = A.pseudoInverse(A_p, sv, 1e-6, imA, imAt); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank: " << rank << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + imA.print(std::cout, 10, "Im(A): "); + imAt.print(std::cout, 10, "Im(A^T): "); + } + \endcode + + Once build, the previous example produces the following output: + \code + A: [2,3]= + 2 3 5 + -4 2 3 + A^+ (pseudo-inverse): [3,2]= + 0.117899 -0.190782 + 0.065380 0.039657 + 0.113612 0.052518 + Rank: 2 + Singular values: 6.874359351 4.443330227 + Im(A): [2,2]= + 0.81458 -0.58003 + 0.58003 0.81458 + Im(A^T): [3,2]= + -0.100515 -0.994397 + 0.524244 -0.024967 + 0.845615 -0.102722 + \endcode +*/ +unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt) const +{ + vpMatrix kerAt; + return pseudoInverse(Ap, sv, svThreshold, imA, imAt, kerAt); +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values, \f$\mbox{Im}(A)\f$ and \f$\mbox{Im}(A^T)\f$ + and return the rank of the matrix. + + See pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const + for a complete description of this function. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param[in] rank_in : Known rank of the matrix. + + \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. + + \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + vpColVector sv; + vpMatrix imA, imAt; + int rank_in = 2; + int rank_out = A.pseudoInverse(A_p, sv, rank_in, imA, imAt); + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_in << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + imA.print(std::cout, 10, "Im(A): "); + imAt.print(std::cout, 10, "Im(A^T): "); + } + \endcode + + Once build, the previous example produces the following output: + \code + A: [2,3]= + 2 3 5 + -4 2 3 + A^+ (pseudo-inverse): [3,2]= + 0.117899 -0.190782 + 0.065380 0.039657 + 0.113612 0.052518 + Rank: 2 + Singular values: 6.874359351 4.443330227 + Im(A): [2,2]= + 0.81458 -0.58003 + 0.58003 0.81458 + Im(A^T): [3,2]= + -0.100515 -0.994397 + 0.524244 -0.024967 + 0.845615 -0.102722 + \endcode +*/ +int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt) const +{ + vpMatrix kerAt; + return pseudoInverse(Ap, sv, rank_in, imA, imAt, kerAt); +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and + \f$\mbox{Ker}(A)\f$ and return the rank of the matrix. + + \note By default, this function uses Lapack 3rd party. It is also possible + to use a specific 3rd party suffixing this function name with one of the + following 3rd party names (Lapack, Eigen3 or OpenCV). + + \warning To inverse a square n-by-n matrix, you have to use rather + inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. + + \param sv : Vector corresponding to matrix A singular values. The size of this vector is equal to min(m, n). + + \param svThreshold : Threshold used to test the singular values.If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \param imA : \f$\mbox { Im }({ \bf A })\f$ that is a m - by - r matrix. + + \param imAt : \f$\mbox { Im }({ \bf A } ^ T)\f$ that is n - by - r matrix. + + \param kerAt : The matrix that contains the null space(kernel) of \f$\bf + A\f$ defined by the matrix \f$ { \bf X } ^ T\f$.If matrix \f$\bf A\f$ is full + rank, the dimension of \c kerAt is(0, n), otherwise the dimension is (n - r, n). + This matrix is thus the transpose of \f$\mbox { Ker }({ \bf A })\f$. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo - inverse of a 2 - by - 3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpColVector sv; + vpMatrix A_p, imA, imAt, kerAt; + unsigned int rank = A.pseudoInverse(A_p, sv, 1e-6, imA, imAt, kerAt); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank: " << rank << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + imA.print(std::cout, 10, "Im(A): "); + imAt.print(std::cout, 10, "Im(A^T): "); + + if (kerAt.size()) { + kerAt.t().print(std::cout, 10, "Ker(A): "); + } + else { + std::cout << "Ker(A) empty " << std::endl; + } + + // Reconstruct matrix A from ImA, ImAt, KerAt + vpMatrix S(rank, A.getCols()); + for (unsigned int i = 0; i< rank; i++) + S[i][i] = sv[i]; + vpMatrix Vt(A.getCols(), A.getCols()); + Vt.insert(imAt.t(), 0, 0); + Vt.insert(kerAt, rank, 0); + (imA *S *Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); + } + \endcode + + Once build, the previous example produces the following output : + + \code{.sh} + A: [2,3] = + 2 3 5 + -4 2 3 + A^+(pseudo-inverse): [3,2]= + 0.117899 -0.190782 + 0.065380 0.039657 + 0.113612 0.052518 + Rank: 2 + Singular values: 6.874359351 4.443330227 + Im(A): [2,2]= + 0.81458 -0.58003 + 0.58003 0.81458 + Im(A^T): [3,2] = + -0.100515 -0.994397 + 0.524244 -0.024967 + 0.845615 -0.102722 + Ker(A): [3,1]= + -0.032738 + -0.851202 + 0.523816 + Im(A) * S * [Im(A^T) | Ker(A)]^T: [2,3]= + 2 3 5 + -4 2 3 + \endcode +*/ +unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, + vpMatrix &kerAt) const +{ +#if defined(VISP_HAVE_LAPACK) + return pseudoInverseLapack(Ap, sv, svThreshold, imA, imAt, kerAt); +#elif defined(VISP_HAVE_EIGEN3) + return pseudoInverseEigen3(Ap, sv, svThreshold, imA, imAt, kerAt); +#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 + return pseudoInverseOpenCV(Ap, sv, svThreshold, imA, imAt, kerAt); +#else + (void)Ap; + (void)sv; + (void)svThreshold; + (void)imA; + (void)imAt; + (void)kerAt; + throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " + "Install Lapack, Eigen3 or OpenCV 3rd party")); +#endif +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and + \f$\mbox { Ker }(A)\f$ and return the rank of the matrix. + + \note By default, this function uses Lapack 3rd party.It is also possible + to use a specific 3rd party suffixing this function name with one of the + following 3rd party names(Lapack, Eigen3 or OpenCV). + + \warning To inverse a square n - by - n matrix, you have to use rather + inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. + + \param Ap : The Moore - Penros pseudo inverse \f$ { \bf A } ^ +\f$. + + \param sv : Vector corresponding to matrix \f$A\f$ singular values.The size + of this vector is equal to min(m, n). + + \param[in] rank_in : Known rank of the matrix. + + \param imA : \f$\mbox { Im }({ \bf A })\f$ that is a m - by - r matrix. + + \param imAt : \f$\mbox { Im }({ \bf A } ^T)\f$ that is n - by - r matrix. + + \param kerAt : The matrix that contains the null space(kernel) of \f$\bf + A\f$ defined by the matrix \f$ { \bf X } ^ T\f$.If matrix \f$\bf A\f$ is full + rank, the dimension of \c kerAt is(0, n), otherwise the dimension is(n - r, + n).This matrix is thus the transpose of \f$\mbox { Ker }({ \bf A })\f$. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo - inverse of a 2 - by - 3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpColVector sv; + vpMatrix A_p, imA, imAt, kerAt; + int rank_in = 2; + int rank_out = A.pseudoInverse(A_p, sv, rank_in, imA, imAt, kerAt); + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + imA.print(std::cout, 10, "Im(A): "); + imAt.print(std::cout, 10, "Im(A^T): "); + + if (kerAt.size()) { + kerAt.t().print(std::cout, 10, "Ker(A): "); + } + else { + std::cout << "Ker(A) empty " << std::endl; + } + + // Reconstruct matrix A from ImA, ImAt, KerAt + vpMatrix S(rank, A.getCols()); + for (unsigned int i = 0; i < rank_in; i++) + S[i][i] = sv[i]; + vpMatrix Vt(A.getCols(), A.getCols()); + Vt.insert(imAt.t(), 0, 0); + Vt.insert(kerAt, rank, 0); + (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); + } + \endcode + + Once build, the previous example produces the following output : + \code + A : [2, 3] = + 2 3 5 + - 4 2 3 + A ^ +(pseudo - inverse) : [3, 2] = + 0.117899 - 0.190782 + 0.065380 0.039657 + 0.113612 0.052518 + Rank in : 2 + Rank out : 2 + Singular values : 6.874359351 4.443330227 + Im(A) : [2, 2] = + 0.81458 - 0.58003 + 0.58003 0.81458 + Im(A ^ T) : [3, 2] = + -0.100515 - 0.994397 + 0.524244 - 0.024967 + 0.845615 - 0.102722 + Ker(A) : [3, 1] = + -0.032738 + - 0.851202 + 0.523816 + Im(A) * S *[Im(A ^ T) | Ker(A)] ^ T : [2, 3] = + 2 3 5 + - 4 2 3 + \endcode +*/ +int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, + vpMatrix &kerAt) const +{ +#if defined(VISP_HAVE_LAPACK) + return pseudoInverseLapack(Ap, sv, rank_in, imA, imAt, kerAt); +#elif defined(VISP_HAVE_EIGEN3) + return pseudoInverseEigen3(Ap, sv, rank_in, imA, imAt, kerAt); +#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 + return pseudoInverseOpenCV(Ap, sv, rank_in, imA, imAt, kerAt); +#else + (void)Ap; + (void)sv; + (void)rank_in; + (void)imA; + (void)imAt; + (void)kerAt; + throw(vpException(vpException::fatalError, "Cannot compute pseudo-inverse. " + "Install Lapack, Eigen3 or OpenCV 3rd party")); +#endif +} + +END_VISP_NAMESPACE diff --git a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_eigen.cpp b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_eigen.cpp new file mode 100644 index 0000000000..2e304929b3 --- /dev/null +++ b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_eigen.cpp @@ -0,0 +1,670 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Pseudo inverse computation. + */ + +#include + +#include "private/vpMatrix_pseudo_inverse.h" + +BEGIN_VISP_NAMESPACE + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + +#if defined(VISP_HAVE_EIGEN3) +/*! + Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n + matrix \f$\bf A\f$ using Eigen3 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The Moore-Penros pseudo inverse \f$ A^+ \f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p = A.pseudoInverseEigen3(); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + } + \endcode + + \sa pseudoInverse(double) +*/ +vpMatrix vpMatrix::pseudoInverseEigen3(double svThreshold) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + vpMatrix U, V, Ap; + vpColVector sv; + + U = *this; + U.svdEigen3(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); + + return Ap; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ and return the rank of the matrix using Eigen3 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The rank of the matrix. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + unsigned int rank = A.pseudoInverseEigen3(A_p); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank: " << rank << std::endl; + } + \endcode + + \sa pseudoInverse(vpMatrix &, double) const +*/ +unsigned int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, double svThreshold) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + vpMatrix U, V; + vpColVector sv; + + U = *this; + U.svdEigen3(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); + + return static_cast(rank_out); +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values and return the rank of the matrix using + Eigen3 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + vpColVector sv; + unsigned int rank = A.pseudoInverseEigen3(A_p, sv); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + + std::cout << "Rank: " << rank << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, double) const +*/ +unsigned int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + vpMatrix U, V; + + Ap.resize(ncols, nrows, false, false); + + U = *this; + U.svdEigen3(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); + + return static_cast(rank_out); +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and + \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using Eigen3 3rd + party. + + \warning To inverse a square n-by-n matrix, you have to use rather + inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. + + Using singular value decomposition, we have: + + \f[ + {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf + V^\top}_{n\times n} \f] \f[ + {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & + \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix + \f$A\f$ singular values. + + This equation could be reformulated in a minimal way: + \f[ + {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix + \f$A\f$ first r singular values. + + The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) + = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. + + \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param svThreshold: Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. + + \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. + + \param kerAt: The matrix that contains the null space (kernel) of \f$\bf + A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full + rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, + n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpColVector sv; + vpMatrix A_p, imA, imAt, kerAt; + unsigned int rank = A.pseudoInverseEigen3(A_p, sv, 1e-6, imA, imAt, kerAt); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank: " << rank << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + imA.print(std::cout, 10, "Im(A): "); + imAt.print(std::cout, 10, "Im(A^T): "); + + if (kerAt.size()) { + kerAt.t().print(std::cout, 10, "Ker(A): "); + } + else { + std::cout << "Ker(A) empty " << std::endl; + } + + // Reconstruct matrix A from ImA, ImAt, KerAt + vpMatrix S(rank, A.getCols()); + for(unsigned int i = 0; i< rank; i++) + S[i][i] = sv[i]; + vpMatrix Vt(A.getCols(), A.getCols()); + Vt.insert(imAt.t(), 0, 0); + Vt.insert(kerAt, rank, 0); + (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const +*/ +unsigned int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, + vpMatrix &imAt, vpMatrix &kerAt) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + vpMatrix U, V; + + if (nrows < ncols) { + U.resize(ncols, ncols, true); + U.insert(*this, 0, 0); + } + else { + U = *this; + } + + U.svdEigen3(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, &imA, &imAt, &kerAt); + + return static_cast(rank_out); +} + +/*! + Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n + matrix \f$\bf A\f$ using Eigen3 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param[in] rank_in : Known rank of the matrix. + \return The Moore-Penros pseudo inverse \f$ A^+ \f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + // This matrix rank is 2 + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + int rank_in = 2; + vpMatrix A_p = A.pseudoInverseEigen3(rank_in); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + return 0; + } + \endcode + + \sa pseudoInverse(int) const +*/ +vpMatrix vpMatrix::pseudoInverseEigen3(int rank_in) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + vpMatrix U, V, Ap; + vpColVector sv; + + U = *this; + U.svdEigen3(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); + + return Ap; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ and return the rank of the matrix using Eigen3 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param[out] Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param[in] rank_in : Known rank of the matrix. + + \return The computed rank of the matrix. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + // This matrix rank is 2 + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + int rank_in = 2; + int rank_out = A.pseudoInverseEigen3(A_p, rank_in); + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + return 0; + } + \endcode + + \sa pseudoInverse(vpMatrix &, int) const +*/ +int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + vpMatrix U, V; + vpColVector sv; + + Ap.resize(ncols, nrows, false, false); + + U = *this; + U.svdEigen3(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); + + return rank_out; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values and return the rank of the matrix using + Eigen3 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param[in] rank_in : Known rank of the matrix. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + // This matrix rank is 2 + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + vpColVector sv; + int rank_in = 2; + + int rank_out = A.pseudoInverseEigen3(A_p, sv, rank_in); + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + return 0; + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, int) const +*/ +int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + vpMatrix U, V; + + Ap.resize(ncols, nrows, false, false); + + U = *this; + U.svdEigen3(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); + + return rank_out; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and + \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using Eigen3 3rd + party. + + \warning To inverse a square n-by-n matrix, you have to use rather + inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. + + Using singular value decomposition, we have: + + \f[ + {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf + V^\top}_{n\times n} \f] \f[ + {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & + \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix + \f$A\f$ singular values. + + This equation could be reformulated in a minimal way: + \f[ + {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix + \f$A\f$ first r singular values. + + The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) + = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. + + \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param[in] rank_in : Known rank of the matrix. + + \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. + + \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. + + \param kerAt: The matrix that contains the null space (kernel) of \f$\bf + A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full + rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, + n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpColVector sv; + vpMatrix A_p, imA, imAt, kerAt; + int rank_in = 2; + int rank_out = A.pseudoInverseEigen3(A_p, sv, rank_in, imA, imAt, kerAt); + + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + imA.print(std::cout, 10, "Im(A): "); + imAt.print(std::cout, 10, "Im(A^T): "); + + if (kerAt.size()) { + kerAt.t().print(std::cout, 10, "Ker(A): "); + } + else { + std::cout << "Ker(A) empty " << std::endl; + } + + // Reconstruct matrix A from ImA, ImAt, KerAt + vpMatrix S(rank_in, A.getCols()); + for(unsigned int i = 0; i< rank_in; i++) + S[i][i] = sv[i]; + vpMatrix Vt(A.getCols(), A.getCols()); + Vt.insert(imAt.t(), 0, 0); + Vt.insert(kerAt, rank_in, 0); + (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, int, vpMatrix &, vpMatrix &, vpMatrix &) const +*/ +int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, + vpMatrix &kerAt) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + vpMatrix U, V; + + if (nrows < ncols) { + U.resize(ncols, ncols, true); + U.insert(*this, 0, 0); + } + else { + U = *this; + } + U.svdEigen3(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt); + + return rank_out; +} +#endif + +#endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS + +END_VISP_NAMESPACE diff --git a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_lapack.cpp b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_lapack.cpp new file mode 100644 index 0000000000..ae69ce5410 --- /dev/null +++ b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_lapack.cpp @@ -0,0 +1,685 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Pseudo inverse computation. + */ + +#include + +#include "private/vpMatrix_pseudo_inverse.h" + +#ifdef VISP_HAVE_LAPACK +#ifdef VISP_HAVE_GSL +#include +#include +#include +#elif defined(VISP_HAVE_MKL) +#include +#endif +#endif + +BEGIN_VISP_NAMESPACE + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + +#if defined(VISP_HAVE_LAPACK) +/*! + Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n + matrix \f$\bf A\f$ using Lapack 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The Moore-Penros pseudo inverse \f$ A^+ \f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p = A.pseudoInverseLapack(); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + } + \endcode + + \sa pseudoInverse(double) const +*/ +vpMatrix vpMatrix::pseudoInverseLapack(double svThreshold) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + + vpMatrix U, V, Ap; + vpColVector sv; + + U = *this; + U.svdLapack(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); + + return Ap; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ and return the rank of the matrix using Lapack 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The rank of the matrix. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + unsigned int rank = A.pseudoInverseLapack(A_p); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank: " << rank << std::endl; + } + \endcode + + \sa pseudoInverse(vpMatrix &, double) const +*/ +unsigned int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, double svThreshold) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + + vpMatrix U, V; + vpColVector sv; + + U = *this; + U.svdLapack(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); + + return static_cast(rank_out); +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values and return the rank of the matrix using + Lapack 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + vpColVector sv; + unsigned int rank = A.pseudoInverseLapack(A_p, sv); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + + std::cout << "Rank: " << rank << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, double) const +*/ +unsigned int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + + vpMatrix U, V; + + Ap.resize(ncols, nrows, false, false); + + U = *this; + U.svdLapack(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); + + return static_cast(rank_out); +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and + \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using Lapack 3rd + party. + + \warning To inverse a square n-by-n matrix, you have to use rather + inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. + + Using singular value decomposition, we have: + + \f[ + {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf + V^\top}_{n\times n} \f] \f[ + {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & + \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix + \f$A\f$ singular values. + + This equation could be reformulated in a minimal way: + \f[ + {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix + \f$A\f$ first r singular values. + + The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) + = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. + + \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param svThreshold: Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. + + \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. + + \param kerAt: The matrix that contains the null space (kernel) of \f$\bf + A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full + rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, + n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpColVector sv; + vpMatrix A_p, imA, imAt, kerAt; + unsigned int rank = A.pseudoInverseLapack(A_p, sv, 1e-6, imA, imAt, kerAt); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank: " << rank << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + imA.print(std::cout, 10, "Im(A): "); + imAt.print(std::cout, 10, "Im(A^T): "); + + if (kerAt.size()) { + kerAt.t().print(std::cout, 10, "Ker(A): "); + } + else { + std::cout << "Ker(A) empty " << std::endl; + } + + // Reconstruct matrix A from ImA, ImAt, KerAt + vpMatrix S(rank, A.getCols()); + for(unsigned int i = 0; i< rank; i++) + S[i][i] = sv[i]; + vpMatrix Vt(A.getCols(), A.getCols()); + Vt.insert(imAt.t(), 0, 0); + Vt.insert(kerAt, rank, 0); + (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const +*/ +unsigned int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, + vpMatrix &imAt, vpMatrix &kerAt) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + vpMatrix U, V; + + if (nrows < ncols) { + U.resize(ncols, ncols, true); + U.insert(*this, 0, 0); + } + else { + U = *this; + } + + U.svdLapack(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, &imA, &imAt, &kerAt); + + return static_cast(rank_out); +} + +/*! + Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n + matrix \f$\bf A\f$ using Lapack 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param[in] rank_in : Known rank of the matrix. + \return The Moore-Penros pseudo inverse \f$ A^+ \f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + // This matrix rank is 2 + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + int rank_in = 2; + vpMatrix A_p = A.pseudoInverseLapack(rank_in); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + return 0; + } + \endcode + + \sa pseudoInverse(int) const +*/ +vpMatrix vpMatrix::pseudoInverseLapack(int rank_in) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + + vpMatrix U, V, Ap; + vpColVector sv; + + U = *this; + U.svdLapack(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); + + return Ap; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ and return the rank of the matrix using Lapack 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param[out] Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param[in] rank_in : Known rank of the matrix. + + \return The computed rank of the matrix. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + // This matrix rank is 2 + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + int rank_in = 2; + int rank_out = A.pseudoInverseLapack(A_p, rank_in); + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + return 0; + } + \endcode + + \sa pseudoInverse(vpMatrix &, int) const +*/ +int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, int rank_in) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + + vpMatrix U, V; + vpColVector sv; + + U = *this; + U.svdLapack(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); + + return rank_out; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values and return the rank of the matrix using + Lapack 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param[in] rank_in : Known rank of the matrix. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + // This matrix rank is 2 + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + vpColVector sv; + int rank_in = 2; + + int rank_out = A.pseudoInverseLapack(A_p, sv, rank_in); + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + return 0; + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, int) const +*/ +int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + vpMatrix U, V; + + Ap.resize(ncols, nrows, false, false); + + U = *this; + U.svdLapack(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); + + return rank_out; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and + \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using Lapack 3rd + party. + + \warning To inverse a square n-by-n matrix, you have to use rather + inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. + + Using singular value decomposition, we have: + + \f[ + {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf + V^\top}_{n\times n} \f] \f[ + {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & + \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix + \f$A\f$ singular values. + + This equation could be reformulated in a minimal way: + \f[ + {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix + \f$A\f$ first r singular values. + + The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) + = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. + + \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param[in] rank_in : Known rank of the matrix. + + \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. + + \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. + + \param kerAt: The matrix that contains the null space (kernel) of \f$\bf + A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full + rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, + n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpColVector sv; + vpMatrix A_p, imA, imAt, kerAt; + int rank_in = 2; + int rank_out = A.pseudoInverseLapack(A_p, sv, rank_in, imA, imAt, kerAt); + + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + imA.print(std::cout, 10, "Im(A): "); + imAt.print(std::cout, 10, "Im(A^T): "); + + if (kerAt.size()) { + kerAt.t().print(std::cout, 10, "Ker(A): "); + } + else { + std::cout << "Ker(A) empty " << std::endl; + } + + // Reconstruct matrix A from ImA, ImAt, KerAt + vpMatrix S(rank_in, A.getCols()); + for(unsigned int i = 0; i< rank_in; i++) + S[i][i] = sv[i]; + vpMatrix Vt(A.getCols(), A.getCols()); + Vt.insert(imAt.t(), 0, 0); + Vt.insert(kerAt, rank_in, 0); + (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, int, vpMatrix &, vpMatrix &, vpMatrix &) const +*/ +int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, + vpMatrix &kerAt) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + vpMatrix U, V; + + if (nrows < ncols) { + U.resize(ncols, ncols, true); + U.insert(*this, 0, 0); + } + else { + U = *this; + } + + U.svdLapack(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt); + + return rank_out; +} + +#endif + +#endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS + +END_VISP_NAMESPACE diff --git a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_opencv.cpp b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_opencv.cpp new file mode 100644 index 0000000000..1bcaa2f85b --- /dev/null +++ b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_opencv.cpp @@ -0,0 +1,672 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Pseudo inverse computation. + */ + +#include + +#include "private/vpMatrix_pseudo_inverse.h" + +BEGIN_VISP_NAMESPACE + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + +#if defined(VISP_HAVE_OPENCV) +/*! + Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n + matrix \f$\bf A\f$ using OpenCV 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The Moore-Penros pseudo inverse \f$ A^+ \f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p = A.pseudoInverseEigen3(); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + } + \endcode + + \sa pseudoInverse(double) const +*/ +vpMatrix vpMatrix::pseudoInverseOpenCV(double svThreshold) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + vpMatrix U, V, Ap; + vpColVector sv; + + U = *this; + U.svdOpenCV(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); + + return Ap; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ and return the rank of the matrix using OpenCV 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The rank of the matrix. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + unsigned int rank = A.pseudoInverseOpenCV(A_p); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank: " << rank << std::endl; + } + \endcode + + \sa pseudoInverse(vpMatrix &, double) const +*/ +unsigned int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + vpMatrix U, V; + vpColVector sv; + + Ap.resize(ncols, nrows, false, false); + + U = *this; + U.svdOpenCV(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); + + return static_cast(rank_out); +} +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values and return the rank of the matrix using + OpenCV 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param svThreshold : Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + vpColVector sv; + unsigned int rank = A.pseudoInverseOpenCV(A_p, sv); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + + std::cout << "Rank: " << rank << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, double) const +*/ +unsigned int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + vpMatrix U, V; + + Ap.resize(ncols, nrows, false, false); + + U = *this; + U.svdOpenCV(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, nullptr, nullptr, nullptr); + + return static_cast(rank_out); +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and + \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using OpenCV 3rd + party. + + \warning To inverse a square n-by-n matrix, you have to use rather + inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. + + Using singular value decomposition, we have: + + \f[ + {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf + V^\top}_{n\times n} \f] \f[ + {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & + \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix + \f$A\f$ singular values. + + This equation could be reformulated in a minimal way: + \f[ + {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix + \f$A\f$ first r singular values. + + The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) + = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. + + \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param svThreshold: Threshold used to test the singular values. If + a singular value is lower than this threshold we consider that the + matrix is not full rank. + + \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. + + \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. + + \param kerAt: The matrix that contains the null space (kernel) of \f$\bf + A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full + rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, + n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpColVector sv; + vpMatrix A_p, imA, imAt, kerAt; + unsigned int rank = A.pseudoInverseOpenCV(A_p, sv, 1e-6, imA, imAt, kerAt); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank: " << rank << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + imA.print(std::cout, 10, "Im(A): "); + imAt.print(std::cout, 10, "Im(A^T): "); + + if (kerAt.size()) { + kerAt.t().print(std::cout, 10, "Ker(A): "); + } + else { + std::cout << "Ker(A) empty " << std::endl; + } + + // Reconstruct matrix A from ImA, ImAt, KerAt + vpMatrix S(rank, A.getCols()); + for(unsigned int i = 0; i< rank; i++) + S[i][i] = sv[i]; + vpMatrix Vt(A.getCols(), A.getCols()); + Vt.insert(imAt.t(), 0, 0); + Vt.insert(kerAt, rank, 0); + (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const +*/ +unsigned int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, + vpMatrix &imAt, vpMatrix &kerAt) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + vpMatrix U, V; + + if (nrows < ncols) { + U.resize(ncols, ncols, true); + U.insert(*this, 0, 0); + } + else { + U = *this; + } + + U.svdOpenCV(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, nullptr, &imA, &imAt, &kerAt); + + return static_cast(rank_out); +} + +/*! + Compute and return the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n + matrix \f$\bf A\f$ using OpenCV 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param[in] rank_in : Known rank of the matrix. + \return The Moore-Penros pseudo inverse \f$ A^+ \f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + // This matrix rank is 2 + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + int rank_in = 2; + vpMatrix A_p = A.pseudoInverseOpenCV(rank_in); + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + return 0; + } + \endcode + + \sa pseudoInverse(int) const +*/ +vpMatrix vpMatrix::pseudoInverseOpenCV(int rank_in) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + vpMatrix U, V, Ap; + vpColVector sv; + + U = *this; + U.svdOpenCV(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); + + return Ap; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ and return the rank of the matrix using OpenCV 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param[out] Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param[in] rank_in : Known rank of the matrix. + + \return The computed rank of the matrix. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + // This matrix rank is 2 + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + int rank_in = 2; + int rank_out = A.pseudoInverseOpenCV(A_p, rank_in); + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + return 0; + } + \endcode + + \sa pseudoInverse(vpMatrix &, int) const +*/ +int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + vpMatrix U, V; + vpColVector sv; + + Ap.resize(ncols, nrows, false, false); + + U = *this; + U.svdOpenCV(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); + + return rank_out; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values and return the rank of the matrix using + OpenCV 3rd party. + + \warning To inverse a square n-by-n matrix, you have to use rather one of + the following functions inverseByLU(), inverseByQR(), inverseByCholesky() that + are kwown as faster. + + \param Ap : The Moore-Penros pseudo inverse \f$ A^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param[in] rank_in : Known rank of the matrix. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + // This matrix rank is 2 + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpMatrix A_p; + vpColVector sv; + int rank_in = 2; + + int rank_out = A.pseudoInverseOpenCV(A_p, sv, rank_in); + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + return 0; + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, int) const +*/ +int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + vpMatrix U, V; + + Ap.resize(ncols, nrows, false, false); + + U = *this; + U.svdOpenCV(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, nullptr, nullptr, nullptr); + + return rank_out; +} + +/*! + Compute the Moore-Penros pseudo inverse \f$A^+\f$ of a m-by-n matrix \f$\bf + A\f$ along with singular values, \f$\mbox{Im}(A)\f$, \f$\mbox{Im}(A^T)\f$ and + \f$\mbox{Ker}(A)\f$ and return the rank of the matrix using OpenCV 3rd + party. + + \warning To inverse a square n-by-n matrix, you have to use rather + inverseByLU(), inverseByCholesky(), or inverseByQR() that are kwown as faster. + + Using singular value decomposition, we have: + + \f[ + {\bf A}_{m\times n} = {\bf U}_{m\times m} \; {\bf S}_{m\times n} \; {\bf + V^\top}_{n\times n} \f] \f[ + {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} ({\bf A}) & | & + \mbox{Ker} ({\bf A}^\top) \end{array} \right] {\bf S}_{m\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{m\times n}\f$ corresponds to the matrix + \f$A\f$ singular values. + + This equation could be reformulated in a minimal way: + \f[ + {\bf A}_{m\times n} = \mbox{Im} ({\bf A}) \; {\bf S}_{r\times n} + \left[ + \begin{array}{c} \left[\mbox{Im} ({\bf A}^\top)\right]^\top \\ + \\ + \hline \\ + \left[\mbox{Ker}({\bf A})\right]^\top \end{array}\right] + \f] + + where the diagonal of \f${\bf S}_{r\times n}\f$ corresponds to the matrix + \f$A\f$ first r singular values. + + The null space of a matrix \f$\bf A\f$ is defined as \f$\mbox{Ker}({\bf A}) + = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\f$. + + \param Ap: The Moore-Penros pseudo inverse \f$ {\bf A}^+ \f$. + + \param sv: Vector corresponding to matrix \f$A\f$ singular values. The size + of this vector is equal to min(m, n). + + \param[in] rank_in : Known rank of the matrix. + + \param imA: \f$\mbox{Im}({\bf A})\f$ that is a m-by-r matrix. + + \param imAt: \f$\mbox{Im}({\bf A}^T)\f$ that is n-by-r matrix. + + \param kerAt: The matrix that contains the null space (kernel) of \f$\bf + A\f$ defined by the matrix \f${\bf X}^T\f$. If matrix \f$\bf A\f$ is full + rank, the dimension of \c kerAt is (0, n), otherwise the dimension is (n-r, + n). This matrix is thus the transpose of \f$\mbox{Ker}({\bf A})\f$. + + \return The rank of the matrix \f$\bf A\f$. + + Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2. + + \code + #include + + int main() + { + vpMatrix A(2, 3); + + A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; + A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; + + A.print(std::cout, 10, "A: "); + + vpColVector sv; + vpMatrix A_p, imA, imAt, kerAt; + int rank_in = 2; + int rank_out = A.pseudoInverseOpenCV(A_p, sv, rank_in, imA, imAt, kerAt); + + if (rank_out != rank_in) { + std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; + std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; + } + + A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); + std::cout << "Rank in : " << rank_in << std::endl; + std::cout << "Rank out: " << rank_out << std::endl; + std::cout << "Singular values: " << sv.t() << std::endl; + imA.print(std::cout, 10, "Im(A): "); + imAt.print(std::cout, 10, "Im(A^T): "); + + if (kerAt.size()) { + kerAt.t().print(std::cout, 10, "Ker(A): "); + } + else { + std::cout << "Ker(A) empty " << std::endl; + } + + // Reconstruct matrix A from ImA, ImAt, KerAt + vpMatrix S(rank_in, A.getCols()); + for(unsigned int i = 0; i< rank_in; i++) + S[i][i] = sv[i]; + vpMatrix Vt(A.getCols(), A.getCols()); + Vt.insert(imAt.t(), 0, 0); + Vt.insert(kerAt, rank_in, 0); + (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); + } + \endcode + + \sa pseudoInverse(vpMatrix &, vpColVector &, int, vpMatrix &, vpMatrix &, vpMatrix &) const +*/ +int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix &imA, vpMatrix &imAt, + vpMatrix &kerAt) const +{ + unsigned int nrows = getRows(); + unsigned int ncols = getCols(); + int rank_out; + double svThreshold = 1e-26; + vpMatrix U, V; + + if (nrows < ncols) { + U.resize(ncols, ncols, true); + U.insert(*this, 0, 0); + } + else { + U = *this; + } + + U.svdOpenCV(sv, V); + + compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt); + + return rank_out; +} +#endif + +#endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS + +END_VISP_NAMESPACE diff --git a/modules/core/src/math/matrix/vpMatrix_stack.cpp b/modules/core/src/math/matrix/vpMatrix_stack.cpp new file mode 100644 index 0000000000..48452e25bb --- /dev/null +++ b/modules/core/src/math/matrix/vpMatrix_stack.cpp @@ -0,0 +1,357 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Stack matrix. + */ + +#include +#include + +BEGIN_VISP_NAMESPACE + +/*! + Stacks columns of a matrix in a vector. + \param out : a vpColVector. +*/ +void vpMatrix::stackColumns(vpColVector &out) +{ + if ((out.rowNum != (colNum * rowNum)) || (out.colNum != 1)) { + out.resize(colNum * rowNum, false, false); + } + + double *optr = out.data; + for (unsigned int j = 0; j < colNum; ++j) { + for (unsigned int i = 0; i < rowNum; ++i) { + *(optr++) = rowPtrs[i][j]; + } + } +} + +/*! + Stacks columns of a matrix in a vector. + \return a vpColVector. +*/ +vpColVector vpMatrix::stackColumns() +{ + vpColVector out(colNum * rowNum); + stackColumns(out); + return out; +} + +/*! + Stacks rows of a matrix in a vector + \param out : a vpRowVector. +*/ +void vpMatrix::stackRows(vpRowVector &out) +{ + if ((out.getRows() != 1) || (out.getCols() != (colNum * rowNum))) { + out.resize(colNum * rowNum, false, false); + } + + memcpy(out.data, data, sizeof(double) * out.getCols()); +} + +/*! + Stacks rows of a matrix in a vector. + \return a vpRowVector. +*/ +vpRowVector vpMatrix::stackRows() +{ + vpRowVector out(colNum * rowNum); + stackRows(out); + return out; +} + +/*! + Stack matrix \e B to the end of matrix \e A and return the resulting matrix + [ A B ]^T + + \param A : Upper matrix. + \param B : Lower matrix. + \return Stacked matrix [ A B ]^T + + \warning A and B must have the same number of columns. +*/ +vpMatrix vpMatrix::stack(const vpMatrix &A, const vpMatrix &B) +{ + vpMatrix C; + + vpMatrix::stack(A, B, C); + + return C; +} + +/*! + Stack matrix \e B to the end of matrix \e A and return the resulting matrix + in \e C. + + \param A : Upper matrix. + \param B : Lower matrix. + \param C : Stacked matrix C = [ A B ]^T + + \warning A and B must have the same number of columns. A and C, B and C must + be two different objects. +*/ +void vpMatrix::stack(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) +{ + unsigned int nra = A.getRows(); + unsigned int nrb = B.getRows(); + + if (nra != 0) { + if (A.getCols() != B.getCols()) { + throw(vpException(vpException::dimensionError, "Cannot stack (%dx%d) matrix with (%dx%d) matrix", A.getRows(), + A.getCols(), B.getRows(), B.getCols())); + } + } + + if ((A.data != nullptr) && (A.data == C.data)) { + std::cerr << "A and C must be two different objects!" << std::endl; + return; + } + + if ((B.data != nullptr) && (B.data == C.data)) { + std::cerr << "B and C must be two different objects!" << std::endl; + return; + } + + C.resize(nra + nrb, B.getCols(), false, false); + + if ((C.data != nullptr) && (A.data != nullptr) && (A.size() > 0)) { + // Copy A in C + memcpy(C.data, A.data, sizeof(double) * A.size()); + } + + if ((C.data != nullptr) && (B.data != nullptr) && (B.size() > 0)) { + // Copy B in C + memcpy(C.data + A.size(), B.data, sizeof(double) * B.size()); + } +} + +/*! + Stack row vector \e r to matrix \e A and return the resulting matrix [ A r ]^T + + \param A : Upper matrix. + \param r : Lower row vector. + \return Stacked matrix [ A r ]^T + + \warning \e A and \e r must have the same number of columns. +*/ +vpMatrix vpMatrix::stack(const vpMatrix &A, const vpRowVector &r) +{ + vpMatrix C; + vpMatrix::stack(A, r, C); + + return C; +} + +/*! + Stack row vector \e r to the end of matrix \e A and return the resulting + matrix in \e C. + + \param A : Upper matrix. + \param r : Lower row vector. + \param C : Stacked matrix C = [ A r ]^T + + \warning A and r must have the same number of columns. A and C must be two + different objects. +*/ +void vpMatrix::stack(const vpMatrix &A, const vpRowVector &r, vpMatrix &C) +{ + if ((A.data != nullptr) && (A.data == C.data)) { + std::cerr << "A and C must be two different objects!" << std::endl; + return; + } + + C = A; + C.stack(r); +} + +/*! + Stack column vector \e c to matrix \e A and return the resulting matrix [ A c ] + + \param A : Left matrix. + \param c : Right column vector. + \return Stacked matrix [ A c ] + + \warning \e A and \e c must have the same number of rows. +*/ +vpMatrix vpMatrix::stack(const vpMatrix &A, const vpColVector &c) +{ + vpMatrix C; + vpMatrix::stack(A, c, C); + + return C; +} + +/*! + Stack column vector \e c to the end of matrix \e A and return the resulting + matrix in \e C. + + \param A : Left matrix. + \param c : Right column vector. + \param C : Stacked matrix C = [ A c ] + + \warning A and c must have the same number of rows. A and C must be two + different objects. +*/ +void vpMatrix::stack(const vpMatrix &A, const vpColVector &c, vpMatrix &C) +{ + if ((A.data != nullptr) && (A.data == C.data)) { + std::cerr << "A and C must be two different objects!" << std::endl; + return; + } + + C = A; + C.stack(c); +} + +/*! + Stack A at the end of the current matrix, or copy if the matrix has no + dimensions : this = [ this A ]^T. +*/ +void vpMatrix::stack(const vpMatrix &A) +{ + if (rowNum == 0) { + *this = A; + } + else if (A.getRows() > 0) { + if (colNum != A.getCols()) { + throw(vpException(vpException::dimensionError, "Cannot stack (%dx%d) matrix with (%dx%d) matrix", rowNum, colNum, + A.getRows(), A.getCols())); + } + + unsigned int rowNumOld = rowNum; + resize(rowNum + A.getRows(), colNum, false, false); + insert(A, rowNumOld, 0); + } +} + +/*! + Stack row vector \e r at the end of the current matrix, or copy if the + matrix has no dimensions: this = [ this r ]^T. + + Here an example for a robot velocity log : + \code + vpMatrix A; + vpColVector v(6); + for(unsigned int i = 0;i<100;i++) + { + robot.getVelocity(vpRobot::ARTICULAR_FRAME, v); + Velocities.stack(v.t()); + } + \endcode +*/ +void vpMatrix::stack(const vpRowVector &r) +{ + if (rowNum == 0) { + *this = r; + } + else { + if (colNum != r.getCols()) { + throw(vpException(vpException::dimensionError, "Cannot stack (%dx%d) matrix with (1x%d) row vector", rowNum, + colNum, r.getCols())); + } + + if (r.size() == 0) { + return; + } + + unsigned int oldSize = size(); + resize(rowNum + 1, colNum, false, false); + + if ((data != nullptr) && (r.data != nullptr) && (data != r.data)) { + // Copy r in data + memcpy(data + oldSize, r.data, sizeof(double) * r.size()); + } + } +} + +/*! + Stack column vector \e c at the right of the current matrix, or copy if the + matrix has no dimensions: this = [ this c ]. + + Here an example for a robot velocity log matrix: + \code + vpMatrix log; + vpColVector v(6); + for(unsigned int i = 0; i<100;i++) + { + robot.getVelocity(vpRobot::ARTICULAR_FRAME, v); + log.stack(v); + } + \endcode + Here the log matrix has size 6 rows by 100 columns. +*/ +void vpMatrix::stack(const vpColVector &c) +{ + if (colNum == 0) { + *this = c; + } + else { + if (rowNum != c.getRows()) { + throw(vpException(vpException::dimensionError, "Cannot stack (%dx%d) matrix with (%dx1) column vector", rowNum, + colNum, c.getRows())); + } + + if (c.size() == 0) { + return; + } + + vpMatrix tmp = *this; + unsigned int oldColNum = colNum; + resize(rowNum, colNum + 1, false, false); + + if ((data != nullptr) && (tmp.data != nullptr) && (data != tmp.data)) { + // Copy c in data + for (unsigned int i = 0; i < rowNum; ++i) { + memcpy(data + (i * colNum), tmp.data + (i * oldColNum), sizeof(double) * oldColNum); + rowPtrs[i][oldColNum] = c[i]; + } + } + } +} + +#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) +vpMatrix vpMatrix::stackMatrices(const vpColVector &A, const vpColVector &B) +{ + return (vpMatrix)(vpColVector::stack(A, B)); +} + +void vpMatrix::stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C) +{ + vpColVector::stack(A, B, C); +} + +vpMatrix vpMatrix::stackMatrices(const vpMatrix &A, const vpRowVector &B) { return vpMatrix::stack(A, B); } + +void vpMatrix::stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C) { vpMatrix::stack(A, B, C); } +#endif + +END_VISP_NAMESPACE diff --git a/modules/core/src/math/matrix/vpMatrix_svd.cpp b/modules/core/src/math/matrix/vpMatrix_svd.cpp index 146d0dd8c8..45e48bca2a 100644 --- a/modules/core/src/math/matrix/vpMatrix_svd.cpp +++ b/modules/core/src/math/matrix/vpMatrix_svd.cpp @@ -29,8 +29,7 @@ * * Description: * Matrix SVD decomposition. - * -*****************************************************************************/ + */ #include #include @@ -72,11 +71,193 @@ extern "C" int dgesdd_(char *jobz, integer *m, integer *n, double *a, integer *l #endif BEGIN_VISP_NAMESPACE -/*--------------------------------------------------------------------- -SVD related functions +/*! + + Solve a linear system \f$ A X = B \f$ using Singular Value + Decomposition (SVD). + + Non destructive wrt. A and B. + + \param b : Vector\f$ B \f$. + + \param x : Vector \f$ X \f$. + + Here an example: + \code + #include + #include + + int main() + { + vpMatrix A(3,3); + + A[0][0] = 4.64; + A[0][1] = 0.288; + A[0][2] = -0.384; + + A[1][0] = 0.288; + A[1][1] = 7.3296; + A[1][2] = 2.2272; + + A[2][0] = -0.384; + A[2][1] = 2.2272; + A[2][2] = 6.0304; + + vpColVector X(3), B(3); + B[0] = 1; + B[1] = 2; + B[2] = 3; + + A.solveBySVD(B, X); + + // Obtained values of X + // X[0] = 0.2468; + // X[1] = 0.120782; + // X[2] = 0.468587; + + std::cout << "X:\n" << X << std::endl; + } + \endcode + + \sa solveBySVD(const vpColVector &) +*/ +void vpMatrix::solveBySVD(const vpColVector &b, vpColVector &x) const { x = pseudoInverse(1e-6) * b; } + +/*! + + Solve a linear system \f$ A X = B \f$ using Singular Value + Decomposition (SVD). + + Non destructive wrt. A and B. + + \param B : Vector\f$ B \f$. + + \return Vector \f$ X \f$. + + Here an example: + \code + #include + #include + + int main() + { + vpMatrix A(3,3); + + A[0][0] = 4.64; + A[0][1] = 0.288; + A[0][2] = -0.384; + + A[1][0] = 0.288; + A[1][1] = 7.3296; + A[1][2] = 2.2272; + + A[2][0] = -0.384; + A[2][1] = 2.2272; + A[2][2] = 6.0304; + + vpColVector X(3), B(3); + B[0] = 1; + B[1] = 2; + B[2] = 3; + + X = A.solveBySVD(B); + // Obtained values of X + // X[0] = 0.2468; + // X[1] = 0.120782; + // X[2] = 0.468587; + + std::cout << "X:\n" << X << std::endl; + } + \endcode + + \sa solveBySVD(const vpColVector &, vpColVector &) +*/ +vpColVector vpMatrix::solveBySVD(const vpColVector &B) const +{ + vpColVector X(colNum); + + solveBySVD(B, X); + return X; +} ----------------------------------------------------------------------*/ +/*! + + Matrix singular value decomposition (SVD). + + This function calls the first following function that is available: + - svdLapack() if Lapack 3rd party is installed + - svdEigen3() if Eigen3 3rd party is installed + - svdOpenCV() if OpenCV 3rd party is installed. + + If none of these previous 3rd parties is installed, we use by default + svdLapack() with a Lapack built-in version. + + Given matrix \f$M\f$, this function computes it singular value decomposition + such as + + \f[ M = U \Sigma V^{\top} \f] + + \warning This method is destructive wrt. to the matrix \f$ M \f$ to + decompose. You should make a COPY of that matrix if needed. + + \param w : Vector of singular values: \f$ \Sigma = diag(w) \f$. + + \param V : Matrix \f$ V \f$. + + The matrix object `(*this) is updated with \f$ U \f$. + + \note The singular values are ordered in decreasing + fashion in \e w. It means that the highest singular value is in \e w[0]. + + Here an example of SVD decomposition of a non square Matrix M. + + \code + #include + + int main() + { + vpMatrix M(3,2); + M[0][0] = 1; M[0][1] = 6; + M[1][0] = 2; M[1][1] = 8; + M[2][0] = 0.5; M[2][1] = 9; + + vpColVector w; + vpMatrix V, Sigma, U = M; + + U.svd(w, V); + + // Construct the diagonal matrix from the singular values + Sigma.diag(w); + + // Reconstruct the initial matrix using the decomposition + vpMatrix Mrec = U * Sigma * V.t(); + + // Here, Mrec is obtained equal to the initial value of M + // Mrec[0][0] = 1; Mrec[0][1] = 6; + // Mrec[1][0] = 2; Mrec[1][1] = 8; + // Mrec[2][0] = 0.5; Mrec[2][1] = 9; + + std::cout << "Reconstructed M matrix: \n" << Mrec << std::endl; + } + \endcode + + \sa svdLapack(), svdEigen3(), svdOpenCV() +*/ +void vpMatrix::svd(vpColVector &w, vpMatrix &V) +{ +#if defined(VISP_HAVE_LAPACK) + svdLapack(w, V); +#elif defined(VISP_HAVE_EIGEN3) + svdEigen3(w, V); +#elif defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 + svdOpenCV(w, V); +#else + (void)w; + (void)V; + throw(vpException(vpException::fatalError, "Cannot compute SVD. Install Lapack, Eigen3 or OpenCV 3rd party")); +#endif +} #if defined(VISP_HAVE_OPENCV) // Require opencv >= 2.1.1 diff --git a/modules/core/src/math/matrix/vpRowVector.cpp b/modules/core/src/math/matrix/vpRowVector.cpp index b4573e870c..7fc4dfb89f 100644 --- a/modules/core/src/math/matrix/vpRowVector.cpp +++ b/modules/core/src/math/matrix/vpRowVector.cpp @@ -29,8 +29,7 @@ * * Description: * Operation on row vectors. - * -*****************************************************************************/ + */ /*! \file vpRowVector.cpp diff --git a/modules/core/src/tools/endian/vpEndian.cpp b/modules/core/src/tools/endian/vpEndian.cpp index c334d45234..7524f8e143 100644 --- a/modules/core/src/tools/endian/vpEndian.cpp +++ b/modules/core/src/tools/endian/vpEndian.cpp @@ -46,7 +46,13 @@ namespace vpEndian Swap 16 bits by shifting to the right the first byte and by shifting to the left the second byte. */ -uint16_t swap16bits(uint16_t val) { return (((val >> 8) & 0x00FF) | ((val << 8) & 0xFF00)); } +uint16_t swap16bits(uint16_t val) +{ + const unsigned int magic_8 = 8; + const unsigned int magic_0x00FF = 0x00FF; + const unsigned int magic_0xFF00 = 0xFF00; + return (((val >> magic_8) & magic_0x00FF) | ((val << magic_8) & magic_0xFF00)); +} /*! Swap 32 bits by shifting to the right the first 2 bytes and by shifting to @@ -54,8 +60,14 @@ uint16_t swap16bits(uint16_t val) { return (((val >> 8) & 0x00FF) | ((val << 8) */ uint32_t swap32bits(uint32_t val) { - return (((val >> 24) & 0x000000FF) | ((val >> 8) & 0x0000FF00) | ((val << 8) & 0x00FF0000) | - ((val << 24) & 0xFF000000)); + const unsigned int magic_8 = 8; + const unsigned int magic_24 = 24; + const unsigned int magic_0x000000FF = 0x000000FF; + const unsigned int magic_0x0000FF00 = 0x0000FF00; + const unsigned int magic_0x00FF0000 = 0x00FF0000; + const unsigned int magic_0xFF000000 = 0xFF000000; + return (((val >> magic_24) & magic_0x000000FF) | ((val >> magic_8) & magic_0x0000FF00) | ((val << magic_8) & magic_0x00FF0000) | + ((val << magic_24) & magic_0xFF000000)); } /*! diff --git a/modules/core/src/tools/file/vpIoTools.cpp b/modules/core/src/tools/file/vpIoTools.cpp index 3781995b7c..b1fb4dd73d 100644 --- a/modules/core/src/tools/file/vpIoTools.cpp +++ b/modules/core/src/tools/file/vpIoTools.cpp @@ -91,7 +91,6 @@ #endif #endif - #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX #define VP_STAT stat #elif defined(_WIN32) && defined(__MINGW32__) @@ -101,420 +100,6 @@ #else #define VP_STAT stat #endif - -#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98) && defined(VISP_HAVE_MINIZ) -#define USE_ZLIB_API 0 - -#if !USE_ZLIB_API -// See: https://github.com/BinomialLLC/basis_universal/blob/master/encoder/basisu_miniz.h -// Apache License, Version 2.0 -#include "basisu_miniz.h" - -using namespace buminiz; -#else -#include -#endif - -// To avoid warnings such as: warning: unused variable ‘littleEndian’ [-Wunused-variable] -#define UNUSED(x) ((void)(x)) // see: https://stackoverflow.com/a/777359 - -// Copyright (C) 2011 Carl Rogers -// Released under MIT License -// license available in LICENSE file, or at http://www.opensource.org/licenses/mit-license.php - -#include - -char visp::cnpy::BigEndianTest() -{ - int x = 1; - return (((reinterpret_cast(&x))[0]) ? '<' : '>'); -} - -char visp::cnpy::map_type(const std::type_info &t) -{ - if (t == typeid(float)) { return 'f'; } - if (t == typeid(double)) { return 'f'; } - if (t == typeid(long double)) { return 'f'; } - - if (t == typeid(int)) { return 'i'; } - if (t == typeid(char)) { return 'i'; } - if (t == typeid(short)) { return 'i'; } - if (t == typeid(long)) { return 'i'; } - if (t == typeid(long long)) { return 'i'; } - - if (t == typeid(unsigned char)) { return 'u'; } - if (t == typeid(unsigned short)) { return 'u'; } - if (t == typeid(unsigned long)) { return 'u'; } - if (t == typeid(unsigned long long)) { return 'u'; } - if (t == typeid(unsigned int)) { return 'u'; } - - if (t == typeid(bool)) { return 'b'; } - - if (t == typeid(std::complex)) { return 'c'; } - if (t == typeid(std::complex)) { return 'c'; } - if (t == typeid(std::complex)) { return 'c'; } - - else { return '?'; } -} - -void visp::cnpy::parse_npy_header(unsigned char *buffer, size_t &word_size, std::vector &shape, bool &fortran_order) -{ - uint16_t header_len = *reinterpret_cast(buffer+8); - std::string header(reinterpret_cast(buffer+9), header_len); - - //fortran order - size_t loc1 = header.find("fortran_order")+16; - fortran_order = (header.substr(loc1, 4) == "True" ? true : false); - - //shape - loc1 = header.find("("); - size_t loc2 = header.find(")"); - - std::regex num_regex("[0-9][0-9]*"); - std::smatch sm; - shape.clear(); - - std::string str_shape = header.substr(loc1+1, loc2-loc1-1); - while (std::regex_search(str_shape, sm, num_regex)) { - shape.push_back(std::stoi(sm[0].str())); - str_shape = sm.suffix().str(); - } - - //endian, word size, data type - //byte order code | stands for not applicable. - //not sure when this applies except for byte array - loc1 = header.find("descr")+9; - bool littleEndian = (((header[loc1] == '<') || (header[loc1] == '|')) ? true : false); - UNUSED(littleEndian); assert(littleEndian); - - std::string str_ws = header.substr(loc1+2); - loc2 = str_ws.find("'"); - word_size = atoi(str_ws.substr(0, loc2).c_str()); -} - -void visp::cnpy::parse_npy_header(FILE *fp, size_t &word_size, std::vector &shape, bool &fortran_order) -{ - char buffer[256]; - size_t res = fread(buffer, sizeof(char), 11, fp); - if (res != 11) { - throw std::runtime_error("parse_npy_header: failed fread"); - } - std::string header = fgets(buffer, 256, fp); - assert(header[header.size()-1] == '\n'); - - size_t loc1, loc2; - - //fortran order - loc1 = header.find("fortran_order"); - if (loc1 == std::string::npos) { - throw std::runtime_error("parse_npy_header: failed to find header keyword: 'fortran_order'"); - } - loc1 += 16; - fortran_order = (header.substr(loc1, 4) == "True" ? true : false); - - //shape - loc1 = header.find("("); - loc2 = header.find(")"); - if ((loc1 == std::string::npos) || (loc2 == std::string::npos)) { - throw std::runtime_error("parse_npy_header: failed to find header keyword: '(' or ')'"); - } - - std::regex num_regex("[0-9][0-9]*"); - std::smatch sm; - shape.clear(); - - std::string str_shape = header.substr(loc1+1, loc2-loc1-1); - while (std::regex_search(str_shape, sm, num_regex)) { - shape.push_back(std::stoi(sm[0].str())); - str_shape = sm.suffix().str(); - } - - //endian, word size, data type - //byte order code | stands for not applicable. - //not sure when this applies except for byte array - loc1 = header.find("descr"); - if (loc1 == std::string::npos) { - throw std::runtime_error("parse_npy_header: failed to find header keyword: 'descr'"); - } - loc1 += 9; - bool littleEndian = ((header[loc1] == '<') || (header[loc1] == '|') ? true : false); - UNUSED(littleEndian); assert(littleEndian); - - // --comment: char type equals header[loc1+1]; - // --comment: assert type equals map_type(T); - - std::string str_ws = header.substr(loc1+2); - loc2 = str_ws.find("'"); - word_size = atoi(str_ws.substr(0, loc2).c_str()); -} - -void visp::cnpy::parse_zip_footer(FILE *fp, uint16_t &nrecs, size_t &global_header_size, size_t &global_header_offset) -{ - std::vector footer(22); - fseek(fp, -22, SEEK_END); - size_t res = fread(&footer[0], sizeof(char), 22, fp); - if (res != 22) { - throw std::runtime_error("parse_zip_footer: failed fread"); - } - - uint16_t disk_no, disk_start, nrecs_on_disk, comment_len; - disk_no = *(uint16_t *)&footer[4]; - disk_start = *(uint16_t *)&footer[6]; - nrecs_on_disk = *(uint16_t *)&footer[8]; - nrecs = *(uint16_t *)&footer[10]; - global_header_size = *(uint32_t *)&footer[12]; - global_header_offset = *(uint32_t *)&footer[16]; - comment_len = *(uint16_t *)&footer[20]; - - UNUSED(disk_no); assert(disk_no == 0); - UNUSED(disk_start); assert(disk_start == 0); - UNUSED(nrecs_on_disk); assert(nrecs_on_disk == nrecs); - UNUSED(comment_len); assert(comment_len == 0); -} - -visp::cnpy::NpyArray load_the_npy_file(FILE *fp) -{ - std::vector shape; - size_t word_size; - bool fortran_order; - visp::cnpy::parse_npy_header(fp, word_size, shape, fortran_order); - - visp::cnpy::NpyArray arr(shape, word_size, fortran_order); - size_t nread = fread(arr.data(), 1, arr.num_bytes(), fp); - if (nread != arr.num_bytes()) { - throw std::runtime_error("load_the_npy_file: failed fread"); - } - return arr; -} - -visp::cnpy::NpyArray load_the_npz_array(FILE *fp, uint32_t compr_bytes, uint32_t uncompr_bytes) -{ - std::vector buffer_compr(compr_bytes); - std::vector buffer_uncompr(uncompr_bytes); - size_t nread = fread(&buffer_compr[0], 1, compr_bytes, fp); - if (nread != compr_bytes) { - throw std::runtime_error("load_the_npy_file: failed fread"); - } - - z_stream d_stream; - - d_stream.zalloc = Z_NULL; - d_stream.zfree = Z_NULL; - d_stream.opaque = Z_NULL; - d_stream.avail_in = 0; - d_stream.next_in = Z_NULL; - int err = inflateInit2(&d_stream, -MAX_WBITS); - UNUSED(err); assert(err == 0); - - d_stream.avail_in = compr_bytes; - d_stream.next_in = &buffer_compr[0]; - d_stream.avail_out = uncompr_bytes; - d_stream.next_out = &buffer_uncompr[0]; - - err = inflate(&d_stream, Z_FINISH); - UNUSED(err); assert(err == 0); - err = inflateEnd(&d_stream); - UNUSED(err); assert(err == 0); - - std::vector shape; - size_t word_size; - bool fortran_order; - visp::cnpy::parse_npy_header(&buffer_uncompr[0], word_size, shape, fortran_order); - - visp::cnpy::NpyArray array(shape, word_size, fortran_order); - - size_t offset = uncompr_bytes - array.num_bytes(); - memcpy(array.data(), &buffer_uncompr[0]+offset, array.num_bytes()); - - return array; -} - -/*! - Load the specified \p fname filepath as arrays of data. This function is similar to the - numpy.load function. - \param[in] fname : Path to the npz file. - \return A map of arrays data. The key represents the variable name, the value is an array of basic data type. - \warning This function has only been tested on little endian platform. - \note Original library: cnpy with MIT license. - */ -visp::cnpy::npz_t visp::cnpy::npz_load(std::string fname) -{ - FILE *fp = fopen(fname.c_str(), "rb"); - - if (!fp) { - throw std::runtime_error("npz_load: Error! Unable to open file "+fname+"!"); - } - - visp::cnpy::npz_t arrays; - bool quit = false; - const unsigned int index_2 = 2; - const unsigned int index_3 = 3; - const unsigned int index_26 = 26; - const unsigned int index_28 = 28; - const unsigned int val_8 = 8; - const unsigned int val_18 = 18; - const unsigned int val_22 = 22; - const unsigned int val_30 = 30; - while (!quit) { - std::vector local_header(30); - size_t headerres = fread(&local_header[0], sizeof(char), val_30, fp); - if (headerres != 30) { - throw std::runtime_error("npz_load: failed fread"); - } - - //if we've reached the global header, stop reading - if ((local_header[index_2] != 0x03) || (local_header[index_3] != 0x04)) { - quit = true; - } - else { - //read in the variable name - uint16_t name_len = *(uint16_t *)&local_header[index_26]; - std::string varname(name_len, ' '); - size_t vname_res = fread(&varname[0], sizeof(char), name_len, fp); - if (vname_res != name_len) { - throw std::runtime_error("npz_load: failed fread"); - } - - //erase the lagging .npy - varname.erase(varname.end()-4, varname.end()); - - //read in the extra field - uint16_t extra_field_len = *(uint16_t *)&local_header[index_28]; - if (extra_field_len > 0) { - std::vector buff(extra_field_len); - size_t efield_res = fread(&buff[0], sizeof(char), extra_field_len, fp); - if (efield_res != extra_field_len) { - throw std::runtime_error("npz_load: failed fread"); - } - } - - uint16_t compr_method = *reinterpret_cast(&local_header[0] + val_8); - uint32_t compr_bytes = *reinterpret_cast(&local_header[0] + val_18); - uint32_t uncompr_bytes = *reinterpret_cast(&local_header[0] + val_22); - - if (compr_method == 0) { arrays[varname] = load_the_npy_file(fp); } - else { arrays[varname] = load_the_npz_array(fp, compr_bytes, uncompr_bytes); } - } - } - - fclose(fp); - return arrays; -} - -/*! - Load the specified \p varname array of data from the \p fname npz file. This function is similar to the - numpy.load function. - \param[in] fname : Path to the npz file. - \param[in] varname : Identifier for the requested array of data. - \return An array of basic data type. - \warning This function has only been tested on little endian platform. - \note Original library: cnpy with MIT license. - */ -visp::cnpy::NpyArray visp::cnpy::npz_load(std::string fname, std::string varname) -{ - FILE *fp = fopen(fname.c_str(), "rb"); - - if (!fp) { - throw std::runtime_error("npz_load: Unable to open file "+fname); - } - - bool quit = false; - const unsigned int index_2 = 2; - const unsigned int index_3 = 3; - const unsigned int index_26 = 26; - const unsigned int index_28 = 28; - const unsigned int val_8 = 8; - const unsigned int val_18 = 18; - const unsigned int val_22 = 22; - const unsigned int val_30 = 30; - while (!quit) { - std::vector local_header(30); - size_t header_res = fread(&local_header[0], sizeof(char), val_30, fp); - if (header_res != 30) { - throw std::runtime_error("npz_load: failed fread"); - } - - //if we've reached the global header, stop reading - if ((local_header[index_2] != 0x03) || (local_header[index_3] != 0x04)) { - quit = true; - } - else { - //read in the variable name - uint16_t name_len = *(uint16_t *)&local_header[index_26]; - std::string vname(name_len, ' '); - size_t vname_res = fread(&vname[0], sizeof(char), name_len, fp); - if (vname_res != name_len) { - throw std::runtime_error("npz_load: failed fread"); - } - vname.erase(vname.end()-4, vname.end()); //erase the lagging .npy - - //read in the extra field - uint16_t extra_field_len = *(uint16_t *)&local_header[index_28]; - fseek(fp, extra_field_len, SEEK_CUR); //skip past the extra field - - uint16_t compr_method = *reinterpret_cast(&local_header[0] + val_8); - uint32_t compr_bytes = *reinterpret_cast(&local_header[0] + val_18); - uint32_t uncompr_bytes = *reinterpret_cast(&local_header[0] + val_22); - - if (vname == varname) { - NpyArray array = (compr_method == 0) ? load_the_npy_file(fp) : load_the_npz_array(fp, compr_bytes, uncompr_bytes); - fclose(fp); - return array; - } - else { - //skip past the data - uint32_t size = *(uint32_t *)&local_header[22]; - fseek(fp, size, SEEK_CUR); - } - } - } - - fclose(fp); - - //if we get here, we haven't found the variable in the file - throw std::runtime_error("npz_load: Variable name "+varname+" not found in "+fname); -} - -/*! - Load the specified npy \p fname filepath as one array of data. This function is similar to the - numpy.load function. - \param[in] fname : Path to the npy file. - \return An array of basic data type. - \warning This function has only been tested on little endian platform. - \note Original library: cnpy with MIT license. - */ -visp::cnpy::NpyArray visp::cnpy::npy_load(std::string fname) -{ - - FILE *fp = fopen(fname.c_str(), "rb"); - - if (!fp) { - throw std::runtime_error("npy_load: Unable to open file "+fname); - } - - NpyArray arr = load_the_npy_file(fp); - - fclose(fp); - return arr; -} - -#endif - -BEGIN_VISP_NAMESPACE -std::string vpIoTools::baseName = ""; -std::string vpIoTools::baseDir = ""; -std::string vpIoTools::configFile = ""; -std::vector vpIoTools::configVars = std::vector(); -std::vector vpIoTools::configValues = std::vector(); - -const char vpIoTools::separator = -#if defined(_WIN32) -'\\'; -#else -'/'; -#endif -END_VISP_NAMESPACE - namespace { // The following code is not working on iOS since wordexp() is not available @@ -532,26 +117,6 @@ void replaceAll(std::string &str, const std::string &search, const std::string & } #endif #endif - -std::string <rim(std::string &s) -{ -#if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98 - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) { return !std::isspace(c); })); -#else - s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); -#endif - return s; -} - -std::string &rtrim(std::string &s) -{ -#if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98 - s.erase(std::find_if(s.rbegin(), s.rend(), [](int c) { return !std::isspace(c); }).base(), s.end()); -#else - s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); -#endif - return s; -} } // namespace BEGIN_VISP_NAMESPACE @@ -652,34 +217,6 @@ std::string vpIoTools::getTempPath() #endif } -/*! - Sets the base name (prefix) of the experiment files. - - \param s : Prefix of the experiment files. -*/ -void vpIoTools::setBaseName(const std::string &s) { baseName = s; } - -/*! - Sets the base directory of the experiment files. - - \param dir : Directory where the data will be saved. -*/ -void vpIoTools::setBaseDir(const std::string &dir) { baseDir = dir + "/"; } - -/*! - Gets the base name (prefix) of the experiment files. - - \return the base name of the experiment files. -*/ -std::string vpIoTools::getBaseName() { return baseName; } - -/*! - Gets the full path of the experiment files : baseDir/baseName - - \return the full path of the experiment files. -*/ -std::string vpIoTools::getFullName() { return baseDir + baseName; } - /*! Get the user name. @@ -758,24 +295,24 @@ std::string vpIoTools::getUserName() getting the environment variable value. \code -#include -#include -#include + #include + #include + #include -int main() -{ - std::string envvalue; - try { - std::string env = "HOME"; - envvalue = vpIoTools::getenv(env); - std::cout << "$HOME = \"" << envvalue << "\"" << std::endl; - } - catch (const vpException &e) { - std::cout << e.getMessage() << std::endl; - return -1; + int main() + { + std::string envvalue; + try { + std::string env = "HOME"; + envvalue = vpIoTools::getenv(env); + std::cout << "$HOME = \"" << envvalue << "\"" << std::endl; + } + catch (const vpException &e) { + std::cout << e.getMessage() << std::endl; + return -1; + } + return 0; } - return 0; -} \endcode */ std::string vpIoTools::getenv(const std::string &env) @@ -1487,379 +1024,17 @@ std::string vpIoTools::path(const std::string &pathname) } /*! - Reads the configuration file and parses it. - - \param confFile : path to the file containing the configuration parameters to - parse. - - \return true if succeed, false otherwise. - */ -bool vpIoTools::loadConfigFile(const std::string &confFile) -{ - configFile = path(confFile); - configVars.clear(); - configValues.clear(); - std::ifstream confContent(configFile.c_str(), std::ios::in); - - if (confContent.is_open()) { - std::string line, var, val; - unsigned long int k; - int c; - std::string stop[3] = { " ", "\t", "#" }; - while (std::getline(confContent, line)) { - if ((line.compare(0, 1, "#") != 0) && (line.size() > 2)) { - // name of the variable - k = static_cast(line.find(" ")); - var = line.substr(0, k); - // look for the end of the actual value - c = 200; - for (unsigned i = 0; i < 3; ++i) { - c = vpMath::minimum(c, - static_cast(line.find(stop[i], static_cast(k) + static_cast(1)))); - } - if (c == -1) { - c = static_cast(line.size()); - } - unsigned long int c_ = static_cast(c); - val = line.substr(static_cast(k) + static_cast(1), - static_cast(c_) - static_cast(k) - static_cast(1)); - configVars.push_back(var); - configValues.push_back(val); - } - } - confContent.close(); - } - else { - return false; - } - return true; -} - -/*! - Tries to read the parameter named \e var as a \e float. - - \param var : Name of the parameter in the configuration file. - \param value : Value to be read. - - \return true if the parameter could be read. -*/ -bool vpIoTools::readConfigVar(const std::string &var, float &value) -{ - bool found = false; - unsigned int configvars_size = configVars.size(); - unsigned int k = 0; - while ((k < configvars_size) && (!found)) { - if (configVars[k] == var) { - if (configValues[k].compare("PI") == 0) { - value = static_cast(M_PI); - } - else if (configValues[k].compare("PI/2") == 0) { - value = static_cast(M_PI / 2.0); - } - else if (configValues[k].compare("-PI/2") == 0) { - value = static_cast(-M_PI / 2.0); - } - else { - value = static_cast(atof(configValues[k].c_str())); - } - found = true; - } - ++k; - } - if (!found) { - std::cout << var << " not found in config file" << std::endl; - } - return found; -} -/*! - Tries to read the parameter named \e var as a \e double. - - \param var : Name of the parameter in the configuration file. - \param value : Value to be read. - - \return true if the parameter could be read. -*/ -bool vpIoTools::readConfigVar(const std::string &var, double &value) -{ - bool found = false; - unsigned int configvars_size = configVars.size(); - unsigned int k = 0; - while ((k < configvars_size) && (!found)) { - if (configVars[k] == var) { - if (configValues[k].compare("PI") == 0) { - value = M_PI; - } - else if (configValues[k].compare("PI/2") == 0) { - value = M_PI / 2; - } - else if (configValues[k].compare("-PI/2") == 0) { - value = -M_PI / 2; - } - else { - value = atof(configValues[k].c_str()); - } - found = true; - } - ++k; - } - if (!found) { - std::cout << var << " not found in config file" << std::endl; - } - return found; -} - -/*! - Tries to read the parameter named \e var as a \e int. - - \param var : Name of the parameter in the configuration file. - \param value : Value to be read. - - \return true if the parameter could be read. -*/ -bool vpIoTools::readConfigVar(const std::string &var, int &value) -{ - bool found = false; - unsigned int configvars_size = configVars.size(); - unsigned int k = 0; - while ((k < configvars_size) && (!found)) { - if (configVars[k] == var) { - value = atoi(configValues[k].c_str()); - found = true; - } - ++k; - } - if (!found) { - std::cout << var << " not found in config file" << std::endl; - } - return found; -} - -/*! - Tries to read the parameter named \e var as a \e unsigned int. - - \param var : Name of the parameter in the configuration file. - \param value : Value to be read. - - \return true if the parameter could be read. -*/ -bool vpIoTools::readConfigVar(const std::string &var, unsigned int &value) -{ - int v = 0; - bool found = readConfigVar(var, v); - value = static_cast(v); - return found; -} - -/*! - Tries to read the parameter named \e var as a \e bool. - - \param var : Name of the parameter in the configuration file. - \param value : Value to be read. - - \return true if the parameter could be read. -*/ -bool vpIoTools::readConfigVar(const std::string &var, bool &value) -{ - int v = 0; - bool found = readConfigVar(var, v); - value = (v != 0); - return found; -} - -/*! - Tries to read the parameter named \e var as a \e vpColor. - - \param var : Name of the parameter in the configuration file. - \param value : Value to be read. See vpColor.cpp for the color number. - - \return true if the parameter could be read. -*/ -bool vpIoTools::readConfigVar(const std::string &var, vpColor &value) -{ - unsigned int v = 0; - bool found = readConfigVar(var, v); - value = vpColor::getColor(v); - return found; -} - -/*! - Tries to read the parameter named \e var as a \e std::string. - - \param var : Name of the parameter in the configuration file. - \param value : Value to be read. - - \return true if the parameter could be read. -*/ -bool vpIoTools::readConfigVar(const std::string &var, std::string &value) -{ - bool found = false; - unsigned int configvars_size = configVars.size(); - unsigned int k = 0; - while ((k < configvars_size) && (!found)) { - if (configVars[k] == var) { - value = configValues[k]; - found = true; - } - ++k; - } - if (!found) { - std::cout << var << " not found in config file" << std::endl; - } - return found; -} - -/*! - Tries to read the parameter named \e var as a \e vpMatrix. - If \e nCols and \e nRows are indicated, will resize the matrix. - Otherwise, will try to read as many values as indicated by the dimension of - \e value. - - \param var : Name of the parameter in the configuration file. - \param value : Value to be read. - \param nCols : Column dimension if resized. - \param nRows : Row dimension if resized - - \return true if the parameter could be read. -*/ -bool vpIoTools::readConfigVar(const std::string &var, vpArray2D &value, const unsigned int &nCols, - const unsigned int &nRows) -{ - bool found = false; - std::string nb; - unsigned int configvars_size = configVars.size(); - unsigned int k = 0; - while ((k < configvars_size) && (!found)) { - if (configVars[k] == var) { - found = true; - // resize or not - if ((nCols != 0) && (nRows != 0)) { - value.resize(nRows, nCols); - } - size_t ind = 0, ind2; - unsigned int value_rows = value.getRows(); - unsigned int value_cols = value.getCols(); - for (unsigned int i = 0; i < value_rows; ++i) { - for (unsigned int j = 0; j < value_cols; ++j) { - ind2 = configValues[k].find(",", ind); - nb = configValues[k].substr(ind, ind2 - ind); - if (nb.compare("PI") == 0) { - value[i][j] = M_PI; - } - else if (nb.compare("PI/2") == 0) { - value[i][j] = M_PI / 2; - } - else if (nb.compare("-PI/2") == 0) { - value[i][j] = -M_PI / 2; - } - else { - value[i][j] = atof(nb.c_str()); - } - ind = ind2 + 1; - } - } - } - ++k; - } - if (found == false) { - std::cout << var << " not found in config file" << std::endl; - } - return found; -} - -// construct experiment filename & path - -/*! - Augments the prefix of the experiment files by \e strTrue if \e cond is - verified, and by \e strFalse otherwise. - - \param strTrue : String to add if \e cond is true - \param cond : Condition managing the file name - \param strFalse : String to add if \e cond is false (default "") -*/ -void vpIoTools::addNameElement(const std::string &strTrue, const bool &cond, const std::string &strFalse) -{ - if (cond) { - baseName += "_" + strTrue; - } - else if (strFalse != "") { - baseName += "_" + strFalse; - } -} - -/*! - Augments the prefix of the experiment files by \e strTrue followed by \e - val. - - \param strTrue : String to add - \param val : Value to add - -*/ -void vpIoTools::addNameElement(const std::string &strTrue, const double &val) -{ - // if(val != 0.) - if (std::fabs(val) < std::numeric_limits::epsilon()) { - std::stringstream valS; - valS.precision(4); - valS << val; - baseName += "_" + strTrue + valS.str(); - } -} - -/*! - Creates the directory \e baseDir/baseName. If already exists, empties - it if \e empty is true. - Useful to save the images corresponding to a particular experiment. - - \param empty : Indicates if the new directory has to be emptied - -*/ -void vpIoTools::createBaseNamePath(const bool &empty) -{ - std::string path = baseDir + baseName; - if (vpIoTools::checkDirectory(path) == false) { - try { - vpIoTools::makeDirectory(path); - std::cout << "Creating directory " << path << std::endl; - } - catch (...) { - throw(vpException(vpException::fatalError, "Cannot create base name directory %s", path.c_str())); - } - } - else { - if (empty) { - std::cout << "Emptying directory " << path << std::endl; - vpIoTools::remove(path + "/*"); - } - } -} - -/*! - Copy the initial configuration file to the experiment directory. - - \param actuallySave : If false, do not copy the file. - -*/ -void vpIoTools::saveConfigFile(const bool &actuallySave) -{ - if (actuallySave) { - std::string dest = baseDir + "/" + baseName + "_config.txt"; - // file copy - vpIoTools::copy(configFile, dest); - } -} - -/*! - Get ViSP images data path. ViSP images data can be installed from Debian or - Ubuntu \e visp-images-data package. It can be also installed from - visp-images-3.x.y.zip that can be found on https://visp.inria.fr/download page. - - This function returns the path to the folder that contains the data. - - It checks first if VISP_INPUT_IMAGE_PATH environment variable that gives the - location of the data is set. In that case returns the content of this - environment var. - - Otherwise it checks if \e visp-images-data binary package (Ubuntu, Debian) is installed. - In that case returns then \e /usr/share/visp-images-data". - - If the path is not found, returns an empty string. + Get ViSP images data path. ViSP images data can be installed from Debian or + Ubuntu \e visp-images-data package. It can be also installed from + visp-images-3.x.y.zip that can be found on https://visp.inria.fr/download page. + + This function returns the path to the folder that contains the data. + - It checks first if VISP_INPUT_IMAGE_PATH environment variable that gives the + location of the data is set. In that case returns the content of this + environment var. + - Otherwise it checks if \e visp-images-data binary package (Ubuntu, Debian) is installed. + In that case returns then \e /usr/share/visp-images-data". + - If the path is not found, returns an empty string. */ std::string vpIoTools::getViSPImagesDataPath() { @@ -2407,52 +1582,52 @@ std::pair vpIoTools::splitDrive(const std::string &pat } /*! - Split a chain. - \param chain : Input chain to split. - \param sep : Character separator. - \return A vector that contains all the subchains. + Split a chain. + \param chain : Input chain to split. + \param sep : Character separator. + \return A vector that contains all the subchains. - The following code shows how to use this function: - \code -#include + The following code shows how to use this function: + \code + #include -int main() -{ + int main() { - std::string chain("/home/user;/usr/local/include;/usr/include"); - std::string sep = ";"; + { + std::string chain("/home/user;/usr/local/include;/usr/include"); + std::string sep = ";"; - std::vector subChain = vpIoTools::splitChain(chain, sep); - std::cout << "Found the following subchains: " << std::endl; - for (size_t i=0; i < subChain.size(); ++i) - std::cout << subChain[i] << std::endl; - } + std::vector subChain = vpIoTools::splitChain(chain, sep); + std::cout << "Found the following subchains: " << std::endl; + for (size_t i=0; i < subChain.size(); ++i) + std::cout << subChain[i] << std::endl; + } - { - std::string chain("This is an other example"); - std::string sep = " "; + { + std::string chain("This is an other example"); + std::string sep = " "; - std::vector subChain = vpIoTools::splitChain(chain, sep); - std::cout << "Found the following subchains: " << std::endl; - for (size_t i=0; i < subChain.size(); ++i) - std::cout << subChain[i] << std::endl; + std::vector subChain = vpIoTools::splitChain(chain, sep); + std::cout << "Found the following subchains: " << std::endl; + for (size_t i=0; i < subChain.size(); ++i) + std::cout << subChain[i] << std::endl; + } } -} - \endcode - - It produces the following output: - \code -Found the following subchains: -/home/user -/usr/local/include -/usr/include -Found the following subchains: -This -is -an -other -example - \endcode + \endcode + + It produces the following output: + \code + Found the following subchains: + /home/user + /usr/local/include + /usr/include + Found the following subchains: + This + is + an + other + example + \endcode */ std::vector vpIoTools::splitChain(const std::string &chain, const std::string &sep) { @@ -2546,181 +1721,4 @@ std::vector vpIoTools::getDirFiles(const std::string &pathname) #endif } -/*! - Read a 16-bits integer value stored in little endian. - */ -void vpIoTools::readBinaryValueLE(std::ifstream &file, int16_t &short_value) -{ - file.read((char *)(&short_value), sizeof(short_value)); - -#ifdef VISP_BIG_ENDIAN - // Swap bytes order from little endian to big endian - short_value = vpEndian::swap16bits((uint16_t)short_value); -#endif -} - -/*! - Read a 16-bits unsigned integer value stored in little endian. - */ -void vpIoTools::readBinaryValueLE(std::ifstream &file, uint16_t &ushort_value) -{ - file.read((char *)(&ushort_value), sizeof(ushort_value)); - -#ifdef VISP_BIG_ENDIAN - // Swap bytes order from little endian to big endian - ushort_value = vpEndian::swap16bits(ushort_value); -#endif -} - -/*! - Read a 32-bits integer value stored in little endian. - */ -void vpIoTools::readBinaryValueLE(std::ifstream &file, int32_t &int_value) -{ - file.read((char *)(&int_value), sizeof(int_value)); - -#ifdef VISP_BIG_ENDIAN - // Swap bytes order from little endian to big endian - int_value = vpEndian::swap32bits((uint32_t)int_value); -#endif -} - -/*! - Read a 32-bits unsigned integer value stored in little endian. - */ -void vpIoTools::readBinaryValueLE(std::ifstream &file, uint32_t &uint_value) -{ - file.read((char *)(&uint_value), sizeof(uint_value)); - -#ifdef VISP_BIG_ENDIAN - // Swap bytes order from little endian to big endian - uint_value = vpEndian::swap32bits(uint_value); -#endif -} - -/*! - Read a float value stored in little endian. - */ -void vpIoTools::readBinaryValueLE(std::ifstream &file, float &float_value) -{ - file.read((char *)(&float_value), sizeof(float_value)); - -#ifdef VISP_BIG_ENDIAN - // Swap bytes order from little endian to big endian - float_value = vpEndian::swapFloat(float_value); -#endif -} - -/*! - Read a double value stored in little endian. - */ -void vpIoTools::readBinaryValueLE(std::ifstream &file, double &double_value) -{ - file.read((char *)(&double_value), sizeof(double_value)); - -#ifdef VISP_BIG_ENDIAN - // Swap bytes order from little endian to big endian - double_value = vpEndian::swapDouble(double_value); -#endif -} - -/*! - Write a 16-bits integer value in little endian. - */ -void vpIoTools::writeBinaryValueLE(std::ofstream &file, const int16_t short_value) -{ -#ifdef VISP_BIG_ENDIAN - // Swap bytes order to little endian - uint16_t swap_short = vpEndian::swap16bits((uint16_t)short_value); - file.write((char *)(&swap_short), sizeof(swap_short)); -#else - file.write((char *)(&short_value), sizeof(short_value)); -#endif -} - -/*! - Write a 16-bits unsigned integer value in little endian. - */ -void vpIoTools::writeBinaryValueLE(std::ofstream &file, const uint16_t ushort_value) -{ -#ifdef VISP_BIG_ENDIAN - // Swap bytes order to little endian - uint16_t swap_ushort = vpEndian::swap16bits(ushort_value); - file.write((char *)(&swap_ushort), sizeof(swap_ushort)); -#else - file.write((char *)(&ushort_value), sizeof(ushort_value)); -#endif -} - -/*! - Write a 32-bits integer value in little endian. - */ -void vpIoTools::writeBinaryValueLE(std::ofstream &file, const int32_t int_value) -{ -#ifdef VISP_BIG_ENDIAN - // Swap bytes order to little endian - uint32_t swap_int = vpEndian::swap32bits((uint32_t)int_value); - file.write((char *)(&swap_int), sizeof(swap_int)); -#else - file.write((char *)(&int_value), sizeof(int_value)); -#endif -} - -/*! - Write a 32-bits unsigned integer value in little endian. - */ -void vpIoTools::writeBinaryValueLE(std::ofstream &file, const uint32_t uint_value) -{ -#ifdef VISP_BIG_ENDIAN - // Swap bytes order to little endian - uint32_t swap_int = vpEndian::swap32bits(uint_value); - file.write((char *)(&swap_int), sizeof(swap_int)); -#else - file.write((char *)(&uint_value), sizeof(uint_value)); -#endif -} - -/*! - Write a float value in little endian. - */ -void vpIoTools::writeBinaryValueLE(std::ofstream &file, float float_value) -{ -#ifdef VISP_BIG_ENDIAN - // Swap bytes order to little endian - float swap_float = vpEndian::swapFloat(float_value); - file.write((char *)(&swap_float), sizeof(swap_float)); -#else - file.write((char *)(&float_value), sizeof(float_value)); -#endif -} - -/*! - Write a double value in little endian. - */ -void vpIoTools::writeBinaryValueLE(std::ofstream &file, double double_value) -{ -#ifdef VISP_BIG_ENDIAN - // Swap bytes order to little endian - double swap_double = vpEndian::swapDouble(double_value); - file.write((char *)(&swap_double), sizeof(swap_double)); -#else - file.write((char *)(&double_value), sizeof(double_value)); -#endif -} - -bool vpIoTools::parseBoolean(std::string input) -{ - std::transform(input.begin(), input.end(), input.begin(), ::tolower); - std::istringstream is(input); - bool b; - // Parse string to boolean either in the textual representation - // (True/False) or in numeric representation (1/0) - is >> (input.size() > 1 ? std::boolalpha : std::noboolalpha) >> b; - return b; -} - -/*! - Remove leading and trailing whitespaces from a string. - */ -std::string vpIoTools::trim(std::string s) { return ltrim(rtrim(s)); } END_VISP_NAMESPACE diff --git a/modules/core/src/tools/file/vpIoTools_config_file.cpp b/modules/core/src/tools/file/vpIoTools_config_file.cpp new file mode 100644 index 0000000000..d090a22a2d --- /dev/null +++ b/modules/core/src/tools/file/vpIoTools_config_file.cpp @@ -0,0 +1,643 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Io tools dedicated to npy. + */ + +#include +#include + +BEGIN_VISP_NAMESPACE + +std::string vpIoTools::baseName = ""; +std::string vpIoTools::baseDir = ""; +std::string vpIoTools::configFile = ""; +std::vector vpIoTools::configVars = std::vector(); +std::vector vpIoTools::configValues = std::vector(); + +const char vpIoTools::separator = +#if defined(_WIN32) +'\\'; +#else +'/'; +#endif + +namespace +{ +std::string <rim(std::string &s) +{ +#if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98 + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) { return !std::isspace(c); })); +#else + s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); +#endif + return s; +} + +std::string &rtrim(std::string &s) +{ +#if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98 + s.erase(std::find_if(s.rbegin(), s.rend(), [](int c) { return !std::isspace(c); }).base(), s.end()); +#else + s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); +#endif + return s; +} +} // namespace +/*! + Sets the base name (prefix) of the experiment files. + + \param s : Prefix of the experiment files. +*/ +void vpIoTools::setBaseName(const std::string &s) { baseName = s; } + +/*! + Sets the base directory of the experiment files. + + \param dir : Directory where the data will be saved. +*/ +void vpIoTools::setBaseDir(const std::string &dir) { baseDir = dir + "/"; } + +/*! + Gets the base name (prefix) of the experiment files. + + \return the base name of the experiment files. +*/ +std::string vpIoTools::getBaseName() { return baseName; } + +/*! + Gets the full path of the experiment files : baseDir/baseName + + \return the full path of the experiment files. +*/ +std::string vpIoTools::getFullName() { return baseDir + baseName; } + +/*! + Reads the configuration file and parses it. + + \param confFile : path to the file containing the configuration parameters to + parse. + + \return true if succeed, false otherwise. + */ +bool vpIoTools::loadConfigFile(const std::string &confFile) +{ + configFile = path(confFile); + configVars.clear(); + configValues.clear(); + std::ifstream confContent(configFile.c_str(), std::ios::in); + + if (confContent.is_open()) { + std::string line, var, val; + unsigned long int k; + int c; + std::string stop[3] = { " ", "\t", "#" }; + while (std::getline(confContent, line)) { + if ((line.compare(0, 1, "#") != 0) && (line.size() > 2)) { + // name of the variable + k = static_cast(line.find(" ")); + var = line.substr(0, k); + // look for the end of the actual value + c = 200; + for (unsigned i = 0; i < 3; ++i) { + c = vpMath::minimum(c, + static_cast(line.find(stop[i], static_cast(k) + static_cast(1)))); + } + if (c == -1) { + c = static_cast(line.size()); + } + unsigned long int c_ = static_cast(c); + val = line.substr(static_cast(k) + static_cast(1), + static_cast(c_) - static_cast(k) - static_cast(1)); + configVars.push_back(var); + configValues.push_back(val); + } + } + confContent.close(); + } + else { + return false; + } + return true; +} + +/*! + Tries to read the parameter named \e var as a \e float. + + \param var : Name of the parameter in the configuration file. + \param value : Value to be read. + + \return true if the parameter could be read. +*/ +bool vpIoTools::readConfigVar(const std::string &var, float &value) +{ + bool found = false; + unsigned int configvars_size = configVars.size(); + unsigned int k = 0; + while ((k < configvars_size) && (!found)) { + if (configVars[k] == var) { + if (configValues[k].compare("PI") == 0) { + value = static_cast(M_PI); + } + else if (configValues[k].compare("PI/2") == 0) { + value = static_cast(M_PI / 2.0); + } + else if (configValues[k].compare("-PI/2") == 0) { + value = static_cast(-M_PI / 2.0); + } + else { + value = static_cast(atof(configValues[k].c_str())); + } + found = true; + } + ++k; + } + if (!found) { + std::cout << var << " not found in config file" << std::endl; + } + return found; +} + +/*! + Tries to read the parameter named \e var as a \e double. + + \param var : Name of the parameter in the configuration file. + \param value : Value to be read. + + \return true if the parameter could be read. +*/ +bool vpIoTools::readConfigVar(const std::string &var, double &value) +{ + bool found = false; + unsigned int configvars_size = configVars.size(); + unsigned int k = 0; + while ((k < configvars_size) && (!found)) { + if (configVars[k] == var) { + if (configValues[k].compare("PI") == 0) { + value = M_PI; + } + else if (configValues[k].compare("PI/2") == 0) { + value = M_PI / 2; + } + else if (configValues[k].compare("-PI/2") == 0) { + value = -M_PI / 2; + } + else { + value = atof(configValues[k].c_str()); + } + found = true; + } + ++k; + } + if (!found) { + std::cout << var << " not found in config file" << std::endl; + } + return found; +} + +/*! + Tries to read the parameter named \e var as a \e int. + + \param var : Name of the parameter in the configuration file. + \param value : Value to be read. + + \return true if the parameter could be read. +*/ +bool vpIoTools::readConfigVar(const std::string &var, int &value) +{ + bool found = false; + unsigned int configvars_size = configVars.size(); + unsigned int k = 0; + while ((k < configvars_size) && (!found)) { + if (configVars[k] == var) { + value = atoi(configValues[k].c_str()); + found = true; + } + ++k; + } + if (!found) { + std::cout << var << " not found in config file" << std::endl; + } + return found; +} + +/*! + Tries to read the parameter named \e var as a \e unsigned int. + + \param var : Name of the parameter in the configuration file. + \param value : Value to be read. + + \return true if the parameter could be read. +*/ +bool vpIoTools::readConfigVar(const std::string &var, unsigned int &value) +{ + int v = 0; + bool found = readConfigVar(var, v); + value = static_cast(v); + return found; +} + +/*! + Tries to read the parameter named \e var as a \e bool. + + \param var : Name of the parameter in the configuration file. + \param value : Value to be read. + + \return true if the parameter could be read. +*/ +bool vpIoTools::readConfigVar(const std::string &var, bool &value) +{ + int v = 0; + bool found = readConfigVar(var, v); + value = (v != 0); + return found; +} + +/*! + Tries to read the parameter named \e var as a \e vpColor. + + \param var : Name of the parameter in the configuration file. + \param value : Value to be read. See vpColor.cpp for the color number. + + \return true if the parameter could be read. +*/ +bool vpIoTools::readConfigVar(const std::string &var, vpColor &value) +{ + unsigned int v = 0; + bool found = readConfigVar(var, v); + value = vpColor::getColor(v); + return found; +} + +/*! + Tries to read the parameter named \e var as a \e std::string. + + \param var : Name of the parameter in the configuration file. + \param value : Value to be read. + + \return true if the parameter could be read. +*/ +bool vpIoTools::readConfigVar(const std::string &var, std::string &value) +{ + bool found = false; + unsigned int configvars_size = configVars.size(); + unsigned int k = 0; + while ((k < configvars_size) && (!found)) { + if (configVars[k] == var) { + value = configValues[k]; + found = true; + } + ++k; + } + if (!found) { + std::cout << var << " not found in config file" << std::endl; + } + return found; +} + +/*! + Tries to read the parameter named \e var as a \e vpMatrix. + If \e nCols and \e nRows are indicated, will resize the matrix. + Otherwise, will try to read as many values as indicated by the dimension of + \e value. + + \param var : Name of the parameter in the configuration file. + \param value : Value to be read. + \param nCols : Column dimension if resized. + \param nRows : Row dimension if resized + + \return true if the parameter could be read. +*/ +bool vpIoTools::readConfigVar(const std::string &var, vpArray2D &value, const unsigned int &nCols, + const unsigned int &nRows) +{ + bool found = false; + std::string nb; + unsigned int configvars_size = configVars.size(); + unsigned int k = 0; + while ((k < configvars_size) && (!found)) { + if (configVars[k] == var) { + found = true; + // resize or not + if ((nCols != 0) && (nRows != 0)) { + value.resize(nRows, nCols); + } + size_t ind = 0, ind2; + unsigned int value_rows = value.getRows(); + unsigned int value_cols = value.getCols(); + for (unsigned int i = 0; i < value_rows; ++i) { + for (unsigned int j = 0; j < value_cols; ++j) { + ind2 = configValues[k].find(",", ind); + nb = configValues[k].substr(ind, ind2 - ind); + if (nb.compare("PI") == 0) { + value[i][j] = M_PI; + } + else if (nb.compare("PI/2") == 0) { + value[i][j] = M_PI / 2; + } + else if (nb.compare("-PI/2") == 0) { + value[i][j] = -M_PI / 2; + } + else { + value[i][j] = atof(nb.c_str()); + } + ind = ind2 + 1; + } + } + } + ++k; + } + if (found == false) { + std::cout << var << " not found in config file" << std::endl; + } + return found; +} + +// construct experiment filename & path + +/*! + Augments the prefix of the experiment files by \e strTrue if \e cond is + verified, and by \e strFalse otherwise. + + \param strTrue : String to add if \e cond is true + \param cond : Condition managing the file name + \param strFalse : String to add if \e cond is false (default "") +*/ +void vpIoTools::addNameElement(const std::string &strTrue, const bool &cond, const std::string &strFalse) +{ + if (cond) { + baseName += "_" + strTrue; + } + else if (strFalse != "") { + baseName += "_" + strFalse; + } +} + +/*! + Augments the prefix of the experiment files by \e strTrue followed by \e + val. + + \param strTrue : String to add + \param val : Value to add + +*/ +void vpIoTools::addNameElement(const std::string &strTrue, const double &val) +{ + // if(val != 0.) + if (std::fabs(val) < std::numeric_limits::epsilon()) { + std::stringstream valS; + valS.precision(4); + valS << val; + baseName += "_" + strTrue + valS.str(); + } +} + +/*! + Creates the directory \e baseDir/baseName. If already exists, empties + it if \e empty is true. + Useful to save the images corresponding to a particular experiment. + + \param empty : Indicates if the new directory has to be emptied + +*/ +void vpIoTools::createBaseNamePath(const bool &empty) +{ + std::string path = baseDir + baseName; + if (vpIoTools::checkDirectory(path) == false) { + try { + vpIoTools::makeDirectory(path); + std::cout << "Creating directory " << path << std::endl; + } + catch (...) { + throw(vpException(vpException::fatalError, "Cannot create base name directory %s", path.c_str())); + } + } + else { + if (empty) { + std::cout << "Emptying directory " << path << std::endl; + vpIoTools::remove(path + "/*"); + } + } +} + +/*! + Copy the initial configuration file to the experiment directory. + + \param actuallySave : If false, do not copy the file. + +*/ +void vpIoTools::saveConfigFile(const bool &actuallySave) +{ + if (actuallySave) { + std::string dest = baseDir + "/" + baseName + "_config.txt"; + // file copy + vpIoTools::copy(configFile, dest); + } +} + +/*! + Read a 16-bits integer value stored in little endian. + */ +void vpIoTools::readBinaryValueLE(std::ifstream &file, int16_t &short_value) +{ + file.read((char *)(&short_value), sizeof(short_value)); + +#ifdef VISP_BIG_ENDIAN + // Swap bytes order from little endian to big endian + short_value = vpEndian::swap16bits((uint16_t)short_value); +#endif +} + +/*! + Read a 16-bits unsigned integer value stored in little endian. + */ +void vpIoTools::readBinaryValueLE(std::ifstream &file, uint16_t &ushort_value) +{ + file.read((char *)(&ushort_value), sizeof(ushort_value)); + +#ifdef VISP_BIG_ENDIAN + // Swap bytes order from little endian to big endian + ushort_value = vpEndian::swap16bits(ushort_value); +#endif +} + +/*! + Read a 32-bits integer value stored in little endian. + */ +void vpIoTools::readBinaryValueLE(std::ifstream &file, int32_t &int_value) +{ + file.read((char *)(&int_value), sizeof(int_value)); + +#ifdef VISP_BIG_ENDIAN + // Swap bytes order from little endian to big endian + int_value = vpEndian::swap32bits((uint32_t)int_value); +#endif +} + +/*! + Read a 32-bits unsigned integer value stored in little endian. + */ +void vpIoTools::readBinaryValueLE(std::ifstream &file, uint32_t &uint_value) +{ + file.read((char *)(&uint_value), sizeof(uint_value)); + +#ifdef VISP_BIG_ENDIAN + // Swap bytes order from little endian to big endian + uint_value = vpEndian::swap32bits(uint_value); +#endif +} + +/*! + Read a float value stored in little endian. + */ +void vpIoTools::readBinaryValueLE(std::ifstream &file, float &float_value) +{ + file.read((char *)(&float_value), sizeof(float_value)); + +#ifdef VISP_BIG_ENDIAN + // Swap bytes order from little endian to big endian + float_value = vpEndian::swapFloat(float_value); +#endif +} + +/*! + Read a double value stored in little endian. + */ +void vpIoTools::readBinaryValueLE(std::ifstream &file, double &double_value) +{ + file.read((char *)(&double_value), sizeof(double_value)); + +#ifdef VISP_BIG_ENDIAN + // Swap bytes order from little endian to big endian + double_value = vpEndian::swapDouble(double_value); +#endif +} + +/*! + Write a 16-bits integer value in little endian. + */ +void vpIoTools::writeBinaryValueLE(std::ofstream &file, const int16_t short_value) +{ +#ifdef VISP_BIG_ENDIAN + // Swap bytes order to little endian + uint16_t swap_short = vpEndian::swap16bits((uint16_t)short_value); + file.write((char *)(&swap_short), sizeof(swap_short)); +#else + file.write((char *)(&short_value), sizeof(short_value)); +#endif +} + +/*! + Write a 16-bits unsigned integer value in little endian. + */ +void vpIoTools::writeBinaryValueLE(std::ofstream &file, const uint16_t ushort_value) +{ +#ifdef VISP_BIG_ENDIAN + // Swap bytes order to little endian + uint16_t swap_ushort = vpEndian::swap16bits(ushort_value); + file.write((char *)(&swap_ushort), sizeof(swap_ushort)); +#else + file.write((char *)(&ushort_value), sizeof(ushort_value)); +#endif +} + +/*! + Write a 32-bits integer value in little endian. + */ +void vpIoTools::writeBinaryValueLE(std::ofstream &file, const int32_t int_value) +{ +#ifdef VISP_BIG_ENDIAN + // Swap bytes order to little endian + uint32_t swap_int = vpEndian::swap32bits((uint32_t)int_value); + file.write((char *)(&swap_int), sizeof(swap_int)); +#else + file.write((char *)(&int_value), sizeof(int_value)); +#endif +} + +/*! + Write a 32-bits unsigned integer value in little endian. + */ +void vpIoTools::writeBinaryValueLE(std::ofstream &file, const uint32_t uint_value) +{ +#ifdef VISP_BIG_ENDIAN + // Swap bytes order to little endian + uint32_t swap_int = vpEndian::swap32bits(uint_value); + file.write((char *)(&swap_int), sizeof(swap_int)); +#else + file.write((char *)(&uint_value), sizeof(uint_value)); +#endif +} + +/*! + Write a float value in little endian. + */ +void vpIoTools::writeBinaryValueLE(std::ofstream &file, float float_value) +{ +#ifdef VISP_BIG_ENDIAN + // Swap bytes order to little endian + float swap_float = vpEndian::swapFloat(float_value); + file.write((char *)(&swap_float), sizeof(swap_float)); +#else + file.write((char *)(&float_value), sizeof(float_value)); +#endif +} + +/*! + Write a double value in little endian. + */ +void vpIoTools::writeBinaryValueLE(std::ofstream &file, double double_value) +{ +#ifdef VISP_BIG_ENDIAN + // Swap bytes order to little endian + double swap_double = vpEndian::swapDouble(double_value); + file.write((char *)(&swap_double), sizeof(swap_double)); +#else + file.write((char *)(&double_value), sizeof(double_value)); +#endif +} + +bool vpIoTools::parseBoolean(std::string input) +{ + std::transform(input.begin(), input.end(), input.begin(), ::tolower); + std::istringstream is(input); + bool b; + // Parse string to boolean either in the textual representation + // (True/False) or in numeric representation (1/0) + is >> (input.size() > 1 ? std::boolalpha : std::noboolalpha) >> b; + return b; +} + +/*! + Remove leading and trailing whitespaces from a string. + */ +std::string vpIoTools::trim(std::string s) { return ltrim(rtrim(s)); } + +END_VISP_NAMESPACE diff --git a/modules/core/src/tools/file/vpIoTools_npy.cpp b/modules/core/src/tools/file/vpIoTools_npy.cpp new file mode 100644 index 0000000000..640c08c6ed --- /dev/null +++ b/modules/core/src/tools/file/vpIoTools_npy.cpp @@ -0,0 +1,437 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Io tools dedicated to npy. + */ + +#include +#include + +BEGIN_VISP_NAMESPACE + +#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98) && defined(VISP_HAVE_MINIZ) +#define USE_ZLIB_API 0 + +#if !USE_ZLIB_API +// See: https://github.com/BinomialLLC/basis_universal/blob/master/encoder/basisu_miniz.h +// Apache License, Version 2.0 +#include "basisu_miniz.h" + +using namespace buminiz; +#else +#include +#endif + +// To avoid warnings such as: warning: unused variable ‘littleEndian’ [-Wunused-variable] +#define UNUSED(x) ((void)(x)) // see: https://stackoverflow.com/a/777359 + +// Copyright (C) 2011 Carl Rogers +// Released under MIT License +// license available in LICENSE file, or at http://www.opensource.org/licenses/mit-license.php + +#include + +char visp::cnpy::BigEndianTest() +{ + int x = 1; + return (((reinterpret_cast(&x))[0]) ? '<' : '>'); +} + +char visp::cnpy::map_type(const std::type_info &t) +{ + if (t == typeid(float)) { return 'f'; } + if (t == typeid(double)) { return 'f'; } + if (t == typeid(long double)) { return 'f'; } + + if (t == typeid(int)) { return 'i'; } + if (t == typeid(char)) { return 'i'; } + if (t == typeid(short)) { return 'i'; } + if (t == typeid(long)) { return 'i'; } + if (t == typeid(long long)) { return 'i'; } + + if (t == typeid(unsigned char)) { return 'u'; } + if (t == typeid(unsigned short)) { return 'u'; } + if (t == typeid(unsigned long)) { return 'u'; } + if (t == typeid(unsigned long long)) { return 'u'; } + if (t == typeid(unsigned int)) { return 'u'; } + + if (t == typeid(bool)) { return 'b'; } + + if (t == typeid(std::complex)) { return 'c'; } + if (t == typeid(std::complex)) { return 'c'; } + if (t == typeid(std::complex)) { return 'c'; } + + else { return '?'; } +} + +void visp::cnpy::parse_npy_header(unsigned char *buffer, size_t &word_size, std::vector &shape, bool &fortran_order) +{ + uint16_t header_len = *reinterpret_cast(buffer+8); + std::string header(reinterpret_cast(buffer+9), header_len); + + //fortran order + size_t loc1 = header.find("fortran_order")+16; + fortran_order = (header.substr(loc1, 4) == "True" ? true : false); + + //shape + loc1 = header.find("("); + size_t loc2 = header.find(")"); + + std::regex num_regex("[0-9][0-9]*"); + std::smatch sm; + shape.clear(); + + std::string str_shape = header.substr(loc1+1, loc2-loc1-1); + while (std::regex_search(str_shape, sm, num_regex)) { + shape.push_back(std::stoi(sm[0].str())); + str_shape = sm.suffix().str(); + } + + //endian, word size, data type + //byte order code | stands for not applicable. + //not sure when this applies except for byte array + loc1 = header.find("descr")+9; + bool littleEndian = (((header[loc1] == '<') || (header[loc1] == '|')) ? true : false); + UNUSED(littleEndian); assert(littleEndian); + + std::string str_ws = header.substr(loc1+2); + loc2 = str_ws.find("'"); + word_size = atoi(str_ws.substr(0, loc2).c_str()); +} + +void visp::cnpy::parse_npy_header(FILE *fp, size_t &word_size, std::vector &shape, bool &fortran_order) +{ + char buffer[256]; + size_t res = fread(buffer, sizeof(char), 11, fp); + if (res != 11) { + throw std::runtime_error("parse_npy_header: failed fread"); + } + std::string header = fgets(buffer, 256, fp); + assert(header[header.size()-1] == '\n'); + + size_t loc1, loc2; + + //fortran order + loc1 = header.find("fortran_order"); + if (loc1 == std::string::npos) { + throw std::runtime_error("parse_npy_header: failed to find header keyword: 'fortran_order'"); + } + loc1 += 16; + fortran_order = (header.substr(loc1, 4) == "True" ? true : false); + + //shape + loc1 = header.find("("); + loc2 = header.find(")"); + if ((loc1 == std::string::npos) || (loc2 == std::string::npos)) { + throw std::runtime_error("parse_npy_header: failed to find header keyword: '(' or ')'"); + } + + std::regex num_regex("[0-9][0-9]*"); + std::smatch sm; + shape.clear(); + + std::string str_shape = header.substr(loc1+1, loc2-loc1-1); + while (std::regex_search(str_shape, sm, num_regex)) { + shape.push_back(std::stoi(sm[0].str())); + str_shape = sm.suffix().str(); + } + + //endian, word size, data type + //byte order code | stands for not applicable. + //not sure when this applies except for byte array + loc1 = header.find("descr"); + if (loc1 == std::string::npos) { + throw std::runtime_error("parse_npy_header: failed to find header keyword: 'descr'"); + } + loc1 += 9; + bool littleEndian = ((header[loc1] == '<') || (header[loc1] == '|') ? true : false); + UNUSED(littleEndian); assert(littleEndian); + + // --comment: char type equals header[loc1+1]; + // --comment: assert type equals map_type(T); + + std::string str_ws = header.substr(loc1+2); + loc2 = str_ws.find("'"); + word_size = atoi(str_ws.substr(0, loc2).c_str()); +} + +void visp::cnpy::parse_zip_footer(FILE *fp, uint16_t &nrecs, size_t &global_header_size, size_t &global_header_offset) +{ + std::vector footer(22); + fseek(fp, -22, SEEK_END); + size_t res = fread(&footer[0], sizeof(char), 22, fp); + if (res != 22) { + throw std::runtime_error("parse_zip_footer: failed fread"); + } + + uint16_t disk_no, disk_start, nrecs_on_disk, comment_len; + disk_no = *(uint16_t *)&footer[4]; + disk_start = *(uint16_t *)&footer[6]; + nrecs_on_disk = *(uint16_t *)&footer[8]; + nrecs = *(uint16_t *)&footer[10]; + global_header_size = *(uint32_t *)&footer[12]; + global_header_offset = *(uint32_t *)&footer[16]; + comment_len = *(uint16_t *)&footer[20]; + + UNUSED(disk_no); assert(disk_no == 0); + UNUSED(disk_start); assert(disk_start == 0); + UNUSED(nrecs_on_disk); assert(nrecs_on_disk == nrecs); + UNUSED(comment_len); assert(comment_len == 0); +} + +visp::cnpy::NpyArray load_the_npy_file(FILE *fp) +{ + std::vector shape; + size_t word_size; + bool fortran_order; + visp::cnpy::parse_npy_header(fp, word_size, shape, fortran_order); + + visp::cnpy::NpyArray arr(shape, word_size, fortran_order); + size_t nread = fread(arr.data(), 1, arr.num_bytes(), fp); + if (nread != arr.num_bytes()) { + throw std::runtime_error("load_the_npy_file: failed fread"); + } + return arr; +} + +visp::cnpy::NpyArray load_the_npz_array(FILE *fp, uint32_t compr_bytes, uint32_t uncompr_bytes) +{ + std::vector buffer_compr(compr_bytes); + std::vector buffer_uncompr(uncompr_bytes); + size_t nread = fread(&buffer_compr[0], 1, compr_bytes, fp); + if (nread != compr_bytes) { + throw std::runtime_error("load_the_npy_file: failed fread"); + } + + z_stream d_stream; + + d_stream.zalloc = Z_NULL; + d_stream.zfree = Z_NULL; + d_stream.opaque = Z_NULL; + d_stream.avail_in = 0; + d_stream.next_in = Z_NULL; + int err = inflateInit2(&d_stream, -MAX_WBITS); + UNUSED(err); assert(err == 0); + + d_stream.avail_in = compr_bytes; + d_stream.next_in = &buffer_compr[0]; + d_stream.avail_out = uncompr_bytes; + d_stream.next_out = &buffer_uncompr[0]; + + err = inflate(&d_stream, Z_FINISH); + UNUSED(err); assert(err == 0); + err = inflateEnd(&d_stream); + UNUSED(err); assert(err == 0); + + std::vector shape; + size_t word_size; + bool fortran_order; + visp::cnpy::parse_npy_header(&buffer_uncompr[0], word_size, shape, fortran_order); + + visp::cnpy::NpyArray array(shape, word_size, fortran_order); + + size_t offset = uncompr_bytes - array.num_bytes(); + memcpy(array.data(), &buffer_uncompr[0]+offset, array.num_bytes()); + + return array; +} + +/*! + Load the specified \p fname filepath as arrays of data. This function is similar to the + numpy.load function. + \param[in] fname : Path to the npz file. + \return A map of arrays data. The key represents the variable name, the value is an array of basic data type. + \warning This function has only been tested on little endian platform. + \note Original library: cnpy with MIT license. + */ +visp::cnpy::npz_t visp::cnpy::npz_load(std::string fname) +{ + FILE *fp = fopen(fname.c_str(), "rb"); + + if (!fp) { + throw std::runtime_error("npz_load: Error! Unable to open file "+fname+"!"); + } + + visp::cnpy::npz_t arrays; + bool quit = false; + const unsigned int index_2 = 2; + const unsigned int index_3 = 3; + const unsigned int index_26 = 26; + const unsigned int index_28 = 28; + const unsigned int val_8 = 8; + const unsigned int val_18 = 18; + const unsigned int val_22 = 22; + const unsigned int val_30 = 30; + while (!quit) { + std::vector local_header(30); + size_t headerres = fread(&local_header[0], sizeof(char), val_30, fp); + if (headerres != 30) { + throw std::runtime_error("npz_load: failed fread"); + } + + //if we've reached the global header, stop reading + if ((local_header[index_2] != 0x03) || (local_header[index_3] != 0x04)) { + quit = true; + } + else { + //read in the variable name + uint16_t name_len = *(uint16_t *)&local_header[index_26]; + std::string varname(name_len, ' '); + size_t vname_res = fread(&varname[0], sizeof(char), name_len, fp); + if (vname_res != name_len) { + throw std::runtime_error("npz_load: failed fread"); + } + + //erase the lagging .npy + varname.erase(varname.end()-4, varname.end()); + + //read in the extra field + uint16_t extra_field_len = *(uint16_t *)&local_header[index_28]; + if (extra_field_len > 0) { + std::vector buff(extra_field_len); + size_t efield_res = fread(&buff[0], sizeof(char), extra_field_len, fp); + if (efield_res != extra_field_len) { + throw std::runtime_error("npz_load: failed fread"); + } + } + + uint16_t compr_method = *reinterpret_cast(&local_header[0] + val_8); + uint32_t compr_bytes = *reinterpret_cast(&local_header[0] + val_18); + uint32_t uncompr_bytes = *reinterpret_cast(&local_header[0] + val_22); + + if (compr_method == 0) { arrays[varname] = load_the_npy_file(fp); } + else { arrays[varname] = load_the_npz_array(fp, compr_bytes, uncompr_bytes); } + } + } + + fclose(fp); + return arrays; +} + +/*! + Load the specified \p varname array of data from the \p fname npz file. This function is similar to the + numpy.load function. + \param[in] fname : Path to the npz file. + \param[in] varname : Identifier for the requested array of data. + \return An array of basic data type. + \warning This function has only been tested on little endian platform. + \note Original library: cnpy with MIT license. + */ +visp::cnpy::NpyArray visp::cnpy::npz_load(std::string fname, std::string varname) +{ + FILE *fp = fopen(fname.c_str(), "rb"); + + if (!fp) { + throw std::runtime_error("npz_load: Unable to open file "+fname); + } + + bool quit = false; + const unsigned int index_2 = 2; + const unsigned int index_3 = 3; + const unsigned int index_26 = 26; + const unsigned int index_28 = 28; + const unsigned int val_8 = 8; + const unsigned int val_18 = 18; + const unsigned int val_22 = 22; + const unsigned int val_30 = 30; + while (!quit) { + std::vector local_header(30); + size_t header_res = fread(&local_header[0], sizeof(char), val_30, fp); + if (header_res != 30) { + throw std::runtime_error("npz_load: failed fread"); + } + + //if we've reached the global header, stop reading + if ((local_header[index_2] != 0x03) || (local_header[index_3] != 0x04)) { + quit = true; + } + else { + //read in the variable name + uint16_t name_len = *(uint16_t *)&local_header[index_26]; + std::string vname(name_len, ' '); + size_t vname_res = fread(&vname[0], sizeof(char), name_len, fp); + if (vname_res != name_len) { + throw std::runtime_error("npz_load: failed fread"); + } + vname.erase(vname.end()-4, vname.end()); //erase the lagging .npy + + //read in the extra field + uint16_t extra_field_len = *(uint16_t *)&local_header[index_28]; + fseek(fp, extra_field_len, SEEK_CUR); //skip past the extra field + + uint16_t compr_method = *reinterpret_cast(&local_header[0] + val_8); + uint32_t compr_bytes = *reinterpret_cast(&local_header[0] + val_18); + uint32_t uncompr_bytes = *reinterpret_cast(&local_header[0] + val_22); + + if (vname == varname) { + NpyArray array = (compr_method == 0) ? load_the_npy_file(fp) : load_the_npz_array(fp, compr_bytes, uncompr_bytes); + fclose(fp); + return array; + } + else { + //skip past the data + uint32_t size = *(uint32_t *)&local_header[22]; + fseek(fp, size, SEEK_CUR); + } + } + } + + fclose(fp); + + //if we get here, we haven't found the variable in the file + throw std::runtime_error("npz_load: Variable name "+varname+" not found in "+fname); +} + +/*! + Load the specified npy \p fname filepath as one array of data. This function is similar to the + numpy.load function. + \param[in] fname : Path to the npy file. + \return An array of basic data type. + \warning This function has only been tested on little endian platform. + \note Original library: cnpy with MIT license. + */ +visp::cnpy::NpyArray visp::cnpy::npy_load(std::string fname) +{ + + FILE *fp = fopen(fname.c_str(), "rb"); + + if (!fp) { + throw std::runtime_error("npy_load: Unable to open file "+fname); + } + + NpyArray arr = load_the_npy_file(fp); + + fclose(fp); + return arr; +} + +#endif + +END_VISP_NAMESPACE diff --git a/modules/core/src/tools/histogram/vpHistogram.cpp b/modules/core/src/tools/histogram/vpHistogram.cpp index e36b39fe7f..51b4b34024 100644 --- a/modules/core/src/tools/histogram/vpHistogram.cpp +++ b/modules/core/src/tools/histogram/vpHistogram.cpp @@ -511,7 +511,7 @@ void vpHistogram::display(const vpImage &I, const vpColor &color, Smoothes the histogram. A simple average scheme is used where each value \f$h(i)\f$ in the - histogram is replaced by the average of itself and the neighbours. + histogram is replaced by the average of itself and the neighbors. \f[h(i) = \sum_{j=i-\frac{fsize}{2}}^{i+\frac{fsize}{2}} h(j) \f] @@ -519,7 +519,7 @@ void vpHistogram::display(const vpImage &I, const vpColor &color, around each point used to compute the mean value. \exception vpImageException::notInitializedError : Histogram array - not initialsed. Means that the histogram was not calculated before. + not initialised. Means that the histogram was not calculated before. \sa calculate() diff --git a/modules/core/test/image/testImageGetValue.cpp b/modules/core/test/image/testImageGetValue.cpp index 99b1c2589a..fe20646340 100644 --- a/modules/core/test/image/testImageGetValue.cpp +++ b/modules/core/test/image/testImageGetValue.cpp @@ -1,6 +1,7 @@ -/* +/**************************************************************************** + * * ViSP, open source Visual Servoing Platform software. - * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * Copyright (C) 2005 - 2023 by Inria. All rights reserved. * * This software is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,7 +30,8 @@ * * Description: * Test for vpImagePoint::getValue(). - */ + * +*****************************************************************************/ /*! \example testImageGetValue.cpp diff --git a/modules/tracker/blob/src/dots/vpDot2.cpp b/modules/tracker/blob/src/dots/vpDot2.cpp index e28047e842..5551c20c6b 100644 --- a/modules/tracker/blob/src/dots/vpDot2.cpp +++ b/modules/tracker/blob/src/dots/vpDot2.cpp @@ -959,273 +959,6 @@ void vpDot2::searchDotsInArea(const vpImage &I, std::list searchDotsInArea(I, 0, 0, I.getWidth(), I.getHeight(), niceDots); } -/** - * \brief Performs the research of dots in the area when the point u, v is a good germ. - * - * \param data The data required for the algorithm. - */ -void vpDot2::searchDotsAreaGoodGerm(vpSearchDotsInAreaGoodGermData &data) -{ -// Compute the right border position for this possible germ - unsigned int border_u; - unsigned int border_v; - bool good_germ = true; - std::list::iterator itbad; - std::list::iterator itnice; - vpDot2 *dotToTest = nullptr; - vpDot2 tmpDot; - vpImagePoint cogTmpDot; - if (findFirstBorder(data.m_I, data.m_u, data.m_v, border_u, border_v) == false) { - // germ is not good. - // Jump all the pixels between v,u and v, - // dotToTest->getFirstBorder_u() - data.m_u = border_u; - data.m_v = border_v; - } - else { - itbad = data.m_badDotsVector.begin(); - vpImagePoint cogBadDot; - - while ((itbad != data.m_badDotsVector.end()) && (good_germ == true)) { - if ((static_cast(data.m_u) >= (*itbad).m_bbox_u_min) && (static_cast(data.m_u) <= (*itbad).m_bbox_u_max) && - (static_cast(data.m_v) >= (*itbad).m_bbox_v_min) && (static_cast(data.m_v) <= (*itbad).m_bbox_v_max)) { - std::list::const_iterator it_edges = m_ip_edges_list.begin(); - while ((it_edges != m_ip_edges_list.end()) && (good_germ == true)) { - // Test if the germ belong to a previously detected dot: - // - from the germ go right to the border and compare this - // position to the list of pixels of previously detected dots - cogBadDot = *it_edges; - if ((std::fabs(border_u - cogBadDot.get_u()) <= - (vpMath::maximum(std::fabs(static_cast(border_u)), std::fabs(cogBadDot.get_u())) * - std::numeric_limits::epsilon())) && - (std::fabs(data.m_v - cogBadDot.get_v()) <= - (vpMath::maximum(std::fabs(static_cast(data.m_v)), std::fabs(cogBadDot.get_v())) * - std::numeric_limits::epsilon()))) { - good_germ = false; - } - ++it_edges; - } - } - ++itbad; - } - - if (!good_germ) { - // Jump all the pixels between v,u and v, - // dotToTest->getFirstBorder_u() - data.m_u = border_u; - data.m_v = border_v; - } - else { - vpImagePoint germ; - germ.set_u(data.m_u); - germ.set_v(data.m_v); - - // otherwise estimate the width, height and surface of the dot we - // created, and test it. - if (dotToTest != nullptr) { - delete dotToTest; - } - dotToTest = getInstance(); - dotToTest->setCog(germ); - dotToTest->setGrayLevelMin(getGrayLevelMin()); - dotToTest->setGrayLevelMax(getGrayLevelMax()); - dotToTest->setGrayLevelPrecision(getGrayLevelPrecision()); - dotToTest->setSizePrecision(getSizePrecision()); - dotToTest->setGraphics(m_graphics); - dotToTest->setGraphicsThickness(m_thickness); - dotToTest->setComputeMoments(true); - dotToTest->setArea(m_area); - dotToTest->setEllipsoidShapePrecision(m_ellipsoidShapePrecision); - dotToTest->setEllipsoidBadPointsPercentage(m_allowedBadPointsPercentage); - - // first compute the parameters of the dot. - // if for some reasons this caused an error tracking - // (dot partially out of the image...), check the next intersection - if (dotToTest->computeParameters(data.m_I) == false) { - // Jump all the pixels between v,u and v, - // dotToTest->getFirstBorder_u() - data.m_u = border_u; - data.m_v = border_v; - } - else { - // if the dot to test is valid, - if (dotToTest->isValid(data.m_I, *this)) { - vpImagePoint cogDotToTest = dotToTest->getCog(); - // Compute the distance to the center. The center used here is not the - // area center available by area.getCenter(area_center_u, - // area_center_v) but the center of the input area which may be - // partially outside the image. - - double area_center_u = (data.m_area.getLeft() + (data.m_area.getWidth() / 2.0)) - 0.5; - double area_center_v = (data.m_area.getTop() + (data.m_area.getHeight() / 2.0)) - 0.5; - - double thisDiff_u = cogDotToTest.get_u() - area_center_u; - double thisDiff_v = cogDotToTest.get_v() - area_center_v; - double thisDist = sqrt((thisDiff_u * thisDiff_u) + (thisDiff_v * thisDiff_v)); - - bool stopLoop = false; - itnice = data.m_niceDots.begin(); - - while ((itnice != data.m_niceDots.end()) && (stopLoop == false)) { - tmpDot = *itnice; - - // --comment: epsilon equals 0.001 -- detecte +sieurs points - double epsilon = 3.0; - // if the center of the dot is the same than the current - // don't add it, test the next point of the grid - cogTmpDot = tmpDot.getCog(); - - if ((fabs(cogTmpDot.get_u() - cogDotToTest.get_u()) < epsilon) && - (fabs(cogTmpDot.get_v() - cogDotToTest.get_v()) < epsilon)) { - stopLoop = true; - // Jump all the pixels between v,u and v, - // tmpDot->getFirstBorder_u() - data.m_u = border_u; - data.m_v = border_v; - } - else { - double otherDiff_u = cogTmpDot.get_u() - area_center_u; - double otherDiff_v = cogTmpDot.get_v() - area_center_v; - double otherDist = sqrt((otherDiff_u * otherDiff_u) + (otherDiff_v * otherDiff_v)); - - // if the distance of the curent vector element to the center - // is greater than the distance of this dot to the center, - // then add this dot before the current vector element. - if (otherDist > thisDist) { - data.m_niceDots.insert(itnice, *dotToTest); - stopLoop = true; - // Jump all the pixels between v,u and v, - // tmpDot->getFirstBorder_u() - data.m_u = border_u; - data.m_v = border_v; - } - ++itnice; - } - } - - // if we reached the end of the vector without finding the dot - // or inserting it, insert it now. - if ((itnice == data.m_niceDots.end()) && (stopLoop == false)) { - data.m_niceDots.push_back(*dotToTest); - } - } - else { - // Store bad dots - data.m_badDotsVector.push_front(*dotToTest); - } - } - } - } - if (dotToTest != nullptr) { - delete dotToTest; - } -} - -/*! - - Look for a list of dot matching this dot parameters within a region of - interest defined by a rectangle in the image. The rectangle upper-left - coordinates are given by - (\e area_u, \e area_v). The size of the rectangle is given by \e area_w and - \e area_h. - - \param I : Image to process. - \param area_u : Coordinate (column) of the upper-left area corner. - \param area_v : Coordinate (row) of the upper-left area corner. - - \param area_w : Width or the area in which a dot is searched. - \param area_h : Height or the area in which a dot is searched. - - \param niceDots: List of the dots that are found. - - \warning Allocates memory for the list of vpDot2 returned by this method. - Desallocation has to be done by yourself, see searchDotsInArea() - - \sa searchDotsInArea(vpImage& I, std::list &) -*/ -void vpDot2::searchDotsInArea(const vpImage &I, int area_u, int area_v, unsigned int area_w, - unsigned int area_h, std::list &niceDots) - -{ - // clear the list of nice dots - niceDots.clear(); - - // Fit the input area in the image; we keep only the common part between - // this area and the image. - setArea(I, area_u, area_v, area_w, area_h); - - // compute the size of the search grid - unsigned int gridWidth; - unsigned int gridHeight; - getGridSize(gridWidth, gridHeight); - - if (m_graphics) { - // Display the area were the dot is search - vpDisplay::displayRectangle(I, m_area, vpColor::blue, false, m_thickness); - } - -#ifdef DEBUG - vpDisplay::displayRectangle(I, m_area, vpColor::blue); - vpDisplay::flush(I); -#endif - // start the search loop; for all points of the search grid, - // test if the pixel belongs to a valid dot. - // if it is so eventually add it to the vector of valid dots. - std::list badDotsVector; - std::list::iterator itnice; - - vpDot2 tmpDot; - - unsigned int area_u_min = static_cast(m_area.getLeft()); - unsigned int area_u_max = static_cast(m_area.getRight()); - unsigned int area_v_min = static_cast(m_area.getTop()); - unsigned int area_v_max = static_cast(m_area.getBottom()); - - unsigned int u, v; - vpImagePoint cogTmpDot; - - v = area_v_min; - while (v < area_v_max) { - u = area_u_min; - while (u < area_u_max) { - // if the pixel we're in doesn't have the right color (outside the - // graylevel interval), no need to check further, just get to the - // next grid intersection. - if (hasGoodLevel(I, u, v)) { - - // Test if an other germ is inside the bounding box of a dot previously - // detected - bool good_germ = true; - - itnice = niceDots.begin(); - while ((itnice != niceDots.end()) && (good_germ == true)) { - tmpDot = *itnice; - - cogTmpDot = tmpDot.getCog(); - double u0 = cogTmpDot.get_u(); - double v0 = cogTmpDot.get_v(); - double half_w = tmpDot.getWidth() / 2.; - double half_h = tmpDot.getHeight() / 2.; - - if ((u >= (u0 - half_w)) && (u <= (u0 + half_w)) && (v >= (v0 - half_h)) && (v <= (v0 + half_h))) { - // Germ is in a previously detected dot - good_germ = false; - } - ++itnice; - } - - if (good_germ) { - vpRect area(area_u, area_v, area_w, area_h); - vpSearchDotsInAreaGoodGermData data(I, area, u, v, niceDots, badDotsVector); - searchDotsAreaGoodGerm(data); - } - } - u = u + gridWidth; - } - v = v + gridHeight; - } -} - /*! Check if the dot is "like" the wanted dot passed in. @@ -1517,22 +1250,6 @@ bool vpDot2::hasReverseLevel(const vpImage &I, const unsigned int */ vpDot2 *vpDot2::getInstance() { return new vpDot2(); } -/*! - - Gets the list of Freeman chain code used to turn around the dot - counterclockwise. - - \param[out] freeman_chain : List of Freeman chain list [0, ..., 7] - - 0 : right - - 1 : top right - - 2 : top - - 3 : top left - - 4 : left - - 5 : down left - - 6 : down - - 7 : down right -*/ -void vpDot2::getFreemanChain(std::list &freeman_chain) const { freeman_chain = m_direction_list; } /****************************************************************************** * @@ -1797,422 +1514,6 @@ bool vpDot2::findFirstBorder(const vpImage &I, const unsigned int return true; } -/*! - - Considering a pixel (u, v) compute the next element of the Freeman chain - code. - - According to the gray level of pixel (u, v) and his eight neighbors - determine the next element of the chain in order to turn around the dot - counterclockwise. - - \param I : The image we are working with. - \param v : The row coordinate of a pixel on a border. - \param u : The column coordinate of the pixel on a border. - \param element : The next freeman element chain code (0, 1, 2, 3, 4, 5, 6, - 7) with 0 for right moving, 2 for down, 4 for left and 6 for up moving. - - \return false if an element cannot be found. Occurs for example with an area - constituted by a single pixel. Return true if success. -*/ -bool vpDot2::computeFreemanChainElement(const vpImage &I, const unsigned int &u, const unsigned int &v, - unsigned int &element) -{ - if (hasGoodLevel(I, u, v)) { - unsigned int v_u = u; - unsigned int v_v = v; - const unsigned int val_1 = 1; - const unsigned int val_2 = 2; - const unsigned int val_3 = 3; - const unsigned int val_4 = 4; - const unsigned int val_5 = 5; - const unsigned int val_6 = 6; - const unsigned int val_7 = 7; - const unsigned int val_8 = 8; - // get the point on the right of the point passed in - updateFreemanPosition(v_u, v_v, (element + val_2) % val_8); - if (hasGoodLevel(I, v_u, v_v)) { - element = (element + val_2) % val_8; // turn right - } - else { - unsigned int v_u1 = u; - unsigned int v_v1 = v; - updateFreemanPosition(v_u1, v_v1, (element + val_1) % val_8); - - if (hasGoodLevel(I, v_u1, v_v1)) { - element = (element + val_1) % val_8; // turn diag right - } - else { - unsigned int v_u2 = u; - unsigned int v_v2 = v; - updateFreemanPosition(v_u2, v_v2, element); // same direction - - if (hasGoodLevel(I, v_u2, v_v2)) { - // element = element; // keep same dir - } - else { - unsigned int v_u3 = u; - unsigned int v_v3 = v; - updateFreemanPosition(v_u3, v_v3, (element + val_7) % val_8); // diag left - - if (hasGoodLevel(I, v_u3, v_v3)) { - element = (element + val_7) % val_8; // turn diag left - } - else { - unsigned int v_u4 = u; - unsigned int v_v4 = v; - updateFreemanPosition(v_u4, v_v4, (element + val_6) % val_8); // left - - if (hasGoodLevel(I, v_u4, v_v4)) { - element = (element + val_6) % val_8; // turn left - } - else { - unsigned int v_u5 = u; - unsigned int v_v5 = v; - updateFreemanPosition(v_u5, v_v5, (element + val_5) % val_8); // left - - if (hasGoodLevel(I, v_u5, v_v5)) { - element = (element + val_5) % val_8; // turn diag down - } - else { - unsigned int v_u6 = u; - unsigned int v_v6 = v; - updateFreemanPosition(v_u6, v_v6, (element + val_4) % val_8); // left - - if (hasGoodLevel(I, v_u6, v_v6)) { - element = (element + val_4) % val_8; // turn down - } - else { - unsigned int v_u7 = u; - unsigned int v_v7 = v; - updateFreemanPosition(v_u7, v_v7, (element + val_3) % val_8); // diag - - if (hasGoodLevel(I, v_u7, v_v7)) { - element = (element + val_3) % val_8; // turn diag right down - } - else { - // No neighbor with a good level - // - return false; - } - } - } - } - } - } - } - } - } - - else { - return false; - } - - return true; -} - -namespace -{ -/*! -* Given the previous position of a pixel (u_p, v_p) on the dot border, the -* direction to reach the next pixel on the border being top right and -* because with use the moment, compute Freeman parameters. -* \param u_p : Previous value of the row coordinate of a pixel on a border. -* \param v_p : Previous value of the column coordinate of a pixel on a border. -* \param dMuv : Moment increases. Cumulated values of dMuv gives m11. -* \param dMu2 : Second order moment along v axis increases. Cumulated values -* of dMu2 gives m20. -* \param dMv2 : Second order moment along u axis increases. Cumulated values -* of dMv2 gives m02. -*/ -void computeTopRightWithMoment(const int &u_p, const int &v_p, float &dMuv, float &dMu2, float &dMv2) -{ - float half_u_p = static_cast(0.5 * u_p); - dMuv = static_cast((v_p * v_p * (0.25 + half_u_p)) + (v_p * ((1. / 3.) + half_u_p)) + ((1. / 6.) * u_p) + 0.125); - dMu2 = static_cast(((-1. / 3.) * u_p * ((u_p * u_p) + (1.5 * u_p) + 1.)) - (1. / 12.0)); - dMv2 = static_cast(((1. / 3.) * v_p * ((v_p * v_p) + (1.5 * v_p) + 1.)) + (1. / 12.0)); -} - -/*! -* Given the previous position of a pixel (u_p, v_p) on the dot border, the -* direction to reach the next pixel on the border being top left and -* because with use the moment, compute Freeman parameters. -* \param u_p : Previous value of the row coordinate of a pixel on a border. -* \param v_p : Previous value of the column coordinate of a pixel on a border. -* \param dMuv : Moment increases. Cumulated values of dMuv gives m11. -* \param dMu2 : Second order moment along v axis increases. Cumulated values -* of dMu2 gives m20. -* \param dMv2 : Second order moment along u axis increases. Cumulated values -* of dMv2 gives m02. -*/ -void computeTopLeftWithMoment(const int &u_p, const int &v_p, float &dMuv, float &dMu2, float &dMv2) -{ - float half_u_p = static_cast(0.5 * u_p); - dMuv = static_cast((((v_p * v_p * (0.25 - half_u_p)) + (v_p * ((1. / 3.) - half_u_p))) - ((1. / 6.) * u_p)) + 0.125); - dMu2 = static_cast(((-1. / 3.) * u_p * (((u_p * u_p) - (1.5 * u_p)) + 1.)) - (1. / 12.0)); - dMv2 = static_cast(((-1. / 3.) * v_p * ((v_p * v_p) + (1.5 * v_p) + 1.)) - (1. / 12.0)); -} - -/*! -* Given the previous position of a pixel (u_p, v_p) on the dot border, the -* direction to reach the next pixel on the border being down right and -* because with use the moment, compute Freeman parameters. -* \param u_p : Previous value of the row coordinate of a pixel on a border. -* \param v_p : Previous value of the column coordinate of a pixel on a border. -* \param dMuv : Moment increases. Cumulated values of dMuv gives m11. -* \param dMu2 : Second order moment along v axis increases. Cumulated values -* of dMu2 gives m20. -* \param dMv2 : Second order moment along u axis increases. Cumulated values -* of dMv2 gives m02. -*/ -void computeDownRightWithMoment(const int &u_p, const int &v_p, float &dMuv, float &dMu2, float &dMv2) -{ - float half_u_p = static_cast(0.5 * u_p); - dMuv = static_cast(((v_p * v_p * (0.25 + half_u_p)) - (v_p * ((1. / 3.) + half_u_p))) + ((1. / 6.) * u_p) + 0.125); - dMu2 = static_cast(((1. / 3.) * u_p * ((u_p * u_p) + (1.5 * u_p) + 1.)) + (1. / 12.0)); - dMv2 = static_cast(((1. / 3.) * v_p * (((v_p * v_p) - (1.5 * v_p)) + 1.)) - (1. / 12.0)); -} - -/*! -* Given the previous position of a pixel (u_p, v_p) on the dot border, the -* direction to reach the next pixel on the border being down left and -* because with use the moment, compute Freeman parameters. -* \param u_p : Previous value of the row coordinate of a pixel on a border. -* \param v_p : Previous value of the column coordinate of a pixel on a border. -* \param dMuv : Moment increases. Cumulated values of dMuv gives m11. -* \param dMu2 : Second order moment along v axis increases. Cumulated values -* of dMu2 gives m20. -* \param dMv2 : Second order moment along u axis increases. Cumulated values -* of dMv2 gives m02. -*/ -void computeDownLeftWithMoment(const int &u_p, const int &v_p, float &dMuv, float &dMu2, float &dMv2) -{ - float half_u_p = static_cast(0.5 * u_p); - dMuv = static_cast((((v_p * v_p * (0.25 - half_u_p)) - (v_p * ((1. / 3.) - half_u_p))) - ((1. / 6.) * u_p)) + 0.125); - dMu2 = static_cast(((1. / 3.) * u_p * (((u_p * u_p) - (1.5 * u_p)) + 1.)) - (1. / 12.0)); - dMv2 = static_cast(((-1. / 3.) * v_p * (((v_p * v_p) - (1.5 * v_p)) + 1.)) - (1. / 12.0)); -} -} - -/*! - - Given the previous position of a pixel (u_p, v_p) on the dot border and the - direction to reach the next pixel on the border, compute Freeman parameters. - - \param u_p : Previous value of the row coordinate of a pixel on a border. - \param v_p : Previous value of the column coordinate of a pixel on a border. - \param du : Increment to go from previous to next pixel on the dot border. - \param dv : Increment to go from previous to next pixel on the dot border. - - \param dS : Enclosed area increases. Cumulated values of dS gives m00. - - \param dMu : First order moment along v axis increases. Cumulated values of - dMu gives m10. - - \param dMv : First order moment along u axis increases. Cumulated values of - dMv gives m01. - - \param dMuv : Moment increases. Cumulated values of dMuv gives m11. - - \param dMu2 : Second order moment along v axis increases. Cumulated values - of dMu2 gives m20. - - \param dMv2 : Second order moment along u axis increases. Cumulated values - of dMv2 gives m02. - - Considering the previous coordinates (u_p, v_p) of a pixel on a border, the - next coordinates (u, v) are given by: u = u_p + du and v = v_p + dv -*/ -void vpDot2::computeFreemanParameters(const int &u_p, const int &v_p, unsigned int &element, int &du, int &dv, - float &dS, float &dMu, float &dMv, float &dMuv, float &dMu2, float &dMv2) -{ - /* - 3 2 1 - \ | / - \|/ - 4 ------- 0 - /|\ - / | \ - 5 6 7 - */ - const unsigned int go_right = 0; - const unsigned int go_right_top = 1; - const unsigned int go_top = 2; - const unsigned int go_top_left = 3; - const unsigned int go_left = 4; - const unsigned int go_left_down = 5; - const unsigned int go_down = 6; - const unsigned int go_down_right = 7; - du = 0; - dv = 0; - dMuv = 0; - dMu2 = 0; - dMv2 = 0; - const unsigned int val_2 = 2; - switch (element) { - case go_right: // go right - du = 1; - dS = static_cast(v_p); - dMu = 0.0; - dMv = static_cast(0.5 * v_p * v_p); - if (m_compute_moment) { - dMuv = static_cast(0.25 * v_p * v_p * ((val_2 * u_p) + 1)); - dMu2 = 0; - dMv2 = static_cast((1.0 / 3.) * v_p * v_p * v_p); - } - break; - - case go_right_top: // go right top - du = 1; - dv = 1; - dS = static_cast(v_p + 0.5); - dMu = -static_cast((0.5 * u_p * (u_p + 1)) + (1.0 / 6.0)); - dMv = static_cast((0.5 * v_p * (v_p + 1)) + (1.0 / 6.0)); - if (m_compute_moment) { - computeTopRightWithMoment(u_p, v_p, dMuv, dMu2, dMv2); - } - break; - - case go_top: // go top - dv = 1; - dS = 0.0; - dMu = static_cast(-0.5 * u_p * u_p); - dMv = 0.0; - if (m_compute_moment) { - dMuv = 0; - dMu2 = static_cast((-1.0 / 3.) * u_p * u_p * u_p); - dMv2 = 0; - } - break; - - case go_top_left: - du = -1; - dv = 1; - dS = static_cast(-v_p - 0.5); - dMu = -static_cast((0.5 * u_p * (u_p - 1)) + (1.0 / 6.0)); - dMv = -static_cast((0.5 * v_p * (v_p + 1)) + (1.0 / 6.0)); - if (m_compute_moment) { - computeTopLeftWithMoment(u_p, v_p, dMuv, dMu2, dMv2); - } - break; - - case go_left: - du = -1; - dS = static_cast(-v_p); - dMv = static_cast(-0.5 * v_p * v_p); - dMu = 0.0; - if (m_compute_moment) { - dMuv = static_cast(-0.25 * v_p * v_p * ((val_2 * u_p) - 1)); - dMu2 = 0; - dMv2 = static_cast((-1.0 / 3.) * v_p * v_p * v_p); - } - break; - - case go_left_down: - du = -1; - dv = -1; - dS = static_cast(-v_p + 0.5); - dMu = static_cast((0.5 * u_p * (u_p - 1)) + (1.0 / 6.0)); - dMv = static_cast(-((0.5 * v_p * (v_p - 1)) + (1.0 / 6.0))); - if (m_compute_moment) { - computeDownLeftWithMoment(u_p, v_p, dMuv, dMu2, dMv2); - } - break; - - case go_down: - dv = -1; - dS = 0.0; - dMu = static_cast(0.5 * u_p * u_p); - dMv = 0.0; - if (m_compute_moment) { - dMuv = 0; - dMu2 = static_cast((1.0 / 3.) * u_p * u_p * u_p); - dMv2 = 0; - } - break; - - case go_down_right: - du = 1; - dv = -1; - dS = static_cast(v_p - 0.5); - dMu = static_cast((0.5 * u_p * (u_p + 1)) + (1.0 / 6.0)); - dMv = static_cast((0.5 * v_p * (v_p - 1)) + (1.0 / 6.0)); - if (m_compute_moment) { - computeDownRightWithMoment(u_p, v_p, dMuv, dMu2, dMv2); - } - break; - - default: - std::cout << "to complete the default" << std::endl; - } -} - -/*! - - From a pixel coordinate and a direction, update the pixel coordinates after - moving forward. - - \param v : The row coordinate of the pixel, updated by this method. - - \param u : The column coordinate of the pixel, updated by this method. - - \param dir : The direction in the image, 0=right, 1, 2=down, 3, 4=left, 5, - 6=up and 7. - -*/ -void vpDot2::updateFreemanPosition(unsigned int &u, unsigned int &v, const unsigned int &dir) -{ - /* - 3 2 1 - \ | / - \|/ - 4 ------- 0 - /|\ - / | \ - 5 6 7 - */ - const unsigned int go_right = 0; - const unsigned int go_right_top = 1; - const unsigned int go_top = 2; - const unsigned int go_top_left = 3; - const unsigned int go_left = 4; - const unsigned int go_left_down = 5; - const unsigned int go_down = 6; - const unsigned int go_down_right = 7; - switch (dir) { - case go_right: - u += 1; - break; - case go_right_top: - u += 1; - v += 1; - break; - case go_top: - v += 1; - break; - case go_top_left: - u -= 1; - v += 1; - break; - case go_left: - u -= 1; - break; - case go_left_down: - u -= 1; - v -= 1; - break; - case go_down: - v -= 1; - break; - case go_down_right: - u += 1; - v -= 1; - break; - default: - std::cout << "In vpDot2::updateFreemanPosition dir not identified" << std::endl; - } -} - /*! Test if a pixel is in the image. Points of the border are not @@ -2281,15 +1582,12 @@ bool vpDot2::isInArea(const unsigned int &u, const unsigned int &v) const } /*! - Get the search grid size used to found a dot in a region of interest. This grid is used to parse only some pixels of the search area. \param gridWidth : Number of pixels between to vertical lines of the grid \param gridHeight : Number of pixels between to horizontal lines of the grid - - */ void vpDot2::getGridSize(unsigned int &gridWidth, unsigned int &gridHeight) { @@ -2310,7 +1608,6 @@ void vpDot2::getGridSize(unsigned int &gridWidth, unsigned int &gridHeight) } /*! - Compute an approximation of mean gray level of the dot. We compute it by searching the mean of vertical and diagonal points which gray is between min and max gray level. @@ -2318,8 +1615,6 @@ void vpDot2::getGridSize(unsigned int &gridWidth, unsigned int &gridHeight) \param I: The image. \return the mean gray level - - */ void vpDot2::computeMeanGrayLevel(const vpImage &I) { @@ -2406,15 +1701,15 @@ void vpDot2::computeMeanGrayLevel(const vpImage &I) If the dots from the file cannot be tracked in the image, will ask to click them. - \param dot : dot2 array - \param n : number of dots, array dimension - \param dotFile : path for the file - \param I : image - \param col : color to print the dots (default Blue) - \param trackDot : if true, tracks the dots in the image, if false + \param dot : dot2 array + \param n : number of dots, array dimension + \param dotFile : path for the file + \param I : image + \param col : color to print the dots (default Blue) + \param trackDot : if true, tracks the dots in the image, if false simply loads the coordinates (default true) - \return an nx2 matrix with the coordinates of the dots + \return an nx2 matrix with the coordinates of the dots */ vpMatrix vpDot2::defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage &I, vpColor col, bool trackDot) diff --git a/modules/tracker/blob/src/dots/vpDot2_freeman.cpp b/modules/tracker/blob/src/dots/vpDot2_freeman.cpp new file mode 100644 index 0000000000..7f8554e1f4 --- /dev/null +++ b/modules/tracker/blob/src/dots/vpDot2_freeman.cpp @@ -0,0 +1,472 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Freeman chain dedicated functions. + */ + +#include +#include + +BEGIN_VISP_NAMESPACE + +namespace +{ +/*! +* Given the previous position of a pixel (u_p, v_p) on the dot border, the +* direction to reach the next pixel on the border being top right and +* because with use the moment, compute Freeman parameters. +* \param u_p : Previous value of the row coordinate of a pixel on a border. +* \param v_p : Previous value of the column coordinate of a pixel on a border. +* \param dMuv : Moment increases. Cumulated values of dMuv gives m11. +* \param dMu2 : Second order moment along v axis increases. Cumulated values +* of dMu2 gives m20. +* \param dMv2 : Second order moment along u axis increases. Cumulated values +* of dMv2 gives m02. +*/ +void computeTopRightWithMoment(const int &u_p, const int &v_p, float &dMuv, float &dMu2, float &dMv2) +{ + float half_u_p = static_cast(0.5 * u_p); + dMuv = static_cast((v_p * v_p * (0.25 + half_u_p)) + (v_p * ((1. / 3.) + half_u_p)) + ((1. / 6.) * u_p) + 0.125); + dMu2 = static_cast(((-1. / 3.) * u_p * ((u_p * u_p) + (1.5 * u_p) + 1.)) - (1. / 12.0)); + dMv2 = static_cast(((1. / 3.) * v_p * ((v_p * v_p) + (1.5 * v_p) + 1.)) + (1. / 12.0)); +} + +/*! +* Given the previous position of a pixel (u_p, v_p) on the dot border, the +* direction to reach the next pixel on the border being top left and +* because with use the moment, compute Freeman parameters. +* \param u_p : Previous value of the row coordinate of a pixel on a border. +* \param v_p : Previous value of the column coordinate of a pixel on a border. +* \param dMuv : Moment increases. Cumulated values of dMuv gives m11. +* \param dMu2 : Second order moment along v axis increases. Cumulated values +* of dMu2 gives m20. +* \param dMv2 : Second order moment along u axis increases. Cumulated values +* of dMv2 gives m02. +*/ +void computeTopLeftWithMoment(const int &u_p, const int &v_p, float &dMuv, float &dMu2, float &dMv2) +{ + float half_u_p = static_cast(0.5 * u_p); + dMuv = static_cast((((v_p * v_p * (0.25 - half_u_p)) + (v_p * ((1. / 3.) - half_u_p))) - ((1. / 6.) * u_p)) + 0.125); + dMu2 = static_cast(((-1. / 3.) * u_p * (((u_p * u_p) - (1.5 * u_p)) + 1.)) - (1. / 12.0)); + dMv2 = static_cast(((-1. / 3.) * v_p * ((v_p * v_p) + (1.5 * v_p) + 1.)) - (1. / 12.0)); +} + +/*! +* Given the previous position of a pixel (u_p, v_p) on the dot border, the +* direction to reach the next pixel on the border being down right and +* because with use the moment, compute Freeman parameters. +* \param u_p : Previous value of the row coordinate of a pixel on a border. +* \param v_p : Previous value of the column coordinate of a pixel on a border. +* \param dMuv : Moment increases. Cumulated values of dMuv gives m11. +* \param dMu2 : Second order moment along v axis increases. Cumulated values +* of dMu2 gives m20. +* \param dMv2 : Second order moment along u axis increases. Cumulated values +* of dMv2 gives m02. +*/ +void computeDownRightWithMoment(const int &u_p, const int &v_p, float &dMuv, float &dMu2, float &dMv2) +{ + float half_u_p = static_cast(0.5 * u_p); + dMuv = static_cast(((v_p * v_p * (0.25 + half_u_p)) - (v_p * ((1. / 3.) + half_u_p))) + ((1. / 6.) * u_p) + 0.125); + dMu2 = static_cast(((1. / 3.) * u_p * ((u_p * u_p) + (1.5 * u_p) + 1.)) + (1. / 12.0)); + dMv2 = static_cast(((1. / 3.) * v_p * (((v_p * v_p) - (1.5 * v_p)) + 1.)) - (1. / 12.0)); +} + +/*! +* Given the previous position of a pixel (u_p, v_p) on the dot border, the +* direction to reach the next pixel on the border being down left and +* because with use the moment, compute Freeman parameters. +* \param u_p : Previous value of the row coordinate of a pixel on a border. +* \param v_p : Previous value of the column coordinate of a pixel on a border. +* \param dMuv : Moment increases. Cumulated values of dMuv gives m11. +* \param dMu2 : Second order moment along v axis increases. Cumulated values +* of dMu2 gives m20. +* \param dMv2 : Second order moment along u axis increases. Cumulated values +* of dMv2 gives m02. +*/ +void computeDownLeftWithMoment(const int &u_p, const int &v_p, float &dMuv, float &dMu2, float &dMv2) +{ + float half_u_p = static_cast(0.5 * u_p); + dMuv = static_cast((((v_p * v_p * (0.25 - half_u_p)) - (v_p * ((1. / 3.) - half_u_p))) - ((1. / 6.) * u_p)) + 0.125); + dMu2 = static_cast(((1. / 3.) * u_p * (((u_p * u_p) - (1.5 * u_p)) + 1.)) - (1. / 12.0)); + dMv2 = static_cast(((-1. / 3.) * v_p * (((v_p * v_p) - (1.5 * v_p)) + 1.)) - (1. / 12.0)); +} +} + +/*! + + Gets the list of Freeman chain code used to turn around the dot + counterclockwise. + + \param[out] freeman_chain : List of Freeman chain list [0, ..., 7] + - 0 : right + - 1 : top right + - 2 : top + - 3 : top left + - 4 : left + - 5 : down left + - 6 : down + - 7 : down right +*/ +void vpDot2::getFreemanChain(std::list &freeman_chain) const { freeman_chain = m_direction_list; } + +/*! + + Considering a pixel (u, v) compute the next element of the Freeman chain + code. + + According to the gray level of pixel (u, v) and his eight neighbors + determine the next element of the chain in order to turn around the dot + counterclockwise. + + \param I : The image we are working with. + \param v : The row coordinate of a pixel on a border. + \param u : The column coordinate of the pixel on a border. + \param element : The next freeman element chain code (0, 1, 2, 3, 4, 5, 6, + 7) with 0 for right moving, 2 for down, 4 for left and 6 for up moving. + + \return false if an element cannot be found. Occurs for example with an area + constituted by a single pixel. Return true if success. +*/ +bool vpDot2::computeFreemanChainElement(const vpImage &I, const unsigned int &u, const unsigned int &v, + unsigned int &element) +{ + if (hasGoodLevel(I, u, v)) { + unsigned int v_u = u; + unsigned int v_v = v; + const unsigned int val_1 = 1; + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; + const unsigned int val_4 = 4; + const unsigned int val_5 = 5; + const unsigned int val_6 = 6; + const unsigned int val_7 = 7; + const unsigned int val_8 = 8; + // get the point on the right of the point passed in + updateFreemanPosition(v_u, v_v, (element + val_2) % val_8); + if (hasGoodLevel(I, v_u, v_v)) { + element = (element + val_2) % val_8; // turn right + } + else { + unsigned int v_u1 = u; + unsigned int v_v1 = v; + updateFreemanPosition(v_u1, v_v1, (element + val_1) % val_8); + + if (hasGoodLevel(I, v_u1, v_v1)) { + element = (element + val_1) % val_8; // turn diag right + } + else { + unsigned int v_u2 = u; + unsigned int v_v2 = v; + updateFreemanPosition(v_u2, v_v2, element); // same direction + + if (hasGoodLevel(I, v_u2, v_v2)) { + // element = element; // keep same dir + } + else { + unsigned int v_u3 = u; + unsigned int v_v3 = v; + updateFreemanPosition(v_u3, v_v3, (element + val_7) % val_8); // diag left + + if (hasGoodLevel(I, v_u3, v_v3)) { + element = (element + val_7) % val_8; // turn diag left + } + else { + unsigned int v_u4 = u; + unsigned int v_v4 = v; + updateFreemanPosition(v_u4, v_v4, (element + val_6) % val_8); // left + + if (hasGoodLevel(I, v_u4, v_v4)) { + element = (element + val_6) % val_8; // turn left + } + else { + unsigned int v_u5 = u; + unsigned int v_v5 = v; + updateFreemanPosition(v_u5, v_v5, (element + val_5) % val_8); // left + + if (hasGoodLevel(I, v_u5, v_v5)) { + element = (element + val_5) % val_8; // turn diag down + } + else { + unsigned int v_u6 = u; + unsigned int v_v6 = v; + updateFreemanPosition(v_u6, v_v6, (element + val_4) % val_8); // left + + if (hasGoodLevel(I, v_u6, v_v6)) { + element = (element + val_4) % val_8; // turn down + } + else { + unsigned int v_u7 = u; + unsigned int v_v7 = v; + updateFreemanPosition(v_u7, v_v7, (element + val_3) % val_8); // diag + + if (hasGoodLevel(I, v_u7, v_v7)) { + element = (element + val_3) % val_8; // turn diag right down + } + else { + // No neighbor with a good level + // + return false; + } + } + } + } + } + } + } + } + } + + else { + return false; + } + + return true; +} + +/*! + + Given the previous position of a pixel (u_p, v_p) on the dot border and the + direction to reach the next pixel on the border, compute Freeman parameters. + + \param u_p : Previous value of the row coordinate of a pixel on a border. + \param v_p : Previous value of the column coordinate of a pixel on a border. + \param du : Increment to go from previous to next pixel on the dot border. + \param dv : Increment to go from previous to next pixel on the dot border. + + \param dS : Enclosed area increases. Cumulated values of dS gives m00. + + \param dMu : First order moment along v axis increases. Cumulated values of + dMu gives m10. + + \param dMv : First order moment along u axis increases. Cumulated values of + dMv gives m01. + + \param dMuv : Moment increases. Cumulated values of dMuv gives m11. + + \param dMu2 : Second order moment along v axis increases. Cumulated values + of dMu2 gives m20. + + \param dMv2 : Second order moment along u axis increases. Cumulated values + of dMv2 gives m02. + + Considering the previous coordinates (u_p, v_p) of a pixel on a border, the + next coordinates (u, v) are given by: u = u_p + du and v = v_p + dv +*/ +void vpDot2::computeFreemanParameters(const int &u_p, const int &v_p, unsigned int &element, int &du, int &dv, + float &dS, float &dMu, float &dMv, float &dMuv, float &dMu2, float &dMv2) +{ + /* + 3 2 1 + \ | / + \|/ + 4 ------- 0 + /|\ + / | \ + 5 6 7 + */ + const unsigned int go_right = 0; + const unsigned int go_right_top = 1; + const unsigned int go_top = 2; + const unsigned int go_top_left = 3; + const unsigned int go_left = 4; + const unsigned int go_left_down = 5; + const unsigned int go_down = 6; + const unsigned int go_down_right = 7; + du = 0; + dv = 0; + dMuv = 0; + dMu2 = 0; + dMv2 = 0; + const unsigned int val_2 = 2; + switch (element) { + case go_right: // go right + du = 1; + dS = static_cast(v_p); + dMu = 0.0; + dMv = static_cast(0.5 * v_p * v_p); + if (m_compute_moment) { + dMuv = static_cast(0.25 * v_p * v_p * ((val_2 * u_p) + 1)); + dMu2 = 0; + dMv2 = static_cast((1.0 / 3.) * v_p * v_p * v_p); + } + break; + + case go_right_top: // go right top + du = 1; + dv = 1; + dS = static_cast(v_p + 0.5); + dMu = -static_cast((0.5 * u_p * (u_p + 1)) + (1.0 / 6.0)); + dMv = static_cast((0.5 * v_p * (v_p + 1)) + (1.0 / 6.0)); + if (m_compute_moment) { + computeTopRightWithMoment(u_p, v_p, dMuv, dMu2, dMv2); + } + break; + + case go_top: // go top + dv = 1; + dS = 0.0; + dMu = static_cast(-0.5 * u_p * u_p); + dMv = 0.0; + if (m_compute_moment) { + dMuv = 0; + dMu2 = static_cast((-1.0 / 3.) * u_p * u_p * u_p); + dMv2 = 0; + } + break; + + case go_top_left: + du = -1; + dv = 1; + dS = static_cast(-v_p - 0.5); + dMu = -static_cast((0.5 * u_p * (u_p - 1)) + (1.0 / 6.0)); + dMv = -static_cast((0.5 * v_p * (v_p + 1)) + (1.0 / 6.0)); + if (m_compute_moment) { + computeTopLeftWithMoment(u_p, v_p, dMuv, dMu2, dMv2); + } + break; + + case go_left: + du = -1; + dS = static_cast(-v_p); + dMv = static_cast(-0.5 * v_p * v_p); + dMu = 0.0; + if (m_compute_moment) { + dMuv = static_cast(-0.25 * v_p * v_p * ((val_2 * u_p) - 1)); + dMu2 = 0; + dMv2 = static_cast((-1.0 / 3.) * v_p * v_p * v_p); + } + break; + + case go_left_down: + du = -1; + dv = -1; + dS = static_cast(-v_p + 0.5); + dMu = static_cast((0.5 * u_p * (u_p - 1)) + (1.0 / 6.0)); + dMv = static_cast(-((0.5 * v_p * (v_p - 1)) + (1.0 / 6.0))); + if (m_compute_moment) { + computeDownLeftWithMoment(u_p, v_p, dMuv, dMu2, dMv2); + } + break; + + case go_down: + dv = -1; + dS = 0.0; + dMu = static_cast(0.5 * u_p * u_p); + dMv = 0.0; + if (m_compute_moment) { + dMuv = 0; + dMu2 = static_cast((1.0 / 3.) * u_p * u_p * u_p); + dMv2 = 0; + } + break; + + case go_down_right: + du = 1; + dv = -1; + dS = static_cast(v_p - 0.5); + dMu = static_cast((0.5 * u_p * (u_p + 1)) + (1.0 / 6.0)); + dMv = static_cast((0.5 * v_p * (v_p - 1)) + (1.0 / 6.0)); + if (m_compute_moment) { + computeDownRightWithMoment(u_p, v_p, dMuv, dMu2, dMv2); + } + break; + + default: + std::cout << "to complete the default" << std::endl; + } +} + +/*! + + From a pixel coordinate and a direction, update the pixel coordinates after + moving forward. + + \param v : The row coordinate of the pixel, updated by this method. + + \param u : The column coordinate of the pixel, updated by this method. + + \param dir : The direction in the image, 0=right, 1, 2=down, 3, 4=left, 5, + 6=up and 7. + +*/ +void vpDot2::updateFreemanPosition(unsigned int &u, unsigned int &v, const unsigned int &dir) +{ + /* + 3 2 1 + \ | / + \|/ + 4 ------- 0 + /|\ + / | \ + 5 6 7 + */ + const unsigned int go_right = 0; + const unsigned int go_right_top = 1; + const unsigned int go_top = 2; + const unsigned int go_top_left = 3; + const unsigned int go_left = 4; + const unsigned int go_left_down = 5; + const unsigned int go_down = 6; + const unsigned int go_down_right = 7; + switch (dir) { + case go_right: + u += 1; + break; + case go_right_top: + u += 1; + v += 1; + break; + case go_top: + v += 1; + break; + case go_top_left: + u -= 1; + v += 1; + break; + case go_left: + u -= 1; + break; + case go_left_down: + u -= 1; + v -= 1; + break; + case go_down: + v -= 1; + break; + case go_down_right: + u += 1; + v -= 1; + break; + default: + std::cout << "In vpDot2::updateFreemanPosition dir not identified" << std::endl; + } +} + +END_VISP_NAMESPACE diff --git a/modules/tracker/blob/src/dots/vpDot2_search.cpp b/modules/tracker/blob/src/dots/vpDot2_search.cpp new file mode 100644 index 0000000000..5ae5c0595a --- /dev/null +++ b/modules/tracker/blob/src/dots/vpDot2_search.cpp @@ -0,0 +1,307 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Search a dot in an area. + */ + +#include +#include +#include + +BEGIN_VISP_NAMESPACE + +/** + * \brief Performs the research of dots in the area when the point u, v is a good germ. + * + * \param data The data required for the algorithm. + */ + void vpDot2::searchDotsAreaGoodGerm(vpSearchDotsInAreaGoodGermData &data) +{ +// Compute the right border position for this possible germ + unsigned int border_u; + unsigned int border_v; + bool good_germ = true; + std::list::iterator itbad; + std::list::iterator itnice; + vpDot2 *dotToTest = nullptr; + vpDot2 tmpDot; + vpImagePoint cogTmpDot; + if (findFirstBorder(data.m_I, data.m_u, data.m_v, border_u, border_v) == false) { + // germ is not good. + // Jump all the pixels between v,u and v, + // dotToTest->getFirstBorder_u() + data.m_u = border_u; + data.m_v = border_v; + } + else { + itbad = data.m_badDotsVector.begin(); + vpImagePoint cogBadDot; + + while ((itbad != data.m_badDotsVector.end()) && (good_germ == true)) { + if ((static_cast(data.m_u) >= (*itbad).m_bbox_u_min) && (static_cast(data.m_u) <= (*itbad).m_bbox_u_max) && + (static_cast(data.m_v) >= (*itbad).m_bbox_v_min) && (static_cast(data.m_v) <= (*itbad).m_bbox_v_max)) { + std::list::const_iterator it_edges = m_ip_edges_list.begin(); + while ((it_edges != m_ip_edges_list.end()) && (good_germ == true)) { + // Test if the germ belong to a previously detected dot: + // - from the germ go right to the border and compare this + // position to the list of pixels of previously detected dots + cogBadDot = *it_edges; + if ((std::fabs(border_u - cogBadDot.get_u()) <= + (vpMath::maximum(std::fabs(static_cast(border_u)), std::fabs(cogBadDot.get_u())) * + std::numeric_limits::epsilon())) && + (std::fabs(data.m_v - cogBadDot.get_v()) <= + (vpMath::maximum(std::fabs(static_cast(data.m_v)), std::fabs(cogBadDot.get_v())) * + std::numeric_limits::epsilon()))) { + good_germ = false; + } + ++it_edges; + } + } + ++itbad; + } + + if (!good_germ) { + // Jump all the pixels between v,u and v, + // dotToTest->getFirstBorder_u() + data.m_u = border_u; + data.m_v = border_v; + } + else { + vpImagePoint germ; + germ.set_u(data.m_u); + germ.set_v(data.m_v); + + // otherwise estimate the width, height and surface of the dot we + // created, and test it. + if (dotToTest != nullptr) { + delete dotToTest; + } + dotToTest = getInstance(); + dotToTest->setCog(germ); + dotToTest->setGrayLevelMin(getGrayLevelMin()); + dotToTest->setGrayLevelMax(getGrayLevelMax()); + dotToTest->setGrayLevelPrecision(getGrayLevelPrecision()); + dotToTest->setSizePrecision(getSizePrecision()); + dotToTest->setGraphics(m_graphics); + dotToTest->setGraphicsThickness(m_thickness); + dotToTest->setComputeMoments(true); + dotToTest->setArea(m_area); + dotToTest->setEllipsoidShapePrecision(m_ellipsoidShapePrecision); + dotToTest->setEllipsoidBadPointsPercentage(m_allowedBadPointsPercentage); + + // first compute the parameters of the dot. + // if for some reasons this caused an error tracking + // (dot partially out of the image...), check the next intersection + if (dotToTest->computeParameters(data.m_I) == false) { + // Jump all the pixels between v,u and v, + // dotToTest->getFirstBorder_u() + data.m_u = border_u; + data.m_v = border_v; + } + else { + // if the dot to test is valid, + if (dotToTest->isValid(data.m_I, *this)) { + vpImagePoint cogDotToTest = dotToTest->getCog(); + // Compute the distance to the center. The center used here is not the + // area center available by area.getCenter(area_center_u, + // area_center_v) but the center of the input area which may be + // partially outside the image. + + double area_center_u = (data.m_area.getLeft() + (data.m_area.getWidth() / 2.0)) - 0.5; + double area_center_v = (data.m_area.getTop() + (data.m_area.getHeight() / 2.0)) - 0.5; + + double thisDiff_u = cogDotToTest.get_u() - area_center_u; + double thisDiff_v = cogDotToTest.get_v() - area_center_v; + double thisDist = sqrt((thisDiff_u * thisDiff_u) + (thisDiff_v * thisDiff_v)); + + bool stopLoop = false; + itnice = data.m_niceDots.begin(); + + while ((itnice != data.m_niceDots.end()) && (stopLoop == false)) { + tmpDot = *itnice; + + // --comment: epsilon equals 0.001 -- detecte +sieurs points + double epsilon = 3.0; + // if the center of the dot is the same than the current + // don't add it, test the next point of the grid + cogTmpDot = tmpDot.getCog(); + + if ((fabs(cogTmpDot.get_u() - cogDotToTest.get_u()) < epsilon) && + (fabs(cogTmpDot.get_v() - cogDotToTest.get_v()) < epsilon)) { + stopLoop = true; + // Jump all the pixels between v,u and v, + // tmpDot->getFirstBorder_u() + data.m_u = border_u; + data.m_v = border_v; + } + else { + double otherDiff_u = cogTmpDot.get_u() - area_center_u; + double otherDiff_v = cogTmpDot.get_v() - area_center_v; + double otherDist = sqrt((otherDiff_u * otherDiff_u) + (otherDiff_v * otherDiff_v)); + + // if the distance of the curent vector element to the center + // is greater than the distance of this dot to the center, + // then add this dot before the current vector element. + if (otherDist > thisDist) { + data.m_niceDots.insert(itnice, *dotToTest); + stopLoop = true; + // Jump all the pixels between v,u and v, + // tmpDot->getFirstBorder_u() + data.m_u = border_u; + data.m_v = border_v; + } + ++itnice; + } + } + + // if we reached the end of the vector without finding the dot + // or inserting it, insert it now. + if ((itnice == data.m_niceDots.end()) && (stopLoop == false)) { + data.m_niceDots.push_back(*dotToTest); + } + } + else { + // Store bad dots + data.m_badDotsVector.push_front(*dotToTest); + } + } + } + } + if (dotToTest != nullptr) { + delete dotToTest; + } +} + +/*! + + Look for a list of dot matching this dot parameters within a region of + interest defined by a rectangle in the image. The rectangle upper-left + coordinates are given by + (\e area_u, \e area_v). The size of the rectangle is given by \e area_w and + \e area_h. + + \param I : Image to process. + \param area_u : Coordinate (column) of the upper-left area corner. + \param area_v : Coordinate (row) of the upper-left area corner. + + \param area_w : Width or the area in which a dot is searched. + \param area_h : Height or the area in which a dot is searched. + + \param niceDots: List of the dots that are found. + + \warning Allocates memory for the list of vpDot2 returned by this method. + Desallocation has to be done by yourself, see searchDotsInArea() + + \sa searchDotsInArea(vpImage& I, std::list &) +*/ +void vpDot2::searchDotsInArea(const vpImage &I, int area_u, int area_v, unsigned int area_w, + unsigned int area_h, std::list &niceDots) + +{ + // clear the list of nice dots + niceDots.clear(); + + // Fit the input area in the image; we keep only the common part between + // this area and the image. + setArea(I, area_u, area_v, area_w, area_h); + + // compute the size of the search grid + unsigned int gridWidth; + unsigned int gridHeight; + getGridSize(gridWidth, gridHeight); + + if (m_graphics) { + // Display the area were the dot is search + vpDisplay::displayRectangle(I, m_area, vpColor::blue, false, m_thickness); + } + +#ifdef DEBUG + vpDisplay::displayRectangle(I, m_area, vpColor::blue); + vpDisplay::flush(I); +#endif + // start the search loop; for all points of the search grid, + // test if the pixel belongs to a valid dot. + // if it is so eventually add it to the vector of valid dots. + std::list badDotsVector; + std::list::iterator itnice; + + vpDot2 tmpDot; + + unsigned int area_u_min = static_cast(m_area.getLeft()); + unsigned int area_u_max = static_cast(m_area.getRight()); + unsigned int area_v_min = static_cast(m_area.getTop()); + unsigned int area_v_max = static_cast(m_area.getBottom()); + + unsigned int u, v; + vpImagePoint cogTmpDot; + + v = area_v_min; + while (v < area_v_max) { + u = area_u_min; + while (u < area_u_max) { + // if the pixel we're in doesn't have the right color (outside the + // graylevel interval), no need to check further, just get to the + // next grid intersection. + if (hasGoodLevel(I, u, v)) { + + // Test if an other germ is inside the bounding box of a dot previously + // detected + bool good_germ = true; + + itnice = niceDots.begin(); + while ((itnice != niceDots.end()) && (good_germ == true)) { + tmpDot = *itnice; + + cogTmpDot = tmpDot.getCog(); + double u0 = cogTmpDot.get_u(); + double v0 = cogTmpDot.get_v(); + double half_w = tmpDot.getWidth() / 2.; + double half_h = tmpDot.getHeight() / 2.; + + if ((u >= (u0 - half_w)) && (u <= (u0 + half_w)) && (v >= (v0 - half_h)) && (v <= (v0 + half_h))) { + // Germ is in a previously detected dot + good_germ = false; + } + ++itnice; + } + + if (good_germ) { + vpRect area(area_u, area_v, area_w, area_h); + vpSearchDotsInAreaGoodGermData data(I, area, u, v, niceDots, badDotsVector); + searchDotsAreaGoodGerm(data); + } + } + u = u + gridWidth; + } + v = v + gridHeight; + } +} + +END_VISP_NAMESPACE diff --git a/modules/tracker/me/src/moving-edges/vpMeEllipse.cpp b/modules/tracker/me/src/moving-edges/vpMeEllipse.cpp index 15e8683f1e..fffd6e8f13 100644 --- a/modules/tracker/me/src/moving-edges/vpMeEllipse.cpp +++ b/modules/tracker/me/src/moving-edges/vpMeEllipse.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include @@ -552,500 +551,6 @@ unsigned int vpMeEllipse::plugHoles(const vpImage &I) return nb_pts_added; } -void vpMeEllipse::leastSquare(const vpImage &I, const std::vector &iP) -{ - double um = I.getWidth() / 2.; - double vm = I.getHeight() / 2.; - unsigned int n = static_cast(iP.size()); - const unsigned int index_0 = 0; - const unsigned int index_1 = 1; - const unsigned int index_2 = 2; - const unsigned int index_3 = 3; - const unsigned int index_4 = 4; - const unsigned int index_5 = 5; - - if (m_trackCircle) { // we track a circle - const unsigned int circleDims = 3; - if (n < circleDims) { - throw(vpException(vpException::dimensionError, "Not enough points to compute the circle")); - } - // System A x = b to be solved by least squares - // with A = (u v 1), b = (u^2 + v^2) and x = (2xc, 2yc, r^2-xc^2-yc^2) - - vpMatrix A(n, 3); - vpColVector b(n); - - for (unsigned int k = 0; k < n; ++k) { - // normalization so that (u,v) in [-1;1] - double u = (iP[k].get_u() - um) / um; - double v = (iP[k].get_v() - vm) / um; // um here to not deform the circle - A[k][index_0] = u; - A[k][index_1] = v; - A[k][index_2] = 1.0; - b[k] = (u * u) + (v * v); - } - vpColVector x(3); - x = A.solveBySVD(b); - // A circle is a particular ellipse. Going from x for circle to K for ellipse - // using inverse normalization to go back to pixel values - double ratio = vm / um; - m_K[index_0] = (m_K[index_1] = (1.0 / (um * um))); - m_K[index_2] = 0.0; - m_K[index_3] = -(1.0 + (x[index_0] / 2.0)) / um; - m_K[index_4] = -(ratio + (x[index_1] / 2.0)) / um; - m_K[index_5] = -x[index_2] + 1.0 + (ratio * ratio) + x[index_0] + (ratio * x[index_1]); - } - else { // we track an ellipse - const unsigned int npoints_min = 5; - if (n < npoints_min) { - throw(vpException(vpException::dimensionError, "Not enough points to compute the ellipse")); - } - // Homogeneous system A x = 0 ; x is the nullspace of A - // K0 u^2 + K1 v^2 + 2 K2 u v + 2 K3 u + 2 K4 v + K5 = 0 - // A = (u^2 v^2 2uv 2u 2v 1), x = (K0 K1 K2 K3 K4 K5)^T - - // It would be a bad idea to solve the same system using A x = b where - // A = (u^2 v^2 2uv 2u 2v), b = (-1), x = (K0 K1 K2 K3 K4)^T since it - // cannot consider the case where the origin belongs to the ellipse. - // Another possibility would be to consider K0+K1=1 which is always valid, - // leading to the system A x = b where - // A = (u^2-v^2 2uv 2u 2v 1), b = (-v^2), x = (K0 K2 K3 K4 K5)^T - - vpMatrix A(n, 6); - - for (unsigned int k = 0; k < n; ++k) { - // Normalization so that (u,v) in [-1;1] - double u = (iP[k].get_u() - um) / um; - double v = (iP[k].get_v() - vm) / vm; - A[k][index_0] = u * u; - A[k][index_1] = v * v; - A[k][index_2] = 2.0 * u * v; - A[k][index_3] = 2.0 * u; - A[k][index_4] = 2.0 * v; - A[k][index_5] = 1.0; - } - vpMatrix KerA; - unsigned int dim = A.nullSpace(KerA, 1); - if (dim > 1) { // case with less than 5 independent points - throw(vpMatrixException(vpMatrixException::rankDeficient, "Linear system for computing the ellipse equation ill conditioned")); - } - unsigned int nbRows = m_K.getRows(); - for (unsigned int i = 0; i < nbRows; ++i) { - m_K[i] = KerA[i][0]; - } - - // inverse normalization - m_K[index_0] *= vm / um; - m_K[index_1] *= um / vm; - m_K[index_3] = (m_K[index_3] * vm) - (m_K[index_0] * um) - (m_K[index_2] * vm); - m_K[index_4] = (m_K[index_4] * um) - (m_K[index_1] * vm) - (m_K[index_2] * um); - m_K[index_5] = (m_K[index_5] * um * vm) - (m_K[index_0] * um * um) - (m_K[index_1] * vm * vm) - - (2.0 * m_K[index_2] * um * vm) - (2.0 * m_K[index_3] * um) - (2.0 * m_K[index_4] * vm); - } - getParameters(); -} - -void vpMeEllipse::leastSquareRobustCircle(const double &um, const double &vm, unsigned int &k, vpColVector &w) -{ - const unsigned int nos = numberOfSignal(); - const unsigned int index_0 = 0; - const unsigned int index_1 = 1; - const unsigned int index_2 = 2; - const unsigned int index_3 = 3; - const unsigned int index_4 = 4; - const unsigned int index_5 = 5; - - // System A x = b to be solved by least squares - // with A = (u v 1), b = (u^2 + v^2) and x = (2xc, 2yc, r^2-xc^2-yc^2) - - // Note that the (nos-k) last rows of A, b, xp and yp are not used. - // Hopefully, this is not an issue. - vpMatrix A(nos, 3); - vpColVector b(nos); - - // Useful to compute the weights in the robust estimation - vpColVector xp(nos), yp(nos); - std::list::const_iterator end = m_meList.end(); - - for (std::list::const_iterator it = m_meList.begin(); it != end; ++it) { - vpMeSite p_me = *it; - if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { - // from (i,j) to (u,v) frame + normalization so that (u,v) in [-1;1] - double u = (p_me.get_jfloat() - um) / um; - double v = (p_me.get_ifloat() - vm) / um; // um to not deform the circle - A[k][index_0] = u; - A[k][index_1] = v; - A[k][index_2] = 1.0; - b[k] = (u * u) + (v * v); - // Useful to compute the weights in the robust estimation - xp[k] = p_me.get_jfloat(); - yp[k] = p_me.get_ifloat(); - - ++k; - } - } - - const unsigned int minRequiredNbMe = 3; - if (k < minRequiredNbMe) { - throw(vpException(vpException::dimensionError, "Not enough moving edges %d / %d to track the circle ", - k, m_meList.size())); - } - - vpRobust r; - r.setMinMedianAbsoluteDeviation(1.0); // Image noise in pixels for the algebraic distance - - unsigned int iter = 0; - double var = 1.0; - vpColVector x(3); - vpMatrix DA(k, 3); - vpColVector Db(k); - vpColVector xg_prev(2); - xg_prev = -10.0; - - // stop after 4 it or if cog variation between 2 it is more than 1 pixel - const unsigned int maxNbIter = 4; - const unsigned int widthDA = DA.getCols(); - while ((iter < maxNbIter) && (var > 0.1)) { - for (unsigned int i = 0; i < k; ++i) { - for (unsigned int j = 0; j < widthDA; ++j) { - DA[i][j] = w[i] * A[i][j]; - } - Db[i] = w[i] * b[i]; - } - x = DA.solveBySVD(Db); - - // A circle is a particular ellipse. Going from x for circle to K for ellipse - // using inverse normalization to go back to pixel values - double ratio = vm / um; - m_K[index_0] = (m_K[index_1] = (1.0 / (um * um))); - m_K[index_2] = 0.0; - m_K[index_3] = -(1.0 + (x[index_0] / 2.0)) / um; - m_K[index_4] = -(ratio + (x[index_1] / 2.0)) / um; - m_K[index_5] = -x[index_2] + 1.0 + (ratio * ratio) + x[index_0] + (ratio * x[index_1]); - - getParameters(); - vpColVector xg(2); - xg[0] = m_uc; - xg[1] = m_vc; - var = (xg - xg_prev).frobeniusNorm(); - xg_prev = xg; - - vpColVector residu(k); // near to geometric distance in pixel - for (unsigned int i = 0; i < k; ++i) { - double x = xp[i]; - double y = yp[i]; - double sign = (m_K[index_0] * x * x) + (m_K[index_1] * y * y) + (2. * m_K[index_2] * x * y) - + (2. * m_K[index_3] * x) + (2. * m_K[index_4] * y) + m_K[index_5]; - vpImagePoint ip1, ip2; - ip1.set_uv(x, y); - double ang = computeAngleOnEllipse(ip1); - computePointOnEllipse(ang, ip2); - // residu = 0 if point is exactly on the ellipse, not otherwise - if (sign > 0) { - residu[i] = vpImagePoint::distance(ip1, ip2); - } - else { - residu[i] = -vpImagePoint::distance(ip1, ip2); - } - } - r.MEstimator(vpRobust::TUKEY, residu, w); - - ++iter; - } -} - -void vpMeEllipse::leastSquareRobustEllipse(const double &um, const double &vm, unsigned int &k, vpColVector &w) -{ - const unsigned int nos = numberOfSignal(); - const unsigned int index_0 = 0; - const unsigned int index_1 = 1; - const unsigned int index_2 = 2; - const unsigned int index_3 = 3; - const unsigned int index_4 = 4; - const unsigned int index_5 = 5; - // Homogeneous system A x = 0 ; x is the nullspace of A - // K0 u^2 + K1 v^2 + 2 K2 u v + 2 K3 u + 2 K4 v + K5 = 0 - // A = (u^2 v^2 2uv 2u 2v 1), x = (K0 K1 K2 K3 K4 K5)^T - - // It would be a bad idea to solve the same system using A x = b where - // A = (u^2 v^2 2uv 2u 2v), b = (-1), x = (K0 K1 K2 K3 K4)^T since it - // cannot consider the case where the origin belongs to the ellipse. - // Another possibility would be to consider K0+K1=1 which is always valid, - // leading to the system A x = b where - // A = (u^2-v^2 2uv 2u 2v 1), b = (-v^2), x = (K0 K2 K3 K4 K5)^T - const unsigned int nbColsA = 6; - vpMatrix A(nos, nbColsA); - // Useful to compute the weights in the robust estimation - vpColVector xp(nos), yp(nos); - std::list::const_iterator end = m_meList.end(); - - for (std::list::const_iterator it = m_meList.begin(); it != end; ++it) { - vpMeSite p_me = *it; - if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { - // from (i,j) to (u,v) frame + normalization so that (u,v) in [-1;1] - double u = (p_me.get_jfloat() - um) / um; - double v = (p_me.get_ifloat() - vm) / vm; - A[k][index_0] = u * u; - A[k][index_1] = v * v; - A[k][index_2] = 2.0 * u * v; - A[k][index_3] = 2.0 * u; - A[k][index_4] = 2.0 * v; - A[k][index_5] = 1.0; - // Useful to compute the weights in the robust estimation - xp[k] = p_me.get_jfloat(); - yp[k] = p_me.get_ifloat(); - - ++k; - } - } - - const unsigned int minRequiredMe = 5; - if (k < minRequiredMe) { - throw(vpException(vpException::dimensionError, "Not enough moving edges to track the ellipse")); - } - - vpRobust r; - - r.setMinMedianAbsoluteDeviation(1.0); // image noise in pixels for the geometrical distance - unsigned int iter = 0; - double var = 1.0; - vpMatrix DA(k, 6); - vpMatrix KerDA; - vpColVector xg_prev(2); - xg_prev = -10.0; - - // Stop after 4 iterations or if cog variation between 2 iterations is more than 0.1 pixel - const unsigned int maxIter = 4; - const unsigned int widthDA = DA.getCols(); - while ((iter < maxIter) && (var > 0.1)) { - for (unsigned int i = 0; i < k; ++i) { - for (unsigned int j = 0; j < widthDA; ++j) { - DA[i][j] = w[i] * A[i][j]; - } - } - unsigned int dim = DA.nullSpace(KerDA, 1); - if (dim > 1) { // case with less than 5 independent points - throw(vpMatrixException(vpMatrixException::rankDeficient, "Linear system for computing the ellipse equation ill conditioned")); - } - - const unsigned int nparam = 6; - for (unsigned int i = 0; i < nparam; ++i) { - m_K[i] = KerDA[i][0]; // norm(K) = 1 - } - - // inverse normalization - m_K[index_0] *= vm / um; - m_K[index_1] *= um / vm; - m_K[index_3] = (m_K[index_3] * vm) - (m_K[0] * um) - (m_K[index_2] * vm); - m_K[index_4] = (m_K[index_4] * um) - (m_K[1] * vm) - (m_K[index_2] * um); - m_K[index_5] = (m_K[index_5] * um * vm) - (m_K[index_0] * um * um) - (m_K[index_1] * vm * vm) - - (2.0 * m_K[index_2] * um * vm) - (2.0 * m_K[index_3] * um) - (2.0 * m_K[index_4] * vm); - - getParameters(); // since a, b, and e are used just after - vpColVector xg(2); - xg[0] = m_uc; - xg[1] = m_vc; - var = (xg - xg_prev).frobeniusNorm(); - xg_prev = xg; - - vpColVector residu(k); - for (unsigned int i = 0; i < k; ++i) { - double x = xp[i]; - double y = yp[i]; - double sign = (m_K[0] * x * x) + (m_K[1] * y * y) + (2. * m_K[2] * x * y) + (2. * m_K[3] * x) + (2. * m_K[4] * y) + m_K[5]; - vpImagePoint ip1, ip2; - ip1.set_uv(x, y); - double ang = computeAngleOnEllipse(ip1); - computePointOnEllipse(ang, ip2); - // residu = 0 if point is exactly on the ellipse, not otherwise - if (sign > 0) { - residu[i] = vpImagePoint::distance(ip1, ip2); - } - else { - residu[i] = -vpImagePoint::distance(ip1, ip2); - } - } - r.MEstimator(vpRobust::TUKEY, residu, w); - - ++iter; - } -} - -unsigned int vpMeEllipse::leastSquareRobust(const vpImage &I) -{ - double um = I.getWidth() / 2.; - double vm = I.getHeight() / 2.; - - const unsigned int nos = numberOfSignal(); - unsigned int k = 0; // count the number of tracked MEs - - vpColVector w(nos); - w = 1.0; - // Note that the (nos-k) last rows of w are not used. Hopefully, this is not an issue. - - if (m_trackCircle) { // we track a circle - leastSquareRobustCircle(um, vm, k, w); - } - else { // we track an ellipse - leastSquareRobustEllipse(um, vm, k, w); - } // end of case ellipse - - // Remove bad points and outliers from the lists - // Modify the angle to order the list - double previous_ang = -4.0 * M_PI; - k = 0; - std::list::iterator angleList = m_angleList.begin(); - std::list::iterator end = m_meList.end(); - std::list::iterator meList = m_meList.begin(); - while (meList != end) { - vpMeSite p_me = *meList; - if (p_me.getState() != vpMeSite::NO_SUPPRESSION) { - // points not selected as me - meList = m_meList.erase(meList); - angleList = m_angleList.erase(angleList); - } - else { - if (w[k] < m_thresholdWeight) { // outlier - meList = m_meList.erase(meList); - angleList = m_angleList.erase(angleList); - } - else { // good point - double ang = *angleList; - vpImagePoint iP; - iP.set_ij(p_me.m_ifloat, p_me.m_jfloat); - double new_ang = computeAngleOnEllipse(iP); - if ((new_ang - ang) > M_PI) { - new_ang -= 2.0 * M_PI; - } - else if ((ang - new_ang) > M_PI) { - new_ang += 2.0 * M_PI; - } - previous_ang = new_ang; - *angleList = new_ang; - ++meList; - ++angleList; - } - ++k; // k contains good points and outliers (used for w[k]) - } - } - - if (m_meList.size() != m_angleList.size()) { - // Should never occur - throw(vpTrackingException(vpTrackingException::fatalError, "Lists are not coherent in vpMeEllipse::leastSquareRobust(): nb MEs %ld, nb ang %ld", - m_meList.size(), m_angleList.size())); - } - - // Manage the list so that all new angles belong to [0;2Pi] - bool nbdeb = false; - std::list finAngle; - finAngle.clear(); - std::list finMe; - finMe.clear(); - std::list::iterator debutAngleList; - std::list::iterator debutMeList; - angleList = m_angleList.begin(); - meList = m_meList.begin(); - end = m_meList.end(); - while (meList != end) { - vpMeSite p_me = *meList; - double ang = *angleList; - - // Move these ones to another list to be added at the end - if (ang < m_alpha1) { - ang += 2.0 * M_PI; - angleList = m_angleList.erase(angleList); - finAngle.push_back(ang); - meList = m_meList.erase(meList); - finMe.push_back(p_me); - } - // Moved at the beginning of the list - else if (ang > m_alpha2) { - ang -= 2.0 * M_PI; - angleList = m_angleList.erase(angleList); - meList = m_meList.erase(meList); - if (!nbdeb) { - m_angleList.push_front(ang); - debutAngleList = m_angleList.begin(); - ++debutAngleList; - - m_meList.push_front(p_me); - debutMeList = m_meList.begin(); - ++debutMeList; - - nbdeb = true; - } - else { - debutAngleList = m_angleList.insert(debutAngleList, ang); - ++debutAngleList; - debutMeList = m_meList.insert(debutMeList, p_me); - ++debutMeList; - } - } - else { - ++angleList; - ++meList; - } - } - // Fuse the lists - angleList = m_angleList.end(); - m_angleList.splice(angleList, finAngle); - meList = m_meList.end(); - m_meList.splice(meList, finMe); - - unsigned int numberOfGoodPoints = 0; - previous_ang = -4.0 * M_PI; - - // Perimeter of the ellipse using Ramanujan formula - double perim = M_PI * ((3.0 * (m_a + m_b)) - sqrt(((3.0 * m_a) + m_b) * (m_a + (3.0 * m_b)))); - unsigned int nb_pt = static_cast(floor(perim / m_me->getSampleStep())); - double incr = (2.0 * M_PI) / nb_pt; - // Update of the expected density - if (!m_trackArc) { // number of points for a complete ellipse - m_expectedDensity = nb_pt; - } - else { // number of points for an arc of ellipse - m_expectedDensity *= static_cast(floor((perim / m_me->getSampleStep()) * ((m_alpha2 - m_alpha1) / (2.0 * M_PI)))); - } - - // Keep only the points in the interval [alpha1 ; alpha2] - // and those that are not too close - angleList = m_angleList.begin(); - end = m_meList.end(); - meList = m_meList.begin(); - while (meList != end) { - vpMeSite p_me = *meList; - double new_ang = *angleList; - if ((new_ang >= m_alpha1) && (new_ang <= m_alpha2)) { - if ((new_ang - previous_ang) >= (0.6 * incr)) { - previous_ang = new_ang; - ++numberOfGoodPoints; - ++meList; - ++angleList; - } - else { - meList = m_meList.erase(meList); - angleList = m_angleList.erase(angleList); - } - } - else { // point not in the interval [alpha1 ; alpha2] - meList = m_meList.erase(meList); - angleList = m_angleList.erase(angleList); - } - } - - if ((m_meList.size() != numberOfGoodPoints) || (m_angleList.size() != numberOfGoodPoints)) { - // Should never occur - throw(vpTrackingException(vpTrackingException::fatalError, "Lists are not coherent at the end of vpMeEllipse::leastSquareRobust(): nb goog MEs %d and %ld, nb ang %ld", - numberOfGoodPoints, m_meList.size(), m_angleList.size())); - } - - // set extremities of the angle list - m_alphamin = m_angleList.front(); - m_alphamax = m_angleList.back(); - - return numberOfGoodPoints; -} - void vpMeEllipse::display(const vpImage &I, const vpColor &col, unsigned int thickness) { vpMeEllipse::displayEllipse(I, m_iPc, m_a, m_b, m_e, m_alpha1, m_alpha2, col, thickness); diff --git a/modules/tracker/me/src/moving-edges/vpMeEllipse_least_square.cpp b/modules/tracker/me/src/moving-edges/vpMeEllipse_least_square.cpp new file mode 100644 index 0000000000..c382103415 --- /dev/null +++ b/modules/tracker/me/src/moving-edges/vpMeEllipse_least_square.cpp @@ -0,0 +1,533 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include +#include +#include +#include +#include + +BEGIN_VISP_NAMESPACE + +void vpMeEllipse::leastSquare(const vpImage &I, const std::vector &iP) +{ + double um = I.getWidth() / 2.; + double vm = I.getHeight() / 2.; + unsigned int n = static_cast(iP.size()); + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + const unsigned int index_3 = 3; + const unsigned int index_4 = 4; + const unsigned int index_5 = 5; + + if (m_trackCircle) { // we track a circle + const unsigned int circleDims = 3; + if (n < circleDims) { + throw(vpException(vpException::dimensionError, "Not enough points to compute the circle")); + } + // System A x = b to be solved by least squares + // with A = (u v 1), b = (u^2 + v^2) and x = (2xc, 2yc, r^2-xc^2-yc^2) + + vpMatrix A(n, 3); + vpColVector b(n); + + for (unsigned int k = 0; k < n; ++k) { + // normalization so that (u,v) in [-1;1] + double u = (iP[k].get_u() - um) / um; + double v = (iP[k].get_v() - vm) / um; // um here to not deform the circle + A[k][index_0] = u; + A[k][index_1] = v; + A[k][index_2] = 1.0; + b[k] = (u * u) + (v * v); + } + vpColVector x(3); + x = A.solveBySVD(b); + // A circle is a particular ellipse. Going from x for circle to K for ellipse + // using inverse normalization to go back to pixel values + double ratio = vm / um; + m_K[index_0] = (m_K[index_1] = (1.0 / (um * um))); + m_K[index_2] = 0.0; + m_K[index_3] = -(1.0 + (x[index_0] / 2.0)) / um; + m_K[index_4] = -(ratio + (x[index_1] / 2.0)) / um; + m_K[index_5] = -x[index_2] + 1.0 + (ratio * ratio) + x[index_0] + (ratio * x[index_1]); + } + else { // we track an ellipse + const unsigned int npoints_min = 5; + if (n < npoints_min) { + throw(vpException(vpException::dimensionError, "Not enough points to compute the ellipse")); + } + // Homogeneous system A x = 0 ; x is the nullspace of A + // K0 u^2 + K1 v^2 + 2 K2 u v + 2 K3 u + 2 K4 v + K5 = 0 + // A = (u^2 v^2 2uv 2u 2v 1), x = (K0 K1 K2 K3 K4 K5)^T + + // It would be a bad idea to solve the same system using A x = b where + // A = (u^2 v^2 2uv 2u 2v), b = (-1), x = (K0 K1 K2 K3 K4)^T since it + // cannot consider the case where the origin belongs to the ellipse. + // Another possibility would be to consider K0+K1=1 which is always valid, + // leading to the system A x = b where + // A = (u^2-v^2 2uv 2u 2v 1), b = (-v^2), x = (K0 K2 K3 K4 K5)^T + + vpMatrix A(n, 6); + + for (unsigned int k = 0; k < n; ++k) { + // Normalization so that (u,v) in [-1;1] + double u = (iP[k].get_u() - um) / um; + double v = (iP[k].get_v() - vm) / vm; + A[k][index_0] = u * u; + A[k][index_1] = v * v; + A[k][index_2] = 2.0 * u * v; + A[k][index_3] = 2.0 * u; + A[k][index_4] = 2.0 * v; + A[k][index_5] = 1.0; + } + vpMatrix KerA; + unsigned int dim = A.nullSpace(KerA, 1); + if (dim > 1) { // case with less than 5 independent points + throw(vpMatrixException(vpMatrixException::rankDeficient, "Linear system for computing the ellipse equation ill conditioned")); + } + unsigned int nbRows = m_K.getRows(); + for (unsigned int i = 0; i < nbRows; ++i) { + m_K[i] = KerA[i][0]; + } + + // inverse normalization + m_K[index_0] *= vm / um; + m_K[index_1] *= um / vm; + m_K[index_3] = (m_K[index_3] * vm) - (m_K[index_0] * um) - (m_K[index_2] * vm); + m_K[index_4] = (m_K[index_4] * um) - (m_K[index_1] * vm) - (m_K[index_2] * um); + m_K[index_5] = (m_K[index_5] * um * vm) - (m_K[index_0] * um * um) - (m_K[index_1] * vm * vm) - + (2.0 * m_K[index_2] * um * vm) - (2.0 * m_K[index_3] * um) - (2.0 * m_K[index_4] * vm); + } + getParameters(); +} + +void vpMeEllipse::leastSquareRobustCircle(const double &um, const double &vm, unsigned int &k, vpColVector &w) +{ + const unsigned int nos = numberOfSignal(); + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + const unsigned int index_3 = 3; + const unsigned int index_4 = 4; + const unsigned int index_5 = 5; + + // System A x = b to be solved by least squares + // with A = (u v 1), b = (u^2 + v^2) and x = (2xc, 2yc, r^2-xc^2-yc^2) + + // Note that the (nos-k) last rows of A, b, xp and yp are not used. + // Hopefully, this is not an issue. + vpMatrix A(nos, 3); + vpColVector b(nos); + + // Useful to compute the weights in the robust estimation + vpColVector xp(nos), yp(nos); + std::list::const_iterator end = m_meList.end(); + + for (std::list::const_iterator it = m_meList.begin(); it != end; ++it) { + vpMeSite p_me = *it; + if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { + // from (i,j) to (u,v) frame + normalization so that (u,v) in [-1;1] + double u = (p_me.get_jfloat() - um) / um; + double v = (p_me.get_ifloat() - vm) / um; // um to not deform the circle + A[k][index_0] = u; + A[k][index_1] = v; + A[k][index_2] = 1.0; + b[k] = (u * u) + (v * v); + // Useful to compute the weights in the robust estimation + xp[k] = p_me.get_jfloat(); + yp[k] = p_me.get_ifloat(); + + ++k; + } + } + + const unsigned int minRequiredNbMe = 3; + if (k < minRequiredNbMe) { + throw(vpException(vpException::dimensionError, "Not enough moving edges %d / %d to track the circle ", + k, m_meList.size())); + } + + vpRobust r; + r.setMinMedianAbsoluteDeviation(1.0); // Image noise in pixels for the algebraic distance + + unsigned int iter = 0; + double var = 1.0; + vpColVector x(3); + vpMatrix DA(k, 3); + vpColVector Db(k); + vpColVector xg_prev(2); + xg_prev = -10.0; + + // stop after 4 it or if cog variation between 2 it is more than 1 pixel + const unsigned int maxNbIter = 4; + const unsigned int widthDA = DA.getCols(); + while ((iter < maxNbIter) && (var > 0.1)) { + for (unsigned int i = 0; i < k; ++i) { + for (unsigned int j = 0; j < widthDA; ++j) { + DA[i][j] = w[i] * A[i][j]; + } + Db[i] = w[i] * b[i]; + } + x = DA.solveBySVD(Db); + + // A circle is a particular ellipse. Going from x for circle to K for ellipse + // using inverse normalization to go back to pixel values + double ratio = vm / um; + m_K[index_0] = (m_K[index_1] = (1.0 / (um * um))); + m_K[index_2] = 0.0; + m_K[index_3] = -(1.0 + (x[index_0] / 2.0)) / um; + m_K[index_4] = -(ratio + (x[index_1] / 2.0)) / um; + m_K[index_5] = -x[index_2] + 1.0 + (ratio * ratio) + x[index_0] + (ratio * x[index_1]); + + getParameters(); + vpColVector xg(2); + xg[0] = m_uc; + xg[1] = m_vc; + var = (xg - xg_prev).frobeniusNorm(); + xg_prev = xg; + + vpColVector residu(k); // near to geometric distance in pixel + for (unsigned int i = 0; i < k; ++i) { + double x = xp[i]; + double y = yp[i]; + double sign = (m_K[index_0] * x * x) + (m_K[index_1] * y * y) + (2. * m_K[index_2] * x * y) + + (2. * m_K[index_3] * x) + (2. * m_K[index_4] * y) + m_K[index_5]; + vpImagePoint ip1, ip2; + ip1.set_uv(x, y); + double ang = computeAngleOnEllipse(ip1); + computePointOnEllipse(ang, ip2); + // residu = 0 if point is exactly on the ellipse, not otherwise + if (sign > 0) { + residu[i] = vpImagePoint::distance(ip1, ip2); + } + else { + residu[i] = -vpImagePoint::distance(ip1, ip2); + } + } + r.MEstimator(vpRobust::TUKEY, residu, w); + + ++iter; + } +} + +void vpMeEllipse::leastSquareRobustEllipse(const double &um, const double &vm, unsigned int &k, vpColVector &w) +{ + const unsigned int nos = numberOfSignal(); + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + const unsigned int index_3 = 3; + const unsigned int index_4 = 4; + const unsigned int index_5 = 5; + // Homogeneous system A x = 0 ; x is the nullspace of A + // K0 u^2 + K1 v^2 + 2 K2 u v + 2 K3 u + 2 K4 v + K5 = 0 + // A = (u^2 v^2 2uv 2u 2v 1), x = (K0 K1 K2 K3 K4 K5)^T + + // It would be a bad idea to solve the same system using A x = b where + // A = (u^2 v^2 2uv 2u 2v), b = (-1), x = (K0 K1 K2 K3 K4)^T since it + // cannot consider the case where the origin belongs to the ellipse. + // Another possibility would be to consider K0+K1=1 which is always valid, + // leading to the system A x = b where + // A = (u^2-v^2 2uv 2u 2v 1), b = (-v^2), x = (K0 K2 K3 K4 K5)^T + const unsigned int nbColsA = 6; + vpMatrix A(nos, nbColsA); + // Useful to compute the weights in the robust estimation + vpColVector xp(nos), yp(nos); + std::list::const_iterator end = m_meList.end(); + + for (std::list::const_iterator it = m_meList.begin(); it != end; ++it) { + vpMeSite p_me = *it; + if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { + // from (i,j) to (u,v) frame + normalization so that (u,v) in [-1;1] + double u = (p_me.get_jfloat() - um) / um; + double v = (p_me.get_ifloat() - vm) / vm; + A[k][index_0] = u * u; + A[k][index_1] = v * v; + A[k][index_2] = 2.0 * u * v; + A[k][index_3] = 2.0 * u; + A[k][index_4] = 2.0 * v; + A[k][index_5] = 1.0; + // Useful to compute the weights in the robust estimation + xp[k] = p_me.get_jfloat(); + yp[k] = p_me.get_ifloat(); + + ++k; + } + } + + const unsigned int minRequiredMe = 5; + if (k < minRequiredMe) { + throw(vpException(vpException::dimensionError, "Not enough moving edges to track the ellipse")); + } + + vpRobust r; + + r.setMinMedianAbsoluteDeviation(1.0); // image noise in pixels for the geometrical distance + unsigned int iter = 0; + double var = 1.0; + vpMatrix DA(k, 6); + vpMatrix KerDA; + vpColVector xg_prev(2); + xg_prev = -10.0; + + // Stop after 4 iterations or if cog variation between 2 iterations is more than 0.1 pixel + const unsigned int maxIter = 4; + const unsigned int widthDA = DA.getCols(); + while ((iter < maxIter) && (var > 0.1)) { + for (unsigned int i = 0; i < k; ++i) { + for (unsigned int j = 0; j < widthDA; ++j) { + DA[i][j] = w[i] * A[i][j]; + } + } + unsigned int dim = DA.nullSpace(KerDA, 1); + if (dim > 1) { // case with less than 5 independent points + throw(vpMatrixException(vpMatrixException::rankDeficient, "Linear system for computing the ellipse equation ill conditioned")); + } + + const unsigned int nparam = 6; + for (unsigned int i = 0; i < nparam; ++i) { + m_K[i] = KerDA[i][0]; // norm(K) = 1 + } + + // inverse normalization + m_K[index_0] *= vm / um; + m_K[index_1] *= um / vm; + m_K[index_3] = (m_K[index_3] * vm) - (m_K[0] * um) - (m_K[index_2] * vm); + m_K[index_4] = (m_K[index_4] * um) - (m_K[1] * vm) - (m_K[index_2] * um); + m_K[index_5] = (m_K[index_5] * um * vm) - (m_K[index_0] * um * um) - (m_K[index_1] * vm * vm) + - (2.0 * m_K[index_2] * um * vm) - (2.0 * m_K[index_3] * um) - (2.0 * m_K[index_4] * vm); + + getParameters(); // since a, b, and e are used just after + vpColVector xg(2); + xg[0] = m_uc; + xg[1] = m_vc; + var = (xg - xg_prev).frobeniusNorm(); + xg_prev = xg; + + vpColVector residu(k); + for (unsigned int i = 0; i < k; ++i) { + double x = xp[i]; + double y = yp[i]; + double sign = (m_K[0] * x * x) + (m_K[1] * y * y) + (2. * m_K[2] * x * y) + (2. * m_K[3] * x) + (2. * m_K[4] * y) + m_K[5]; + vpImagePoint ip1, ip2; + ip1.set_uv(x, y); + double ang = computeAngleOnEllipse(ip1); + computePointOnEllipse(ang, ip2); + // residu = 0 if point is exactly on the ellipse, not otherwise + if (sign > 0) { + residu[i] = vpImagePoint::distance(ip1, ip2); + } + else { + residu[i] = -vpImagePoint::distance(ip1, ip2); + } + } + r.MEstimator(vpRobust::TUKEY, residu, w); + + ++iter; + } +} + +unsigned int vpMeEllipse::leastSquareRobust(const vpImage &I) +{ + double um = I.getWidth() / 2.; + double vm = I.getHeight() / 2.; + + const unsigned int nos = numberOfSignal(); + unsigned int k = 0; // count the number of tracked MEs + + vpColVector w(nos); + w = 1.0; + // Note that the (nos-k) last rows of w are not used. Hopefully, this is not an issue. + + if (m_trackCircle) { // we track a circle + leastSquareRobustCircle(um, vm, k, w); + } + else { // we track an ellipse + leastSquareRobustEllipse(um, vm, k, w); + } // end of case ellipse + + // Remove bad points and outliers from the lists + // Modify the angle to order the list + double previous_ang = -4.0 * M_PI; + k = 0; + std::list::iterator angleList = m_angleList.begin(); + std::list::iterator end = m_meList.end(); + std::list::iterator meList = m_meList.begin(); + while (meList != end) { + vpMeSite p_me = *meList; + if (p_me.getState() != vpMeSite::NO_SUPPRESSION) { + // points not selected as me + meList = m_meList.erase(meList); + angleList = m_angleList.erase(angleList); + } + else { + if (w[k] < m_thresholdWeight) { // outlier + meList = m_meList.erase(meList); + angleList = m_angleList.erase(angleList); + } + else { // good point + double ang = *angleList; + vpImagePoint iP; + iP.set_ij(p_me.m_ifloat, p_me.m_jfloat); + double new_ang = computeAngleOnEllipse(iP); + if ((new_ang - ang) > M_PI) { + new_ang -= 2.0 * M_PI; + } + else if ((ang - new_ang) > M_PI) { + new_ang += 2.0 * M_PI; + } + previous_ang = new_ang; + *angleList = new_ang; + ++meList; + ++angleList; + } + ++k; // k contains good points and outliers (used for w[k]) + } + } + + if (m_meList.size() != m_angleList.size()) { + // Should never occur + throw(vpTrackingException(vpTrackingException::fatalError, "Lists are not coherent in vpMeEllipse::leastSquareRobust(): nb MEs %ld, nb ang %ld", + m_meList.size(), m_angleList.size())); + } + + // Manage the list so that all new angles belong to [0;2Pi] + bool nbdeb = false; + std::list finAngle; + finAngle.clear(); + std::list finMe; + finMe.clear(); + std::list::iterator debutAngleList; + std::list::iterator debutMeList; + angleList = m_angleList.begin(); + meList = m_meList.begin(); + end = m_meList.end(); + while (meList != end) { + vpMeSite p_me = *meList; + double ang = *angleList; + + // Move these ones to another list to be added at the end + if (ang < m_alpha1) { + ang += 2.0 * M_PI; + angleList = m_angleList.erase(angleList); + finAngle.push_back(ang); + meList = m_meList.erase(meList); + finMe.push_back(p_me); + } + // Moved at the beginning of the list + else if (ang > m_alpha2) { + ang -= 2.0 * M_PI; + angleList = m_angleList.erase(angleList); + meList = m_meList.erase(meList); + if (!nbdeb) { + m_angleList.push_front(ang); + debutAngleList = m_angleList.begin(); + ++debutAngleList; + + m_meList.push_front(p_me); + debutMeList = m_meList.begin(); + ++debutMeList; + + nbdeb = true; + } + else { + debutAngleList = m_angleList.insert(debutAngleList, ang); + ++debutAngleList; + debutMeList = m_meList.insert(debutMeList, p_me); + ++debutMeList; + } + } + else { + ++angleList; + ++meList; + } + } + // Fuse the lists + angleList = m_angleList.end(); + m_angleList.splice(angleList, finAngle); + meList = m_meList.end(); + m_meList.splice(meList, finMe); + + unsigned int numberOfGoodPoints = 0; + previous_ang = -4.0 * M_PI; + + // Perimeter of the ellipse using Ramanujan formula + double perim = M_PI * ((3.0 * (m_a + m_b)) - sqrt(((3.0 * m_a) + m_b) * (m_a + (3.0 * m_b)))); + unsigned int nb_pt = static_cast(floor(perim / m_me->getSampleStep())); + double incr = (2.0 * M_PI) / nb_pt; + // Update of the expected density + if (!m_trackArc) { // number of points for a complete ellipse + m_expectedDensity = nb_pt; + } + else { // number of points for an arc of ellipse + m_expectedDensity *= static_cast(floor((perim / m_me->getSampleStep()) * ((m_alpha2 - m_alpha1) / (2.0 * M_PI)))); + } + + // Keep only the points in the interval [alpha1 ; alpha2] + // and those that are not too close + angleList = m_angleList.begin(); + end = m_meList.end(); + meList = m_meList.begin(); + while (meList != end) { + vpMeSite p_me = *meList; + double new_ang = *angleList; + if ((new_ang >= m_alpha1) && (new_ang <= m_alpha2)) { + if ((new_ang - previous_ang) >= (0.6 * incr)) { + previous_ang = new_ang; + ++numberOfGoodPoints; + ++meList; + ++angleList; + } + else { + meList = m_meList.erase(meList); + angleList = m_angleList.erase(angleList); + } + } + else { // point not in the interval [alpha1 ; alpha2] + meList = m_meList.erase(meList); + angleList = m_angleList.erase(angleList); + } + } + + if ((m_meList.size() != numberOfGoodPoints) || (m_angleList.size() != numberOfGoodPoints)) { + // Should never occur + throw(vpTrackingException(vpTrackingException::fatalError, "Lists are not coherent at the end of vpMeEllipse::leastSquareRobust(): nb goog MEs %d and %ld, nb ang %ld", + numberOfGoodPoints, m_meList.size(), m_angleList.size())); + } + + // set extremities of the angle list + m_alphamin = m_angleList.front(); + m_alphamax = m_angleList.back(); + + return numberOfGoodPoints; +} + +END_VISP_NAMESPACE From 1b4382600c15dbb023a1a2fcda7905dc24cc3302 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 24 Jun 2024 18:42:56 +0200 Subject: [PATCH 02/11] Introduce explict keyword to satisfy misra c++ quality rules --- .vscode/settings.json | 6 +- CMakeLists.txt | 13 +- cmake/templates/VISPConfig.cmake.in | 1 + cmake/templates/vpConfig.h.in | 59 ++++-- demo/wireframe-simulator/servoSimu4Points.cpp | 6 +- .../wireframe-simulator/servoSimuCylinder.cpp | 4 +- demo/wireframe-simulator/servoSimuSphere.cpp | 6 +- example/calibration/calibration-helper.hpp | 2 +- .../photometricMappingVisualServoing.cpp | 2 +- .../photometricVisualServoing.cpp | 2 +- ...hotometricVisualServoingWithoutVpServo.cpp | 2 +- .../manGeometricFeatures.cpp | 2 +- example/moments/image/servoMomentImage.cpp | 4 +- example/moments/points/servoMomentPoints.cpp | 2 +- .../moments/polygon/servoMomentPolygon.cpp | 2 +- example/servo-pioneer/sonarPioneerReader.cpp | 2 +- .../wireframeSimulator.cpp | 8 +- .../include/visp3/ar/vpPanda3DCommonFilters.h | 8 +- .../visp3/ar/vpPanda3DGeometryRenderer.h | 4 +- .../visp3/ar/vpPanda3DPostProcessFilter.h | 8 +- .../include/visp3/ar/vpPanda3DRGBRenderer.h | 8 +- .../include/visp3/ar/vpPanda3DRendererSet.h | 20 +- .../include/visp3/ar/vpSimulatorException.h | 2 +- modules/core/include/visp3/core/vpArray2D.h | 6 +- modules/core/include/visp3/core/vpCircle.h | 28 +-- modules/core/include/visp3/core/vpClient.h | 2 +- modules/core/include/visp3/core/vpColVector.h | 39 ++-- modules/core/include/visp3/core/vpCylinder.h | 20 +- modules/core/include/visp3/core/vpDisplay.h | 8 +- .../include/visp3/core/vpDisplayException.h | 2 +- .../include/visp3/core/vpEigenConversion.h | 30 +-- modules/core/include/visp3/core/vpException.h | 2 +- .../include/visp3/core/vpForceTwistMatrix.h | 20 +- .../visp3/core/vpFrameGrabberException.h | 2 +- modules/core/include/visp3/core/vpHinkley.h | 4 +- modules/core/include/visp3/core/vpHistogram.h | 4 +- .../include/visp3/core/vpHomogeneousMatrix.h | 26 +-- modules/core/include/visp3/core/vpImage.h | 12 +- .../include/visp3/core/vpImageException.h | 2 +- .../include/visp3/core/vpImageMorphology.h | 6 +- .../core/include/visp3/core/vpImagePoint.h | 2 +- .../core/include/visp3/core/vpImageTools.h | 12 +- .../include/visp3/core/vpImageTools_warp.h | 18 +- .../core/include/visp3/core/vpImage_getters.h | 9 +- .../core/include/visp3/core/vpIoException.h | 2 +- .../core/include/visp3/core/vpKalmanFilter.h | 2 +- modules/core/include/visp3/core/vpLine.h | 18 +- modules/core/include/visp3/core/vpMatrix.h | 114 +++++++---- .../include/visp3/core/vpMatrixException.h | 2 +- .../visp3/core/vpMomentAreaNormalized.h | 2 +- .../include/visp3/core/vpMomentCInvariant.h | 2 +- .../core/include/visp3/core/vpMomentCommon.h | 4 +- .../core/include/visp3/core/vpMomentObject.h | 2 +- modules/core/include/visp3/core/vpMutex.h | 2 +- .../visp3/core/vpPixelMeterConversion.h | 4 +- modules/core/include/visp3/core/vpPoint.h | 22 +-- modules/core/include/visp3/core/vpPolygon.h | 10 +- modules/core/include/visp3/core/vpPolygon3D.h | 2 +- .../core/include/visp3/core/vpPoseVector.h | 12 +- .../include/visp3/core/vpQuaternionVector.h | 18 +- modules/core/include/visp3/core/vpRGBa.h | 32 +++- modules/core/include/visp3/core/vpRGBf.h | 17 +- modules/core/include/visp3/core/vpRansac.h | 21 +- modules/core/include/visp3/core/vpRect.h | 12 +- .../core/include/visp3/core/vpRectOriented.h | 6 +- modules/core/include/visp3/core/vpRobust.h | 8 +- .../include/visp3/core/vpRotationMatrix.h | 38 ++-- .../include/visp3/core/vpRotationVector.h | 2 +- modules/core/include/visp3/core/vpRowVector.h | 109 ++++++----- .../core/include/visp3/core/vpRxyzVector.h | 18 +- .../core/include/visp3/core/vpRzyxVector.h | 18 +- .../core/include/visp3/core/vpRzyzVector.h | 18 +- modules/core/include/visp3/core/vpServer.h | 4 +- modules/core/include/visp3/core/vpSphere.h | 26 +-- .../core/include/visp3/core/vpSubColVector.h | 2 +- modules/core/include/visp3/core/vpSubMatrix.h | 2 +- .../core/include/visp3/core/vpSubRowVector.h | 2 +- .../core/include/visp3/core/vpThetaUVector.h | 38 ++-- modules/core/include/visp3/core/vpThread.h | 2 +- .../include/visp3/core/vpTrackingException.h | 2 +- .../include/visp3/core/vpTranslationVector.h | 16 +- modules/core/include/visp3/core/vpTriangle.h | 2 +- .../visp3/core/vpVelocityTwistMatrix.h | 20 +- modules/core/src/camera/vpXmlParserCamera.cpp | 20 +- modules/core/src/display/vpDisplay_impl.h | 5 +- .../core/src/image/vpImageConvert_opencv.cpp | 3 + .../core/src/image/vpImageConvert_yarp.cpp | 4 + modules/core/src/image/vpRGBa.cpp | 68 +++++-- modules/core/src/image/vpRGBf.cpp | 47 ++++- modules/core/src/math/matrix/vpColVector.cpp | 20 +- .../src/math/matrix/vpEigenConversion.cpp | 18 +- modules/core/src/math/matrix/vpMatrix.cpp | 66 ++++++- .../src/math/matrix/vpMatrix_operations.cpp | 83 ++++++++ .../src/math/matrix/vpMatrix_operators.cpp | 155 ++++++++++++++- modules/core/src/math/matrix/vpRowVector.cpp | 180 ++++++++++-------- .../math/transformation/vpRotationMatrix.cpp | 30 +-- modules/core/src/tools/file/vpIoTools_npy.cpp | 5 +- .../src/tools/geometry/vpRectOriented.cpp | 6 +- .../core/src/tools/optimization/vpLinProg.cpp | 15 +- .../src/tools/optimization/vpQuadProg.cpp | 9 +- .../test/math/perfMatrixMultiplication.cpp | 24 +-- .../core/test/math/testEigenConversion.cpp | 6 +- modules/core/test/math/testMatrix.cpp | 6 +- modules/core/test/math/testRand.cpp | 2 +- .../visp3/detection/vpDetectorAprilTag.h | 8 +- .../detection/vpDetectorDataMatrixCode.h | 4 +- .../include/visp3/detection/vpDetectorFace.h | 2 +- .../visp3/detection/vpDetectorQRCode.h | 2 +- modules/gui/include/visp3/gui/vpD3DRenderer.h | 4 +- modules/gui/include/visp3/gui/vpDisplayGTK.h | 80 ++++---- .../gui/include/visp3/gui/vpDisplayOpenCV.h | 74 +++---- .../gui/include/visp3/gui/vpDisplayWin32.h | 76 ++++---- modules/gui/include/visp3/gui/vpDisplayX.h | 74 +++---- modules/gui/include/visp3/gui/vpGDIRenderer.h | 2 +- .../include/visp3/gui/vpProjectionDisplay.h | 2 +- modules/gui/include/visp3/gui/vpWin32Window.h | 2 +- modules/gui/test/display/testDisplayRoi.cpp | 2 +- modules/gui/test/display/testDisplays.cpp | 13 +- .../visp3/imgproc/vpCircleHoughTransform.h | 4 +- .../include/visp3/imgproc/vpContours.h | 2 +- modules/imgproc/src/vpImgproc.cpp | 2 +- modules/io/include/visp3/io/vpDiskGrabber.h | 4 +- .../visp3/io/vpParallelPortException.h | 2 +- .../include/visp3/robot/vpImageSimulator.h | 2 +- .../robot/include/visp3/robot/vpRobotAfma4.h | 12 +- .../robot/include/visp3/robot/vpRobotAfma6.h | 12 +- .../include/visp3/robot/vpRobotBiclops.h | 18 +- .../robot/include/visp3/robot/vpRobotCamera.h | 8 +- .../include/visp3/robot/vpRobotException.h | 2 +- .../include/visp3/robot/vpRobotFlirPtu.h | 12 +- .../robot/include/visp3/robot/vpRobotFranka.h | 10 +- .../robot/include/visp3/robot/vpRobotKinova.h | 14 +- .../include/visp3/robot/vpRobotPioneer.h | 4 +- .../include/visp3/robot/vpRobotPololuPtu.h | 14 +- .../robot/include/visp3/robot/vpRobotPtu46.h | 14 +- .../include/visp3/robot/vpRobotTemplate.h | 16 +- .../visp3/robot/vpRobotUniversalRobots.h | 6 +- .../include/visp3/robot/vpRobotViper650.h | 10 +- .../include/visp3/robot/vpRobotViper850.h | 12 +- .../visp3/robot/vpRobotWireFrameSimulator.h | 2 +- .../robot/include/visp3/robot/vpServolens.h | 2 +- .../include/visp3/robot/vpSimulatorAfma6.h | 28 +-- .../include/visp3/robot/vpSimulatorCamera.h | 8 +- .../include/visp3/robot/vpSimulatorPioneer.h | 8 +- .../visp3/robot/vpSimulatorPioneerPan.h | 8 +- .../include/visp3/robot/vpSimulatorViper850.h | 28 +-- .../robot/include/visp3/robot/vpVirtuose.h | 2 +- .../vpRobotWireFrameSimulator.cpp | 4 +- .../vpWireFrameSimulator.cpp | 12 +- .../include/visp3/sensor/vp1394TwoGrabber.h | 2 +- .../include/visp3/sensor/vpDirectShowDevice.h | 2 +- .../sensor/vpForceTorqueAtiNetFTSensor.h | 2 +- .../visp3/sensor/vpForceTorqueAtiSensor.h | 2 +- .../sensor/include/visp3/sensor/vpSickLDMRS.h | 2 +- .../include/visp3/sensor/vpV4l2Grabber.h | 2 +- .../tracker/blob/include/visp3/blob/vpDot.h | 4 +- .../tracker/blob/include/visp3/blob/vpDot2.h | 2 +- .../include/visp3/mbt/vpMbDepthDenseTracker.h | 42 ++-- .../visp3/mbt/vpMbDepthNormalTracker.h | 42 ++-- .../include/visp3/mbt/vpMbEdgeKltTracker.h | 36 ++-- .../mbt/include/visp3/mbt/vpMbEdgeTracker.h | 42 ++-- .../include/visp3/mbt/vpMbGenericTracker.h | 148 +++++++------- .../mbt/include/visp3/mbt/vpMbKltTracker.h | 46 ++--- .../mbt/include/visp3/mbt/vpMbtMeEllipse.h | 2 +- .../mbt/include/visp3/mbt/vpMbtMeLine.h | 4 +- .../tracker/me/include/visp3/me/vpMeEllipse.h | 8 +- .../tracker/me/include/visp3/me/vpMeLine.h | 14 +- .../tracker/me/include/visp3/me/vpMeNurbs.h | 2 +- .../tracker/me/include/visp3/me/vpMeTracker.h | 4 +- .../tt/include/visp3/tt/vpTemplateTracker.h | 4 +- .../include/visp3/tt/vpTemplateTrackerSSD.h | 2 +- .../visp3/tt/vpTemplateTrackerSSDESM.h | 2 +- .../vpTemplateTrackerSSDForwardAdditional.h | 2 +- ...vpTemplateTrackerSSDForwardCompositional.h | 2 +- ...vpTemplateTrackerSSDInverseCompositional.h | 2 +- .../include/visp3/tt/vpTemplateTrackerZNCC.h | 2 +- .../vpTemplateTrackerZNCCForwardAdditional.h | 2 +- ...pTemplateTrackerZNCCInverseCompositional.h | 4 +- .../include/visp3/tt_mi/vpTemplateTrackerMI.h | 6 +- .../visp3/tt_mi/vpTemplateTrackerMIESM.h | 2 +- .../vpTemplateTrackerMIForwardAdditional.h | 2 +- .../vpTemplateTrackerMIForwardCompositional.h | 2 +- .../vpTemplateTrackerMIInverseCompositional.h | 2 +- .../visp3/vision/vpCalibrationException.h | 2 +- modules/vision/include/visp3/vision/vpPose.h | 2 +- .../include/visp3/vision/vpPoseException.h | 2 +- .../visp3/visual_features/vpFeatureDepth.h | 14 +- .../visp3/visual_features/vpFeatureEllipse.h | 28 +-- .../visual_features/vpFeatureException.h | 2 +- .../visp3/visual_features/vpFeatureLine.h | 14 +- .../visual_features/vpFeatureLuminance.h | 16 +- .../vpFeatureLuminanceMapping.h | 22 +-- .../visp3/visual_features/vpFeatureMoment.h | 12 +- .../visual_features/vpFeatureMomentAlpha.h | 4 +- .../visual_features/vpFeatureMomentArea.h | 2 +- .../vpFeatureMomentAreaNormalized.h | 4 +- .../visual_features/vpFeatureMomentBasic.h | 2 +- .../vpFeatureMomentCInvariant.h | 4 +- .../visual_features/vpFeatureMomentCentered.h | 2 +- .../vpFeatureMomentGravityCenter.h | 4 +- .../vpFeatureMomentGravityCenterNormalized.h | 4 +- .../visp3/visual_features/vpFeaturePoint.h | 14 +- .../visp3/visual_features/vpFeaturePoint3D.h | 14 +- .../visual_features/vpFeaturePointPolar.h | 14 +- .../visp3/visual_features/vpFeatureSegment.h | 16 +- .../visp3/visual_features/vpFeatureThetaU.h | 16 +- .../visual_features/vpFeatureTranslation.h | 16 +- .../visual_features/vpFeatureVanishingPoint.h | 14 +- .../visp3/visual_features/vpGenericFeature.h | 16 +- .../src/visual-feature/vpFeatureEllipse.cpp | 6 +- modules/vs/include/visp3/vs/vpAdaptiveGain.h | 2 +- modules/vs/include/visp3/vs/vpServo.h | 2 +- .../vs/include/visp3/vs/vpServoException.h | 2 +- modules/vs/src/vpServo.cpp | 24 +-- tutorial/ar/tutorial-panda3d-renderer.cpp | 6 +- tutorial/image/drawingHelpers.cpp | 62 +++--- tutorial/imgproc/contour/tutorial-contour.cpp | 2 +- .../hough-transform/drawingHelpers.cpp | 22 ++- 218 files changed, 1924 insertions(+), 1367 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e4c76f7c07..5dec46c458 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -161,7 +161,11 @@ "primitiveset": "cpp", "stateattribute": "cpp", "uniform": "cpp", - "polytope": "cpp" + "polytope": "cpp", + "core": "cpp", + "dense": "cpp", + "stdvector": "cpp", + "numericaldiff": "cpp" }, "C_Cpp.vcFormat.indent.namespaceContents": false, "editor.formatOnSave": true, diff --git a/CMakeLists.txt b/CMakeLists.txt index a7510de777..9ac08e07c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -543,6 +543,8 @@ VP_OPTION(ENABLE_FULL_DOC "" "" "Build doc with internal classes that are b # Allow introduction of "visp" namespace. By default disabled to keep compat with previous versions VP_OPTION(ENABLE_VISP_NAMESPACE "" "" "Enable visp namespace" "" OFF) +# Allow introduction of "explicit" keyword. By default disabled to keep compat with previous versions +VP_OPTION(ENABLE_EXPLICIT_KEYWORD "" "" "Enable c++ explicit keyword" "" OFF) if(ENABLE_SOLUTION_FOLDERS) set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -1610,11 +1612,12 @@ foreach(m ${VISP_MODULES_DISABLED_AUTO}) endforeach() string(REPLACE "visp_" "" VISP_MODULES_DISABLED_AUTO_ST "${VISP_MODULES_DISABLED_AUTO_ST}") -status(" To be built:" VISP_MODULES_BUILD THEN ${VISP_MODULES_BUILD_ST} ELSE "-") -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") +status(" To be built:" VISP_MODULES_BUILD THEN ${VISP_MODULES_BUILD_ST} ELSE "-") +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") +status(" Enable explicit keyword:" ENABLE_EXPLICIT_KEYWORD THEN "yes" ELSE "no") # ========================== Android details ========================== if(ANDROID) diff --git a/cmake/templates/VISPConfig.cmake.in b/cmake/templates/VISPConfig.cmake.in index 87710c01fe..2e3f786289 100644 --- a/cmake/templates/VISPConfig.cmake.in +++ b/cmake/templates/VISPConfig.cmake.in @@ -190,6 +190,7 @@ set(VISP_BIN_INSTALL_PATH "@VISP_BIN_INSTALL_PATH@") # Remember VISP third party libs configuration #---------------------------------------------------------------------- set(ENABLE_VISP_NAMESPACE "@ENABLE_VISP_NAMESPACE@") +set(ENABLE_EXPLICIT_KEYWORD "@ENABLE_EXPLICIT_KEYWORD@") set(VISP_HAVE_AFMA4 "@VISP_HAVE_AFMA4@") set(VISP_HAVE_AFMA6 "@VISP_HAVE_AFMA6@") set(VISP_HAVE_APRILTAG "@VISP_HAVE_APRILTAG@") diff --git a/cmake/templates/vpConfig.h.in b/cmake/templates/vpConfig.h.in index e73c52a4b2..c36e4dae15 100644 --- a/cmake/templates/vpConfig.h.in +++ b/cmake/templates/vpConfig.h.in @@ -33,8 +33,8 @@ * *****************************************************************************/ -#ifndef _vpConfig_h_ -#define _vpConfig_h_ +#ifndef VP_CONFIG_H +#define VP_CONFIG_H // To get access to EXIT_SUCCESS and EXIT_FAILURE #include @@ -610,15 +610,6 @@ namespace vp = VISP_NAMESPACE_NAME; #include #endif -// Macro to be able to add override keyword -#ifndef vp_override - #if (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1600) - #define vp_override override - #else - #define vp_override - #endif -#endif - // Handle portable symbol export. // Defining manually which symbol should be exported is required // under Windows whether MinGW or MSVC is used. @@ -668,12 +659,52 @@ namespace vp = VISP_NAMESPACE_NAME; # define VISP_LOCAL #endif +#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) +// Add the material to produce a warning when deprecated functions are used +# ifndef vp_deprecated +# if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX +# define vp_deprecated __attribute__((deprecated)) +# else +# define vp_deprecated __declspec(deprecated) +# endif +# endif +// Macro to be able to add override keyword +# ifndef vp_override +# if (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1600) +# define vp_override override +# else +# define vp_override +# endif +# endif +#endif + // Add the material to produce a warning when deprecated functions are used -#ifndef vp_deprecated +#ifndef VP_DEPRECATED # if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX -# define vp_deprecated __attribute__((deprecated)) +# define VP_DEPRECATED __attribute__((deprecated)) +# else +# define VP_DEPRECATED __declspec(deprecated) +# endif +#endif + +// Macro to be able to add override keyword +#ifndef VP_OVERRIDE +# if (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1600) +# define VP_OVERRIDE override +# else +# define VP_OVERRIDE +# endif +#endif + +// Defined if the user wants to enable explicit keyword +#cmakedefine ENABLE_EXPLICIT_KEYWORD + +// Add the macro for explicit keyword +#ifndef VP_EXPLICIT +# if ((__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1600)) && defined(ENABLE_EXPLICIT_KEYWORD) +# define VP_EXPLICIT explicit # else -# define vp_deprecated __declspec(deprecated) +# define VP_EXPLICIT # endif #endif diff --git a/demo/wireframe-simulator/servoSimu4Points.cpp b/demo/wireframe-simulator/servoSimu4Points.cpp index 2df71e1d98..f23fbcd7ad 100644 --- a/demo/wireframe-simulator/servoSimu4Points.cpp +++ b/demo/wireframe-simulator/servoSimu4Points.cpp @@ -172,9 +172,9 @@ int main(int argc, const char **argv) return EXIT_FAILURE; } - vpImage Iint(480, 640, 255); - vpImage Iext1(480, 640, 255); - vpImage Iext2(480, 640, 255); + vpImage Iint(480, 640, vpRGBa(255)); + vpImage Iext1(480, 640, vpRGBa(255)); + vpImage Iext2(480, 640, vpRGBa(255)); #if defined(VISP_HAVE_X11) vpDisplayX display[3]; diff --git a/demo/wireframe-simulator/servoSimuCylinder.cpp b/demo/wireframe-simulator/servoSimuCylinder.cpp index 58c2880d9c..90ed93b343 100644 --- a/demo/wireframe-simulator/servoSimuCylinder.cpp +++ b/demo/wireframe-simulator/servoSimuCylinder.cpp @@ -171,8 +171,8 @@ int main(int argc, const char **argv) return EXIT_FAILURE; } - vpImage Iint(480, 640, 255); - vpImage Iext(480, 640, 255); + vpImage Iint(480, 640, vpRGBa(255)); + vpImage Iext(480, 640, vpRGBa(255)); #if defined(VISP_HAVE_X11) vpDisplayX display[2]; diff --git a/demo/wireframe-simulator/servoSimuSphere.cpp b/demo/wireframe-simulator/servoSimuSphere.cpp index 67c29bcc0c..4bb868c9e4 100644 --- a/demo/wireframe-simulator/servoSimuSphere.cpp +++ b/demo/wireframe-simulator/servoSimuSphere.cpp @@ -227,9 +227,9 @@ int main(int argc, const char **argv) return EXIT_FAILURE; } - vpImage Iint(480, 640, 255); - vpImage Iext1(480, 640, 255); - vpImage Iext2(480, 640, 255); + vpImage Iint(480, 640, vpRGBa(255)); + vpImage Iext1(480, 640, vpRGBa(255)); + vpImage Iext2(480, 640, vpRGBa(255)); #if defined(VISP_HAVE_X11) vpDisplayX display[3]; diff --git a/example/calibration/calibration-helper.hpp b/example/calibration/calibration-helper.hpp index 4c09ce25ad..9d1ea54e98 100644 --- a/example/calibration/calibration-helper.hpp +++ b/example/calibration/calibration-helper.hpp @@ -144,7 +144,7 @@ struct CalibInfo void drawCalibrationOccupancy(VISP_NAMESPACE_ADDRESSING vpImage &I, const std::vector &calib_info, unsigned int patternW) { - I = 0; + I = 0u; unsigned char pixel_value = static_cast(255.0 / calib_info.size()); for (size_t idx = 0; idx < calib_info.size(); idx++) { const CalibInfo &calib = calib_info[idx]; diff --git a/example/direct-visual-servoing/photometricMappingVisualServoing.cpp b/example/direct-visual-servoing/photometricMappingVisualServoing.cpp index 7e50556f0c..5f1a7cc047 100644 --- a/example/direct-visual-servoing/photometricMappingVisualServoing.cpp +++ b/example/direct-visual-servoing/photometricMappingVisualServoing.cpp @@ -405,7 +405,7 @@ int main(int argc, const char **argv) // set the robot at the desired position sim.setCameraPosition(cMo); - I = 0; + I = 0u; sim.getImage(I, cam); // and aquire the image Id #if defined(VISP_HAVE_GUI) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK)) diff --git a/example/direct-visual-servoing/photometricVisualServoing.cpp b/example/direct-visual-servoing/photometricVisualServoing.cpp index 728aec0a2f..7ad27ed54a 100644 --- a/example/direct-visual-servoing/photometricVisualServoing.cpp +++ b/example/direct-visual-servoing/photometricVisualServoing.cpp @@ -306,7 +306,7 @@ int main(int argc, const char **argv) // set the robot at the desired position sim.setCameraPosition(cMo); - I = 0; + I = 0u; sim.getImage(I, cam); // and aquire the image Id #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK) diff --git a/example/direct-visual-servoing/photometricVisualServoingWithoutVpServo.cpp b/example/direct-visual-servoing/photometricVisualServoingWithoutVpServo.cpp index c0be3a104b..3953b261cb 100644 --- a/example/direct-visual-servoing/photometricVisualServoingWithoutVpServo.cpp +++ b/example/direct-visual-servoing/photometricVisualServoingWithoutVpServo.cpp @@ -307,7 +307,7 @@ int main(int argc, const char **argv) // set the robot at the desired position sim.setCameraPosition(cMo); - I = 0; + I = 0u; sim.getImage(I, cam); // and aquire the image Id #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK) diff --git a/example/manual/geometric-features/manGeometricFeatures.cpp b/example/manual/geometric-features/manGeometricFeatures.cpp index 319f6f9998..605f44786f 100644 --- a/example/manual/geometric-features/manGeometricFeatures.cpp +++ b/example/manual/geometric-features/manGeometricFeatures.cpp @@ -81,7 +81,7 @@ int main() unsigned int height = 288; unsigned int width = 384; vpImage I(height, width); - I = 255; // I is a white image + I = 255u; // I is a white image // create a display window #if defined(VISP_HAVE_X11) diff --git a/example/moments/image/servoMomentImage.cpp b/example/moments/image/servoMomentImage.cpp index 250a738333..258e3a5bdd 100644 --- a/example/moments/image/servoMomentImage.cpp +++ b/example/moments/image/servoMomentImage.cpp @@ -88,9 +88,9 @@ class servoMoment { public: servoMoment() - : m_width(640), m_height(480), m_cMo(), m_cdMo(), m_robot(), m_Iint(m_height, m_width, 0), m_task(), m_cam(), + : m_width(640), m_height(480), m_cMo(), m_cdMo(), m_robot(), m_Iint(m_height, m_width, vpRGBa(0)), m_task(), m_cam(), m_error(0), m_imsim(), m_cur_img(m_height, m_width, 0), m_src_img(m_height, m_width, 0), - m_dst_img(m_height, m_width, 0), m_start_img(m_height, m_width, 0), m_interaction_type(), m_src(6), m_dst(6), + m_dst_img(m_height, m_width, 0), m_start_img(m_height, m_width, vpRGBa(0)), m_interaction_type(), m_src(6), m_dst(6), m_moments(nullptr), m_momentsDes(nullptr), m_featureMoments(nullptr), m_featureMomentsDes(nullptr), m_displayInt(nullptr) { } ~servoMoment() diff --git a/example/moments/points/servoMomentPoints.cpp b/example/moments/points/servoMomentPoints.cpp index 15d9d658b1..b5e9f5b048 100644 --- a/example/moments/points/servoMomentPoints.cpp +++ b/example/moments/points/servoMomentPoints.cpp @@ -86,7 +86,7 @@ class servoMoment { public: servoMoment() - : m_width(640), m_height(480), m_cMo(), m_cdMo(), m_robot(false), m_Iint(m_height, m_width, 255), m_task(), m_cam(), + : m_width(640), m_height(480), m_cMo(), m_cdMo(), m_robot(false), m_Iint(m_height, m_width, vpRGBa(255)), m_task(), m_cam(), m_error(0), m_imsim(), m_interaction_type(), m_src(6), m_dst(6), m_moments(nullptr), m_momentsDes(nullptr), m_featureMoments(nullptr), m_featureMomentsDes(nullptr), m_displayInt(nullptr) { } diff --git a/example/moments/polygon/servoMomentPolygon.cpp b/example/moments/polygon/servoMomentPolygon.cpp index ad2dae20a8..941259b4a4 100644 --- a/example/moments/polygon/servoMomentPolygon.cpp +++ b/example/moments/polygon/servoMomentPolygon.cpp @@ -85,7 +85,7 @@ class servoMoment { public: servoMoment() - : m_width(640), m_height(480), m_cMo(), m_cdMo(), m_robot(false), m_Iint(m_height, m_width, 255), m_task(), m_cam(), + : m_width(640), m_height(480), m_cMo(), m_cdMo(), m_robot(false), m_Iint(m_height, m_width, vpRGBa(255)), m_task(), m_cam(), m_error(0), m_imsim(), m_interaction_type(), m_src(6), m_dst(6), m_moments(nullptr), m_momentsDes(nullptr), m_featureMoments(nullptr), m_featureMomentsDes(nullptr), m_displayInt(nullptr) { } diff --git a/example/servo-pioneer/sonarPioneerReader.cpp b/example/servo-pioneer/sonarPioneerReader.cpp index 8b093c7ed2..aafd43c801 100644 --- a/example/servo-pioneer/sonarPioneerReader.cpp +++ b/example/servo-pioneer/sonarPioneerReader.cpp @@ -240,7 +240,7 @@ int main(int argc, char **argv) // Create a display to show sensor data if (isInitialized == false) { I.resize((unsigned int)half_size * 2, (unsigned int)half_size * 2); - I = 255; + I = 255u; #if defined(VISP_HAVE_X11) d = new vpDisplayX; diff --git a/example/wireframe-simulator/wireframeSimulator.cpp b/example/wireframe-simulator/wireframeSimulator.cpp index 9eb333d71b..99107b65bd 100644 --- a/example/wireframe-simulator/wireframeSimulator.cpp +++ b/example/wireframe-simulator/wireframeSimulator.cpp @@ -164,9 +164,9 @@ int main(int argc, const char **argv) Three vpImage are created : one for the main camera and the others for two external cameras */ - vpImage Iint(480, 640, 255); - vpImage Iext1(480, 640, 255); - vpImage Iext2(480, 640, 255); + vpImage Iint(480, 640, vpRGBa(255)); + vpImage Iext1(480, 640, vpRGBa(255)); + vpImage Iext2(480, 640, vpRGBa(255)); /* Create a display for each different cameras. @@ -360,6 +360,6 @@ int main() std::cout << "Tip if you are on a windows-like system:" << std::endl; std::cout << "- Install GDI, configure again ViSP using cmake and build again this example" << std::endl; return EXIT_SUCCESS; - } +} #endif diff --git a/modules/ar/include/visp3/ar/vpPanda3DCommonFilters.h b/modules/ar/include/visp3/ar/vpPanda3DCommonFilters.h index 5b1e40016f..9b2dafda5a 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DCommonFilters.h +++ b/modules/ar/include/visp3/ar/vpPanda3DCommonFilters.h @@ -49,7 +49,7 @@ class VISP_EXPORT vpPanda3DLuminanceFilter : public vpPanda3DPostProcessFilter { public: vpPanda3DLuminanceFilter(const std::string &name, std::shared_ptr inputRenderer, bool isOutput); - FrameBufferProperties getBufferProperties() const vp_override; + FrameBufferProperties getBufferProperties() const VP_OVERRIDE; void getRender(vpImage &I) const; private: @@ -67,7 +67,7 @@ class VISP_EXPORT vpPanda3DGaussianBlur : public vpPanda3DPostProcessFilter { public: vpPanda3DGaussianBlur(const std::string &name, std::shared_ptr inputRenderer, bool isOutput); - FrameBufferProperties getBufferProperties() const vp_override; + FrameBufferProperties getBufferProperties() const VP_OVERRIDE; void getRender(vpImage &I) const; private: @@ -88,12 +88,12 @@ class VISP_EXPORT vpPanda3DCanny : public vpPanda3DPostProcessFilter { public: vpPanda3DCanny(const std::string &name, std::shared_ptr inputRenderer, bool isOutput, float edgeThreshold); - FrameBufferProperties getBufferProperties() const vp_override; + FrameBufferProperties getBufferProperties() const VP_OVERRIDE; void getRender(vpImage &I) const; void setEdgeThreshold(float edgeThreshold); protected: - void setupScene() vp_override; + void setupScene() VP_OVERRIDE; private: static const char *FRAGMENT_SHADER; diff --git a/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h b/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h index b15e192f8b..e5eff88826 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h +++ b/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h @@ -85,8 +85,8 @@ class VISP_EXPORT vpPanda3DGeometryRenderer : public vpPanda3DBaseRenderer GraphicsOutput *getMainOutputBuffer() vp_override { return m_normalDepthBuffer; } protected: - void setupScene() vp_override; - void setupRenderTarget() vp_override; + void setupScene() VP_OVERRIDE; + void setupRenderTarget() VP_OVERRIDE; private: vpRenderType m_renderType; diff --git a/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h b/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h index 4e13f8c7c5..bac794e6cc 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h +++ b/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h @@ -70,13 +70,13 @@ class VISP_EXPORT vpPanda3DPostProcessFilter : public vpPanda3DBaseRenderer GraphicsOutput *getMainOutputBuffer() vp_override { return m_buffer; } protected: - virtual void setupScene() vp_override; + virtual void setupScene() VP_OVERRIDE; - void setupCamera() vp_override; + void setupCamera() VP_OVERRIDE; - void setupRenderTarget() vp_override; + void setupRenderTarget() VP_OVERRIDE; - void setRenderParameters(const vpPanda3DRenderParameters ¶ms) vp_override; + void setRenderParameters(const vpPanda3DRenderParameters ¶ms) VP_OVERRIDE; void getRenderBasic(vpImage &I) const; void getRenderBasic(vpImage &I) const; diff --git a/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h b/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h index f847bfece6..38d862ca81 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h +++ b/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h @@ -88,7 +88,7 @@ class VISP_EXPORT vpPanda3DRGBRenderer : public vpPanda3DBaseRenderer, public vp */ void getRender(vpImage &I) const; - void addNodeToScene(const NodePath &object) vp_override; + void addNodeToScene(const NodePath &object) VP_OVERRIDE; void setBackgroundImage(const vpImage &background); @@ -98,8 +98,8 @@ class VISP_EXPORT vpPanda3DRGBRenderer : public vpPanda3DBaseRenderer, public vp protected: - void setupScene() vp_override; - void setupRenderTarget() vp_override; + void setupScene() VP_OVERRIDE; + void setupRenderTarget() VP_OVERRIDE; virtual std::string makeFragmentShader(bool hasTexture, bool specular); private: @@ -111,7 +111,7 @@ class VISP_EXPORT vpPanda3DRGBRenderer : public vpPanda3DBaseRenderer, public vp NodePath m_backgroundImage; DisplayRegion *m_display2d; - Texture* m_backgroundTexture; + Texture *m_backgroundTexture; }; diff --git a/modules/ar/include/visp3/ar/vpPanda3DRendererSet.h b/modules/ar/include/visp3/ar/vpPanda3DRendererSet.h index dcade55b77..d0eea9dd2f 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DRendererSet.h +++ b/modules/ar/include/visp3/ar/vpPanda3DRendererSet.h @@ -70,14 +70,14 @@ class VISP_EXPORT vpPanda3DRendererSet : public vpPanda3DBaseRenderer, public vp * The subrenderers will be initialized in the order of their priority as defined by vpPanda3DBaseRenderer::getRenderOrder * Thus, if a renderer B depends on A for its render, and if B.getRenderOrder() > A.getRenderOrder() it can rely on A being initialized when B.initFromParent is called (along with the setupCamera, setupRenderTarget). */ - void initFramework() vp_override; + void initFramework() VP_OVERRIDE; /** * @brief Set the pose of the camera, using the ViSP convention. This change is propagated to all subrenderers * * @param wTc Pose of the camera */ - void setCameraPose(const vpHomogeneousMatrix &wTc) vp_override; + void setCameraPose(const vpHomogeneousMatrix &wTc) VP_OVERRIDE; /** * @brief Retrieve the pose of the camera. As this renderer contains multiple other renderers. @@ -87,7 +87,7 @@ class VISP_EXPORT vpPanda3DRendererSet : public vpPanda3DBaseRenderer, public vp * * @return the pose of the camera using the ViSP convention */ - vpHomogeneousMatrix getCameraPose() vp_override; + vpHomogeneousMatrix getCameraPose() VP_OVERRIDE; /** * @brief Set the pose of an object for all the subrenderers. The pose is specified using the ViSP convention @@ -98,7 +98,7 @@ class VISP_EXPORT vpPanda3DRendererSet : public vpPanda3DBaseRenderer, public vp * @param name * @param wTo */ - void setNodePose(const std::string &name, const vpHomogeneousMatrix &wTo) vp_override; + void setNodePose(const std::string &name, const vpHomogeneousMatrix &wTo) VP_OVERRIDE; /** * @brief This method is not supported for this renderer type. Use the std::string version @@ -107,7 +107,7 @@ class VISP_EXPORT vpPanda3DRendererSet : public vpPanda3DBaseRenderer, public vp * @param object * @param wTo */ - void setNodePose(NodePath &object, const vpHomogeneousMatrix &wTo) vp_override; + void setNodePose(NodePath &object, const vpHomogeneousMatrix &wTo) VP_OVERRIDE; /** * @brief Retrieve the pose of a scene node. The pose is in the world frame, using a ViSP convention. @@ -119,7 +119,7 @@ class VISP_EXPORT vpPanda3DRendererSet : public vpPanda3DBaseRenderer, public vp * @param name name of the node * @return vpHomogeneousMatrix the pose of the node in the world frame */ - vpHomogeneousMatrix getNodePose(const std::string &name) vp_override; + vpHomogeneousMatrix getNodePose(const std::string &name) VP_OVERRIDE; /** * @brief This method is not supported for this renderer type. Use the std::string version @@ -127,16 +127,16 @@ class VISP_EXPORT vpPanda3DRendererSet : public vpPanda3DBaseRenderer, public vp * \throws vpException, as this method is not supported * @param object */ - vpHomogeneousMatrix getNodePose(NodePath &object) vp_override; + vpHomogeneousMatrix getNodePose(NodePath &object) VP_OVERRIDE; /** * \warning This method is not supported and will throw */ - void addNodeToScene(const NodePath &object) vp_override; + void addNodeToScene(const NodePath &object) VP_OVERRIDE; - void setRenderParameters(const vpPanda3DRenderParameters ¶ms) vp_override; + void setRenderParameters(const vpPanda3DRenderParameters ¶ms) VP_OVERRIDE; - void addLight(const vpPanda3DLight &light) vp_override; + void addLight(const vpPanda3DLight &light) VP_OVERRIDE; /** * @brief Add a new subrenderer: This subrenderer should have a unique name, not present in the set. diff --git a/modules/ar/include/visp3/ar/vpSimulatorException.h b/modules/ar/include/visp3/ar/vpSimulatorException.h index e2a545222b..1f7b52d272 100644 --- a/modules/ar/include/visp3/ar/vpSimulatorException.h +++ b/modules/ar/include/visp3/ar/vpSimulatorException.h @@ -81,7 +81,7 @@ class VISP_EXPORT vpSimulatorException : public vpException /*! * Constructor. */ - explicit vpSimulatorException(int id); + VP_EXPLICIT vpSimulatorException(int id); }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpArray2D.h b/modules/core/include/visp3/core/vpArray2D.h index 6e5b62b950..f97defc41c 100644 --- a/modules/core/include/visp3/core/vpArray2D.h +++ b/modules/core/include/visp3/core/vpArray2D.h @@ -254,13 +254,13 @@ template class vpArray2D A.data = nullptr; } - explicit vpArray2D(const std::initializer_list &list) : vpArray2D() + VP_EXPLICIT vpArray2D(const std::initializer_list &list) : vpArray2D() { resize(1, static_cast(list.size()), false, false); std::copy(list.begin(), list.end(), data); } - explicit vpArray2D(unsigned int nrows, unsigned int ncols, const std::initializer_list &list) + VP_EXPLICIT vpArray2D(unsigned int nrows, unsigned int ncols, const std::initializer_list &list) : data(nullptr), rowNum(0), colNum(0), rowPtrs(nullptr), dsize(0) { if ((nrows * ncols) != static_cast(list.size())) { @@ -273,7 +273,7 @@ template class vpArray2D std::copy(list.begin(), list.end(), data); } - explicit vpArray2D(const std::initializer_list > &lists) : vpArray2D() + VP_EXPLICIT vpArray2D(const std::initializer_list > &lists) : vpArray2D() { unsigned int nrows = static_cast(lists.size()), ncols = 0; for (auto &l : lists) { diff --git a/modules/core/include/visp3/core/vpCircle.h b/modules/core/include/visp3/core/vpCircle.h index d7c6428344..ed2ac60ef0 100644 --- a/modules/core/include/visp3/core/vpCircle.h +++ b/modules/core/include/visp3/core/vpCircle.h @@ -87,23 +87,23 @@ class VISP_EXPORT vpCircle : public vpForwardProjection { public: vpCircle(); - explicit vpCircle(const vpColVector &oP); + VP_EXPLICIT vpCircle(const vpColVector &oP); vpCircle(double oA, double oB, double oC, double oX, double oY, double oZ, double R); - virtual ~vpCircle() vp_override; - void changeFrame(const vpHomogeneousMatrix &noMo, vpColVector &noP) const vp_override; - void changeFrame(const vpHomogeneousMatrix &cMo) vp_override; + virtual ~vpCircle() VP_OVERRIDE; + void changeFrame(const vpHomogeneousMatrix &noMo, vpColVector &noP) const VP_OVERRIDE; + void changeFrame(const vpHomogeneousMatrix &cMo) VP_OVERRIDE; void display(const vpImage &I, const vpCameraParameters &cam, const vpColor &color = vpColor::green, - unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &color = vpColor::green, unsigned int thickness = 1) vp_override; + const vpColor &color = vpColor::green, unsigned int thickness = 1) VP_OVERRIDE; void display(const vpImage &I, const vpCameraParameters &cam, const vpColor &color = vpColor::green, unsigned int thickness = 1); void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color = vpColor::green, unsigned int thickness = 1); - vpCircle *duplicate() const vp_override; + vpCircle *duplicate() const VP_OVERRIDE; double get_x() const { return p[0]; } double get_y() const { return p[1]; } @@ -122,9 +122,9 @@ class VISP_EXPORT vpCircle : public vpForwardProjection double getR() const { const unsigned int index_6 = 6; return cP[index_6]; } - void projection() vp_override; - void projection(const vpColVector &cP, vpColVector &p) const vp_override; - void setWorldCoordinates(const vpColVector &oP) vp_override; + void projection() VP_OVERRIDE; + void projection(const vpColVector &cP, vpColVector &p) const VP_OVERRIDE; + void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE; void setWorldCoordinates(double oA, double oB, double oC, double oX, double oY, double oZ, double R); @@ -146,25 +146,25 @@ class VISP_EXPORT vpCircle : public vpForwardProjection * returns second order centered moments of the ellipse normalized * by its area that corresponds to \f$n_20 = mu_20/a\f$. */ - vp_deprecated double get_mu20() const { const unsigned int index_2 = 2; return p[index_2]; } + VP_DEPRECATED double get_mu20() const { const unsigned int index_2 = 2; return p[index_2]; } /*! * \deprecated You should rather use get_n11(). * This function is incorrectly named and is confusing since it * returns second order centered moments of the ellipse normalized * by its area that corresponds to \f$n_11 = mu@name Deprecated functions_11/a\f$. */ - vp_deprecated double get_mu11() const { const unsigned int index_3 = 3; return p[index_3]; } + VP_DEPRECATED double get_mu11() const { const unsigned int index_3 = 3; return p[index_3]; } /*! * \deprecated You should rather use get_n02(). * This function is incorrectly named and is confusing since it * returns second order centered moments of the ellipse normalized * by its area that corresponds to \f$n_02 = mu_02/a\f$. */ - vp_deprecated double get_mu02() const { const unsigned int index_4 = 4; return p[index_4]; } + VP_DEPRECATED double get_mu02() const { const unsigned int index_4 = 4; return p[index_4]; } //@} #endif protected: - void init() vp_override; + void init() VP_OVERRIDE; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpClient.h b/modules/core/include/visp3/core/vpClient.h index a74eee5789..75a2e0727c 100644 --- a/modules/core/include/visp3/core/vpClient.h +++ b/modules/core/include/visp3/core/vpClient.h @@ -169,7 +169,7 @@ class VISP_EXPORT vpClient : public vpNetwork public: vpClient(); - virtual ~vpClient() vp_override; + virtual ~vpClient() VP_OVERRIDE; bool connectToHostname(const std::string &hostname, const unsigned int &port_serv); bool connectToIP(const std::string &ip, const unsigned int &port_serv); diff --git a/modules/core/include/visp3/core/vpColVector.h b/modules/core/include/visp3/core/vpColVector.h index 8875575573..40fb48d844 100644 --- a/modules/core/include/visp3/core/vpColVector.h +++ b/modules/core/include/visp3/core/vpColVector.h @@ -182,7 +182,7 @@ class VISP_EXPORT vpColVector : public vpArray2D * \warning Elements are not initialized. If you want to set an initial value use * vpColVector(unsigned int, double). */ - explicit vpColVector(unsigned int n) : vpArray2D(n, 1) { } + VP_EXPLICIT vpColVector(unsigned int n) : vpArray2D(n, 1) { } /*! * Construct a column vector of size n. Each element is set to \e val. @@ -214,17 +214,17 @@ class VISP_EXPORT vpColVector : public vpArray2D * Constructor that initialize a column vector from a 3-dim (Euler or * \f$\theta {\bf u}\f$) or 4-dim (quaternion) rotation vector. */ - explicit vpColVector(const vpRotationVector &v); + VP_EXPLICIT vpColVector(const vpRotationVector &v); /*! * Constructor that initialize a column vector from a 6-dim pose vector. */ - explicit vpColVector(const vpPoseVector &p); + VP_EXPLICIT vpColVector(const vpPoseVector &p); /*! * Constructor that initialize a column vector from a 3-dim translation vector. */ - explicit vpColVector(const vpTranslationVector &t); + VP_EXPLICIT vpColVector(const vpTranslationVector &t); /*! * Constructor that creates a column vector from a m-by-1 matrix `M`. @@ -232,7 +232,7 @@ class VISP_EXPORT vpColVector : public vpArray2D * \exception vpException::dimensionError If the matrix is not a m-by-1 * matrix. */ - explicit vpColVector(const vpMatrix &M); + VP_EXPLICIT vpColVector(const vpMatrix &M); /*! * Constructor that takes column `j` of matrix `M`. @@ -242,12 +242,12 @@ class VISP_EXPORT vpColVector : public vpArray2D /*! * Constructor that creates a column vector from a std vector of double. */ - explicit vpColVector(const std::vector &v); + VP_EXPLICIT vpColVector(const std::vector &v); /*! * Constructor that creates a column vector from a std vector of float. */ - explicit vpColVector(const std::vector &v); + VP_EXPLICIT vpColVector(const std::vector &v); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) /*! @@ -727,6 +727,15 @@ class VISP_EXPORT vpColVector : public vpArray2D */ vpMatrix operator*(const vpRowVector &v) const; + /*! + * Multiply a column vector by a matrix. + * + * \param M : Matrix. + * + * \return The resulting matrix. + */ + vpMatrix operator*(const vpMatrix &M) const; + /*! * Operator that allows to multiply each element of a column vector by a * scalar. @@ -1362,7 +1371,7 @@ class VISP_EXPORT vpColVector : public vpArray2D * \deprecated Provided only for compat with previous releases. * This function does nothing. */ - vp_deprecated void init() { } + VP_DEPRECATED void init() { } /*! * \deprecated Provided only for compat with previous releases. Use rather @@ -1399,12 +1408,12 @@ class VISP_EXPORT vpColVector : public vpArray2D * v: 0 10 11 3 * \endcode */ - vp_deprecated void insert(const vpColVector &v, unsigned int i); + VP_DEPRECATED void insert(const vpColVector &v, unsigned int i); /*! * \deprecated You should rather use extract(). */ - vp_deprecated vpColVector rows(unsigned int first_row, unsigned int last_row) const + VP_DEPRECATED vpColVector rows(unsigned int first_row, unsigned int last_row) const { return vpColVector(*this, first_row - 1, last_row - first_row + 1); } @@ -1412,17 +1421,17 @@ class VISP_EXPORT vpColVector : public vpArray2D /*! * \deprecated You should rather use stack(const vpColVector &) */ - vp_deprecated void stackMatrices(const vpColVector &r) { stack(r); } + VP_DEPRECATED void stackMatrices(const vpColVector &r) { stack(r); } /*! * \deprecated You should rather use stack(const vpColVector &A, const vpColVector &B) */ - vp_deprecated static vpColVector stackMatrices(const vpColVector &A, const vpColVector &B) { return stack(A, B); } + VP_DEPRECATED static vpColVector stackMatrices(const vpColVector &A, const vpColVector &B) { return stack(A, B); } /*! * \deprecated You should rather use stack(const vpColVector &A, const vpColVector &B, vpColVector &C) */ - vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C) + VP_DEPRECATED static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C) { stack(A, B, C); } @@ -1440,7 +1449,7 @@ class VISP_EXPORT vpColVector : public vpArray2D * \param r : The index of the row to begin to insert data. * \param c : Not used. */ - vp_deprecated void insert(const vpColVector &v, unsigned int r, unsigned int c = 0); + VP_DEPRECATED void insert(const vpColVector &v, unsigned int r, unsigned int c = 0); /*! * \deprecated This function is deprecated. You should rather use frobeniusNorm(). @@ -1451,7 +1460,7 @@ class VISP_EXPORT vpColVector : public vpArray2D * * \sa frobeniusNorm(), infinityNorm() */ - vp_deprecated double euclideanNorm() const; + VP_DEPRECATED double euclideanNorm() const; //@} #endif }; diff --git a/modules/core/include/visp3/core/vpCylinder.h b/modules/core/include/visp3/core/vpCylinder.h index b533955bae..5c8e777d11 100644 --- a/modules/core/include/visp3/core/vpCylinder.h +++ b/modules/core/include/visp3/core/vpCylinder.h @@ -107,24 +107,24 @@ class VISP_EXPORT vpCylinder : public vpForwardProjection } vpLineCylinderType; vpCylinder(); - explicit vpCylinder(const vpColVector &oP); + VP_EXPLICIT vpCylinder(const vpColVector &oP); vpCylinder(double oA, double oB, double oC, double oX, double oY, double oZ, double R); - void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const vp_override; - void changeFrame(const vpHomogeneousMatrix &cMo) vp_override; + void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const VP_OVERRIDE; + void changeFrame(const vpHomogeneousMatrix &cMo) VP_OVERRIDE; double computeZ(double x, double y) const; void display(const vpImage &I, const vpCameraParameters &cam, const vpColor &color = vpColor::green, - unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; void display(const vpImage &I, const vpCameraParameters &cam, const vpColor &color = vpColor::green, unsigned int thickness = 1); void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &color = vpColor::green, unsigned int thickness = 1) vp_override; + const vpColor &color = vpColor::green, unsigned int thickness = 1) VP_OVERRIDE; void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color = vpColor::green, unsigned int thickness = 1); - vpCylinder *duplicate() const vp_override; + vpCylinder *duplicate() const VP_OVERRIDE; /*! * Return the \f$\rho_1\f$ parameter of the line corresponding to the @@ -187,12 +187,12 @@ class VISP_EXPORT vpCylinder : public vpForwardProjection */ double getR() const { return cP[6]; } - void init() vp_override; + void init() VP_OVERRIDE; - void projection() vp_override; - void projection(const vpColVector &cP, vpColVector &p) const vp_override; + void projection() VP_OVERRIDE; + void projection(const vpColVector &cP, vpColVector &p) const VP_OVERRIDE; - void setWorldCoordinates(const vpColVector &oP) vp_override; + void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE; void setWorldCoordinates(double oA, double oB, double oC, double oX, double oY, double oZ, double R); }; END_VISP_NAMESPACE diff --git a/modules/core/include/visp3/core/vpDisplay.h b/modules/core/include/visp3/core/vpDisplay.h index 6e1ca8060e..93af8de649 100644 --- a/modules/core/include/visp3/core/vpDisplay.h +++ b/modules/core/include/visp3/core/vpDisplay.h @@ -900,13 +900,13 @@ class VISP_EXPORT vpDisplay * @name Deprecated functions */ //@{ - vp_deprecated static void displayCharString(const vpImage &I, const vpImagePoint &ip, const char *string, + VP_DEPRECATED static void displayCharString(const vpImage &I, const vpImagePoint &ip, const char *string, const vpColor &color); - vp_deprecated static void displayCharString(const vpImage &I, int i, int j, const char *string, + VP_DEPRECATED static void displayCharString(const vpImage &I, int i, int j, const char *string, const vpColor &color); - vp_deprecated static void displayCharString(const vpImage &I, const vpImagePoint &ip, const char *string, + VP_DEPRECATED static void displayCharString(const vpImage &I, const vpImagePoint &ip, const char *string, const vpColor &color); - vp_deprecated static void displayCharString(const vpImage &I, int i, int j, const char *string, + VP_DEPRECATED static void displayCharString(const vpImage &I, int i, int j, const char *string, const vpColor &color); //@} #endif diff --git a/modules/core/include/visp3/core/vpDisplayException.h b/modules/core/include/visp3/core/vpDisplayException.h index c034be99a6..4aed6b8cdc 100644 --- a/modules/core/include/visp3/core/vpDisplayException.h +++ b/modules/core/include/visp3/core/vpDisplayException.h @@ -89,7 +89,7 @@ class VISP_EXPORT vpDisplayException : public vpException /*! * Constructor. */ - explicit vpDisplayException(int id) : vpException(id) { } + VP_EXPLICIT vpDisplayException(int id) : vpException(id) { } }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpEigenConversion.h b/modules/core/include/visp3/core/vpEigenConversion.h index f64dc349be..16bce7a59c 100644 --- a/modules/core/include/visp3/core/vpEigenConversion.h +++ b/modules/core/include/visp3/core/vpEigenConversion.h @@ -44,38 +44,43 @@ namespace VISP_NAMESPACE_NAME { #ifdef VISP_HAVE_EIGEN3 /* Eigen to ViSP */ -VISP_EXPORT void eigen2visp(const Eigen::MatrixXd &src, VISP_NAMESPACE_ADDRESSING vpMatrix &dst); +VISP_EXPORT void eigen2visp(const Eigen::MatrixXd &src, vpMatrix &dst); -VISP_EXPORT void eigen2visp(const Eigen::MatrixXd &src, VISP_NAMESPACE_ADDRESSING vpHomogeneousMatrix &dst); +VISP_EXPORT void eigen2visp(const Eigen::MatrixXd &src, vpHomogeneousMatrix &dst); -template void eigen2visp(const Eigen::Quaternion &src, VISP_NAMESPACE_ADDRESSING vpQuaternionVector &dst) +template +void eigen2visp(const Eigen::Quaternion &src, vpQuaternionVector &dst) { dst.build(src.x(), src.y(), src.z(), src.w()); } -template void eigen2visp(const Eigen::AngleAxis &src, VISP_NAMESPACE_ADDRESSING vpThetaUVector &dst) +template +void eigen2visp(const Eigen::AngleAxis &src, vpThetaUVector &dst) { dst.build(src.angle() * src.axis()(0), src.angle() * src.axis()(1), src.angle() * src.axis()(2)); } -VISP_EXPORT void eigen2visp(const Eigen::VectorXd &src, VISP_NAMESPACE_ADDRESSING vpColVector &dst); +VISP_EXPORT void eigen2visp(const Eigen::VectorXd &src, vpColVector &dst); -VISP_EXPORT void eigen2visp(const Eigen::RowVectorXd &src, VISP_NAMESPACE_ADDRESSING vpRowVector &dst); +VISP_EXPORT void eigen2visp(const Eigen::RowVectorXd &src, vpRowVector &dst); /* ViSP to Eigen */ -template void visp2eigen(const VISP_NAMESPACE_ADDRESSING vpMatrix &src, Eigen::MatrixBase &dst) +template +void visp2eigen(const vpMatrix &src, Eigen::MatrixBase &dst) { dst = Eigen::Map >(src.data, src.getRows(), src.getCols()); } -template void visp2eigen(const VISP_NAMESPACE_ADDRESSING vpHomogeneousMatrix &src, Eigen::MatrixBase &dst) +template +void visp2eigen(const vpHomogeneousMatrix &src, Eigen::MatrixBase &dst) { dst = Eigen::Map >(src.data, src.getRows(), src.getCols()); } -template void visp2eigen(const VISP_NAMESPACE_ADDRESSING vpQuaternionVector &src, Eigen::Quaternion &dst) +template +void visp2eigen(const vpQuaternionVector &src, Eigen::Quaternion &dst) { dst.w() = static_cast(src.w()); dst.x() = static_cast(src.x()); @@ -83,7 +88,8 @@ template void visp2eigen(const VISP_NAMESPACE_ADDRESSING vpQuate dst.z() = static_cast(src.z()); } -template void visp2eigen(const VISP_NAMESPACE_ADDRESSING vpThetaUVector &src, Eigen::AngleAxis &dst) +template +void visp2eigen(const vpThetaUVector &src, Eigen::AngleAxis &dst) { const unsigned int index_0 = 0; const unsigned int index_1 = 1; @@ -94,9 +100,9 @@ template void visp2eigen(const VISP_NAMESPACE_ADDRESSING vpTheta dst.axis()(index_2) = static_cast(src.getU()[index_2]); } -VISP_EXPORT void visp2eigen(const VISP_NAMESPACE_ADDRESSING vpColVector &src, Eigen::VectorXd &dst); +VISP_EXPORT void visp2eigen(const vpColVector &src, Eigen::VectorXd &dst); -VISP_EXPORT void visp2eigen(const VISP_NAMESPACE_ADDRESSING vpRowVector &src, Eigen::RowVectorXd &dst); +VISP_EXPORT void visp2eigen(const vpRowVector &src, Eigen::RowVectorXd &dst); #endif } // namespace VISP_NAMESPACE_NAME #endif diff --git a/modules/core/include/visp3/core/vpException.h b/modules/core/include/visp3/core/vpException.h index c669c12bfe..03f66c3827 100644 --- a/modules/core/include/visp3/core/vpException.h +++ b/modules/core/include/visp3/core/vpException.h @@ -98,7 +98,7 @@ class VISP_EXPORT vpException : public std::exception /*! * Constructor. */ - explicit vpException(int code); + VP_EXPLICIT vpException(int code); /** @name Inherited functionalities from vpException */ //@{ diff --git a/modules/core/include/visp3/core/vpForceTwistMatrix.h b/modules/core/include/visp3/core/vpForceTwistMatrix.h index 0b00589001..cad70a35d4 100644 --- a/modules/core/include/visp3/core/vpForceTwistMatrix.h +++ b/modules/core/include/visp3/core/vpForceTwistMatrix.h @@ -174,7 +174,7 @@ class VISP_EXPORT vpForceTwistMatrix : public vpArray2D // copy constructor vpForceTwistMatrix(const vpForceTwistMatrix &F); // constructor from an homogeneous transformation - explicit vpForceTwistMatrix(const vpHomogeneousMatrix &M, bool full = true); + VP_EXPLICIT vpForceTwistMatrix(const vpHomogeneousMatrix &M, bool full = true); // Construction from Translation and rotation (matrix parameterization) vpForceTwistMatrix(const vpTranslationVector &t, const vpRotationMatrix &R); @@ -182,16 +182,16 @@ class VISP_EXPORT vpForceTwistMatrix : public vpArray2D vpForceTwistMatrix(const vpTranslationVector &t, const vpThetaUVector &thetau); vpForceTwistMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz); - explicit vpForceTwistMatrix(const vpRotationMatrix &R); - explicit vpForceTwistMatrix(const vpThetaUVector &thetau); + VP_EXPLICIT vpForceTwistMatrix(const vpRotationMatrix &R); + VP_EXPLICIT vpForceTwistMatrix(const vpThetaUVector &thetau); #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) - vp_deprecated vpForceTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R); - vp_deprecated vpForceTwistMatrix buildFrom(const vpTranslationVector &t, const vpThetaUVector &thetau); - vp_deprecated vpForceTwistMatrix buildFrom(const vpHomogeneousMatrix &M, bool full = true); + VP_DEPRECATED vpForceTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R); + VP_DEPRECATED vpForceTwistMatrix buildFrom(const vpTranslationVector &t, const vpThetaUVector &thetau); + VP_DEPRECATED vpForceTwistMatrix buildFrom(const vpHomogeneousMatrix &M, bool full = true); - vp_deprecated vpForceTwistMatrix buildFrom(const vpRotationMatrix &R); - vp_deprecated vpForceTwistMatrix buildFrom(const vpThetaUVector &thetau); + VP_DEPRECATED vpForceTwistMatrix buildFrom(const vpRotationMatrix &R); + VP_DEPRECATED vpForceTwistMatrix buildFrom(const vpThetaUVector &thetau); #endif vpForceTwistMatrix &build(const vpTranslationVector &t, const vpRotationMatrix &R); vpForceTwistMatrix &build(const vpTranslationVector &t, const vpThetaUVector &thetau); @@ -235,11 +235,11 @@ class VISP_EXPORT vpForceTwistMatrix : public vpArray2D \deprecated Provided only for compat with previous releases. This function does nothing. */ - vp_deprecated void init() { } + VP_DEPRECATED void init() { } /*! \deprecated You should rather use eye(). */ - vp_deprecated void setIdentity(); + VP_DEPRECATED void setIdentity(); //@} #endif }; diff --git a/modules/core/include/visp3/core/vpFrameGrabberException.h b/modules/core/include/visp3/core/vpFrameGrabberException.h index 30a244fd57..f1b0ca8885 100644 --- a/modules/core/include/visp3/core/vpFrameGrabberException.h +++ b/modules/core/include/visp3/core/vpFrameGrabberException.h @@ -86,7 +86,7 @@ class VISP_EXPORT vpFrameGrabberException : public vpException /*! * Constructor. */ - explicit vpFrameGrabberException(int id) : vpException(id) { } + VP_EXPLICIT vpFrameGrabberException(int id) : vpException(id) { } }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpHinkley.h b/modules/core/include/visp3/core/vpHinkley.h index 8cd60dd173..bc38133983 100644 --- a/modules/core/include/visp3/core/vpHinkley.h +++ b/modules/core/include/visp3/core/vpHinkley.h @@ -107,9 +107,9 @@ class VISP_EXPORT vpHinkley } vpHinkleyJumpType; public: - vp_deprecated vpHinkley(); + VP_DEPRECATED vpHinkley(); virtual ~vpHinkley(); - vp_deprecated vpHinkley(double alpha, double delta); + VP_DEPRECATED vpHinkley(double alpha, double delta); void init(); void init(double alpha, double delta); diff --git a/modules/core/include/visp3/core/vpHistogram.h b/modules/core/include/visp3/core/vpHistogram.h index 971bd6ce45..df4aeb99ae 100644 --- a/modules/core/include/visp3/core/vpHistogram.h +++ b/modules/core/include/visp3/core/vpHistogram.h @@ -107,8 +107,8 @@ class VISP_EXPORT vpHistogram public: vpHistogram(); vpHistogram(const vpHistogram &h); - explicit vpHistogram(const vpImage &I); - explicit vpHistogram(const vpImage &I, const vpImage *p_mask); + VP_EXPLICIT vpHistogram(const vpImage &I); + VP_EXPLICIT vpHistogram(const vpImage &I, const vpImage *p_mask); virtual ~vpHistogram(); vpHistogram &operator=(const vpHistogram &h); diff --git a/modules/core/include/visp3/core/vpHomogeneousMatrix.h b/modules/core/include/visp3/core/vpHomogeneousMatrix.h index d1a6a4248b..80e05177d6 100644 --- a/modules/core/include/visp3/core/vpHomogeneousMatrix.h +++ b/modules/core/include/visp3/core/vpHomogeneousMatrix.h @@ -209,22 +209,22 @@ class VISP_EXPORT vpHomogeneousMatrix : public vpArray2D vpHomogeneousMatrix(const vpTranslationVector &t, const vpRotationMatrix &R); vpHomogeneousMatrix(const vpTranslationVector &t, const vpThetaUVector &tu); vpHomogeneousMatrix(const vpTranslationVector &t, const vpQuaternionVector &q); - explicit vpHomogeneousMatrix(const vpPoseVector &p); - explicit vpHomogeneousMatrix(const std::vector &v); - explicit vpHomogeneousMatrix(const std::vector &v); + VP_EXPLICIT vpHomogeneousMatrix(const vpPoseVector &p); + VP_EXPLICIT vpHomogeneousMatrix(const std::vector &v); + VP_EXPLICIT vpHomogeneousMatrix(const std::vector &v); vpHomogeneousMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) - explicit vpHomogeneousMatrix(const std::initializer_list &list); + VP_EXPLICIT vpHomogeneousMatrix(const std::initializer_list &list); #endif #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS - vp_deprecated void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R); - vp_deprecated void buildFrom(const vpTranslationVector &t, const vpThetaUVector &tu); - vp_deprecated void buildFrom(const vpTranslationVector &t, const vpQuaternionVector &q); - vp_deprecated void buildFrom(const vpPoseVector &p); - vp_deprecated void buildFrom(const std::vector &v); - vp_deprecated void buildFrom(const std::vector &v); - vp_deprecated void buildFrom(double tx, double ty, double tz, double tux, double tuy, double tuz); + VP_DEPRECATED void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R); + VP_DEPRECATED void buildFrom(const vpTranslationVector &t, const vpThetaUVector &tu); + VP_DEPRECATED void buildFrom(const vpTranslationVector &t, const vpQuaternionVector &q); + VP_DEPRECATED void buildFrom(const vpPoseVector &p); + VP_DEPRECATED void buildFrom(const std::vector &v); + VP_DEPRECATED void buildFrom(const std::vector &v); + VP_DEPRECATED void buildFrom(double tx, double ty, double tz, double tux, double tuy, double tuz); #endif vpHomogeneousMatrix &build(const vpTranslationVector &t, const vpRotationMatrix &R); vpHomogeneousMatrix &build(const vpTranslationVector &t, const vpThetaUVector &tu); @@ -403,11 +403,11 @@ class VISP_EXPORT vpHomogeneousMatrix : public vpArray2D * \deprecated Provided only for compat with previous releases. * This function does nothing. */ - vp_deprecated void init() { } + VP_DEPRECATED void init() { } /*! * \deprecated You should rather use eye(). */ - vp_deprecated void setIdentity(); + VP_DEPRECATED void setIdentity(); //@} #endif diff --git a/modules/core/include/visp3/core/vpImage.h b/modules/core/include/visp3/core/vpImage.h index 313740cafa..814599e759 100644 --- a/modules/core/include/visp3/core/vpImage.h +++ b/modules/core/include/visp3/core/vpImage.h @@ -169,6 +169,7 @@ template class vpImage \sa getWidth() */ inline unsigned int getCols() const { return width; } + /*! Get the image height. @@ -245,9 +246,9 @@ template class vpImage //! Set the size of the image void init(unsigned int height, unsigned int width); - //! Set the size of the image + //! Set the size of the image and initialize all the elements to 'value' void init(unsigned int height, unsigned int width, Type value); - //! init from an image stored as a continuous array in memory + //! Initialization from an image stored as a continuous array in memory void init(Type *const array, unsigned int height, unsigned int width, bool copyData = false); void insert(const vpImage &src, const vpImagePoint &topLeft); @@ -371,10 +372,6 @@ template class vpImage template void vpImage::init(unsigned int h, unsigned int w, Type value) { init(h, w); - /* - // for (unsigned int i = 0; i < npixels; ++i) - // bitmap[i] = value; - */ std::fill(bitmap, bitmap + npixels, value); } @@ -487,7 +484,8 @@ template vpImage::vpImage(unsigned int h, unsigned int w) : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true) { - init(h, w, 0); + Type val(0); + init(h, w, val); } /*! diff --git a/modules/core/include/visp3/core/vpImageException.h b/modules/core/include/visp3/core/vpImageException.h index d2d9dc1824..8fa26bde75 100644 --- a/modules/core/include/visp3/core/vpImageException.h +++ b/modules/core/include/visp3/core/vpImageException.h @@ -88,7 +88,7 @@ class VISP_EXPORT vpImageException : public vpException /*! * Constructor. */ - explicit vpImageException(int id) : vpException(id) { } + VP_EXPLICIT vpImageException(int id) : vpException(id) { } }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpImageMorphology.h b/modules/core/include/visp3/core/vpImageMorphology.h index 25341c0569..dab0ee754b 100644 --- a/modules/core/include/visp3/core/vpImageMorphology.h +++ b/modules/core/include/visp3/core/vpImageMorphology.h @@ -112,7 +112,7 @@ class VISP_EXPORT vpImageMorphology \param I : Gray-scale image to process. \param connexity : Type of connexity: 4 or 8. */ - vp_deprecated static void erosion(vpImage &I, const vpConnexityType &connexity = CONNEXITY_4) + VP_DEPRECATED static void erosion(vpImage &I, const vpConnexityType &connexity = CONNEXITY_4) { vpImageMorphology::erosion(I, connexity); } @@ -129,7 +129,7 @@ class VISP_EXPORT vpImageMorphology \param I : Gray-scale image to process. \param connexity : Type of connexity: 4 or 8. */ - vp_deprecated static void dilatation(vpImage &I, const vpConnexityType &connexity = CONNEXITY_4) + VP_DEPRECATED static void dilatation(vpImage &I, const vpConnexityType &connexity = CONNEXITY_4) { vpImageMorphology::dilatation(I, connexity); } @@ -431,7 +431,7 @@ void vpImageMorphology::dilatation(vpImage &I, const vpConnexityType &connexi template void vpImageMorphology::imageOperation(vpImage &I, const T &(*operation)(const T &, const T &), const int &size) { - if (size % 2 != 1) { + if ((size % 2) != 1) { throw(vpException(vpException::badValue, "Dilatation/erosion kernel must be odd.")); } diff --git a/modules/core/include/visp3/core/vpImagePoint.h b/modules/core/include/visp3/core/vpImagePoint.h index bcee40ca41..d9e3c8e58d 100644 --- a/modules/core/include/visp3/core/vpImagePoint.h +++ b/modules/core/include/visp3/core/vpImagePoint.h @@ -221,7 +221,7 @@ class VISP_EXPORT vpImagePoint #if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher return { end.get_i() - (line_slope * (end.get_j() - j_)), j_ }; #else - return vpImagePoint(end.get_i() - line_slope * (end.get_j() - j_), j_); + return vpImagePoint(end.get_i() - (line_slope * (end.get_j() - j_)), j_); #endif } else { diff --git a/modules/core/include/visp3/core/vpImageTools.h b/modules/core/include/visp3/core/vpImageTools.h index d3ce6aecf8..e4a2ee02f3 100644 --- a/modules/core/include/visp3/core/vpImageTools.h +++ b/modules/core/include/visp3/core/vpImageTools.h @@ -183,11 +183,11 @@ class VISP_EXPORT vpImageTools */ //@{ template - vp_deprecated static void createSubImage(const vpImage &I, unsigned int i_sub, unsigned int j_sub, + VP_DEPRECATED static void createSubImage(const vpImage &I, unsigned int i_sub, unsigned int j_sub, unsigned int nrow_sub, unsigned int ncol_sub, vpImage &S); template - vp_deprecated static void createSubImage(const vpImage &I, const vpRect &rect, vpImage &S); + VP_DEPRECATED static void createSubImage(const vpImage &I, const vpRect &rect, vpImage &S); //@} #endif @@ -435,23 +435,23 @@ void vpImageTools::crop(const unsigned char *bitmap, unsigned int width, unsigne if (v_scale == 1 && h_scale == 1) { for (unsigned int i = 0; i < r_height; ++i) { - void *src = (void *)(bitmap + ((i + i_min_u) * width + j_min_u) * sizeof(Type)); + void *src = (void *)(bitmap + ((((i + i_min_u) * width) + j_min_u) * sizeof(Type))); void *dst = (void *)(crop[i]); memcpy(dst, src, r_width * sizeof(Type)); } } else if (h_scale == 1) { for (unsigned int i = 0; i < r_height; ++i) { - void *src = (void *)(bitmap + ((i + i_min_u) * width * v_scale + j_min_u) * sizeof(Type)); + void *src = (void *)(bitmap + (((((i + i_min_u) * width) * v_scale) + j_min_u) * sizeof(Type))); void *dst = (void *)(crop[i]); memcpy(dst, src, r_width * sizeof(Type)); } } else { for (unsigned int i = 0; i < r_height; ++i) { - unsigned int i_src = (i + i_min_u) * width * v_scale + j_min_u * h_scale; + unsigned int i_src = (((i + i_min_u) * width) * v_scale) + (j_min_u * h_scale); for (unsigned int j = 0; j < r_width; ++j) { - void *src = (void *)(bitmap + (i_src + j * h_scale) * sizeof(Type)); + void *src = (void *)(bitmap + ((i_src + (j * h_scale)) * sizeof(Type))); void *dst = (void *)(&crop[i][j]); memcpy(dst, src, sizeof(Type)); } diff --git a/modules/core/include/visp3/core/vpImageTools_warp.h b/modules/core/include/visp3/core/vpImageTools_warp.h index af7c152d30..7b314c6fff 100644 --- a/modules/core/include/visp3/core/vpImageTools_warp.h +++ b/modules/core/include/visp3/core/vpImageTools_warp.h @@ -209,9 +209,9 @@ void vpImageTools::warpNN(const vpImage &src, const vpMatrix &T, vpImage::epsilon())) { w = 1.0; @@ -281,22 +281,22 @@ void vpImageTools::warpLinear(const vpImage &src, const vpMatrix &T, vpIma const Type val10 = src[y_ + 1][x_]; const Type val11 = src[y_ + 1][x_ + 1]; const int64_t interp_i64 = - static_cast(s_1 * t_1 * val00 + s * t_1 * val01 + s_1 * t * val10 + s * t * val11); - const float interp = (interp_i64 >> (nbits * 2)) + (interp_i64 & 0xFFFFFFFF) * precision_2; + static_cast(((s_1 * t_1) * val00) + ((s * t_1) * val01) + ((s_1 * t) * val10) + ((s * t) * val11)); + const float interp = (interp_i64 >> (nbits * 2)) + ((interp_i64 & 0xFFFFFFFF) * precision_2); dst[i][j] = vpMath::saturate(interp); } else if (y_ < (static_cast(src.getHeight()) - 1)) { const Type val00 = src[y_][x_]; const Type val10 = src[y_ + 1][x_]; - const int64_t interp_i64 = static_cast(t_1 * val00 + t * val10); - const float interp = (interp_i64 >> nbits) + (interp_i64 & 0xFFFF) * precision_1; + const int64_t interp_i64 = static_cast((t_1 * val00) + (t * val10)); + const float interp = (interp_i64 >> nbits) + ((interp_i64 & 0xFFFF) * precision_1); dst[i][j] = vpMath::saturate(interp); } else if (x_ < (static_cast(src.getWidth()) - 1)) { const Type val00 = src[y_][x_]; const Type val01 = src[y_][x_ + 1]; - const int64_t interp_i64 = static_cast(s_1 * val00 + s * val01); - const float interp = (interp_i64 >> nbits) + (interp_i64 & 0xFFFF) * precision_1; + const int64_t interp_i64 = static_cast((s_1 * val00) + (s * val01)); + const float interp = (interp_i64 >> nbits) + ((interp_i64 & 0xFFFF) * precision_1); dst[i][j] = vpMath::saturate(interp); } else { diff --git a/modules/core/include/visp3/core/vpImage_getters.h b/modules/core/include/visp3/core/vpImage_getters.h index d1e9e3e4ad..584691c9ab 100644 --- a/modules/core/include/visp3/core/vpImage_getters.h +++ b/modules/core/include/visp3/core/vpImage_getters.h @@ -169,16 +169,15 @@ template <> inline unsigned char vpImage::getValue(double i, doub uint16_t up = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + (y_ * width) + x_); uint16_t down = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + ((y_ + 1) * width) + x_); - return static_cast(((((up & magic_0x00FF) * rfrac) + ((down & magic_0x00FF) * rratio)) * cfrac + - (((up >> magic_8) * rfrac) + ((down >> 8) * rratio)) * cratio) >> - magic_32); + return static_cast((((((up & magic_0x00FF) * rfrac) + ((down & magic_0x00FF) * rratio)) * cfrac) + + (((up >> magic_8) * rfrac) + ((down >> magic_8) * rratio)) * cratio) >> magic_32); } else if ((y_ + 1) < height) { - return static_cast(((row[y_][x_] * rfrac) + (row[y_ + 1][x_] * rratio)) >> 16); + return static_cast(((row[y_][x_] * rfrac) + (row[y_ + 1][x_] * rratio)) >> magic_16); } else if ((x_ + 1) < width) { uint16_t up = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + (y_ * width) + x_); - return static_cast((((up & 0x00FF) * cfrac) + ((up >> 8) * cratio)) >> magic_16); + return static_cast((((up & magic_0x00FF) * cfrac) + ((up >> magic_8) * cratio)) >> magic_16); } else { return row[y_][x_]; diff --git a/modules/core/include/visp3/core/vpIoException.h b/modules/core/include/visp3/core/vpIoException.h index 8482bd1fab..13ae69bff5 100644 --- a/modules/core/include/visp3/core/vpIoException.h +++ b/modules/core/include/visp3/core/vpIoException.h @@ -87,7 +87,7 @@ class VISP_EXPORT vpIoException : public vpException /*! * Constructor. */ - explicit vpIoException(int id) : vpException(id) { } + VP_EXPLICIT vpIoException(int id) : vpException(id) { } }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpKalmanFilter.h b/modules/core/include/visp3/core/vpKalmanFilter.h index 32ee2b78de..33da7537dd 100644 --- a/modules/core/include/visp3/core/vpKalmanFilter.h +++ b/modules/core/include/visp3/core/vpKalmanFilter.h @@ -123,7 +123,7 @@ class VISP_EXPORT vpKalmanFilter public: vpKalmanFilter(); - explicit vpKalmanFilter(unsigned int n_signal); + VP_EXPLICIT vpKalmanFilter(unsigned int n_signal); vpKalmanFilter(unsigned int size_state, unsigned int size_measure, unsigned int n_signal); /*! Destructor that does noting. */ virtual ~vpKalmanFilter() { }; diff --git a/modules/core/include/visp3/core/vpLine.h b/modules/core/include/visp3/core/vpLine.h index fee8d08505..632364175e 100644 --- a/modules/core/include/visp3/core/vpLine.h +++ b/modules/core/include/visp3/core/vpLine.h @@ -104,20 +104,20 @@ class VISP_EXPORT vpLine : public vpForwardProjection public: vpLine(); - void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const vp_override; - void changeFrame(const vpHomogeneousMatrix &cMo) vp_override; + void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const VP_OVERRIDE; + void changeFrame(const vpHomogeneousMatrix &cMo) VP_OVERRIDE; void display(const vpImage &I, const vpCameraParameters &cam, const vpColor &color = vpColor::green, - unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &color = vpColor::green, unsigned int thickness = 1) vp_override; + const vpColor &color = vpColor::green, unsigned int thickness = 1) VP_OVERRIDE; void display(const vpImage &I, const vpCameraParameters &cam, const vpColor &color = vpColor::green, unsigned int thickness = 1); void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color = vpColor::green, unsigned int thickness = 1); - vpLine *duplicate() const vp_override; + vpLine *duplicate() const VP_OVERRIDE; /*! @@ -167,12 +167,12 @@ class VISP_EXPORT vpLine : public vpForwardProjection void setWorldCoordinates(const vpColVector &oP1, const vpColVector &oP2); - void setWorldCoordinates(const vpColVector &oP) vp_override; - void projection() vp_override; - void projection(const vpColVector &cP, vpColVector &p) const vp_override; + void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE; + void projection() VP_OVERRIDE; + void projection(const vpColVector &cP, vpColVector &p) const VP_OVERRIDE; protected: - void init() vp_override; + void init() VP_OVERRIDE; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpMatrix.h b/modules/core/include/visp3/core/vpMatrix.h index 9580918d18..1d216c91d7 100644 --- a/modules/core/include/visp3/core/vpMatrix.h +++ b/modules/core/include/visp3/core/vpMatrix.h @@ -74,16 +74,16 @@ BEGIN_VISP_NAMESPACE This class needs one of the following third-party to compute matrix inverse, pseudo-inverse, singular value decomposition, determinant: - If Lapack is installed and detected by ViSP, this 3rd party is used by - vpMatrix. Installation instructions are provided here - https://visp.inria.fr/3rd_lapack; + vpMatrix. Installation instructions are provided here + https://visp.inria.fr/3rd_lapack; - else if Eigen3 is installed and detected by ViSP, this 3rd party is used - by vpMatrix. Installation instructions are provided here - https://visp.inria.fr/3rd_eigen; + by vpMatrix. Installation instructions are provided here + https://visp.inria.fr/3rd_eigen; - else if OpenCV is installed and detected by ViSP, this 3rd party is used, Installation instructions are provided here - https://visp.inria.fr/3rd_opencv; + https://visp.inria.fr/3rd_opencv; - If none of these previous 3rd parties is installed, we use by default a - Lapack built-in version. + Lapack built-in version. vpMatrix class provides a data structure for the matrices as well as a set of operations on these matrices. @@ -185,26 +185,32 @@ class VISP_EXPORT vpMatrix : public vpArray2D vpMatrix(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols); /*! - Create a matrix from a 2D array that could be one of the following - container that inherit from vpArray2D such as vpMatrix, vpRotationMatrix, - vpHomogeneousMatrix, vpPoseVector, vpColVector, vpRowVector... + Create a matrix from a 2D array that could be one of the following + container that inherit from vpArray2D such as vpMatrix, vpRotationMatrix, + vpHomogeneousMatrix, vpPoseVector, vpColVector, vpRowVector... - The following example shows how to create a matrix from an homogeneous - matrix: + The following example shows how to create a matrix from an homogeneous + matrix: \code vpRotationMatrix R; vpMatrix M(R); \endcode */ - vpMatrix(const vpArray2D &A) : vpArray2D(A) { } - + VP_EXPLICIT vpMatrix(const vpArray2D &A) : vpArray2D(A) { } vpMatrix(const vpMatrix &A) : vpArray2D(A) { } + VP_EXPLICIT vpMatrix(const vpHomogeneousMatrix &R); + VP_EXPLICIT vpMatrix(const vpRotationMatrix &R); + VP_EXPLICIT vpMatrix(const vpVelocityTwistMatrix &V); + VP_EXPLICIT vpMatrix(const vpForceTwistMatrix &F); + VP_EXPLICIT vpMatrix(const vpColVector &v); + VP_EXPLICIT vpMatrix(const vpRowVector &v); + VP_EXPLICIT vpMatrix(const vpTranslationVector &t); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) vpMatrix(vpMatrix &&A); - explicit vpMatrix(const std::initializer_list &list); - explicit vpMatrix(unsigned int nrows, unsigned int ncols, const std::initializer_list &list); - explicit vpMatrix(const std::initializer_list > &lists); + VP_EXPLICIT vpMatrix(const std::initializer_list &list); + VP_EXPLICIT vpMatrix(unsigned int nrows, unsigned int ncols, const std::initializer_list &list); + VP_EXPLICIT vpMatrix(const std::initializer_list > &lists); #endif /*! @@ -281,6 +287,13 @@ class VISP_EXPORT vpMatrix : public vpArray2D vpMatrix &operator,(double val); vpMatrix &operator=(const vpArray2D &A); vpMatrix &operator=(const vpMatrix &A); + vpMatrix &operator=(const vpHomogeneousMatrix &M); + vpMatrix &operator=(const vpRotationMatrix &R); + vpMatrix &operator=(const vpVelocityTwistMatrix &V); + vpMatrix &operator=(const vpForceTwistMatrix &F); + vpMatrix &operator=(const vpColVector &v); + vpMatrix &operator=(const vpRowVector &v); + vpMatrix &operator=(const vpTranslationVector &t); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) vpMatrix &operator=(vpMatrix &&A); @@ -342,6 +355,33 @@ class VISP_EXPORT vpMatrix : public vpArray2D //--------------------------------- /** @name Matrix operations */ //@{ + /*! + Perform a 2D convolution similar to Matlab conv2 function: \f$ M \star kernel \f$. + + \param M : First matrix. + \param kernel : Second matrix. + \param mode : Convolution mode: "full" (default), "same", "valid". + + \image html vpMatrix-conv2-mode.jpg "Convolution mode: full, same, valid (image credit: Theano doc)." + + \note This is a very basic implementation that does not use FFT. + */ + static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode); + + /*! + Perform a 2D convolution similar to Matlab conv2 function: \f$ M \star kernel \f$. + + \param M : First array. + \param kernel : Second array. + \param res : Result. + \param mode : Convolution mode: "full" (default), "same", "valid". + + \image html vpMatrix-conv2-mode.jpg "Convolution mode: full, same, valid (image credit: Theano doc)." + + \note This is a very basic implementation that does not use FFT. + */ + static void conv2(const vpMatrix &M, const vpMatrix &kernel, vpMatrix &res, const std::string &mode); + // return the determinant of the matrix. double det(vpDetMethod method = LU_DECOMPOSITION) const; double detByLU() const; @@ -993,7 +1033,7 @@ class VISP_EXPORT vpMatrix : public vpArray2D //@} #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) - vp_deprecated double euclideanNorm() const; + VP_DEPRECATED double euclideanNorm() const; /*! @name Deprecated functions @@ -1003,57 +1043,57 @@ class VISP_EXPORT vpMatrix : public vpArray2D \deprecated Only provided for compatibility with ViSP previous releases. This function does nothing. */ - vp_deprecated void init() { } + VP_DEPRECATED void init() { } /*! \deprecated You should rather use stack(const vpMatrix &A) */ - vp_deprecated void stackMatrices(const vpMatrix &A) { stack(A); } + VP_DEPRECATED void stackMatrices(const vpMatrix &A) { stack(A); } /*! \deprecated You should rather use stack(const vpMatrix &A, const vpMatrix &B) */ - vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B) { return stack(A, B); } + VP_DEPRECATED static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B) { return stack(A, B); } /*! \deprecated You should rather use stack(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) */ - vp_deprecated static void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) { stack(A, B, C); } + VP_DEPRECATED static void stackMatrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) { stack(A, B, C); } /*! \deprecated You should rather use stack(const vpMatrix &A, const vpMatrix &B) */ - vp_deprecated static vpMatrix stackMatrices(const vpMatrix &A, const vpRowVector &B); + VP_DEPRECATED static vpMatrix stackMatrices(const vpMatrix &A, const vpRowVector &B); /*! \deprecated You should rather use stack(const vpMatrix &A, const vpRowVector &B, vpMatrix &C) */ - vp_deprecated static void stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C); + VP_DEPRECATED static void stackMatrices(const vpMatrix &A, const vpRowVector &B, vpMatrix &C); /*! \deprecated You should rather use vpColVector::stack(const vpColVector &A, const vpColVector &B) */ - vp_deprecated static vpMatrix stackMatrices(const vpColVector &A, const vpColVector &B); + VP_DEPRECATED static vpMatrix stackMatrices(const vpColVector &A, const vpColVector &B); /*! \deprecated You should rather use vpColVector::stack(const vpColVector &A, const vpColVector &B, vpColVector &C) */ - vp_deprecated static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C); + VP_DEPRECATED static void stackMatrices(const vpColVector &A, const vpColVector &B, vpColVector &C); /*! \deprecated You should rather use diag(const double &) */ - vp_deprecated void setIdentity(const double &val = 1.0); + VP_DEPRECATED void setIdentity(const double &val = 1.0); - vp_deprecated vpRowVector row(unsigned int i); - vp_deprecated vpColVector column(unsigned int j); + VP_DEPRECATED vpRowVector row(unsigned int i); + VP_DEPRECATED vpColVector column(unsigned int j); // Deprecated functions using GSL #ifndef DOXYGEN_SHOULD_SKIP_THIS /*! \deprecated You should rather use detByLULapack() or detByLU(). */ - vp_deprecated double detByLUGsl() const + VP_DEPRECATED double detByLUGsl() const { #if defined(VISP_HAVE_LAPACK) return detByLULapack(); @@ -1065,7 +1105,7 @@ class VISP_EXPORT vpMatrix : public vpArray2D /*! \deprecated You should rather use inverseByLULapack() or inverseByLU(). */ - vp_deprecated vpMatrix inverseByLUGsl() const + VP_DEPRECATED vpMatrix inverseByLUGsl() const { #if defined(VISP_HAVE_LAPACK) return inverseByLULapack(); @@ -1077,7 +1117,7 @@ class VISP_EXPORT vpMatrix : public vpArray2D /*! \deprecated You should rather use inverseByCholeskyLapack() or inverseByCholesky(). */ - vp_deprecated vpMatrix inverseByCholeskyGsl() const + VP_DEPRECATED vpMatrix inverseByCholeskyGsl() const { #if defined(VISP_HAVE_LAPACK) return inverseByCholeskyLapack(); @@ -1089,7 +1129,7 @@ class VISP_EXPORT vpMatrix : public vpArray2D /*! \deprecated You should rather use inverseByQRLapack() or inverseByQR(). */ - vp_deprecated vpMatrix inverseByQRGsl() const + VP_DEPRECATED vpMatrix inverseByQRGsl() const { #if defined(VISP_HAVE_LAPACK) return inverseByQRLapack(); @@ -1101,7 +1141,7 @@ class VISP_EXPORT vpMatrix : public vpArray2D /*! \deprecated You should rather use pseudoInverseLapack() or pseudoInverse(). */ - vp_deprecated vpMatrix pseudoInverseGsl(double svThreshold = 1e-6) const + VP_DEPRECATED vpMatrix pseudoInverseGsl(double svThreshold = 1e-6) const { #if defined(VISP_HAVE_LAPACK) return pseudoInverseLapack(svThreshold); @@ -1114,7 +1154,7 @@ class VISP_EXPORT vpMatrix : public vpArray2D /*! \deprecated You should rather use pseudoInverseLapack() or pseudoInverse(). */ - vp_deprecated unsigned int pseudoInverseGsl(vpMatrix &Ap, double svThreshold = 1e-6) const + VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, double svThreshold = 1e-6) const { #if defined(VISP_HAVE_LAPACK) return pseudoInverseLapack(Ap, svThreshold); @@ -1128,7 +1168,7 @@ class VISP_EXPORT vpMatrix : public vpArray2D /*! \deprecated You should rather use pseudoInverseLapack() or pseudoInverse(). */ - vp_deprecated unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const + VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold = 1e-6) const { #if defined(VISP_HAVE_LAPACK) return pseudoInverseLapack(Ap, sv, svThreshold); @@ -1143,7 +1183,7 @@ class VISP_EXPORT vpMatrix : public vpArray2D /*! \deprecated You should rather use pseudoInverseLapack() or pseudoInverse(). */ - vp_deprecated unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, + VP_DEPRECATED unsigned int pseudoInverseGsl(vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &imA, vpMatrix &imAt, vpMatrix &kerAt) const { #if defined(VISP_HAVE_LAPACK) @@ -1162,7 +1202,7 @@ class VISP_EXPORT vpMatrix : public vpArray2D /*! \deprecated You should rather use svdLapack() or svd(). */ - vp_deprecated void svdGsl(vpColVector &w, vpMatrix &V) + VP_DEPRECATED void svdGsl(vpColVector &w, vpMatrix &V) { #if defined(VISP_HAVE_LAPACK) svdLapack(w, V); diff --git a/modules/core/include/visp3/core/vpMatrixException.h b/modules/core/include/visp3/core/vpMatrixException.h index 3aa5d14833..e2edd42c08 100644 --- a/modules/core/include/visp3/core/vpMatrixException.h +++ b/modules/core/include/visp3/core/vpMatrixException.h @@ -98,7 +98,7 @@ class VISP_EXPORT vpMatrixException : public vpException /*! * Constructor. */ - explicit vpMatrixException(int id) : vpException(id) { } + VP_EXPLICIT vpMatrixException(int id) : vpException(id) { } }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpMomentAreaNormalized.h b/modules/core/include/visp3/core/vpMomentAreaNormalized.h index 6e5ae0e920..189e942d11 100644 --- a/modules/core/include/visp3/core/vpMomentAreaNormalized.h +++ b/modules/core/include/visp3/core/vpMomentAreaNormalized.h @@ -172,7 +172,7 @@ class VISP_EXPORT vpMomentAreaNormalized : public vpMoment * \deprecated Use rather getDesiredArea() * Retrieves the desired surface \e a* as specified in the constructor. */ - vp_deprecated double getDesiredSurface() const { return desiredSurface; } + VP_DEPRECATED double getDesiredSurface() const { return desiredSurface; } //@} #endif diff --git a/modules/core/include/visp3/core/vpMomentCInvariant.h b/modules/core/include/visp3/core/vpMomentCInvariant.h index 7dd2cdf2b4..187aaec733 100644 --- a/modules/core/include/visp3/core/vpMomentCInvariant.h +++ b/modules/core/include/visp3/core/vpMomentCInvariant.h @@ -141,7 +141,7 @@ class VISP_EXPORT vpMomentCInvariant : public vpMoment bool flg_sxsynormalization_; public: - explicit vpMomentCInvariant(bool flg_sxsynormalization = false); + VP_EXPLICIT vpMomentCInvariant(bool flg_sxsynormalization = false); /*! Shorcut for getting the value of \f$C_1\f$. diff --git a/modules/core/include/visp3/core/vpMomentCommon.h b/modules/core/include/visp3/core/vpMomentCommon.h index a5a2322002..91b6138e4e 100644 --- a/modules/core/include/visp3/core/vpMomentCommon.h +++ b/modules/core/include/visp3/core/vpMomentCommon.h @@ -130,13 +130,13 @@ class VISP_EXPORT vpMomentCommon : public vpMomentDatabase vpMomentCommon(double dstSurface, const std::vector &ref, double refAlpha, double dstZ = 1.0, bool flg_sxsyfromnormalized = false); - virtual ~vpMomentCommon() vp_override; + virtual ~vpMomentCommon() VP_OVERRIDE; static double getAlpha(vpMomentObject &object); static std::vector getMu3(vpMomentObject &object); static double getSurface(vpMomentObject &object); - void updateAll(vpMomentObject &object) vp_override; + void updateAll(vpMomentObject &object) VP_OVERRIDE; }; END_VISP_NAMESPACE #endif // VPCOMMONMOMENTS_H diff --git a/modules/core/include/visp3/core/vpMomentObject.h b/modules/core/include/visp3/core/vpMomentObject.h index 3892b8133b..7498212d22 100644 --- a/modules/core/include/visp3/core/vpMomentObject.h +++ b/modules/core/include/visp3/core/vpMomentObject.h @@ -246,7 +246,7 @@ class VISP_EXPORT vpMomentObject // value present in it // Constructors - explicit vpMomentObject(unsigned int order); + VP_EXPLICIT vpMomentObject(unsigned int order); vpMomentObject(const vpMomentObject &srcobj); /*! Virtual destructor to allow polymorphic usage. diff --git a/modules/core/include/visp3/core/vpMutex.h b/modules/core/include/visp3/core/vpMutex.h index 950f4f5547..ef1ef73da7 100644 --- a/modules/core/include/visp3/core/vpMutex.h +++ b/modules/core/include/visp3/core/vpMutex.h @@ -67,7 +67,7 @@ namespace VISP_NAMESPACE_NAME \sa vpScopedLock */ -class vp_deprecated vpMutex +class VP_DEPRECATED vpMutex { public: vpMutex() : m_mutex() diff --git a/modules/core/include/visp3/core/vpPixelMeterConversion.h b/modules/core/include/visp3/core/vpPixelMeterConversion.h index 273333d118..ee06703cf0 100644 --- a/modules/core/include/visp3/core/vpPixelMeterConversion.h +++ b/modules/core/include/visp3/core/vpPixelMeterConversion.h @@ -308,8 +308,8 @@ class VISP_EXPORT vpPixelMeterConversion /* // new_theta = theta - theta_fix, theta_fix = f0(theta) / f0'(theta) */ - double theta_fix = (theta * (val_1 + k0_theta2 + k1_theta4 + k2_theta6 + k3_theta8) - r_d) / - (val_1 + val_3 * k0_theta2 + val_5 * k1_theta4 + val_7 * k2_theta6 + val_9 * k3_theta8); + double theta_fix = ((theta * (val_1 + k0_theta2 + k1_theta4 + k2_theta6 + k3_theta8)) - r_d) + / (val_1 + (val_3 * k0_theta2) + (val_5 * k1_theta4) + (val_7 * k2_theta6) + (val_9 * k3_theta8)); theta = theta - theta_fix; if (fabs(theta_fix) < EPS) { break; diff --git a/modules/core/include/visp3/core/vpPoint.h b/modules/core/include/visp3/core/vpPoint.h index 8edb243ea8..5592429bca 100644 --- a/modules/core/include/visp3/core/vpPoint.h +++ b/modules/core/include/visp3/core/vpPoint.h @@ -82,25 +82,25 @@ class VISP_EXPORT vpPoint : public vpForwardProjection //! Basic constructor. vpPoint(); vpPoint(double oX, double oY, double oZ); - explicit vpPoint(const vpColVector &oP); - explicit vpPoint(const std::vector &oP); + VP_EXPLICIT vpPoint(const vpColVector &oP); + VP_EXPLICIT vpPoint(const std::vector &oP); public: // Compute the 3D coordinates _cP (camera frame) - void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const vp_override; - void changeFrame(const vpHomogeneousMatrix &cMo) vp_override; + void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const VP_OVERRIDE; + void changeFrame(const vpHomogeneousMatrix &cMo) VP_OVERRIDE; void display(const vpImage &I, const vpCameraParameters &cam, const vpColor &color = vpColor::green, - unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &color = vpColor::green, unsigned int thickness = 1) vp_override; + const vpColor &color = vpColor::green, unsigned int thickness = 1) VP_OVERRIDE; void display(const vpImage &I, const vpCameraParameters &cam, const vpColor &color = vpColor::green, unsigned int thickness = 1); void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color = vpColor::green, unsigned int thickness = 1); - vpPoint *duplicate() const vp_override; + vpPoint *duplicate() const VP_OVERRIDE; // Get coordinates double get_X() const; @@ -125,8 +125,8 @@ class VISP_EXPORT vpPoint : public vpForwardProjection //! Projection onto the image plane of a point. Input: the 3D coordinates in //! the camera frame _cP, output : the 2D coordinates _p. - void projection(const vpColVector &_cP, vpColVector &_p) const vp_override; - void projection() vp_override; + void projection(const vpColVector &_cP, vpColVector &_p) const VP_OVERRIDE; + void projection() VP_OVERRIDE; // Set coordinates void set_X(double cX); @@ -143,12 +143,12 @@ class VISP_EXPORT vpPoint : public vpForwardProjection void setWorldCoordinates(double oX, double oY, double oZ); - void setWorldCoordinates(const vpColVector &oP) vp_override; + void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE; void setWorldCoordinates(const std::vector &oP); protected: //! Basic construction. - void init() vp_override; + void init() VP_OVERRIDE; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpPolygon.h b/modules/core/include/visp3/core/vpPolygon.h index 48b7f20a5c..552daf2b69 100644 --- a/modules/core/include/visp3/core/vpPolygon.h +++ b/modules/core/include/visp3/core/vpPolygon.h @@ -106,17 +106,17 @@ class VISP_EXPORT vpPolygon }; vpPolygon(); - explicit vpPolygon(const std::vector &corners); - explicit vpPolygon(const std::list &corners); + VP_EXPLICIT vpPolygon(const std::vector &corners); + VP_EXPLICIT vpPolygon(const std::list &corners); vpPolygon(const vpPolygon &poly); virtual ~vpPolygon(); vpPolygon &operator=(const vpPolygon &poly); #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS - vp_deprecated void buildFrom(const std::vector &corners, const bool create_convex_hull = false); - vp_deprecated void buildFrom(const std::list &corners, const bool create_convex_hull = false); - vp_deprecated void buildFrom(const std::vector &corners, const vpCameraParameters &cam, + VP_DEPRECATED void buildFrom(const std::vector &corners, const bool create_convex_hull = false); + VP_DEPRECATED void buildFrom(const std::list &corners, const bool create_convex_hull = false); + VP_DEPRECATED void buildFrom(const std::vector &corners, const vpCameraParameters &cam, const bool create_convex_hull = false); #endif vpPolygon &build(const std::vector &corners, const bool &create_convex_hull = false); diff --git a/modules/core/include/visp3/core/vpPolygon3D.h b/modules/core/include/visp3/core/vpPolygon3D.h index 4c9f5899bb..27472e2b32 100644 --- a/modules/core/include/visp3/core/vpPolygon3D.h +++ b/modules/core/include/visp3/core/vpPolygon3D.h @@ -165,7 +165,7 @@ class VISP_EXPORT vpPolygon3D @name Deprecated functions */ //@{ - vp_deprecated void getRoiClipped(std::vector &points); + VP_DEPRECATED void getRoiClipped(std::vector &points); //@} #endif diff --git a/modules/core/include/visp3/core/vpPoseVector.h b/modules/core/include/visp3/core/vpPoseVector.h index 80bceaae4c..fa61b9dbe8 100644 --- a/modules/core/include/visp3/core/vpPoseVector.h +++ b/modules/core/include/visp3/core/vpPoseVector.h @@ -191,7 +191,7 @@ class VISP_EXPORT vpPoseVector : public vpArray2D // constructor from 3 angles (in radian) vpPoseVector(double tx, double ty, double tz, double tux, double tuy, double tuz); // constructor convert an homogeneous matrix in a pose - explicit vpPoseVector(const vpHomogeneousMatrix &M); + VP_EXPLICIT vpPoseVector(const vpHomogeneousMatrix &M); // constructor convert a translation and a "thetau" vector into a pose vpPoseVector(const vpTranslationVector &tv, const vpThetaUVector &tu); // constructor convert a translation and a rotation matrix into a pose @@ -200,13 +200,13 @@ class VISP_EXPORT vpPoseVector : public vpArray2D virtual ~vpPoseVector() { } #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS - vp_deprecated vpPoseVector buildFrom(double tx, double ty, double tz, double tux, double tuy, double tuz); + VP_DEPRECATED vpPoseVector buildFrom(double tx, double ty, double tz, double tux, double tuy, double tuz); // convert an homogeneous matrix in a pose - vp_deprecated vpPoseVector buildFrom(const vpHomogeneousMatrix &M); + VP_DEPRECATED vpPoseVector buildFrom(const vpHomogeneousMatrix &M); // convert a translation and a "thetau" vector into a pose - vp_deprecated vpPoseVector buildFrom(const vpTranslationVector &tv, const vpThetaUVector &tu); + VP_DEPRECATED vpPoseVector buildFrom(const vpTranslationVector &tv, const vpThetaUVector &tu); // convert a translation and a rotation matrix into a pose - vp_deprecated vpPoseVector buildFrom(const vpTranslationVector &tv, const vpRotationMatrix &R); + VP_DEPRECATED vpPoseVector buildFrom(const vpTranslationVector &tv, const vpRotationMatrix &R); #endif vpPoseVector &build(const double &tx, const double &ty, const double &tz, const double &tux, const double &tuy, const double &tuz); @@ -319,7 +319,7 @@ class VISP_EXPORT vpPoseVector : public vpArray2D \deprecated Provided only for compat with previous releases. This function does nothing. */ - vp_deprecated void init() { }; + VP_DEPRECATED void init() { }; //@} #endif }; diff --git a/modules/core/include/visp3/core/vpQuaternionVector.h b/modules/core/include/visp3/core/vpQuaternionVector.h index 5f82af0d3b..21d6eaf93d 100644 --- a/modules/core/include/visp3/core/vpQuaternionVector.h +++ b/modules/core/include/visp3/core/vpQuaternionVector.h @@ -108,17 +108,17 @@ class VISP_EXPORT vpQuaternionVector : public vpRotationVector vpQuaternionVector(); vpQuaternionVector(const vpQuaternionVector &q); vpQuaternionVector(const double qx, const double qy, const double qz, const double qw); - explicit vpQuaternionVector(const vpRotationMatrix &R); - explicit vpQuaternionVector(const vpThetaUVector &tu); - explicit vpQuaternionVector(const vpColVector &q); - explicit vpQuaternionVector(const std::vector &q); + VP_EXPLICIT vpQuaternionVector(const vpRotationMatrix &R); + VP_EXPLICIT vpQuaternionVector(const vpThetaUVector &tu); + VP_EXPLICIT vpQuaternionVector(const vpColVector &q); + VP_EXPLICIT vpQuaternionVector(const std::vector &q); #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS - vp_deprecated vpQuaternionVector buildFrom(const double qx, const double qy, const double qz, const double qw); - vp_deprecated vpQuaternionVector buildFrom(const vpRotationMatrix &R); - vp_deprecated vpQuaternionVector buildFrom(const vpThetaUVector &tu); - vp_deprecated vpQuaternionVector buildFrom(const vpColVector &q); - vp_deprecated vpQuaternionVector buildFrom(const std::vector &q); + VP_DEPRECATED vpQuaternionVector buildFrom(const double qx, const double qy, const double qz, const double qw); + VP_DEPRECATED vpQuaternionVector buildFrom(const vpRotationMatrix &R); + VP_DEPRECATED vpQuaternionVector buildFrom(const vpThetaUVector &tu); + VP_DEPRECATED vpQuaternionVector buildFrom(const vpColVector &q); + VP_DEPRECATED vpQuaternionVector buildFrom(const std::vector &q); #endif vpQuaternionVector &build(const double &qx, const double &qy, const double &qz, const double &qw); vpQuaternionVector &build(const vpRotationMatrix &R); diff --git a/modules/core/include/visp3/core/vpRGBa.h b/modules/core/include/visp3/core/vpRGBa.h index 145ee335d4..0eebdf9d6c 100644 --- a/modules/core/include/visp3/core/vpRGBa.h +++ b/modules/core/include/visp3/core/vpRGBa.h @@ -40,6 +40,8 @@ #ifndef VP_RGBA_H #define VP_RGBA_H +#include + #include #include @@ -92,7 +94,31 @@ class VISP_EXPORT vpRGBa \param v : Value to set. */ - inline vpRGBa(unsigned char v) : R(v), G(v), B(v), A(v) { } + explicit inline vpRGBa(unsigned char v) : R(v), G(v), B(v), A(v) { } + + /*! + Constructor. + + Initialize all the R, G, B, A components to \e v. + + \param v : Value to set. + */ + explicit inline vpRGBa(unsigned int v) : R(v), G(v), B(v), A(v) + { + assert(v < 256); + } + + /*! + Constructor. + + Initialize all the R, G, B, A components to \e v. + + \param v : Value to set. + */ + explicit inline vpRGBa(int v) : R(v), G(v), B(v), A(v) + { + assert(v < 256); + } /*! Copy constructor. @@ -107,7 +133,7 @@ class VISP_EXPORT vpRGBa B=v[2] A=v[3] */ - inline vpRGBa(const vpColVector &v) : R(0), G(0), B(0), A(vpRGBa::alpha_default) { *this = v; } + explicit inline vpRGBa(const vpColVector &v) : R(0), G(0), B(0), A(vpRGBa::alpha_default) { *this = v; } // We cannot add here the following destructor without changing the // hypothesis that the size of this class is 4. With the destructor it @@ -115,6 +141,8 @@ class VISP_EXPORT vpRGBa // virtual ~vpRGBa() {}; // Not to implement vpRGBa &operator=(const unsigned char &v); + vpRGBa &operator=(const unsigned int &v); + vpRGBa &operator=(const int &v); vpRGBa &operator=(const vpRGBa &v); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) vpRGBa &operator=(const vpRGBa &&v); diff --git a/modules/core/include/visp3/core/vpRGBf.h b/modules/core/include/visp3/core/vpRGBf.h index 865b7c6306..ce177e1ff6 100644 --- a/modules/core/include/visp3/core/vpRGBf.h +++ b/modules/core/include/visp3/core/vpRGBf.h @@ -86,7 +86,19 @@ class VISP_EXPORT vpRGBf \param v : Value to set. */ - inline vpRGBf(float v) : R(v), G(v), B(v) { } + explicit inline vpRGBf(float v) : R(v), G(v), B(v) { } + + /*! + Constructor. + + Initialize all the R, G, B components to \e v. + + \param v : Value to set. + */ + explicit inline vpRGBf(int v) + { + *this = v; + } /*! Copy constructor. @@ -100,9 +112,10 @@ class VISP_EXPORT vpRGBf G=v[1] B=v[2] */ - inline vpRGBf(const vpColVector &v) : R(0), G(0), B(0) { *this = v; } + explicit inline vpRGBf(const vpColVector &v) : R(0), G(0), B(0) { *this = v; } vpRGBf &operator=(float v); + vpRGBf &operator=(int v); vpRGBf &operator=(const vpRGBf &v); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) vpRGBf &operator=(const vpRGBf &&v); diff --git a/modules/core/include/visp3/core/vpRansac.h b/modules/core/include/visp3/core/vpRansac.h index 20cc8ffc36..f7ce7723ae 100644 --- a/modules/core/include/visp3/core/vpRansac.h +++ b/modules/core/include/visp3/core/vpRansac.h @@ -121,9 +121,9 @@ bool vpRansac::ransac(unsigned int npts, const vpColVector &x, int maxTrials = maxNbumbersOfTrials; // Maximum number of trials before we give up. int maxDataTrials = 1000; // Max number of attempts to select a non-degenerate // data set. - - if (s < 4) { - s = 4; + const unsigned int magic_4 = 4; + if (s < magic_4) { + s = magic_4; } // Sentinel value allowing detection of solution failure. @@ -138,7 +138,7 @@ bool vpRansac::ransac(unsigned int npts, const vpColVector &x, unsigned int *ind = new unsigned int[s]; int ninliers = 0; - while ((N > trialcount) && (consensus > bestscore)) { + while ((N > trialcount) && (consensus > bestscore) && (trialcount > maxTrials)) { // Select at random s data points to form a trial model, M. // In selecting these points we have to check that they are not in // a degenerate configuration. @@ -210,16 +210,13 @@ bool vpRansac::ransac(unsigned int npts, const vpColVector &x, N = (log(1 - p) / log(pNoOutliers)); } - trialcount = trialcount + 1; // Safeguard against being stuck in this loop forever - if (trialcount > maxTrials) { - std::cout << "Warning: ransac reached the maximum number of " << maxTrials << " trials" << std::endl; - break; - } + ++trialcount; } - - if (solutionFind == true) // We got a solution - { + if (trialcount > maxTrials) { + std::cout << "Warning: ransac reached the maximum number of " << maxTrials << " trials" << std::endl; + } + if (solutionFind == true) { // We got a solution M = bestM; inliers = bestinliers; } diff --git a/modules/core/include/visp3/core/vpRect.h b/modules/core/include/visp3/core/vpRect.h index 40060ed70e..f9fdd07943 100644 --- a/modules/core/include/visp3/core/vpRect.h +++ b/modules/core/include/visp3/core/vpRect.h @@ -83,7 +83,7 @@ class VISP_EXPORT vpRect vpRect(const vpImagePoint &topLeft, double width, double height); vpRect(const vpImagePoint &topLeft, const vpImagePoint &bottomRight); vpRect(const vpRect &r); - explicit vpRect(const std::vector &ip); + VP_EXPLICIT vpRect(const std::vector &ip); /*! Returns the area of the rectangle. @@ -389,8 +389,9 @@ class VISP_EXPORT vpRect */ inline void moveCenter(double x, double y) { - this->left = (x - (this->width / 2)) + 0.5; - this->top = (y - (this->height / 2)) + 0.5; + const unsigned int magic_2 = 2; + this->left = (x - (this->width / magic_2)) + 0.5; + this->top = (y - (this->height / magic_2)) + 0.5; } /*! @@ -401,8 +402,9 @@ class VISP_EXPORT vpRect */ inline void moveCenter(const vpImagePoint ¢er) { - this->left = (center.get_u() - (this->width / 2)) + 0.5; - this->top = (center.get_v() - (this->height / 2)) + 0.5; + const unsigned int magic_2 = 2; + this->left = (center.get_u() - (this->width / magic_2)) + 0.5; + this->top = (center.get_v() - (this->height / magic_2)) + 0.5; } private: diff --git a/modules/core/include/visp3/core/vpRectOriented.h b/modules/core/include/visp3/core/vpRectOriented.h index 1fbf7bfb27..4175daf1ed 100644 --- a/modules/core/include/visp3/core/vpRectOriented.h +++ b/modules/core/include/visp3/core/vpRectOriented.h @@ -56,7 +56,7 @@ class VISP_EXPORT vpRectOriented vpRectOriented(const vpImagePoint ¢er, double width, double height, double theta = 0); - explicit vpRectOriented(const vpRect &rect); + VP_EXPLICIT vpRectOriented(const vpRect &rect); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) vpRectOriented &operator=(const vpRectOriented &) = default; @@ -66,7 +66,11 @@ class VISP_EXPORT vpRectOriented vpRectOriented &operator=(const vpRect &rect); +#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) + explicit operator vpRect(); +#else operator vpRect(); +#endif void setCenter(const vpImagePoint ¢er); diff --git a/modules/core/include/visp3/core/vpRobust.h b/modules/core/include/visp3/core/vpRobust.h index 70c0ed615e..f9520d23a3 100644 --- a/modules/core/include/visp3/core/vpRobust.h +++ b/modules/core/include/visp3/core/vpRobust.h @@ -140,7 +140,7 @@ class VISP_EXPORT vpRobust @name Deprecated functions */ //@{ - vp_deprecated explicit vpRobust(unsigned int n_data); + VP_DEPRECATED VP_EXPLICIT vpRobust(unsigned int n_data); //! Compute the weights according a residue vector and a PsiFunction void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, const vpColVector &all_residues, vpColVector &weights); @@ -148,7 +148,7 @@ class VISP_EXPORT vpRobust * \deprecated Set iteration. This function is to call before simultMEstimator(). * \param iter : The first call iter should be set to 0. */ - vp_deprecated void setIteration(unsigned int iter) { m_iter = iter; } + VP_DEPRECATED void setIteration(unsigned int iter) { m_iter = iter; } /*! \deprecated You should rather use setMinMedianAbsoluteDeviation(). Set minimal median absolute deviation (MAD) value. @@ -157,8 +157,8 @@ class VISP_EXPORT vpRobust \param mad_min : Minimal Median Absolute Deviation value. Default value is set to 0.0017 in the default constructor. */ - vp_deprecated inline void setThreshold(double mad_min) { m_mad_min = mad_min; } - vp_deprecated vpColVector simultMEstimator(vpColVector &residues); + VP_DEPRECATED inline void setThreshold(double mad_min) { m_mad_min = mad_min; } + VP_DEPRECATED vpColVector simultMEstimator(vpColVector &residues); //@} #endif private: diff --git a/modules/core/include/visp3/core/vpRotationMatrix.h b/modules/core/include/visp3/core/vpRotationMatrix.h index 28afed04a6..f859851b49 100644 --- a/modules/core/include/visp3/core/vpRotationMatrix.h +++ b/modules/core/include/visp3/core/vpRotationMatrix.h @@ -119,29 +119,29 @@ class VISP_EXPORT vpRotationMatrix : public vpArray2D public: vpRotationMatrix(); vpRotationMatrix(const vpRotationMatrix &R); - explicit vpRotationMatrix(const vpHomogeneousMatrix &M); - explicit vpRotationMatrix(const vpThetaUVector &r); - explicit vpRotationMatrix(const vpPoseVector &p); - explicit vpRotationMatrix(const vpRzyzVector &r); - explicit vpRotationMatrix(const vpRxyzVector &r); - explicit vpRotationMatrix(const vpRzyxVector &r); - explicit vpRotationMatrix(const vpQuaternionVector &q); - explicit vpRotationMatrix(const vpMatrix &R); + VP_EXPLICIT vpRotationMatrix(const vpHomogeneousMatrix &M); + VP_EXPLICIT vpRotationMatrix(const vpThetaUVector &r); + VP_EXPLICIT vpRotationMatrix(const vpPoseVector &p); + VP_EXPLICIT vpRotationMatrix(const vpRzyzVector &r); + VP_EXPLICIT vpRotationMatrix(const vpRxyzVector &r); + VP_EXPLICIT vpRotationMatrix(const vpRzyxVector &r); + VP_EXPLICIT vpRotationMatrix(const vpQuaternionVector &q); + VP_EXPLICIT vpRotationMatrix(const vpMatrix &R); vpRotationMatrix(double tux, double tuy, double tuz); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) - explicit vpRotationMatrix(const std::initializer_list &list); + VP_EXPLICIT vpRotationMatrix(const std::initializer_list &list); #endif #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS - vp_deprecated vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M); - vp_deprecated vpRotationMatrix buildFrom(const vpThetaUVector &v); - vp_deprecated vpRotationMatrix buildFrom(const vpPoseVector &p); - vp_deprecated vpRotationMatrix buildFrom(const vpRzyzVector &v); - vp_deprecated vpRotationMatrix buildFrom(const vpRxyzVector &v); - vp_deprecated vpRotationMatrix buildFrom(const vpRzyxVector &v); - vp_deprecated vpRotationMatrix buildFrom(const vpQuaternionVector &q); - vp_deprecated vpRotationMatrix buildFrom(double tux, double tuy, double tuz); + VP_DEPRECATED vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M); + VP_DEPRECATED vpRotationMatrix buildFrom(const vpThetaUVector &v); + VP_DEPRECATED vpRotationMatrix buildFrom(const vpPoseVector &p); + VP_DEPRECATED vpRotationMatrix buildFrom(const vpRzyzVector &v); + VP_DEPRECATED vpRotationMatrix buildFrom(const vpRxyzVector &v); + VP_DEPRECATED vpRotationMatrix buildFrom(const vpRzyxVector &v); + VP_DEPRECATED vpRotationMatrix buildFrom(const vpQuaternionVector &q); + VP_DEPRECATED vpRotationMatrix buildFrom(double tux, double tuy, double tuz); #endif vpRotationMatrix &build(const vpHomogeneousMatrix &M); vpRotationMatrix &build(const vpThetaUVector &v); @@ -216,11 +216,11 @@ class VISP_EXPORT vpRotationMatrix : public vpArray2D \deprecated Provided only for compat with previous releases. This function does nothing. */ - vp_deprecated void init() { } + VP_DEPRECATED void init() { } /*! \deprecated You should rather use eye(). */ - vp_deprecated void setIdentity(); + VP_DEPRECATED void setIdentity(); //@} #endif diff --git a/modules/core/include/visp3/core/vpRotationVector.h b/modules/core/include/visp3/core/vpRotationVector.h index c2481632c4..a381b28a08 100644 --- a/modules/core/include/visp3/core/vpRotationVector.h +++ b/modules/core/include/visp3/core/vpRotationVector.h @@ -103,7 +103,7 @@ class VISP_EXPORT vpRotationVector : public vpArray2D //! Constructor that constructs a vector of size n and initialize all values //! to zero. - explicit vpRotationVector(unsigned int n) : vpArray2D(n, 1), m_index(0) { } + VP_EXPLICIT vpRotationVector(unsigned int n) : vpArray2D(n, 1), m_index(0) { } /*! Copy operator. diff --git a/modules/core/include/visp3/core/vpRowVector.h b/modules/core/include/visp3/core/vpRowVector.h index 88cf80bee3..91865e4bdf 100644 --- a/modules/core/include/visp3/core/vpRowVector.h +++ b/modules/core/include/visp3/core/vpRowVector.h @@ -68,42 +68,42 @@ class vpColVector; The code below shows how to create a 3-element row vector of doubles, set the element values and access them: \code -#include &) \code -int main() -{ - vpRowVector v; - v = {-1, -2.1, -3}; -} + int main() + { + vpRowVector v; + v = {-1, -2.1, -3}; + } \endcode */ class VISP_EXPORT vpRowVector : public vpArray2D @@ -113,20 +113,20 @@ class VISP_EXPORT vpRowVector : public vpArray2D vpRowVector() : vpArray2D() { } //! Construct a row vector of size n. All the elements are initialized to //! zero. - explicit vpRowVector(unsigned int n) : vpArray2D(1, n) { } + VP_EXPLICIT vpRowVector(unsigned int n) : vpArray2D(1, n) { } //! Construct a row vector of size n. Each element is set to \e val. vpRowVector(unsigned int n, double val) : vpArray2D(1, n, val) { } //! Copy constructor that allows to construct a row vector from an other //! one. vpRowVector(const vpRowVector &v) : vpArray2D(v) { } vpRowVector(const vpRowVector &v, unsigned int c, unsigned int ncols); - explicit vpRowVector(const vpMatrix &M); + VP_EXPLICIT vpRowVector(const vpMatrix &M); vpRowVector(const vpMatrix &M, unsigned int i); - explicit vpRowVector(const std::vector &v); - explicit vpRowVector(const std::vector &v); + VP_EXPLICIT vpRowVector(const std::vector &v); + VP_EXPLICIT vpRowVector(const std::vector &v); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) vpRowVector(vpRowVector &&v); - explicit vpRowVector(const std::initializer_list &list) : vpArray2D(list) { } + VP_EXPLICIT vpRowVector(const std::initializer_list &list) : vpArray2D(list) { } #endif /*! @@ -163,23 +163,22 @@ class VISP_EXPORT vpRowVector : public vpArray2D (*this) *= d2r; } - /*! - Extract a sub-row vector from a row vector. - \param c : Index of the column corresponding to the first element of the - vector to extract. - \param rowsize : Size of the vector to extract. - \exception vpException::fatalError If the vector to extract is not - contained in the original one. - - \code - vpRowVector r1; - for (unsigned int i=0; i<4; ++i) - r1.stack(i); - // r1 is equal to [0 1 2 3] - vpRowVector r2 = r1.extract(1, 3); - // r2 is equal to [1 2 3] - \endcode + Extract a sub-row vector from a row vector. + \param c : Index of the column corresponding to the first element of the + vector to extract. + \param rowsize : Size of the vector to extract. + \exception vpException::fatalError If the vector to extract is not + contained in the original one. + + \code + vpRowVector r1; + for (unsigned int i=0; i<4; ++i) + r1.stack(i); + // r1 is equal to [0 1 2 3] + vpRowVector r2 = r1.extract(1, 3); + // r2 is equal to [1 2 3] + \endcode */ vpRowVector extract(unsigned int c, unsigned int rowsize) const { @@ -194,6 +193,16 @@ class VISP_EXPORT vpRowVector : public vpArray2D } double frobeniusNorm() const; + + /*! + * Compute the Hadamard product (element wise vector multiplication). + * + * \param v : Second vector; + * \return v1.hadamard(v2) The kronecker product : + * \f$ v1 \circ v2 = (v1 \circ v2)_{i} = (v1)_{i} (v2)_{i} \f$ + */ + vpRowVector hadamard(const vpRowVector &v) const; + void init(const vpRowVector &v, unsigned int c, unsigned int ncols); void insert(unsigned int i, const vpRowVector &v); @@ -309,21 +318,21 @@ class VISP_EXPORT vpRowVector : public vpArray2D \deprecated Provided only for compat with previous releases. This function does nothing. */ - vp_deprecated void init() { } + VP_DEPRECATED void init() { } /*! \deprecated You should rather use stack(const vpRowVector &) */ - vp_deprecated void stackMatrices(const vpRowVector &r) { stack(r); } + VP_DEPRECATED void stackMatrices(const vpRowVector &r) { stack(r); } /*! \deprecated You should rather use stack(const vpRowVector &A, const vpRowVector &B) */ - vp_deprecated static vpRowVector stackMatrices(const vpRowVector &A, const vpRowVector &B) { return stack(A, B); } + VP_DEPRECATED static vpRowVector stackMatrices(const vpRowVector &A, const vpRowVector &B) { return stack(A, B); } /*! \deprecated You should rather use stack(const vpRowVector &A, const vpRowVector &B, vpRowVector &C) */ - vp_deprecated static void stackMatrices(const vpRowVector &A, const vpRowVector &B, vpRowVector &C) + VP_DEPRECATED static void stackMatrices(const vpRowVector &A, const vpRowVector &B, vpRowVector &C) { stack(A, B, C); } @@ -331,8 +340,8 @@ class VISP_EXPORT vpRowVector : public vpArray2D /*! \deprecated You should rather use eye() */ - vp_deprecated void setIdentity(const double &val = 1.0); - vp_deprecated double euclideanNorm() const; + VP_DEPRECATED void setIdentity(const double &val = 1.0); + VP_DEPRECATED double euclideanNorm() const; //@} #endif }; diff --git a/modules/core/include/visp3/core/vpRxyzVector.h b/modules/core/include/visp3/core/vpRxyzVector.h index 8f4a572467..f649f32af3 100644 --- a/modules/core/include/visp3/core/vpRxyzVector.h +++ b/modules/core/include/visp3/core/vpRxyzVector.h @@ -183,23 +183,23 @@ class VISP_EXPORT vpRxyzVector : public vpRotationVector vpRxyzVector(double phi, double theta, double psi); // initialize a Rxyz vector from a rotation matrix - explicit vpRxyzVector(const vpRotationMatrix &R); + VP_EXPLICIT vpRxyzVector(const vpRotationMatrix &R); // initialize a Rxyz vector from a ThetaU vector - explicit vpRxyzVector(const vpThetaUVector &tu); - explicit vpRxyzVector(const vpColVector &rxyz); - explicit vpRxyzVector(const std::vector &rxyz); + VP_EXPLICIT vpRxyzVector(const vpThetaUVector &tu); + VP_EXPLICIT vpRxyzVector(const vpColVector &rxyz); + VP_EXPLICIT vpRxyzVector(const std::vector &rxyz); #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS // convert a rotation matrix into Rxyz vector - vp_deprecated vpRxyzVector buildFrom(const vpRotationMatrix &R); + VP_DEPRECATED vpRxyzVector buildFrom(const vpRotationMatrix &R); // convert a ThetaU vector into a Rxyz vector - vp_deprecated vpRxyzVector buildFrom(const vpThetaUVector &tu); - vp_deprecated vpRxyzVector buildFrom(const vpColVector &rxyz); - vp_deprecated vpRxyzVector buildFrom(const std::vector &rxyz); + VP_DEPRECATED vpRxyzVector buildFrom(const vpThetaUVector &tu); + VP_DEPRECATED vpRxyzVector buildFrom(const vpColVector &rxyz); + VP_DEPRECATED vpRxyzVector buildFrom(const std::vector &rxyz); - vp_deprecated void buildFrom(double phi, double theta, double psi); + VP_DEPRECATED void buildFrom(double phi, double theta, double psi); #endif // convert a rotation matrix into Rxyz vector vpRxyzVector &build(const vpRotationMatrix &R); diff --git a/modules/core/include/visp3/core/vpRzyxVector.h b/modules/core/include/visp3/core/vpRzyxVector.h index 40972dc35a..6653d3ca07 100644 --- a/modules/core/include/visp3/core/vpRzyxVector.h +++ b/modules/core/include/visp3/core/vpRzyxVector.h @@ -184,23 +184,23 @@ class VISP_EXPORT vpRzyxVector : public vpRotationVector vpRzyxVector(double phi, double theta, double psi); // initialize a Rzyx vector from a rotation matrix - explicit vpRzyxVector(const vpRotationMatrix &R); + VP_EXPLICIT vpRzyxVector(const vpRotationMatrix &R); // initialize a Rzyx vector from a ThetaU vector - explicit vpRzyxVector(const vpThetaUVector &tu); - explicit vpRzyxVector(const vpColVector &rzyx); - explicit vpRzyxVector(const std::vector &rzyx); + VP_EXPLICIT vpRzyxVector(const vpThetaUVector &tu); + VP_EXPLICIT vpRzyxVector(const vpColVector &rzyx); + VP_EXPLICIT vpRzyxVector(const std::vector &rzyx); #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS // convert a rotation matrix into Rzyx vector - vp_deprecated vpRzyxVector buildFrom(const vpRotationMatrix &R); + VP_DEPRECATED vpRzyxVector buildFrom(const vpRotationMatrix &R); // convert a ThetaU vector into a Rzyx vector - vp_deprecated vpRzyxVector buildFrom(const vpThetaUVector &R); - vp_deprecated vpRzyxVector buildFrom(const vpColVector &rxyz); - vp_deprecated vpRzyxVector buildFrom(const std::vector &rxyz); + VP_DEPRECATED vpRzyxVector buildFrom(const vpThetaUVector &R); + VP_DEPRECATED vpRzyxVector buildFrom(const vpColVector &rxyz); + VP_DEPRECATED vpRzyxVector buildFrom(const std::vector &rxyz); - vp_deprecated void buildFrom(double phi, double theta, double psi); + VP_DEPRECATED void buildFrom(double phi, double theta, double psi); #endif // convert a rotation matrix into Rzyx vector vpRzyxVector &build(const vpRotationMatrix &R); diff --git a/modules/core/include/visp3/core/vpRzyzVector.h b/modules/core/include/visp3/core/vpRzyzVector.h index 7f30bd863b..9b14b5bbc1 100644 --- a/modules/core/include/visp3/core/vpRzyzVector.h +++ b/modules/core/include/visp3/core/vpRzyzVector.h @@ -181,25 +181,25 @@ class VISP_EXPORT vpRzyzVector : public vpRotationVector vpRzyzVector(const vpRzyzVector &rzyz); // initialize a Rzyz vector from a rotation matrix - explicit vpRzyzVector(const vpRotationMatrix &R); + VP_EXPLICIT vpRzyzVector(const vpRotationMatrix &R); // initialize a Rzyz vector from a ThetaU vector - explicit vpRzyzVector(const vpThetaUVector &tu); + VP_EXPLICIT vpRzyzVector(const vpThetaUVector &tu); vpRzyzVector(double phi, double theta, double psi); - explicit vpRzyzVector(const vpColVector &rzyz); - explicit vpRzyzVector(const std::vector &rzyz); + VP_EXPLICIT vpRzyzVector(const vpColVector &rzyz); + VP_EXPLICIT vpRzyzVector(const std::vector &rzyz); #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS // convert a rotation matrix into Rzyz vector - vp_deprecated vpRzyzVector buildFrom(const vpRotationMatrix &R); + VP_DEPRECATED vpRzyzVector buildFrom(const vpRotationMatrix &R); // convert a ThetaU vector into a Rzyz vector - vp_deprecated vpRzyzVector buildFrom(const vpThetaUVector &R); - vp_deprecated vpRzyzVector buildFrom(const vpColVector &rxyz); - vp_deprecated vpRzyzVector buildFrom(const std::vector &rxyz); + VP_DEPRECATED vpRzyzVector buildFrom(const vpThetaUVector &R); + VP_DEPRECATED vpRzyzVector buildFrom(const vpColVector &rxyz); + VP_DEPRECATED vpRzyzVector buildFrom(const std::vector &rxyz); - vp_deprecated void buildFrom(double phi, double theta, double psi); + VP_DEPRECATED void buildFrom(double phi, double theta, double psi); #endif // convert a rotation matrix into Rzyz vector vpRzyzVector &build(const vpRotationMatrix &R); diff --git a/modules/core/include/visp3/core/vpServer.h b/modules/core/include/visp3/core/vpServer.h index 9a5d19a0e1..0233136c68 100644 --- a/modules/core/include/visp3/core/vpServer.h +++ b/modules/core/include/visp3/core/vpServer.h @@ -172,10 +172,10 @@ class VISP_EXPORT vpServer : public vpNetwork public: vpServer(); - explicit vpServer(const int &port); + VP_EXPLICIT vpServer(const int &port); vpServer(const std::string &adress_serv, const int &port_serv); - virtual ~vpServer() vp_override; + virtual ~vpServer() VP_OVERRIDE; bool checkForConnections(); diff --git a/modules/core/include/visp3/core/vpSphere.h b/modules/core/include/visp3/core/vpSphere.h index bb0a763742..5ba502b7f3 100644 --- a/modules/core/include/visp3/core/vpSphere.h +++ b/modules/core/include/visp3/core/vpSphere.h @@ -80,23 +80,23 @@ class VISP_EXPORT vpSphere : public vpForwardProjection { public: vpSphere(); - explicit vpSphere(const vpColVector &oP); + VP_EXPLICIT vpSphere(const vpColVector &oP); vpSphere(double oX, double oY, double oZ, double R); - void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const vp_override; - void changeFrame(const vpHomogeneousMatrix &cMo) vp_override; + void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const VP_OVERRIDE; + void changeFrame(const vpHomogeneousMatrix &cMo) VP_OVERRIDE; void display(const vpImage &I, const vpCameraParameters &cam, const vpColor &color = vpColor::green, - unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &color = vpColor::green, unsigned int thickness = 1) vp_override; + const vpColor &color = vpColor::green, unsigned int thickness = 1) VP_OVERRIDE; void display(const vpImage &I, const vpCameraParameters &cam, const vpColor &color = vpColor::green, unsigned int thickness = 1); void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &color = vpColor::green, unsigned int thickness = 1); - vpSphere *duplicate() const vp_override; + vpSphere *duplicate() const VP_OVERRIDE; double get_x() const { return p[0]; } double get_y() const { return p[1]; } @@ -111,9 +111,9 @@ class VISP_EXPORT vpSphere : public vpForwardProjection double getR() const { const unsigned int index_3 = 3; return cP[index_3]; } - void projection() vp_override; - void projection(const vpColVector &cP, vpColVector &p) const vp_override; - void setWorldCoordinates(const vpColVector &oP) vp_override; + void projection() VP_OVERRIDE; + void projection(const vpColVector &cP, vpColVector &p) const VP_OVERRIDE; + void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE; void setWorldCoordinates(double oX, double oY, double oZ, double R); @@ -129,25 +129,25 @@ class VISP_EXPORT vpSphere : public vpForwardProjection * returns second order centered moments of the ellipse normalized * by its area that corresponds to \f$n_20 = mu_20/a\f$. */ - vp_deprecated double get_mu20() const { const unsigned int index_2 = 2; return p[index_2]; } + VP_DEPRECATED double get_mu20() const { const unsigned int index_2 = 2; return p[index_2]; } /*! * \deprecated You should rather use get_n11(). * This function is incorrectly named and is confusing since it * returns second order centered moments of the ellipse normalized * by its area that corresponds to \f$n_11 = mu_11/a\f$. */ - vp_deprecated double get_mu11() const { const unsigned int index_3 = 3; return p[index_3]; } + VP_DEPRECATED double get_mu11() const { const unsigned int index_3 = 3; return p[index_3]; } /*! * \deprecated You should rather use get_n02(). * This function is incorrectly named and is confusing since it * returns second order centered moments of the ellipse normalized * by its area that corresponds to \f$n_02 = mu_02/a\f$. */ - vp_deprecated double get_mu02() const { const unsigned int index_4 = 4; return p[index_4]; } + VP_DEPRECATED double get_mu02() const { const unsigned int index_4 = 4; return p[index_4]; } //@} #endif protected: - void init() vp_override; + void init() VP_OVERRIDE; }; END_VISP_NAMESPACE diff --git a/modules/core/include/visp3/core/vpSubColVector.h b/modules/core/include/visp3/core/vpSubColVector.h index 949d026a65..dfcbb30e3a 100644 --- a/modules/core/include/visp3/core/vpSubColVector.h +++ b/modules/core/include/visp3/core/vpSubColVector.h @@ -59,7 +59,7 @@ class VISP_EXPORT vpSubColVector : public vpColVector public: vpSubColVector(); vpSubColVector(vpColVector &v, const unsigned int &offset, const unsigned int &nrows); - virtual ~vpSubColVector() vp_override; + virtual ~vpSubColVector() VP_OVERRIDE; void checkParentStatus() const; diff --git a/modules/core/include/visp3/core/vpSubMatrix.h b/modules/core/include/visp3/core/vpSubMatrix.h index 73536d5304..c94c8aa0db 100644 --- a/modules/core/include/visp3/core/vpSubMatrix.h +++ b/modules/core/include/visp3/core/vpSubMatrix.h @@ -63,7 +63,7 @@ class VISP_EXPORT vpSubMatrix : public vpMatrix vpSubMatrix(vpMatrix &m, const unsigned int &row, const unsigned int &col, const unsigned int &nrows, const unsigned int &ncols); //! Destructor - virtual ~vpSubMatrix() vp_override; + virtual ~vpSubMatrix() VP_OVERRIDE; //! Initialisation of vpMatrix void init(vpMatrix &m, const unsigned int &row, const unsigned int &col, const unsigned int &nrows, diff --git a/modules/core/include/visp3/core/vpSubRowVector.h b/modules/core/include/visp3/core/vpSubRowVector.h index b3f3f6f8de..266bb19ab0 100644 --- a/modules/core/include/visp3/core/vpSubRowVector.h +++ b/modules/core/include/visp3/core/vpSubRowVector.h @@ -60,7 +60,7 @@ class VISP_EXPORT vpSubRowVector : public vpRowVector public: vpSubRowVector(); vpSubRowVector(vpRowVector &v, const unsigned int &offset, const unsigned int &ncols); - virtual ~vpSubRowVector() vp_override; + virtual ~vpSubRowVector() VP_OVERRIDE; void checkParentStatus() const; diff --git a/modules/core/include/visp3/core/vpThetaUVector.h b/modules/core/include/visp3/core/vpThetaUVector.h index 8d5ceab495..82f86a0b9d 100644 --- a/modules/core/include/visp3/core/vpThetaUVector.h +++ b/modules/core/include/visp3/core/vpThetaUVector.h @@ -171,41 +171,41 @@ class VISP_EXPORT vpThetaUVector : public vpRotationVector vpThetaUVector(const vpThetaUVector &tu); // constructor initialize a Theta U vector from a homogeneous matrix - explicit vpThetaUVector(const vpHomogeneousMatrix &M); + VP_EXPLICIT vpThetaUVector(const vpHomogeneousMatrix &M); // constructor initialize a Theta U vector from a pose vector - explicit vpThetaUVector(const vpPoseVector &p); + VP_EXPLICIT vpThetaUVector(const vpPoseVector &p); // constructor initialize a Theta U vector from a rotation matrix - explicit vpThetaUVector(const vpRotationMatrix &R); + VP_EXPLICIT vpThetaUVector(const vpRotationMatrix &R); // constructor initialize a Theta U vector from a RzyxVector - explicit vpThetaUVector(const vpRzyxVector &rzyx); + VP_EXPLICIT vpThetaUVector(const vpRzyxVector &rzyx); // constructor initialize a Theta U vector from a RzyzVector - explicit vpThetaUVector(const vpRzyzVector &rzyz); + VP_EXPLICIT vpThetaUVector(const vpRzyzVector &rzyz); // constructor initialize a Theta U vector from a RxyzVector - explicit vpThetaUVector(const vpRxyzVector &rxyz); - explicit vpThetaUVector(const vpQuaternionVector &q); - explicit vpThetaUVector(const vpColVector &tu); - explicit vpThetaUVector(const std::vector &tu); + VP_EXPLICIT vpThetaUVector(const vpRxyzVector &rxyz); + VP_EXPLICIT vpThetaUVector(const vpQuaternionVector &q); + VP_EXPLICIT vpThetaUVector(const vpColVector &tu); + VP_EXPLICIT vpThetaUVector(const std::vector &tu); vpThetaUVector(double tux, double tuy, double tuz); #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS // convert an homogeneous matrix into Theta U vector - vp_deprecated vpThetaUVector buildFrom(const vpHomogeneousMatrix &M); + VP_DEPRECATED vpThetaUVector buildFrom(const vpHomogeneousMatrix &M); // convert a pose vector into Theta U vector - vp_deprecated vpThetaUVector buildFrom(const vpPoseVector &p); + VP_DEPRECATED vpThetaUVector buildFrom(const vpPoseVector &p); // convert a rotation matrix into Theta U vector - vp_deprecated vpThetaUVector buildFrom(const vpRotationMatrix &R); + VP_DEPRECATED vpThetaUVector buildFrom(const vpRotationMatrix &R); // convert an Rzyx vector into Theta U vector - vp_deprecated vpThetaUVector buildFrom(const vpRzyxVector &rzyx); + VP_DEPRECATED vpThetaUVector buildFrom(const vpRzyxVector &rzyx); // convert an Rzyz vector into Theta U vector - vp_deprecated vpThetaUVector buildFrom(const vpRzyzVector &zyz); + VP_DEPRECATED vpThetaUVector buildFrom(const vpRzyzVector &zyz); // convert an Rxyz vector into Theta U vector - vp_deprecated vpThetaUVector buildFrom(const vpRxyzVector &xyz); - vp_deprecated vpThetaUVector buildFrom(const vpQuaternionVector &q); - vp_deprecated vpThetaUVector buildFrom(const vpColVector &tu); - vp_deprecated vpThetaUVector buildFrom(const std::vector &tu); + VP_DEPRECATED vpThetaUVector buildFrom(const vpRxyzVector &xyz); + VP_DEPRECATED vpThetaUVector buildFrom(const vpQuaternionVector &q); + VP_DEPRECATED vpThetaUVector buildFrom(const vpColVector &tu); + VP_DEPRECATED vpThetaUVector buildFrom(const std::vector &tu); - vp_deprecated void buildFrom(double tux, double tuy, double tuz); + VP_DEPRECATED void buildFrom(double tux, double tuy, double tuz); #endif // convert an homogeneous matrix into Theta U vector vpThetaUVector &build(const vpHomogeneousMatrix &M); diff --git a/modules/core/include/visp3/core/vpThread.h b/modules/core/include/visp3/core/vpThread.h index b710683a68..c6b0ba9917 100644 --- a/modules/core/include/visp3/core/vpThread.h +++ b/modules/core/include/visp3/core/vpThread.h @@ -64,7 +64,7 @@ namespace VISP_NAMESPACE_NAME native Windows threading capabilities if pthread is not available under Windows. */ -class vp_deprecated vpThread +class VP_DEPRECATED vpThread { public: #if defined(VISP_HAVE_PTHREAD) diff --git a/modules/core/include/visp3/core/vpTrackingException.h b/modules/core/include/visp3/core/vpTrackingException.h index dd29883f17..91b893277c 100644 --- a/modules/core/include/visp3/core/vpTrackingException.h +++ b/modules/core/include/visp3/core/vpTrackingException.h @@ -88,7 +88,7 @@ class VISP_EXPORT vpTrackingException : public vpException /*! * Constructor. */ - explicit vpTrackingException(int id) : vpException(id) { } + VP_EXPLICIT vpTrackingException(int id) : vpException(id) { } }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpTranslationVector.h b/modules/core/include/visp3/core/vpTranslationVector.h index 1317e2dc44..e1e2415ff2 100644 --- a/modules/core/include/visp3/core/vpTranslationVector.h +++ b/modules/core/include/visp3/core/vpTranslationVector.h @@ -121,15 +121,15 @@ class VISP_EXPORT vpTranslationVector : public vpArray2D vpTranslationVector() : vpArray2D(3, 1), m_index(0) { } vpTranslationVector(double tx, double ty, double tz); vpTranslationVector(const vpTranslationVector &tv); - explicit vpTranslationVector(const vpHomogeneousMatrix &M); - explicit vpTranslationVector(const vpPoseVector &p); - explicit vpTranslationVector(const vpColVector &v); + VP_EXPLICIT vpTranslationVector(const vpHomogeneousMatrix &M); + VP_EXPLICIT vpTranslationVector(const vpPoseVector &p); + VP_EXPLICIT vpTranslationVector(const vpColVector &v); #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS - vp_deprecated vpTranslationVector buildFrom(double tx, double ty, double tz); - vp_deprecated vpTranslationVector buildFrom(const vpHomogeneousMatrix &M); - vp_deprecated vpTranslationVector buildFrom(const vpPoseVector &p); - vp_deprecated vpTranslationVector buildFrom(const vpColVector &v); + VP_DEPRECATED vpTranslationVector buildFrom(double tx, double ty, double tz); + VP_DEPRECATED vpTranslationVector buildFrom(const vpHomogeneousMatrix &M); + VP_DEPRECATED vpTranslationVector buildFrom(const vpPoseVector &p); + VP_DEPRECATED vpTranslationVector buildFrom(const vpColVector &v); #endif vpTranslationVector &build(const double &tx, const double &ty, const double &tz); vpTranslationVector &build(const vpHomogeneousMatrix &M); @@ -202,7 +202,7 @@ class VISP_EXPORT vpTranslationVector : public vpArray2D @name Deprecated functions */ //@{ - vp_deprecated double euclideanNorm() const; + VP_DEPRECATED double euclideanNorm() const; //} #endif diff --git a/modules/core/include/visp3/core/vpTriangle.h b/modules/core/include/visp3/core/vpTriangle.h index f6048d8710..58feaffae5 100644 --- a/modules/core/include/visp3/core/vpTriangle.h +++ b/modules/core/include/visp3/core/vpTriangle.h @@ -76,7 +76,7 @@ class VISP_EXPORT vpTriangle vpTriangle(const vpImagePoint &iP1, const vpImagePoint &iP2, const vpImagePoint &iP3); #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS - vp_deprecated void buildFrom(const vpImagePoint &iP1, const vpImagePoint &iP2, const vpImagePoint &iP3); + VP_DEPRECATED void buildFrom(const vpImagePoint &iP1, const vpImagePoint &iP2, const vpImagePoint &iP3); #endif vpTriangle &build(const vpImagePoint &iP1, const vpImagePoint &iP2, const vpImagePoint &iP3); diff --git a/modules/core/include/visp3/core/vpVelocityTwistMatrix.h b/modules/core/include/visp3/core/vpVelocityTwistMatrix.h index 2f461e59af..2be04f2bfb 100644 --- a/modules/core/include/visp3/core/vpVelocityTwistMatrix.h +++ b/modules/core/include/visp3/core/vpVelocityTwistMatrix.h @@ -169,7 +169,7 @@ class VISP_EXPORT vpVelocityTwistMatrix : public vpArray2D // copy constructor vpVelocityTwistMatrix(const vpVelocityTwistMatrix &V); // constructor from an homogeneous transformation - explicit vpVelocityTwistMatrix(const vpHomogeneousMatrix &M, bool full = true); + VP_EXPLICIT vpVelocityTwistMatrix(const vpHomogeneousMatrix &M, bool full = true); // Construction from Translation and rotation (matrix parameterization) vpVelocityTwistMatrix(const vpTranslationVector &t, const vpRotationMatrix &R); @@ -177,15 +177,15 @@ class VISP_EXPORT vpVelocityTwistMatrix : public vpArray2D vpVelocityTwistMatrix(const vpTranslationVector &t, const vpThetaUVector &thetau); vpVelocityTwistMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz); - explicit vpVelocityTwistMatrix(const vpRotationMatrix &R); - explicit vpVelocityTwistMatrix(const vpThetaUVector &thetau); + VP_EXPLICIT vpVelocityTwistMatrix(const vpRotationMatrix &R); + VP_EXPLICIT vpVelocityTwistMatrix(const vpThetaUVector &thetau); #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS - vp_deprecated vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R); - vp_deprecated vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpThetaUVector &thetau); - vp_deprecated vpVelocityTwistMatrix buildFrom(const vpHomogeneousMatrix &M, bool full = true); - vp_deprecated vpVelocityTwistMatrix buildFrom(const vpRotationMatrix &R); - vp_deprecated vpVelocityTwistMatrix buildFrom(const vpThetaUVector &thetau); + VP_DEPRECATED vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R); + VP_DEPRECATED vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpThetaUVector &thetau); + VP_DEPRECATED vpVelocityTwistMatrix buildFrom(const vpHomogeneousMatrix &M, bool full = true); + VP_DEPRECATED vpVelocityTwistMatrix buildFrom(const vpRotationMatrix &R); + VP_DEPRECATED vpVelocityTwistMatrix buildFrom(const vpThetaUVector &thetau); #endif vpVelocityTwistMatrix &build(const vpTranslationVector &t, const vpRotationMatrix &R); vpVelocityTwistMatrix &build(const vpTranslationVector &t, const vpThetaUVector &thetau); @@ -232,11 +232,11 @@ class VISP_EXPORT vpVelocityTwistMatrix : public vpArray2D \deprecated Provided only for compat with previous releases. This function does nothing. */ - vp_deprecated void init() { } + VP_DEPRECATED void init() { } /*! \deprecated You should rather use eye(). */ - vp_deprecated void setIdentity(); + VP_DEPRECATED void setIdentity(); //@} #endif }; diff --git a/modules/core/src/camera/vpXmlParserCamera.cpp b/modules/core/src/camera/vpXmlParserCamera.cpp index 6c35a05650..19d2a5241d 100644 --- a/modules/core/src/camera/vpXmlParserCamera.cpp +++ b/modules/core/src/camera/vpXmlParserCamera.cpp @@ -1144,20 +1144,20 @@ class vpXmlParserCamera::Impl node_tmp = node_model.append_child(pugi::node_comment); node_tmp.set_value("Distortion coefficients"); node_tmp = node_model.append_child(LABEL_XML_K1); - distortion_coefs.size() == index_0 ? node_tmp.append_child(pugi::node_pcdata).text() = 0 - : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[index_0]; + distortion_coefs.size() == index_0 ? (node_tmp.append_child(pugi::node_pcdata).text() = 0) + : (node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[index_0]); node_tmp = node_model.append_child(LABEL_XML_K2); - distortion_coefs.size() <= index_1 ? node_tmp.append_child(pugi::node_pcdata).text() = 0 - : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[index_1]; + distortion_coefs.size() <= index_1 ? (node_tmp.append_child(pugi::node_pcdata).text() = 0) + : (node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[index_1]); node_tmp = node_model.append_child(LABEL_XML_K3); - distortion_coefs.size() <= index_2 ? node_tmp.append_child(pugi::node_pcdata).text() = 0 - : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[index_2]; + distortion_coefs.size() <= index_2 ? (node_tmp.append_child(pugi::node_pcdata).text() = 0) + : (node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[index_2]); node_tmp = node_model.append_child(LABEL_XML_K4); - distortion_coefs.size() <= index_3 ? node_tmp.append_child(pugi::node_pcdata).text() = 0 - : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[index_3]; + distortion_coefs.size() <= index_3 ? (node_tmp.append_child(pugi::node_pcdata).text() = 0) + : (node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[index_3]); node_tmp = node_model.append_child(LABEL_XML_K5); - distortion_coefs.size() <= index_4 ? node_tmp.append_child(pugi::node_pcdata).text() = 0 - : node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[index_4]; + distortion_coefs.size() <= index_4 ? (node_tmp.append_child(pugi::node_pcdata).text() = 0) + : (node_tmp.append_child(pugi::node_pcdata).text() = distortion_coefs[index_4]); } vpCameraParameters camera; diff --git a/modules/core/src/display/vpDisplay_impl.h b/modules/core/src/display/vpDisplay_impl.h index ac6ecf450e..65f91861f2 100644 --- a/modules/core/src/display/vpDisplay_impl.h +++ b/modules/core/src/display/vpDisplay_impl.h @@ -212,11 +212,12 @@ void vp_display_display_ellipse(const vpImage &I, const vpImagePoint ¢ double n11_p = coef2; double n02_p = coef3; double num = n20_p - n02_p; - double d = num * num + 4.0 * n11_p * n11_p; // always >= 0 + double d = (num * num) + (4.0 * n11_p * n11_p); // always >= 0 if (d <= std::numeric_limits::epsilon()) { // circle e = 0.0; // case n20 = n02 and n11 = 0 : circle, e undefined - a = b = 2.0 * sqrt(n20_p); + b = 2.0 * sqrt(n20_p); + a = b; } else { // real ellipse e = atan2(2.0 * n11_p, num) / 2.0; // e in [-Pi/2 ; Pi/2] diff --git a/modules/core/src/image/vpImageConvert_opencv.cpp b/modules/core/src/image/vpImageConvert_opencv.cpp index d9630da13e..b748465ae6 100644 --- a/modules/core/src/image/vpImageConvert_opencv.cpp +++ b/modules/core/src/image/vpImageConvert_opencv.cpp @@ -45,6 +45,7 @@ #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) +BEGIN_VISP_NAMESPACE /*! Convert a cv::Mat to a vpImage\. @@ -516,4 +517,6 @@ void vpImageConvert::convert(const vpImage &src, cv::Mat &dest) cv::cvtColor(vpToMat, dest, cv::COLOR_RGB2BGR); } +END_VISP_NAMESPACE + #endif diff --git a/modules/core/src/image/vpImageConvert_yarp.cpp b/modules/core/src/image/vpImageConvert_yarp.cpp index 2173f17829..9128374a5d 100644 --- a/modules/core/src/image/vpImageConvert_yarp.cpp +++ b/modules/core/src/image/vpImageConvert_yarp.cpp @@ -39,6 +39,8 @@ #include #ifdef VISP_HAVE_YARP + +BEGIN_VISP_NAMESPACE /*! Convert a vpImage\ to a yarp::sig::ImageOf\ @@ -324,4 +326,6 @@ void vpImageConvert::convert(const yarp::sig::ImageOf *src, } } +END_VISP_NAMESPACE + #endif diff --git a/modules/core/src/image/vpRGBa.cpp b/modules/core/src/image/vpRGBa.cpp index ed70551af3..f676b88820 100644 --- a/modules/core/src/image/vpRGBa.cpp +++ b/modules/core/src/image/vpRGBa.cpp @@ -44,9 +44,9 @@ BEGIN_VISP_NAMESPACE /*! - Copy operator (from an unsigned char value) + Copy operator that initializes all the components to `v`. - \param v : Input color ( R = G = B = v ) + \param v : Value used to initialize the object ( R = G = B = v ). */ vpRGBa &vpRGBa::operator=(const unsigned char &v) { @@ -57,6 +57,36 @@ vpRGBa &vpRGBa::operator=(const unsigned char &v) return *this; } +/*! + Copy operator that initializes all the components to `v`. + + \param v : Value used to initialize the object ( R = G = B = v ). +*/ +vpRGBa &vpRGBa::operator=(const unsigned int &v) +{ + assert(v < 256); + this->R = v; + this->G = v; + this->B = v; + this->A = v; + return *this; +} + +/*! + Copy operator that initializes all the components to `v`. + + \param v : Value used to initialize the object ( R = G = B = v ). +*/ +vpRGBa &vpRGBa::operator=(const int &v) +{ + assert(v < 256); + this->R = v; + this->G = v; + this->B = v; + this->A = v; + return *this; +} + /*! Copy operator. */ @@ -251,10 +281,24 @@ bool vpRGBa::operator>(const vpRGBa &v) const return (gray1 > gray2); } -vpRGBa operator*(const double &x, const vpRGBa &rgb) { return rgb * x; } - /*! + * Scale RGB components by x. Alpha component remain unchanged. + * + * @param x : Value used to scale RGB color components. + * @param rgb : RGB color components to rescale. + * @return Rescaled components with RGB * x. + */ +vpRGBa operator*(const double &x, const vpRGBa &rgb) +{ + vpRGBa rgba; + rgba.R = rgb.R * x; + rgba.G = rgb.G * x; + rgba.B = rgb.B * x; + rgba.A = rgb.A; + return rgba; +} +/*! \relates vpRGBa Writes the RGBA values to the stream \e os, and @@ -262,17 +306,17 @@ vpRGBa operator*(const double &x, const vpRGBa &rgb) { return rgb * x; } coordinates are separated by a comma. The following code prints the intensity of the pixel in the middle of the image: -\code -#include + \code + #include -int main() -{ - vpImage I(480,640); + int main() + { + vpImage I(480,640); - std::cout << "RGB: " << I[240][320] << std::endl; + std::cout << "RGB: " << I[240][320] << std::endl; - return 0; -} + return 0; + } \endcode */ VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpRGBa &rgba) diff --git a/modules/core/src/image/vpRGBf.cpp b/modules/core/src/image/vpRGBf.cpp index 646b905d69..9181f0786a 100644 --- a/modules/core/src/image/vpRGBf.cpp +++ b/modules/core/src/image/vpRGBf.cpp @@ -45,7 +45,7 @@ BEGIN_VISP_NAMESPACE /*! - Copy operator (from a floating-point value) + Copy operator (from a floating-point value). \param v : Input color ( R = G = B = v ) */ @@ -57,6 +57,19 @@ vpRGBf &vpRGBf::operator=(float v) return *this; } +/*! + Copy operator. + + \param v : Input color ( R = G = B = v ) +*/ +vpRGBf &vpRGBf::operator=(int v) +{ + this->R = v; + this->G = v; + this->B = v; + return *this; +} + /*! Copy operator. */ @@ -252,7 +265,21 @@ bool vpRGBf::operator>(const vpRGBf &v) const return (gray1 > gray2); } -VISP_EXPORT VISP_NAMESPACE_ADDRESSING vpRGBf operator*(double x, const vpRGBf &rgb) { return rgb * x; } +/*! + * Scale RGB components by x. + * + * @param x : Value used to scale RGB color components. + * @param rgb : RGB color components to rescale. + * @return Rescaled components with RGB * x. + */ +vpRGBf operator*(double x, const vpRGBf &rgb) +{ + vpRGBf rgbf; + rgbf.R = rgb.R * x; + rgbf.G = rgb.G * x; + rgbf.B = rgb.B * x; + return rgbf; +} /*! \relates vpRGBf @@ -262,17 +289,17 @@ VISP_EXPORT VISP_NAMESPACE_ADDRESSING vpRGBf operator*(double x, const vpRGBf &r coordinates are separated by a comma. The following code prints the intensity of the pixel in the middle of the image: -\code -#include + \code + #include -int main() -{ - vpImage I(480,640); + int main() + { + vpImage I(480,640); - std::cout << "RGB: " << I[240][320] << std::endl; + std::cout << "RGB: " << I[240][320] << std::endl; - return 0; -} + return 0; + } \endcode */ VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpRGBf &rgb) diff --git a/modules/core/src/math/matrix/vpColVector.cpp b/modules/core/src/math/matrix/vpColVector.cpp index 7c0df736fc..65b6815032 100644 --- a/modules/core/src/math/matrix/vpColVector.cpp +++ b/modules/core/src/math/matrix/vpColVector.cpp @@ -141,6 +141,23 @@ vpMatrix vpColVector::operator*(const vpRowVector &v) const return M; } +vpMatrix vpColVector::operator*(const vpMatrix &M) const +{ + if (M.getRows() != 1) { + throw(vpException(vpException::dimensionError, + "Bad size during vpColVector (%dx1) and vpMatrix (%dx%d) multiplication", + getRows(), M.getRows(), M.getCols())); + } + vpMatrix R(rowNum, M.getCols()); + unsigned int M_cols = M.getCols(); + for (unsigned int i = 0; i < rowNum; ++i) { + for (unsigned int j = 0; j < M_cols; ++j) { + R[i][j] = (*this)[i] * M[0][j]; + } + } + return R; +} + vpColVector vpColVector::operator-(const vpColVector &m) const { if (getRows() != m.getRows()) { @@ -914,11 +931,10 @@ vpColVector vpColVector::hadamard(const vpColVector &v) const #if defined(VISP_HAVE_SIMDLIB) SimdVectorHadamard(data, v.data, rowNum, out.data); #else - -#endif for (unsigned int i = 0; i < dsize; ++i) { out.data[i] = data[i] * v.data[i]; } +#endif return out; } diff --git a/modules/core/src/math/matrix/vpEigenConversion.cpp b/modules/core/src/math/matrix/vpEigenConversion.cpp index f79a3510c5..2aed2b6a62 100644 --- a/modules/core/src/math/matrix/vpEigenConversion.cpp +++ b/modules/core/src/math/matrix/vpEigenConversion.cpp @@ -37,24 +37,24 @@ namespace VISP_NAMESPACE_NAME { #ifdef VISP_HAVE_EIGEN3 /* Eigen to ViSP */ -void eigen2visp(const Eigen::MatrixXd &src, VISP_NAMESPACE_ADDRESSING vpMatrix &dst) +void eigen2visp(const Eigen::MatrixXd &src, vpMatrix &dst) { dst.resize(static_cast(src.rows()), static_cast(src.cols()), false, false); Eigen::Map >(&dst.data[0], src.rows(), src.cols()) = src; } -void eigen2visp(const Eigen::MatrixXd &src, VISP_NAMESPACE_ADDRESSING vpHomogeneousMatrix &dst) +void eigen2visp(const Eigen::MatrixXd &src, vpHomogeneousMatrix &dst) { if ((src.rows() != 4) || (src.cols() != 4)) { - throw VISP_NAMESPACE_ADDRESSING vpException(VISP_NAMESPACE_ADDRESSING vpException::dimensionError, "Input Eigen Matrix must be of size (4,4)!"); + throw vpException(vpException::dimensionError, "Input Eigen Matrix must be of size (4,4)!"); } Eigen::Map >(&dst.data[0], src.rows(), src.cols()) = src; } -void eigen2visp(const Eigen::VectorXd &src, VISP_NAMESPACE_ADDRESSING vpColVector &dst) +void eigen2visp(const Eigen::VectorXd &src, vpColVector &dst) { dst.resize(static_cast(src.rows())); #if (VP_VERSION_INT(EIGEN_WORLD_VERSION, EIGEN_MAJOR_VERSION, EIGEN_MINOR_VERSION) < 0x030300) @@ -66,9 +66,9 @@ void eigen2visp(const Eigen::VectorXd &src, VISP_NAMESPACE_ADDRESSING vpColVecto #endif dst[static_cast(i)] = src(i); } - } +} -void eigen2visp(const Eigen::RowVectorXd &src, VISP_NAMESPACE_ADDRESSING vpRowVector &dst) +void eigen2visp(const Eigen::RowVectorXd &src, vpRowVector &dst) { dst.resize(static_cast(src.cols())); #if (VP_VERSION_INT(EIGEN_WORLD_VERSION, EIGEN_MAJOR_VERSION, EIGEN_MINOR_VERSION) < 0x030300) @@ -80,11 +80,11 @@ void eigen2visp(const Eigen::RowVectorXd &src, VISP_NAMESPACE_ADDRESSING vpRowVe #endif dst[static_cast(i)] = src(i); } - } +} -void visp2eigen(const VISP_NAMESPACE_ADDRESSING vpColVector &src, Eigen::VectorXd &dst) { dst = Eigen::VectorXd::Map(src.data, src.size()); } +void visp2eigen(const vpColVector &src, Eigen::VectorXd &dst) { dst = Eigen::VectorXd::Map(src.data, src.size()); } -void visp2eigen(const VISP_NAMESPACE_ADDRESSING vpRowVector &src, Eigen::RowVectorXd &dst) +void visp2eigen(const vpRowVector &src, Eigen::RowVectorXd &dst) { dst = Eigen::RowVectorXd::Map(src.data, src.size()); } diff --git a/modules/core/src/math/matrix/vpMatrix.cpp b/modules/core/src/math/matrix/vpMatrix.cpp index 14d87bb11f..7fdfe12f8a 100644 --- a/modules/core/src/math/matrix/vpMatrix.cpp +++ b/modules/core/src/math/matrix/vpMatrix.cpp @@ -123,8 +123,7 @@ vpMatrix subblock(const vpMatrix &M, unsigned int col, unsigned int row); /*! Construct a matrix as a sub-matrix of the input matrix \e M. - \sa init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int - nrows, unsigned int ncols) + \sa init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) */ vpMatrix::vpMatrix(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) : vpArray2D() @@ -140,6 +139,69 @@ vpMatrix::vpMatrix(const vpMatrix &M, unsigned int r, unsigned int c, unsigned i init(M, r, c, nrows, ncols); } +/*! + * Create a matrix from a homogeneous matrix. + * @param M : Homogeneous matrix. + */ +vpMatrix::vpMatrix(const vpHomogeneousMatrix &M) +{ + *this = M; +} + +/*! + * Create a matrix from a velocity twist matrix. + * @param V : Velocity twist matrix. + */ +vpMatrix::vpMatrix(const vpVelocityTwistMatrix &V) +{ + *this = V; +} + +/*! + * Create a matrix from a force twist matrix. + * @param F : Force twist matrix. + */ +vpMatrix::vpMatrix(const vpForceTwistMatrix &F) +{ + *this = F; +} + +/*! + * Create a matrix from a row vector. + * @param v : Row vector. + */ +vpMatrix::vpMatrix(const vpRotationMatrix &R) +{ + *this = R; +} + +/*! + * Create a matrix from a column vector. + * @param v : Column vector. + */ +vpMatrix::vpMatrix(const vpColVector &v) +{ + *this = v; +} + +/*! + * Create a matrix from a row vector. + * @param v : Row vector. + */ +vpMatrix::vpMatrix(const vpRowVector &v) +{ + *this = v; +} + +/*! + * Create a matrix from a row vector. + * @param v : Row vector. + */ +vpMatrix::vpMatrix(const vpTranslationVector &t) +{ + *this = t; +} + #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) vpMatrix::vpMatrix(vpMatrix &&A) : vpArray2D() { diff --git a/modules/core/src/math/matrix/vpMatrix_operations.cpp b/modules/core/src/math/matrix/vpMatrix_operations.cpp index 7686e8cd57..5c64ef18df 100644 --- a/modules/core/src/math/matrix/vpMatrix_operations.cpp +++ b/modules/core/src/math/matrix/vpMatrix_operations.cpp @@ -887,4 +887,87 @@ vpMatrix vpMatrix::kron(const vpMatrix &m1, const vpMatrix &m2) */ vpMatrix vpMatrix::kron(const vpMatrix &m) const { return kron(*this, m); } +vpMatrix vpMatrix::conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode) +{ + vpMatrix res; + conv2(M, kernel, res, mode); + return res; +} + +void vpMatrix::conv2(const vpMatrix &M, const vpMatrix &kernel, vpMatrix &res, const std::string &mode) +{ + if (((M.getRows() * M.getCols()) == 0) || ((kernel.getRows() * kernel.getCols()) == 0)) { + return; + } + + if (mode == "valid") { + if ((kernel.getRows() > M.getRows()) || (kernel.getCols() > M.getCols())) { + return; + } + } + + vpMatrix M_padded, res_same; + + if ((mode == "full") || (mode == "same")) { + const unsigned int pad_x = kernel.getCols() - 1; + const unsigned int pad_y = kernel.getRows() - 1; + const unsigned int pad = 2; + M_padded.resize(M.getRows() + (pad * pad_y), M.getCols() + (pad * pad_x), true, false); + M_padded.insert(M, pad_y, pad_x); + + if (mode == "same") { + res.resize(M.getRows(), M.getCols(), false, false); + res_same.resize(M.getRows() + pad_y, M.getCols() + pad_x, true, false); + } + else { + res.resize(M.getRows() + pad_y, M.getCols() + pad_x, true, false); + } + } + else if (mode == "valid") { + M_padded = M; + res.resize((M.getRows() - kernel.getRows()) + 1, (M.getCols() - kernel.getCols()) + 1); + } + else { + return; + } + + if (mode == "same") { + unsigned int res_same_rows = res_same.getRows(); + unsigned int res_same_cols = res_same.getCols(); + unsigned int kernel_rows = kernel.getRows(); + unsigned int kernel_cols = kernel.getCols(); + for (unsigned int i = 0; i < res_same_rows; ++i) { + for (unsigned int j = 0; j < res_same_cols; ++j) { + for (unsigned int k = 0; k < kernel_rows; ++k) { + for (unsigned int l = 0; l < kernel_cols; ++l) { + res_same[i][j] += M_padded[i + k][j + l] * kernel[kernel.getRows() - k - 1][kernel.getCols() - l - 1]; + } + } + } + } + + const unsigned int start_i = kernel.getRows() / 2; + const unsigned int start_j = kernel.getCols() / 2; + unsigned int m_rows = M.getRows(); + for (unsigned int i = 0; i < m_rows; ++i) { + memcpy(res.data + (i * M.getCols()), res_same.data + ((i + start_i) * res_same.getCols()) + start_j, + sizeof(double) * M.getCols()); + } + } + else { + unsigned int res_rows = res.getRows(); + unsigned int res_cols = res.getCols(); + unsigned int kernel_rows = kernel.getRows(); + unsigned int kernel_cols = kernel.getCols(); + for (unsigned int i = 0; i < res_rows; ++i) { + for (unsigned int j = 0; j < res_cols; ++j) { + for (unsigned int k = 0; k < kernel_rows; ++k) { + for (unsigned int l = 0; l < kernel_cols; ++l) { + res[i][j] += M_padded[i + k][j + l] * kernel[kernel.getRows() - k - 1][kernel.getCols() - l - 1]; + } + } + } + } + } +} END_VISP_NAMESPACE diff --git a/modules/core/src/math/matrix/vpMatrix_operators.cpp b/modules/core/src/math/matrix/vpMatrix_operators.cpp index bd575192ff..fea1937648 100644 --- a/modules/core/src/math/matrix/vpMatrix_operators.cpp +++ b/modules/core/src/math/matrix/vpMatrix_operators.cpp @@ -54,7 +54,6 @@ BEGIN_VISP_NAMESPACE vpRotationMatrix R; vpMatrix M = R; \endcode - */ vpMatrix &vpMatrix::operator=(const vpArray2D &A) { @@ -67,6 +66,160 @@ vpMatrix &vpMatrix::operator=(const vpArray2D &A) return *this; } +/*! + Copy operator that allows to convert a homogenous matrix to a matrix. + + \param R : Homogeneous matrix. + + The following example shows how to create a matrix from a homogenous matrix: + \code + vpHomogeneousMatrix M; + vpMatrix M = M; + \endcode +*/ +vpMatrix &vpMatrix::operator=(const vpHomogeneousMatrix &M) +{ + resize(M.getRows(), M.getCols(), false, false); + + if ((data != nullptr) && (M.data != nullptr) && (data != M.data)) { + memcpy(data, M.data, dsize * sizeof(double)); + } + + return *this; +} + +/*! + Copy operator that allows to convert a rotation matrix to a matrix. + + \param R : Rotation matrix. + + The following example shows how to create a matrix from a rotation matrix: + \code + vpRotationMatrix R; + vpMatrix M = R; + \endcode +*/ +vpMatrix &vpMatrix::operator=(const vpRotationMatrix &R) +{ + resize(R.getRows(), R.getCols(), false, false); + + if ((data != nullptr) && (R.data != nullptr) && (data != R.data)) { + memcpy(data, R.data, dsize * sizeof(double)); + } + + return *this; +} + +/*! + Copy operator that allows to convert a velocity twist matrix to a matrix. + + \param V : Velocity twist matrix. + + The following example shows how to create a matrix from a velocity twist matrix: + \code + vpVelocityTwistMatrix V; + vpMatrix M = V; + \endcode +*/ +vpMatrix &vpMatrix::operator=(const vpVelocityTwistMatrix &V) +{ + resize(V.getRows(), V.getCols(), false, false); + + if ((data != nullptr) && (V.data != nullptr) && (data != V.data)) { + memcpy(data, V.data, dsize * sizeof(double)); + } + + return *this; +} + +/*! + Copy operator that allows to convert a force twist matrix to a matrix. + + \param F : Force twist matrix. + + The following example shows how to create a matrix from a force twist matrix: + \code + vpForceTwistMatrix F; + vpMatrix M = F; + \endcode +*/ +vpMatrix &vpMatrix::operator=(const vpForceTwistMatrix &F) +{ + resize(F.getRows(), F.getCols(), false, false); + + if ((data != nullptr) && (F.data != nullptr) && (data != F.data)) { + memcpy(data, F.data, dsize * sizeof(double)); + } + + return *this; +} + +/*! + Copy operator that allows to convert a column vector to a matrix. + + \param v : Column vector. + + The following example shows how to create a matrix from a column vector: + \code + vpColVector v(3); + vpMatrix M = v; + \endcode +*/ +vpMatrix &vpMatrix::operator=(const vpColVector &v) +{ + resize(v.getRows(), v.getCols(), false, false); + + if ((data != nullptr) && (v.data != nullptr) && (data != v.data)) { + memcpy(data, v.data, dsize * sizeof(double)); + } + + return *this; +} + +/*! + Copy operator that allows to convert a row vector to a matrix. + + \param v : Column vector. + + The following example shows how to create a matrix from a row vector: + \code + vpRowVector v(3); + vpMatrix M = v; + \endcode +*/ +vpMatrix &vpMatrix::operator=(const vpRowVector &v) +{ + resize(v.getRows(), v.getCols(), false, false); + + if ((data != nullptr) && (v.data != nullptr) && (data != v.data)) { + memcpy(data, v.data, dsize * sizeof(double)); + } + + return *this; +} + +/*! + Copy operator that allows to convert a translation vector to a matrix. + + \param t : Translation vector. + + The following example shows how to create a matrix from a translation vector: + \code + vpTranslationVector t; + vpMatrix M = t; + \endcode +*/ +vpMatrix &vpMatrix::operator=(const vpTranslationVector &t) +{ + resize(t.getRows(), t.getCols(), false, false); + + if ((data != nullptr) && (t.data != nullptr) && (data != t.data)) { + memcpy(data, t.data, dsize * sizeof(double)); + } + + return *this; +} + vpMatrix &vpMatrix::operator=(const vpMatrix &A) { resize(A.getRows(), A.getCols(), false, false); diff --git a/modules/core/src/math/matrix/vpRowVector.cpp b/modules/core/src/math/matrix/vpRowVector.cpp index 7fc4dfb89f..42fff76a14 100644 --- a/modules/core/src/math/matrix/vpRowVector.cpp +++ b/modules/core/src/math/matrix/vpRowVector.cpp @@ -48,6 +48,10 @@ #include #include +#if defined(VISP_HAVE_SIMDLIB) +#include +#endif + BEGIN_VISP_NAMESPACE //! Copy operator. Allow operation such as A = v vpRowVector &vpRowVector::operator=(const vpRowVector &v) @@ -151,18 +155,18 @@ vpRowVector &vpRowVector::operator=(vpRowVector &&other) /*! Set vector elements from a list of double. \code -#include + #include -int main() -{ - vpRowVector r; - r = {1, 2, 3}; - std::cout << "r: " << r << std::endl; -} + int main() + { + vpRowVector r; + r = {1, 2, 3}; + std::cout << "r: " << r << std::endl; + } \endcode It produces the following printings: \code -r: 1 2 3 + r: 1 2 3 \endcode \sa operator<<() */ @@ -543,6 +547,7 @@ vpRowVector::vpRowVector(const vpMatrix &M, unsigned int i) : vpArray2D( (*this)[j] = M[i][j]; } } + /*! Constructor that creates a row vector from a 1-by-n matrix \e M. @@ -702,15 +707,15 @@ int main() If you run the previous example, you get: \code -mat: -1 2 3 4 -5 6 7 8 -9 10 11 12 -row vector: 1 2 3 4 5 6 7 8 9 10 11 12 -remat: -1 2 3 4 -5 6 7 8 -9 10 11 12 + mat: + 1 2 3 4 + 5 6 7 8 + 9 10 11 12 + row vector: 1 2 3 4 5 6 7 8 9 10 11 12 + remat: + 1 2 3 4 + 5 6 7 8 + 9 10 11 12 \endcode */ void vpRowVector::reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols) @@ -736,33 +741,34 @@ void vpRowVector::reshape(vpMatrix &M, const unsigned int &nrows, const unsigned /*! Insert a row vector. - \param i : Index of the first element to introduce. This index starts from -0. \param v : Row vector to insert. + \param i : Index of the first element to introduce. This index starts from 0. + \param v : Row vector to insert. The following example shows how to use this function: \code -#include + #include -int main() -{ - vpRowVector v(4); - for (unsigned int i=0; i < v.size(); i++) - v[i] = i; - std::cout << "v: " << v << std::endl; - - vpRowVector w(2); - for (unsigned int i=0; i < w.size(); i++) - w[i] = i+10; - std::cout << "w: " << w << std::endl; - - v.insert(1, w); - std::cout << "v: " << v << std::endl; -} \endcode + int main() + { + vpRowVector v(4); + for (unsigned int i=0; i < v.size(); i++) + v[i] = i; + std::cout << "v: " << v << std::endl; + + vpRowVector w(2); + for (unsigned int i=0; i < w.size(); i++) + w[i] = i+10; + std::cout << "w: " << w << std::endl; + + v.insert(1, w); + std::cout << "v: " << v << std::endl; + } + \endcode It produces the following output: \code -v: 0 1 2 3 -w: 10 11 -v: 0 10 11 3 + v: 0 1 2 3 + w: 10 11 + v: 0 10 11 3 \endcode */ void vpRowVector::insert(unsigned int i, const vpRowVector &v) @@ -1083,7 +1089,7 @@ int vpRowVector::print(std::ostream &s, unsigned int length, char const *intro) Return the sum of all the elements \f$v_{i}\f$ of the row vector v(n). \return The sum square value: \f$\sum_{j=0}^{n} v_j\f$. - */ + */ double vpRowVector::sum() const { double sum = 0.0; @@ -1100,7 +1106,7 @@ double vpRowVector::sum() const v(n). \return The sum square value: \f$\sum_{j=0}^{n} v_j^{2}\f$. - */ + */ double vpRowVector::sumSquare() const { double sum_square = 0.0; @@ -1117,7 +1123,7 @@ double vpRowVector::sumSquare() const Compute and return the Frobenius norm \f$ ||v|| = \sqrt{ \sum{v_{i}^2}} \f$. \return The Frobenius norm if the vector is initialized, 0 otherwise. -*/ + */ double vpRowVector::frobeniusNorm() const { double norm = sumSquare(); @@ -1167,8 +1173,8 @@ double vpRowVector::euclideanNorm() const { return frobeniusNorm(); } std::cout << "w: " << w << std::endl; } \endcode - It produces the following output: - \code + It produces the following output: + \code v: 0 1 2 3 w: 1 2 \endcode @@ -1244,23 +1250,23 @@ std::ostream &vpRowVector::cppPrint(std::ostream &os, const std::string &matrixN The following code \code -#include + #include -int main() -{ - std::ofstream ofs("log.csv", std::ofstream::out); - vpRowVector r(3); - for (unsigned int i=0; i + #include -int main() -{ - vpRowVector r(3); - for (unsigned int i=0; i + #include -int main() -{ - vpRotationMatrix R - R = { 0, 0, -1, 0, -1, 0, -1, 0, 0 }; - std::cout << "R:\n" << R << std::endl; -} - \endcode - It produces the following output: - \code -R: -0 0 -1 -0 -1 0 --1 0 0 + int main() + { + vpRotationMatrix R + R = { 0, 0, -1, 0, -1, 0, -1, 0, 0 }; + std::cout << "R:\n" << R << std::endl; + } + \endcode + It produces the following output: + \code + R: + 0 0 -1 + 0 -1 0 + -1 0 0 \endcode \sa operator<<() */ @@ -1112,7 +1112,7 @@ vpRotationMatrix vpRotationMatrix::mean(const std::vector &vec */ void vpRotationMatrix::orthogonalize() { - vpMatrix U = *this; + vpMatrix U(*this); vpColVector w; vpMatrix V; U.svd(w, V); diff --git a/modules/core/src/tools/file/vpIoTools_npy.cpp b/modules/core/src/tools/file/vpIoTools_npy.cpp index 640c08c6ed..f2d64cbac2 100644 --- a/modules/core/src/tools/file/vpIoTools_npy.cpp +++ b/modules/core/src/tools/file/vpIoTools_npy.cpp @@ -34,8 +34,6 @@ #include #include -BEGIN_VISP_NAMESPACE - #if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98) && defined(VISP_HAVE_MINIZ) #define USE_ZLIB_API 0 @@ -58,6 +56,7 @@ using namespace buminiz; #include + char visp::cnpy::BigEndianTest() { int x = 1; @@ -433,5 +432,3 @@ visp::cnpy::NpyArray visp::cnpy::npy_load(std::string fname) } #endif - -END_VISP_NAMESPACE diff --git a/modules/core/src/tools/geometry/vpRectOriented.cpp b/modules/core/src/tools/geometry/vpRectOriented.cpp index f2b482f190..104d396ad0 100644 --- a/modules/core/src/tools/geometry/vpRectOriented.cpp +++ b/modules/core/src/tools/geometry/vpRectOriented.cpp @@ -29,8 +29,7 @@ * * Description: * Defines a (possibly oriented) rectangle in the plane. - * -*****************************************************************************/ + */ #include #include @@ -125,7 +124,8 @@ vpRectOriented &vpRectOriented::operator=(const vpRect &rect) return *this; } -/** Conversion to vpRect operator. +/** + * Conversion to vpRect operator. */ vpRectOriented::operator vpRect() { diff --git a/modules/core/src/tools/optimization/vpLinProg.cpp b/modules/core/src/tools/optimization/vpLinProg.cpp index 67dbf4446d..3fa2ee080a 100644 --- a/modules/core/src/tools/optimization/vpLinProg.cpp +++ b/modules/core/src/tools/optimization/vpLinProg.cpp @@ -1,7 +1,6 @@ -/**************************************************************************** - * +/* * ViSP, open source Visual Servoing Platform software. - * Copyright (C) 2005 - 2023 by Inria. All rights reserved. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. * * This software is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,11 +29,7 @@ * * Description: * Linear Programming - * - * Authors: - * Olivier Kermorgant - * -*****************************************************************************/ + */ #include @@ -153,7 +148,7 @@ bool vpLinProg::colReduction(vpMatrix &A, vpColVector &b, bool full_rank, const while (A.getCols() < n - m) { // add next column and check rank of A^T.A if (!allZero(IQQt.getCol(j))) { - A = vpMatrix::juxtaposeMatrices(A, IQQt.getCol(j)); + A = vpMatrix::juxtaposeMatrices(A, vpMatrix(IQQt.getCol(j))); if (A.qr(Q, R, false, false, tol) != A.getCols()) A.resize(n, A.getCols() - 1, false); } @@ -196,7 +191,7 @@ bool vpLinProg::colReduction(vpMatrix &A, vpColVector &b, bool full_rank, const while (A.getCols() < n - r) { // add next column and check rank of A^T.A if (!allZero(IQQt.getCol(j))) { - A = vpMatrix::juxtaposeMatrices(A, IQQt.getCol(j)); + A = vpMatrix::juxtaposeMatrices(A, vpMatrix(IQQt.getCol(j))); if (A.qr(Q, R, false, false, tol) != A.getCols()) A.resize(n, A.getCols() - 1, false); } diff --git a/modules/core/src/tools/optimization/vpQuadProg.cpp b/modules/core/src/tools/optimization/vpQuadProg.cpp index 05a7d3d210..df912cd1ac 100644 --- a/modules/core/src/tools/optimization/vpQuadProg.cpp +++ b/modules/core/src/tools/optimization/vpQuadProg.cpp @@ -1,5 +1,4 @@ -/**************************************************************************** - * +/* * ViSP, open source Visual Servoing Platform software. * Copyright (C) 2005 - 2023 by Inria. All rights reserved. * @@ -30,11 +29,7 @@ * * Description: * Quadratic Programming - * - * Authors: - * Olivier Kermorgant - * -*****************************************************************************/ + */ #include #include diff --git a/modules/core/test/math/perfMatrixMultiplication.cpp b/modules/core/test/math/perfMatrixMultiplication.cpp index 30e40d8e28..93ab318a92 100644 --- a/modules/core/test/math/perfMatrixMultiplication.cpp +++ b/modules/core/test/math/perfMatrixMultiplication.cpp @@ -316,7 +316,7 @@ TEST_CASE("Benchmark matrix-rotation matrix multiplication", "[benchmark]") vpMatrix AB, AB_true; BENCHMARK(oss.str().c_str()) { - AB_true = dgemm_regular(A, B); + AB_true = dgemm_regular(A, static_cast(B)); return AB_true; }; @@ -388,7 +388,7 @@ TEST_CASE("Benchmark matrix-rotation matrix multiplication", "[benchmark]") vpRotationMatrix B(vpMath::deg(getRandomValues(0, 360)), vpMath::deg(getRandomValues(0, 360)), vpMath::deg(getRandomValues(0, 360))); - vpMatrix AB_true = dgemm_regular(A, B); + vpMatrix AB_true = dgemm_regular(A, static_cast(B)); vpMatrix AB = A * B; REQUIRE(equalMatrix(AB, AB_true)); } @@ -410,7 +410,7 @@ TEST_CASE("Benchmark matrix-homogeneous matrix multiplication", "[benchmark]") vpMatrix AB, AB_true; BENCHMARK(oss.str().c_str()) { - AB_true = dgemm_regular(A, B); + AB_true = dgemm_regular(A, static_cast(B)); return AB_true; }; @@ -483,9 +483,9 @@ TEST_CASE("Benchmark matrix-homogeneous matrix multiplication", "[benchmark]") vpMath::deg(getRandomValues(0, 360)), vpMath::deg(getRandomValues(0, 360)), vpMath::deg(getRandomValues(0, 360))); - vpMatrix AB_true = dgemm_regular(A, B); + vpMatrix AB_true = dgemm_regular(A, static_cast(B)); vpMatrix AB; - vpMatrix::mult2Matrices(A, B, AB); + vpMatrix::mult2Matrices(A, static_cast(B), AB); REQUIRE(equalMatrix(AB, AB_true)); } } @@ -505,7 +505,7 @@ TEST_CASE("Benchmark matrix-vector multiplication", "[benchmark]") vpColVector C, C_true; BENCHMARK(oss.str().c_str()) { - C_true = dgemv_regular(A, B); + C_true = dgemv_regular(A, static_cast(B)); return C_true; }; @@ -516,7 +516,7 @@ TEST_CASE("Benchmark matrix-vector multiplication", "[benchmark]") C = A * B; return C; }; - REQUIRE(equalMatrix(C, C_true)); + REQUIRE(equalMatrix(static_cast(C), static_cast(C_true))); if (runBenchmarkAll) { #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) @@ -574,7 +574,7 @@ TEST_CASE("Benchmark matrix-vector multiplication", "[benchmark]") vpColVector C_true = dgemv_regular(A, B); vpColVector C = A * B; - REQUIRE(equalMatrix(C, C_true)); + REQUIRE(equalMatrix(static_cast(C), static_cast(C_true))); } } @@ -747,7 +747,7 @@ TEST_CASE("Benchmark matrix-velocity twist multiplication", "[benchmark]") vpMatrix AV, AV_true; BENCHMARK(oss.str().c_str()) { - AV_true = dgemm_regular(A, V); + AV_true = dgemm_regular(A, static_cast(V)); return AV_true; }; @@ -817,7 +817,7 @@ TEST_CASE("Benchmark matrix-velocity twist multiplication", "[benchmark]") vpMatrix A = generateRandomMatrix(rows, cols); vpVelocityTwistMatrix V(vpTranslationVector(0.1, -0.4, 1.5), vpThetaUVector(0.4, -0.1, 0.7)); - vpMatrix AV_true = dgemm_regular(A, V); + vpMatrix AV_true = dgemm_regular(A, static_cast(V)); vpMatrix AV = A * V; REQUIRE(equalMatrix(AV, AV_true)); } @@ -837,7 +837,7 @@ TEST_CASE("Benchmark matrix-force twist multiplication", "[benchmark]") vpMatrix AV, AV_true; BENCHMARK(oss.str().c_str()) { - AV_true = dgemm_regular(A, V); + AV_true = dgemm_regular(A, static_cast(V)); return AV_true; }; @@ -907,7 +907,7 @@ TEST_CASE("Benchmark matrix-force twist multiplication", "[benchmark]") vpMatrix A = generateRandomMatrix(rows, cols); vpForceTwistMatrix V(vpTranslationVector(0.1, -0.4, 1.5), vpThetaUVector(0.4, -0.1, 0.7)); - vpMatrix AV_true = dgemm_regular(A, V); + vpMatrix AV_true = dgemm_regular(A, static_cast(V)); vpMatrix AV = A * V; REQUIRE(equalMatrix(AV, AV_true)); } diff --git a/modules/core/test/math/testEigenConversion.cpp b/modules/core/test/math/testEigenConversion.cpp index 10fb1b1e31..1eb36f7086 100644 --- a/modules/core/test/math/testEigenConversion.cpp +++ b/modules/core/test/math/testEigenConversion.cpp @@ -308,7 +308,7 @@ TEST_CASE("Eigen::RowVector4d <--> vpRowVector conversion", "[eigen_conversion]" std::cout << "ViSP vpRowVector: " << visp_row << std::endl; Eigen::RowVector4d eigen_row2; - VISP_NAMESPACE_NAME::visp2eigen(visp_row, eigen_row2); + VISP_NAMESPACE_NAME::visp2eigen(static_cast(visp_row), eigen_row2); std::cout << "Eigen RowVector4d: " << eigen_row2 << std::endl; vpRowVector visp_row2; @@ -322,11 +322,11 @@ TEST_CASE("vpRowVector <--> Eigen::RowVector4d conversion", "[eigen_conversion]" vpRowVector visp_row(4, 10); visp_row = 10; Eigen::RowVector4d eigen_row; - VISP_NAMESPACE_NAME::visp2eigen(visp_row, eigen_row); + VISP_NAMESPACE_NAME::visp2eigen(static_cast(visp_row), eigen_row); std::cout << "Eigen RowVector4d: " << eigen_row << std::endl; vpRowVector visp_row2; - VISP_NAMESPACE_NAME::eigen2visp(eigen_row, visp_row2); + VISP_NAMESPACE_NAME::eigen2visp(static_cast(eigen_row), visp_row2); std::cout << "ViSP vpRowVector: " << visp_row2 << std::endl; REQUIRE(visp_row == visp_row2); std::cout << std::endl; diff --git a/modules/core/test/math/testMatrix.cpp b/modules/core/test/math/testMatrix.cpp index 7092d0aa33..52c4268320 100644 --- a/modules/core/test/math/testMatrix.cpp +++ b/modules/core/test/math/testMatrix.cpp @@ -195,11 +195,11 @@ int main(int argc, char *argv[]) vpMatrix M(3, 3); M[2][0] = M[1][1] = M[0][2] = 1.; vpRotationMatrix R1(M); - if (test("R1", R1, bench) == false) + if (test("R1", static_cast(R1), bench) == false) return EXIT_FAILURE; vpRotationMatrix R2; R2 = M; - if (test("R2", R2, bench) == false) + if (test("R2", static_cast(R2), bench) == false) return EXIT_FAILURE; } { @@ -289,7 +289,7 @@ int main(int argc, char *argv[]) std::cout << "M1: \n" << M1 << std::endl; vpMatrix M2(M1); std::cout << "M2: \n" << M2 << std::endl; - vpMatrix M3 = R; + vpMatrix M3 = static_cast(R); std::cout << "M3: \n" << M3 << std::endl; vpMatrix M4 = M1; std::cout << "M4: \n" << M4 << std::endl; diff --git a/modules/core/test/math/testRand.cpp b/modules/core/test/math/testRand.cpp index aa07d1378f..7ab6b54b4a 100644 --- a/modules/core/test/math/testRand.cpp +++ b/modules/core/test/math/testRand.cpp @@ -110,7 +110,7 @@ class vpUniRandOld public: //! Default constructor. - explicit vpUniRandOld(const long seed = 0) + VP_EXPLICIT vpUniRandOld(const long seed = 0) : a(16807), m(2147483647), q(127773), r(2836), normalizer(2147484721.0), x((seed) ? seed : 739806647) { } diff --git a/modules/detection/include/visp3/detection/vpDetectorAprilTag.h b/modules/detection/include/visp3/detection/vpDetectorAprilTag.h index 7b8d4411e5..47d9cd0cfe 100644 --- a/modules/detection/include/visp3/detection/vpDetectorAprilTag.h +++ b/modules/detection/include/visp3/detection/vpDetectorAprilTag.h @@ -249,8 +249,8 @@ class VISP_EXPORT vpDetectorAprilTag : public vpDetectorBase const vpPoseEstimationMethod &poseEstimationMethod = HOMOGRAPHY_VIRTUAL_VS); vpDetectorAprilTag(const vpDetectorAprilTag &o); vpDetectorAprilTag &operator=(vpDetectorAprilTag o); - virtual ~vpDetectorAprilTag() vp_override; - bool detect(const vpImage &I) vp_override; + virtual ~vpDetectorAprilTag() VP_OVERRIDE; + bool detect(const vpImage &I) VP_OVERRIDE; bool detect(const vpImage &I, double tagSize, const vpCameraParameters &cam, @@ -312,8 +312,8 @@ class VISP_EXPORT vpDetectorAprilTag : public vpDetectorBase @name Deprecated functions */ //@{ - vp_deprecated void setAprilTagRefinePose(bool refinePose); - vp_deprecated void setAprilTagRefineDecode(bool refineDecode); + VP_DEPRECATED void setAprilTagRefinePose(bool refinePose); + VP_DEPRECATED void setAprilTagRefineDecode(bool refineDecode); //@} #endif diff --git a/modules/detection/include/visp3/detection/vpDetectorDataMatrixCode.h b/modules/detection/include/visp3/detection/vpDetectorDataMatrixCode.h index 2bee838e0a..d7b6a130ad 100644 --- a/modules/detection/include/visp3/detection/vpDetectorDataMatrixCode.h +++ b/modules/detection/include/visp3/detection/vpDetectorDataMatrixCode.h @@ -107,11 +107,11 @@ BEGIN_VISP_NAMESPACE * Other examples are also provided in tutorial-barcode-detector.cpp and * tutorial-barcode-detector-live.cpp */ -class VISP_EXPORT vpDetectorDataMatrixCode : public vpDetectorBase + class VISP_EXPORT vpDetectorDataMatrixCode : public vpDetectorBase { public: vpDetectorDataMatrixCode(); - bool detect(const vpImage &I) vp_override; + bool detect(const vpImage &I) VP_OVERRIDE; }; END_VISP_NAMESPACE #endif diff --git a/modules/detection/include/visp3/detection/vpDetectorFace.h b/modules/detection/include/visp3/detection/vpDetectorFace.h index 7aee7d6543..ed5514fb4e 100644 --- a/modules/detection/include/visp3/detection/vpDetectorFace.h +++ b/modules/detection/include/visp3/detection/vpDetectorFace.h @@ -93,7 +93,7 @@ class VISP_EXPORT vpDetectorFace : public vpDetectorBase public: vpDetectorFace(); - bool detect(const vpImage &I) vp_override; + bool detect(const vpImage &I) VP_OVERRIDE; bool detect(const cv::Mat &frame_gray); void setCascadeClassifierFile(const std::string &filename); }; diff --git a/modules/detection/include/visp3/detection/vpDetectorQRCode.h b/modules/detection/include/visp3/detection/vpDetectorQRCode.h index 1fa5b37e57..1ceb0f780d 100644 --- a/modules/detection/include/visp3/detection/vpDetectorQRCode.h +++ b/modules/detection/include/visp3/detection/vpDetectorQRCode.h @@ -114,7 +114,7 @@ class VISP_EXPORT vpDetectorQRCode : public vpDetectorBase public: vpDetectorQRCode(); - bool detect(const vpImage &I) vp_override; + bool detect(const vpImage &I) VP_OVERRIDE; }; END_VISP_NAMESPACE #endif diff --git a/modules/gui/include/visp3/gui/vpD3DRenderer.h b/modules/gui/include/visp3/gui/vpD3DRenderer.h index 586ca8c3a2..cdd4e724e9 100644 --- a/modules/gui/include/visp3/gui/vpD3DRenderer.h +++ b/modules/gui/include/visp3/gui/vpD3DRenderer.h @@ -95,7 +95,7 @@ class VISP_EXPORT vpD3DRenderer : public vpWin32Renderer bool render(); vpD3DRenderer(); - virtual ~vpD3DRenderer() vp_override; + virtual ~vpD3DRenderer() VP_OVERRIDE; void setImg(const vpImage &im); void setImg(const vpImage &im); @@ -122,7 +122,7 @@ class VISP_EXPORT vpD3DRenderer : public vpWin32Renderer void drawArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int w, unsigned int h, unsigned int thickness = 1); - void getImage(vpImage &I) vp_override; + void getImage(vpImage &I) VP_OVERRIDE; private: void initView(float, float); diff --git a/modules/gui/include/visp3/gui/vpDisplayGTK.h b/modules/gui/include/visp3/gui/vpDisplayGTK.h index 61a3ba1ee6..f97e887d07 100644 --- a/modules/gui/include/visp3/gui/vpDisplayGTK.h +++ b/modules/gui/include/visp3/gui/vpDisplayGTK.h @@ -161,67 +161,67 @@ class VISP_EXPORT vpDisplayGTK : public vpDisplay vpDisplayGTK(vpImage &I, int win_x = -1, int win_y = -1, const std::string &win_title = "", vpScaleType type = SCALE_DEFAULT); - virtual ~vpDisplayGTK() vp_override; + virtual ~vpDisplayGTK() VP_OVERRIDE; - void getImage(vpImage &I) vp_override; + void getImage(vpImage &I) VP_OVERRIDE; unsigned int getScreenDepth(); - unsigned int getScreenHeight() vp_override; - void getScreenSize(unsigned int &screen_width, unsigned int &screen_height) vp_override; - unsigned int getScreenWidth() vp_override; + unsigned int getScreenHeight() VP_OVERRIDE; + void getScreenSize(unsigned int &screen_width, unsigned int &screen_height) VP_OVERRIDE; + unsigned int getScreenWidth() VP_OVERRIDE; - void init(vpImage &I, int win_x = -1, int win_y = -1, const std::string &win_title = "") vp_override; - void init(vpImage &I, int win_x = -1, int win_y = -1, const std::string &win_title = "") vp_override; + void init(vpImage &I, int win_x = -1, int win_y = -1, const std::string &win_title = "") VP_OVERRIDE; + void init(vpImage &I, int win_x = -1, int win_y = -1, const std::string &win_title = "") VP_OVERRIDE; void init(unsigned int win_width, unsigned int win_height, int win_x = -1, int win_y = -1, - const std::string &win_title = "") vp_override; + const std::string &win_title = "") VP_OVERRIDE; protected: - void setFont(const std::string &fontname) vp_override; - void setTitle(const std::string &win_title) vp_override; - void setWindowPosition(int win_x, int win_y) vp_override; + void setFont(const std::string &fontname) VP_OVERRIDE; + void setTitle(const std::string &win_title) VP_OVERRIDE; + void setWindowPosition(int win_x, int win_y) VP_OVERRIDE; - void clearDisplay(const vpColor &color = vpColor::white) vp_override; + void clearDisplay(const vpColor &color = vpColor::white) VP_OVERRIDE; - void closeDisplay() vp_override; + void closeDisplay() VP_OVERRIDE; void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white, - unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) vp_override; + unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) VP_OVERRIDE; void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill = false, - unsigned int thickness = 1) vp_override; - void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; + void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, - unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; - void displayImage(const vpImage &I) vp_override; - void displayImage(const vpImage &I) vp_override; + void displayImage(const vpImage &I) VP_OVERRIDE; + void displayImage(const vpImage &I) VP_OVERRIDE; void displayImage(const unsigned char *I); void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, - unsigned int height) vp_override; - void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override; + unsigned int height) VP_OVERRIDE; + void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE; - void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) vp_override; + void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; - void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) vp_override; + void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, - bool fill = false, unsigned int thickness = 1) vp_override; + bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color, - bool fill = false, unsigned int thickness = 1) vp_override; - void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) vp_override; - - void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) vp_override; - - void flushDisplay() vp_override; - void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override; - - bool getClick(bool blocking = true) vp_override; - bool getClick(vpImagePoint &ip, bool blocking = true) vp_override; - bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) vp_override; - bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) vp_override; - bool getKeyboardEvent(bool blocking = true) vp_override; - bool getKeyboardEvent(std::string &key, bool blocking = true) vp_override; - bool getPointerMotionEvent(vpImagePoint &ip) vp_override; - bool getPointerPosition(vpImagePoint &ip) vp_override; + bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; + void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; + + void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) VP_OVERRIDE; + + void flushDisplay() VP_OVERRIDE; + void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE; + + bool getClick(bool blocking = true) VP_OVERRIDE; + bool getClick(vpImagePoint &ip, bool blocking = true) VP_OVERRIDE; + bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE; + bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE; + bool getKeyboardEvent(bool blocking = true) VP_OVERRIDE; + bool getKeyboardEvent(std::string &key, bool blocking = true) VP_OVERRIDE; + bool getPointerMotionEvent(vpImagePoint &ip) VP_OVERRIDE; + bool getPointerPosition(vpImagePoint &ip) VP_OVERRIDE; private: // Implementation diff --git a/modules/gui/include/visp3/gui/vpDisplayOpenCV.h b/modules/gui/include/visp3/gui/vpDisplayOpenCV.h index ff4e84fafb..e2d431ed5f 100644 --- a/modules/gui/include/visp3/gui/vpDisplayOpenCV.h +++ b/modules/gui/include/visp3/gui/vpDisplayOpenCV.h @@ -198,66 +198,66 @@ class VISP_EXPORT vpDisplayOpenCV : public vpDisplay vpDisplayOpenCV(vpImage &I, int winx = -1, int winy = -1, const std::string &title = "", vpScaleType type = SCALE_DEFAULT); - virtual ~vpDisplayOpenCV() vp_override; + virtual ~vpDisplayOpenCV() VP_OVERRIDE; - void getImage(vpImage &I) vp_override; - unsigned int getScreenHeight() vp_override; - void getScreenSize(unsigned int &width, unsigned int &height) vp_override; - unsigned int getScreenWidth() vp_override; + void getImage(vpImage &I) VP_OVERRIDE; + unsigned int getScreenHeight() VP_OVERRIDE; + void getScreenSize(unsigned int &width, unsigned int &height) VP_OVERRIDE; + unsigned int getScreenWidth() VP_OVERRIDE; - void init(vpImage &I, int winx = -1, int winy = -1, const std::string &title = "") vp_override; - void init(vpImage &I, int winx = -1, int winy = -1, const std::string &title = "") vp_override; - void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "") vp_override; + void init(vpImage &I, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE; + void init(vpImage &I, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE; + void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE; protected: - void setFont(const std::string &font) vp_override; - void setTitle(const std::string &title) vp_override; - void setWindowPosition(int winx, int winy) vp_override; + void setFont(const std::string &font) VP_OVERRIDE; + void setTitle(const std::string &title) VP_OVERRIDE; + void setWindowPosition(int winx, int winy) VP_OVERRIDE; - void clearDisplay(const vpColor &color = vpColor::white) vp_override; + void clearDisplay(const vpColor &color = vpColor::white) VP_OVERRIDE; - void closeDisplay() vp_override; + void closeDisplay() VP_OVERRIDE; void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white, - unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) vp_override; + unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) VP_OVERRIDE; void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill = false, - unsigned int thickness = 1) vp_override; - void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; + void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, - unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; - void displayImage(const vpImage &I) vp_override; - void displayImage(const vpImage &I) vp_override; + void displayImage(const vpImage &I) VP_OVERRIDE; + void displayImage(const vpImage &I) VP_OVERRIDE; void displayImage(const unsigned char *I); void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, - unsigned int height) vp_override; - void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override; + unsigned int height) VP_OVERRIDE; + void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE; - void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) vp_override; - void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) vp_override; + void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; + void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, - bool fill = false, unsigned int thickness = 1) vp_override; + bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color, - bool fill = false, unsigned int thickness = 1) vp_override; - void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) vp_override; + bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; + void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; - void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) vp_override; + void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) VP_OVERRIDE; - void flushDisplay() vp_override; - void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override; + void flushDisplay() VP_OVERRIDE; + void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE; - bool getClick(bool blocking = true) vp_override; - bool getClick(vpImagePoint &ip, bool blocking = true) vp_override; - bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) vp_override; - bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) vp_override; + bool getClick(bool blocking = true) VP_OVERRIDE; + bool getClick(vpImagePoint &ip, bool blocking = true) VP_OVERRIDE; + bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE; + bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE; - bool getKeyboardEvent(bool blocking = true) vp_override; - bool getKeyboardEvent(std::string &key, bool blocking = true) vp_override; - bool getPointerMotionEvent(vpImagePoint &ip) vp_override; - bool getPointerPosition(vpImagePoint &ip) vp_override; + bool getKeyboardEvent(bool blocking = true) VP_OVERRIDE; + bool getKeyboardEvent(std::string &key, bool blocking = true) VP_OVERRIDE; + bool getPointerMotionEvent(vpImagePoint &ip) VP_OVERRIDE; + bool getPointerPosition(vpImagePoint &ip) VP_OVERRIDE; static void on_mouse(int event, int x, int y, int flags, void *param); diff --git a/modules/gui/include/visp3/gui/vpDisplayWin32.h b/modules/gui/include/visp3/gui/vpDisplayWin32.h index 9f6734ec50..dd8daaf9d4 100644 --- a/modules/gui/include/visp3/gui/vpDisplayWin32.h +++ b/modules/gui/include/visp3/gui/vpDisplayWin32.h @@ -115,78 +115,78 @@ class VISP_EXPORT vpDisplayWin32 : public vpDisplay friend void vpCreateWindow(threadParam *param); public: - explicit vpDisplayWin32(vpWin32Renderer *rend = nullptr); + VP_EXPLICIT vpDisplayWin32(vpWin32Renderer *rend = nullptr); vpDisplayWin32(vpImage &I, int winx = -1, int winy = -1, const std::string &title = ""); vpDisplayWin32(vpImage &I, int winx = -1, int winy = -1, const std::string &title = ""); - virtual ~vpDisplayWin32() vp_override; + virtual ~vpDisplayWin32() VP_OVERRIDE; - void clearDisplay(const vpColor &color = vpColor::white) vp_override; - void closeDisplay() vp_override; - void displayImage(const vpImage &I) vp_override; - void displayImage(const vpImage &I) vp_override; + void clearDisplay(const vpColor &color = vpColor::white) VP_OVERRIDE; + void closeDisplay() VP_OVERRIDE; + void displayImage(const vpImage &I) VP_OVERRIDE; + void displayImage(const vpImage &I) VP_OVERRIDE; void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, - unsigned int height) vp_override; - void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override; + unsigned int height) VP_OVERRIDE; + void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE; - void flushDisplay() vp_override; - void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override; + void flushDisplay() VP_OVERRIDE; + void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE; - void getImage(vpImage &I) vp_override; - unsigned int getScreenHeight() vp_override; - void getScreenSize(unsigned int &width, unsigned int &height) vp_override; - unsigned int getScreenWidth() vp_override; + void getImage(vpImage &I) VP_OVERRIDE; + unsigned int getScreenHeight() VP_OVERRIDE; + void getScreenSize(unsigned int &width, unsigned int &height) VP_OVERRIDE; + unsigned int getScreenWidth() VP_OVERRIDE; - void init(vpImage &I, int winx = -1, int winy = -1, const std::string &title = "") vp_override; - void init(vpImage &I, int winx = -1, int winy = -1, const std::string &title = "") vp_override; - void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "") vp_override; + void init(vpImage &I, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE; + void init(vpImage &I, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE; + void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE; - void setFont(const std::string &fontname) vp_override; + void setFont(const std::string &fontname) VP_OVERRIDE; void setDownScalingFactor(unsigned int scale) { window.setScale(scale); m_scale = scale; } void setDownScalingFactor(vpScaleType scaleType) { m_scaleType = scaleType; } - void setTitle(const std::string &windowtitle) vp_override; - void setWindowPosition(int winx, int winy) vp_override; + void setTitle(const std::string &windowtitle) VP_OVERRIDE; + void setWindowPosition(int winx, int winy) VP_OVERRIDE; protected: void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white, - unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) vp_override; + unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) VP_OVERRIDE; void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill = false, - unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; - void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) vp_override; + void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, - unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; - void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) vp_override; + void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; - void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) vp_override; + void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, - bool fill = false, unsigned int thickness = 1) vp_override; + bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color, - bool fill = false, unsigned int thickness = 1) vp_override; - void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) vp_override; + bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; + void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; - void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) vp_override; + void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) VP_OVERRIDE; - bool getClick(bool blocking = true) vp_override; - bool getClick(vpImagePoint &ip, bool blocking = true) vp_override; - bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) vp_override; - bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) vp_override; + bool getClick(bool blocking = true) VP_OVERRIDE; + bool getClick(vpImagePoint &ip, bool blocking = true) VP_OVERRIDE; + bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE; + bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE; - bool getKeyboardEvent(bool blocking = true) vp_override; - bool getKeyboardEvent(std::string &key, bool blocking) vp_override; - bool getPointerMotionEvent(vpImagePoint &ip) vp_override; - bool getPointerPosition(vpImagePoint &ip) vp_override; + bool getKeyboardEvent(bool blocking = true) VP_OVERRIDE; + bool getKeyboardEvent(std::string &key, bool blocking) VP_OVERRIDE; + bool getPointerMotionEvent(vpImagePoint &ip) VP_OVERRIDE; + bool getPointerPosition(vpImagePoint &ip) VP_OVERRIDE; void waitForInit(); }; diff --git a/modules/gui/include/visp3/gui/vpDisplayX.h b/modules/gui/include/visp3/gui/vpDisplayX.h index 5ad842eb1f..f416d4eed3 100644 --- a/modules/gui/include/visp3/gui/vpDisplayX.h +++ b/modules/gui/include/visp3/gui/vpDisplayX.h @@ -157,69 +157,69 @@ class VISP_EXPORT vpDisplayX : public vpDisplay vpDisplayX(vpImage &I, int winx = -1, int winy = -1, const std::string &title = "", vpScaleType type = SCALE_DEFAULT); - virtual ~vpDisplayX() vp_override; + virtual ~vpDisplayX() VP_OVERRIDE; - void getImage(vpImage &I) vp_override; + void getImage(vpImage &I) VP_OVERRIDE; unsigned int getScreenDepth(); - unsigned int getScreenHeight() vp_override; - void getScreenSize(unsigned int &width, unsigned int &height) vp_override; - unsigned int getScreenWidth() vp_override; + unsigned int getScreenHeight() VP_OVERRIDE; + void getScreenSize(unsigned int &width, unsigned int &height) VP_OVERRIDE; + unsigned int getScreenWidth() VP_OVERRIDE; - void init(vpImage &I, int win_x = -1, int win_y = -1, const std::string &win_title = "") vp_override; - void init(vpImage &I, int win_x = -1, int win_y = -1, const std::string &win_title = "") vp_override; + void init(vpImage &I, int win_x = -1, int win_y = -1, const std::string &win_title = "") VP_OVERRIDE; + void init(vpImage &I, int win_x = -1, int win_y = -1, const std::string &win_title = "") VP_OVERRIDE; void init(unsigned int win_width, unsigned int win_height, int win_x = -1, int win_y = -1, - const std::string &win_title = "") vp_override; + const std::string &win_title = "") VP_OVERRIDE; protected: - void clearDisplay(const vpColor &color = vpColor::white) vp_override; + void clearDisplay(const vpColor &color = vpColor::white) VP_OVERRIDE; - void closeDisplay() vp_override; + void closeDisplay() VP_OVERRIDE; void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white, - unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) vp_override; + unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) VP_OVERRIDE; void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill = false, - unsigned int thickness = 1) vp_override; - void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; + void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, - unsigned int thickness = 1) vp_override; + unsigned int thickness = 1) VP_OVERRIDE; - void displayImage(const vpImage &I) vp_override; - void displayImage(const vpImage &I) vp_override; + void displayImage(const vpImage &I) VP_OVERRIDE; + void displayImage(const vpImage &I) VP_OVERRIDE; void displayImage(const unsigned char *I); void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, - unsigned int height) vp_override; - void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override; + unsigned int height) VP_OVERRIDE; + void displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE; - void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) vp_override; - void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) vp_override; + void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; + void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE; void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, - bool fill = false, unsigned int thickness = 1) vp_override; + bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color, - bool fill = false, unsigned int thickness = 1) vp_override; - void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) vp_override; + bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; + void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) VP_OVERRIDE; - void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) vp_override; + void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) VP_OVERRIDE; - void flushDisplay() vp_override; - void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override; + void flushDisplay() VP_OVERRIDE; + void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE; - bool getClick(bool blocking = true) vp_override; - bool getClick(vpImagePoint &ip, bool blocking = true) vp_override; - bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) vp_override; - bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) vp_override; + bool getClick(bool blocking = true) VP_OVERRIDE; + bool getClick(vpImagePoint &ip, bool blocking = true) VP_OVERRIDE; + bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE; + bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE; - bool getKeyboardEvent(bool blocking = true) vp_override; - bool getKeyboardEvent(std::string &key, bool blocking = true) vp_override; + bool getKeyboardEvent(bool blocking = true) VP_OVERRIDE; + bool getKeyboardEvent(std::string &key, bool blocking = true) VP_OVERRIDE; - bool getPointerMotionEvent(vpImagePoint &ip) vp_override; - bool getPointerPosition(vpImagePoint &ip) vp_override; + bool getPointerMotionEvent(vpImagePoint &ip) VP_OVERRIDE; + bool getPointerPosition(vpImagePoint &ip) VP_OVERRIDE; - void setFont(const std::string &font) vp_override; - void setTitle(const std::string &title) vp_override; - void setWindowPosition(int win_x, int win_y) vp_override; + void setFont(const std::string &font) VP_OVERRIDE; + void setTitle(const std::string &title) VP_OVERRIDE; + void setWindowPosition(int win_x, int win_y) VP_OVERRIDE; private: // Implementation diff --git a/modules/gui/include/visp3/gui/vpGDIRenderer.h b/modules/gui/include/visp3/gui/vpGDIRenderer.h index 894b2a9aa4..71a975d985 100644 --- a/modules/gui/include/visp3/gui/vpGDIRenderer.h +++ b/modules/gui/include/visp3/gui/vpGDIRenderer.h @@ -108,7 +108,7 @@ class VISP_EXPORT vpGDIRenderer : public vpWin32Renderer void drawArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int w, unsigned int h, unsigned int thickness = 1); - void getImage(vpImage &I) vp_override; + void getImage(vpImage &I) VP_OVERRIDE; private: // updates the renderer hbitmaps. diff --git a/modules/gui/include/visp3/gui/vpProjectionDisplay.h b/modules/gui/include/visp3/gui/vpProjectionDisplay.h index a05bfe5b01..50aeaf5503 100644 --- a/modules/gui/include/visp3/gui/vpProjectionDisplay.h +++ b/modules/gui/include/visp3/gui/vpProjectionDisplay.h @@ -101,7 +101,7 @@ class VISP_EXPORT vpProjectionDisplay { init(); } - explicit vpProjectionDisplay(int select) + VP_EXPLICIT vpProjectionDisplay(int select) : Icam(), Iext(), #if defined(VISP_HAVE_DISPLAY) dIcam(), dIext(), diff --git a/modules/gui/include/visp3/gui/vpWin32Window.h b/modules/gui/include/visp3/gui/vpWin32Window.h index b96f73c0b3..4df54bd97f 100644 --- a/modules/gui/include/visp3/gui/vpWin32Window.h +++ b/modules/gui/include/visp3/gui/vpWin32Window.h @@ -109,7 +109,7 @@ class VISP_EXPORT vpWin32Window vpWin32Renderer *renderer; public: - explicit vpWin32Window(vpWin32Renderer *rend = nullptr); + VP_EXPLICIT vpWin32Window(vpWin32Renderer *rend = nullptr); virtual ~vpWin32Window(); HWND getHWnd() { return hWnd; } diff --git a/modules/gui/test/display/testDisplayRoi.cpp b/modules/gui/test/display/testDisplayRoi.cpp index 0fb808f707..9e9ef656cc 100644 --- a/modules/gui/test/display/testDisplayRoi.cpp +++ b/modules/gui/test/display/testDisplayRoi.cpp @@ -179,7 +179,7 @@ int main(int argc, const char **argv) vpDisplay::display(I); vpDisplay::flush(I); - I = 0; + I = 0u; vpRect roi(I.getWidth() / 4, I.getHeight() / 4, I.getWidth() / 2, I.getHeight() / 2); vpDisplay::displayROI(I, roi); diff --git a/modules/gui/test/display/testDisplays.cpp b/modules/gui/test/display/testDisplays.cpp index b16c1dbe7e..e7ca90dad9 100644 --- a/modules/gui/test/display/testDisplays.cpp +++ b/modules/gui/test/display/testDisplays.cpp @@ -277,7 +277,8 @@ template static void draw(vpImage &I) vpDisplay::displayPolygon(I, polygon, vpColor::cyan, 3, false); } -template static void runTest(bool opt_display, bool opt_click_allowed) +template +static void runTest(bool opt_display, bool opt_click_allowed) { vpImage Ix; vpImage Igtk; @@ -287,7 +288,7 @@ template static void runTest(bool opt_display, bool opt_click_al #if defined(VISP_HAVE_X11) vpDisplayX *displayX = new vpDisplayX; - Ix.init(480, 640, 255); + Ix.init(480, 640, Type(255)); if (opt_display) { displayX->init(Ix, 100, 100, "Display X11"); vpDisplay::display(Ix); @@ -300,7 +301,7 @@ template static void runTest(bool opt_display, bool opt_click_al #if defined(HAVE_OPENCV_HIGHGUI) vpDisplayOpenCV *displayCv = new vpDisplayOpenCV; - Icv.init(480, 640, 255); + Icv.init(480, 640, Type(255)); if (opt_display) { displayCv->init(Icv, 100, 100, "Display OpenCV"); vpDisplay::display(Icv); @@ -313,7 +314,7 @@ template static void runTest(bool opt_display, bool opt_click_al #if defined(VISP_HAVE_GTK) vpDisplayGTK *displayGtk = new vpDisplayGTK; - Igtk.init(480, 640, 255); + Igtk.init(480, 640, Type(255)); if (opt_display) { displayGtk->init(Igtk, 100, 100, "Display GTK"); vpDisplay::display(Igtk); @@ -327,7 +328,7 @@ template static void runTest(bool opt_display, bool opt_click_al #if defined(VISP_HAVE_GDI) vpDisplayGDI *displayGdi = new vpDisplayGDI; - Igdi.init(480, 640, 255); + Igdi.init(480, 640, Type(255)); if (opt_display) { displayGdi->init(Igdi, 100, 100, "Display GDI"); vpDisplay::display(Igdi); @@ -340,7 +341,7 @@ template static void runTest(bool opt_display, bool opt_click_al #if defined(VISP_HAVE_D3D9) vpDisplayD3D *displayD3d = new vpDisplayD3D; - Id3d.init(480, 640, 255); + Id3d.init(480, 640, Type(255)); if (opt_display) { displayD3d->init(Id3d, 100, 100, "Display Direct 3D"); vpDisplay::display(Id3d); diff --git a/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h b/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h index a0a0fcf71b..eae732d5f6 100644 --- a/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h +++ b/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h @@ -686,7 +686,7 @@ class VISP_EXPORT vpCircleHoughTransform * from a \b vpCircleHoughTransformParams object. * \param[in] algoParams The parameters of the Circle Hough Transform. */ - explicit vpCircleHoughTransform(const vpCircleHoughTransformParams &algoParams); + VP_EXPLICIT vpCircleHoughTransform(const vpCircleHoughTransformParams &algoParams); /** * \brief Destroy the vp Circle Hough Transform object @@ -758,7 +758,7 @@ class VISP_EXPORT vpCircleHoughTransform * does not exist. * \param[in] jsonPath The path towards the JSON configuration file. */ - explicit vpCircleHoughTransform(const std::string &jsonPath); + VP_EXPLICIT vpCircleHoughTransform(const std::string &jsonPath); /** * \brief Initialize all the algorithm parameters using the JSON file diff --git a/modules/imgproc/include/visp3/imgproc/vpContours.h b/modules/imgproc/include/visp3/imgproc/vpContours.h index 90e1a5d54c..6c59a0dce8 100644 --- a/modules/imgproc/include/visp3/imgproc/vpContours.h +++ b/modules/imgproc/include/visp3/imgproc/vpContours.h @@ -225,7 +225,7 @@ struct vpContour /*! * Constructor of a given contour type. */ - explicit vpContour(const vpContourType &type) : m_children(), m_contourType(type), m_parent(nullptr), m_points() { } + VP_EXPLICIT vpContour(const vpContourType &type) : m_children(), m_contourType(type), m_parent(nullptr), m_points() { } /*! * Copy constructor. diff --git a/modules/imgproc/src/vpImgproc.cpp b/modules/imgproc/src/vpImgproc.cpp index 4077523a47..f6f092d0eb 100644 --- a/modules/imgproc/src/vpImgproc.cpp +++ b/modules/imgproc/src/vpImgproc.cpp @@ -747,7 +747,7 @@ void stretchContrast(const vpImage &I1, vpImage &I void stretchContrast(vpImage &I) { // Find min and max intensity values - vpRGBa min = 255, max = 0; + vpRGBa min(255), max(0); // Split the RGBa image into 4 images vpImage pR(I.getHeight(), I.getWidth()); diff --git a/modules/io/include/visp3/io/vpDiskGrabber.h b/modules/io/include/visp3/io/vpDiskGrabber.h index 25366d9c6e..891a50b87b 100644 --- a/modules/io/include/visp3/io/vpDiskGrabber.h +++ b/modules/io/include/visp3/io/vpDiskGrabber.h @@ -127,7 +127,7 @@ class VISP_EXPORT vpDiskGrabber : public vpFrameGrabber /*! * Constructor that takes a generic image sequence as input. */ - explicit vpDiskGrabber(const std::string &genericName); + VP_EXPLICIT vpDiskGrabber(const std::string &genericName); /*! * Destructor. @@ -145,7 +145,7 @@ class VISP_EXPORT vpDiskGrabber : public vpFrameGrabber * \param noz : Number of zero to code the image number. * \param ext : Extension of the image file. */ - explicit vpDiskGrabber(const std::string &dir, const std::string &basename, long number, int step, unsigned int noz, + VP_EXPLICIT vpDiskGrabber(const std::string &dir, const std::string &basename, long number, int step, unsigned int noz, const std::string &ext); /*! diff --git a/modules/io/include/visp3/io/vpParallelPortException.h b/modules/io/include/visp3/io/vpParallelPortException.h index 39c8312ca1..a51f106c39 100644 --- a/modules/io/include/visp3/io/vpParallelPortException.h +++ b/modules/io/include/visp3/io/vpParallelPortException.h @@ -87,7 +87,7 @@ class VISP_EXPORT vpParallelPortException : public vpException /*! * Constructor. */ - explicit vpParallelPortException(int id) : vpException(id) { } + VP_EXPLICIT vpParallelPortException(int id) : vpException(id) { } }; END_VISP_NAMESPACE #endif diff --git a/modules/robot/include/visp3/robot/vpImageSimulator.h b/modules/robot/include/visp3/robot/vpImageSimulator.h index 05a75e1fc4..1ffe688bb0 100644 --- a/modules/robot/include/visp3/robot/vpImageSimulator.h +++ b/modules/robot/include/visp3/robot/vpImageSimulator.h @@ -206,7 +206,7 @@ class VISP_EXPORT vpImageSimulator bool needClipping; public: - explicit vpImageSimulator(const vpColorPlan &col = COLORED); + VP_EXPLICIT vpImageSimulator(const vpColorPlan &col = COLORED); vpImageSimulator(const vpImageSimulator &text); virtual ~vpImageSimulator(); diff --git a/modules/robot/include/visp3/robot/vpRobotAfma4.h b/modules/robot/include/visp3/robot/vpRobotAfma4.h index 6c664fd8e9..6818c6177c 100644 --- a/modules/robot/include/visp3/robot/vpRobotAfma4.h +++ b/modules/robot/include/visp3/robot/vpRobotAfma4.h @@ -216,11 +216,11 @@ class VISP_EXPORT vpRobotAfma4 : public vpAfma4, public vpRobot static const double defaultPositioningVelocity; // = 20.0; public: /* Methode publiques */ - explicit vpRobotAfma4(bool verbose = true); + VP_EXPLICIT vpRobotAfma4(bool verbose = true); virtual ~vpRobotAfma4(void); void getDisplacement(vpRobot::vpControlFrameType frame, vpColVector &displacement); - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) VP_OVERRIDE; void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position, double ×tamp); double getPositioningVelocity(void); @@ -237,8 +237,8 @@ class VISP_EXPORT vpRobotAfma4 : public vpAfma4, public vpRobot void get_cMe(vpHomogeneousMatrix &cMe) const; void get_cVe(vpVelocityTwistMatrix &cVe) const; void get_cVf(vpVelocityTwistMatrix &cVf) const; - void get_eJe(vpMatrix &eJe) vp_override; - void get_fJe(vpMatrix &fJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; + void get_fJe(vpMatrix &fJe) VP_OVERRIDE; void init(void); @@ -251,7 +251,7 @@ class VISP_EXPORT vpRobotAfma4 : public vpAfma4, public vpRobot static bool savePosFile(const std::string &filename, const vpColVector &q); /* --- POSITIONNEMENT --------------------------------------------------- */ - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) VP_OVERRIDE; void setPosition(const vpRobot::vpControlFrameType frame, const double q1, const double q2, const double q4, const double q5); void setPosition(const char *filename); @@ -263,7 +263,7 @@ class VISP_EXPORT vpRobotAfma4 : public vpAfma4, public vpRobot /* --- VITESSE ---------------------------------------------------------- */ - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) VP_OVERRIDE; void stopMotion(); }; diff --git a/modules/robot/include/visp3/robot/vpRobotAfma6.h b/modules/robot/include/visp3/robot/vpRobotAfma6.h index a6c8e0bca1..8eeeb304ae 100644 --- a/modules/robot/include/visp3/robot/vpRobotAfma6.h +++ b/modules/robot/include/visp3/robot/vpRobotAfma6.h @@ -250,7 +250,7 @@ class VISP_EXPORT vpRobotAfma6 : public vpAfma6, public vpRobot static const double defaultPositioningVelocity; // = 20.0; public: /* Methode publiques */ - explicit vpRobotAfma6(bool verbose = true); + VP_EXPLICIT vpRobotAfma6(bool verbose = true); virtual ~vpRobotAfma6(void); bool checkJointLimits(vpColVector &jointsStatus); @@ -259,7 +259,7 @@ class VISP_EXPORT vpRobotAfma6 : public vpAfma6, public vpRobot void getDisplacement(vpRobot::vpControlFrameType frame, vpColVector &displacement); - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) VP_OVERRIDE; void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position, double ×tamp); void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &position); void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &position, double ×tamp); @@ -276,8 +276,8 @@ class VISP_EXPORT vpRobotAfma6 : public vpAfma6, public vpRobot void get_cMe(vpHomogeneousMatrix &_cMe) const; void get_cVe(vpVelocityTwistMatrix &_cVe) const; - void get_eJe(vpMatrix &_eJe) vp_override; - void get_fJe(vpMatrix &_fJe) vp_override; + void get_eJe(vpMatrix &_eJe) VP_OVERRIDE; + void get_fJe(vpMatrix &_fJe) VP_OVERRIDE; void init(void); void init(vpAfma6::vpAfma6ToolType tool, const vpHomogeneousMatrix &eMc); @@ -299,7 +299,7 @@ class VISP_EXPORT vpRobotAfma6 : public vpAfma6, public vpRobot /* --- POSITIONNEMENT --------------------------------------------------- */ void setPosition(const vpRobot::vpControlFrameType frame, const vpPoseVector &pose); - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) VP_OVERRIDE; void setPosition(const vpRobot::vpControlFrameType frame, double pos1, double pos2, double pos3, double pos4, double pos5, double pos6); void setPosition(const std::string &filename); @@ -312,7 +312,7 @@ class VISP_EXPORT vpRobotAfma6 : public vpAfma6, public vpRobot /* --- VITESSE ---------------------------------------------------------- */ - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) VP_OVERRIDE; void stopMotion(); }; diff --git a/modules/robot/include/visp3/robot/vpRobotBiclops.h b/modules/robot/include/visp3/robot/vpRobotBiclops.h index d254c70fc1..e0e375363b 100644 --- a/modules/robot/include/visp3/robot/vpRobotBiclops.h +++ b/modules/robot/include/visp3/robot/vpRobotBiclops.h @@ -154,7 +154,7 @@ class VISP_EXPORT vpRobotBiclops : public vpBiclops, public vpRobot * } * \endcode */ - explicit vpRobotBiclops(const std::string &filename); + VP_EXPLICIT vpRobotBiclops(const std::string &filename); /*! * Destructor. @@ -169,7 +169,7 @@ class VISP_EXPORT vpRobotBiclops : public vpBiclops, public vpRobot * \exception vpRobotException::constructionError If the config file cannot be * opened. */ - void init() vp_override; + void init() VP_OVERRIDE; /*! * Get the homogeneous matrix corresponding to the transformation between the @@ -199,7 +199,7 @@ class VISP_EXPORT vpRobotBiclops : public vpBiclops, public vpRobot * \param eJe : Jacobian between end effector frame and end effector frame (on * tilt axis). */ - void get_eJe(vpMatrix &eJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; /*! * Get the robot jacobian expressed in the robot reference frame @@ -207,7 +207,7 @@ class VISP_EXPORT vpRobotBiclops : public vpBiclops, public vpRobot * \param fJe : Jacobian between reference frame (or fix frame) and end * effector frame (on tilt axis). */ - void get_fJe(vpMatrix &fJe) vp_override; + void get_fJe(vpMatrix &fJe) VP_OVERRIDE; /*! * Get the robot displacement since the last call of this method. @@ -229,7 +229,7 @@ class VISP_EXPORT vpRobotBiclops : public vpBiclops, public vpRobot * \exception vpRobotException::wrongStateError If a not supported frame type * is given. */ - void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &d) vp_override; + void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &d) VP_OVERRIDE; /*! * Return the position of each axis. @@ -244,7 +244,7 @@ class VISP_EXPORT vpRobotBiclops : public vpBiclops, public vpRobot * \exception vpRobotException::wrongStateError : If a not supported frame type * is given. */ - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; /*! * Get the velocity in % used for a position control. @@ -316,7 +316,7 @@ class VISP_EXPORT vpRobotBiclops : public vpBiclops, public vpRobot * \exception vpRobotException::wrongStateError : If a not supported frame * type is given. */ - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE; /*! * Move the robot in position control. @@ -360,7 +360,7 @@ class VISP_EXPORT vpRobotBiclops : public vpBiclops, public vpRobot * Change the state of the robot either to stop them, or to set position or * speed control. */ - vpRobot::vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState) vp_override; + vpRobot::vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState) VP_OVERRIDE; /*! * Send a velocity on each axis. @@ -386,7 +386,7 @@ class VISP_EXPORT vpRobotBiclops : public vpBiclops, public vpRobot * \warning Velocities could be saturated if one of them exceed the maximal * authorized speed (see vpRobot::maxRotationVelocity). */ - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &q_dot) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &q_dot) VP_OVERRIDE; /*! * Halt all the axis. diff --git a/modules/robot/include/visp3/robot/vpRobotCamera.h b/modules/robot/include/visp3/robot/vpRobotCamera.h index e7cb180022..6ecdd1bf64 100644 --- a/modules/robot/include/visp3/robot/vpRobotCamera.h +++ b/modules/robot/include/visp3/robot/vpRobotCamera.h @@ -116,17 +116,17 @@ class VISP_EXPORT vpRobotCamera : public vpRobotSimulator /** @name Inherited functionalities from vpRobotCamera */ //@{ void get_cVe(vpVelocityTwistMatrix &cVe) const; - void get_eJe(vpMatrix &eJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; void getPosition(vpHomogeneousMatrix &cMw) const; - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; void setPosition(const vpHomogeneousMatrix &cMw); - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v) VP_OVERRIDE; //@} private: - void init() vp_override; + void init() VP_OVERRIDE; // Non implemented virtual pure functions void get_fJe(vpMatrix & /*_fJe */) vp_override { }; diff --git a/modules/robot/include/visp3/robot/vpRobotException.h b/modules/robot/include/visp3/robot/vpRobotException.h index 3c3f30aaa9..fdfe35a7be 100644 --- a/modules/robot/include/visp3/robot/vpRobotException.h +++ b/modules/robot/include/visp3/robot/vpRobotException.h @@ -115,7 +115,7 @@ class VISP_EXPORT vpRobotException : public vpException /*! * Constructor. */ - explicit vpRobotException(int id) : vpException(id) { } + VP_EXPLICIT vpRobotException(int id) : vpException(id) { } }; END_VISP_NAMESPACE #endif diff --git a/modules/robot/include/visp3/robot/vpRobotFlirPtu.h b/modules/robot/include/visp3/robot/vpRobotFlirPtu.h index ba77625e0b..6e25da34a8 100644 --- a/modules/robot/include/visp3/robot/vpRobotFlirPtu.h +++ b/modules/robot/include/visp3/robot/vpRobotFlirPtu.h @@ -100,9 +100,9 @@ class VISP_EXPORT vpRobotFlirPtu : public vpRobot void connect(const std::string &portname, int baudrate = 9600); void disconnect(); - void get_eJe(vpMatrix &eJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; vpMatrix get_eJe(); - void get_fJe(vpMatrix &fJe) vp_override; + void get_fJe(vpMatrix &fJe) VP_OVERRIDE; vpMatrix get_fJe(); vpMatrix get_fMe(); @@ -113,13 +113,13 @@ class VISP_EXPORT vpRobotFlirPtu : public vpRobot vpHomogeneousMatrix get_eMc() const { return m_eMc; } vpVelocityTwistMatrix get_cVe() const; - void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; + void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; std::string getNetworkIP(); std::string getNetworkGateway(); std::string getNetworkHostName(); - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; vpColVector getPanPosLimits(); vpColVector getTiltPosLimits(); vpColVector getPanTiltVelMax(); @@ -131,13 +131,13 @@ class VISP_EXPORT vpRobotFlirPtu : public vpRobot If your tool is a camera, this transformation is obtained by hand-eye calibration. */ void set_eMc(vpHomogeneousMatrix &eMc) { m_eMc = eMc; } - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE; void setPanPosLimits(const vpColVector &pan_limits); void setTiltPosLimits(const vpColVector &tilt_limits); void setPositioningVelocity(double velocity); vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState); - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE; void stopMotion(); static void emergencyStop(int signo); diff --git a/modules/robot/include/visp3/robot/vpRobotFranka.h b/modules/robot/include/visp3/robot/vpRobotFranka.h index ad9634b889..6a9f2b4c9e 100644 --- a/modules/robot/include/visp3/robot/vpRobotFranka.h +++ b/modules/robot/include/visp3/robot/vpRobotFranka.h @@ -279,9 +279,9 @@ class VISP_EXPORT vpRobotFranka : public vpRobot vpHomogeneousMatrix get_fMc(const vpColVector &q); vpHomogeneousMatrix get_eMc() const; - void get_eJe(vpMatrix &eJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; void get_eJe(const vpColVector &q, vpMatrix &eJe); - void get_fJe(vpMatrix &fJe) vp_override; + void get_fJe(vpMatrix &fJe) VP_OVERRIDE; void get_fJe(const vpColVector &q, vpMatrix &fJe); void getCoriolis(vpColVector &coriolis); @@ -324,7 +324,7 @@ class VISP_EXPORT vpRobotFranka : public vpRobot void getMass(vpMatrix &mass); - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) VP_OVERRIDE; void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &pose); void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &d_position); @@ -346,11 +346,11 @@ class VISP_EXPORT vpRobotFranka : public vpRobot void setForceTorque(const vpRobot::vpControlFrameType frame, const vpColVector &ft, const double &filter_gain = 0.1, const bool &activate_pi_controller = false); void setLogFolder(const std::string &folder); - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) VP_OVERRIDE; void setPositioningVelocity(double velocity); vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState); - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE; void stopMotion(); }; diff --git a/modules/robot/include/visp3/robot/vpRobotKinova.h b/modules/robot/include/visp3/robot/vpRobotKinova.h index 2bf7e1c2d5..21e45bcfc7 100644 --- a/modules/robot/include/visp3/robot/vpRobotKinova.h +++ b/modules/robot/include/visp3/robot/vpRobotKinova.h @@ -93,12 +93,12 @@ class VISP_EXPORT vpRobotKinova : public vpRobot typedef enum { CMD_LAYER_USB, CMD_LAYER_ETHERNET, CMD_LAYER_UNSET } CommandLayer; vpRobotKinova(); - virtual ~vpRobotKinova() vp_override; + virtual ~vpRobotKinova() VP_OVERRIDE; int connect(); - void get_eJe(vpMatrix &eJe) vp_override; - void get_fJe(vpMatrix &fJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; + void get_fJe(vpMatrix &fJe) VP_OVERRIDE; /*! * Return constant transformation between end-effector and tool frame. @@ -108,8 +108,8 @@ class VISP_EXPORT vpRobotKinova : public vpRobot int getActiveDevice() const { return m_active_device; } int getNumDevices() const { return m_devices_count; } - void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) vp_override; + void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) VP_OVERRIDE; void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &pose); void homing(); @@ -126,7 +126,7 @@ class VISP_EXPORT vpRobotKinova : public vpRobot */ void setCommandLayer(CommandLayer command_layer) { m_command_layer = command_layer; } void setDoF(unsigned int dof); - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE; /*! * \param[in] plugin_location: Path to Jaco SDK plugins (ie. `Kinova.API.USBCommandLayerUbuntu.so` on * unix-like platform or `CommandLayerWindows.dll` on Windows platform). By default this location is empty, @@ -134,7 +134,7 @@ class VISP_EXPORT vpRobotKinova : public vpRobot * them. */ void setPluginLocation(const std::string &plugin_location) { m_plugin_location = plugin_location; } - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE; /*! * Enable or disable verbose mode to print to stdout additional information. * \param[in] verbose : true to enable verbose, false to disable. By default verbose diff --git a/modules/robot/include/visp3/robot/vpRobotPioneer.h b/modules/robot/include/visp3/robot/vpRobotPioneer.h index 48d12e0c47..f9a8a83123 100644 --- a/modules/robot/include/visp3/robot/vpRobotPioneer.h +++ b/modules/robot/include/visp3/robot/vpRobotPioneer.h @@ -70,7 +70,7 @@ class VISP_EXPORT vpRobotPioneer : public vpRobot, public vpPioneer, public ArRo public: vpRobotPioneer(); - virtual ~vpRobotPioneer() vp_override; + virtual ~vpRobotPioneer() VP_OVERRIDE; /*! * Get the robot Jacobian expressed at point E, the point located at the @@ -121,7 +121,7 @@ class VISP_EXPORT vpRobotPioneer : public vpRobot, public vpPioneer, public ArRo void setPosition(const vpRobot::vpControlFrameType /*frame*/, const vpColVector & /*q*/) vp_override { }; public: - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE; /*! * Enable or disable sonar device usage. diff --git a/modules/robot/include/visp3/robot/vpRobotPololuPtu.h b/modules/robot/include/visp3/robot/vpRobotPololuPtu.h index 035ccd39ab..936cb11ee4 100644 --- a/modules/robot/include/visp3/robot/vpRobotPololuPtu.h +++ b/modules/robot/include/visp3/robot/vpRobotPololuPtu.h @@ -75,7 +75,7 @@ class VISP_EXPORT vpRobotPololuPtu : public vpRobot /*! * Destructor that stops the movements. */ - ~vpRobotPololuPtu() vp_override; + ~vpRobotPololuPtu() VP_OVERRIDE; /*! * Get the robot jacobian expressed in the end-effector frame. @@ -86,7 +86,7 @@ class VISP_EXPORT vpRobotPololuPtu : public vpRobot * \param[out] eJe : Jacobian between end effector frame and end effector frame (on * tilt axis). */ - void get_eJe(vpMatrix &eJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; /*! * Get the robot jacobian expressed in the end-effector frame. @@ -107,7 +107,7 @@ class VISP_EXPORT vpRobotPololuPtu : public vpRobot * \param[out] fJe : Jacobian between reference frame (or fix frame) and end * effector frame (on tilt axis). */ - void get_fJe(vpMatrix &fJe) vp_override; + void get_fJe(vpMatrix &fJe) VP_OVERRIDE; /*! * Get the robot jacobian expressed in the robot reference frame. @@ -136,7 +136,7 @@ class VISP_EXPORT vpRobotPololuPtu : public vpRobot * \exception vpRobotException::wrongStateError : If a not supported frame type * is given. */ - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; /*! * Get the percentage of the maximum velocity applied to move the PTU in position. @@ -165,7 +165,7 @@ class VISP_EXPORT vpRobotPololuPtu : public vpRobot * \exception vpRobotException::wrongStateError : If a not supported frame * type is given. */ - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE; /*! * Set the percentage of the maximum velocity applied to move the PTU in position. @@ -214,7 +214,7 @@ class VISP_EXPORT vpRobotPololuPtu : public vpRobot * \warning Velocities could be saturated if one of them exceed the maximal * authorized speed (see vpRobot::maxRotationVelocity). */ - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &q_dot) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &q_dot) VP_OVERRIDE; /*! * Stop the velocity command. @@ -225,7 +225,7 @@ class VISP_EXPORT vpRobotPololuPtu : public vpRobot * Change the state of the robot either to stop them, or to set position or * speed control. */ - vpRobot::vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState) vp_override; + vpRobot::vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState) VP_OVERRIDE; private: /*! diff --git a/modules/robot/include/visp3/robot/vpRobotPtu46.h b/modules/robot/include/visp3/robot/vpRobotPtu46.h index bffe1eca06..2fe09cdf0e 100644 --- a/modules/robot/include/visp3/robot/vpRobotPtu46.h +++ b/modules/robot/include/visp3/robot/vpRobotPtu46.h @@ -93,17 +93,17 @@ class VISP_EXPORT vpRobotPtu46 : public vpPtu46, public vpRobot public: static const double defaultPositioningVelocity; - explicit vpRobotPtu46(const std::string &device = "/dev/ttyS0"); - explicit vpRobotPtu46(vpRobotPtu46 *pub); + VP_EXPLICIT vpRobotPtu46(const std::string &device = "/dev/ttyS0"); + VP_EXPLICIT vpRobotPtu46(vpRobotPtu46 *pub); virtual ~vpRobotPtu46(void); void get_cMe(vpHomogeneousMatrix &_cMe) const; void get_cVe(vpVelocityTwistMatrix &_cVe) const; - void get_eJe(vpMatrix &_eJe) vp_override; - void get_fJe(vpMatrix &_fJe) vp_override; + void get_eJe(vpMatrix &_eJe) VP_OVERRIDE; + void get_fJe(vpMatrix &_fJe) VP_OVERRIDE; void getDisplacement(vpRobot::vpControlFrameType frame, vpColVector &q); - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; double getPositioningVelocity(void); void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &q_dot); vpColVector getVelocity(const vpRobot::vpControlFrameType frame); @@ -112,13 +112,13 @@ class VISP_EXPORT vpRobotPtu46 : public vpPtu46, public vpRobot bool readPositionFile(const std::string &filename, vpColVector &q); - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE; void setPosition(const vpRobot::vpControlFrameType frame, const double &q1, const double &q2); void setPosition(const char *filename); void setPositioningVelocity(double velocity); vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState); - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &q_dot) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &q_dot) VP_OVERRIDE; void stopMotion(); }; diff --git a/modules/robot/include/visp3/robot/vpRobotTemplate.h b/modules/robot/include/visp3/robot/vpRobotTemplate.h index f7f01bbe2e..99a2ad1028 100644 --- a/modules/robot/include/visp3/robot/vpRobotTemplate.h +++ b/modules/robot/include/visp3/robot/vpRobotTemplate.h @@ -54,10 +54,10 @@ class VISP_EXPORT vpRobotTemplate : public vpRobot { public: vpRobotTemplate(); - virtual ~vpRobotTemplate() vp_override; + virtual ~vpRobotTemplate() VP_OVERRIDE; - void get_eJe(vpMatrix &eJe_) vp_override; - void get_fJe(vpMatrix &fJe_) vp_override; + void get_eJe(vpMatrix &eJe_) VP_OVERRIDE; + void get_fJe(vpMatrix &fJe_) VP_OVERRIDE; /*! * Return constant transformation between end-effector and tool frame. @@ -65,19 +65,19 @@ class VISP_EXPORT vpRobotTemplate : public vpRobot */ vpHomogeneousMatrix get_eMc() const { return m_eMc; } - void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; + void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; /*! * Set constant transformation between end-effector and tool frame. * If your tool is a camera, this transformation is obtained by hand-eye calibration. */ void set_eMc(vpHomogeneousMatrix &eMc) { m_eMc = eMc; } - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) vp_override; - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE; protected: - void init() vp_override; + void init() VP_OVERRIDE; void getJointPosition(vpColVector &q); void setCartVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v); void setJointVelocity(const vpColVector &qdot); diff --git a/modules/robot/include/visp3/robot/vpRobotUniversalRobots.h b/modules/robot/include/visp3/robot/vpRobotUniversalRobots.h index a4e74e9358..4985fa432a 100644 --- a/modules/robot/include/visp3/robot/vpRobotUniversalRobots.h +++ b/modules/robot/include/visp3/robot/vpRobotUniversalRobots.h @@ -96,7 +96,7 @@ class VISP_EXPORT vpRobotUniversalRobots : public vpRobot void getForceTorque(const vpRobot::vpControlFrameType frame, vpColVector &force); std::string getPolyScopeVersion(); - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) VP_OVERRIDE; void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &pose); int getRobotMode() const; std::string getRobotModel() const; @@ -106,12 +106,12 @@ class VISP_EXPORT vpRobotUniversalRobots : public vpRobot bool readPosFile(const std::string &filename, vpColVector &q); bool savePosFile(const std::string &filename, const vpColVector &q); - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) VP_OVERRIDE; void setPosition(const vpRobot::vpControlFrameType frame, const vpPoseVector &pose); void setPositioningVelocity(double velocity); vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState); - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE; void set_eMc(const vpHomogeneousMatrix &eMc); diff --git a/modules/robot/include/visp3/robot/vpRobotViper650.h b/modules/robot/include/visp3/robot/vpRobotViper650.h index 742ea15188..5472c48c65 100644 --- a/modules/robot/include/visp3/robot/vpRobotViper650.h +++ b/modules/robot/include/visp3/robot/vpRobotViper650.h @@ -383,7 +383,7 @@ class VISP_EXPORT vpRobotViper650 : public vpViper650, public vpRobot vpControlModeType m_controlMode; public: /* Methode publiques */ - explicit vpRobotViper650(bool verbose = true); + VP_EXPLICIT vpRobotViper650(bool verbose = true); virtual ~vpRobotViper650(void); // Force/Torque control @@ -423,8 +423,8 @@ class VISP_EXPORT vpRobotViper650 : public vpViper650, public vpRobot void get_cMe(vpHomogeneousMatrix &cMe) const; void get_cVe(vpVelocityTwistMatrix &cVe) const; - void get_eJe(vpMatrix &eJe) vp_override; - void get_fJe(vpMatrix &fJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; + void get_fJe(vpMatrix &fJe) VP_OVERRIDE; void init(void); void @@ -450,7 +450,7 @@ class VISP_EXPORT vpRobotViper650 : public vpViper650, public vpRobot void setMaxRotationVelocityJoint6(double w6_max); // Position control - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) VP_OVERRIDE; void setPosition(const vpRobot::vpControlFrameType frame, double pos1, double pos2, double pos3, double pos4, double pos5, double pos6); void setPosition(const std::string &filename); @@ -459,7 +459,7 @@ class VISP_EXPORT vpRobotViper650 : public vpViper650, public vpRobot // State vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState); // Velocity control - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) VP_OVERRIDE; void stopMotion(); diff --git a/modules/robot/include/visp3/robot/vpRobotViper850.h b/modules/robot/include/visp3/robot/vpRobotViper850.h index bd7abd4453..19b3ef13f4 100644 --- a/modules/robot/include/visp3/robot/vpRobotViper850.h +++ b/modules/robot/include/visp3/robot/vpRobotViper850.h @@ -394,7 +394,7 @@ class VISP_EXPORT vpRobotViper850 : public vpViper850, public vpRobot #endif public: /* Methode publiques */ - explicit vpRobotViper850(bool verbose = true); + VP_EXPLICIT vpRobotViper850(bool verbose = true); virtual ~vpRobotViper850(void); // Force/Torque control @@ -416,7 +416,7 @@ class VISP_EXPORT vpRobotViper850 : public vpViper850, public vpRobot vpColVector getForceTorque() const; double getMaxRotationVelocityJoint6() const; - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) VP_OVERRIDE; void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position, double ×tamp); void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &position); void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &position, double ×tamp); @@ -434,8 +434,8 @@ class VISP_EXPORT vpRobotViper850 : public vpViper850, public vpRobot void get_cMe(vpHomogeneousMatrix &cMe) const; void get_cVe(vpVelocityTwistMatrix &cVe) const; - void get_eJe(vpMatrix &eJe) vp_override; - void get_fJe(vpMatrix &fJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; + void get_fJe(vpMatrix &fJe) VP_OVERRIDE; void init(void); void @@ -461,7 +461,7 @@ class VISP_EXPORT vpRobotViper850 : public vpViper850, public vpRobot void setMaxRotationVelocityJoint6(double w6_max); // Position control - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) VP_OVERRIDE; void setPosition(const vpRobot::vpControlFrameType frame, double pos1, double pos2, double pos3, double pos4, double pos5, double pos6); void setPosition(const std::string &filename); @@ -471,7 +471,7 @@ class VISP_EXPORT vpRobotViper850 : public vpViper850, public vpRobot vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState); // Velocity control - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) VP_OVERRIDE; void stopMotion(); void unbiasForceTorqueSensor(); diff --git a/modules/robot/include/visp3/robot/vpRobotWireFrameSimulator.h b/modules/robot/include/visp3/robot/vpRobotWireFrameSimulator.h index 9dfc689d15..3d5ed8fd4f 100644 --- a/modules/robot/include/visp3/robot/vpRobotWireFrameSimulator.h +++ b/modules/robot/include/visp3/robot/vpRobotWireFrameSimulator.h @@ -165,7 +165,7 @@ class VISP_EXPORT vpRobotWireFrameSimulator : protected vpWireFrameSimulator, pu public: vpRobotWireFrameSimulator(); - explicit vpRobotWireFrameSimulator(bool display); + VP_EXPLICIT vpRobotWireFrameSimulator(bool display); /** @name Inherited functionalities from vpRobotWireFrameSimulator */ //@{ diff --git a/modules/robot/include/visp3/robot/vpServolens.h b/modules/robot/include/visp3/robot/vpServolens.h index 36bf1f3adf..d481c0109c 100644 --- a/modules/robot/include/visp3/robot/vpServolens.h +++ b/modules/robot/include/visp3/robot/vpServolens.h @@ -104,7 +104,7 @@ class VISP_EXPORT vpServolens typedef enum { AUTO = 1, CONTROLLED = 2, RELEASED = 3 } vpControllerType; vpServolens(); - explicit vpServolens(const char *port); + VP_EXPLICIT vpServolens(const char *port); virtual ~vpServolens(); void open(const char *port = "/dev/ttyS0"); diff --git a/modules/robot/include/visp3/robot/vpSimulatorAfma6.h b/modules/robot/include/visp3/robot/vpSimulatorAfma6.h index c5a8d44fa1..5db60b04a9 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorAfma6.h +++ b/modules/robot/include/visp3/robot/vpSimulatorAfma6.h @@ -188,14 +188,14 @@ class VISP_EXPORT vpSimulatorAfma6 : public vpRobotWireFrameSimulator, public vp public: vpSimulatorAfma6(); - explicit vpSimulatorAfma6(bool display); - virtual ~vpSimulatorAfma6() vp_override; + VP_EXPLICIT vpSimulatorAfma6(bool display); + virtual ~vpSimulatorAfma6() VP_OVERRIDE; void getCameraParameters(vpCameraParameters &cam, const unsigned int &image_width, const unsigned int &image_height); void getCameraParameters(vpCameraParameters &cam, const vpImage &I); void getCameraParameters(vpCameraParameters &cam, const vpImage &I); - void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &displacement) vp_override; - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; + void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &displacement) VP_OVERRIDE; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q, double ×tamp); void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &position); void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &position, double ×tamp); @@ -207,8 +207,8 @@ class VISP_EXPORT vpSimulatorAfma6 : public vpRobotWireFrameSimulator, public vp void get_cMe(vpHomogeneousMatrix &cMe); void get_cVe(vpVelocityTwistMatrix &cVe); - void get_eJe(vpMatrix &eJe) vp_override; - void get_fJe(vpMatrix &fJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; + void get_fJe(vpMatrix &fJe) VP_OVERRIDE; void init(vpAfma6::vpAfma6ToolType tool, @@ -223,22 +223,22 @@ class VISP_EXPORT vpSimulatorAfma6 : public vpRobotWireFrameSimulator, public vp void setCameraParameters(const vpCameraParameters &cam); void setJointLimit(const vpColVector &limitMin, const vpColVector &limitMax); - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE; void setPosition(const vpRobot::vpControlFrameType frame, double pos1, double pos2, double pos3, double pos4, double pos5, double pos6); void setPosition(const char *filename); void setPositioningVelocity(double vel) { positioningVelocity = vel; } bool setPosition(const vpHomogeneousMatrix &cdMo, vpImage *Iint = nullptr, const double &errMax = 0.001); - vpRobot::vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState) vp_override; + vpRobot::vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState) VP_OVERRIDE; - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) VP_OVERRIDE; void stopMotion(); protected: /** @name Protected Member Functions Inherited from vpSimulatorAfma6 */ //@{ - void computeArticularVelocity() vp_override; + void computeArticularVelocity() VP_OVERRIDE; void compute_fMi(); void findHighestPositioningSpeed(vpColVector &q); void getExternalImage(vpImage &I); @@ -251,12 +251,12 @@ class VISP_EXPORT vpSimulatorAfma6 : public vpRobotWireFrameSimulator, public vp m_mutex_fMi.unlock(); } - void init() vp_override; - void initArms() vp_override; + void init() VP_OVERRIDE; + void initArms() VP_OVERRIDE; void initDisplay(); - int isInJointLimit() vp_override; + int isInJointLimit() VP_OVERRIDE; bool singularityTest(const vpColVector &q, vpMatrix &J); - void updateArticularPosition() vp_override; + void updateArticularPosition() VP_OVERRIDE; //@} }; END_VISP_NAMESPACE diff --git a/modules/robot/include/visp3/robot/vpSimulatorCamera.h b/modules/robot/include/visp3/robot/vpSimulatorCamera.h index 8f75ee1d36..e06efd9373 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorCamera.h +++ b/modules/robot/include/visp3/robot/vpSimulatorCamera.h @@ -113,17 +113,17 @@ class VISP_EXPORT vpSimulatorCamera : public vpRobotSimulator /** @name Inherited functionalities from vpSimulatorCamera */ //@{ void get_cVe(vpVelocityTwistMatrix &cVe) const; - void get_eJe(vpMatrix &eJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; vpHomogeneousMatrix getPosition() const; void getPosition(vpHomogeneousMatrix &wMc) const; - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; void setPosition(const vpHomogeneousMatrix &wMc); - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE; //@} private: - void init() vp_override; + void init() VP_OVERRIDE; // Non implemented virtual pure functions void get_fJe(vpMatrix & /*_fJe */) vp_override { }; diff --git a/modules/robot/include/visp3/robot/vpSimulatorPioneer.h b/modules/robot/include/visp3/robot/vpSimulatorPioneer.h index e6f4b60ee7..7221bc0da3 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorPioneer.h +++ b/modules/robot/include/visp3/robot/vpSimulatorPioneer.h @@ -117,15 +117,15 @@ class VISP_EXPORT vpSimulatorPioneer : public vpPioneer, public vpRobotSimulator public: /** @name Inherited functionalities from vpSimulatorPioneer */ //@{ - void get_eJe(vpMatrix &eJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; void getPosition(vpHomogeneousMatrix &wMc) const; - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE; //@} private: - void init() vp_override; + void init() VP_OVERRIDE; // Non implemented virtual pure functions void get_fJe(vpMatrix & /*_fJe */) vp_override { }; diff --git a/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h b/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h index c6c09d7378..3c894164cb 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h +++ b/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h @@ -118,15 +118,15 @@ class VISP_EXPORT vpSimulatorPioneerPan : public vpPioneerPan, public vpRobotSim public: /** @name Inherited functionalities from vpSimulatorPioneerPan */ //@{ - void get_eJe(vpMatrix &eJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; void getPosition(vpHomogeneousMatrix &wMc) const; - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE; //@} private: - void init() vp_override; + void init() VP_OVERRIDE; // Non implemented virtual pure functions void get_fJe(vpMatrix & /*_fJe */) vp_override { }; diff --git a/modules/robot/include/visp3/robot/vpSimulatorViper850.h b/modules/robot/include/visp3/robot/vpSimulatorViper850.h index 90a1f7436f..60722b7512 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorViper850.h +++ b/modules/robot/include/visp3/robot/vpSimulatorViper850.h @@ -213,16 +213,16 @@ class VISP_EXPORT vpSimulatorViper850 : public vpRobotWireFrameSimulator, public public: vpSimulatorViper850(); - explicit vpSimulatorViper850(bool display); - virtual ~vpSimulatorViper850() vp_override; + VP_EXPLICIT vpSimulatorViper850(bool display); + virtual ~vpSimulatorViper850() VP_OVERRIDE; void getCameraParameters(vpCameraParameters &cam, const unsigned int &image_width, const unsigned int &image_height); void getCameraParameters(vpCameraParameters &cam, const vpImage &I); void getCameraParameters(vpCameraParameters &cam, const vpImage &I); - void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &displacement) vp_override; + void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &displacement) VP_OVERRIDE; - void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override; + void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE; void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q, double ×tamp); void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &position); void getPosition(const vpRobot::vpControlFrameType frame, vpPoseVector &position, double ×tamp); @@ -235,8 +235,8 @@ class VISP_EXPORT vpSimulatorViper850 : public vpRobotWireFrameSimulator, public void get_cMe(vpHomogeneousMatrix &cMe); void get_cVe(vpVelocityTwistMatrix &cVe); - void get_eJe(vpMatrix &eJe) vp_override; - void get_fJe(vpMatrix &fJe) vp_override; + void get_eJe(vpMatrix &eJe) VP_OVERRIDE; + void get_fJe(vpMatrix &fJe) VP_OVERRIDE; void init(vpViper850::vpToolType tool, @@ -251,21 +251,21 @@ class VISP_EXPORT vpSimulatorViper850 : public vpRobotWireFrameSimulator, public void setCameraParameters(const vpCameraParameters &cam); void setJointLimit(const vpColVector &limitMin, const vpColVector &limitMax); - void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) vp_override; + void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE; void setPosition(const vpRobot::vpControlFrameType frame, double pos1, double pos2, double pos3, double pos4, double pos5, double pos6); void setPosition(const char *filename); void setPositioningVelocity(double vel) { positioningVelocity = vel; } - vpRobot::vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState) vp_override; + vpRobot::vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState) VP_OVERRIDE; - void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) vp_override; + void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) VP_OVERRIDE; void stopMotion(); protected: /** @name Protected Member Functions Inherited from vpSimulatorViper850 */ //@{ - void computeArticularVelocity() vp_override; + void computeArticularVelocity() VP_OVERRIDE; void compute_fMi(); void findHighestPositioningSpeed(vpColVector &q); void getExternalImage(vpImage &I); @@ -278,12 +278,12 @@ class VISP_EXPORT vpSimulatorViper850 : public vpRobotWireFrameSimulator, public } m_mutex_fMi.unlock(); } - void init() vp_override; - void initArms() vp_override; + void init() VP_OVERRIDE; + void initArms() VP_OVERRIDE; void initDisplay(); - int isInJointLimit() vp_override; + int isInJointLimit() VP_OVERRIDE; bool singularityTest(const vpColVector &q, vpMatrix &J); - void updateArticularPosition() vp_override; + void updateArticularPosition() VP_OVERRIDE; //@} }; END_VISP_NAMESPACE diff --git a/modules/robot/include/visp3/robot/vpVirtuose.h b/modules/robot/include/visp3/robot/vpVirtuose.h index 1ad4c33739..32b851b91f 100644 --- a/modules/robot/include/visp3/robot/vpVirtuose.h +++ b/modules/robot/include/visp3/robot/vpVirtuose.h @@ -209,7 +209,7 @@ class VISP_EXPORT vpVirtuose * * \sa setIpAddressAndPort() */ - vp_deprecated inline void setIpAddress(const std::string &ip_port) { m_ip_port = ip_port; } + VP_DEPRECATED inline void setIpAddress(const std::string &ip_port) { m_ip_port = ip_port; } //@} #endif diff --git a/modules/robot/src/robot-simulator/vpRobotWireFrameSimulator.cpp b/modules/robot/src/robot-simulator/vpRobotWireFrameSimulator.cpp index 2618e82b25..cda9d9b0e1 100644 --- a/modules/robot/src/robot-simulator/vpRobotWireFrameSimulator.cpp +++ b/modules/robot/src/robot-simulator/vpRobotWireFrameSimulator.cpp @@ -62,7 +62,7 @@ vpRobotWireFrameSimulator::vpRobotWireFrameSimulator() setSamplingTime(0.010); velocity.resize(6); I.resize(480, 640); - I = 255; + I = vpRGBa(255); #if defined(VISP_HAVE_DISPLAY) display.init(I, 0, 0, "The External view"); #endif @@ -87,7 +87,7 @@ vpRobotWireFrameSimulator::vpRobotWireFrameSimulator(bool do_display) setSamplingTime(0.010); velocity.resize(6); I.resize(480, 640); - I = 255; + I = vpRGBa(255); #if defined(VISP_HAVE_DISPLAY) if (do_display) diff --git a/modules/robot/src/wireframe-simulator/vpWireFrameSimulator.cpp b/modules/robot/src/wireframe-simulator/vpWireFrameSimulator.cpp index dca6da6b38..6e1615dd04 100644 --- a/modules/robot/src/wireframe-simulator/vpWireFrameSimulator.cpp +++ b/modules/robot/src/wireframe-simulator/vpWireFrameSimulator.cpp @@ -761,7 +761,7 @@ void vpWireFrameSimulator::getInternalImage(vpImage &I) vp2jlc_matrix(cdMo.inverse(), o44cd); if (displayImageSimulator) { - I = 255; + I = vpRGBa(255); for (std::list::iterator it = objectImage.begin(); it != objectImage.end(); ++it) { vpImageSimulator *imSim = &(*it); @@ -858,7 +858,7 @@ void vpWireFrameSimulator::getExternalImage(vpImage &I) } if (displayImageSimulator) { - I = 255; + I = vpRGBa(255); for (std::list::iterator it = objectImage.begin(); it != objectImage.end(); ++it) { vpImageSimulator *imSim = &(*it); @@ -978,7 +978,7 @@ void vpWireFrameSimulator::getExternalImage(vpImage &I, const vpHomogene add_vwstack("start", "window", -u, u, -v, v); if (displayImageSimulator) { - I = 255; + I = vpRGBa(255); for (std::list::iterator it = objectImage.begin(); it != objectImage.end(); ++it) { vpImageSimulator *imSim = &(*it); @@ -1030,7 +1030,7 @@ void vpWireFrameSimulator::getInternalImage(vpImage &I) vp2jlc_matrix(cdMo.inverse(), o44cd); if (displayImageSimulator) { - I = 255; + I = 255u; for (std::list::iterator it = objectImage.begin(); it != objectImage.end(); ++it) { vpImageSimulator *imSim = &(*it); @@ -1127,7 +1127,7 @@ void vpWireFrameSimulator::getExternalImage(vpImage &I) } if (displayImageSimulator) { - I = 255; + I = 255u; for (std::list::iterator it = objectImage.begin(); it != objectImage.end(); ++it) { vpImageSimulator *imSim = &(*it); imSim->setCameraPosition(rotz * camMf * fMo); @@ -1246,7 +1246,7 @@ void vpWireFrameSimulator::getExternalImage(vpImage &I, const vpH add_vwstack("start", "window", -u, u, -v, v); if (displayImageSimulator) { - I = 255; + I = 255u; for (std::list::iterator it = objectImage.begin(); it != objectImage.end(); ++it) { vpImageSimulator *imSim = &(*it); imSim->setCameraPosition(rotz * cam_Mf * fMo); diff --git a/modules/sensor/include/visp3/sensor/vp1394TwoGrabber.h b/modules/sensor/include/visp3/sensor/vp1394TwoGrabber.h index 7623bcea41..4cd222f2f4 100644 --- a/modules/sensor/include/visp3/sensor/vp1394TwoGrabber.h +++ b/modules/sensor/include/visp3/sensor/vp1394TwoGrabber.h @@ -354,7 +354,7 @@ class VISP_EXPORT vp1394TwoGrabber : public vpFrameGrabber //#endif public: - explicit vp1394TwoGrabber(bool reset = true); + VP_EXPLICIT vp1394TwoGrabber(bool reset = true); virtual ~vp1394TwoGrabber(); void acquire(vpImage &I); diff --git a/modules/sensor/include/visp3/sensor/vpDirectShowDevice.h b/modules/sensor/include/visp3/sensor/vpDirectShowDevice.h index 9998487dd2..26e2b123c5 100644 --- a/modules/sensor/include/visp3/sensor/vpDirectShowDevice.h +++ b/modules/sensor/include/visp3/sensor/vpDirectShowDevice.h @@ -61,7 +61,7 @@ class VISP_EXPORT vpDirectShowDevice public: vpDirectShowDevice() : inUse(false) { } - explicit vpDirectShowDevice(const CComPtr &moniker) : inUse(false) { init(moniker); } + VP_EXPLICIT vpDirectShowDevice(const CComPtr &moniker) : inUse(false) { init(moniker); } bool init(const CComPtr &moniker); diff --git a/modules/sensor/include/visp3/sensor/vpForceTorqueAtiNetFTSensor.h b/modules/sensor/include/visp3/sensor/vpForceTorqueAtiNetFTSensor.h index dd8bc5e085..1a8f416d8c 100644 --- a/modules/sensor/include/visp3/sensor/vpForceTorqueAtiNetFTSensor.h +++ b/modules/sensor/include/visp3/sensor/vpForceTorqueAtiNetFTSensor.h @@ -103,7 +103,7 @@ class VISP_EXPORT vpForceTorqueAtiNetFTSensor : public vpUDPClient public: vpForceTorqueAtiNetFTSensor(); vpForceTorqueAtiNetFTSensor(const std::string &hostname, int port); - virtual ~vpForceTorqueAtiNetFTSensor() vp_override; + virtual ~vpForceTorqueAtiNetFTSensor() VP_OVERRIDE; void bias(unsigned int n_counts = 50); /*! diff --git a/modules/sensor/include/visp3/sensor/vpForceTorqueAtiSensor.h b/modules/sensor/include/visp3/sensor/vpForceTorqueAtiSensor.h index 855bcad166..fb4267abed 100644 --- a/modules/sensor/include/visp3/sensor/vpForceTorqueAtiSensor.h +++ b/modules/sensor/include/visp3/sensor/vpForceTorqueAtiSensor.h @@ -86,7 +86,7 @@ class VISP_EXPORT vpForceTorqueAtiSensor : public vpComedi { public: vpForceTorqueAtiSensor(); - virtual ~vpForceTorqueAtiSensor() vp_override; + virtual ~vpForceTorqueAtiSensor() VP_OVERRIDE; void bias(); void close(); diff --git a/modules/sensor/include/visp3/sensor/vpSickLDMRS.h b/modules/sensor/include/visp3/sensor/vpSickLDMRS.h index e5019cee25..c028445054 100644 --- a/modules/sensor/include/visp3/sensor/vpSickLDMRS.h +++ b/modules/sensor/include/visp3/sensor/vpSickLDMRS.h @@ -123,7 +123,7 @@ class VISP_EXPORT vpSickLDMRS : public vpLaserScanner { *this = sick; }; - virtual ~vpSickLDMRS() vp_override; + virtual ~vpSickLDMRS() VP_OVERRIDE; /*! Copy operator. */ vpSickLDMRS &operator=(const vpSickLDMRS &sick) diff --git a/modules/sensor/include/visp3/sensor/vpV4l2Grabber.h b/modules/sensor/include/visp3/sensor/vpV4l2Grabber.h index acd7815937..dafb32e2b9 100644 --- a/modules/sensor/include/visp3/sensor/vpV4l2Grabber.h +++ b/modules/sensor/include/visp3/sensor/vpV4l2Grabber.h @@ -209,7 +209,7 @@ class VISP_EXPORT vpV4l2Grabber : public vpFrameGrabber public: vpV4l2Grabber(); - explicit vpV4l2Grabber(bool verbose); + VP_EXPLICIT vpV4l2Grabber(bool verbose); vpV4l2Grabber(unsigned input, unsigned scale = vpV4l2Grabber::DEFAULT_SCALE); vpV4l2Grabber(vpImage &I, unsigned input, unsigned scale = vpV4l2Grabber::DEFAULT_SCALE); vpV4l2Grabber(vpImage &I, unsigned input, unsigned scale = vpV4l2Grabber::DEFAULT_SCALE); diff --git a/modules/tracker/blob/include/visp3/blob/vpDot.h b/modules/tracker/blob/include/visp3/blob/vpDot.h index b432f5e5de..1fd65f0dec 100644 --- a/modules/tracker/blob/include/visp3/blob/vpDot.h +++ b/modules/tracker/blob/include/visp3/blob/vpDot.h @@ -187,9 +187,9 @@ class VISP_EXPORT vpDot : public vpTracker public: vpDot(); - explicit vpDot(const vpImagePoint &ip); + VP_EXPLICIT vpDot(const vpImagePoint &ip); vpDot(const vpDot &d); - virtual ~vpDot() vp_override; + virtual ~vpDot() VP_OVERRIDE; void display(const vpImage &I, vpColor color = vpColor::red, unsigned int thickness = 1) const; diff --git a/modules/tracker/blob/include/visp3/blob/vpDot2.h b/modules/tracker/blob/include/visp3/blob/vpDot2.h index 2916d542af..b6a7d030b3 100644 --- a/modules/tracker/blob/include/visp3/blob/vpDot2.h +++ b/modules/tracker/blob/include/visp3/blob/vpDot2.h @@ -125,7 +125,7 @@ class VISP_EXPORT vpDot2 : public vpTracker { public: vpDot2(); - explicit vpDot2(const vpImagePoint &ip); + VP_EXPLICIT vpDot2(const vpImagePoint &ip); vpDot2(const vpDot2 &twinDot); static vpMatrix defineDots(vpDot2 dot[], const unsigned int &n, const std::string &dotFile, vpImage &I, diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbDepthDenseTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbDepthDenseTracker.h index e78feb3d07..b9826e5439 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbDepthDenseTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbDepthDenseTracker.h @@ -49,26 +49,26 @@ class VISP_EXPORT vpMbDepthDenseTracker : public virtual vpMbTracker { public: vpMbDepthDenseTracker(); - virtual ~vpMbDepthDenseTracker() vp_override; + virtual ~vpMbDepthDenseTracker() VP_OVERRIDE; virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual inline vpColVector getError() const vp_override { return m_error_depthDense; } virtual std::vector > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - bool displayFullModel = false) vp_override; + bool displayFullModel = false) VP_OVERRIDE; virtual inline vpColVector getRobustWeights() const vp_override { return m_w_depthDense; } - virtual void init(const vpImage &I) vp_override; + virtual void init(const vpImage &I) VP_OVERRIDE; - virtual void loadConfigFile(const std::string &configFile, bool verbose = true) vp_override; + virtual void loadConfigFile(const std::string &configFile, bool verbose = true) VP_OVERRIDE; void reInitModel(const vpImage &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose = false); @@ -77,9 +77,9 @@ class VISP_EXPORT vpMbDepthDenseTracker : public virtual vpMbTracker const vpHomogeneousMatrix &cMo, bool verbose = false); #endif - virtual void resetTracker() vp_override; + virtual void resetTracker() VP_OVERRIDE; - virtual void setCameraParameters(const vpCameraParameters &camera) vp_override; + virtual void setCameraParameters(const vpCameraParameters &camera) VP_OVERRIDE; virtual void setDepthDenseFilteringMaxDistance(double maxDistance); virtual void setDepthDenseFilteringMethod(int method); @@ -97,22 +97,22 @@ class VISP_EXPORT vpMbDepthDenseTracker : public virtual vpMbTracker m_depthDenseSamplingStepY = stepY; } - virtual void setOgreVisibilityTest(const bool &v) vp_override; + virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE; - virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) vp_override; - virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) vp_override; + virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; + virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON) virtual void setPose(const pcl::PointCloud::ConstPtr &point_cloud, const vpHomogeneousMatrix &cdMo); #endif - virtual void setScanLineVisibilityTest(const bool &v) vp_override; + virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE; void setUseDepthDenseTracking(const std::string &name, const bool &useDepthDenseTracking); - virtual void testTracking() vp_override; + virtual void testTracking() VP_OVERRIDE; - virtual void track(const vpImage &) vp_override; - virtual void track(const vpImage &) vp_override; + virtual void track(const vpImage &) VP_OVERRIDE; + virtual void track(const vpImage &) VP_OVERRIDE; #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON) virtual void track(const pcl::PointCloud::ConstPtr &point_cloud); #endif @@ -151,20 +151,20 @@ class VISP_EXPORT vpMbDepthDenseTracker : public virtual vpMbTracker void computeVisibility(unsigned int width, unsigned int height); void computeVVS(); - virtual void computeVVSInit() vp_override; - virtual void computeVVSInteractionMatrixAndResidu() vp_override; + virtual void computeVVSInit() VP_OVERRIDE; + virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE; virtual void computeVVSWeights(); using vpMbTracker::computeVVSWeights; virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace = 0, - const std::string &name = "") vp_override; + const std::string &name = "") VP_OVERRIDE; virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace = 0, - const std::string &name = "") vp_override; + const std::string &name = "") VP_OVERRIDE; - virtual void initFaceFromCorners(vpMbtPolygon &polygon) vp_override; + virtual void initFaceFromCorners(vpMbtPolygon &polygon) VP_OVERRIDE; - virtual void initFaceFromLines(vpMbtPolygon &polygon) vp_override; + virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE; #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON) void segmentPointCloud(const pcl::PointCloud::ConstPtr &point_cloud); diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbDepthNormalTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbDepthNormalTracker.h index 8871e3d9c6..b5500c8b51 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbDepthNormalTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbDepthNormalTracker.h @@ -48,13 +48,13 @@ class VISP_EXPORT vpMbDepthNormalTracker : public virtual vpMbTracker { public: vpMbDepthNormalTracker(); - virtual ~vpMbDepthNormalTracker() vp_override; + virtual ~vpMbDepthNormalTracker() VP_OVERRIDE; virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual inline vpMbtFaceDepthNormal::vpFeatureEstimationType getDepthFeatureEstimationMethod() const { @@ -66,13 +66,13 @@ class VISP_EXPORT vpMbDepthNormalTracker : public virtual vpMbTracker virtual std::vector > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - bool displayFullModel = false) vp_override; + bool displayFullModel = false) VP_OVERRIDE; virtual inline vpColVector getRobustWeights() const vp_override { return m_w_depthNormal; } - virtual void init(const vpImage &I) vp_override; + virtual void init(const vpImage &I) VP_OVERRIDE; - virtual void loadConfigFile(const std::string &configFile, bool verbose = true) vp_override; + virtual void loadConfigFile(const std::string &configFile, bool verbose = true) VP_OVERRIDE; void reInitModel(const vpImage &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose = false); @@ -81,9 +81,9 @@ class VISP_EXPORT vpMbDepthNormalTracker : public virtual vpMbTracker const vpHomogeneousMatrix &cMo, bool verbose = false); #endif - virtual void resetTracker() vp_override; + virtual void resetTracker() VP_OVERRIDE; - virtual void setCameraParameters(const vpCameraParameters &camera) vp_override; + virtual void setCameraParameters(const vpCameraParameters &camera) VP_OVERRIDE; virtual void setDepthNormalFaceCentroidMethod(const vpMbtFaceDepthNormal::vpFaceCentroidType &method); @@ -99,22 +99,22 @@ class VISP_EXPORT vpMbDepthNormalTracker : public virtual vpMbTracker // virtual void setDepthNormalUseRobust(bool use); - virtual void setOgreVisibilityTest(const bool &v) vp_override; + virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE; - virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) vp_override; - virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) vp_override; + virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; + virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON) virtual void setPose(const pcl::PointCloud::ConstPtr &point_cloud, const vpHomogeneousMatrix &cdMo); #endif - virtual void setScanLineVisibilityTest(const bool &v) vp_override; + virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE; void setUseDepthNormalTracking(const std::string &name, const bool &useDepthNormalTracking); - virtual void testTracking() vp_override; + virtual void testTracking() VP_OVERRIDE; - virtual void track(const vpImage &) vp_override; - virtual void track(const vpImage &I_color) vp_override; + virtual void track(const vpImage &) VP_OVERRIDE; + virtual void track(const vpImage &I_color) VP_OVERRIDE; #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON) virtual void track(const pcl::PointCloud::ConstPtr &point_cloud); #endif @@ -165,20 +165,20 @@ class VISP_EXPORT vpMbDepthNormalTracker : public virtual vpMbTracker void computeVisibility(unsigned int width, unsigned int height); void computeVVS(); - virtual void computeVVSInit() vp_override; - virtual void computeVVSInteractionMatrixAndResidu() vp_override; + virtual void computeVVSInit() VP_OVERRIDE; + virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE; virtual std::vector > getFeaturesForDisplayDepthNormal(); virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace = 0, - const std::string &name = "") vp_override; + const std::string &name = "") VP_OVERRIDE; virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace = 0, - const std::string &name = "") vp_override; + const std::string &name = "") VP_OVERRIDE; - virtual void initFaceFromCorners(vpMbtPolygon &polygon) vp_override; + virtual void initFaceFromCorners(vpMbtPolygon &polygon) VP_OVERRIDE; - virtual void initFaceFromLines(vpMbtPolygon &polygon) vp_override; + virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE; #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON) void segmentPointCloud(const pcl::PointCloud::ConstPtr &point_cloud); diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h index 4a0f0f1178..3bbea80c3a 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h @@ -231,16 +231,16 @@ class VISP_EXPORT vpMbEdgeKltTracker : virtual ~vpMbEdgeKltTracker(); virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual inline vpColVector getError() const vp_override { return m_error_hybrid; } virtual std::vector > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - bool displayFullModel = false) vp_override; + bool displayFullModel = false) VP_OVERRIDE; virtual inline vpColVector getRobustWeights() const vp_override { return m_w_hybrid; } @@ -251,13 +251,13 @@ class VISP_EXPORT vpMbEdgeKltTracker : */ virtual inline double getNearClippingDistance() const vp_override { return vpMbKltTracker::getNearClippingDistance(); } - virtual void loadConfigFile(const std::string &configFile, bool verbose = true) vp_override; + virtual void loadConfigFile(const std::string &configFile, bool verbose = true) VP_OVERRIDE; void reInitModel(const vpImage &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, - bool verbose = false, const vpHomogeneousMatrix &T = vpHomogeneousMatrix()) vp_override; - void resetTracker() vp_override; + bool verbose = false, const vpHomogeneousMatrix &T = vpHomogeneousMatrix()) VP_OVERRIDE; + void resetTracker() VP_OVERRIDE; - virtual void setCameraParameters(const vpCameraParameters &cam) vp_override; + virtual void setCameraParameters(const vpCameraParameters &cam) VP_OVERRIDE; /*! * Specify which clipping to use. @@ -309,8 +309,8 @@ class VISP_EXPORT vpMbEdgeKltTracker : vpMbKltTracker::setScanLineVisibilityTest(v); } - virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) vp_override; - virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) vp_override; + virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; + virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; /*! * Set if the projection error criteria has to be computed. @@ -324,23 +324,23 @@ class VISP_EXPORT vpMbEdgeKltTracker : } virtual void testTracking() vp_override { } - virtual void track(const vpImage &I) vp_override; - virtual void track(const vpImage &I_color) vp_override; + virtual void track(const vpImage &I) VP_OVERRIDE; + virtual void track(const vpImage &I_color) VP_OVERRIDE; protected: virtual void computeVVS(const vpImage &I, const unsigned int &nbInfos, unsigned int &nbrow, unsigned int lvl = 0, double *edge_residual = nullptr, double *klt_residual = nullptr); - virtual void computeVVSInit() vp_override; - virtual void computeVVSInteractionMatrixAndResidu() vp_override; + virtual void computeVVSInit() VP_OVERRIDE; + virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE; using vpMbTracker::computeCovarianceMatrixVVS; using vpMbTracker::computeVVSPoseEstimation; - virtual void init(const vpImage &I) vp_override; + virtual void init(const vpImage &I) VP_OVERRIDE; virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, double r, int idFace = 0, - const std::string &name = "") vp_override; - virtual void initCylinder(const vpPoint &, const vpPoint &, double r, int idFace, const std::string &name = "") vp_override; - virtual void initFaceFromCorners(vpMbtPolygon &polygon) vp_override; - virtual void initFaceFromLines(vpMbtPolygon &polygon) vp_override; + const std::string &name = "") VP_OVERRIDE; + virtual void initCylinder(const vpPoint &, const vpPoint &, double r, int idFace, const std::string &name = "") VP_OVERRIDE; + virtual void initFaceFromCorners(vpMbtPolygon &polygon) VP_OVERRIDE; + virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE; unsigned int initMbtTracking(unsigned int level = 0); bool postTracking(const vpImage &I, vpColVector &w_mbt, vpColVector &w_klt, unsigned int lvl = 0); diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h index bd80dc5f42..4fea74f221 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h @@ -313,15 +313,15 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker public: vpMbEdgeTracker(); - virtual ~vpMbEdgeTracker() vp_override; + virtual ~vpMbEdgeTracker() VP_OVERRIDE; /** @name Inherited functionalities from vpMbEdgeTracker */ //@{ virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; void getLline(std::list &linesList, unsigned int level = 0) const; void getLcircle(std::list &circlesList, unsigned int level = 0) const; @@ -330,7 +330,7 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker virtual std::vector > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - bool displayFullModel = false) vp_override; + bool displayFullModel = false) VP_OVERRIDE; /*! * Get the moving edge parameters. @@ -369,11 +369,11 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker virtual inline vpColVector getRobustWeights() const vp_override { return m_w_edge; } - virtual void loadConfigFile(const std::string &configFile, bool verbose = true) vp_override; + virtual void loadConfigFile(const std::string &configFile, bool verbose = true) VP_OVERRIDE; virtual void reInitModel(const vpImage &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose = false, const vpHomogeneousMatrix &T = vpHomogeneousMatrix()); - void resetTracker() vp_override; + void resetTracker() VP_OVERRIDE; /*! * Set the camera parameters. @@ -402,11 +402,11 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker } } - virtual void setClipping(const unsigned int &flags) vp_override; + virtual void setClipping(const unsigned int &flags) VP_OVERRIDE; - virtual void setFarClippingDistance(const double &dist) vp_override; + virtual void setFarClippingDistance(const double &dist) VP_OVERRIDE; - virtual void setNearClippingDistance(const double &dist) vp_override; + virtual void setNearClippingDistance(const double &dist) VP_OVERRIDE; /*! * Use Ogre3D for visibility tests @@ -459,15 +459,15 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker void setMovingEdge(const vpMe &me); - virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) vp_override; - virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) vp_override; + virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; + virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; void setScales(const std::vector &_scales); void setUseEdgeTracking(const std::string &name, const bool &useEdgeTracking); - virtual void track(const vpImage &I) vp_override; - virtual void track(const vpImage &I) vp_override; + virtual void track(const vpImage &I) VP_OVERRIDE; + virtual void track(const vpImage &I) VP_OVERRIDE; //@} protected: @@ -486,8 +486,8 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker void computeVVSFirstPhase(const vpImage &I, unsigned int iter, double &count, unsigned int lvl = 0); void computeVVSFirstPhaseFactor(const vpImage &I, unsigned int lvl = 0); void computeVVSFirstPhasePoseEstimation(unsigned int iter, bool &isoJoIdentity); - virtual void computeVVSInit() vp_override; - virtual void computeVVSInteractionMatrixAndResidu() vp_override; + virtual void computeVVSInit() VP_OVERRIDE; + virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE; virtual void computeVVSInteractionMatrixAndResidu(const vpImage &I); virtual void computeVVSWeights(); using vpMbTracker::computeVVSWeights; @@ -496,13 +496,13 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker void displayFeaturesOnImage(const vpImage &I); void downScale(const unsigned int _scale); virtual std::vector > getFeaturesForDisplayEdge(); - virtual void init(const vpImage &I) vp_override; + virtual void init(const vpImage &I) VP_OVERRIDE; virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace = 0, - const std::string &name = "") vp_override; + const std::string &name = "") VP_OVERRIDE; virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace = 0, - const std::string &name = "") vp_override; - virtual void initFaceFromCorners(vpMbtPolygon &polygon) vp_override; - virtual void initFaceFromLines(vpMbtPolygon &polygon) vp_override; + const std::string &name = "") VP_OVERRIDE; + virtual void initFaceFromCorners(vpMbtPolygon &polygon) VP_OVERRIDE; + virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE; unsigned int initMbtTracking(unsigned int &nberrors_lines, unsigned int &nberrors_cylinders, unsigned int &nberrors_circles); void initMovingEdge(const vpImage &I, const vpHomogeneousMatrix &_cMo); @@ -513,7 +513,7 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker void removeCylinder(const std::string &name); void removeLine(const std::string &name); void resetMovingEdge(); - virtual void testTracking() vp_override; + virtual void testTracking() VP_OVERRIDE; void trackMovingEdge(const vpImage &I); void updateMovingEdge(const vpImage &I); void updateMovingEdgeWeights(); diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h index 5ff490bebc..5d92b2d757 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h @@ -212,20 +212,20 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker vpMbGenericTracker(); vpMbGenericTracker(unsigned int nbCameras, int trackerType = EDGE_TRACKER); - explicit vpMbGenericTracker(const std::vector &trackerTypes); + VP_EXPLICIT vpMbGenericTracker(const std::vector &trackerTypes); vpMbGenericTracker(const std::vector &cameraNames, const std::vector &trackerTypes); - virtual ~vpMbGenericTracker() vp_override; + virtual ~vpMbGenericTracker() VP_OVERRIDE; virtual double computeCurrentProjectionError(const vpImage &I, const vpHomogeneousMatrix &_cMo, - const vpCameraParameters &_cam) vp_override; + const vpCameraParameters &_cam) VP_OVERRIDE; virtual double computeCurrentProjectionError(const vpImage &I, const vpHomogeneousMatrix &_cMo, const vpCameraParameters &_cam); virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual void display(const vpImage &I1, const vpImage &I2, const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1, @@ -247,7 +247,7 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual std::vector getCameraNames() const; using vpMbTracker::getCameraParameters; - virtual void getCameraParameters(vpCameraParameters &camera) const vp_override; + virtual void getCameraParameters(vpCameraParameters &camera) const VP_OVERRIDE; virtual void getCameraParameters(vpCameraParameters &cam1, vpCameraParameters &cam2) const; virtual void getCameraParameters(std::map &mapOfCameraParameters) const; @@ -259,7 +259,7 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual inline vpColVector getError() const vp_override { return m_error; } - virtual vpMbHiddenFaces &getFaces() vp_override; + virtual vpMbHiddenFaces &getFaces() VP_OVERRIDE; virtual vpMbHiddenFaces &getFaces(const std::string &cameraName); #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) @@ -304,7 +304,7 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual std::vector > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - bool displayFullModel = false) vp_override; + bool displayFullModel = false) VP_OVERRIDE; virtual void getModelForDisplay(std::map > > &mapOfModels, const std::map &mapOfwidths, const std::map &mapOfheights, @@ -341,20 +341,20 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual unsigned int getNbPoints(unsigned int level = 0) const; virtual void getNbPoints(std::map &mapOfNbPoints, unsigned int level = 0) const; - virtual unsigned int getNbPolygon() const vp_override; + virtual unsigned int getNbPolygon() const VP_OVERRIDE; virtual void getNbPolygon(std::map &mapOfNbPolygons) const; - virtual vpMbtPolygon *getPolygon(unsigned int index) vp_override; + virtual vpMbtPolygon *getPolygon(unsigned int index) VP_OVERRIDE; virtual vpMbtPolygon *getPolygon(const std::string &cameraName, unsigned int index); virtual std::pair, std::vector > > - getPolygonFaces(bool orderPolygons = true, bool useVisibility = true, bool clipPolygon = false) vp_override; + getPolygonFaces(bool orderPolygons = true, bool useVisibility = true, bool clipPolygon = false) VP_OVERRIDE; virtual void getPolygonFaces(std::map > &mapOfPolygons, std::map > > &mapOfPoints, bool orderPolygons = true, bool useVisibility = true, bool clipPolygon = false); using vpMbTracker::getPose; - virtual void getPose(vpHomogeneousMatrix &cMo) const vp_override; + virtual void getPose(vpHomogeneousMatrix &cMo) const VP_OVERRIDE; virtual void getPose(vpHomogeneousMatrix &c1Mo, vpHomogeneousMatrix &c2Mo) const; virtual void getPose(std::map &mapOfCameraPoses) const; @@ -364,7 +364,7 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual int getTrackerType() const; - virtual void init(const vpImage &I) vp_override; + virtual void init(const vpImage &I) VP_OVERRIDE; #ifdef VISP_HAVE_MODULE_GUI using vpMbTracker::initClick; @@ -399,7 +399,7 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker const std::map &mapOfInitPoints); using vpMbTracker::initFromPose; - virtual void initFromPose(const vpImage &I, const vpHomogeneousMatrix &cMo) vp_override; + virtual void initFromPose(const vpImage &I, const vpHomogeneousMatrix &cMo) VP_OVERRIDE; virtual void initFromPose(const vpImage &I1, const vpImage &I2, const std::string &initFile1, const std::string &initFile2); virtual void initFromPose(const vpImage &I_color1, const vpImage &I_color2, @@ -420,7 +420,7 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual void initFromPose(const std::map *> &mapOfColorImages, const std::map &mapOfCameraPoses); - virtual void loadConfigFile(const std::string &configFile, bool verbose = true) vp_override; + virtual void loadConfigFile(const std::string &configFile, bool verbose = true) VP_OVERRIDE; virtual void loadConfigFile(const std::string &configFile1, const std::string &configFile2, bool verbose = true); virtual void loadConfigFile(const std::map &mapOfConfigFiles, bool verbose = true); @@ -429,7 +429,7 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker #endif virtual void loadModel(const std::string &modelFile, bool verbose = false, - const vpHomogeneousMatrix &T = vpHomogeneousMatrix()) vp_override; + const vpHomogeneousMatrix &T = vpHomogeneousMatrix()) VP_OVERRIDE; virtual void loadModel(const std::string &modelFile1, const std::string &modelFile2, bool verbose = false, const vpHomogeneousMatrix &T1 = vpHomogeneousMatrix(), const vpHomogeneousMatrix &T2 = vpHomogeneousMatrix()); @@ -465,17 +465,17 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker const std::map &mapOfCameraPoses, bool verbose = false, const std::map &mapOfT = std::map()); - virtual void resetTracker() vp_override; + virtual void resetTracker() VP_OVERRIDE; - virtual void setAngleAppear(const double &a) vp_override; + virtual void setAngleAppear(const double &a) VP_OVERRIDE; virtual void setAngleAppear(const double &a1, const double &a2); virtual void setAngleAppear(const std::map &mapOfAngles); - virtual void setAngleDisappear(const double &a) vp_override; + virtual void setAngleDisappear(const double &a) VP_OVERRIDE; virtual void setAngleDisappear(const double &a1, const double &a2); virtual void setAngleDisappear(const std::map &mapOfAngles); - virtual void setCameraParameters(const vpCameraParameters &camera) vp_override; + virtual void setCameraParameters(const vpCameraParameters &camera) VP_OVERRIDE; virtual void setCameraParameters(const vpCameraParameters &camera1, const vpCameraParameters &camera2); virtual void setCameraParameters(const std::map &mapOfCameraParameters); @@ -484,7 +484,7 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual void setCameraTransformationMatrix(const std::map &mapOfTransformationMatrix); - virtual void setClipping(const unsigned int &flags) vp_override; + virtual void setClipping(const unsigned int &flags) VP_OVERRIDE; virtual void setClipping(const unsigned int &flags1, const unsigned int &flags2); virtual void setClipping(const std::map &mapOfClippingFlags); @@ -501,9 +501,9 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual void setDepthNormalPclPlaneEstimationRansacThreshold(double threshold); virtual void setDepthNormalSamplingStep(unsigned int stepX, unsigned int stepY); - virtual void setDisplayFeatures(bool displayF) vp_override; + virtual void setDisplayFeatures(bool displayF) VP_OVERRIDE; - virtual void setFarClippingDistance(const double &dist) vp_override; + virtual void setFarClippingDistance(const double &dist) VP_OVERRIDE; virtual void setFarClippingDistance(const double &dist1, const double &dist2); virtual void setFarClippingDistance(const std::map &mapOfClippingDists); @@ -528,28 +528,28 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual void setKltThresholdAcceptation(double th); #endif - virtual void setLod(bool useLod, const std::string &name = "") vp_override; + virtual void setLod(bool useLod, const std::string &name = "") VP_OVERRIDE; - virtual void setMask(const vpImage &mask) vp_override; + virtual void setMask(const vpImage &mask) VP_OVERRIDE; - virtual void setMinLineLengthThresh(double minLineLengthThresh, const std::string &name = "") vp_override; - virtual void setMinPolygonAreaThresh(double minPolygonAreaThresh, const std::string &name = "") vp_override; + virtual void setMinLineLengthThresh(double minLineLengthThresh, const std::string &name = "") VP_OVERRIDE; + virtual void setMinPolygonAreaThresh(double minPolygonAreaThresh, const std::string &name = "") VP_OVERRIDE; virtual void setMovingEdge(const vpMe &me); virtual void setMovingEdge(const vpMe &me1, const vpMe &me2); virtual void setMovingEdge(const std::map &mapOfMe); - virtual void setNearClippingDistance(const double &dist) vp_override; + virtual void setNearClippingDistance(const double &dist) VP_OVERRIDE; virtual void setNearClippingDistance(const double &dist1, const double &dist2); virtual void setNearClippingDistance(const std::map &mapOfDists); - virtual void setOgreShowConfigDialog(bool showConfigDialog) vp_override; - virtual void setOgreVisibilityTest(const bool &v) vp_override; + virtual void setOgreShowConfigDialog(bool showConfigDialog) VP_OVERRIDE; + virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE; - virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt) vp_override; + virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt) VP_OVERRIDE; - virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) vp_override; - virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) vp_override; + virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; + virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; virtual void setPose(const vpImage &I1, const vpImage &I2, const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo); @@ -561,15 +561,15 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual void setPose(const std::map *> &mapOfColorImages, const std::map &mapOfCameraPoses); - virtual void setProjectionErrorComputation(const bool &flag) vp_override; + virtual void setProjectionErrorComputation(const bool &flag) VP_OVERRIDE; - virtual void setProjectionErrorDisplay(bool display) vp_override; - virtual void setProjectionErrorDisplayArrowLength(unsigned int length) vp_override; - virtual void setProjectionErrorDisplayArrowThickness(unsigned int thickness) vp_override; + virtual void setProjectionErrorDisplay(bool display) VP_OVERRIDE; + virtual void setProjectionErrorDisplayArrowLength(unsigned int length) VP_OVERRIDE; + virtual void setProjectionErrorDisplayArrowThickness(unsigned int thickness) VP_OVERRIDE; virtual void setReferenceCameraName(const std::string &referenceCameraName); - virtual void setScanLineVisibilityTest(const bool &v) vp_override; + virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE; virtual void setTrackerType(int type); virtual void setTrackerType(const std::map &mapOfTrackerTypes); @@ -581,10 +581,10 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual void setUseKltTracking(const std::string &name, const bool &useKltTracking); #endif - virtual void testTracking() vp_override; + virtual void testTracking() VP_OVERRIDE; - virtual void track(const vpImage &I) vp_override; - virtual void track(const vpImage &I_color) vp_override; + virtual void track(const vpImage &I) VP_OVERRIDE; + virtual void track(const vpImage &I_color) VP_OVERRIDE; virtual void track(const vpImage &I1, const vpImage &I2); virtual void track(const vpImage &I_color1, const vpImage &I_color2); @@ -622,23 +622,23 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual void computeVVS(std::map *> &mapOfImages); - virtual void computeVVSInit() vp_override; + virtual void computeVVSInit() VP_OVERRIDE; virtual void computeVVSInit(std::map *> &mapOfImages); - virtual void computeVVSInteractionMatrixAndResidu() vp_override; + virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE; virtual void computeVVSInteractionMatrixAndResidu(std::map *> &mapOfImages, std::map &mapOfVelocityTwist); using vpMbTracker::computeVVSWeights; virtual void computeVVSWeights(); virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace = 0, - const std::string &name = "") vp_override; + const std::string &name = "") VP_OVERRIDE; virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace = 0, - const std::string &name = "") vp_override; + const std::string &name = "") VP_OVERRIDE; - virtual void initFaceFromCorners(vpMbtPolygon &polygon) vp_override; + virtual void initFaceFromCorners(vpMbtPolygon &polygon) VP_OVERRIDE; - virtual void initFaceFromLines(vpMbtPolygon &polygon) vp_override; + virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE; virtual void loadConfigFileXML(const std::string &configFile, bool verbose = true); #ifdef VISP_HAVE_NLOHMANN_JSON @@ -694,53 +694,53 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual inline int getTrackerType() const { return m_trackerType; } virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual std::vector > getFeaturesForDisplay(); virtual std::vector > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - bool displayFullModel = false) vp_override; + bool displayFullModel = false) VP_OVERRIDE; - virtual void init(const vpImage &I) vp_override; + virtual void init(const vpImage &I) VP_OVERRIDE; - virtual void loadConfigFile(const std::string &configFile, bool verbose = true) vp_override; + virtual void loadConfigFile(const std::string &configFile, bool verbose = true) VP_OVERRIDE; virtual void reInitModel(const vpImage &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose = false, - const vpHomogeneousMatrix &T = vpHomogeneousMatrix()) vp_override; + const vpHomogeneousMatrix &T = vpHomogeneousMatrix()) VP_OVERRIDE; virtual void reInitModel(const vpImage &I_color, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose = false, const vpHomogeneousMatrix &T = vpHomogeneousMatrix()); - virtual void resetTracker() vp_override; + virtual void resetTracker() VP_OVERRIDE; - virtual void setCameraParameters(const vpCameraParameters &camera) vp_override; + virtual void setCameraParameters(const vpCameraParameters &camera) VP_OVERRIDE; - virtual void setClipping(const unsigned int &flags) vp_override; + virtual void setClipping(const unsigned int &flags) VP_OVERRIDE; - virtual void setFarClippingDistance(const double &dist) vp_override; + virtual void setFarClippingDistance(const double &dist) VP_OVERRIDE; - virtual void setNearClippingDistance(const double &dist) vp_override; + virtual void setNearClippingDistance(const double &dist) VP_OVERRIDE; - virtual void setOgreVisibilityTest(const bool &v) vp_override; + virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE; - virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) vp_override; - virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) vp_override; + virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; + virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; - virtual void setProjectionErrorComputation(const bool &flag) vp_override; + virtual void setProjectionErrorComputation(const bool &flag) VP_OVERRIDE; - virtual void setScanLineVisibilityTest(const bool &v) vp_override; + virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE; virtual void setTrackerType(int type); - virtual void testTracking() vp_override; + virtual void testTracking() VP_OVERRIDE; - virtual void track(const vpImage &I) vp_override; - virtual void track(const vpImage &I_color) vp_override; + virtual void track(const vpImage &I) VP_OVERRIDE; + virtual void track(const vpImage &I_color) VP_OVERRIDE; #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON) // Fix error: using declaration ‘using vpMbDepthDenseTracker::setPose’ conflicts with a previous // using declaration that occurs with g++ 4.6.3 on Ubuntu 12.04 @@ -755,22 +755,22 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker protected: virtual void computeVVS(const vpImage *const ptr_I); - virtual void computeVVSInit() vp_override; + virtual void computeVVSInit() VP_OVERRIDE; virtual void computeVVSInit(const vpImage *const ptr_I); - virtual void computeVVSInteractionMatrixAndResidu() vp_override; + virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE; using vpMbEdgeTracker::computeVVSInteractionMatrixAndResidu; virtual void computeVVSInteractionMatrixAndResidu(const vpImage *const ptr_I); using vpMbTracker::computeVVSWeights; - virtual void computeVVSWeights() vp_override; + virtual void computeVVSWeights() VP_OVERRIDE; virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace = 0, - const std::string &name = "") vp_override; + const std::string &name = "") VP_OVERRIDE; virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace = 0, - const std::string &name = "") vp_override; + const std::string &name = "") VP_OVERRIDE; - virtual void initFaceFromCorners(vpMbtPolygon &polygon) vp_override; - virtual void initFaceFromLines(vpMbtPolygon &polygon) vp_override; + virtual void initFaceFromCorners(vpMbtPolygon &polygon) VP_OVERRIDE; + virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE; virtual void initMbtTracking(const vpImage *const ptr_I); @@ -803,7 +803,7 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker #endif #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) virtual void setPose(const vpImage *I, const vpImage *I_color, - const vpHomogeneousMatrix &cdMo) vp_override; + const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; #else virtual void setPose(const vpImage *I, const vpImage *I_color, const vpHomogeneousMatrix &cdMo); diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h index a2d4415298..bc56e7816f 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h @@ -258,9 +258,9 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, double r, const std::string &name = ""); virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override; + const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; /*! Return the address of the circle feature list. */ virtual std::list &getFeaturesCircle() { return circles_disp; } @@ -316,15 +316,15 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker virtual std::vector > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, - bool displayFullModel = false) vp_override; + bool displayFullModel = false) VP_OVERRIDE; - virtual void loadConfigFile(const std::string &configFile, bool verbose = true) vp_override; + virtual void loadConfigFile(const std::string &configFile, bool verbose = true) VP_OVERRIDE; virtual void reInitModel(const vpImage &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose = false, const vpHomogeneousMatrix &T = vpHomogeneousMatrix()); - void resetTracker() vp_override; + void resetTracker() VP_OVERRIDE; - void setCameraParameters(const vpCameraParameters &cam) vp_override; + void setCameraParameters(const vpCameraParameters &cam) VP_OVERRIDE; /*! * Set the erosion of the mask used on the Model faces. @@ -376,8 +376,8 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker (*it)->useScanLine = v; } - virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) vp_override; - virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) vp_override; + virtual void setPose(const vpImage &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; + virtual void setPose(const vpImage &I_color, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE; /*! * Set if the projection error criteria has to be computed. @@ -395,9 +395,9 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker void setUseKltTracking(const std::string &name, const bool &useKltTracking); - virtual void testTracking() vp_override; - virtual void track(const vpImage &I) vp_override; - virtual void track(const vpImage &I_color) vp_override; + virtual void testTracking() VP_OVERRIDE; + virtual void track(const vpImage &I) VP_OVERRIDE; + virtual void track(const vpImage &I_color) VP_OVERRIDE; /*! @name Deprecated functions @@ -410,7 +410,7 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker * * \return The erosion. */ - /* vp_deprecated */ inline unsigned int getMaskBorder() const { return maskBorder; } + /* VP_DEPRECATED */ inline unsigned int getMaskBorder() const { return maskBorder; } /*! * Get the current number of klt points. @@ -418,7 +418,7 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker * * \return the number of features */ - /* vp_deprecated */ inline int getNbKltPoints() const { return tracker.getNbFeatures(); } + /* VP_DEPRECATED */ inline int getNbKltPoints() const { return tracker.getNbFeatures(); } /*! * Get the threshold for the acceptation of a point. @@ -427,14 +427,14 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker * \return threshold_outlier : Threshold for the weight below which a point * is rejected. */ - /* vp_deprecated */ inline double getThresholdAcceptation() const { return threshold_outlier; } + /* VP_DEPRECATED */ inline double getThresholdAcceptation() const { return threshold_outlier; } /*! * Set the erosion of the mask used on the Model faces. * * \param e : The desired erosion. */ - /* vp_deprecated */ inline void setMaskBorder(const unsigned int &e) + /* VP_DEPRECATED */ inline void setMaskBorder(const unsigned int &e) { maskBorder = e; // if(useScanLine) @@ -447,7 +447,7 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker * * \param th : Threshold for the weight below which a point is rejected. */ - /* vp_deprecated */ inline void setThresholdAcceptation(double th) { threshold_outlier = th; } + /* VP_DEPRECATED */ inline void setThresholdAcceptation(double th) { threshold_outlier = th; } //@} @@ -455,16 +455,16 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker /** @name Protected Member Functions Inherited from vpMbKltTracker */ //@{ void computeVVS(); - virtual void computeVVSInit() vp_override; - virtual void computeVVSInteractionMatrixAndResidu() vp_override; + virtual void computeVVSInit() VP_OVERRIDE; + virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE; virtual std::vector > getFeaturesForDisplayKlt(); - virtual void init(const vpImage &I) vp_override; - virtual void initFaceFromCorners(vpMbtPolygon &polygon) vp_override; - virtual void initFaceFromLines(vpMbtPolygon &polygon) vp_override; - virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, double, int, const std::string &name = "") vp_override; - virtual void initCylinder(const vpPoint &, const vpPoint &, double, int, const std::string &name = "") vp_override; + virtual void init(const vpImage &I) VP_OVERRIDE; + virtual void initFaceFromCorners(vpMbtPolygon &polygon) VP_OVERRIDE; + virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE; + virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, double, int, const std::string &name = "") VP_OVERRIDE; + virtual void initCylinder(const vpPoint &, const vpPoint &, double, int, const std::string &name = "") VP_OVERRIDE; void preTracking(const vpImage &I); bool postTracking(const vpImage &I, vpColVector &w); diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbtMeEllipse.h b/modules/tracker/mbt/include/visp3/mbt/vpMbtMeEllipse.h index 0d22ae9013..edb1be5939 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbtMeEllipse.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbtMeEllipse.h @@ -75,7 +75,7 @@ class VISP_EXPORT vpMbtMeEllipse : public vpMeEllipse private: void reSample(const vpImage &I); - void sample(const vpImage &I, bool doNotTrack = false) vp_override; + void sample(const vpImage &I, bool doNotTrack = false) VP_OVERRIDE; void suppressPoints(); }; END_VISP_NAMESPACE diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbtMeLine.h b/modules/tracker/mbt/include/visp3/mbt/vpMbtMeLine.h index 4b1b87335d..259f41910f 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbtMeLine.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbtMeLine.h @@ -68,7 +68,7 @@ class VISP_EXPORT vpMbtMeLine : public vpMeTracker public: vpMbtMeLine(); - virtual ~vpMbtMeLine() vp_override; + virtual ~vpMbtMeLine() VP_OVERRIDE; void computeProjectionError(const vpImage &_I, double &_sumErrorRad, unsigned int &_nbFeatures, const vpMatrix &SobelX, const vpMatrix &SobelY, bool display, unsigned int length, @@ -113,7 +113,7 @@ class VISP_EXPORT vpMbtMeLine : public vpMeTracker private: void bubbleSortI(); void bubbleSortJ(); - void sample(const vpImage &image, bool doNotTrack = false) vp_override; + void sample(const vpImage &image, bool doNotTrack = false) VP_OVERRIDE; void seekExtremities(const vpImage &I); void setExtremities(); void suppressPoints(const vpImage &I); diff --git a/modules/tracker/me/include/visp3/me/vpMeEllipse.h b/modules/tracker/me/include/visp3/me/vpMeEllipse.h index 3b9460cd4b..e1108937a0 100644 --- a/modules/tracker/me/include/visp3/me/vpMeEllipse.h +++ b/modules/tracker/me/include/visp3/me/vpMeEllipse.h @@ -108,7 +108,7 @@ class VISP_EXPORT vpMeEllipse : public vpMeTracker /*! * Destructor. */ - virtual ~vpMeEllipse() vp_override; + virtual ~vpMeEllipse() VP_OVERRIDE; /*! * Display the ellipse or arc of ellipse @@ -390,14 +390,14 @@ class VISP_EXPORT vpMeEllipse : public vpMeTracker /*! * \deprecated Use rather displayEllipse(). */ - vp_deprecated static void display(const vpImage &I, const vpImagePoint ¢er, const double &A, const double &B, + VP_DEPRECATED static void display(const vpImage &I, const vpImagePoint ¢er, const double &A, const double &B, const double &E, const double &smallalpha, const double &highalpha, const vpColor &color = vpColor::green, unsigned int thickness = 1); /*! * \deprecated Use rather displayEllipse(). */ - vp_deprecated static void display(const vpImage &I, const vpImagePoint ¢er, const double &A, const double &B, + VP_DEPRECATED static void display(const vpImage &I, const vpImagePoint ¢er, const double &A, const double &B, const double &E, const double &smallalpha, const double &highalpha, const vpColor &color = vpColor::green, unsigned int thickness = 1); #endif @@ -611,7 +611,7 @@ class VISP_EXPORT vpMeEllipse : public vpMeTracker * \exception vpTrackingException::initializationError : Moving edges not * initialized. */ - virtual void sample(const vpImage &I, bool doNotTrack = false) vp_override; + virtual void sample(const vpImage &I, bool doNotTrack = false) VP_OVERRIDE; /*! * Compute the \f$ theta \f$ angle for each vpMeSite. diff --git a/modules/tracker/me/include/visp3/me/vpMeLine.h b/modules/tracker/me/include/visp3/me/vpMeLine.h index e8fe3fab0b..b8a0c6d1a4 100644 --- a/modules/tracker/me/include/visp3/me/vpMeLine.h +++ b/modules/tracker/me/include/visp3/me/vpMeLine.h @@ -103,7 +103,7 @@ BEGIN_VISP_NAMESPACE * vpImage I(240, 320); * * // Fill the image with a black rectangle - * I = 0; + * I = 0u; * for (int i = 100; i < 180; i ++) { * for (int j = 120; j < 250; j ++) { * I[i][j] = 255; @@ -182,7 +182,7 @@ class VISP_EXPORT vpMeLine : public vpMeTracker /*! * Destructor. */ - virtual ~vpMeLine() vp_override; + virtual ~vpMeLine() VP_OVERRIDE; /*! * Display line. @@ -214,7 +214,7 @@ class VISP_EXPORT vpMeLine : public vpMeTracker * \exception vpTrackingException::initializationError : Moving edges not * initialized. */ - virtual void sample(const vpImage &I, bool doNotTrack = false) vp_override; + virtual void sample(const vpImage &I, bool doNotTrack = false) VP_OVERRIDE; /*! * Resample the line if the number of sample is less than 80% of the @@ -433,28 +433,28 @@ class VISP_EXPORT vpMeLine : public vpMeTracker /*! * \deprecated Use rather displayLine(). */ - vp_deprecated static void display(const vpImage &I, const vpMeSite &PExt1, const vpMeSite &PExt2, const double &A, + VP_DEPRECATED static void display(const vpImage &I, const vpMeSite &PExt1, const vpMeSite &PExt2, const double &A, const double &B, const double &C, const vpColor &color = vpColor::green, unsigned int thickness = 1); /*! * \deprecated Use rather displayLine(). */ - vp_deprecated static void display(const vpImage &I, const vpMeSite &PExt1, const vpMeSite &PExt2, const double &A, + VP_DEPRECATED static void display(const vpImage &I, const vpMeSite &PExt1, const vpMeSite &PExt2, const double &A, const double &B, const double &C, const vpColor &color = vpColor::green, unsigned int thickness = 1); /*! * \deprecated Use rather displayLine(). */ - vp_deprecated static void display(const vpImage &I, const vpMeSite &PExt1, const vpMeSite &PExt2, + VP_DEPRECATED static void display(const vpImage &I, const vpMeSite &PExt1, const vpMeSite &PExt2, const std::list &site_list, const double &A, const double &B, const double &C, const vpColor &color = vpColor::green, unsigned int thickness = 1); /*! * \deprecated Use rather displayLine(). */ - vp_deprecated static void display(const vpImage &I, const vpMeSite &PExt1, const vpMeSite &PExt2, + VP_DEPRECATED static void display(const vpImage &I, const vpMeSite &PExt1, const vpMeSite &PExt2, const std::list &site_list, const double &A, const double &B, const double &C, const vpColor &color = vpColor::green, unsigned int thickness = 1); #endif diff --git a/modules/tracker/me/include/visp3/me/vpMeNurbs.h b/modules/tracker/me/include/visp3/me/vpMeNurbs.h index 3fd4f40ea4..4bfe6b3916 100644 --- a/modules/tracker/me/include/visp3/me/vpMeNurbs.h +++ b/modules/tracker/me/include/visp3/me/vpMeNurbs.h @@ -76,7 +76,7 @@ BEGIN_VISP_NAMESPACE * vpImage I(240, 320); * * // Fill the image with a black rectangle - * I = 0; + * I = 0u; * for (int i = 100; i < 180; i ++) { * for (int j = 0; j < 320; j ++) { * I[i][j] = 255; diff --git a/modules/tracker/me/include/visp3/me/vpMeTracker.h b/modules/tracker/me/include/visp3/me/vpMeTracker.h index 745a37026b..10196e09a7 100644 --- a/modules/tracker/me/include/visp3/me/vpMeTracker.h +++ b/modules/tracker/me/include/visp3/me/vpMeTracker.h @@ -74,7 +74,7 @@ class VISP_EXPORT vpMeTracker : public vpTracker /*! * Destructor. */ - virtual ~vpMeTracker() vp_override; + virtual ~vpMeTracker() VP_OVERRIDE; /** @name Public Member Functions Inherited from vpMeTracker */ //@{ @@ -296,7 +296,7 @@ class VISP_EXPORT vpMeTracker : public vpTracker * \param i : Pixel coordinate along the rows. * \param j : Pixel coordinate along the columns. */ - vp_deprecated static bool inMask(const vpImage *mask, unsigned int i, unsigned int j) + VP_DEPRECATED static bool inMask(const vpImage *mask, unsigned int i, unsigned int j) { return inRoiMask(mask, i, j); } diff --git a/modules/tracker/tt/include/visp3/tt/vpTemplateTracker.h b/modules/tracker/tt/include/visp3/tt/vpTemplateTracker.h index b8560651d4..49c70500cb 100644 --- a/modules/tracker/tt/include/visp3/tt/vpTemplateTracker.h +++ b/modules/tracker/tt/include/visp3/tt/vpTemplateTracker.h @@ -158,7 +158,7 @@ class VISP_EXPORT vpTemplateTracker useCompositionnal(false), useInverse(false), Warp(nullptr), p(), dp(), X1(), X2(), dW(), BI(), dIx(), dIy(), zoneRef_() { } - explicit vpTemplateTracker(vpTemplateTrackerWarp *_warp); + VP_EXPLICIT vpTemplateTracker(vpTemplateTrackerWarp *_warp); virtual ~vpTemplateTracker(); void display(const vpImage &I, const vpColor &col = vpColor::green, unsigned int thickness = 3); @@ -279,7 +279,7 @@ class VISP_EXPORT vpTemplateTracker Use rather setThresholdResidualDerivative() \param threshold : Unused value. */ - vp_deprecated void setThresholdRMS(double threshold) { (void)threshold; } + VP_DEPRECATED void setThresholdRMS(double threshold) { (void)threshold; } //@} #endif diff --git a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSD.h b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSD.h index bfbcfc1d0e..701d4996d4 100644 --- a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSD.h +++ b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSD.h @@ -74,7 +74,7 @@ class VISP_EXPORT vpTemplateTrackerSSD : public vpTemplateTracker virtual void trackNoPyr(const vpImage &I) = 0; public: - explicit vpTemplateTrackerSSD(vpTemplateTrackerWarp *warp); + VP_EXPLICIT vpTemplateTrackerSSD(vpTemplateTrackerWarp *warp); double getSSD(const vpImage &I, const vpColVector &tp); void setGain(double g) { gain = g; } diff --git a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDESM.h b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDESM.h index 77d5372ea1..2ef6b287b5 100644 --- a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDESM.h +++ b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDESM.h @@ -69,7 +69,7 @@ class VISP_EXPORT vpTemplateTrackerSSDESM : public vpTemplateTrackerSSD void trackNoPyr(const vpImage &I); public: - explicit vpTemplateTrackerSSDESM(vpTemplateTrackerWarp *warp); + VP_EXPLICIT vpTemplateTrackerSSDESM(vpTemplateTrackerWarp *warp); }; END_VISP_NAMESPACE #endif diff --git a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDForwardAdditional.h b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDForwardAdditional.h index 980d9338cd..3843579cfa 100644 --- a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDForwardAdditional.h +++ b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDForwardAdditional.h @@ -71,7 +71,7 @@ class VISP_EXPORT vpTemplateTrackerSSDForwardAdditional : public vpTemplateTrack void trackNoPyr(const vpImage &I); public: - explicit vpTemplateTrackerSSDForwardAdditional(vpTemplateTrackerWarp *warp); + VP_EXPLICIT vpTemplateTrackerSSDForwardAdditional(vpTemplateTrackerWarp *warp); void setMinimizationMethod(vpMinimizationTypeSSDForwardAdditional method) { minimizationMethod = method; } }; diff --git a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDForwardCompositional.h b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDForwardCompositional.h index 8673fb0ea4..cd2af1c414 100644 --- a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDForwardCompositional.h +++ b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDForwardCompositional.h @@ -64,7 +64,7 @@ class VISP_EXPORT vpTemplateTrackerSSDForwardCompositional : public vpTemplateTr void trackNoPyr(const vpImage &I); public: - explicit vpTemplateTrackerSSDForwardCompositional(vpTemplateTrackerWarp *warp); + VP_EXPLICIT vpTemplateTrackerSSDForwardCompositional(vpTemplateTrackerWarp *warp); }; END_VISP_NAMESPACE #endif diff --git a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDInverseCompositional.h b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDInverseCompositional.h index 667ec1ef65..2d9a0a2580 100644 --- a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDInverseCompositional.h +++ b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerSSDInverseCompositional.h @@ -68,7 +68,7 @@ class VISP_EXPORT vpTemplateTrackerSSDInverseCompositional : public vpTemplateTr void trackNoPyr(const vpImage &I); public: - explicit vpTemplateTrackerSSDInverseCompositional(vpTemplateTrackerWarp *warp); + VP_EXPLICIT vpTemplateTrackerSSDInverseCompositional(vpTemplateTrackerWarp *warp); /*! Use only the strong gradient pixels to compute the Jabobian. By default * this feature is disabled. */ diff --git a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCC.h b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCC.h index 9359c78285..7aea85f334 100644 --- a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCC.h +++ b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCC.h @@ -80,7 +80,7 @@ class VISP_EXPORT vpTemplateTrackerZNCC : public vpTemplateTracker virtual void trackNoPyr(const vpImage &I) = 0; public: - explicit vpTemplateTrackerZNCC(vpTemplateTrackerWarp *warp); + VP_EXPLICIT vpTemplateTrackerZNCC(vpTemplateTrackerWarp *warp); void setGain(double _gain) { gain = _gain; } }; diff --git a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCCForwardAdditional.h b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCCForwardAdditional.h index f32fd25593..dc7418600f 100644 --- a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCCForwardAdditional.h +++ b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCCForwardAdditional.h @@ -62,7 +62,7 @@ class VISP_EXPORT vpTemplateTrackerZNCCForwardAdditional : public vpTemplateTrac void trackNoPyr(const vpImage &I); public: - explicit vpTemplateTrackerZNCCForwardAdditional(vpTemplateTrackerWarp *warp); + VP_EXPLICIT vpTemplateTrackerZNCCForwardAdditional(vpTemplateTrackerWarp *warp); }; END_VISP_NAMESPACE #endif diff --git a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCCInverseCompositional.h b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCCInverseCompositional.h index e8a350644c..9456b08af0 100644 --- a/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCCInverseCompositional.h +++ b/modules/tracker/tt/include/visp3/tt/vpTemplateTrackerZNCCInverseCompositional.h @@ -56,7 +56,7 @@ BEGIN_VISP_NAMESPACE The algorithm implemented in this class is described in \cite Irani98a and \cite Marchand16a. */ -class VISP_EXPORT vpTemplateTrackerZNCCInverseCompositional : public vpTemplateTrackerZNCC + class VISP_EXPORT vpTemplateTrackerZNCCInverseCompositional : public vpTemplateTrackerZNCC { protected: bool compoInitialised; @@ -68,7 +68,7 @@ class VISP_EXPORT vpTemplateTrackerZNCCInverseCompositional : public vpTemplateT void trackNoPyr(const vpImage &I); public: - explicit vpTemplateTrackerZNCCInverseCompositional(vpTemplateTrackerWarp *warp); + VP_EXPLICIT vpTemplateTrackerZNCCInverseCompositional(vpTemplateTrackerWarp *warp); }; END_VISP_NAMESPACE #endif diff --git a/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMI.h b/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMI.h index b423d14af2..54b4783214 100644 --- a/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMI.h +++ b/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMI.h @@ -116,7 +116,7 @@ class VISP_EXPORT vpTemplateTrackerMI : public vpTemplateTracker void computeMI(double &MI); void computeProba(int &nbpoint); - double getCost(const vpImage &I, const vpColVector &tp) vp_override; + double getCost(const vpImage &I, const vpColVector &tp) VP_OVERRIDE; double getCost(const vpImage &I) { return getCost(I, p); } double getNormalizedCost(const vpImage &I, const vpColVector &tp); double getNormalizedCost(const vpImage &I) { return getNormalizedCost(I, p); } @@ -151,8 +151,8 @@ class VISP_EXPORT vpTemplateTrackerMI : public vpTemplateTracker NMI_preEstimation(0), NMI_postEstimation(0), covarianceMatrix(), computeCovariance(false), m_du(), m_dv(), m_A(), m_dB(), m_d2u(), m_d2v(), m_dA() { } - explicit vpTemplateTrackerMI(vpTemplateTrackerWarp *_warp); - virtual ~vpTemplateTrackerMI() vp_override; + VP_EXPLICIT vpTemplateTrackerMI(vpTemplateTrackerWarp *_warp); + virtual ~vpTemplateTrackerMI() VP_OVERRIDE; vpMatrix getCovarianceMatrix() const { return covarianceMatrix; } double getMI() const { return MI_postEstimation; } double getMI(const vpImage &I, int &nc, const int &bspline, vpColVector &tp); diff --git a/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIESM.h b/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIESM.h index 484b50ca7b..6d30fe65f6 100644 --- a/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIESM.h +++ b/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIESM.h @@ -102,7 +102,7 @@ class VISP_EXPORT vpTemplateTrackerMIESM : public vpTemplateTrackerMI : vpTemplateTrackerMI(), minimizationMethod(USE_NEWTON), CompoInitialised(false), HDirect(), HInverse(), HdesireDirect(), HdesireInverse(), GDirect(), GInverse() { } - explicit vpTemplateTrackerMIESM(vpTemplateTrackerWarp *_warp); + VP_EXPLICIT vpTemplateTrackerMIESM(vpTemplateTrackerWarp *_warp); void setMinimizationMethod(vpMinimizationTypeMIESM method) { minimizationMethod = method; } }; diff --git a/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIForwardAdditional.h b/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIForwardAdditional.h index 80be91d081..9c4ac261f1 100644 --- a/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIForwardAdditional.h +++ b/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIForwardAdditional.h @@ -77,7 +77,7 @@ class VISP_EXPORT vpTemplateTrackerMIForwardAdditional : public vpTemplateTracke vpTemplateTrackerMIForwardAdditional() : vpTemplateTrackerMI(), minimizationMethod(USE_NEWTON), p_prec(), G_prec(), KQuasiNewton() { } - explicit vpTemplateTrackerMIForwardAdditional(vpTemplateTrackerWarp *_warp); + VP_EXPLICIT vpTemplateTrackerMIForwardAdditional(vpTemplateTrackerWarp *_warp); void setMinimizationMethod(vpMinimizationTypeMIForwardAdditional method) { minimizationMethod = method; } }; END_VISP_NAMESPACE diff --git a/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIForwardCompositional.h b/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIForwardCompositional.h index 831304c71e..3eb3c2a043 100644 --- a/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIForwardCompositional.h +++ b/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIForwardCompositional.h @@ -66,7 +66,7 @@ class VISP_EXPORT vpTemplateTrackerMIForwardCompositional : public vpTemplateTra void trackNoPyr(const vpImage &I); public: - explicit vpTemplateTrackerMIForwardCompositional(vpTemplateTrackerWarp *_warp); + VP_EXPLICIT vpTemplateTrackerMIForwardCompositional(vpTemplateTrackerWarp *_warp); }; END_VISP_NAMESPACE #endif diff --git a/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIInverseCompositional.h b/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIInverseCompositional.h index cf30bd2efe..27ab9c5648 100644 --- a/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIInverseCompositional.h +++ b/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMIInverseCompositional.h @@ -87,7 +87,7 @@ class VISP_EXPORT vpTemplateTrackerMIInverseCompositional : public vpTemplateTra : vpTemplateTrackerMI(), minimizationMethod(USE_LMA), CompoInitialised(false), useTemplateSelect(false), p_prec(), G_prec(), KQuasiNewton() { } - explicit vpTemplateTrackerMIInverseCompositional(vpTemplateTrackerWarp *_warp); + VP_EXPLICIT vpTemplateTrackerMIInverseCompositional(vpTemplateTrackerWarp *_warp); /*! Use only the strong gradient pixels to compute the Jabobian. By default * this feature is disabled. */ diff --git a/modules/vision/include/visp3/vision/vpCalibrationException.h b/modules/vision/include/visp3/vision/vpCalibrationException.h index 7d574c5c76..52e92a9681 100644 --- a/modules/vision/include/visp3/vision/vpCalibrationException.h +++ b/modules/vision/include/visp3/vision/vpCalibrationException.h @@ -89,7 +89,7 @@ class VISP_EXPORT vpCalibrationException : public vpException /*! * Constructor. */ - explicit vpCalibrationException(int id) : vpException(id) { } + VP_EXPLICIT vpCalibrationException(int id) : vpException(id) { } }; END_VISP_NAMESPACE #endif diff --git a/modules/vision/include/visp3/vision/vpPose.h b/modules/vision/include/visp3/vision/vpPose.h index 439690f975..8af6989702 100644 --- a/modules/vision/include/visp3/vision/vpPose.h +++ b/modules/vision/include/visp3/vision/vpPose.h @@ -127,7 +127,7 @@ class VISP_EXPORT vpPose /*! * Constructor from a vector of points. */ - explicit vpPose(const std::vector &lP); + VP_EXPLICIT vpPose(const std::vector &lP); /*! * Destructor that deletes the array of point (freed the memory). diff --git a/modules/vision/include/visp3/vision/vpPoseException.h b/modules/vision/include/visp3/vision/vpPoseException.h index a3df88da52..d6b08ca7a8 100644 --- a/modules/vision/include/visp3/vision/vpPoseException.h +++ b/modules/vision/include/visp3/vision/vpPoseException.h @@ -88,7 +88,7 @@ class VISP_EXPORT vpPoseException : public vpException /*! * Constructor. */ - explicit vpPoseException(int id) : vpException(id) { } + VP_EXPLICIT vpPoseException(int id) : vpException(id) { } }; END_VISP_NAMESPACE diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureDepth.h b/modules/visual_features/include/visp3/visual_features/vpFeatureDepth.h index 30728379cc..41de99c559 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureDepth.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureDepth.h @@ -180,11 +180,11 @@ class VISP_EXPORT vpFeatureDepth : public vpBasicFeature vpFeatureDepth &build(const double &x, const double &y, const double &Z, const double &LogZoverZstar); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; - vpFeatureDepth *duplicate() const vp_override; - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; + vpFeatureDepth *duplicate() const VP_OVERRIDE; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; double get_x() const; @@ -194,9 +194,9 @@ class VISP_EXPORT vpFeatureDepth : public vpBasicFeature double get_LogZoverZstar() const; - void init() vp_override; - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; - void print(unsigned int select = FEATURE_ALL) const vp_override; + void init() VP_OVERRIDE; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; void set_x(double x); diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureEllipse.h b/modules/visual_features/include/visp3/visual_features/vpFeatureEllipse.h index f40d2bb05b..680255b6c0 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureEllipse.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureEllipse.h @@ -81,15 +81,15 @@ class VISP_EXPORT vpFeatureEllipse : public vpBasicFeature vpFeatureEllipse &build(const double &x, const double &y, const double &n20, const double &n11, const double &n02, const double &A, const double &B, const double &C); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; //! Feature duplication - vpFeatureEllipse *duplicate() const vp_override; + vpFeatureEllipse *duplicate() const VP_OVERRIDE; //! compute the error between two visual features from a subset //! a the possible features - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; /*! * Returns the visual feature corresponding to the ellipse centroid coordinate along camera x-axis. @@ -116,12 +116,12 @@ class VISP_EXPORT vpFeatureEllipse : public vpBasicFeature double get_n02() const { return s[4]; } //! Default initialization. - void init() vp_override; + void init() VP_OVERRIDE; //! compute the interaction matrix from a subset a the possible features - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; //! Print the name of the feature - void print(unsigned int select = FEATURE_ALL) const vp_override; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; void set_x(double x); void set_y(double y); @@ -145,31 +145,31 @@ class VISP_EXPORT vpFeatureEllipse : public vpBasicFeature @name Deprecated functions */ //@{ - vp_deprecated void setMu(double mu20, double mu11, double mu02); - vp_deprecated static unsigned int selectMu20(); - vp_deprecated static unsigned int selectMu11(); - vp_deprecated static unsigned int selectMu02(); + VP_DEPRECATED void setMu(double mu20, double mu11, double mu02); + VP_DEPRECATED static unsigned int selectMu20(); + VP_DEPRECATED static unsigned int selectMu11(); + VP_DEPRECATED static unsigned int selectMu02(); /*! * \deprecated You should rather use get_n20(). * This function is incorrectly named and is confusing since it * returns the visual feature corresponding to the second order centered moments * of the ellipse normalized by its area \f$n_20 = mu_20/a\f$. */ - vp_deprecated double getMu20() const { return s[2]; } + VP_DEPRECATED double getMu20() const { return s[2]; } /*! * \deprecated You should rather use get_n11(). * This function is incorrectly named and is confusing since it * returns the visual feature corresponding to the second order centered moments * of the ellipse normalized by its area \f$n_11 = mu_11/a\f$. */ - vp_deprecated double getMu11() const { return s[3]; } + VP_DEPRECATED double getMu11() const { return s[3]; } /*! * \deprecated You should rather use get_n02(). * This function is incorrectly named and is confusing since it * returns the visual feature corresponding to the second order centered moments * of the ellipse normalized by its area \f$n_02 = mu_02/a\f$. */ - vp_deprecated double getMu02() const { return s[4]; } + VP_DEPRECATED double getMu02() const { return s[4]; } //@} #endif diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureException.h b/modules/visual_features/include/visp3/visual_features/vpFeatureException.h index fdc1ca71e6..143111d68c 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureException.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureException.h @@ -91,7 +91,7 @@ class VISP_EXPORT vpFeatureException : public vpException /*! * Constructor. */ - explicit vpFeatureException(int id) : vpException(id) { } + VP_EXPLICIT vpFeatureException(int id) : vpException(id) { } }; END_VISP_NAMESPACE #endif diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureLine.h b/modules/visual_features/include/visp3/visual_features/vpFeatureLine.h index ae98b4d48c..477ccad87c 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureLine.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureLine.h @@ -210,11 +210,11 @@ class VISP_EXPORT vpFeatureLine : public vpBasicFeature vpFeatureLine &build(const double &rho, const double &theta, const double &A, const double &B, const double &C, const double &D); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; - vpFeatureLine *duplicate() const vp_override; - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; + vpFeatureLine *duplicate() const VP_OVERRIDE; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; /*! * Return the \f$ \rho \f$ subset value of the visual feature \f$ s \f$. @@ -226,9 +226,9 @@ class VISP_EXPORT vpFeatureLine : public vpBasicFeature */ double getTheta() const { return s[1]; } - void init() vp_override; - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; - void print(unsigned int select = FEATURE_ALL) const vp_override; + void init() VP_OVERRIDE; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; void setRhoTheta(double rho, double theta); void setABCD(double A, double B, double C, double D); diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureLuminance.h b/modules/visual_features/include/visp3/visual_features/vpFeatureLuminance.h index eaeb1e88c1..537a6f8321 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureLuminance.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureLuminance.h @@ -95,7 +95,7 @@ class VISP_EXPORT vpFeatureLuminance : public vpBasicFeature vpFeatureLuminance(const vpFeatureLuminance &f); //! Destructor. - virtual ~vpFeatureLuminance() vp_override; + virtual ~vpFeatureLuminance() VP_OVERRIDE; #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS void buildFrom(vpImage &I); @@ -103,13 +103,13 @@ class VISP_EXPORT vpFeatureLuminance : public vpBasicFeature vpFeatureLuminance &build(vpImage &I); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; - vpFeatureLuminance *duplicate() const vp_override; + vpFeatureLuminance *duplicate() const VP_OVERRIDE; - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; void error(const vpBasicFeature &s_star, vpColVector &e); double get_Z() const; @@ -118,10 +118,10 @@ class VISP_EXPORT vpFeatureLuminance : public vpBasicFeature void init(unsigned int _nbr, unsigned int _nbc, double _Z); - void init() vp_override; - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; + void init() VP_OVERRIDE; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; void interaction(vpMatrix &L); - void print(unsigned int select = FEATURE_ALL) const vp_override; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; vpFeatureLuminance &operator=(const vpFeatureLuminance &f); diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureLuminanceMapping.h b/modules/visual_features/include/visp3/visual_features/vpFeatureLuminanceMapping.h index 1b3f88b7ea..ea3b0b836a 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureLuminanceMapping.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureLuminanceMapping.h @@ -204,9 +204,9 @@ class VISP_EXPORT vpLuminancePCA : public vpLuminanceMapping */ vpColVector getExplainedVariance() const { return m_explainedVariance; } - void map(const vpImage &I, vpColVector &s) vp_override; - void inverse(const vpColVector &s, vpImage &I) vp_override; - void interaction(const vpImage &I, const vpMatrix &LI, const vpColVector &s, vpMatrix &L) vp_override; + void map(const vpImage &I, vpColVector &s) VP_OVERRIDE; + void inverse(const vpColVector &s, vpImage &I) VP_OVERRIDE; + void interaction(const vpImage &I, const vpMatrix &LI, const vpColVector &s, vpMatrix &L) VP_OVERRIDE; /** * \brief Save the PCA basis to multiple text files, for later use via the \ref load function. @@ -354,9 +354,9 @@ class VISP_EXPORT vpLuminanceDCT : public vpLuminanceMapping vpLuminanceDCT &operator=(const vpLuminanceDCT &other) = default; - void map(const vpImage &I, vpColVector &s) vp_override; - void inverse(const vpColVector &s, vpImage &I) vp_override; - void interaction(const vpImage &I, const vpMatrix &LI, const vpColVector &s, vpMatrix &L) vp_override; + void map(const vpImage &I, vpColVector &s) VP_OVERRIDE; + void inverse(const vpColVector &s, vpImage &I) VP_OVERRIDE; + void interaction(const vpImage &I, const vpMatrix &LI, const vpColVector &s, vpMatrix &L) VP_OVERRIDE; private: void computeDCTMatrix(vpMatrix &D, unsigned int n) const; @@ -389,13 +389,13 @@ class VISP_EXPORT vpFeatureLuminanceMapping : public vpBasicFeature public: vpFeatureLuminanceMapping(const vpCameraParameters &cam, unsigned int h, unsigned int w, double Z, const std::shared_ptr mapping); vpFeatureLuminanceMapping(const vpFeatureLuminance &luminance, std::shared_ptr mapping); - void init() vp_override; + void init() VP_OVERRIDE; void init(const vpCameraParameters &cam, unsigned int h, unsigned int w, double Z, std::shared_ptr mapping); void init(const vpFeatureLuminance &luminance, std::shared_ptr mapping); vpFeatureLuminanceMapping(const vpFeatureLuminanceMapping &f); vpFeatureLuminanceMapping &operator=(const vpFeatureLuminanceMapping &f); - vpFeatureLuminanceMapping *duplicate() const vp_override; + vpFeatureLuminanceMapping *duplicate() const VP_OVERRIDE; virtual ~vpFeatureLuminanceMapping() = default; @@ -408,13 +408,13 @@ class VISP_EXPORT vpFeatureLuminanceMapping : public vpBasicFeature unsigned int = 1) const vp_override { } - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; void error(const vpBasicFeature &s_star, vpColVector &e); - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; void interaction(vpMatrix &L); - void print(unsigned int select = FEATURE_ALL) const vp_override; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; vpFeatureLuminance &getLuminanceFeature() { return m_featI; } std::shared_ptr &getMapping() { return m_mapping; } diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h index cab170def7..0fe7e79314 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h @@ -209,15 +209,15 @@ class VISP_EXPORT vpFeatureMoment : public vpBasicFeature //@{ virtual void compute_interaction(void); - vpBasicFeature *duplicate() const vp_override; + vpBasicFeature *duplicate() const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; int getDimension(unsigned int select = FEATURE_ALL) const; - void init(void) vp_override; - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; + void init(void) VP_OVERRIDE; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; void linkTo(vpFeatureMomentDatabase &featureMoments); @@ -232,7 +232,7 @@ class VISP_EXPORT vpFeatureMoment : public vpBasicFeature */ virtual const std::string name() const = 0; - void print(unsigned int select = FEATURE_ALL) const vp_override; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; virtual void printDependencies(std::ostream &os) const; void update(double A, double B, double C); diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h index f787a2b5c0..0445755b7d 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h @@ -116,7 +116,7 @@ class VISP_EXPORT vpFeatureMomentAlpha : public vpFeatureMoment : vpFeatureMoment(data_base, A_, B_, C_, featureMoments, 1) { } - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; /*! * Associated moment name. */ @@ -133,7 +133,7 @@ class VISP_EXPORT vpFeatureMomentAlpha : public vpFeatureMoment return "vpFeatureMomentAlpha"; } - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; }; END_VISP_NAMESPACE #endif diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h index d57bcb2e70..2b025fbd8c 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h @@ -71,7 +71,7 @@ class VISP_EXPORT vpFeatureMomentArea : public vpFeatureMoment : vpFeatureMoment(data_base, A_, B_, C_, featureMoments, 1) { } - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; /*! * Associated moment name. diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h index 6a6c2787df..44fe5fa720 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h @@ -97,7 +97,7 @@ class VISP_EXPORT vpFeatureMomentAreaNormalized : public vpFeatureMoment : vpFeatureMoment(database, A_, B_, C_, featureMoments, 1) { } - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; /*! * Associated moment name. @@ -199,7 +199,7 @@ class VISP_EXPORT vpFeatureMomentAreaNormalized : public vpFeatureMoment : vpFeatureMoment(data_base, A_, B_, C_, featureMoments, 1) { } - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; /*! * Associated moment name. diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h index d05fe6b506..e7c10d120a 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h @@ -83,7 +83,7 @@ class VISP_EXPORT vpFeatureMomentBasic : public vpFeatureMoment vpFeatureMomentBasic(vpMomentDatabase &moments, double A, double B, double C, vpFeatureMomentDatabase *featureMoments = nullptr); - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; #ifndef DOXYGEN_SHOULD_SKIP_THIS /* Add function due to pure virtual definition in vpBasicFeature.h */ diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h index 2d649839a9..2e1d2c8ba2 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h @@ -107,7 +107,7 @@ class VISP_EXPORT vpFeatureMomentCInvariant : public vpFeatureMoment : vpFeatureMoment(moments, A, B, C, featureMoments, 16) { } - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; /*! * Associated moment name. @@ -253,7 +253,7 @@ class VISP_EXPORT vpFeatureMomentCInvariant : public vpFeatureMoment : vpFeatureMoment(data_base, A_, B_, C_, featureMoments, 16), LI(16) { } - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; /*! * Associated moment name. */ diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h index 302c7d8d22..096a7b89d2 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h @@ -89,7 +89,7 @@ class VISP_EXPORT vpFeatureMomentCentered : public vpFeatureMoment vpFeatureMomentCentered(vpMomentDatabase &moments, double A, double B, double C, vpFeatureMomentDatabase *featureMoments = nullptr); - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; #ifndef DOXYGEN_SHOULD_SKIP_THIS /* Add function due to pure virtual definition in vpBasicFeature.h */ diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h index c994621f46..0966928a01 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h @@ -163,7 +163,7 @@ class VISP_EXPORT vpFeatureMomentGravityCenter : public vpFeatureMoment : vpFeatureMoment(database, A_, B_, C_, featureMoments, 2) { } - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; /*! * Associated moment name. @@ -235,7 +235,7 @@ class VISP_EXPORT vpFeatureMomentGravityCenter : public vpFeatureMoment : vpFeatureMoment(data_base, A_, B_, C_, featureMoments, 2) { } - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; /*! * Associated moment name. diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h index 5792e708d5..9c6c2e58ae 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h @@ -104,7 +104,7 @@ class VISP_EXPORT vpFeatureMomentGravityCenterNormalized : public vpFeatureMomen : vpFeatureMoment(database, A_, B_, C_, featureMoments, 2) { } - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; /*! * Associated moment name. @@ -258,7 +258,7 @@ class VISP_EXPORT vpFeatureMomentGravityCenterNormalized : public vpFeatureMomen vpFeatureMomentDatabase *featureMoments = nullptr) : vpFeatureMoment(data_base, A_, B_, C_, featureMoments, 2) { } - void compute_interaction() vp_override; + void compute_interaction() VP_OVERRIDE; /*! * Associated moment name. diff --git a/modules/visual_features/include/visp3/visual_features/vpFeaturePoint.h b/modules/visual_features/include/visp3/visual_features/vpFeaturePoint.h index 528b3f5dfe..5f27a79d42 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeaturePoint.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeaturePoint.h @@ -189,13 +189,13 @@ class VISP_EXPORT vpFeaturePoint : public vpBasicFeature vpFeaturePoint &build(const double &x, const double &y, const double &Z); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; - vpFeaturePoint *duplicate() const vp_override; + vpFeaturePoint *duplicate() const VP_OVERRIDE; - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; double get_x() const; @@ -203,9 +203,9 @@ class VISP_EXPORT vpFeaturePoint : public vpBasicFeature double get_Z() const; - void init() vp_override; - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; - void print(unsigned int select = FEATURE_ALL) const vp_override; + void init() VP_OVERRIDE; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; void set_x(double x); diff --git a/modules/visual_features/include/visp3/visual_features/vpFeaturePoint3D.h b/modules/visual_features/include/visp3/visual_features/vpFeaturePoint3D.h index 6b685c9a24..b77179c607 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeaturePoint3D.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeaturePoint3D.h @@ -222,16 +222,16 @@ class VISP_EXPORT vpFeaturePoint3D : public vpBasicFeature vpFeaturePoint3D &build(const double &X, const double &Y, const double &Z); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; // feature duplication - vpFeaturePoint3D *duplicate() const vp_override; + vpFeaturePoint3D *duplicate() const VP_OVERRIDE; // compute the error between two visual features from a subset // a the possible features - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; // get the point X-coordinates double get_X() const; @@ -241,12 +241,12 @@ class VISP_EXPORT vpFeaturePoint3D : public vpBasicFeature double get_Z() const; // basic construction - void init() vp_override; + void init() VP_OVERRIDE; // compute the interaction matrix from a subset a the possible features - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; // print the name of the feature - void print(unsigned int select = FEATURE_ALL) const vp_override; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; // set the point X-coordinates void set_X(double X); diff --git a/modules/visual_features/include/visp3/visual_features/vpFeaturePointPolar.h b/modules/visual_features/include/visp3/visual_features/vpFeaturePointPolar.h index 9f34bdfe55..7ff03741ed 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeaturePointPolar.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeaturePointPolar.h @@ -267,19 +267,19 @@ class VISP_EXPORT vpFeaturePointPolar : public vpBasicFeature vpFeaturePointPolar &build(const double &rho, const double &theta, const double &Z); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; // feature duplication - vpFeaturePointPolar *duplicate() const vp_override; + vpFeaturePointPolar *duplicate() const VP_OVERRIDE; // compute the error between two visual features from a subset // a the possible features - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; // basic construction - void init() vp_override; + void init() VP_OVERRIDE; // get the point rho-coordinates double get_rho() const; @@ -289,10 +289,10 @@ class VISP_EXPORT vpFeaturePointPolar : public vpBasicFeature double get_Z() const; // compute the interaction matrix from a subset a the possible features - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; // print the name of the feature - void print(unsigned int select = FEATURE_ALL) const vp_override; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; // set the point rho-coordinates void set_rho(double rho); diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureSegment.h b/modules/visual_features/include/visp3/visual_features/vpFeatureSegment.h index 79584140bb..2713ae3a58 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureSegment.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureSegment.h @@ -68,7 +68,7 @@ class VISP_EXPORT vpFeatureSegment : public vpBasicFeature { public: // empty constructor - explicit vpFeatureSegment(bool normalized = false); + VP_EXPLICIT vpFeatureSegment(bool normalized = false); #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS // change values of the segment @@ -78,14 +78,14 @@ class VISP_EXPORT vpFeatureSegment : public vpBasicFeature vpFeatureSegment &build(const double &x1, const double &y1, const double &Z1, const double &x2, const double &y2, const double &Z2); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; //! Feature duplication. - vpFeatureSegment *duplicate() const vp_override; + vpFeatureSegment *duplicate() const VP_OVERRIDE; // compute the error between two visual features from a subset // a the possible features - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; /*! * Get the x coordinate of the segment center in the image plane. @@ -137,12 +137,12 @@ class VISP_EXPORT vpFeatureSegment : public vpBasicFeature inline double getZ2() const { return Z2_; } // Basic construction. - void init() vp_override; + void init() VP_OVERRIDE; // compute the interaction matrix from a subset a the possible features - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; - void print(unsigned int select = FEATURE_ALL) const vp_override; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; /*! * Indicates if the normalized features are considered. diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureThetaU.h b/modules/visual_features/include/visp3/visual_features/vpFeatureThetaU.h index a7ff99d246..52a00296d6 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureThetaU.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureThetaU.h @@ -248,7 +248,7 @@ class VISP_EXPORT vpFeatureThetaU : public vpBasicFeature public: // Basic constructor. vpFeatureThetaU(); - explicit vpFeatureThetaU(vpFeatureThetaURotationRepresentationType r); + VP_EXPLICIT vpFeatureThetaU(vpFeatureThetaURotationRepresentationType r); vpFeatureThetaU(vpThetaUVector &tu, vpFeatureThetaURotationRepresentationType r); vpFeatureThetaU(vpRotationMatrix &R, vpFeatureThetaURotationRepresentationType r); vpFeatureThetaU(vpHomogeneousMatrix &M, vpFeatureThetaURotationRepresentationType r); @@ -267,16 +267,16 @@ class VISP_EXPORT vpFeatureThetaU : public vpBasicFeature vpFeatureThetaU &build(const vpHomogeneousMatrix &M); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; //! Feature duplication. - vpFeatureThetaU *duplicate() const vp_override; + vpFeatureThetaU *duplicate() const VP_OVERRIDE; // compute the error between two visual features from a subset // a the possible features - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; vpFeatureThetaURotationRepresentationType getFeatureThetaURotationType() const; @@ -285,10 +285,10 @@ class VISP_EXPORT vpFeatureThetaU : public vpBasicFeature double get_TUz() const; // Basic construction. - void init() vp_override; + void init() VP_OVERRIDE; // compute the interaction matrix from a subset a the possible features - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; - void print(unsigned int select = FEATURE_ALL) const vp_override; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; void set_TUx(double tu_x); void set_TUy(double tu_y); diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureTranslation.h b/modules/visual_features/include/visp3/visual_features/vpFeatureTranslation.h index 839ae0e714..d95e159251 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureTranslation.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureTranslation.h @@ -292,7 +292,7 @@ class VISP_EXPORT vpFeatureTranslation : public vpBasicFeature // basic constructor vpFeatureTranslation(); // basic constructor specifying the type of translation feature - explicit vpFeatureTranslation(vpFeatureTranslationRepresentationType r); + VP_EXPLICIT vpFeatureTranslation(vpFeatureTranslationRepresentationType r); // constructor : build from an homogeneous matrix // cdMc is the displacement that the camera has to realize vpFeatureTranslation(vpHomogeneousMatrix &f2Mf1, vpFeatureTranslationRepresentationType r); @@ -307,16 +307,16 @@ class VISP_EXPORT vpFeatureTranslation : public vpBasicFeature vpFeatureTranslation &build(const vpHomogeneousMatrix &f2Mf1); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; //! Feature duplication - vpFeatureTranslation *duplicate() const vp_override; + vpFeatureTranslation *duplicate() const VP_OVERRIDE; // compute the error between two visual features from a subset // a the possible features - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; vpFeatureTranslationRepresentationType getFeatureTranslationType() const; @@ -325,12 +325,12 @@ class VISP_EXPORT vpFeatureTranslation : public vpBasicFeature double get_Tz() const; // basic construction - void init() vp_override; + void init() VP_OVERRIDE; // compute the interaction matrix from a subset a the possible features - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; // print the name of the feature - void print(unsigned int select = FEATURE_ALL) const vp_override; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; void set_Tx(double t_x); void set_Ty(double t_y); diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureVanishingPoint.h b/modules/visual_features/include/visp3/visual_features/vpFeatureVanishingPoint.h index f3ab9c3dc7..62e4cb1b3c 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureVanishingPoint.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureVanishingPoint.h @@ -87,11 +87,11 @@ class VISP_EXPORT vpFeatureVanishingPoint : public vpBasicFeature vpFeatureVanishingPoint &build(const double &x, const double &y); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; - vpFeatureVanishingPoint *duplicate() const vp_override; - vpColVector error(const vpBasicFeature &s_star, unsigned int select = (vpFeatureVanishingPoint::selectX() | vpFeatureVanishingPoint::selectY())) vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; + vpFeatureVanishingPoint *duplicate() const VP_OVERRIDE; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = (vpFeatureVanishingPoint::selectX() | vpFeatureVanishingPoint::selectY())) VP_OVERRIDE; double get_x() const; double get_y() const; @@ -99,9 +99,9 @@ class VISP_EXPORT vpFeatureVanishingPoint : public vpBasicFeature double getOneOverRho() const; double getAlpha() const; - void init() vp_override; - vpMatrix interaction(unsigned int select = (vpFeatureVanishingPoint::selectX() | vpFeatureVanishingPoint::selectY())) vp_override; - void print(unsigned int select = (vpFeatureVanishingPoint::selectX() | vpFeatureVanishingPoint::selectY())) const vp_override; + void init() VP_OVERRIDE; + vpMatrix interaction(unsigned int select = (vpFeatureVanishingPoint::selectX() | vpFeatureVanishingPoint::selectY())) VP_OVERRIDE; + void print(unsigned int select = (vpFeatureVanishingPoint::selectX() | vpFeatureVanishingPoint::selectY())) const VP_OVERRIDE; void set_x(double x); void set_y(double y); diff --git a/modules/visual_features/include/visp3/visual_features/vpGenericFeature.h b/modules/visual_features/include/visp3/visual_features/vpGenericFeature.h index 69c825055a..adde52e73d 100644 --- a/modules/visual_features/include/visp3/visual_features/vpGenericFeature.h +++ b/modules/visual_features/include/visp3/visual_features/vpGenericFeature.h @@ -180,14 +180,14 @@ class VISP_EXPORT vpGenericFeature : public vpBasicFeature vpGenericFeature(); public: - explicit vpGenericFeature(unsigned int dim); + VP_EXPLICIT vpGenericFeature(unsigned int dim); void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override; - vpGenericFeature *duplicate() const vp_override; - vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override; + unsigned int thickness = 1) const VP_OVERRIDE; + vpGenericFeature *duplicate() const VP_OVERRIDE; + vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; vpColVector error(unsigned int select = FEATURE_ALL); @@ -197,9 +197,9 @@ class VISP_EXPORT vpGenericFeature : public vpBasicFeature void get_s(double &s0, double &s1) const; void get_s(double &s0, double &s1, double &s2) const; - void init() vp_override; - vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override; - void print(unsigned int select = FEATURE_ALL) const vp_override; + void init() VP_OVERRIDE; + vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE; + void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE; void setInteractionMatrix(const vpMatrix &L); void setError(const vpColVector &error_vector); void set_s(const vpColVector &s); diff --git a/modules/visual_features/src/visual-feature/vpFeatureEllipse.cpp b/modules/visual_features/src/visual-feature/vpFeatureEllipse.cpp index 9d7a19f5b4..8930eacecd 100644 --- a/modules/visual_features/src/visual-feature/vpFeatureEllipse.cpp +++ b/modules/visual_features/src/visual-feature/vpFeatureEllipse.cpp @@ -467,20 +467,20 @@ unsigned int vpFeatureEllipse::select_n02() { return FEATURE_LINE[4]; } * intends to select as visual feature second order centered moments of the ellipse normalized * by its area that corresponds to \f$n_20 = mu_20/a\f$. */ -vp_deprecated unsigned int vpFeatureEllipse::selectMu20() { return FEATURE_LINE[2]; } +VP_DEPRECATED unsigned int vpFeatureEllipse::selectMu20() { return FEATURE_LINE[2]; } /*! * \deprecated You should rather use select_n20(). * This function is incorrectly named and is confusing since it * intends to select as visual feature second order centered moments of the ellipse normalized * by its area that corresponds to \f$n_11 = mu_11/a\f$. */ -vp_deprecated unsigned int vpFeatureEllipse::selectMu11() { return FEATURE_LINE[3]; } +VP_DEPRECATED unsigned int vpFeatureEllipse::selectMu11() { return FEATURE_LINE[3]; } /*! * \deprecated You should rather use select_n20(). * This function is incorrectly named and is confusing since it * intends to select as visual feature second order centered moments of the ellipse normalized * by its area that corresponds to \f$n_02 = mu_02/a\f$. */ -vp_deprecated unsigned int vpFeatureEllipse::selectMu02() { return FEATURE_LINE[4]; } +VP_DEPRECATED unsigned int vpFeatureEllipse::selectMu02() { return FEATURE_LINE[4]; } #endif END_VISP_NAMESPACE diff --git a/modules/vs/include/visp3/vs/vpAdaptiveGain.h b/modules/vs/include/visp3/vs/vpAdaptiveGain.h index 8ed9210c2b..898e2781a3 100644 --- a/modules/vs/include/visp3/vs/vpAdaptiveGain.h +++ b/modules/vs/include/visp3/vs/vpAdaptiveGain.h @@ -147,7 +147,7 @@ class VISP_EXPORT vpAdaptiveGain * * \param c : Value of the constant gain. A typical value is 0.5. */ - explicit vpAdaptiveGain(double c); + VP_EXPLICIT vpAdaptiveGain(double c); /*! * Constructor that initializes the gain as adaptive. diff --git a/modules/vs/include/visp3/vs/vpServo.h b/modules/vs/include/visp3/vs/vpServo.h index 9185f042f1..b19a8d3552 100644 --- a/modules/vs/include/visp3/vs/vpServo.h +++ b/modules/vs/include/visp3/vs/vpServo.h @@ -301,7 +301,7 @@ class VISP_EXPORT vpServo * - In the control law the pseudo inverse will be used. The method * setInteractionMatrixType() allows to use the transpose instead. */ - explicit vpServo(vpServoType servo_type); + VP_EXPLICIT vpServo(vpServoType servo_type); /*! * Destructor. diff --git a/modules/vs/include/visp3/vs/vpServoException.h b/modules/vs/include/visp3/vs/vpServoException.h index 686d665fb8..99b9457039 100644 --- a/modules/vs/include/visp3/vs/vpServoException.h +++ b/modules/vs/include/visp3/vs/vpServoException.h @@ -90,7 +90,7 @@ class VISP_EXPORT vpServoException : public vpException /*! * Constructor. */ - explicit vpServoException(int id) : vpException(id) { } + VP_EXPLICIT vpServoException(int id) : vpException(id) { } }; END_VISP_NAMESPACE #endif diff --git a/modules/vs/src/vpServo.cpp b/modules/vs/src/vpServo.cpp index fd7ec004b6..953c7c5d86 100644 --- a/modules/vs/src/vpServo.cpp +++ b/modules/vs/src/vpServo.cpp @@ -802,7 +802,7 @@ vpColVector vpServo::computeControlLaw() J1p.print(std::cout, 10, "J1p"); #endif e1 = WpW * J1p * error; - } + } e = -lambda(e1) * e1; I.eye(J1.getCols()); @@ -812,7 +812,7 @@ vpColVector vpServo::computeControlLaw() m_first_iteration = false; return e; - } +} vpColVector vpServo::computeControlLaw(double t) { @@ -911,10 +911,10 @@ vpColVector vpServo::computeControlLaw(double t) std::cout << "J1p" << std::endl << J1p; #endif e1 = WpW * J1p * error; - } + } - // memorize the initial e1 value if the function is called the first time - // or if the time given as parameter is equal to 0. + // memorize the initial e1 value if the function is called the first time + // or if the time given as parameter is equal to 0. if (m_first_iteration || std::fabs(t) < std::numeric_limits::epsilon()) { e1_initial = e1; } @@ -932,7 +932,7 @@ vpColVector vpServo::computeControlLaw(double t) m_first_iteration = false; return e; - } +} vpColVector vpServo::computeControlLaw(double t, const vpColVector &e_dot_init) { @@ -1031,10 +1031,10 @@ vpColVector vpServo::computeControlLaw(double t, const vpColVector &e_dot_init) std::cout << "J1p" << std::endl << J1p; #endif e1 = WpW * J1p * error; - } + } - // memorize the initial e1 value if the function is called the first time - // or if the time given as parameter is equal to 0. + // memorize the initial e1 value if the function is called the first time + // or if the time given as parameter is equal to 0. if (m_first_iteration || std::fabs(t) < std::numeric_limits::epsilon()) { e1_initial = e1; } @@ -1052,7 +1052,7 @@ vpColVector vpServo::computeControlLaw(double t, const vpColVector &e_dot_init) m_first_iteration = false; return e; - } +} void vpServo::computeProjectionOperators(const vpMatrix &J1_, const vpMatrix &I_, const vpMatrix &I_WpW_, const vpColVector &error_, vpMatrix &P_) const @@ -1075,7 +1075,7 @@ void vpServo::computeProjectionOperators(const vpMatrix &J1_, const vpMatrix &I_ else sig = 0.0; - vpMatrix eT_J = error_.t() * J1_; + vpMatrix eT_J = static_cast(error_.t()) * J1_; vpMatrix eT_J_JT_e = eT_J.AAt(); double pp = eT_J_JT_e[0][0]; @@ -1106,8 +1106,8 @@ vpColVector vpServo::secondaryTask(const vpColVector &de2dt, const bool &useLarg #endif // std::cout << "I-WpW" << std::endl << I_WpW < +#ifdef ENABLE_VISP_NAMESPACE +using namespace VISP_NAMESPACE_NAME; +#endif + #if defined(VISP_HAVE_X11) -VISP_NAMESPACE_ADDRESSING vpDisplayX drawingHelpers::d_Iinput; -VISP_NAMESPACE_ADDRESSING vpDisplayX drawingHelpers::d_dIx; -VISP_NAMESPACE_ADDRESSING vpDisplayX drawingHelpers::d_dIy; -VISP_NAMESPACE_ADDRESSING vpDisplayX drawingHelpers::d_IcannyVisp; -VISP_NAMESPACE_ADDRESSING vpDisplayX drawingHelpers::d_IcannyImgFilter; +vpDisplayX drawingHelpers::d_Iinput; +vpDisplayX drawingHelpers::d_dIx; +vpDisplayX drawingHelpers::d_dIy; +vpDisplayX drawingHelpers::d_IcannyVisp; +vpDisplayX drawingHelpers::d_IcannyImgFilter; #elif defined(HAVE_OPENCV_HIGHGUI) -VISP_NAMESPACE_ADDRESSING vpDisplayOpenCV drawingHelpers::d_Iinput; -VISP_NAMESPACE_ADDRESSING vpDisplayOpenCV drawingHelpers::d_dIx; -VISP_NAMESPACE_ADDRESSING vpDisplayOpenCV drawingHelpers::d_dIy; -VISP_NAMESPACE_ADDRESSING vpDisplayOpenCV drawingHelpers::d_IcannyVisp; -VISP_NAMESPACE_ADDRESSING vpDisplayOpenCV drawingHelpers::d_IcannyImgFilter; +vpDisplayOpenCV drawingHelpers::d_Iinput; +vpDisplayOpenCV drawingHelpers::d_dIx; +vpDisplayOpenCV drawingHelpers::d_dIy; +vpDisplayOpenCV drawingHelpers::d_IcannyVisp; +vpDisplayOpenCV drawingHelpers::d_IcannyImgFilter; #elif defined(VISP_HAVE_GTK) -VISP_NAMESPACE_ADDRESSING VISP_NAMESPACE_ADDRESSING vpDisplayGTK drawingHelpers::d_Iinput; -VISP_NAMESPACE_ADDRESSING vpDisplayGTK drawingHelpers::d_dIx; -VISP_NAMESPACE_ADDRESSING vpDisplayGTK drawingHelpers::d_dIy; -VISP_NAMESPACE_ADDRESSING vpDisplayGTK drawingHelpers::d_IcannyVisp; -VISP_NAMESPACE_ADDRESSING vpDisplayGTK drawingHelpers::d_IcannyImgFilter; +vpDisplayGTK drawingHelpers::d_Iinput; +vpDisplayGTK drawingHelpers::d_dIx; +vpDisplayGTK drawingHelpers::d_dIy; +vpDisplayGTK drawingHelpers::d_IcannyVisp; +vpDisplayGTK drawingHelpers::d_IcannyImgFilter; #elif defined(VISP_HAVE_GDI) -VISP_NAMESPACE_ADDRESSING vpDisplayGDI drawingHelpers::d_Iinput; -VISP_NAMESPACE_ADDRESSING vpDisplayGDI drawingHelpers::d_dIx; -VISP_NAMESPACE_ADDRESSING vpDisplayGDI drawingHelpers::d_dIy; -VISP_NAMESPACE_ADDRESSING vpDisplayGDI drawingHelpers::d_IcannyVisp; -VISP_NAMESPACE_ADDRESSING vpDisplayGDI drawingHelpers::d_IcannyImgFilter; +vpDisplayGDI drawingHelpers::d_Iinput; +vpDisplayGDI drawingHelpers::d_dIx; +vpDisplayGDI drawingHelpers::d_dIy; +vpDisplayGDI drawingHelpers::d_IcannyVisp; +vpDisplayGDI drawingHelpers::d_IcannyImgFilter; #elif defined(VISP_HAVE_D3D9) -VISP_NAMESPACE_ADDRESSING vpDisplayD3D drawingHelpers::d_Iinput; -VISP_NAMESPACE_ADDRESSING vpDisplayD3D drawingHelpers::d_dIx; -VISP_NAMESPACE_ADDRESSING vpDisplayD3D drawingHelpers::d_dIy; -VISP_NAMESPACE_ADDRESSING vpDisplayD3D drawingHelpers::d_IcannyVisp; -VISP_NAMESPACE_ADDRESSING vpDisplayD3D drawingHelpers::d_IcannyImgFilter; +vpDisplayD3D drawingHelpers::d_Iinput; +vpDisplayD3D drawingHelpers::d_dIx; +vpDisplayD3D drawingHelpers::d_dIy; +vpDisplayD3D drawingHelpers::d_IcannyVisp; +vpDisplayD3D drawingHelpers::d_IcannyImgFilter; #endif -void drawingHelpers::init(VISP_NAMESPACE_ADDRESSING vpImage &Iinput, VISP_NAMESPACE_ADDRESSING vpImage &IcannyVisp, VISP_NAMESPACE_ADDRESSING vpImage *p_dIx, - VISP_NAMESPACE_ADDRESSING vpImage *p_dIy, VISP_NAMESPACE_ADDRESSING vpImage *p_IcannyimgFilter) +void drawingHelpers::init(vpImage &Iinput, vpImage &IcannyVisp, vpImage *p_dIx, + vpImage *p_dIy, vpImage *p_IcannyimgFilter) { #if defined(VISP_HAVE_DISPLAY) d_Iinput.init(Iinput, 10, 10); @@ -88,14 +92,14 @@ void drawingHelpers::init(VISP_NAMESPACE_ADDRESSING vpImage &Iinp #endif } -void drawingHelpers::display(VISP_NAMESPACE_ADDRESSING vpImage &I, const std::string &title) +void drawingHelpers::display(vpImage &I, const std::string &title) { vpDisplay::display(I); vpDisplay::setTitle(I, title); vpDisplay::flush(I); } -bool drawingHelpers::waitForClick(VISP_NAMESPACE_ADDRESSING const vpImage &I, const bool &blockingMode) +bool drawingHelpers::waitForClick(const vpImage &I, const bool &blockingMode) { vpDisplay::displayText(I, 15, 15, "Left click to continue...", vpColor::red); vpDisplay::displayText(I, 35, 15, "Right click to stop...", vpColor::red); diff --git a/tutorial/imgproc/contour/tutorial-contour.cpp b/tutorial/imgproc/contour/tutorial-contour.cpp index 0ba278de63..49657fe835 100644 --- a/tutorial/imgproc/contour/tutorial-contour.cpp +++ b/tutorial/imgproc/contour/tutorial-contour.cpp @@ -126,7 +126,7 @@ int main(int argc, const char **argv) vpDisplay::flush(I_draw_contours); vpDisplay::getClick(I_draw_contours); - I_draw_contours = 0; + I_draw_contours = vpRGBa(0); //! [Draw contours hierarchical] drawContoursTree(I_draw_contours, vp_contours); //! [Draw contours hierarchical] diff --git a/tutorial/imgproc/hough-transform/drawingHelpers.cpp b/tutorial/imgproc/hough-transform/drawingHelpers.cpp index 1c1d15db75..bcff4a8ff4 100644 --- a/tutorial/imgproc/hough-transform/drawingHelpers.cpp +++ b/tutorial/imgproc/hough-transform/drawingHelpers.cpp @@ -2,21 +2,25 @@ #include +#ifdef ENABLE_VISP_NAMESPACE +using namespace VISP_NAMESPACE_NAME; +#endif + #if defined(VISP_HAVE_X11) -VISP_NAMESPACE_ADDRESSING vpDisplayX drawingHelpers::d; +vpDisplayX drawingHelpers::d; #elif defined(VISP_HAVE_OPENCV) -VISP_NAMESPACE_ADDRESSING vpDisplayOpenCV drawingHelpers::d; +vpDisplayOpenCV drawingHelpers::d; #elif defined(VISP_HAVE_GTK) -VISP_NAMESPACE_ADDRESSING vpDisplayGTK drawingHelpers::d; +vpDisplayGTK drawingHelpers::d; #elif defined(VISP_HAVE_GDI) -VISP_NAMESPACE_ADDRESSING vpDisplayGDI drawingHelpers::d; +vpDisplayGDI drawingHelpers::d; #elif defined(VISP_HAVE_D3D9) -VISP_NAMESPACE_ADDRESSING vpDisplayD3D drawingHelpers::d; +vpDisplayD3D drawingHelpers::d; #endif -VISP_NAMESPACE_ADDRESSING vpImage drawingHelpers::I_disp; +vpImage drawingHelpers::I_disp; -bool drawingHelpers::display(VISP_NAMESPACE_ADDRESSING vpImage &I, const std::string &title, const bool &blockingMode) +bool drawingHelpers::display(vpImage< vpRGBa> &I, const std::string &title, const bool &blockingMode) { I_disp = I; #if defined(VISP_HAVE_DISPLAY) @@ -43,14 +47,14 @@ bool drawingHelpers::display(VISP_NAMESPACE_ADDRESSING vpImage &D, const std::string &title, const bool &blockingMode) +bool drawingHelpers::display(vpImage &D, const std::string &title, const bool &blockingMode) { vpImage I; // Image to display vpImageConvert::convert(D, I); return display(I, title, blockingMode); } -bool drawingHelpers::display(VISP_NAMESPACE_ADDRESSING vpImage &D, const std::string &title, const bool &blockingMode) +bool drawingHelpers::display(vpImage &D, const std::string &title, const bool &blockingMode) { vpImage I; // Image to display vpImageConvert::convert(D, I); From 6a159004e1ddbac7ce4b7b691dba3f98c7088d3b Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 24 Jun 2024 18:47:58 +0200 Subject: [PATCH 03/11] Remove c++11 check to use explicit keyword --- cmake/templates/vpConfig.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/templates/vpConfig.h.in b/cmake/templates/vpConfig.h.in index c36e4dae15..efa274b9fc 100644 --- a/cmake/templates/vpConfig.h.in +++ b/cmake/templates/vpConfig.h.in @@ -701,7 +701,7 @@ namespace vp = VISP_NAMESPACE_NAME; // Add the macro for explicit keyword #ifndef VP_EXPLICIT -# if ((__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1600)) && defined(ENABLE_EXPLICIT_KEYWORD) +# if defined(ENABLE_EXPLICIT_KEYWORD) # define VP_EXPLICIT explicit # else # define VP_EXPLICIT From 5e2091a3b4a5993c363f1c7cc1155401f5c6b174 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 24 Jun 2024 18:53:47 +0200 Subject: [PATCH 04/11] Use VP_EXPLICIT instead of explicit --- modules/core/src/tools/geometry/vpRectOriented.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/core/src/tools/geometry/vpRectOriented.cpp b/modules/core/src/tools/geometry/vpRectOriented.cpp index 104d396ad0..c7e0ebe906 100644 --- a/modules/core/src/tools/geometry/vpRectOriented.cpp +++ b/modules/core/src/tools/geometry/vpRectOriented.cpp @@ -124,6 +124,7 @@ vpRectOriented &vpRectOriented::operator=(const vpRect &rect) return *this; } +#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) /** * Conversion to vpRect operator. */ @@ -135,6 +136,7 @@ vpRectOriented::operator vpRect() return vpRect(m_topLeft, m_bottomRight); } +#endif /** Set the corners of the rectangle. * @warning This method doesn't check whether the 4 points actually form a rectangle! From c25448513a5c166496841857558865d1d1fe67ba Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 24 Jun 2024 19:04:57 +0200 Subject: [PATCH 05/11] Use VP_EXPLICIT instead of explicit --- modules/core/include/visp3/core/vpRectOriented.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/core/include/visp3/core/vpRectOriented.h b/modules/core/include/visp3/core/vpRectOriented.h index 4175daf1ed..558cad8042 100644 --- a/modules/core/include/visp3/core/vpRectOriented.h +++ b/modules/core/include/visp3/core/vpRectOriented.h @@ -67,9 +67,7 @@ class VISP_EXPORT vpRectOriented vpRectOriented &operator=(const vpRect &rect); #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) - explicit operator vpRect(); -#else - operator vpRect(); + VP_EXPLICIT operator vpRect(); #endif void setCenter(const vpImagePoint ¢er); From ac57ba93ea38331a813f3ac42d160df49e1ea1c3 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 25 Jun 2024 10:26:05 +0200 Subject: [PATCH 06/11] Use VP_EXPLICIT instead of explicit keyword --- modules/core/include/visp3/core/vpRGBa.h | 8 +++--- modules/core/include/visp3/core/vpRGBf.h | 6 ++--- .../include/visp3/robot/vpImageSimulator.h | 5 ++-- .../visp3/robot/vpWireFrameSimulator.h | 13 +++++----- .../src/image-simulator/vpImageSimulator.cpp | 26 +++++++++---------- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/modules/core/include/visp3/core/vpRGBa.h b/modules/core/include/visp3/core/vpRGBa.h index 0eebdf9d6c..2cba895692 100644 --- a/modules/core/include/visp3/core/vpRGBa.h +++ b/modules/core/include/visp3/core/vpRGBa.h @@ -94,7 +94,7 @@ class VISP_EXPORT vpRGBa \param v : Value to set. */ - explicit inline vpRGBa(unsigned char v) : R(v), G(v), B(v), A(v) { } + VP_EXPLICIT inline vpRGBa(unsigned char v) : R(v), G(v), B(v), A(v) { } /*! Constructor. @@ -103,7 +103,7 @@ class VISP_EXPORT vpRGBa \param v : Value to set. */ - explicit inline vpRGBa(unsigned int v) : R(v), G(v), B(v), A(v) + VP_EXPLICIT inline vpRGBa(unsigned int v) : R(v), G(v), B(v), A(v) { assert(v < 256); } @@ -115,7 +115,7 @@ class VISP_EXPORT vpRGBa \param v : Value to set. */ - explicit inline vpRGBa(int v) : R(v), G(v), B(v), A(v) + VP_EXPLICIT inline vpRGBa(int v) : R(v), G(v), B(v), A(v) { assert(v < 256); } @@ -133,7 +133,7 @@ class VISP_EXPORT vpRGBa B=v[2] A=v[3] */ - explicit inline vpRGBa(const vpColVector &v) : R(0), G(0), B(0), A(vpRGBa::alpha_default) { *this = v; } + VP_EXPLICIT inline vpRGBa(const vpColVector &v) : R(0), G(0), B(0), A(vpRGBa::alpha_default) { *this = v; } // We cannot add here the following destructor without changing the // hypothesis that the size of this class is 4. With the destructor it diff --git a/modules/core/include/visp3/core/vpRGBf.h b/modules/core/include/visp3/core/vpRGBf.h index ce177e1ff6..bbacdd6358 100644 --- a/modules/core/include/visp3/core/vpRGBf.h +++ b/modules/core/include/visp3/core/vpRGBf.h @@ -86,7 +86,7 @@ class VISP_EXPORT vpRGBf \param v : Value to set. */ - explicit inline vpRGBf(float v) : R(v), G(v), B(v) { } + VP_EXPLICIT inline vpRGBf(float v) : R(v), G(v), B(v) { } /*! Constructor. @@ -95,7 +95,7 @@ class VISP_EXPORT vpRGBf \param v : Value to set. */ - explicit inline vpRGBf(int v) + VP_EXPLICIT inline vpRGBf(int v) { *this = v; } @@ -112,7 +112,7 @@ class VISP_EXPORT vpRGBf G=v[1] B=v[2] */ - explicit inline vpRGBf(const vpColVector &v) : R(0), G(0), B(0) { *this = v; } + VP_EXPLICIT inline vpRGBf(const vpColVector &v) : R(0), G(0), B(0) { *this = v; } vpRGBf &operator=(float v); vpRGBf &operator=(int v); diff --git a/modules/robot/include/visp3/robot/vpImageSimulator.h b/modules/robot/include/visp3/robot/vpImageSimulator.h index 1ffe688bb0..6bc6e0664e 100644 --- a/modules/robot/include/visp3/robot/vpImageSimulator.h +++ b/modules/robot/include/visp3/robot/vpImageSimulator.h @@ -73,15 +73,14 @@ int main() { - vpImage Icamera(480,640,0); + vpImage Icamera(480,640,vpRGBa(0)); vpImage Iimage(60,60); // Initialise the image which will be projected into the image Icamera vpRGBa colorb(0,0,255); vpRGBa colorw(255,255,255); vpRGBa colorr(255,0,0); - for(int i = 0; i < 60; i++) - { + for(int i = 0; i < 60; i++) { for(int j = 0; j < 20; j++) Iimage[i][j] = colorb; for(int j = 20; j < 40; j++) diff --git a/modules/robot/include/visp3/robot/vpWireFrameSimulator.h b/modules/robot/include/visp3/robot/vpWireFrameSimulator.h index 0bea74a8d9..d1e4e550ba 100644 --- a/modules/robot/include/visp3/robot/vpWireFrameSimulator.h +++ b/modules/robot/include/visp3/robot/vpWireFrameSimulator.h @@ -113,7 +113,6 @@ BEGIN_VISP_NAMESPACE The following example shows how it is easy to use. \code - #include #include @@ -121,21 +120,21 @@ BEGIN_VISP_NAMESPACE { vpWireFrameSimulator sim; - vpImage Iint(480,640,255); - vpImage Iext(480,640,255); + vpImage Iint(480, 640, vpRGBa(255)); + vpImage Iext(480, 640, vpRGBa(255)); //Set the type of scene to use sim.initScene(vpWireFrameSimulator::PLATE, vpWireFrameSimulator::D_STANDARD); //Set the initial pose of the camera - sim.setCameraPositionRelObj(vpHomogeneousMatrix(0,0,0.5,vpMath::rad(0),vpMath::rad(10),0)); + sim.setCameraPositionRelObj(vpHomogeneousMatrix(0, 0, 0.5, vpMath::rad(0), vpMath::rad(10), 0)); //Set the desired pose of the camera (for the internal view) - sim.setDesiredCameraPosition(vpHomogeneousMatrix(0.0,0,0.5,0,0,0)); + sim.setDesiredCameraPosition(vpHomogeneousMatrix(0.0, 0, 0.5, 0, 0, 0)); //Set the pose of the reference frame (for the external view) - sim.setExternalCameraPosition(vpHomogeneousMatrix(0.1,0,0.2,0,0,0)); + sim.setExternalCameraPosition(vpHomogeneousMatrix(0.1, 0, 0.2, 0, 0, 0)); //Set the camera parameters - vpCameraParameters camera(1000,1000,320,240); + vpCameraParameters camera(1000, 1000, 320, 240); sim.setInternalCameraParameters(camera); sim.setExternalCameraParameters(camera); diff --git a/modules/robot/src/image-simulator/vpImageSimulator.cpp b/modules/robot/src/image-simulator/vpImageSimulator.cpp index 5607b7a832..929b522f5b 100644 --- a/modules/robot/src/image-simulator/vpImageSimulator.cpp +++ b/modules/robot/src/image-simulator/vpImageSimulator.cpp @@ -564,15 +564,14 @@ void vpImageSimulator::getImage(vpImage &I, const vpCameraParameters &ca int main() { - vpImage Icamera(480,640,0); - vpImage Iimage(60,60); + vpImage Icamera(480, 640, vpRGBa(0)); + vpImage Iimage(60, 60); // Initialise the image which will be projected into the image Icamera - vpRGBa colorb(0,0,255); - vpRGBa colorw(255,255,255); - vpRGBa colorr(255,0,0); - for(int i = 0; i < 60; i++) - { + vpRGBa colorb(0, 0, 255); + vpRGBa colorw(255, 255, 255); + vpRGBa colorr(255, 0, 0); + for(int i = 0; i < 60; i++) { for(int j = 0; j < 20; j++) Iimage[i][j] = colorb; for(int j = 20; j < 40; j++) @@ -763,15 +762,14 @@ void vpImageSimulator::getImage(vpImage &I, std::list Icamera(480,640,0); - vpImage Iimage(60,60); + vpImage Icamera(480, 640, vpRGBa(0)); + vpImage Iimage(60, 60); // Initialise the image which will be projected into the image Icamera - vpRGBa colorb(0,0,255); - vpRGBa colorw(255,255,255); - vpRGBa colorr(255,0,0); - for(int i = 0; i < 60; i++) - { + vpRGBa colorb(0, 0, 255); + vpRGBa colorw(255, 255, 255); + vpRGBa colorr(255, 0, 0); + for(int i = 0; i < 60; i++) { for(int j = 0; j < 20; j++) Iimage[i][j] = colorb; for(int j = 20; j < 40; j++) From d299b039089873af1eebb8366e7e0ad198c8a842 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 25 Jun 2024 10:27:56 +0200 Subject: [PATCH 07/11] Remove deprecated buildFrom() usage --- modules/python/examples/yolo-centering-task-afma6.py | 10 +++++----- modules/python/examples/yolo-centering-task.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/python/examples/yolo-centering-task-afma6.py b/modules/python/examples/yolo-centering-task-afma6.py index 48a24e4153..8221727309 100644 --- a/modules/python/examples/yolo-centering-task-afma6.py +++ b/modules/python/examples/yolo-centering-task-afma6.py @@ -255,10 +255,10 @@ def animate(i): Zd = I_depth[h // 2, w // 2] * depth_scale print(f'Desired depth is {Zd}') sd = FeaturePoint() - sd.buildFrom(xd, yd, Zd) + sd.build(xd, yd, Zd) s = FeaturePoint() - s.buildFrom(0.0, 0.0, Zd) + s.build(0.0, 0.0, Zd) task = Servo() task.addFeature(s, sd) @@ -309,14 +309,14 @@ def has_class_box(box): kalman.filter(ColVector([x, y]), (1 / fps)) kalman_state = kalman.getXest() last_detection_time = time.time() - s.buildFrom(kalman_state[0], kalman_state[3], Zd) + s.build(kalman_state[0], kalman_state[3], Zd) v = task.computeControlLaw() else: if last_detection_time < 0.0: raise RuntimeError('No detection at first iteration') kalman.predict(time.time() - last_detection_time) kalman_pred = kalman.getXpred() - s.buildFrom(kalman_pred[0], kalman_pred[3], Zd) + s.build(kalman_pred[0], kalman_pred[3], Zd) task.computeControlLaw() error: ColVector = task.getError() @@ -333,7 +333,7 @@ def has_class_box(box): Display.flush(I) Display.getImage(I, Idisp) robot.getPosition(Robot.ControlFrameType.REFERENCE_FRAME, r) - cTw.buildFrom(r) + cTw.build(r) plotter.on_iter(Idisp, v, error, cTw) # Move robot/update simulator diff --git a/modules/python/examples/yolo-centering-task.py b/modules/python/examples/yolo-centering-task.py index 1d91c53d3e..06ed1b08ed 100644 --- a/modules/python/examples/yolo-centering-task.py +++ b/modules/python/examples/yolo-centering-task.py @@ -125,10 +125,10 @@ def animate(i): # Define centering task xd, yd = PixelMeterConversion.convertPoint(cam, w / 2.0, h / 2.0) sd = FeaturePoint() - sd.buildFrom(xd, yd, Z) + sd.build(xd, yd, Z) s = FeaturePoint() - s.buildFrom(0.0, 0.0, Z) + s.build(0.0, 0.0, Z) task = Servo() task.addFeature(s, sd) @@ -177,7 +177,7 @@ def has_class_box(box): if bb is not None: u, v = bb[0], bb[1] x, y = PixelMeterConversion.convertPoint(cam, u, v) - s.buildFrom(x, y, Z) + s.build(x, y, Z) v = task.computeControlLaw() prev_v = v else: From fc4fe4424a22d7bc2203345d8698ccb646632adb Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 25 Jun 2024 13:56:29 +0200 Subject: [PATCH 08/11] Modify all the sample codes to show how to consider visp namespace --- modules/ar/include/visp3/ar/vpAR.h | 4 + modules/core/include/visp3/core/vpArray2D.h | 18 + .../core/include/visp3/core/vpCPUFeatures.h | 4 + .../include/visp3/core/vpCameraParameters.h | 4 + modules/core/include/visp3/core/vpClient.h | 4 + modules/core/include/visp3/core/vpColVector.h | 80 ++ modules/core/include/visp3/core/vpColor.h | 4 + modules/core/include/visp3/core/vpDebug.h | 44 + modules/core/include/visp3/core/vpDisplay.h | 8 + .../include/visp3/core/vpForceTwistMatrix.h | 12 + .../core/include/visp3/core/vpFrameGrabber.h | 4 + modules/core/include/visp3/core/vpGaussRand.h | 8 + .../include/visp3/core/vpHomogeneousMatrix.h | 16 + modules/core/include/visp3/core/vpImage.h | 4 + .../core/include/visp3/core/vpImagePoint.h | 4 + .../core/include/visp3/core/vpImageTools.h | 4 + .../include/visp3/core/vpImage_operators.h | 4 + modules/core/include/visp3/core/vpIoTools.h | 8 + modules/core/include/visp3/core/vpLinProg.h | 4 + .../core/vpLinearKalmanFilterInstantiation.h | 24 +- modules/core/include/visp3/core/vpMatrix.h | 34 + .../core/include/visp3/core/vpMomentAlpha.h | 4 + .../visp3/core/vpMomentAreaNormalized.h | 4 + .../include/visp3/core/vpMomentCInvariant.h | 93 +- .../include/visp3/core/vpMomentDatabase.h | 4 + .../visp3/core/vpMomentGravityCenter.h | 4 + .../core/include/visp3/core/vpMomentObject.h | 210 ++--- modules/core/include/visp3/core/vpMutex.h | 8 + modules/core/include/visp3/core/vpPolygon.h | 4 + .../core/include/visp3/core/vpPoseVector.h | 16 + .../include/visp3/core/vpRotationMatrix.h | 12 + .../include/visp3/core/vpRotationVector.h | 42 +- modules/core/include/visp3/core/vpRowVector.h | 14 + .../core/include/visp3/core/vpRxyzVector.h | 4 + .../core/include/visp3/core/vpRzyxVector.h | 4 + .../core/include/visp3/core/vpRzyzVector.h | 50 +- modules/core/include/visp3/core/vpSerial.h | 20 +- .../core/include/visp3/core/vpThetaUVector.h | 4 + modules/core/include/visp3/core/vpTime.h | 4 + .../include/visp3/core/vpTranslationVector.h | 4 + modules/core/include/visp3/core/vpUDPClient.h | 8 + modules/core/include/visp3/core/vpUDPServer.h | 192 +++-- .../visp3/core/vpVelocityTwistMatrix.h | 108 +-- .../include/visp3/core/vpXmlParserCamera.h | 132 +-- .../visp3/core/vpXmlParserRectOriented.h | 52 +- .../core/src/camera/vpCameraParameters.cpp | 12 + modules/core/src/camera/vpXmlParserCamera.cpp | 26 +- modules/core/src/display/vpDisplay.cpp | 276 +++--- modules/core/src/display/vpDisplay_rgba.cpp | 50 +- modules/core/src/display/vpDisplay_uchar.cpp | 50 +- modules/core/src/image/vpImageConvert.cpp | 4 + .../core/src/image/vpImageConvert_opencv.cpp | 16 + .../core/src/image/vpImageConvert_yarp.cpp | 24 + .../core/src/image/vpImageFilter_canny.cpp | 12 + modules/core/src/image/vpImagePoint.cpp | 285 ++++--- modules/core/src/image/vpImageTools.cpp | 50 +- modules/core/src/image/vpRGBa.cpp | 4 + modules/core/src/image/vpRGBf.cpp | 4 + .../vpLinearKalmanFilterInstantiation.cpp | 172 ++-- modules/core/src/math/matrix/vpMatrix.cpp | 68 ++ .../src/math/matrix/vpMatrix_cholesky.cpp | 12 + modules/core/src/math/matrix/vpMatrix_lu.cpp | 32 + .../src/math/matrix/vpMatrix_operations.cpp | 8 + .../src/math/matrix/vpMatrix_operators.cpp | 8 + .../math/matrix/vpMatrix_pseudo_inverse.cpp | 40 + .../matrix/vpMatrix_pseudo_inverse_eigen.cpp | 32 + .../matrix/vpMatrix_pseudo_inverse_lapack.cpp | 32 + .../matrix/vpMatrix_pseudo_inverse_opencv.cpp | 32 + modules/core/src/math/matrix/vpMatrix_qr.cpp | 34 + modules/core/src/math/matrix/vpMatrix_svd.cpp | 24 + modules/core/src/math/matrix/vpRowVector.cpp | 88 +- .../transformation/vpForceTwistMatrix.cpp | 30 +- .../transformation/vpHomogeneousMatrix.cpp | 568 +++++++------ .../transformation/vpQuaternionVector.cpp | 8 + .../math/transformation/vpRotationMatrix.cpp | 94 ++- .../math/transformation/vpRotationVector.cpp | 40 +- .../src/math/transformation/vpRxyzVector.cpp | 12 + .../src/math/transformation/vpRzyxVector.cpp | 12 + .../src/math/transformation/vpRzyzVector.cpp | 12 + .../math/transformation/vpThetaUVector.cpp | 28 + .../transformation/vpTranslationVector.cpp | 12 + .../transformation/vpVelocityTwistMatrix.cpp | 40 +- modules/core/src/tools/file/vpIoTools.cpp | 137 +-- .../core/src/tools/optimization/vpLinProg.cpp | 18 +- .../src/tools/optimization/vpQuadProg.cpp | 27 +- modules/core/src/tools/serial/vpSerial.cpp | 108 ++- modules/core/src/tools/time/vpTime.cpp | 37 +- .../core/src/tracking/moments/vpMoment.cpp | 6 +- .../src/tracking/moments/vpMomentCommon.cpp | 4 + .../src/tracking/moments/vpMomentObject.cpp | 139 +-- .../visp3/detection/vpDetectorAprilTag.h | 12 + .../detection/vpDetectorDataMatrixCode.h | 4 + .../include/visp3/detection/vpDetectorFace.h | 4 + .../visp3/detection/vpDetectorQRCode.h | 4 + modules/gui/include/visp3/gui/vpDisplayD3D.h | 4 + modules/gui/include/visp3/gui/vpDisplayGDI.h | 4 + modules/gui/include/visp3/gui/vpDisplayGTK.h | 4 + .../gui/include/visp3/gui/vpDisplayOpenCV.h | 4 + modules/gui/include/visp3/gui/vpDisplayX.h | 4 + modules/gui/src/display/vpDisplayGTK.cpp | 40 +- modules/gui/src/display/vpDisplayOpenCV.cpp | 40 +- modules/gui/src/display/vpDisplayX.cpp | 40 +- modules/io/include/visp3/io/vpDiskGrabber.h | 4 + modules/io/include/visp3/io/vpImageIo.h | 28 +- modules/io/include/visp3/io/vpParallelPort.h | 22 +- modules/io/include/visp3/io/vpVideoReader.h | 12 + modules/io/include/visp3/io/vpVideoWriter.h | 88 +- modules/io/src/video/vpVideoReader.cpp | 60 +- .../include/visp3/robot/vpImageSimulator.h | 4 + .../robot/include/visp3/robot/vpQbSoftHand.h | 4 + .../robot/include/visp3/robot/vpRingLight.h | 73 +- .../robot/include/visp3/robot/vpRobotAfma6.h | 20 +- .../include/visp3/robot/vpRobotBiclops.h | 8 + .../robot/include/visp3/robot/vpRobotCamera.h | 56 +- .../include/visp3/robot/vpRobotViper650.h | 268 +++--- .../include/visp3/robot/vpRobotViper850.h | 260 +++--- .../robot/include/visp3/robot/vpServolens.h | 31 +- .../include/visp3/robot/vpSimulatorAfma6.h | 8 + .../include/visp3/robot/vpSimulatorCamera.h | 4 + .../include/visp3/robot/vpSimulatorPioneer.h | 4 + .../visp3/robot/vpSimulatorPioneerPan.h | 4 + .../include/visp3/robot/vpSimulatorViper850.h | 12 + .../robot/include/visp3/robot/vpVirtuose.h | 82 +- .../visp3/robot/vpWireFrameSimulator.h | 4 + .../src/haptic-device/virtuose/vpVirtuose.cpp | 94 ++- .../src/image-simulator/vpImageSimulator.cpp | 8 + .../src/real-robot/afma4/vpServolens.cpp | 30 +- .../robot/src/real-robot/afma6/vpAfma6.cpp | 248 +++--- .../src/real-robot/afma6/vpRobotAfma6.cpp | 247 +++--- .../vpRobotUniversalRobots.cpp | 70 +- .../src/real-robot/viper/vpRobotViper650.cpp | 775 +++++++++-------- .../src/real-robot/viper/vpRobotViper850.cpp | 798 ++++++++++-------- .../robot/src/real-robot/viper/vpViper.cpp | 38 +- .../robot/src/real-robot/viper/vpViper650.cpp | 208 ++--- .../robot/src/real-robot/viper/vpViper850.cpp | 146 ++-- .../src/robot-simulator/vpSimulatorAfma6.cpp | 384 +++++---- .../robot-simulator/vpSimulatorViper850.cpp | 472 ++++++----- modules/robot/src/vpRobot.cpp | 66 +- .../include/visp3/sensor/vp1394CMUGrabber.h | 90 +- .../include/visp3/sensor/vp1394TwoGrabber.h | 8 + .../sensor/include/visp3/sensor/vpComedi.h | 62 +- .../visp3/sensor/vpFlyCaptureGrabber.h | 56 +- .../visp3/sensor/vpForceTorqueIitSensor.h | 104 +-- .../sensor/include/visp3/sensor/vpKinect.h | 74 +- .../visp3/sensor/vpOccipitalStructure.h | 290 +++---- .../sensor/include/visp3/sensor/vpRealSense.h | 364 ++++---- .../include/visp3/sensor/vpRealSense2.h | 481 ++++++----- .../sensor/include/visp3/sensor/vpScanPoint.h | 28 +- .../sensor/include/visp3/sensor/vpSickLDMRS.h | 4 + .../include/visp3/sensor/vpV4l2Grabber.h | 4 + .../force-torque/vpForceTorqueAtiSensor.cpp | 20 +- .../framegrabber/1394/vp1394CMUGrabber.cpp | 36 +- .../framegrabber/1394/vp1394TwoGrabber.cpp | 685 ++++++++------- .../flycapture/vpFlyCaptureGrabber.cpp | 708 +++++++++------- .../src/framegrabber/v4l2/vpV4l2Grabber.cpp | 56 +- .../src/rgb-depth/realsense/vpRealSense.cpp | 96 ++- .../src/rgb-depth/realsense/vpRealSense2.cpp | 103 +-- .../tracker/blob/include/visp3/blob/vpDot.h | 4 + .../visp3/dnn_tracker/vpMegaPoseTracker.h | 4 + .../include/visp3/mbt/vpMbEdgeKltTracker.h | 4 + .../mbt/include/visp3/mbt/vpMbEdgeTracker.h | 8 + .../include/visp3/mbt/vpMbGenericTracker.h | 4 + .../mbt/include/visp3/mbt/vpMbKltTracker.h | 12 + modules/tracker/mbt/src/vpMbtPolygon.cpp | 40 +- modules/tracker/me/include/visp3/me/vpMe.h | 4 + .../tracker/me/include/visp3/me/vpMeLine.h | 4 + .../tracker/me/include/visp3/me/vpMeNurbs.h | 4 + modules/tracker/tt/src/vpTemplateTracker.cpp | 96 ++- .../include/visp3/vision/vpHomography.h | 4 + .../vision/include/visp3/vision/vpKeyPoint.h | 8 + .../include/visp3/vision/vpPoseFeatures.h | 8 + .../visp3/visual_features/vpFeatureDepth.h | 8 + .../visp3/visual_features/vpFeatureLine.h | 8 + .../visp3/visual_features/vpFeatureMoment.h | 4 + .../visual_features/vpFeatureMomentCommon.h | 4 + .../visual_features/vpFeatureMomentDatabase.h | 4 + .../vpFeatureMomentGravityCenter.h | 4 + .../visp3/visual_features/vpFeaturePoint.h | 8 + .../visp3/visual_features/vpFeaturePoint3D.h | 8 + .../visual_features/vpFeaturePointPolar.h | 8 + .../visp3/visual_features/vpFeatureThetaU.h | 8 + .../visual_features/vpFeatureTranslation.h | 12 + .../visp3/visual_features/vpGenericFeature.h | 8 + .../src/visual-feature/vpFeatureSegment.cpp | 6 +- modules/vs/include/visp3/vs/vpAdaptiveGain.h | 4 + modules/vs/include/visp3/vs/vpServo.h | 8 + 186 files changed, 7301 insertions(+), 5098 deletions(-) diff --git a/modules/ar/include/visp3/ar/vpAR.h b/modules/ar/include/visp3/ar/vpAR.h index cb110926cd..0763039ff0 100644 --- a/modules/ar/include/visp3/ar/vpAR.h +++ b/modules/ar/include/visp3/ar/vpAR.h @@ -88,6 +88,10 @@ BEGIN_VISP_NAMESPACE #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + #ifdef VISP_HAVE_COIN3D_AND_GUI static void *mainloopfunction(void *_simu) { diff --git a/modules/core/include/visp3/core/vpArray2D.h b/modules/core/include/visp3/core/vpArray2D.h index f97defc41c..89e5484619 100644 --- a/modules/core/include/visp3/core/vpArray2D.h +++ b/modules/core/include/visp3/core/vpArray2D.h @@ -72,6 +72,10 @@ BEGIN_VISP_NAMESPACE * \code * #include a(2, 3); @@ -97,6 +101,10 @@ BEGIN_VISP_NAMESPACE * \code * #include a{ {-1, -2, -3}, {4, 5.5, 6.0f} }; @@ -105,6 +113,12 @@ BEGIN_VISP_NAMESPACE * \endcode * The array could also be initialized using operator=(const std::initializer_list< std::initializer_list< Type > > &) * \code + * #include a; @@ -116,6 +130,10 @@ BEGIN_VISP_NAMESPACE * \code * #include a{ -1, -2, -3, 4, 5.5, 6.0f }; diff --git a/modules/core/include/visp3/core/vpCPUFeatures.h b/modules/core/include/visp3/core/vpCPUFeatures.h index 611f3eb75d..030e181b77 100644 --- a/modules/core/include/visp3/core/vpCPUFeatures.h +++ b/modules/core/include/visp3/core/vpCPUFeatures.h @@ -51,6 +51,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { std::cout << "checkSSE2: " << vpCPUFeatures::checkSSE2() << std::endl; diff --git a/modules/core/include/visp3/core/vpCameraParameters.h b/modules/core/include/visp3/core/vpCameraParameters.h index 5c1206097d..c20887f93f 100644 --- a/modules/core/include/visp3/core/vpCameraParameters.h +++ b/modules/core/include/visp3/core/vpCameraParameters.h @@ -263,6 +263,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_NLOHMANN_JSON) diff --git a/modules/core/include/visp3/core/vpClient.h b/modules/core/include/visp3/core/vpClient.h index 75a2e0727c..10219044c3 100644 --- a/modules/core/include/visp3/core/vpClient.h +++ b/modules/core/include/visp3/core/vpClient.h @@ -63,6 +63,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * std::string servername = "localhost"; diff --git a/modules/core/include/visp3/core/vpColVector.h b/modules/core/include/visp3/core/vpColVector.h index 40fb48d844..969db03ec7 100644 --- a/modules/core/include/visp3/core/vpColVector.h +++ b/modules/core/include/visp3/core/vpColVector.h @@ -76,6 +76,10 @@ BEGIN_VISP_NAMESPACE * \code * #include &) * \code + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector v; @@ -133,6 +149,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined(VISP_HAVE_NLOHMANN_JSON) @@ -295,6 +315,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector v(3); @@ -322,6 +346,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * std::ofstream ofs("log.csv", std::ofstream::out); @@ -435,6 +463,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector v(4); @@ -466,6 +498,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector v(4); @@ -498,6 +534,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector v(3); @@ -527,6 +567,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector v(3); @@ -655,6 +699,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector c; @@ -878,6 +926,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector A, B(5); @@ -901,6 +953,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * size_t n = 5; @@ -925,6 +981,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * \code * #include * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * int var=0; @@ -1222,6 +1290,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector v(10); @@ -1278,6 +1350,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector v(10); @@ -1385,6 +1461,10 @@ class VISP_EXPORT vpColVector : public vpArray2D * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector v(4); diff --git a/modules/core/include/visp3/core/vpColor.h b/modules/core/include/visp3/core/vpColor.h index 148f8b12a6..6af7f0960f 100644 --- a/modules/core/include/visp3/core/vpColor.h +++ b/modules/core/include/visp3/core/vpColor.h @@ -103,6 +103,10 @@ BEGIN_VISP_NAMESPACE #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage I(240, 320); // Create a black grey level image diff --git a/modules/core/include/visp3/core/vpDebug.h b/modules/core/include/visp3/core/vpDebug.h index 95d92041f7..4d45ab6c0f 100644 --- a/modules/core/include/visp3/core/vpDebug.h +++ b/modules/core/include/visp3/core/vpDebug.h @@ -98,6 +98,10 @@ BEGIN_VISP_NAMESPACE #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpIN_FCT("main()"); @@ -259,6 +263,10 @@ class vpTraceOutput #define VP_TRACE // To activate the trace mode #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpIN_FCT("main()"); @@ -279,6 +287,10 @@ class vpTraceOutput #define VP_TRACE // To activate the trace mode #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpIN_FCT("main()"); @@ -316,6 +328,10 @@ inline void vpOUT_FCT(const char * /* a */, ...) { } #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // C++-like debug printings @@ -343,6 +359,10 @@ inline void vpOUT_FCT(const char * /* a */, ...) { } #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // C++-like debug printings @@ -372,6 +392,10 @@ inline void vpOUT_FCT(const char * /* a */, ...) { } #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // Printing depend only VP_DEBUG_MODE value is >= 1 @@ -396,6 +420,10 @@ inline void vpOUT_FCT(const char * /* a */, ...) { } #define VP_TRACE // To activate trace mode #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // C-like debug printings @@ -440,6 +468,10 @@ inline void vpTRACE(int /* level */, const char * /* a */, ...) { } #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // Printing if VP_DEBUG defined and VP_DEBUG_MODE value >= 2 @@ -463,6 +495,10 @@ inline void vpTRACE(int /* level */, const char * /* a */, ...) { } #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // Printing if VP_DEBUG defined and VP_DEBUG_MODE value >= 2 @@ -484,6 +520,10 @@ inline void vpTRACE(int /* level */, const char * /* a */, ...) { } #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // C++-like debug printings @@ -515,6 +555,10 @@ inline void vpTRACE(int /* level */, const char * /* a */, ...) { } #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // Check the active debug levels diff --git a/modules/core/include/visp3/core/vpDisplay.h b/modules/core/include/visp3/core/vpDisplay.h index 93af8de649..42070b3394 100644 --- a/modules/core/include/visp3/core/vpDisplay.h +++ b/modules/core/include/visp3/core/vpDisplay.h @@ -81,6 +81,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpImage I; // Grey level image @@ -613,6 +617,10 @@ class VISP_EXPORT vpDisplay * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #ifdef VISP_HAVE_DISPLAY diff --git a/modules/core/include/visp3/core/vpForceTwistMatrix.h b/modules/core/include/visp3/core/vpForceTwistMatrix.h index cad70a35d4..c28edbc288 100644 --- a/modules/core/include/visp3/core/vpForceTwistMatrix.h +++ b/modules/core/include/visp3/core/vpForceTwistMatrix.h @@ -78,6 +78,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpTranslationVector stp(0.1, 0.2, 0.3); @@ -116,6 +120,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRotationMatrix sRp( {0, 0, -1, @@ -143,6 +151,10 @@ BEGIN_VISP_NAMESPACE #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // Twist transformation matrix from sensor to probe frame diff --git a/modules/core/include/visp3/core/vpFrameGrabber.h b/modules/core/include/visp3/core/vpFrameGrabber.h index f2d96800d1..09613b2d46 100644 --- a/modules/core/include/visp3/core/vpFrameGrabber.h +++ b/modules/core/include/visp3/core/vpFrameGrabber.h @@ -62,6 +62,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) diff --git a/modules/core/include/visp3/core/vpGaussRand.h b/modules/core/include/visp3/core/vpGaussRand.h index 1c44371d6f..e7e55ecfe2 100644 --- a/modules/core/include/visp3/core/vpGaussRand.h +++ b/modules/core/include/visp3/core/vpGaussRand.h @@ -52,6 +52,10 @@ BEGIN_VISP_NAMESPACE #include #include +#ifdef ENABLE_VISP_NAMESPACE +using namespace VISP_NAMESPACE_NAME; +#endif + int main() { vpGaussRand noise(0.5, 10); @@ -86,6 +90,10 @@ current time. The code becomes: #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpGaussRand noise(0.5, 10); diff --git a/modules/core/include/visp3/core/vpHomogeneousMatrix.h b/modules/core/include/visp3/core/vpHomogeneousMatrix.h index 80e05177d6..992aff7c10 100644 --- a/modules/core/include/visp3/core/vpHomogeneousMatrix.h +++ b/modules/core/include/visp3/core/vpHomogeneousMatrix.h @@ -97,6 +97,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpHomogeneousMatrix M; @@ -125,6 +129,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpTranslationVector t; @@ -141,6 +149,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { { @@ -164,6 +176,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_NLOHMANN_JSON) diff --git a/modules/core/include/visp3/core/vpImage.h b/modules/core/include/visp3/core/vpImage.h index 814599e759..5cedde9c8e 100644 --- a/modules/core/include/visp3/core/vpImage.h +++ b/modules/core/include/visp3/core/vpImage.h @@ -879,6 +879,10 @@ template void vpImage::doubleSizeImage(vpImage &res) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage A(288, 384); diff --git a/modules/core/include/visp3/core/vpImagePoint.h b/modules/core/include/visp3/core/vpImagePoint.h index d9e3c8e58d..bb0207f69d 100644 --- a/modules/core/include/visp3/core/vpImagePoint.h +++ b/modules/core/include/visp3/core/vpImagePoint.h @@ -181,6 +181,10 @@ class VISP_EXPORT vpImagePoint * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpImagePoint start_pixel(10, 12); diff --git a/modules/core/include/visp3/core/vpImageTools.h b/modules/core/include/visp3/core/vpImageTools.h index e4a2ee02f3..fa4b5dac55 100644 --- a/modules/core/include/visp3/core/vpImageTools.h +++ b/modules/core/include/visp3/core/vpImageTools.h @@ -846,6 +846,10 @@ template void vpImageTools::flip(const vpImage &I, vpImage #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage I; diff --git a/modules/core/include/visp3/core/vpImage_operators.h b/modules/core/include/visp3/core/vpImage_operators.h index 7d8d15f6b8..fbddbdd292 100644 --- a/modules/core/include/visp3/core/vpImage_operators.h +++ b/modules/core/include/visp3/core/vpImage_operators.h @@ -249,6 +249,10 @@ template bool vpImage::operator!=(const vpImage &I) con \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage A(288, 384); diff --git a/modules/core/include/visp3/core/vpIoTools.h b/modules/core/include/visp3/core/vpIoTools.h index 6eff355ae4..d44988f20b 100644 --- a/modules/core/include/visp3/core/vpIoTools.h +++ b/modules/core/include/visp3/core/vpIoTools.h @@ -405,6 +405,10 @@ template std::vector create_npy_header(const std::vector * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * std::string username; @@ -460,6 +464,10 @@ template std::vector create_npy_header(const std::vector * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * // reading configuration file diff --git a/modules/core/include/visp3/core/vpLinProg.h b/modules/core/include/visp3/core/vpLinProg.h index d8dd28bf6b..4ef56fe8e1 100644 --- a/modules/core/include/visp3/core/vpLinProg.h +++ b/modules/core/include/visp3/core/vpLinProg.h @@ -81,6 +81,10 @@ class VISP_EXPORT vpLinProg * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpColVector c(3), x; diff --git a/modules/core/include/visp3/core/vpLinearKalmanFilterInstantiation.h b/modules/core/include/visp3/core/vpLinearKalmanFilterInstantiation.h index 584fd9734c..c60cb6fa00 100644 --- a/modules/core/include/visp3/core/vpLinearKalmanFilterInstantiation.h +++ b/modules/core/include/visp3/core/vpLinearKalmanFilterInstantiation.h @@ -124,18 +124,22 @@ class VISP_EXPORT vpLinearKalmanFilterInstantiation : public vpKalmanFilter size of the state and measure vectors. \code -#include + #include -int main() -{ - vpLinearKalmanFilterInstantiation kalman; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - kalman.setStateModel(vpLinearKalmanFilterInstantiation::stateConstVelWithColoredNoise_MeasureVel); - // Value is 2 - std::cout << "State vector size: " << kalman.getStateSize() << std::endl; - // Value is 1 - std::cout << "Measure vector size: " << kalman.getMeasureSize() << std::endl; -} + int main() + { + vpLinearKalmanFilterInstantiation kalman; + + kalman.setStateModel(vpLinearKalmanFilterInstantiation::stateConstVelWithColoredNoise_MeasureVel); + // Value is 2 + std::cout << "State vector size: " << kalman.getStateSize() << std::endl; + // Value is 1 + std::cout << "Measure vector size: " << kalman.getMeasureSize() << std::endl; + } \endcode */ void vpLinearKalmanFilterInstantiation::setStateModel(vpStateModel mdl) diff --git a/modules/core/include/visp3/core/vpMatrix.h b/modules/core/include/visp3/core/vpMatrix.h index 1d216c91d7..bf35979321 100644 --- a/modules/core/include/visp3/core/vpMatrix.h +++ b/modules/core/include/visp3/core/vpMatrix.h @@ -94,6 +94,10 @@ BEGIN_VISP_NAMESPACE \code #include > &) \code + #include \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { std::string filename("matrix.bin"); @@ -822,6 +844,10 @@ class VISP_EXPORT vpMatrix : public vpArray2D \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { std::string filename("matrix.yaml"); @@ -899,6 +925,10 @@ class VISP_EXPORT vpMatrix : public vpArray2D \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { std::string filename("matrix.bin"); @@ -971,6 +1001,10 @@ class VISP_EXPORT vpMatrix : public vpArray2D \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { std::string filename("matrix.yaml"); diff --git a/modules/core/include/visp3/core/vpMomentAlpha.h b/modules/core/include/visp3/core/vpMomentAlpha.h index cf1352963b..024e945862 100644 --- a/modules/core/include/visp3/core/vpMomentAlpha.h +++ b/modules/core/include/visp3/core/vpMomentAlpha.h @@ -89,6 +89,10 @@ BEGIN_VISP_NAMESPACE * //generic function for printing * void print (double i) { std::cout << i << "\t";} * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpPoint p; diff --git a/modules/core/include/visp3/core/vpMomentAreaNormalized.h b/modules/core/include/visp3/core/vpMomentAreaNormalized.h index 189e942d11..1e8fd5e88a 100644 --- a/modules/core/include/visp3/core/vpMomentAreaNormalized.h +++ b/modules/core/include/visp3/core/vpMomentAreaNormalized.h @@ -85,6 +85,10 @@ class vpMomentCentered; * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpPoint p; diff --git a/modules/core/include/visp3/core/vpMomentCInvariant.h b/modules/core/include/visp3/core/vpMomentCInvariant.h index 187aaec733..922f578e68 100644 --- a/modules/core/include/visp3/core/vpMomentCInvariant.h +++ b/modules/core/include/visp3/core/vpMomentCInvariant.h @@ -75,51 +75,54 @@ class vpMomentBasic; The example below shows how to retrieve the \f$C_2\f$ invariant: \code -#include -#include -#include -#include -#include - -int main() -{ - vpPoint p; - std::vector vec_p; - - p.set_x(6); p.set_y(-1); // coordinates in meters in the image plane (vertex 1) - vec_p.push_back(p); - p.set_x(2); p.set_y(3); // coordinates in meters in the image plane (vertex 2) - vec_p.push_back(p); - p.set_x(0); p.set_y(1.2); // coordinates in meters in the image plane (vertex 1) - vec_p.push_back(p); - p.set_x(-7); p.set_y(-4); // coordinates in meters in the image plane (vertex 2) - vec_p.push_back(p); - - vpMomentObject obj(5); // Create an image moment object with 5 as maximum order - obj.setType(vpMomentObject::DISCRETE); // Discrete mode for object - obj.fromVector(vec_p); - - //initialisation with default values - vpMomentCommon db(vpMomentCommon::getSurface(obj),vpMomentCommon::getMu3(obj), - vpMomentCommon::getAlpha(obj),1.); - bool success; - - db.updateAll(obj); // Update AND compute all moments - - //get C-invariant - const vpMomentCInvariant& C - = static_cast(db.get("vpMomentCInvariant",success)); - if(success) - std::cout << C.get(1) << std:: endl; // print C2 invariant - else - std::cout << "vpMomentCInvariant not found." << std::endl; - - return 0; -} -\endcode - -vpMomentCInvariant depends on vpMomentCentered (see vpMomentDatabase and -vpMomentCommon). + #include + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpPoint p; + std::vector vec_p; + + p.set_x(6); p.set_y(-1); // coordinates in meters in the image plane (vertex 1) + vec_p.push_back(p); + p.set_x(2); p.set_y(3); // coordinates in meters in the image plane (vertex 2) + vec_p.push_back(p); + p.set_x(0); p.set_y(1.2); // coordinates in meters in the image plane (vertex 1) + vec_p.push_back(p); + p.set_x(-7); p.set_y(-4); // coordinates in meters in the image plane (vertex 2) + vec_p.push_back(p); + + vpMomentObject obj(5); // Create an image moment object with 5 as maximum order + obj.setType(vpMomentObject::DISCRETE); // Discrete mode for object + obj.fromVector(vec_p); + + //initialisation with default values + vpMomentCommon db(vpMomentCommon::getSurface(obj),vpMomentCommon::getMu3(obj), + vpMomentCommon::getAlpha(obj),1.); + bool success; + + db.updateAll(obj); // Update AND compute all moments + + //get C-invariant + const vpMomentCInvariant& C + = static_cast(db.get("vpMomentCInvariant",success)); + if(success) + std::cout << C.get(1) << std:: endl; // print C2 invariant + else + std::cout << "vpMomentCInvariant not found." << std::endl; + + return 0; + } + \endcode + + vpMomentCInvariant depends on vpMomentCentered (see vpMomentDatabase and vpMomentCommon). */ class VISP_EXPORT vpMomentCInvariant : public vpMoment { diff --git a/modules/core/include/visp3/core/vpMomentDatabase.h b/modules/core/include/visp3/core/vpMomentDatabase.h index 66d0070bf5..88f0041f62 100644 --- a/modules/core/include/visp3/core/vpMomentDatabase.h +++ b/modules/core/include/visp3/core/vpMomentDatabase.h @@ -74,6 +74,10 @@ class vpMomentObject; * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpPoint p; diff --git a/modules/core/include/visp3/core/vpMomentGravityCenter.h b/modules/core/include/visp3/core/vpMomentGravityCenter.h index 37506a7c5d..75ce2b1767 100644 --- a/modules/core/include/visp3/core/vpMomentGravityCenter.h +++ b/modules/core/include/visp3/core/vpMomentGravityCenter.h @@ -64,6 +64,10 @@ class vpMomentObject; * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * // Define the contour of an object by a 5 clockwise vertices on a plane diff --git a/modules/core/include/visp3/core/vpMomentObject.h b/modules/core/include/visp3/core/vpMomentObject.h index 7498212d22..ce94051220 100644 --- a/modules/core/include/visp3/core/vpMomentObject.h +++ b/modules/core/include/visp3/core/vpMomentObject.h @@ -101,116 +101,120 @@ class vpCameraParameters; moments such as the gravity center or the centered moments. \code -#include -#include -#include + #include + #include + #include -int main() -{ - // Define an object as 4 clockwise points on a plane (Z=0) - std::vector vec_p; // vector that contains the 4 points - - vec_p.push_back( vpPoint(-0.2, 0.1, 0.0) ); // values in meters - vec_p.push_back( vpPoint(+0.3, 0.1, 0.0) ); // values in meters - vec_p.push_back( vpPoint(+0.2,-0.1, 0.0) ); // values in meters - vec_p.push_back( vpPoint(-0.2,-0.15, 0.0) ); // values in meters - - // These points are observed by a camera - vpHomogeneousMatrix cMo(0, 0, 1, 0, 0, 0); // We set the camera to be 1m far the object - // ... update cMo from an image processing - - // Apply the perspective projection to update the points coordinates in the camera plane - for (unsigned int i=0; i moment = obj.get(); - std::cout << std::endl << "Basic moment available (from vector of doubles)" << std::endl; - for(unsigned int k=0; k<=obj.getOrder(); k++) { - for(unsigned int l=0; l<(obj.getOrder()+1)-k; l++) { - std::cout << "m" << l << k << "=" << moment[k*(momobj.getOrder()+1)+ l] << "\t"; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + // Define an object as 4 clockwise points on a plane (Z=0) + std::vector vec_p; // vector that contains the 4 points + + vec_p.push_back( vpPoint(-0.2, 0.1, 0.0) ); // values in meters + vec_p.push_back( vpPoint(+0.3, 0.1, 0.0) ); // values in meters + vec_p.push_back( vpPoint(+0.2,-0.1, 0.0) ); // values in meters + vec_p.push_back( vpPoint(-0.2,-0.15, 0.0) ); // values in meters + + // These points are observed by a camera + vpHomogeneousMatrix cMo(0, 0, 1, 0, 0, 0); // We set the camera to be 1m far the object + // ... update cMo from an image processing + + // Apply the perspective projection to update the points coordinates in the camera plane + for (unsigned int i=0; i moment = obj.get(); + std::cout << std::endl << "Basic moment available (from vector of doubles)" << std::endl; + for(unsigned int k=0; k<=obj.getOrder(); k++) { + for(unsigned int l=0; l<(obj.getOrder()+1)-k; l++) { + std::cout << "m" << l << k << "=" << moment[k*(momobj.getOrder()+1)+ l] << "\t"; + } + std::cout< mu_3 = vpMomentCommon::getMu3(obj); // centered moment up to 3rd order - - std::cout << std::endl << "Common moments computed using basic moments:" << std::endl; - std::cout << "Surface: " << m00 << std::endl; - std::cout << "Alpha: " << alpha << std::endl; - std::cout << "Centered moments (mu03, mu12, mu21, mu30): "; - for(unsigned int i=0; i mu_3 = vpMomentCommon::getMu3(obj); // centered moment up to 3rd order + + std::cout << std::endl << "Common moments computed using basic moments:" << std::endl; + std::cout << "Surface: " << m00 << std::endl; + std::cout << "Alpha: " << alpha << std::endl; + std::cout << "Centered moments (mu03, mu12, mu21, mu30): "; + for(unsigned int i=0; i + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMutex mutex; @@ -147,6 +151,10 @@ class VP_DEPRECATED vpMutex \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMutex mutex; diff --git a/modules/core/include/visp3/core/vpPolygon.h b/modules/core/include/visp3/core/vpPolygon.h index 552daf2b69..7ba9df160b 100644 --- a/modules/core/include/visp3/core/vpPolygon.h +++ b/modules/core/include/visp3/core/vpPolygon.h @@ -63,6 +63,10 @@ BEGIN_VISP_NAMESPACE #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { std::vector corners; diff --git a/modules/core/include/visp3/core/vpPoseVector.h b/modules/core/include/visp3/core/vpPoseVector.h index fa61b9dbe8..3823115341 100644 --- a/modules/core/include/visp3/core/vpPoseVector.h +++ b/modules/core/include/visp3/core/vpPoseVector.h @@ -88,6 +88,10 @@ class vpRowVector; \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpPoseVector pose; @@ -117,6 +121,10 @@ class vpRowVector; \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpTranslationVector t; @@ -131,6 +139,10 @@ class vpRowVector; \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpTranslationVector t; @@ -149,6 +161,10 @@ class vpRowVector; \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_NLOHMANN_JSON) diff --git a/modules/core/include/visp3/core/vpRotationMatrix.h b/modules/core/include/visp3/core/vpRotationMatrix.h index f859851b49..86354aa754 100644 --- a/modules/core/include/visp3/core/vpRotationMatrix.h +++ b/modules/core/include/visp3/core/vpRotationMatrix.h @@ -68,6 +68,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRotationMatrix R; @@ -95,6 +99,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRotationMatrix R; @@ -107,6 +115,10 @@ BEGIN_VISP_NAMESPACE \code #include -#include -#include + #include + #include + #include -int main() -{ - vpRxyzVector r; // By default initialized to zero - // Rotation around x set to 45 degres converted in radians - r[0] = vpMath::rad(45); - // Rotation around y set to PI radians - r[1] = M_PI; - // Rotation around z set to 0 radians - r[2] = 0; - - std::cout << "Rxyz rotation vector: " << r << std::endl; - - double rx = r[0]; // Get the value of the angle around x axis - double ry = r[1]; // Get the value of the angle around y axis - double rz = r[2]; // Get the value of the angle around z axis -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRxyzVector r; // By default initialized to zero + // Rotation around x set to 45 degres converted in radians + r[0] = vpMath::rad(45); + // Rotation around y set to PI radians + r[1] = M_PI; + // Rotation around z set to 0 radians + r[2] = 0; + + std::cout << "Rxyz rotation vector: " << r << std::endl; + + double rx = r[0]; // Get the value of the angle around x axis + double ry = r[1]; // Get the value of the angle around y axis + double rz = r[2]; // Get the value of the angle around z axis + } \endcode */ diff --git a/modules/core/include/visp3/core/vpRowVector.h b/modules/core/include/visp3/core/vpRowVector.h index 91865e4bdf..dd19e41809 100644 --- a/modules/core/include/visp3/core/vpRowVector.h +++ b/modules/core/include/visp3/core/vpRowVector.h @@ -70,6 +70,10 @@ class vpColVector; \code #include &) \code + #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRxyzVector rxyz; diff --git a/modules/core/include/visp3/core/vpRzyxVector.h b/modules/core/include/visp3/core/vpRzyxVector.h index 6653d3ca07..f13740e53b 100644 --- a/modules/core/include/visp3/core/vpRzyxVector.h +++ b/modules/core/include/visp3/core/vpRzyxVector.h @@ -147,6 +147,10 @@ class vpThetaUVector; #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRzyxVector rzyx; diff --git a/modules/core/include/visp3/core/vpRzyzVector.h b/modules/core/include/visp3/core/vpRzyzVector.h index 9b14b5bbc1..75adbc9246 100644 --- a/modules/core/include/visp3/core/vpRzyzVector.h +++ b/modules/core/include/visp3/core/vpRzyzVector.h @@ -142,36 +142,40 @@ class vpThetaUVector; from the build rotation matrix. \code -#include -#include -#include + #include + #include + #include -int main() -{ - vpRzyzVector rzyz; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRzyzVector rzyz; - // Initialise the Euler angles - rzyz[0] = vpMath::rad( 45.f); // phi angle in rad/s around z axis - rzyz[1] = vpMath::rad(-30.f); // theta angle in rad/s around y axis - rzyz[2] = vpMath::rad( 90.f); // psi angle in rad/s around z axis + // Initialise the Euler angles + rzyz[0] = vpMath::rad( 45.f); // phi angle in rad/s around z axis + rzyz[1] = vpMath::rad(-30.f); // theta angle in rad/s around y axis + rzyz[2] = vpMath::rad( 90.f); // psi angle in rad/s around z axis - // Construct a rotation matrix from the Euler angles - vpRotationMatrix R(rzyz); + // Construct a rotation matrix from the Euler angles + vpRotationMatrix R(rzyz); - // Extract the Euler angles around z,y,z axis from a rotation matrix - rzyz.build(R); + // Extract the Euler angles around z,y,z axis from a rotation matrix + rzyz.build(R); - // Print the extracted Euler angles. Values are the same than the - // one used for initialization - std::cout << rzyz; + // Print the extracted Euler angles. Values are the same than the + // one used for initialization + std::cout << rzyz; - // Since the rotation vector is 3 values column vector, the - // transpose operation produce a row vector. - vpRowVector rzyz_t = rzyz.t(); + // Since the rotation vector is 3 values column vector, the + // transpose operation produce a row vector. + vpRowVector rzyz_t = rzyz.t(); - // Print the transpose row vector - std::cout << rzyz_t << std::endl; -} + // Print the transpose row vector + std::cout << rzyz_t << std::endl; + } \endcode */ class VISP_EXPORT vpRzyzVector : public vpRotationVector diff --git a/modules/core/include/visp3/core/vpSerial.h b/modules/core/include/visp3/core/vpSerial.h index c961e49ca5..fca5de1a55 100644 --- a/modules/core/include/visp3/core/vpSerial.h +++ b/modules/core/include/visp3/core/vpSerial.h @@ -50,15 +50,19 @@ BEGIN_VISP_NAMESPACE The following example shows how to write a string on port `/dev/ttyUSB0` using the default constructor: \code -#include + #include -int main() -{ -#ifndef WIN32 - vpSerial serial("/dev/ttyUSB0"); - serial.write("Hello world"); -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifndef WIN32 + vpSerial serial("/dev/ttyUSB0"); + serial.write("Hello world"); + #endif + } \endcode \note This class is not implemented on windows-like OS. diff --git a/modules/core/include/visp3/core/vpThetaUVector.h b/modules/core/include/visp3/core/vpThetaUVector.h index 82f86a0b9d..7f7b57c6d6 100644 --- a/modules/core/include/visp3/core/vpThetaUVector.h +++ b/modules/core/include/visp3/core/vpThetaUVector.h @@ -136,6 +136,10 @@ class vpQuaternionVector; #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpThetaUVector tu; diff --git a/modules/core/include/visp3/core/vpTime.h b/modules/core/include/visp3/core/vpTime.h index 9233fa3585..7f3dca6c0e 100644 --- a/modules/core/include/visp3/core/vpTime.h +++ b/modules/core/include/visp3/core/vpTime.h @@ -58,6 +58,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * double t; diff --git a/modules/core/include/visp3/core/vpTranslationVector.h b/modules/core/include/visp3/core/vpTranslationVector.h index e1e2415ff2..cdc88a8c6f 100644 --- a/modules/core/include/visp3/core/vpTranslationVector.h +++ b/modules/core/include/visp3/core/vpTranslationVector.h @@ -94,6 +94,10 @@ class vpMatrix; #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpTranslationVector t; // Translation vector diff --git a/modules/core/include/visp3/core/vpUDPClient.h b/modules/core/include/visp3/core/vpUDPClient.h index 3e4131cdda..f810736137 100644 --- a/modules/core/include/visp3/core/vpUDPClient.h +++ b/modules/core/include/visp3/core/vpUDPClient.h @@ -85,6 +85,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() { * try { * std::string servername = "127.0.0.1"; @@ -131,6 +135,10 @@ BEGIN_VISP_NAMESPACE * vpDataType_t(double dbl, int i) : double_val(dbl), int_val(i) {} * }; * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() { * try { * std::string servername = "127.0.0.1"; diff --git a/modules/core/include/visp3/core/vpUDPServer.h b/modules/core/include/visp3/core/vpUDPServer.h index 76e30eae08..28422415e9 100644 --- a/modules/core/include/visp3/core/vpUDPServer.h +++ b/modules/core/include/visp3/core/vpUDPServer.h @@ -83,112 +83,118 @@ href="https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2 echo message to the client: \code -#include -#include -#include -#include -#include -#include - -int main() { - try { - int port = 50037; - vpUDPServer server(port); - - while (true) { - std::string msg = "", hostInfo = ""; - int res = server.receive(msg, hostInfo, 5000); - if (res) { - std::cout << "Server received: " << msg << " from: " << hostInfo << std::endl; - std::cout << "Reply to the client: Echo: " << msg << std::endl; - - //Get address and port - std::istringstream iss(hostInfo); - std::vector tokens; - std::copy(std::istream_iterator(iss), - std::istream_iterator(), - std::back_inserter(tokens)); - server.send("Echo: " + msg, tokens[1], atoi(tokens[2].c_str())); - } else if (res == 0) { - std::cout << "Receive timeout" << std::endl; - } else { - std::cerr << "Error server.receive()!" << std::endl; + #include + #include + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() { + try { + int port = 50037; + vpUDPServer server(port); + + while (true) { + std::string msg = "", hostInfo = ""; + int res = server.receive(msg, hostInfo, 5000); + if (res) { + std::cout << "Server received: " << msg << " from: " << hostInfo << std::endl; + std::cout << "Reply to the client: Echo: " << msg << std::endl; + + //Get address and port + std::istringstream iss(hostInfo); + std::vector tokens; + std::copy(std::istream_iterator(iss), + std::istream_iterator(), + std::back_inserter(tokens)); + server.send("Echo: " + msg, tokens[1], atoi(tokens[2].c_str())); + } else if (res == 0) { + std::cout << "Receive timeout" << std::endl; + } else { + std::cerr << "Error server.receive()!" << std::endl; + } } - } - return EXIT_SUCCESS; - } catch (const vpException &e) { - std::cerr << "Catch an exception: " << e.what() << std::endl; - return EXIT_FAILURE; + return EXIT_SUCCESS; + } catch (const vpException &e) { + std::cerr << "Catch an exception: " << e.what() << std::endl; + return EXIT_FAILURE; + } } -} \endcode If you want to send a complex data type, you can either send the ASCII -representation or send directly the byte data. In the last case, you should -have to handle that both the server and the client have the same data type -representation. Be careful also with the endianness of the network / host. + representation or send directly the byte data. In the last case, you should + have to handle that both the server and the client have the same data type + representation. Be careful also with the endianness of the network / host. Here an example using a structure of data, assuming that both the server and -the client have the same architecture (probably you should write your own -serialization / deserialization functions for the data you want to send / -receive): + the client have the same architecture (probably you should write your own + serialization / deserialization functions for the data you want to send / + receive): \code -#include -#include -#include -#include -#include -#include -#include - -struct vpDataType_t { - double double_val; - int int_val; - - vpDataType_t() : double_val(0.0), int_val(0) {} - vpDataType_t(double dbl, int i) : double_val(dbl), int_val(i) {} -}; + #include + #include + #include + #include + #include + #include + #include + + struct vpDataType_t { + double double_val; + int int_val; + + vpDataType_t() : double_val(0.0), int_val(0) {} + vpDataType_t(double dbl, int i) : double_val(dbl), int_val(i) {} + }; + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() { + try { + int port = 50037; + vpUDPServer server(port); + + std::string msg = "", hostInfo = ""; + int res = server.receive(msg, hostInfo); + if (res) { + vpDataType_t data_type; + memcpy(&data_type.double_val, msg.c_str(), sizeof(data_type.double_val)); + memcpy(&data_type.int_val, msg.c_str()+sizeof(data_type.double_val), sizeof(data_type.int_val)); + std::cout << "Server received double_val: " << data_type.double_val << " ; int_val: " + << data_type.int_val << " from: " << hostInfo << std::endl; -int main() { - try { - int port = 50037; - vpUDPServer server(port); - - std::string msg = "", hostInfo = ""; - int res = server.receive(msg, hostInfo); - if (res) { - vpDataType_t data_type; - memcpy(&data_type.double_val, msg.c_str(), -sizeof(data_type.double_val)); memcpy(&data_type.int_val, -msg.c_str()+sizeof(data_type.double_val), sizeof(data_type.int_val)); - std::cout << "Server received double_val: " << data_type.double_val << " -; int_val: " << data_type.int_val << " from: " << hostInfo << std::endl; - - //Get address and port - std::istringstream iss(hostInfo); - std::vector tokens; - std::copy(std::istream_iterator(iss), - std::istream_iterator(), - std::back_inserter(tokens)); - data_type.double_val += 1.5; - data_type.int_val += 2; - char data[sizeof(data_type.double_val)+sizeof(data_type.int_val)]; - memcpy(data, &data_type.double_val, sizeof(data_type.double_val)); - memcpy(data+sizeof(data_type.double_val), &data_type.int_val, -sizeof(data_type.int_val)); msg = std::string(data, -sizeof(data_type.double_val)+sizeof(data_type.int_val)); - - server.send(msg, tokens[1], atoi(tokens[2].c_str())); - } + // Get address and port + std::istringstream iss(hostInfo); + std::vector tokens; + std::copy(std::istream_iterator(iss), + std::istream_iterator(), + std::back_inserter(tokens)); + data_type.double_val += 1.5; + data_type.int_val += 2; + char data[sizeof(data_type.double_val)+sizeof(data_type.int_val)]; + memcpy(data, &data_type.double_val, sizeof(data_type.double_val)); + memcpy(data+sizeof(data_type.double_val), &data_type.int_val, sizeof(data_type.int_val)); + msg = std::string(data, sizeof(data_type.double_val)+sizeof(data_type.int_val)); + + server.send(msg, tokens[1], atoi(tokens[2].c_str())); + } - return EXIT_SUCCESS; - } catch (const vpException &e) { - std::cerr << "Catch an exception: " << e.what() << std::endl; - return EXIT_FAILURE; + return EXIT_SUCCESS; + } catch (const vpException &e) { + std::cerr << "Catch an exception: " << e.what() << std::endl; + return EXIT_FAILURE; + } } -} \endcode \sa vpUDPServer diff --git a/modules/core/include/visp3/core/vpVelocityTwistMatrix.h b/modules/core/include/visp3/core/vpVelocityTwistMatrix.h index 2be04f2bfb..f37666ca6a 100644 --- a/modules/core/include/visp3/core/vpVelocityTwistMatrix.h +++ b/modules/core/include/visp3/core/vpVelocityTwistMatrix.h @@ -70,28 +70,32 @@ class vpMatrix; There are different ways to initialize such a full velocity twist matrix. The following example shows how to proceed setting the translation and rotation matrix transformations: \code -#include + #include -int main() -{ - vpTranslationVector cte(0.1, 0.2, 0.3); - vpRotationMatrix cRe( {0, 0, -1, - 0, -1, 0, - -1, 0, 0} ); - - vpVelocityTwistMatrix cVe(cte, cRe); - std::cout << "cVe:\n" << cVe << std::endl; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpTranslationVector cte(0.1, 0.2, 0.3); + vpRotationMatrix cRe( {0, 0, -1, + 0, -1, 0, + -1, 0, 0} ); + + vpVelocityTwistMatrix cVe(cte, cRe); + std::cout << "cVe:\n" << cVe << std::endl; + } \endcode It produces the following printings: \code -cVe: -0 0 -1 -0.2 0.3 0 -0 -1 0 0.1 0 -0.3 --1 0 0 0 -0.1 0.2 -0 0 0 0 0 -1 -0 0 0 0 -1 0 -0 0 0 -1 0 0 + cVe: + 0 0 -1 -0.2 0.3 0 + 0 -1 0 0.1 0 -0.3 + -1 0 0 0 -0.1 0.2 + 0 0 0 0 0 -1 + 0 0 0 0 -1 0 + 0 0 0 -1 0 0 \endcode When the point where the velocity is expressed doesn't change, the matrix @@ -109,27 +113,31 @@ int main() To initialize such a velocity twist matrix where translation is not taken into account you can proceed like in the following code: \code -#include + #include -int main() -{ - vpRotationMatrix cRe( {0, 0, -1, - 0, -1, 0, - -1, 0, 0} ); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRotationMatrix cRe( {0, 0, -1, + 0, -1, 0, + -1, 0, 0} ); - vpVelocityTwistMatrix cVe(cRe); - std::cout << "cVe:\n" << cVe << std::endl; -} + vpVelocityTwistMatrix cVe(cRe); + std::cout << "cVe:\n" << cVe << std::endl; + } \endcode It produces the following printings: \code -cVe: -0 0 -1 0 0 0 -0 -1 0 0 0 0 --1 0 0 0 0 0 -0 0 0 0 0 -1 -0 0 0 0 -1 0 -0 0 0 -1 0 0 + cVe: + 0 0 -1 0 0 0 + 0 -1 0 0 0 0 + -1 0 0 0 0 0 + 0 0 0 0 0 -1 + 0 0 0 0 -1 0 + 0 0 0 -1 0 0 \endcode The code below shows how to convert a velocity skew @@ -137,26 +145,30 @@ int main() using the full velocity twist matrix. \code -#include -#include + #include + #include -int main() -{ - vpVelocityTwistMatrix fVc; // Twist transformation matrix from fix to camera frame + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpHomogeneousMatrix fMc; // Fix to camera frame transformation - // ... fMc need here to be initialized + int main() + { + vpVelocityTwistMatrix fVc; // Twist transformation matrix from fix to camera frame + + vpHomogeneousMatrix fMc; // Fix to camera frame transformation + // ... fMc need here to be initialized - fVc.build(fMc); + fVc.build(fMc); - vpColVector c_v(6); // Velocity in the camera frame: vx,vy,vz,wx,wy,wz - // ... c_v should here have an initial value + vpColVector c_v(6); // Velocity in the camera frame: vx,vy,vz,wx,wy,wz + // ... c_v should here have an initial value - vpColVector f_v(6); // Velocity in the fix frame: vx,vy,vz,wx,wy,wz + vpColVector f_v(6); // Velocity in the fix frame: vx,vy,vz,wx,wy,wz - // Compute the velocity in the fix frame - f_v = fVc * c_v; -} + // Compute the velocity in the fix frame + f_v = fVc * c_v; + } \endcode */ class VISP_EXPORT vpVelocityTwistMatrix : public vpArray2D diff --git a/modules/core/include/visp3/core/vpXmlParserCamera.h b/modules/core/include/visp3/core/vpXmlParserCamera.h index 5dcca2a084..cd3f273df1 100644 --- a/modules/core/include/visp3/core/vpXmlParserCamera.h +++ b/modules/core/include/visp3/core/vpXmlParserCamera.h @@ -90,74 +90,82 @@ BEGIN_VISP_NAMESPACE Example of loading existing camera parameters from an XML file: \code -#include -#include - -int main() -{ - vpCameraParameters cam; // Create a camera parameter container - vpXmlParserCamera p; // Create a XML parser - vpCameraParameters::vpCameraParametersProjType projModel; // Projection model - // Use a perspective projection model without distortion - projModel = vpCameraParameters::perspectiveProjWithoutDistortion; - // Parse the xml file "myXmlFile.xml" to find the intrinsic camera - // parameters of the camera named "myCamera" for the image sizes 640x480, - // for the projection model projModel. The size of the image is optional - // if camera parameters are given only for one image size. - if (p.parse(cam, "myXmlFile.xml", "myCamera", projModel,640,480) != vpXmlParserCamera::SEQUENCE_OK) { - std::cout << "Cannot found myCamera" << std::endl; + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpCameraParameters cam; // Create a camera parameter container + vpXmlParserCamera p; // Create a XML parser + vpCameraParameters::vpCameraParametersProjType projModel; // Projection model + // Use a perspective projection model without distortion + projModel = vpCameraParameters::perspectiveProjWithoutDistortion; + // Parse the xml file "myXmlFile.xml" to find the intrinsic camera + // parameters of the camera named "myCamera" for the image sizes 640x480, + // for the projection model projModel. The size of the image is optional + // if camera parameters are given only for one image size. + if (p.parse(cam, "myXmlFile.xml", "myCamera", projModel,640,480) != vpXmlParserCamera::SEQUENCE_OK) { + std::cout << "Cannot found myCamera" << std::endl; + } + + // cout the parameters + cam.printParameters(); + + // Get the camera parameters for the model without distortion + double px = cam.get_px(); + double py = cam.get_py(); + double u0 = cam.get_u0(); + double v0 = cam.get_v0(); + + // Now we modify the principal point (u0,v0) for example to add noise + u0 *= 0.9; + v0 *= 0.8; + + // Set the new camera parameters + cam.initPersProjWithoutDistortion(px, py, u0, v0); + + // Save the parameters in a new file "myXmlFileWithNoise.xml" + p.save(cam,"myXmlFileWithNoise.xml",p.getCameraName(),p.getWidth(),p.getHeight()); } - - // cout the parameters - cam.printParameters(); - - // Get the camera parameters for the model without distortion - double px = cam.get_px(); - double py = cam.get_py(); - double u0 = cam.get_u0(); - double v0 = cam.get_v0(); - - // Now we modify the principal point (u0,v0) for example to add noise - u0 *= 0.9; - v0 *= 0.8; - - // Set the new camera parameters - cam.initPersProjWithoutDistortion(px, py, u0, v0); - - // Save the parameters in a new file "myXmlFileWithNoise.xml" - p.save(cam,"myXmlFileWithNoise.xml",p.getCameraName(),p.getWidth(),p.getHeight()); -} \endcode Example of writing an XML file containing intrinsic camera parameters: \code -#include -#include - -int main() -{ - // Create a camera parameter container. We want to set these parameters - // for a 320x240 image, and we want to use the perspective projection - // modelization without distortion. - vpCameraParameters cam; - - // Set the principal point coordinates (u0,v0) - double u0 = 162.3; - double v0 = 122.4; - // Set the pixel ratio (px, py) - double px = 563.2; - double py = 564.1; - - // Set the camera parameters for a model without distortion - cam.initPersProjWithoutDistortion(px, py, u0, v0); - - // Create a XML parser - vpXmlParserCamera p; - // Save the camera parameters in an XML file. - if (p.save(cam, "myNewXmlFile.xml", "myNewCamera", 320, 240) != vpXmlParserCamera::SEQUENCE_OK) { - std::cout << "Cannot save camera parameters" << std::endl; + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + // Create a camera parameter container. We want to set these parameters + // for a 320x240 image, and we want to use the perspective projection + // modelization without distortion. + vpCameraParameters cam; + + // Set the principal point coordinates (u0,v0) + double u0 = 162.3; + double v0 = 122.4; + // Set the pixel ratio (px, py) + double px = 563.2; + double py = 564.1; + + // Set the camera parameters for a model without distortion + cam.initPersProjWithoutDistortion(px, py, u0, v0); + + // Create a XML parser + vpXmlParserCamera p; + // Save the camera parameters in an XML file. + if (p.save(cam, "myNewXmlFile.xml", "myNewCamera", 320, 240) != vpXmlParserCamera::SEQUENCE_OK) { + std::cout << "Cannot save camera parameters" << std::endl; + } } -} \endcode */ diff --git a/modules/core/include/visp3/core/vpXmlParserRectOriented.h b/modules/core/include/visp3/core/vpXmlParserRectOriented.h index 2ab2f329f4..7e423f045e 100644 --- a/modules/core/include/visp3/core/vpXmlParserRectOriented.h +++ b/modules/core/include/visp3/core/vpXmlParserRectOriented.h @@ -55,31 +55,41 @@ BEGIN_VISP_NAMESPACE The following example shows how to save an oriented rectangle in an xml file: \code -#include -#include -int main() -{ - vpRectOriented rect(vpImagePoint(10, 15), 20, 12, 0.25); - vpXmlParserRectOriented parser; - parser.setRectangle(rect); - std::string filename = "myRectangle.xml"; - parser.save(filename); - return 0; -} + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRectOriented rect(vpImagePoint(10, 15), 20, 12, 0.25); + vpXmlParserRectOriented parser; + parser.setRectangle(rect); + std::string filename = "myRectangle.xml"; + parser.save(filename); + return 0; + } \endcode The following example shows how to read an oriented rectangle from an xml file: \code -#include -#include -int main() -{ - vpXmlParserRectOriented parser; - std::string filename = "myRectangle.xml"; - parser.parse(filename); - vpRectOriented rect = parser.getRectangle(); - return 0; -} + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpXmlParserRectOriented parser; + std::string filename = "myRectangle.xml"; + parser.parse(filename); + vpRectOriented rect = parser.getRectangle(); + return 0; + } \endcode \warning This class is only available if pugixml third-party is successfully diff --git a/modules/core/src/camera/vpCameraParameters.cpp b/modules/core/src/camera/vpCameraParameters.cpp index d3ab550f0b..b937cdc501 100644 --- a/modules/core/src/camera/vpCameraParameters.cpp +++ b/modules/core/src/camera/vpCameraParameters.cpp @@ -170,6 +170,10 @@ void vpCameraParameters::init() * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpImage I(480, 640); @@ -234,6 +238,10 @@ void vpCameraParameters::initPersProjWithoutDistortion(double cam_px, double cam * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpImage I(480, 640); @@ -372,6 +380,10 @@ void vpCameraParameters::initFromCalibrationMatrix(const vpMatrix &K) * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpImage I(480, 640); diff --git a/modules/core/src/camera/vpXmlParserCamera.cpp b/modules/core/src/camera/vpXmlParserCamera.cpp index 19d2a5241d..b8d0b8751b 100644 --- a/modules/core/src/camera/vpXmlParserCamera.cpp +++ b/modules/core/src/camera/vpXmlParserCamera.cpp @@ -1219,20 +1219,24 @@ int vpXmlParserCamera::parse(vpCameraParameters &cam, const std::string &filenam A typical usage would be the following: \code -#include -#include + #include + #include -int main() -{ - vpCameraParameters cam; - std::stringstream ss_additional_info; - ss_additional_info << "" << vpTime::getDateTime() << ""; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpCameraParameters cam; + std::stringstream ss_additional_info; + ss_additional_info << "" << vpTime::getDateTime() << ""; - vpXmlParserCamera p; - if (p.save(cam, "camera.xml", "myCamera", 320, 240, ss_additional_info.str()) != vpXmlParserCamera::SEQUENCE_OK) { - std::cout << "Cannot save camera parameters" << std::endl; + vpXmlParserCamera p; + if (p.save(cam, "camera.xml", "myCamera", 320, 240, ss_additional_info.str()) != vpXmlParserCamera::SEQUENCE_OK) { + std::cout << "Cannot save camera parameters" << std::endl; + } } -} \endcode In \c camera.xml file, you will see: \code diff --git a/modules/core/src/display/vpDisplay.cpp b/modules/core/src/display/vpDisplay.cpp index 90c61eda7b..f2dd3a29bd 100644 --- a/modules/core/src/display/vpDisplay.cpp +++ b/modules/core/src/display/vpDisplay.cpp @@ -73,64 +73,68 @@ vpDisplay::~vpDisplay() { m_displayHasBeenInitialized = false; } The code below shows how to use this method. \code -#include -#include -#include -#include -#include -#include -#include - -int main() -{ - vpImage I(240, 320); // Create a black grey level image - vpImage Ioverlay; - - vpDisplay *d; - - // Depending on the detected third party libraries, we instantiate here the - // first video device which is available -#if defined(VISP_HAVE_X11) - d = new vpDisplayX; -#elif defined(VISP_HAVE_GTK) - d = new vpDisplayGTK; -#elif defined(VISP_HAVE_GDI) - d = new vpDisplayGDI; -#elif defined(VISP_HAVE_D3D9) - d = new vpDisplayD3D; -#elif defined(HAVE_OPENCV_HIGHGUI) - d = new vpDisplayOpenCV; -#endif - - // Initialize the display with the image I. Display and image are - // now link together. -#ifdef VISP_HAVE_DISPLAY - d->init(I); -#endif - - // Set the display background with image I content - vpDisplay::display(I); - - // Draw a red rectangle in the display overlay (foreground) - vpDisplay::displayRectangle(I, 10, 10, 100, 20, vpColor::red, true); - - // Flush the foreground and background display - vpDisplay::flush(I); - - // Updates the color image with the original loaded image and the overlay - vpDisplay::getImage(I, Ioverlay); - - // Write the color image on the disk - std::string ofilename("overlay.ppm"); - vpImageIo::write(Ioverlay, ofilename); - - // Wait for a click in the display window - vpDisplay::getClick(I); - -#ifdef VISP_HAVE_DISPLAY - delete d; -#endif -} + #include + #include + #include + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I(240, 320); // Create a black grey level image + vpImage Ioverlay; + + vpDisplay *d; + + // Depending on the detected third party libraries, we instantiate here the + // first video device which is available + #if defined(VISP_HAVE_X11) + d = new vpDisplayX; + #elif defined(VISP_HAVE_GTK) + d = new vpDisplayGTK; + #elif defined(VISP_HAVE_GDI) + d = new vpDisplayGDI; + #elif defined(VISP_HAVE_D3D9) + d = new vpDisplayD3D; + #elif defined(HAVE_OPENCV_HIGHGUI) + d = new vpDisplayOpenCV; + #endif + + // Initialize the display with the image I. Display and image are + // now link together. + #ifdef VISP_HAVE_DISPLAY + d->init(I); + #endif + + // Set the display background with image I content + vpDisplay::display(I); + + // Draw a red rectangle in the display overlay (foreground) + vpDisplay::displayRectangle(I, 10, 10, 100, 20, vpColor::red, true); + + // Flush the foreground and background display + vpDisplay::flush(I); + + // Updates the color image with the original loaded image and the overlay + vpDisplay::getImage(I, Ioverlay); + + // Write the color image on the disk + std::string ofilename("overlay.ppm"); + vpImageIo::write(Ioverlay, ofilename); + + // Wait for a click in the display window + vpDisplay::getClick(I); + + #ifdef VISP_HAVE_DISPLAY + delete d; + #endif + } \endcode */ void vpDisplay::getImage(const vpImage &Isrc, vpImage &Idest) @@ -148,63 +152,67 @@ void vpDisplay::getImage(const vpImage &Isrc, vpImage &Id The code below shows how to use this method. \code -#include -#include -#include -#include -#include -#include - -int main() -{ - vpImage I(240, 320); // Create a black RGB color image - vpImage Ioverlay; - - vpDisplay *d; - - // Depending on the detected third party libraries, we instantiate here the - // first video device which is available -#if defined(VISP_HAVE_X11) - d = new vpDisplayX; -#elif defined(VISP_HAVE_GTK) - d = new vpDisplayGTK; -#elif defined(VISP_HAVE_GDI) - d = new vpDisplayGDI; -#elif defined(VISP_HAVE_D3D9) - d = new vpDisplayD3D; -#elif defined(HAVE_OPENCV_HIGHGUI) - d = new vpDisplayOpenCV; -#endif - - // Initialize the display with the image I. Display and image are - // now link together. -#ifdef VISP_HAVE_DISPLAY - d->init(I); -#endif - - // Set the display background with image I content - vpDisplay::display(I); - - // Draw a red rectangle in the display overlay (foreground) - vpDisplay::displayRectangle(I, 10, 10, 100, 20, vpColor::red, true); - - // Flush the foreground and background display - vpDisplay::flush(I); - - // Updates the color image with the original loaded image and the overlay - vpDisplay::getImage(I, Ioverlay); - - // Write the color image on the disk - std::string ofilename("overlay.ppm"); - vpImageIo::write(Ioverlay, ofilename); - - // Wait for a click in the display window - vpDisplay::getClick(I); - -#ifdef VISP_HAVE_DISPLAY - delete d; -#endif -} + #include + #include + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I(240, 320); // Create a black RGB color image + vpImage Ioverlay; + + vpDisplay *d; + + // Depending on the detected third party libraries, we instantiate here the + // first video device which is available + #if defined(VISP_HAVE_X11) + d = new vpDisplayX; + #elif defined(VISP_HAVE_GTK) + d = new vpDisplayGTK; + #elif defined(VISP_HAVE_GDI) + d = new vpDisplayGDI; + #elif defined(VISP_HAVE_D3D9) + d = new vpDisplayD3D; + #elif defined(HAVE_OPENCV_HIGHGUI) + d = new vpDisplayOpenCV; + #endif + + // Initialize the display with the image I. Display and image are + // now link together. + #ifdef VISP_HAVE_DISPLAY + d->init(I); + #endif + + // Set the display background with image I content + vpDisplay::display(I); + + // Draw a red rectangle in the display overlay (foreground) + vpDisplay::displayRectangle(I, 10, 10, 100, 20, vpColor::red, true); + + // Flush the foreground and background display + vpDisplay::flush(I); + + // Updates the color image with the original loaded image and the overlay + vpDisplay::getImage(I, Ioverlay); + + // Write the color image on the disk + std::string ofilename("overlay.ppm"); + vpImageIo::write(Ioverlay, ofilename); + + // Wait for a click in the display window + vpDisplay::getClick(I); + + #ifdef VISP_HAVE_DISPLAY + delete d; + #endif + } \endcode */ void vpDisplay::getImage(const vpImage &Isrc, vpImage &Idest) @@ -300,24 +308,28 @@ void vpDisplay::setScale(vpScaleType scaleType, unsigned int width, unsigned int This method has to be called before display initialization. \code -#include -#include + #include + #include -int main() -{ - vpImage I(480, 640); // Black 640 by 480 image -#ifdef VISP_HAVE_X11 - vpDisplayX d; -#elif defined(VISP_HAVE_GDI) - vpDisplayGDI d; -#endif - // Display in a 160 by 120 windows size - d.setDownScalingFactor(vpDisplay::SCALE_4); - d.init(I); - vpDisplay::display(I); - vpDisplay::flush(I); - vpDisplay::getClick(I); // wait for a click to quit -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I(480, 640); // Black 640 by 480 image + #ifdef VISP_HAVE_X11 + vpDisplayX d; + #elif defined(VISP_HAVE_GDI) + vpDisplayGDI d; + #endif + // Display in a 160 by 120 windows size + d.setDownScalingFactor(vpDisplay::SCALE_4); + d.init(I); + vpDisplay::display(I); + vpDisplay::flush(I); + vpDisplay::getClick(I); // wait for a click to quit + } \endcode */ void vpDisplay::setDownScalingFactor(vpScaleType scaleType) diff --git a/modules/core/src/display/vpDisplay_rgba.cpp b/modules/core/src/display/vpDisplay_rgba.cpp index 84af8b05d4..c28d2ea6ea 100644 --- a/modules/core/src/display/vpDisplay_rgba.cpp +++ b/modules/core/src/display/vpDisplay_rgba.cpp @@ -776,23 +776,27 @@ void vpDisplay::displayText(const vpImage &I, int i, int j, const std::s to show the overlay. Because it's time spending, use it parcimoniously. \code -#include -#include -#include -#include -#include - -int main() { - vpImage I(240, 380); - vpDisplayGDI d; - d.init(I); - vpDisplay::display(I); // display the image - vpImagePoint center; - unsigned int radius = 100; - vpDisplay::displayCircle(I, center, radius, vpColor::red); - - vpDisplay::flush(I); // Mandatory to display the requested features. -} + #include + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() { + vpImage I(240, 380); + vpDisplayGDI d; + d.init(I); + vpDisplay::display(I); // display the image + vpImagePoint center; + unsigned int radius = 100; + vpDisplay::displayCircle(I, center, radius, vpColor::red); + + vpDisplay::flush(I); // Mandatory to display the requested features. + } \endcode \sa flushROI() @@ -993,6 +997,10 @@ bool vpDisplay::getClickUp(const vpImage &I, vpMouseButton::vpMouseButto #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage I(240, 320); // Create a black image @@ -1082,6 +1090,10 @@ bool vpDisplay::getKeyboardEvent(const vpImage &I, bool blocking) #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage I(240, 320); // Create a black image @@ -1173,6 +1185,10 @@ bool vpDisplay::getKeyboardEvent(const vpImage &I, std::string &key, boo #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage I(240, 320); // Create a black image diff --git a/modules/core/src/display/vpDisplay_uchar.cpp b/modules/core/src/display/vpDisplay_uchar.cpp index bcef5006bc..092ecc53b6 100644 --- a/modules/core/src/display/vpDisplay_uchar.cpp +++ b/modules/core/src/display/vpDisplay_uchar.cpp @@ -776,23 +776,27 @@ void vpDisplay::displayText(const vpImage &I, int i, int j, const to show the overlay. Because it's time spending, use it parcimoniously. \code -#include -#include -#include -#include -#include - -int main() { - vpImage I(240, 380); - vpDisplayGDI d; - d.init(I); - vpDisplay::display(I); // display the image - vpImagePoint center; - unsigned int radius = 100; - vpDisplay::displayCircle(I, center, radius, vpColor::red); - - vpDisplay::flush(I); // Mandatory to display the requested features. -} + #include + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() { + vpImage I(240, 380); + vpDisplayGDI d; + d.init(I); + vpDisplay::display(I); // display the image + vpImagePoint center; + unsigned int radius = 100; + vpDisplay::displayCircle(I, center, radius, vpColor::red); + + vpDisplay::flush(I); // Mandatory to display the requested features. + } \endcode \sa flushROI() @@ -993,6 +997,10 @@ bool vpDisplay::getClickUp(const vpImage &I, vpMouseButton::vpMou #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage I(240, 320); // Create a black image @@ -1083,6 +1091,10 @@ bool vpDisplay::getKeyboardEvent(const vpImage &I, bool blocking) #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage I(240, 320); // Create a black image @@ -1174,6 +1186,10 @@ bool vpDisplay::getKeyboardEvent(const vpImage &I, std::string &k #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage I(240, 320); // Create a black image diff --git a/modules/core/src/image/vpImageConvert.cpp b/modules/core/src/image/vpImageConvert.cpp index 7965426978..4886152dbe 100644 --- a/modules/core/src/image/vpImageConvert.cpp +++ b/modules/core/src/image/vpImageConvert.cpp @@ -1124,6 +1124,10 @@ void vpImageConvert::YCrCbToRGBa(unsigned char *ycrcb, unsigned char *rgba, unsi #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage Ic; // A color image diff --git a/modules/core/src/image/vpImageConvert_opencv.cpp b/modules/core/src/image/vpImageConvert_opencv.cpp index b748465ae6..12b7eda56f 100644 --- a/modules/core/src/image/vpImageConvert_opencv.cpp +++ b/modules/core/src/image/vpImageConvert_opencv.cpp @@ -70,6 +70,10 @@ BEGIN_VISP_NAMESPACE #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_OPENCV) @@ -186,6 +190,10 @@ void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool fli #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_OPENCV) @@ -414,6 +422,10 @@ void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool fli #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_OPENCV) @@ -458,6 +470,10 @@ void vpImageConvert::convert(const vpImage &src, cv::Mat &dest) #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_IMGCODECS) diff --git a/modules/core/src/image/vpImageConvert_yarp.cpp b/modules/core/src/image/vpImageConvert_yarp.cpp index 9128374a5d..030abf62e7 100644 --- a/modules/core/src/image/vpImageConvert_yarp.cpp +++ b/modules/core/src/image/vpImageConvert_yarp.cpp @@ -58,6 +58,10 @@ BEGIN_VISP_NAMESPACE #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_YARP) @@ -108,6 +112,10 @@ void vpImageConvert::convert(const vpImage &src, yarp::sig::Image #include #endif + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_YARP) @@ -154,6 +162,10 @@ void vpImageConvert::convert(const yarp::sig::ImageOf *src #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_YARP) @@ -203,6 +215,10 @@ void vpImageConvert::convert(const vpImage &src, yarp::sig::ImageOf #endif + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_YARP) @@ -245,6 +261,10 @@ void vpImageConvert::convert(const yarp::sig::ImageOf *src #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_YARP) @@ -296,6 +316,10 @@ void vpImageConvert::convert(const vpImage &src, yarp::sig::ImageOf #endif + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_YARP) diff --git a/modules/core/src/image/vpImageFilter_canny.cpp b/modules/core/src/image/vpImageFilter_canny.cpp index f98930a072..09d9fd6595 100644 --- a/modules/core/src/image/vpImageFilter_canny.cpp +++ b/modules/core/src/image/vpImageFilter_canny.cpp @@ -260,6 +260,10 @@ float vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // Constants for the Canny operator. @@ -306,6 +310,10 @@ void vpImageFilter::canny(const vpImage &Isrc, vpImage #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // Constants for the Canny operator. @@ -367,6 +375,10 @@ void vpImageFilter::canny(const vpImage &Isrc, vpImage * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * // Constants for the Canny operator. diff --git a/modules/core/src/image/vpImagePoint.cpp b/modules/core/src/image/vpImagePoint.cpp index 2eb70923e1..fbe1ab21f9 100644 --- a/modules/core/src/image/vpImagePoint.cpp +++ b/modules/core/src/image/vpImagePoint.cpp @@ -57,27 +57,30 @@ bool vpImagePoint::inRectangle(const vpRect &rect) const /*! Operator +=. - This operator can be used to compute the center of gravity of a set of image -points. + This operator can be used to compute the center of gravity of a set of image points. \code -#include -#include -#include - -int main() -{ - std::vector ip(2); - - ip[0].set_ij(100, 200); - ip[1].set_ij(300, 400); - - vpImagePoint cog(0,0); - for(unsigned int i=0; i + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + std::vector ip(2); + + ip[0].set_ij(100, 200); + ip[1].set_ij(300, 400); + + vpImagePoint cog(0,0); + for(unsigned int i=0; i -#include -#include - -int main() -{ - std::vector ip(2); - - ip[0].set_ij(100, 200); - ip[1].set_ij(300, 400); - - vpImagePoint cog(0,0); - for(unsigned int i=0; i + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + std::vector ip(2); + + ip[0].set_ij(100, 200); + ip[1].set_ij(300, 400); + + vpImagePoint cog(0,0); + for(unsigned int i=0; i -#include + #include + #include -int main() -{ - vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 - std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) - std::cout << "ip+10: " << ip+10 << std::endl; // new coordinates (110, 210) + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - return 0; -} + int main() + { + vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 + std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) + std::cout << "ip+10: " << ip+10 << std::endl; // new coordinates (110, 210) + + return 0; + } \endcode */ VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, int offset) @@ -206,17 +216,21 @@ VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, int offset) Returns a vpImagePoint with an offset added to the two coordinates. \code -#include -#include + #include + #include -int main() -{ - vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 - std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) - std::cout << "ip+10u: " << ip+10u << std::endl; // new coordinates (110, 210) + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - return 0; -} + int main() + { + vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 + std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) + std::cout << "ip+10u: " << ip+10u << std::endl; // new coordinates (110, 210) + + return 0; + } \endcode */ VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, unsigned int offset) @@ -230,17 +244,21 @@ VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, unsigned int offset) Returns a vpImagePoint with an offset added to the two coordinates. \code -#include -#include + #include + #include -int main() -{ - vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 - std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) - std::cout << "ip+12.34: " << ip+12.34 << std::endl; // new coordinates (112.34, 212.34) + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - return 0; -} + int main() + { + vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 + std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) + std::cout << "ip+12.34: " << ip+12.34 << std::endl; // new coordinates (112.34, 212.34) + + return 0; + } \endcode */ VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, double offset) @@ -265,17 +283,21 @@ VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint & Returns a vpImagePoint with an offset subtracted to the two coordinates. \code -#include -#include + #include + #include -int main() -{ - vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 - std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) - std::cout << "ip-10: " << ip-10 << std::endl; // new coordinates (90, 190) + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - return 0; -} + int main() + { + vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 + std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) + std::cout << "ip-10: " << ip-10 << std::endl; // new coordinates (90, 190) + + return 0; + } \endcode */ VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, int offset) @@ -289,17 +311,21 @@ VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, int offset) Returns a vpImagePoint with an offset subtracted to the two coordinates. \code -#include -#include + #include + #include -int main() -{ - vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 - std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) - std::cout << "ip-10u: " << ip-10u << std::endl; // new coordinates (90, 190) + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - return 0; -} + int main() + { + vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 + std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) + std::cout << "ip-10u: " << ip-10u << std::endl; // new coordinates (90, 190) + + return 0; + } \endcode */ VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, unsigned int offset) @@ -313,17 +339,21 @@ VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, unsigned int offset) Returns a vpImagePoint with an offset subtracted to the two coordinates. \code -#include -#include + #include + #include -int main() -{ - vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 - std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) - std::cout << "ip-12.34: " << ip-12.34 << std::endl; // new coordinates (87.66, 187.66) + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - return 0; -} + int main() + { + vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 + std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) + std::cout << "ip-12.34: " << ip-12.34 << std::endl; // new coordinates (87.66, 187.66) + + return 0; + } \endcode */ VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, double offset) @@ -337,17 +367,21 @@ VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, double offset) Returns a vpImagePoint with coordinates multiplied by a scale factor. \code -#include -#include + #include + #include -int main() -{ - vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 - std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) - std::cout << "ip*2: " << ip*2 << std::endl; // new coordinates (200, 400) + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - return 0; -} + int main() + { + vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 + std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) + std::cout << "ip*2: " << ip*2 << std::endl; // new coordinates (200, 400) + + return 0; + } \endcode */ VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, double scale) @@ -361,17 +395,21 @@ VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, double scale) Returns a vpImagePoint with coordinates divided by a scale factor. \code -#include -#include + #include + #include -int main() -{ - vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 - std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) - std::cout << "ip/2: " << ip/2 << std::endl; // new coordinates (50, 100) + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - return 0; -} + int main() + { + vpImagePoint ip(100, 200); // Create an image point with coordinates i=100, j=200 + std::cout << "ip: " << ip << std::endl; // coordinates (100, 200) + std::cout << "ip/2: " << ip/2 << std::endl; // new coordinates (50, 100) + + return 0; + } \endcode */ VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, double scale) @@ -389,20 +427,25 @@ VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, double scale) The following code \code -#include + #include -#include -int main() -{ - vpImagePoint ip; + #include - ip.set_i(10); - ip.set_j(11.1); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - std::cout << "Image point with coordinates: " << ip << std::endl; + int main() + { + vpImagePoint ip; - return 0; -} + ip.set_i(10); + ip.set_j(11.1); + + std::cout << "Image point with coordinates: " << ip << std::endl; + + return 0; + } \endcode produces the output: diff --git a/modules/core/src/image/vpImageTools.cpp b/modules/core/src/image/vpImageTools.cpp index 1a8aeca42e..cb495deea5 100644 --- a/modules/core/src/image/vpImageTools.cpp +++ b/modules/core/src/image/vpImageTools.cpp @@ -71,29 +71,33 @@ BEGIN_VISP_NAMESPACE thresholding this image at level 127 can be done by: \code -#include -#include -#include - -int main() -{ - vpImage I; -#ifdef _WIN32 - std::string filename("C:/Temp/visp-images/Klimt/Klimt.ppm"); -#else - std::string filename("/local/soft/ViSP/ViSP-images/Klimt/Klimt.ppm"); -#endif - - // Read an image from the disk - vpImageIo::read(I, filename); - - // Binarize image I: - // - gray level values less than or equal to 127 are set to 0, - // - gray level values greater than 128 are set to 255 - vpImageTools::changeLUT(I, 127, 0, 128, 255); - - vpImageIo::write(I, "Klimt.pgm"); // Write the image in a PGM P5 image file format -} + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I; + #ifdef _WIN32 + std::string filename("C:/Temp/visp-images/Klimt/Klimt.ppm"); + #else + std::string filename("/local/soft/ViSP/ViSP-images/Klimt/Klimt.ppm"); + #endif + + // Read an image from the disk + vpImageIo::read(I, filename); + + // Binarize image I: + // - gray level values less than or equal to 127 are set to 0, + // - gray level values greater than 128 are set to 255 + vpImageTools::changeLUT(I, 127, 0, 128, 255); + + vpImageIo::write(I, "Klimt.pgm"); // Write the image in a PGM P5 image file format + } \endcode */ diff --git a/modules/core/src/image/vpRGBa.cpp b/modules/core/src/image/vpRGBa.cpp index f676b88820..f1ed74c579 100644 --- a/modules/core/src/image/vpRGBa.cpp +++ b/modules/core/src/image/vpRGBa.cpp @@ -309,6 +309,10 @@ vpRGBa operator*(const double &x, const vpRGBa &rgb) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage I(480,640); diff --git a/modules/core/src/image/vpRGBf.cpp b/modules/core/src/image/vpRGBf.cpp index 9181f0786a..b3749e9de2 100644 --- a/modules/core/src/image/vpRGBf.cpp +++ b/modules/core/src/image/vpRGBf.cpp @@ -292,6 +292,10 @@ vpRGBf operator*(double x, const vpRGBf &rgb) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage I(480,640); diff --git a/modules/core/src/math/kalman/vpLinearKalmanFilterInstantiation.cpp b/modules/core/src/math/kalman/vpLinearKalmanFilterInstantiation.cpp index 9263e95b17..3ba551556a 100644 --- a/modules/core/src/math/kalman/vpLinearKalmanFilterInstantiation.cpp +++ b/modules/core/src/math/kalman/vpLinearKalmanFilterInstantiation.cpp @@ -91,6 +91,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpLinearKalmanFilterInstantiation kalman; @@ -116,6 +120,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpLinearKalmanFilterInstantiation kalman; @@ -447,45 +455,49 @@ by the number of signal to filter. measures. \code -#include + #include -int main() -{ - vpLinearKalmanFilterInstantiation kalman; - // Filter the x and y velocities of a target (2 signals are to consider) - int nsignal = 2; - - // Initialize the filter parameters: - // - Firstly, the state variance - vpColVector sigma_state(4); // 4 = 2 for the state size x 2 signal - sigma_state[1] = 0.001; // Variance on the acceleration for the 1st signal (x) - sigma_state[3] = 0.002; // Variance on the acceleration for the 2nd signal (y) - // - Secondly, the measures variance - vpColVector sigma_measure(nsignal); // 2 velocity measures available - sigma_measure[0] = 0.03; // Variance on the x velocity measure - sigma_measure[1] = 0.06; // Variance on the y velocity measure - // - Thirdly, the correlation between successive accelerations - double rho = 0.9; - - // Initialize the filter - kalman.initStateConstVelWithColoredNoise_MeasureVel(nsignal, sigma_state, sigma_measure, rho); - - // Does the filtering - vpColVector vm(2); // Measured velocities - for ( ; ; ) { - // Get the two dimensional velocity measures - // vm[0] = ...; - // vm[1] = ...; - - // Compute the filtering and the prediction - kalman.filter(vm); - // Print the estimation of the velocities (1st value of the state vector) - std::cout << "Estimated x velocity: kalman.Xest[0]" << std::endl; - std::cout << "Estimated y velocity: kalman.Xest[kalman.getStateSize()]" - << std::endl; - // The one step prediction is available in kalman.Xpre variable + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpLinearKalmanFilterInstantiation kalman; + // Filter the x and y velocities of a target (2 signals are to consider) + int nsignal = 2; + + // Initialize the filter parameters: + // - Firstly, the state variance + vpColVector sigma_state(4); // 4 = 2 for the state size x 2 signal + sigma_state[1] = 0.001; // Variance on the acceleration for the 1st signal (x) + sigma_state[3] = 0.002; // Variance on the acceleration for the 2nd signal (y) + // - Secondly, the measures variance + vpColVector sigma_measure(nsignal); // 2 velocity measures available + sigma_measure[0] = 0.03; // Variance on the x velocity measure + sigma_measure[1] = 0.06; // Variance on the y velocity measure + // - Thirdly, the correlation between successive accelerations + double rho = 0.9; + + // Initialize the filter + kalman.initStateConstVelWithColoredNoise_MeasureVel(nsignal, sigma_state, sigma_measure, rho); + + // Does the filtering + vpColVector vm(2); // Measured velocities + for ( ; ; ) { + // Get the two dimensional velocity measures + // vm[0] = ...; + // vm[1] = ...; + + // Compute the filtering and the prediction + kalman.filter(vm); + // Print the estimation of the velocities (1st value of the state vector) + std::cout << "Estimated x velocity: kalman.Xest[0]" << std::endl; + std::cout << "Estimated y velocity: kalman.Xest[kalman.getStateSize()]" + << std::endl; + // The one step prediction is available in kalman.Xpre variable + } } -} \endcode */ void vpLinearKalmanFilterInstantiation::initStateConstVelWithColoredNoise_MeasureVel(unsigned int n_signal, @@ -662,49 +674,53 @@ mutually uncorrelated stationary random variables with variance measures. \code -#include + #include -int main() -{ - vpLinearKalmanFilterInstantiation kalman; - // Filter the x and y velocities of a target (2 signals are to consider) - int nsignal = 2; - - // Initialize the filter parameters: - // - Firstly, the state variance - vpColVector sigma_state(6); // 6 = 3 for the state size x 2 signal - sigma_state[1] = 0.001; // Variance on the acceleration for the 1st signal (x) - sigma_state[2] = 0.001; // Variance on the acceleration for the 1st signal (x) - sigma_state[4] = 0.002; // Variance on the acceleration for the 2nd signal (y) - sigma_state[5] = 0.002; // Variance on the acceleration for the 2nd signal (y) - // - Secondly, the measures variance - vpColVector sigma_measure(nsignal); // 2 velocity measures available - sigma_measure[0] = 0.03; // Variance on the x velocity measure - sigma_measure[1] = 0.06; // Variance on the y velocity measure - // - Thirdly, the correlation between successive accelerations - double rho = 0.9; - // - Lastly, the sampling time - double dt = 0.020; // 20 ms - - // Initialize the filter - kalman.initStateConstAccWithColoredNoise_MeasureVel(nsignal, sigma_state, sigma_measure, rho, dt); - - // Does the filtering - vpColVector vm(2); // Measured velocities - for ( ; ; ) { - // Get the two dimensional velocity measures - // vm[0] = ...; - // vm[1] = ...; - - // Compute the filtering and the prediction - kalman.filter(vm); - // Print the estimation of the velocities (1st value of the state vector) - std::cout << "Estimated x velocity: kalman.Xest[0]" << std::endl; - std::cout << "Estimated y velocity: kalman.Xest[kalman.getStateSize()]" - << std::endl; - // The one step prediction is available in kalman.Xpre variable + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpLinearKalmanFilterInstantiation kalman; + // Filter the x and y velocities of a target (2 signals are to consider) + int nsignal = 2; + + // Initialize the filter parameters: + // - Firstly, the state variance + vpColVector sigma_state(6); // 6 = 3 for the state size x 2 signal + sigma_state[1] = 0.001; // Variance on the acceleration for the 1st signal (x) + sigma_state[2] = 0.001; // Variance on the acceleration for the 1st signal (x) + sigma_state[4] = 0.002; // Variance on the acceleration for the 2nd signal (y) + sigma_state[5] = 0.002; // Variance on the acceleration for the 2nd signal (y) + // - Secondly, the measures variance + vpColVector sigma_measure(nsignal); // 2 velocity measures available + sigma_measure[0] = 0.03; // Variance on the x velocity measure + sigma_measure[1] = 0.06; // Variance on the y velocity measure + // - Thirdly, the correlation between successive accelerations + double rho = 0.9; + // - Lastly, the sampling time + double dt = 0.020; // 20 ms + + // Initialize the filter + kalman.initStateConstAccWithColoredNoise_MeasureVel(nsignal, sigma_state, sigma_measure, rho, dt); + + // Does the filtering + vpColVector vm(2); // Measured velocities + for ( ; ; ) { + // Get the two dimensional velocity measures + // vm[0] = ...; + // vm[1] = ...; + + // Compute the filtering and the prediction + kalman.filter(vm); + // Print the estimation of the velocities (1st value of the state vector) + std::cout << "Estimated x velocity: kalman.Xest[0]" << std::endl; + std::cout << "Estimated y velocity: kalman.Xest[kalman.getStateSize()]" + << std::endl; + // The one step prediction is available in kalman.Xpre variable + } } -} \endcode */ diff --git a/modules/core/src/math/matrix/vpMatrix.cpp b/modules/core/src/math/matrix/vpMatrix.cpp index 7fdfe12f8a..71e4606483 100644 --- a/modules/core/src/math/matrix/vpMatrix.cpp +++ b/modules/core/src/math/matrix/vpMatrix.cpp @@ -227,6 +227,10 @@ vpMatrix::vpMatrix(vpMatrix &&A) : vpArray2D() \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M( {-1, -2, -3, 4, 5.5, 6.0f} ); @@ -252,6 +256,10 @@ vpMatrix::vpMatrix(const std::initializer_list &list) : vpArray2D + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M(2, 3, {-1, -2, -3, 4, 5.5, 6}); @@ -276,6 +284,10 @@ vpMatrix::vpMatrix(unsigned int nrows, unsigned int ncols, const std::initialize \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M( { {-1, -2, -3}, {4, 5.5, 6} } ); @@ -308,6 +320,10 @@ vpMatrix::vpMatrix(const std::initializer_list > & \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M(4,5); @@ -373,6 +389,10 @@ void vpMatrix::init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M(4,5); @@ -438,6 +458,10 @@ vpMatrix vpMatrix::extract(unsigned int r, unsigned int c, unsigned int nrows, u #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4,4); @@ -489,6 +513,10 @@ vpColVector vpMatrix::getCol(unsigned int j, unsigned int i_begin, unsigned int #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4,4); @@ -530,6 +558,10 @@ vpColVector vpMatrix::getCol(unsigned int j) const { return getCol(j, 0, rowNum) #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4,4); @@ -571,6 +603,10 @@ vpRowVector vpMatrix::getRow(unsigned int i) const { return getRow(i, 0, colNum) #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4, 4); @@ -620,6 +656,10 @@ vpRowVector vpMatrix::getRow(unsigned int i, unsigned int j_begin, unsigned int \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3, 4); @@ -871,6 +911,10 @@ int vpMatrix::print(std::ostream &s, unsigned int length, const std::string &int \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M(2,3); @@ -926,6 +970,10 @@ std::ostream &vpMatrix::matlabPrint(std::ostream &os) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M(2,3); @@ -970,6 +1018,10 @@ std::ostream &vpMatrix::maplePrint(std::ostream &os) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { std::ofstream ofs("log.csv", std::ofstream::out); @@ -1018,6 +1070,10 @@ std::ostream &vpMatrix::csvPrint(std::ostream &os) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M(2,3); @@ -1111,6 +1167,10 @@ void vpMatrix::insert(const vpMatrix &A, unsigned int r, unsigned int c) #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,3); // A is a symmetric matrix @@ -1221,6 +1281,10 @@ vpColVector vpMatrix::eigenValues() const #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4,4); // A is a symmetric matrix @@ -1551,6 +1615,10 @@ unsigned int vpMatrix::nullSpace(vpMatrix &kerA, int dim) const #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,3); diff --git a/modules/core/src/math/matrix/vpMatrix_cholesky.cpp b/modules/core/src/math/matrix/vpMatrix_cholesky.cpp index e6252e8fd9..b30ded7ca1 100644 --- a/modules/core/src/math/matrix/vpMatrix_cholesky.cpp +++ b/modules/core/src/math/matrix/vpMatrix_cholesky.cpp @@ -84,6 +84,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4,4); @@ -127,6 +131,10 @@ vpMatrix vpMatrix::inverseByCholesky() const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { unsigned int n = 4; @@ -279,6 +287,10 @@ vpMatrix vpMatrix::choleskyByLapack()const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { unsigned int n = 4; diff --git a/modules/core/src/math/matrix/vpMatrix_lu.cpp b/modules/core/src/math/matrix/vpMatrix_lu.cpp index 99f5cc6c65..5b6e8d67f8 100644 --- a/modules/core/src/math/matrix/vpMatrix_lu.cpp +++ b/modules/core/src/math/matrix/vpMatrix_lu.cpp @@ -94,6 +94,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4,4); @@ -208,6 +212,10 @@ vpMatrix vpMatrix::inverseByLU() const #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,3); @@ -264,6 +272,10 @@ double vpMatrix::detByLU() const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4,4); @@ -367,6 +379,10 @@ vpMatrix vpMatrix::inverseByLULapack() const #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,3); @@ -466,6 +482,10 @@ double vpMatrix::detByLULapack() const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4,4); @@ -513,6 +533,10 @@ vpMatrix vpMatrix::inverseByLUOpenCV() const #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,3); @@ -555,6 +579,10 @@ double vpMatrix::detByLUOpenCV() const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4,4); @@ -603,6 +631,10 @@ vpMatrix vpMatrix::inverseByLUEigen3() const #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,3); diff --git a/modules/core/src/math/matrix/vpMatrix_operations.cpp b/modules/core/src/math/matrix/vpMatrix_operations.cpp index 5c64ef18df..8d9f029e00 100644 --- a/modules/core/src/math/matrix/vpMatrix_operations.cpp +++ b/modules/core/src/math/matrix/vpMatrix_operations.cpp @@ -657,6 +657,10 @@ vpMatrix vpMatrix::AtA() const #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A; @@ -703,6 +707,10 @@ void vpMatrix::diag(const vpColVector &A) #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3, 4); diff --git a/modules/core/src/math/matrix/vpMatrix_operators.cpp b/modules/core/src/math/matrix/vpMatrix_operators.cpp index fea1937648..9d09383618 100644 --- a/modules/core/src/math/matrix/vpMatrix_operators.cpp +++ b/modules/core/src/math/matrix/vpMatrix_operators.cpp @@ -268,6 +268,10 @@ vpMatrix &vpMatrix::operator=(vpMatrix &&other) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M; @@ -303,6 +307,10 @@ vpMatrix &vpMatrix::operator=(const std::initializer_list &list) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M; diff --git a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp index 50df681246..4edbd3ed75 100644 --- a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp +++ b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp @@ -146,6 +146,10 @@ void compute_pseudo_inverse(const vpMatrix &U, const vpColVector &sv, const vpMa \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -214,6 +218,10 @@ unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, double svThreshold) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -290,6 +298,10 @@ int vpMatrix::pseudoInverse(vpMatrix &Ap, int rank_in) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -353,6 +365,10 @@ vpMatrix vpMatrix::pseudoInverse(double svThreshold) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -425,6 +441,10 @@ vpMatrix vpMatrix::pseudoInverse(int rank_in) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -501,6 +521,10 @@ unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThr \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -589,6 +613,10 @@ int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -667,6 +695,10 @@ unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThr \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -757,6 +789,10 @@ int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, int rank_in, vpMatrix \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -878,6 +914,10 @@ unsigned int vpMatrix::pseudoInverse(vpMatrix &Ap, vpColVector &sv, double svThr \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); diff --git a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_eigen.cpp b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_eigen.cpp index 2e304929b3..78b4e529de 100644 --- a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_eigen.cpp +++ b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_eigen.cpp @@ -59,6 +59,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -113,6 +117,10 @@ vpMatrix vpMatrix::pseudoInverseEigen3(double svThreshold) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -173,6 +181,10 @@ unsigned int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, double svThreshold) con \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -279,6 +291,10 @@ unsigned int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -357,6 +373,10 @@ unsigned int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, double \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -413,6 +433,10 @@ vpMatrix vpMatrix::pseudoInverseEigen3(int rank_in) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -482,6 +506,10 @@ int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, int rank_in) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -595,6 +623,10 @@ int vpMatrix::pseudoInverseEigen3(vpMatrix &Ap, vpColVector &sv, int rank_in) co \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); diff --git a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_lapack.cpp b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_lapack.cpp index ae69ce5410..be59d7b9b0 100644 --- a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_lapack.cpp +++ b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_lapack.cpp @@ -69,6 +69,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -124,6 +128,10 @@ vpMatrix vpMatrix::pseudoInverseLapack(double svThreshold) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -185,6 +193,10 @@ unsigned int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, double svThreshold) con \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -292,6 +304,10 @@ unsigned int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -370,6 +386,10 @@ unsigned int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, double \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -427,6 +447,10 @@ vpMatrix vpMatrix::pseudoInverseLapack(int rank_in) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -495,6 +519,10 @@ int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, int rank_in) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -608,6 +636,10 @@ int vpMatrix::pseudoInverseLapack(vpMatrix &Ap, vpColVector &sv, int rank_in) co \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); diff --git a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_opencv.cpp b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_opencv.cpp index 1bcaa2f85b..bd0aabe2b1 100644 --- a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_opencv.cpp +++ b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse_opencv.cpp @@ -59,6 +59,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -113,6 +117,10 @@ vpMatrix vpMatrix::pseudoInverseOpenCV(double svThreshold) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -174,6 +182,10 @@ unsigned int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, double svThreshold) con \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -280,6 +292,10 @@ unsigned int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -358,6 +374,10 @@ unsigned int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, double \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -414,6 +434,10 @@ vpMatrix vpMatrix::pseudoInverseOpenCV(int rank_in) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -483,6 +507,10 @@ int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, int rank_in) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); @@ -596,6 +624,10 @@ int vpMatrix::pseudoInverseOpenCV(vpMatrix &Ap, vpColVector &sv, int rank_in) co \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(2, 3); diff --git a/modules/core/src/math/matrix/vpMatrix_qr.cpp b/modules/core/src/math/matrix/vpMatrix_qr.cpp index 3cfad7049a..cf3bac257d 100644 --- a/modules/core/src/math/matrix/vpMatrix_qr.cpp +++ b/modules/core/src/math/matrix/vpMatrix_qr.cpp @@ -122,6 +122,10 @@ void display_gsl(gsl_matrix *M) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4,4); @@ -352,6 +356,10 @@ vpMatrix vpMatrix::inverseByQRLapack() const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(4,4); @@ -405,6 +413,10 @@ vpMatrix vpMatrix::inverseByQR() const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + double residual(vpMatrix M1, vpMatrix M2) { return (M1 - M2).frobeniusNorm(); @@ -681,6 +693,10 @@ unsigned int vpMatrix::qr(vpMatrix &Q, vpMatrix &R, bool full, bool squareR, dou \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + double residual(vpMatrix M1, vpMatrix M2) { return (M1 - M2).frobeniusNorm(); @@ -899,6 +915,10 @@ unsigned int vpMatrix::qrPivotLapack(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + double residual(vpMatrix M1, vpMatrix M2) { return (M1 - M2).frobeniusNorm(); @@ -1079,6 +1099,10 @@ unsigned int vpMatrix::qrPivotLapackGSL(vpMatrix &Q, vpMatrix &R, vpMatrix &P, b \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + double residual(vpMatrix M1, vpMatrix M2) { return (M1 - M2).frobeniusNorm(); @@ -1263,6 +1287,11 @@ vpMatrix vpMatrix::inverseTriangular(bool upper) const \code #include #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,3); @@ -1313,6 +1342,11 @@ void vpMatrix::solveByQR(const vpColVector &b, vpColVector &x) const \code #include #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,3); diff --git a/modules/core/src/math/matrix/vpMatrix_svd.cpp b/modules/core/src/math/matrix/vpMatrix_svd.cpp index 45e48bca2a..69f03cbcc4 100644 --- a/modules/core/src/math/matrix/vpMatrix_svd.cpp +++ b/modules/core/src/math/matrix/vpMatrix_svd.cpp @@ -88,6 +88,10 @@ BEGIN_VISP_NAMESPACE #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,3); @@ -140,6 +144,10 @@ void vpMatrix::solveBySVD(const vpColVector &b, vpColVector &x) const { x = pseu #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,3); @@ -215,6 +223,10 @@ vpColVector vpMatrix::solveBySVD(const vpColVector &B) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M(3,2); @@ -287,6 +299,10 @@ void vpMatrix::svd(vpColVector &w, vpMatrix &V) #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M(3,2); @@ -374,6 +390,10 @@ void vpMatrix::svdOpenCV(vpColVector &w, vpMatrix &V) #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M(3,2); @@ -577,6 +597,10 @@ void vpMatrix::svdLapack(vpColVector &w, vpMatrix &V) #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix M(3,2); diff --git a/modules/core/src/math/matrix/vpRowVector.cpp b/modules/core/src/math/matrix/vpRowVector.cpp index 42fff76a14..947a793989 100644 --- a/modules/core/src/math/matrix/vpRowVector.cpp +++ b/modules/core/src/math/matrix/vpRowVector.cpp @@ -157,6 +157,10 @@ vpRowVector &vpRowVector::operator=(vpRowVector &&other) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRowVector r; @@ -478,16 +482,20 @@ vpRowVector &vpRowVector::operator-=(vpRowVector v) Copy operator. Allows operation such as A << v \code -#include + #include -int main() -{ - vpRowVector A, B(5); - for (unsigned int i=0; i + #include -int main() -{ - int var=0; - vpMatrix mat(3, 4); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 4; j++) - mat[i][j] = ++var; - std::cout << "mat: \n" << mat << std::endl; - - vpRowVector row = mat.stackRows(); - std::cout << "row vector: " << row << std::endl; - - vpMatrix remat = row.reshape(3, 4); - std::cout << "remat: \n" << remat << std::endl; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + int var=0; + vpMatrix mat(3, 4); + for (int i = 0; i < 3; i++) + for (int j = 0; j < 4; j++) + mat[i][j] = ++var; + std::cout << "mat: \n" << mat << std::endl; + + vpRowVector row = mat.stackRows(); + std::cout << "row vector: " << row << std::endl; + + vpMatrix remat = row.reshape(3, 4); + std::cout << "remat: \n" << remat << std::endl; + } \endcode If you run the previous example, you get: @@ -748,6 +760,10 @@ void vpRowVector::reshape(vpMatrix &M, const unsigned int &nrows, const unsigned \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRowVector v(4); @@ -1159,6 +1175,10 @@ double vpRowVector::euclideanNorm() const { return frobeniusNorm(); } \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRowVector v(4); @@ -1208,6 +1228,10 @@ void vpRowVector::init(const vpRowVector &v, unsigned int c, unsigned int ncols) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRowVector r(3); @@ -1252,6 +1276,10 @@ std::ostream &vpRowVector::cppPrint(std::ostream &os, const std::string &matrixN \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { std::ofstream ofs("log.csv", std::ofstream::out); @@ -1289,6 +1317,10 @@ std::ostream &vpRowVector::csvPrint(std::ostream &os) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRowVector r(3); @@ -1325,6 +1357,10 @@ std::ostream &vpRowVector::maplePrint(std::ostream &os) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRowVector r(3); diff --git a/modules/core/src/math/transformation/vpForceTwistMatrix.cpp b/modules/core/src/math/transformation/vpForceTwistMatrix.cpp index 58e5dc8cb4..573a6cbc25 100644 --- a/modules/core/src/math/transformation/vpForceTwistMatrix.cpp +++ b/modules/core/src/math/transformation/vpForceTwistMatrix.cpp @@ -255,19 +255,23 @@ vpForceTwistMatrix::vpForceTwistMatrix(double tx, double ty, double tz, double t /*! Operator that allows to multiply a force/torque twist transformation matrix -by an other force/torque skew transformation matrix. + by an other force/torque skew transformation matrix. -\code -#include + \code + #include -int main() -{ - vpForceTwistMatrix aFb, bFc; - // ... initialize the force/torque twist transformations aFb and bFc - // Compute the force/torque transformation from frame a to c - vpForceTwistMatrix aFc = aFb * bFc; -} -\endcode + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpForceTwistMatrix aFb, bFc; + // ... initialize the force/torque twist transformations aFb and bFc + // Compute the force/torque transformation from frame a to c + vpForceTwistMatrix aFc = aFb * bFc; + } + \endcode */ vpForceTwistMatrix vpForceTwistMatrix::operator*(const vpForceTwistMatrix &F) const @@ -334,6 +338,10 @@ vpMatrix vpForceTwistMatrix::operator*(const vpMatrix &M) const #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #ifdef VISP_HAVE_VIPER850 diff --git a/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp b/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp index c172da0265..f246f9f416 100644 --- a/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp +++ b/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp @@ -116,26 +116,30 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const vpPoseVector &p) : vpArray2D + #include -int main() -{ - std::vector v(12, 0); - v[1] = -1.; // ry=-90 - v[4] = 1.; // rx=90 - v[10] = -1.; // rz=-90 - v[3] = 0.3; // tx - v[7] = 0.4; // ty - v[11] = 0.5; // tz - - std::cout << "v: "; - for(unsigned int i=0; i v(12, 0); + v[1] = -1.; // ry=-90 + v[4] = 1.; // rx=90 + v[10] = -1.; // rz=-90 + v[3] = 0.3; // tx + v[7] = 0.4; // ty + v[11] = 0.5; // tz + + std::cout << "v: "; + for(unsigned int i=0; i &v) : vpArray2 \param list : List of double. The following code shows how to use this constructor to initialize an homogeneous matrix: \code -#include + #include -int main() -{ - vpHomogeneousMatrix M { - 0, 0, 1, 0.1, - 0, 1, 0, 0.2, - 1, 0, 0, 0.3 }; - std::cout << "M:\n" << M << std::endl; - vpHomogeneousMatrix N { - 0, 0, 1, 0.1, - 0, 1, 0, 0.2, - 1, 0, 0, 0.3, - 0, 0, 0, 1 }; - std::cout << "N:\n" << N << std::endl; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpHomogeneousMatrix M { + 0, 0, 1, 0.1, + 0, 1, 0, 0.2, + 1, 0, 0, 0.3 }; + std::cout << "M:\n" << M << std::endl; + vpHomogeneousMatrix N { + 0, 0, 1, 0.1, + 0, 1, 0, 0.2, + 1, 0, 0, 0.3, + 0, 0, 0, 1 }; + std::cout << "N:\n" << N << std::endl; + } \endcode It produces the following output: \code -M: -0 0 1 0.1 -0 1 0 0.2 -1 0 0 0.3 -0 0 0 1 -N: -0 0 1 0.1 -0 1 0 0.2 -1 0 0 0.3 -0 0 0 1 + M: + 0 0 1 0.1 + 0 1 0 0.2 + 1 0 0 0.3 + 0 0 0 1 + N: + 0 0 1 0.1 + 0 1 0 0.2 + 1 0 0 0.3 + 0 0 0 1 \endcode */ vpHomogeneousMatrix::vpHomogeneousMatrix(const std::initializer_list &list) @@ -265,36 +273,40 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const std::initializer_list &li The following example shows how to use this function: \code -#include + #include -int main() -{ - std::vector v(12, 0); - v[1] = -1.; // ry=-90 - v[4] = 1.; // rx=90 - v[10] = -1.; // rz=-90 - v[3] = 0.3; // tx - v[7] = 0.4; // ty - v[11] = 0.5; // tz - - std::cout << "v: "; - for(unsigned int i=0; i v(12, 0); + v[1] = -1.; // ry=-90 + v[4] = 1.; // rx=90 + v[10] = -1.; // rz=-90 + v[3] = 0.3; // tx + v[7] = 0.4; // ty + v[11] = 0.5; // tz + + std::cout << "v: "; + for(unsigned int i=0; i &v) : vpArray2D(4, 4), m_index(0) @@ -371,41 +383,45 @@ void vpHomogeneousMatrix::buildFrom(double tx, double ty, double tz, double tux, Build an homogeneous matrix from a vector of float. \param v : Vector of 12 or 16 values corresponding to the values of the -homogeneous matrix. + homogeneous matrix. The following example shows how to use this function: \code -#include + #include -int main() -{ - std::vector v(12, 0); - v[1] = -1.; // ry=-90 - v[4] = 1.; // rx=90 - v[10] = -1.; // rz=-90 - v[3] = 0.3; // tx - v[7] = 0.4; // ty - v[11] = 0.5; // tz - - std::cout << "v: "; - for(unsigned int i=0; i v(12, 0); + v[1] = -1.; // ry=-90 + v[4] = 1.; // rx=90 + v[10] = -1.; // rz=-90 + v[3] = 0.3; // tx + v[7] = 0.4; // ty + v[11] = 0.5; // tz + + std::cout << "v: "; + for(unsigned int i=0; i &v) @@ -421,37 +437,41 @@ homogeneous matrix. The following example shows how to use this function: \code -#include + #include -int main() -{ - std::vector v(12, 0); - v[1] = -1.; // ry=-90 - v[4] = 1.; // rx=90 - v[10] = -1.; // rz=-90 - v[3] = 0.3; // tx - v[7] = 0.4; // ty - v[11] = 0.5; // tz - - std::cout << "v: "; - for(unsigned int i=0; i v(12, 0); + v[1] = -1.; // ry=-90 + v[4] = 1.; // rx=90 + v[10] = -1.; // rz=-90 + v[3] = 0.3; // tx + v[7] = 0.4; // ty + v[11] = 0.5; // tz + + std::cout << "v: "; + for(unsigned int i=0; i &v) @@ -530,41 +550,45 @@ vpHomogeneousMatrix &vpHomogeneousMatrix::build(const double &tx, const double & /*! Build an homogeneous matrix from a vector of float. \param v : Vector of 12 or 16 values corresponding to the values of the -homogeneous matrix. + homogeneous matrix. The following example shows how to use this function: \code -#include + #include -int main() -{ - std::vector v(12, 0); - v[1] = -1.; // ry=-90 - v[4] = 1.; // rx=90 - v[10] = -1.; // rz=-90 - v[3] = 0.3; // tx - v[7] = 0.4; // ty - v[11] = 0.5; // tz - - std::cout << "v: "; - for(unsigned int i=0; i v(12, 0); + v[1] = -1.; // ry=-90 + v[4] = 1.; // rx=90 + v[10] = -1.; // rz=-90 + v[3] = 0.3; // tx + v[7] = 0.4; // ty + v[11] = 0.5; // tz + + std::cout << "v: "; + for(unsigned int i=0; i &v) @@ -582,41 +606,45 @@ vpHomogeneousMatrix &vpHomogeneousMatrix::build(const std::vector &v) /*! Build an homogeneous matrix from a vector of double. \param v : Vector of 12 or 16 values corresponding to the values of the -homogeneous matrix. + homogeneous matrix. The following example shows how to use this function: \code -#include + #include -int main() -{ - std::vector v(12, 0); - v[1] = -1.; // ry=-90 - v[4] = 1.; // rx=90 - v[10] = -1.; // rz=-90 - v[3] = 0.3; // tx - v[7] = 0.4; // ty - v[11] = 0.5; // tz - - std::cout << "v: "; - for(unsigned int i=0; i v(12, 0); + v[1] = -1.; // ry=-90 + v[4] = 1.; // rx=90 + v[10] = -1.; // rz=-90 + v[3] = 0.3; // tx + v[7] = 0.4; // ty + v[11] = 0.5; // tz + + std::cout << "v: "; + for(unsigned int i=0; i &v) @@ -650,16 +678,20 @@ vpHomogeneousMatrix &vpHomogeneousMatrix::operator=(const vpHomogeneousMatrix &M Operator that allow to multiply an homogeneous matrix by an other one. \code -#include + #include -int main() -{ - vpHomogeneousMatrix aMb, bMc; - // Initialize aMb and bMc... + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Compute aMc * bMc - vpHomogeneousMatrix aMc = aMb * bMc; -} + int main() + { + vpHomogeneousMatrix aMb, bMc; + // Initialize aMb and bMc... + + // Compute aMc * bMc + vpHomogeneousMatrix aMc = aMb * bMc; + } \endcode */ @@ -690,16 +722,20 @@ vpHomogeneousMatrix vpHomogeneousMatrix::operator*(const vpHomogeneousMatrix &M) Operator that allow to multiply an homogeneous matrix by an other one. \code -#include + #include -int main() -{ - vpHomogeneousMatrix M1, M2; - // Initialize M1 and M2... + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Compute M1 = M1 * M2 - M1 *= M2; -} + int main() + { + vpHomogeneousMatrix M1, M2; + // Initialize M1 and M2... + + // Compute M1 = M1 * M2 + M1 *= M2; + } \endcode */ @@ -837,36 +873,40 @@ vpHomogeneousMatrix vpHomogeneousMatrix::operator*(const vpRotationMatrix &R) co The following example shows how to initialize a rotation matrix using this operator. \code -#include + #include -int main() -{ - vpHomogeneousMatrix M; - M << 0, 0, 1, 0.1, - 0, 1, 0, 0.2, - 1, 0, 0, 0.3; - std::cout << "M:\n" << M << std::endl; - - vpHomogeneousMatrix N; - N << 0, 0, 1, 0.1, - 0, 1, 0, 0.2, - 1, 0, 0, 0.3, - 0, 0, 0, 1; - std::cout << "N:\n" << N << std::endl; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpHomogeneousMatrix M; + M << 0, 0, 1, 0.1, + 0, 1, 0, 0.2, + 1, 0, 0, 0.3; + std::cout << "M:\n" << M << std::endl; + + vpHomogeneousMatrix N; + N << 0, 0, 1, 0.1, + 0, 1, 0, 0.2, + 1, 0, 0, 0.3, + 0, 0, 0, 1; + std::cout << "N:\n" << N << std::endl; + } \endcode It produces the following printings: \code -M: -0 0 1 0.1 -0 1 0 0.2 -1 0 0 0.3 -0 0 0 1 -N: -0 0 1 0.1 -0 1 0 0.2 -1 0 0 0.3 -0 0 0 1 + M: + 0 0 1 0.1 + 0 1 0 0.2 + 1 0 0 0.3 + 0 0 0 1 + N: + 0 0 1 0.1 + 0 1 0 0.2 + 1 0 0 0.3 + 0 0 0 1 \endcode \sa operator,() @@ -886,36 +926,40 @@ vpHomogeneousMatrix &vpHomogeneousMatrix::operator<<(double val) The following example shows how to initialize an homogeneous matrix using this operator. \code -#include + #include -int main() -{ - vpHomogeneousMatrix M; - M << 0, 0, 1, 0.1, - 0, 1, 0, 0.2, - 1, 0, 0, 0.3; - std::cout << "M:\n" << M << std::endl; - - vpHomogeneousMatrix N; - N << 0, 0, 1, 0.1, - 0, 1, 0, 0.2, - 1, 0, 0, 0.3, - 0, 0, 0, 1; - std::cout << "N:\n" << N << std::endl; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpHomogeneousMatrix M; + M << 0, 0, 1, 0.1, + 0, 1, 0, 0.2, + 1, 0, 0, 0.3; + std::cout << "M:\n" << M << std::endl; + + vpHomogeneousMatrix N; + N << 0, 0, 1, 0.1, + 0, 1, 0, 0.2, + 1, 0, 0, 0.3, + 0, 0, 0, 1; + std::cout << "N:\n" << N << std::endl; + } \endcode It produces the following printings: \code -M: -0 0 1 0.1 -0 1 0 0.2 -1 0 0 0.3 -0 0 0 1 -N: -0 0 1 0.1 -0 1 0 0.2 -1 0 0 0.3 -0 0 0 1 + M: + 0 0 1 0.1 + 0 1 0 0.2 + 1 0 0 0.3 + 0 0 0 1 + N: + 0 0 1 0.1 + 0 1 0 0.2 + 1 0 0 0.3 + 0 0 0 1 \endcode \sa operator<<() @@ -1275,29 +1319,33 @@ vpThetaUVector vpHomogeneousMatrix::getThetaUVector() const /*! Extract a column vector from an homogeneous matrix. \warning All the indexes start from 0 in this function. - \param j : Index of the column to extract. If j=0, the first column is -extracted. \return The extracted column vector. + \param j : Index of the column to extract. If j=0, the first column is extracted. + \return The extracted column vector. The following example shows how to use this function: \code -#include -#include + #include + #include -int main() -{ - vpHomogeneousMatrix M; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpColVector t = M.getCol(3); - std::cout << "Last column: \n" << t << std::endl; -} + int main() + { + vpHomogeneousMatrix M; + + vpColVector t = M.getCol(3); + std::cout << "Last column: \n" << t << std::endl; + } \endcode -It produces the following output: + It produces the following output: \code -Last column: -0 -0 -1 -0 + Last column: + 0 + 0 + 1 + 0 \endcode */ vpColVector vpHomogeneousMatrix::getCol(unsigned int j) const diff --git a/modules/core/src/math/transformation/vpQuaternionVector.cpp b/modules/core/src/math/transformation/vpQuaternionVector.cpp index bdaee5ddea..6e55fa290e 100644 --- a/modules/core/src/math/transformation/vpQuaternionVector.cpp +++ b/modules/core/src/math/transformation/vpQuaternionVector.cpp @@ -307,6 +307,10 @@ vpQuaternionVector vpQuaternionVector::operator/(double l) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpColVector v(4); @@ -418,6 +422,10 @@ double &vpQuaternionVector::w() { const unsigned int index_3 = 3; return data[in \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpQuaternionVector q = {0, 0, 0, 1}; diff --git a/modules/core/src/math/transformation/vpRotationMatrix.cpp b/modules/core/src/math/transformation/vpRotationMatrix.cpp index 90834222d3..9ad5ca9817 100644 --- a/modules/core/src/math/transformation/vpRotationMatrix.cpp +++ b/modules/core/src/math/transformation/vpRotationMatrix.cpp @@ -99,15 +99,19 @@ vpRotationMatrix &vpRotationMatrix::operator=(const vpRotationMatrix &R) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRotationMatrix R R = { 0, 0, -1, 0, -1, 0, -1, 0, 0 }; std::cout << "R:\n" << R << std::endl; } - \endcode - It produces the following output: - \code + \endcode + It produces the following output: + \code R: 0 0 -1 0 -1 0 @@ -188,6 +192,10 @@ vpRotationMatrix &vpRotationMatrix::operator=(const vpMatrix &M) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRotationMatrix R; @@ -222,6 +230,10 @@ vpRotationMatrix &vpRotationMatrix::operator<<(double val) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRotationMatrix R; @@ -346,6 +358,10 @@ vpHomogeneousMatrix vpRotationMatrix::operator*(const vpHomogeneousMatrix &M) co #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpColVector p1(3), p2(3); @@ -559,20 +575,24 @@ vpRotationMatrix::vpRotationMatrix(const vpQuaternionVector &q) : vpArray2D + #include -int main() -{ - vpRotationMatrix R{ 0, 0, -1, 0, -1, 0, -1, 0, 0 }; - std::cout << "R:\n" << R << std::endl; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRotationMatrix R{ 0, 0, -1, 0, -1, 0, -1, 0, 0 }; + std::cout << "R:\n" << R << std::endl; + } \endcode It produces the following output: \code -R: -0 0 -1 -0 -1 0 --1 0 0 + R: + 0 0 -1 + 0 -1 0 + -1 0 0 \endcode */ vpRotationMatrix::vpRotationMatrix(const std::initializer_list &list) @@ -630,15 +650,19 @@ vpRotationMatrix vpRotationMatrix::inverse() const \param R (output): Inverted rotation matrix. \code -#include + #include -int main() -{ - vpRotationMatrix R, Rinv; - // ... Update rotation matrix R - // Compute the inverse in Rinv - R.inverse(Rinv); -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRotationMatrix R, Rinv; + // ... Update rotation matrix R + // Compute the inverse in Rinv + R.inverse(Rinv); + } \endcode */ void vpRotationMatrix::inverse(vpRotationMatrix &R) const { R = inverse(); } @@ -989,23 +1013,27 @@ vpThetaUVector vpRotationMatrix::getThetaUVector() The following example shows how to use this function: \code -#include -#include + #include + #include -int main() -{ - vpRotationMatrix R; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpColVector r = R.getCol(2); - std::cout << "Last column: \n" << r << std::endl; -} + int main() + { + vpRotationMatrix R; + + vpColVector r = R.getCol(2); + std::cout << "Last column: \n" << r << std::endl; + } \endcode It produces the following output: \code -Last column: -0 -0 -1 + Last column: + 0 + 0 + 1 \endcode */ vpColVector vpRotationMatrix::getCol(unsigned int j) const diff --git a/modules/core/src/math/transformation/vpRotationVector.cpp b/modules/core/src/math/transformation/vpRotationVector.cpp index f14f901966..deb56b94a9 100644 --- a/modules/core/src/math/transformation/vpRotationVector.cpp +++ b/modules/core/src/math/transformation/vpRotationVector.cpp @@ -103,18 +103,22 @@ vpColVector vpRotationVector::operator*(double x) const The following example shows how to initialize a \f$\theta_u\f$ vector from a list of 3 values [rad]. \code -#include + #include -int main() -{ - vpThetaUVector tu; - tu << 0, M_PI_2, M_PI; - std::cout << "tu: " << tu.t() << std::endl; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpThetaUVector tu; + tu << 0, M_PI_2, M_PI; + std::cout << "tu: " << tu.t() << std::endl; + } \endcode It produces the following printings: \code -tu: 0 1.570796327 3.141592654 + tu: 0 1.570796327 3.141592654 \endcode \sa operator,() @@ -133,18 +137,22 @@ vpRotationVector &vpRotationVector::operator<<(double val) The following example shows how to initialize a \f$\theta_u\f$ vector from a list of 3 values [rad]. \code -#include + #include -int main() -{ - vpThetaUVector tu; - tu << 0, M_PI_2, M_PI; - std::cout << "tu: " << tu.t() << std::endl; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpThetaUVector tu; + tu << 0, M_PI_2, M_PI; + std::cout << "tu: " << tu.t() << std::endl; + } \endcode It produces the following printings: \code -tu: 0 1.570796327 3.141592654 + tu: 0 1.570796327 3.141592654 \endcode \sa operator<<() diff --git a/modules/core/src/math/transformation/vpRxyzVector.cpp b/modules/core/src/math/transformation/vpRxyzVector.cpp index 782f688fe2..e34fe2e85d 100644 --- a/modules/core/src/math/transformation/vpRxyzVector.cpp +++ b/modules/core/src/math/transformation/vpRxyzVector.cpp @@ -247,6 +247,10 @@ vpRxyzVector &vpRxyzVector::build(const std::vector &rxyz) #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRxyzVector v; @@ -275,6 +279,10 @@ vpRxyzVector &vpRxyzVector::operator=(double v) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpColVector v(3); @@ -307,6 +315,10 @@ vpRxyzVector &vpRxyzVector::operator=(const vpColVector &rxyz) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRxyzVector rxyz = {M_PI, 0, M_PI_2}; diff --git a/modules/core/src/math/transformation/vpRzyxVector.cpp b/modules/core/src/math/transformation/vpRzyxVector.cpp index 84182f0de5..22ed429af5 100644 --- a/modules/core/src/math/transformation/vpRzyxVector.cpp +++ b/modules/core/src/math/transformation/vpRzyxVector.cpp @@ -264,6 +264,10 @@ vpRzyxVector &vpRzyxVector::build(const std::vector &rzyx) #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRzyxVector v; @@ -292,6 +296,10 @@ vpRzyxVector &vpRzyxVector::operator=(double v) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpColVector v(3); @@ -324,6 +332,10 @@ vpRzyxVector &vpRzyxVector::operator=(const vpColVector &rzyx) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRzyxVector rzyx = {M_PI, 0, M_PI_2}; diff --git a/modules/core/src/math/transformation/vpRzyzVector.cpp b/modules/core/src/math/transformation/vpRzyzVector.cpp index 8987d98b8c..4a2e19f510 100644 --- a/modules/core/src/math/transformation/vpRzyzVector.cpp +++ b/modules/core/src/math/transformation/vpRzyzVector.cpp @@ -244,6 +244,10 @@ vpRzyzVector &vpRzyzVector::build(const double &phi, const double &theta, const #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRzyzVector r; @@ -272,6 +276,10 @@ vpRzyzVector &vpRzyzVector::operator=(double v) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpColVector v(3); @@ -304,6 +312,10 @@ vpRzyzVector &vpRzyzVector::operator=(const vpColVector &rzyz) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpRzyzVector rzyz = {M_PI, 0, M_PI_2}; diff --git a/modules/core/src/math/transformation/vpThetaUVector.cpp b/modules/core/src/math/transformation/vpThetaUVector.cpp index 7b1d664eb4..d62c6a291a 100644 --- a/modules/core/src/math/transformation/vpThetaUVector.cpp +++ b/modules/core/src/math/transformation/vpThetaUVector.cpp @@ -85,6 +85,10 @@ vpThetaUVector::vpThetaUVector(const vpQuaternionVector &q) : vpRotationVector(3 \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpThetaUVector tu(0, M_PI_2, M_PI); @@ -413,6 +417,10 @@ vpThetaUVector &vpThetaUVector::build(const double &tux, const double &tuy, cons #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpThetaUVector tu; @@ -441,6 +449,10 @@ vpThetaUVector &vpThetaUVector::operator=(double v) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpColVector v(3); @@ -482,6 +494,10 @@ vpThetaUVector &vpThetaUVector::operator=(const vpColVector &tu) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpHomogeneousMatrix M(0, 0, 1., vpMath::rad(10), vpMath::rad(20), vpMath::rad(30)); @@ -523,6 +539,10 @@ void vpThetaUVector::extract(double &theta, vpColVector &u) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpHomogeneousMatrix M(0, 0, 1., vpMath::rad(10), vpMath::rad(20), vpMath::rad(30)); @@ -554,6 +574,10 @@ double vpThetaUVector::getTheta() const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpHomogeneousMatrix M(0, 0, 1., vpMath::rad(10), vpMath::rad(20), pMath::rad(30)); @@ -609,6 +633,10 @@ vpThetaUVector vpThetaUVector::operator*(const vpThetaUVector &tu_b) const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpThetaUVector tu = {M_PI, 0, M_PI_2}; diff --git a/modules/core/src/math/transformation/vpTranslationVector.cpp b/modules/core/src/math/transformation/vpTranslationVector.cpp index 0dc49913d5..c152f84cc8 100644 --- a/modules/core/src/math/transformation/vpTranslationVector.cpp +++ b/modules/core/src/math/transformation/vpTranslationVector.cpp @@ -603,6 +603,10 @@ vpTranslationVector &vpTranslationVector::operator=(double x) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpTranslationVector t = {0, 0.1, 0.5}; @@ -637,6 +641,10 @@ vpTranslationVector &vpTranslationVector::operator=(const std::initializer_list< \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpTranslationVector t; @@ -667,6 +675,10 @@ vpTranslationVector &vpTranslationVector::operator<<(double val) \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpTranslationVector t; diff --git a/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp b/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp index 16b5e5086c..9b6ec26bb7 100644 --- a/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp +++ b/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp @@ -245,31 +245,35 @@ corresponding camera velocity skew from the joint velocities knowing the robot jacobian. \code -#include -#include -#include -#include + #include + #include + #include + #include -int main() -{ - vpSimulatorCamera robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpColVector q_vel(6); // Joint velocity on the 6 joints - // ... q_vel need here to be initialized + int main() + { + vpSimulatorCamera robot; - vpColVector c_v(6); // Velocity in the camera frame: vx,vy,vz,wx,wy,wz + vpColVector q_vel(6); // Joint velocity on the 6 joints + // ... q_vel need here to be initialized - vpVelocityTwistMatrix cVe; // Velocity skew transformation from camera frame to end-effector - robot.get_cVe(cVe); + vpColVector c_v(6); // Velocity in the camera frame: vx,vy,vz,wx,wy,wz - vpMatrix eJe; // Robot jacobian - robot.get_eJe(eJe); + vpVelocityTwistMatrix cVe; // Velocity skew transformation from camera frame to end-effector + robot.get_cVe(cVe); - // Compute the velocity in the camera frame - c_v = cVe * eJe * q_vel; + vpMatrix eJe; // Robot jacobian + robot.get_eJe(eJe); - return 0; -} + // Compute the velocity in the camera frame + c_v = cVe * eJe * q_vel; + + return 0; + } \endcode \exception vpException::dimensionError If M is not a 6 rows dimension diff --git a/modules/core/src/tools/file/vpIoTools.cpp b/modules/core/src/tools/file/vpIoTools.cpp index b1fb4dd73d..d476228808 100644 --- a/modules/core/src/tools/file/vpIoTools.cpp +++ b/modules/core/src/tools/file/vpIoTools.cpp @@ -142,6 +142,10 @@ BEGIN_VISP_NAMESPACE \code include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { std::string tmp_path = vpIoTools::getTempPath(); @@ -299,6 +303,10 @@ std::string vpIoTools::getUserName() #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { std::string envvalue; @@ -651,6 +659,10 @@ std::string getUuid() \code include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { std::string tmp_path = vpIoTools::getTempPath(); @@ -1076,33 +1088,36 @@ std::string vpIoTools::getViSPImagesDataPath() } /*! - Returns the extension of the file or an empty string if the file has no - extension. If checkFile flag is set, it will check first if the pathname - denotes a directory and so return an empty string and second it will check - if the file denoted by the pathanme exists. If so, it will return the - extension if present. - - \param pathname : The pathname of the file we want to get the extension. - \param checkFile : If true, the file must exist otherwise an empty string will be returned. - \return The extension of the file including the dot "." or an empty string if the file has no extension or if the -pathname is empty. - - The following code shows how to use this function: - \code -#include + Returns the extension of the file or an empty string if the file has no + extension. If checkFile flag is set, it will check first if the pathname + denotes a directory and so return an empty string and second it will check + if the file denoted by the pathanme exists. If so, it will return the + extension if present. -int main() -{ - std::string filename = "my/path/to/file.xml" - std::string ext = vpIoTools::getFileExtension(opt_learning_data); - std::cout << "ext: " << ext << std::endl; -} - \endcode - It produces the following output: - \code -ext: .xml - \endcode + \param pathname : The pathname of the file we want to get the extension. + \param checkFile : If true, the file must exist otherwise an empty string will be returned. + \return The extension of the file including the dot "." or an empty string if the file has no extension or if the + pathname is empty. + + The following code shows how to use this function: + \code + #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + std::string filename = "my/path/to/file.xml" + std::string ext = vpIoTools::getFileExtension(opt_learning_data); + std::cout << "ext: " << ext << std::endl; + } + \endcode + It produces the following output: + \code + ext: .xml + \endcode */ std::string vpIoTools::getFileExtension(const std::string &pathname, bool checkFile) { @@ -1228,24 +1243,28 @@ std::string vpIoTools::getNameWE(const std::string &pathname) The following sample code shows how to use this function: \code -#include + #include -int main() -{ - std::cout << vpIoTools::getIndex("file-1.txt", "file-%d.txt") << std::endl; - std::cout << vpIoTools::getIndex("/tmp/file0040.txt", "/tmp/file%04d.txt") << std::endl; - std::cout << vpIoTools::getIndex("file.txt", "file%d.txt") << std::endl; - std::cout << vpIoTools::getIndex("file03.txt", "file%02d.txt") << std::endl; - std::cout << vpIoTools::getIndex("file-03.txt", "file%02d.txt") << std::endl; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + std::cout << vpIoTools::getIndex("file-1.txt", "file-%d.txt") << std::endl; + std::cout << vpIoTools::getIndex("/tmp/file0040.txt", "/tmp/file%04d.txt") << std::endl; + std::cout << vpIoTools::getIndex("file.txt", "file%d.txt") << std::endl; + std::cout << vpIoTools::getIndex("file03.txt", "file%02d.txt") << std::endl; + std::cout << vpIoTools::getIndex("file-03.txt", "file%02d.txt") << std::endl; + } \endcode It produces the following output: \code -1 -40 --1 -3 --1 + 1 + 40 + -1 + 3 + -1 \endcode */ long vpIoTools::getIndex(const std::string &filename, const std::string &format) @@ -1326,16 +1345,16 @@ std::string vpIoTools::toLowerCase(const std::string &input) out += std::tolower(*it); } return out; - } +} - /** - * @brief Return a upper-case version of the string \b input . - * Numbers and special characters stay the same - * - * @param input The input string for which we want to ensure that all the characters are in upper case. - * @return std::string A upper-case version of the string \b input, where - * numbers and special characters stay the same - */ +/** + * @brief Return a upper-case version of the string \b input . + * Numbers and special characters stay the same + * + * @param input The input string for which we want to ensure that all the characters are in upper case. + * @return std::string A upper-case version of the string \b input, where + * numbers and special characters stay the same + */ std::string vpIoTools::toUpperCase(const std::string &input) { std::string out; @@ -1347,16 +1366,16 @@ std::string vpIoTools::toUpperCase(const std::string &input) out += std::toupper(*it); } return out; - } +} - /*! - Returns the absolute path using realpath() on Unix systems or - GetFullPathName() on Windows systems. \return According to realpath() - manual, returns an absolute pathname that names the same file, whose - resolution does not involve '.', '..', or symbolic links for Unix systems. - According to GetFullPathName() documentation, retrieves the full path of the - specified file for Windows systems. - */ +/*! + Returns the absolute path using realpath() on Unix systems or + GetFullPathName() on Windows systems. \return According to realpath() + manual, returns an absolute pathname that names the same file, whose + resolution does not involve '.', '..', or symbolic links for Unix systems. + According to GetFullPathName() documentation, retrieves the full path of the + specified file for Windows systems. + */ std::string vpIoTools::getAbsolutePathname(const std::string &pathname) { @@ -1591,6 +1610,10 @@ std::pair vpIoTools::splitDrive(const std::string &pat \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { { diff --git a/modules/core/src/tools/optimization/vpLinProg.cpp b/modules/core/src/tools/optimization/vpLinProg.cpp index 3fa2ee080a..8ab4440090 100644 --- a/modules/core/src/tools/optimization/vpLinProg.cpp +++ b/modules/core/src/tools/optimization/vpLinProg.cpp @@ -62,6 +62,10 @@ BEGIN_VISP_NAMESPACE \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,4); @@ -224,6 +228,10 @@ bool vpLinProg::colReduction(vpMatrix &A, vpColVector &b, bool full_rank, const \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix A(3,4); @@ -311,9 +319,12 @@ bool vpLinProg::rowReduction(vpMatrix &A, vpColVector &b, const double &tol) & \text{s.t.}& x, y, z \geq 0\\ & \text{s.t.}& z \leq 6\end{array}\f$ \code - #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpColVector c(3), x; @@ -513,9 +524,12 @@ bool vpLinProg::solveLP(const vpColVector &c, vpMatrix A, vpColVector b, const v & \text{s.t.}& 2x + 5y + 3z + s_2 = 15\\ & \text{s.t.}& x, y, z, s_1, s_2 \geq 0\end{array}\f$ \code - #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpColVector c(5), x; diff --git a/modules/core/src/tools/optimization/vpQuadProg.cpp b/modules/core/src/tools/optimization/vpQuadProg.cpp index df912cd1ac..d6bd54d145 100644 --- a/modules/core/src/tools/optimization/vpQuadProg.cpp +++ b/modules/core/src/tools/optimization/vpQuadProg.cpp @@ -62,10 +62,15 @@ BEGIN_VISP_NAMESPACE \Leftrightarrow \begin{array}{lll} \mathbf{x} = & \arg\min & \frac{1}{2}\mathbf{x}^T\left[\begin{array}{cc}4 & 1 \\ 1 & 2\end{array}\right]\mathbf{x} + - [1~1]\mathbf{x}\\ & \text{s.t.}& [1~1]\mathbf{x} = 1 \end{array} \f$ \code + [1~1]\mathbf{x}\\ & \text{s.t.}& [1~1]\mathbf{x} = 1 \end{array} \f$ + \code #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix H(2,2), A(1,2); @@ -209,9 +214,12 @@ bool vpQuadProg::solveByProjection(const vpMatrix &Q, const vpColVector &r, vpMa \mathbf{x} = & \arg\min & (x_1-1)^2 + x_2^2 \\ & \text{s.t.}& x_1 + x_2 = 1\end{array}\f$ \code - #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix Q(2,2), A(1,2); @@ -282,9 +290,12 @@ bool vpQuadProg::solveQPe(const vpMatrix &Q, const vpColVector &r, vpColVector & \mathbf{x} = & \arg\min & (x_1-1)^2 + x_2^2 \\ & \text{s.t.}& x_1 + x_2 = 1\end{array}\f$ \code - #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix Q(2,2), A(1,2); @@ -345,9 +356,12 @@ bool vpQuadProg::solveQPe(const vpMatrix &Q, const vpColVector &r, vpMatrix A, v & \text{s.t.}& x_1 + x_2 = 1 \\ & \text{s.t.} & x_2 \geq 1\end{array}\f$ \code - #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix Q(2,2), A(1,2), C(1,2); @@ -418,9 +432,12 @@ bool vpQuadProg::solveQP(const vpMatrix &Q, const vpColVector &r, vpMatrix A, vp & \text{s.t.}& x_1 + x_2 \leq 1 \\ & \text{s.t.} & x_1, x_2 \geq 0\end{array}\f$ \code - #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpMatrix Q(2,2), C(3,2); diff --git a/modules/core/src/tools/serial/vpSerial.cpp b/modules/core/src/tools/serial/vpSerial.cpp index dc67b13159..cbf311b474 100644 --- a/modules/core/src/tools/serial/vpSerial.cpp +++ b/modules/core/src/tools/serial/vpSerial.cpp @@ -63,28 +63,36 @@ BEGIN_VISP_NAMESPACE /*! Creates a serial port object that opens the port if the parameter is not empty. \code -#include + #include -int main() -{ -#ifndef WIN32 - vpSerial serial("/dev/ttyUSB0"); -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifndef WIN32 + vpSerial serial("/dev/ttyUSB0"); + #endif + } \endcode Otherwise the port needs to be opened using open(). \code -#include - -int main() -{ -#ifndef WIN32 - vpSerial serial; - serial.setPort("/dev/ttyUSB0"); - serial.open(); -#endif -} + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifndef WIN32 + vpSerial serial; + serial.setPort("/dev/ttyUSB0"); + serial.open(); + #endif + } \endcode \param[in] port : Serial port name. A string similar to `/dev/ttyUSB0`, `/dev/ttySO`, `/dev/ttyAMA0`... @@ -95,8 +103,8 @@ int main() \param[in] flowcontrol : Type of flowcontrol used. Default is no flow control. */ -vpSerial::vpSerial(const std::string &port, unsigned long baudrate, bytesize_t bytesize, parity_t parity, - stopbits_t stopbits, flowcontrol_t flowcontrol) + vpSerial::vpSerial(const std::string &port, unsigned long baudrate, bytesize_t bytesize, parity_t parity, + stopbits_t stopbits, flowcontrol_t flowcontrol) : m_port(port), m_fd(-1), m_is_open(false), m_xonxoff(false), m_rtscts(false), m_baudrate(baudrate), m_parity(parity), m_bytesize(bytesize), m_stopbits(stopbits), m_flowcontrol(flowcontrol) { @@ -142,16 +150,20 @@ void vpSerial::setStopbits(const stopbits_t &stopbits) { m_stopbits = stopbits; /*! Set the serial port name. The name is a string similar to `/dev/ttyUSB0`, `/dev/ttySO`, `/dev/ttyAMA0`... \code -#include - -int main() -{ -#ifndef WIN32 - vpSerial serial; - serial.setPort("/dev/ttyUSB0"); - serial.open(); -#endif -} + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifndef WIN32 + vpSerial serial; + serial.setPort("/dev/ttyUSB0"); + serial.open(); + #endif + } \endcode \sa getPort() @@ -203,23 +215,27 @@ void vpSerial::close() The following example shows how to open the serial port `/dev/ttyUSB0` without using the constructor: \code -#include - -int main() -{ -#ifndef WIN32 - vpSerial serial; - - serial.setPort("/dev/ttyUSB0"); - serial.setBaudrate(9600); - serial.setBytesize(vpSerial::eightbits); - serial.setParity(vpSerial::parity_none); - serial.setStopbits(vpSerial::stopbits_one); - serial.setFlowcontrol(vpSerial::flowcontrol_none); - - serial.open(); -#endif -} + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifndef WIN32 + vpSerial serial; + + serial.setPort("/dev/ttyUSB0"); + serial.setBaudrate(9600); + serial.setBytesize(vpSerial::eightbits); + serial.setParity(vpSerial::parity_none); + serial.setStopbits(vpSerial::stopbits_one); + serial.setFlowcontrol(vpSerial::flowcontrol_none); + + serial.open(); + #endif + } \endcode */ diff --git a/modules/core/src/tools/time/vpTime.cpp b/modules/core/src/tools/time/vpTime.cpp index beaa304f7f..9f4a36e5f4 100644 --- a/modules/core/src/tools/time/vpTime.cpp +++ b/modules/core/src/tools/time/vpTime.cpp @@ -334,26 +334,29 @@ characters| CDT | | %% | A % sign The following example shows how to use this function: \code -#include + #include -int main() -{ - std::cout << "%Y/%m/%d %H:%M:%S (default): " << vpTime::getDateTime() << std::endl; - std::cout << "%Y-%m-%d_%H.%M.%S format : " << vpTime::getDateTime("%Y-%m-%d_%H.%M.%S") << std::endl; - std::cout << "%F format : " << vpTime::getDateTime("%F") << std::endl; - std::cout << "%X format : " << vpTime::getDateTime("%X") << std::endl; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - return 0; -} - \endcode - It produces the following output: - \code -%Y/%m/%d %H:%M:%S (default): 2016/10/05 19:42:44 -%Y-%m-%d_%H.%M.%S format : 2016-10-05_19.42.44 -%F format : 2016-10-05 -%X format : 19:42:44 - \endcode + int main() + { + std::cout << "%Y/%m/%d %H:%M:%S (default): " << vpTime::getDateTime() << std::endl; + std::cout << "%Y-%m-%d_%H.%M.%S format : " << vpTime::getDateTime("%Y-%m-%d_%H.%M.%S") << std::endl; + std::cout << "%F format : " << vpTime::getDateTime("%F") << std::endl; + std::cout << "%X format : " << vpTime::getDateTime("%X") << std::endl; + return 0; + } + \endcode + It produces the following output: + \code + %Y/%m/%d %H:%M:%S (default): 2016/10/05 19:42:44 + %Y-%m-%d_%H.%M.%S format : 2016-10-05_19.42.44 + %F format : 2016-10-05 + %X format : 19:42:44 + \endcode */ std::string getDateTime(const std::string &format) { diff --git a/modules/core/src/tracking/moments/vpMoment.cpp b/modules/core/src/tracking/moments/vpMoment.cpp index 144423d381..f3be8a454c 100644 --- a/modules/core/src/tracking/moments/vpMoment.cpp +++ b/modules/core/src/tracking/moments/vpMoment.cpp @@ -47,7 +47,7 @@ BEGIN_VISP_NAMESPACE * \param os : a std::stream. * \param m : a moment instance. */ -VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMoment &m) + VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMoment &m) { for (std::vector::const_iterator i = m.values.begin(); i != m.values.end(); ++i) os << *i << ","; @@ -73,6 +73,10 @@ vpMoment::vpMoment() : object(nullptr), moments(nullptr), values() { } * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpPoint p; diff --git a/modules/core/src/tracking/moments/vpMomentCommon.cpp b/modules/core/src/tracking/moments/vpMomentCommon.cpp index c15a7c4984..9132d0d683 100644 --- a/modules/core/src/tracking/moments/vpMomentCommon.cpp +++ b/modules/core/src/tracking/moments/vpMomentCommon.cpp @@ -84,6 +84,10 @@ vpMomentCommon::vpMomentCommon(double dstSurface, const std::vector &ref #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { // Define two discrete points diff --git a/modules/core/src/tracking/moments/vpMomentObject.cpp b/modules/core/src/tracking/moments/vpMomentObject.cpp index 5abf0b7514..d680215d05 100644 --- a/modules/core/src/tracking/moments/vpMomentObject.cpp +++ b/modules/core/src/tracking/moments/vpMomentObject.cpp @@ -165,65 +165,72 @@ void vpMomentObject::cacheValues(std::vector &cache, double x, double y, \param points : Vector of points. The code below shows how to use this function to consider a dense object -defined by a closed contour. + defined by a closed contour. \code -#include -#include + #include + #include -int main() -{ - // Define the contour of an object by a 5 clockwise vertices on a plane - vpPoint p; - std::vector vec_p; // vector that contains the vertices of the contour polygon - - p.set_x(-0.2); p.set_y(0.1); // coordinates in meters in the image plane (vertex 1) - vec_p.push_back(p); - p.set_x(+0.3); p.set_y(0.1); // coordinates in meters in the image plane (vertex 2) - vec_p.push_back(p); - p.set_x(+0.2); p.set_y(-0.1); // coordinates in meters in the image plane (vertex 3) - vec_p.push_back(p); - p.set_x(-0.2); p.set_y(-0.15); // coordinates in meters in the image plane (vertex 4) - vec_p.push_back(p); - p.set_x(-0.2); p.set_y(0.1); // close the contour (vertex 5 = vertex 1) - vec_p.push_back(p); - - vpMomentObject obj(4); // Create an image moment object with 4 as maximum order - obj.setType(vpMomentObject::DENSE_POLYGON); // The object is defined by a countour polygon - obj.fromVector(vec_p); // Init the dense object with the polygon - - return 0; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + // Define the contour of an object by a 5 clockwise vertices on a plane + vpPoint p; + std::vector vec_p; // vector that contains the vertices of the contour polygon + + p.set_x(-0.2); p.set_y(0.1); // coordinates in meters in the image plane (vertex 1) + vec_p.push_back(p); + p.set_x(+0.3); p.set_y(0.1); // coordinates in meters in the image plane (vertex 2) + vec_p.push_back(p); + p.set_x(+0.2); p.set_y(-0.1); // coordinates in meters in the image plane (vertex 3) + vec_p.push_back(p); + p.set_x(-0.2); p.set_y(-0.15); // coordinates in meters in the image plane (vertex 4) + vec_p.push_back(p); + p.set_x(-0.2); p.set_y(0.1); // close the contour (vertex 5 = vertex 1) + vec_p.push_back(p); + + vpMomentObject obj(4); // Create an image moment object with 4 as maximum order + obj.setType(vpMomentObject::DENSE_POLYGON); // The object is defined by a countour polygon + obj.fromVector(vec_p); // Init the dense object with the polygon + + return 0; + } \endcode This other example shows how to consider an object as a discrete set of four points. \code -#include -#include + #include + #include -int main() -{ - // Define 4 discrete points on a plane - vpPoint p; - std::vector vec_p; // vector that contains the 4 points - - p.set_x(-0.2); p.set_y(0.1); // coordinates in meters in the image plane (point 1) - vec_p.push_back(p); - p.set_x(+0.3); p.set_y(0.1); // coordinates in meters in the image plane (point 2) - vec_p.push_back(p); - p.set_x(+0.2); p.set_y(-0.1); // coordinates in meters in the image plane (point 3) - vec_p.push_back(p); - p.set_x(-0.2); p.set_y(-0.15); // coordinates in meters in the image plane (point 4) - vec_p.push_back(p); - - vpMomentObject obj(4); // Create an image moment object with 4 as maximum order - obj.setType(vpMomentObject::DISCRETE); // The object is constituted by discrete points - obj.fromVector(vec_p); // Init the dense object with the points - - return 0; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() + { + // Define 4 discrete points on a plane + vpPoint p; + std::vector vec_p; // vector that contains the 4 points + + p.set_x(-0.2); p.set_y(0.1); // coordinates in meters in the image plane (point 1) + vec_p.push_back(p); + p.set_x(+0.3); p.set_y(0.1); // coordinates in meters in the image plane (point 2) + vec_p.push_back(p); + p.set_x(+0.2); p.set_y(-0.1); // coordinates in meters in the image plane (point 3) + vec_p.push_back(p); + p.set_x(-0.2); p.set_y(-0.15); // coordinates in meters in the image plane (point 4) + vec_p.push_back(p); + + vpMomentObject obj(4); // Create an image moment object with 4 as maximum order + obj.setType(vpMomentObject::DISCRETE); // The object is constituted by discrete points + obj.fromVector(vec_p); // Init the dense object with the points + + return 0; + } \endcode */ void vpMomentObject::fromVector(std::vector &points) @@ -264,25 +271,29 @@ void vpMomentObject::fromVector(std::vector &points) The code below shows how to use this function. \code -#include -#include + #include + #include -int main() -{ - vpCameraParameters cam; // Camera parameters used for pixel to -meter conversion vpImage I(288, 384); // Image used to define -the object - // ... Initialize the image + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - unsigned char threshold = 128; // Gray level used to define which part of -the image belong to the dense object + int main() + { + vpCameraParameters cam; // Camera parameters used for pixel to + meter conversion vpImage I(288, 384); // Image used to define + the object + // ... Initialize the image - vpMomentObject obj(3); // Create an image moment object with 3 as maximum -order obj.fromImage(I, threshold, cam); // Initialize the object from the -image + unsigned char threshold = 128; // Gray level used to define which part of + the image belong to the dense object - return 0; -} + vpMomentObject obj(3); // Create an image moment object with 3 as maximum + order obj.fromImage(I, threshold, cam); // Initialize the object from the + image + + return 0; + } \endcode */ diff --git a/modules/detection/include/visp3/detection/vpDetectorAprilTag.h b/modules/detection/include/visp3/detection/vpDetectorAprilTag.h index 47d9cd0cfe..b560eab912 100644 --- a/modules/detection/include/visp3/detection/vpDetectorAprilTag.h +++ b/modules/detection/include/visp3/detection/vpDetectorAprilTag.h @@ -74,6 +74,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #ifdef VISP_HAVE_APRILTAG @@ -118,6 +122,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #ifdef VISP_HAVE_APRILTAG @@ -165,6 +173,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #ifdef VISP_HAVE_APRILTAG diff --git a/modules/detection/include/visp3/detection/vpDetectorDataMatrixCode.h b/modules/detection/include/visp3/detection/vpDetectorDataMatrixCode.h index d7b6a130ad..091ee8b140 100644 --- a/modules/detection/include/visp3/detection/vpDetectorDataMatrixCode.h +++ b/modules/detection/include/visp3/detection/vpDetectorDataMatrixCode.h @@ -66,6 +66,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #ifdef VISP_HAVE_DMTX diff --git a/modules/detection/include/visp3/detection/vpDetectorFace.h b/modules/detection/include/visp3/detection/vpDetectorFace.h index ed5514fb4e..46e3e8c3fe 100644 --- a/modules/detection/include/visp3/detection/vpDetectorFace.h +++ b/modules/detection/include/visp3/detection/vpDetectorFace.h @@ -62,6 +62,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_OBJDETECT) diff --git a/modules/detection/include/visp3/detection/vpDetectorQRCode.h b/modules/detection/include/visp3/detection/vpDetectorQRCode.h index 1ceb0f780d..c1f014e54a 100644 --- a/modules/detection/include/visp3/detection/vpDetectorQRCode.h +++ b/modules/detection/include/visp3/detection/vpDetectorQRCode.h @@ -66,6 +66,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #ifdef VISP_HAVE_ZBAR diff --git a/modules/gui/include/visp3/gui/vpDisplayD3D.h b/modules/gui/include/visp3/gui/vpDisplayD3D.h index 75def030fe..2925185b5a 100644 --- a/modules/gui/include/visp3/gui/vpDisplayD3D.h +++ b/modules/gui/include/visp3/gui/vpDisplayD3D.h @@ -60,6 +60,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined(VISP_HAVE_D3D9) diff --git a/modules/gui/include/visp3/gui/vpDisplayGDI.h b/modules/gui/include/visp3/gui/vpDisplayGDI.h index c0a86550ab..4f19658940 100644 --- a/modules/gui/include/visp3/gui/vpDisplayGDI.h +++ b/modules/gui/include/visp3/gui/vpDisplayGDI.h @@ -58,6 +58,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined(VISP_HAVE_GDI) diff --git a/modules/gui/include/visp3/gui/vpDisplayGTK.h b/modules/gui/include/visp3/gui/vpDisplayGTK.h index f97e887d07..1bb8ba001f 100644 --- a/modules/gui/include/visp3/gui/vpDisplayGTK.h +++ b/modules/gui/include/visp3/gui/vpDisplayGTK.h @@ -61,6 +61,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined(VISP_HAVE_GTK) diff --git a/modules/gui/include/visp3/gui/vpDisplayOpenCV.h b/modules/gui/include/visp3/gui/vpDisplayOpenCV.h index e2d431ed5f..5779a4bcd4 100644 --- a/modules/gui/include/visp3/gui/vpDisplayOpenCV.h +++ b/modules/gui/include/visp3/gui/vpDisplayOpenCV.h @@ -74,6 +74,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined(VISP_HAVE_OPENCV) diff --git a/modules/gui/include/visp3/gui/vpDisplayX.h b/modules/gui/include/visp3/gui/vpDisplayX.h index f416d4eed3..2172b15c8f 100644 --- a/modules/gui/include/visp3/gui/vpDisplayX.h +++ b/modules/gui/include/visp3/gui/vpDisplayX.h @@ -67,6 +67,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpImage I; // Grey level image diff --git a/modules/gui/src/display/vpDisplayGTK.cpp b/modules/gui/src/display/vpDisplayGTK.cpp index 7a4acc58ed..8a69d481f1 100644 --- a/modules/gui/src/display/vpDisplayGTK.cpp +++ b/modules/gui/src/display/vpDisplayGTK.cpp @@ -676,15 +676,19 @@ vpDisplayGTK::vpDisplayGTK(vpImage &I, int win_x, int win_y, const std:: To initialize the display size, you need to call init(). \code -#include -#include + #include + #include -int main() -{ - vpDisplayGTK d(100, 200, "My display"); - vpImage I(240,384); - d.init(I); -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpDisplayGTK d(100, 200, "My display"); + vpImage I(240,384); + d.init(I); + } \endcode */ vpDisplayGTK::vpDisplayGTK(int win_x, int win_y, const std::string &win_title) : vpDisplay(), m_impl(new Impl()) @@ -702,15 +706,19 @@ vpDisplayGTK::vpDisplayGTK(int win_x, int win_y, const std::string &win_title) : init(vpImage &, int, int, const std::string &). \code -#include -#include + #include + #include -int main() -{ - vpDisplayGTK d; - vpImage I(240,384); - d.init(I, 100, 200, "My display"); -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpDisplayGTK d; + vpImage I(240,384); + d.init(I, 100, 200, "My display"); + } \endcode */ vpDisplayGTK::vpDisplayGTK() : vpDisplay(), m_impl(new Impl()) { } diff --git a/modules/gui/src/display/vpDisplayOpenCV.cpp b/modules/gui/src/display/vpDisplayOpenCV.cpp index 3fa964631e..653de7caf2 100644 --- a/modules/gui/src/display/vpDisplayOpenCV.cpp +++ b/modules/gui/src/display/vpDisplayOpenCV.cpp @@ -220,15 +220,19 @@ vpDisplayOpenCV::vpDisplayOpenCV(vpImage &I, int x, int y, const std::st To initialize the display size, you need to call init(). \code -#include -#include + #include + #include -int main() -{ - vpDisplayOpenCV d(100, 200, "My display"); - vpImage I(240, 384); - d.init(I); -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpDisplayOpenCV d(100, 200, "My display"); + vpImage I(240, 384); + d.init(I); + } \endcode */ vpDisplayOpenCV::vpDisplayOpenCV(int x, int y, const std::string &title) @@ -276,15 +280,19 @@ vpDisplayOpenCV::vpDisplayOpenCV(int x, int y, const std::string &title) init(vpImage &, int, int, const std::string &). \code -#include -#include + #include + #include -int main() -{ - vpDisplayOpenCV d; - vpImage I(240, 384); - d.init(I, 100, 200, "My display"); -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpDisplayOpenCV d; + vpImage I(240, 384); + d.init(I, 100, 200, "My display"); + } \endcode */ vpDisplayOpenCV::vpDisplayOpenCV() diff --git a/modules/gui/src/display/vpDisplayX.cpp b/modules/gui/src/display/vpDisplayX.cpp index 371fcddc58..e425b0fbfa 100644 --- a/modules/gui/src/display/vpDisplayX.cpp +++ b/modules/gui/src/display/vpDisplayX.cpp @@ -1731,15 +1731,19 @@ vpDisplayX::vpDisplayX(vpImage &I, int x, int y, const std::string &titl To initialize the display size, you need to call init(). \code -#include -#include + #include + #include -int main() -{ - vpDisplayX d(100, 200, "My display"); - vpImage I(240, 384); - d.init(I); -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpDisplayX d(100, 200, "My display"); + vpImage I(240, 384); + d.init(I); + } \endcode */ vpDisplayX::vpDisplayX(int x, int y, const std::string &title) : vpDisplay(), m_impl(new Impl()) @@ -1758,15 +1762,19 @@ vpDisplayX::vpDisplayX(int x, int y, const std::string &title) : vpDisplay(), m_ init(vpImage &, int, int, const std::string &). \code -#include -#include + #include + #include -int main() -{ - vpDisplayX d; - vpImage I(240, 384); - d.init(I, 100, 200, "My display"); -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpDisplayX d; + vpImage I(240, 384); + d.init(I, 100, 200, "My display"); + } \endcode */ vpDisplayX::vpDisplayX() : vpDisplay(), m_impl(new Impl()) { } diff --git a/modules/io/include/visp3/io/vpDiskGrabber.h b/modules/io/include/visp3/io/vpDiskGrabber.h index 891a50b87b..d2f555e307 100644 --- a/modules/io/include/visp3/io/vpDiskGrabber.h +++ b/modules/io/include/visp3/io/vpDiskGrabber.h @@ -66,6 +66,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main(){ * vpImage I; // Grey level image * diff --git a/modules/io/include/visp3/io/vpImageIo.h b/modules/io/include/visp3/io/vpImageIo.h index 25a835c449..ce456a4847 100644 --- a/modules/io/include/visp3/io/vpImageIo.h +++ b/modules/io/include/visp3/io/vpImageIo.h @@ -74,20 +74,24 @@ BEGIN_VISP_NAMESPACE (".pgm" for PGM P5 and ".ppm" for PPM P6). \code -#include + #include -int main() -{ - vpImage I; -#if defined(_WIN32) - std::string filename("C:/Temp/visp-images/Klimt/Klimt.ppm"); -#else // UNIX - std::string filename("/local/soft/ViSP/ViSP-images/Klimt/Klimt.ppm"); -#endif + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpImageIo::read(I, filename); // Convert the color image in a gray level image - vpImageIo::write(I, "Klimt.pgm"); // Write the image in a PGM P5 image file format -} + int main() + { + vpImage I; + #if defined(_WIN32) + std::string filename("C:/Temp/visp-images/Klimt/Klimt.ppm"); + #else // UNIX + std::string filename("/local/soft/ViSP/ViSP-images/Klimt/Klimt.ppm"); + #endif + + vpImageIo::read(I, filename); // Convert the color image in a gray level image + vpImageIo::write(I, "Klimt.pgm"); // Write the image in a PGM P5 image file format + } \endcode This other example available in tutorial-image-reader.cpp shows how to diff --git a/modules/io/include/visp3/io/vpParallelPort.h b/modules/io/include/visp3/io/vpParallelPort.h index 8dab7b75d7..08f574b652 100644 --- a/modules/io/include/visp3/io/vpParallelPort.h +++ b/modules/io/include/visp3/io/vpParallelPort.h @@ -61,17 +61,21 @@ BEGIN_VISP_NAMESPACE The code below shows how to send a data over the parallel port. \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_PARPORT - vpParallelPort parport; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - unsigned char data = 5; // 0x00000101 = 5 in decimal - parport.sendData(data); // D0 and D2 are set to logical level 1 -#endif -} + int main() + { + #ifdef VISP_HAVE_PARPORT + vpParallelPort parport; + + unsigned char data = 5; // 0x00000101 = 5 in decimal + parport.sendData(data); // D0 and D2 are set to logical level 1 + #endif + } \endcode */ diff --git a/modules/io/include/visp3/io/vpVideoReader.h b/modules/io/include/visp3/io/vpVideoReader.h index 6886e37cde..1e2a9ebb3a 100644 --- a/modules/io/include/visp3/io/vpVideoReader.h +++ b/modules/io/include/visp3/io/vpVideoReader.h @@ -89,6 +89,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #ifdef VISP_HAVE_OPENCV @@ -122,6 +126,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpImage I; @@ -145,6 +153,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpImage I; diff --git a/modules/io/include/visp3/io/vpVideoWriter.h b/modules/io/include/visp3/io/vpVideoWriter.h index d17225037d..99601c7b95 100644 --- a/modules/io/include/visp3/io/vpVideoWriter.h +++ b/modules/io/include/visp3/io/vpVideoWriter.h @@ -87,68 +87,76 @@ BEGIN_VISP_NAMESPACE #include #include -int main() -{ - vpImage I; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpVideoWriter writer; + int main() + { + vpImage I; - //Initialize the writer. - writer.setFileName("./image/image%04d.jpeg"); + vpVideoWriter writer; - writer.open(I); + //Initialize the writer. + writer.setFileName("./image/image%04d.jpeg"); - for ( ; ; ) - { - //Here the code to capture or create an image and stores it in I. + writer.open(I); - //Save the image - writer.saveFrame(I); - } + for ( ; ; ) + { + //Here the code to capture or create an image and stores it in I. - writer.close(); + //Save the image + writer.saveFrame(I); + } - return 0; - } + writer.close(); + + return 0; + } \endcode The other following example explains how to use the class to write directly an mpeg file. \code -#include + #include -int main() -{ -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_VIDEOIO) && defined(HAVE_OPENCV_HIGHGUI) - vpImage I; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpVideoWriter writer; + int main() + { + #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_VIDEOIO) && defined(HAVE_OPENCV_HIGHGUI) + vpImage I; - // Set up the framerate to 30Hz. Default is 25Hz. - writer.setFramerate(30); + vpVideoWriter writer; -#if VISP_HAVE_OPENCV_VERSION >= 0x030000 - writer.setCodec(cv::VideoWriter::fourcc('P', 'I', 'M', '1')); -#else - writer.setCodec(CV_FOURCC('P', 'I', 'M', '1')); -#endif + // Set up the framerate to 30Hz. Default is 25Hz. + writer.setFramerate(30); - writer.setFileName("./test.mpeg"); + #if VISP_HAVE_OPENCV_VERSION >= 0x030000 + writer.setCodec(cv::VideoWriter::fourcc('P', 'I', 'M', '1')); + #else + writer.setCodec(CV_FOURCC('P', 'I', 'M', '1')); + #endif - writer.open(I); + writer.setFileName("./test.mpeg"); - for (; ; ) { - // Here the code to capture or create an image and store it in I. + writer.open(I); - // Save the image - writer.saveFrame(I); - } + for (; ; ) { + // Here the code to capture or create an image and store it in I. - writer.close(); -#endif - return 0; -} + // Save the image + writer.saveFrame(I); + } + + writer.close(); + #endif + return 0; + } \endcode */ diff --git a/modules/io/src/video/vpVideoReader.cpp b/modules/io/src/video/vpVideoReader.cpp index c96bf97e16..b5f85268d2 100644 --- a/modules/io/src/video/vpVideoReader.cpp +++ b/modules/io/src/video/vpVideoReader.cpp @@ -805,22 +805,26 @@ bool vpVideoReader::isVideoExtensionSupported() const \param I : The captured image. \code -#include + #include -int main() -{ - vpImage I; - vpVideoReader reader; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Initialize the reader. - reader.setFileName("./image/image%04d.jpeg"); - reader.setFirstFrameIndex(10); - reader.setLastFrameIndex(20); - reader.open(I); + int main() + { + vpImage I; + vpVideoReader reader; - while (! reader.end() ) - reader >> I; -} + // Initialize the reader. + reader.setFileName("./image/image%04d.jpeg"); + reader.setFirstFrameIndex(10); + reader.setLastFrameIndex(20); + reader.open(I); + + while (! reader.end() ) + reader >> I; + } \endcode */ vpVideoReader &vpVideoReader::operator>>(vpImage &I) @@ -834,22 +838,26 @@ vpVideoReader &vpVideoReader::operator>>(vpImage &I) \param I : The captured image. \code -#include + #include -int main() -{ - vpImage I; - vpVideoReader reader; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Initialize the reader. - reader.setFileName("./image/image%04d.jpeg"); - reader.setFirstFrameIndex(10); - reader.setLastFrameIndex(20); - reader.open(I); + int main() + { + vpImage I; + vpVideoReader reader; - while (! reader.end() ) - reader >> I; -} + // Initialize the reader. + reader.setFileName("./image/image%04d.jpeg"); + reader.setFirstFrameIndex(10); + reader.setLastFrameIndex(20); + reader.open(I); + + while (! reader.end() ) + reader >> I; + } \endcode */ vpVideoReader &vpVideoReader::operator>>(vpImage &I) diff --git a/modules/robot/include/visp3/robot/vpImageSimulator.h b/modules/robot/include/visp3/robot/vpImageSimulator.h index 6bc6e0664e..9ea5492c4b 100644 --- a/modules/robot/include/visp3/robot/vpImageSimulator.h +++ b/modules/robot/include/visp3/robot/vpImageSimulator.h @@ -71,6 +71,10 @@ #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage Icamera(480,640,vpRGBa(0)); diff --git a/modules/robot/include/visp3/robot/vpQbSoftHand.h b/modules/robot/include/visp3/robot/vpQbSoftHand.h index ae0aa96d47..d7d31f134f 100644 --- a/modules/robot/include/visp3/robot/vpQbSoftHand.h +++ b/modules/robot/include/visp3/robot/vpQbSoftHand.h @@ -67,6 +67,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpQbSoftHand qbsofthand; diff --git a/modules/robot/include/visp3/robot/vpRingLight.h b/modules/robot/include/visp3/robot/vpRingLight.h index 2fd6a04d36..8515ef233f 100644 --- a/modules/robot/include/visp3/robot/vpRingLight.h +++ b/modules/robot/include/visp3/robot/vpRingLight.h @@ -63,46 +63,51 @@ BEGIN_VISP_NAMESPACE the lighting system. \code -#include -#include -#include - -int main() -{ -#if defined(VISP_HAVE_PARPORT) && defined(VISP_HAVE_DC1394) - vp1394TwoGrabber g; // Firewire framegrabber based on libdc1394-2.x third party lib - vpImage I; - - vpRingLight light; // Open the device to access to the ring light. - - for (int i=0; i < 10; i++) { - light.pulse(); // Send a pulse to the lighting system - g.acquire(I); // Acquire an image + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_PARPORT) && defined(VISP_HAVE_DC1394) + vp1394TwoGrabber g; // Firewire framegrabber based on libdc1394-2.x third party lib + vpImage I; + + vpRingLight light; // Open the device to access to the ring light. + + for (int i=0; i < 10; i++) { + light.pulse(); // Send a pulse to the lighting system + g.acquire(I); // Acquire an image + } + #endif } -#endif -} \endcode Here is an example showing how to turn on the lighting during 10 seconds. \code -#include -#include - -int main() -{ -#ifdef VISP_HAVE_PARPORT - vpRingLight light; // Open the device to access to the ring light. - - int nsec = 10; // Time to wait in seconds - light.on(); // Turn the ring light on - vpTime::wait(nsec * 1000); // Wait 10 s - light.off(); // and then turn the ring light off -#endif -} + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_PARPORT + vpRingLight light; // Open the device to access to the ring light. + + int nsec = 10; // Time to wait in seconds + light.on(); // Turn the ring light on + vpTime::wait(nsec * 1000); // Wait 10 s + light.off(); // and then turn the ring light off + #endif + } \endcode - - - */ class VISP_EXPORT vpRingLight { diff --git a/modules/robot/include/visp3/robot/vpRobotAfma6.h b/modules/robot/include/visp3/robot/vpRobotAfma6.h index 8eeeb304ae..22eadd4c7b 100644 --- a/modules/robot/include/visp3/robot/vpRobotAfma6.h +++ b/modules/robot/include/visp3/robot/vpRobotAfma6.h @@ -100,16 +100,18 @@ BEGIN_VISP_NAMESPACE class by calling the default constructor: \code -#include + #include -#ifdef VISP_HAVE_AFMA6 -int main() -{ - vpRobotAfma6 robot; -} -#else -int main() {} -#endif + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_AFMA6 + vpRobotAfma6 robot; + #endif + } \endcode This initialize the robot kinematics with the eMc extrinsic camera diff --git a/modules/robot/include/visp3/robot/vpRobotBiclops.h b/modules/robot/include/visp3/robot/vpRobotBiclops.h index e0e375363b..4a7d4327ab 100644 --- a/modules/robot/include/visp3/robot/vpRobotBiclops.h +++ b/modules/robot/include/visp3/robot/vpRobotBiclops.h @@ -105,6 +105,10 @@ class VISP_EXPORT vpRobotBiclops : public vpBiclops, public vpRobot * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #ifdef VISP_HAVE_BICLOPS @@ -136,6 +140,10 @@ class VISP_EXPORT vpRobotBiclops : public vpBiclops, public vpRobot * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #ifdef VISP_HAVE_BICLOPS diff --git a/modules/robot/include/visp3/robot/vpRobotCamera.h b/modules/robot/include/visp3/robot/vpRobotCamera.h index 6ecdd1bf64..15f2c81976 100644 --- a/modules/robot/include/visp3/robot/vpRobotCamera.h +++ b/modules/robot/include/visp3/robot/vpRobotCamera.h @@ -76,32 +76,36 @@ BEGIN_VISP_NAMESPACE The following code shows how to control this robot in position and velocity. \code -#include - -int main() -{ - vpHomogeneousMatrix cMw; - vpRobotCamera robot; - - robot.getPosition(cMw); // Position of the world frame in the camera frame - std::cout << "Default position of the world frame in the camera frame cMw:\n" << cMw << std::endl; - - cMw[2][3] = 1.; // World frame is 1 meter along z axis in front of the camera frame - robot.setPosition(cMw); // Set the new position of the world frame in the camera frame - std::cout << "New position of the world frame in the camera frame cMw:\n" << cMw << std::endl; - - robot.setSamplingTime(0.100); // Modify the default sampling time to 0.1 second - robot.setMaxTranslationVelocity(1.); // vx, vy and vz max set to 1 m/s - robot.setMaxRotationVelocity(vpMath::rad(90)); // wx, wy and wz max set to 90 deg/s - - vpColVector v(6); - v = 0; - v[2] = 1.; // set v_z to 1 m/s - robot.setVelocity(vpRobot::CAMERA_FRAME, v); - // The robot has moved from 0.1 meters along the z axis - robot.getPosition(cMw); // Position of the world frame in the camera frame - std::cout << "New position of the camera cMw:\n" << cMw << std::endl; -} + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpHomogeneousMatrix cMw; + vpRobotCamera robot; + + robot.getPosition(cMw); // Position of the world frame in the camera frame + std::cout << "Default position of the world frame in the camera frame cMw:\n" << cMw << std::endl; + + cMw[2][3] = 1.; // World frame is 1 meter along z axis in front of the camera frame + robot.setPosition(cMw); // Set the new position of the world frame in the camera frame + std::cout << "New position of the world frame in the camera frame cMw:\n" << cMw << std::endl; + + robot.setSamplingTime(0.100); // Modify the default sampling time to 0.1 second + robot.setMaxTranslationVelocity(1.); // vx, vy and vz max set to 1 m/s + robot.setMaxRotationVelocity(vpMath::rad(90)); // wx, wy and wz max set to 90 deg/s + + vpColVector v(6); + v = 0; + v[2] = 1.; // set v_z to 1 m/s + robot.setVelocity(vpRobot::CAMERA_FRAME, v); + // The robot has moved from 0.1 meters along the z axis + robot.getPosition(cMw); // Position of the world frame in the camera frame + std::cout << "New position of the camera cMw:\n" << cMw << std::endl; + } \endcode */ diff --git a/modules/robot/include/visp3/robot/vpRobotViper650.h b/modules/robot/include/visp3/robot/vpRobotViper650.h index 5472c48c65..e4f0a3c563 100644 --- a/modules/robot/include/visp3/robot/vpRobotViper650.h +++ b/modules/robot/include/visp3/robot/vpRobotViper650.h @@ -136,14 +136,18 @@ BEGIN_VISP_NAMESPACE class by calling the default constructor: \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + #endif + } \endcode This initialize the robot kinematics with the \f$^e{\bf M}_c\f$ @@ -153,47 +157,55 @@ int main() distortion you need to initialize the robot with: \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Set the extrinsic camera parameters obtained with a perpective - // projection model including a distortion parameter - robot.init(vpViper650::TOOL_MARLIN_F033C_CAMERA, - vpCameraParameters::perspectiveProjWithDistortion); -#endif -} + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + + // Set the extrinsic camera parameters obtained with a perpective + // projection model including a distortion parameter + robot.init(vpViper650::TOOL_MARLIN_F033C_CAMERA, + vpCameraParameters::perspectiveProjWithDistortion); + #endif + } \endcode You can get the intrinsic camera parameters of an image acquired by the camera attached to the robot, with: \code -#include -#include -#include -#include + #include + #include + #include + #include -int main() -{ -#if defined(VISP_HAVE_VIPER650) && defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g; - g.acquire(I); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotViper650 robot; + int main() + { + #if defined(VISP_HAVE_VIPER650) && defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g; + g.acquire(I); - // ... + vpRobotViper650 robot; - vpCameraParameters cam; - robot.getCameraParameters(cam, I); - // In cam, you get the intrinsic parameters of the projection model - // with distortion. -#endif -} + // ... + + vpCameraParameters cam; + robot.getCameraParameters(cam, I); + // In cam, you get the intrinsic parameters of the projection model + // with distortion. + #endif + } \endcode To control the robot in position, you may set the controller @@ -201,31 +213,35 @@ int main() frame like here in the joint space: \code -#include -#include -#include + #include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; - - vpColVector q(6); - // Set a joint position - q[0] = vpMath::rad(10); // Joint 1 position, in rad - q[1] = 0.2; // Joint 2 position, in rad - q[2] = 0.3; // Joint 3 position, in rad - q[3] = M_PI/8; // Joint 4 position, in rad - q[4] = M_PI/4; // Joint 5 position, in rad - q[5] = M_PI; // Joint 6 position, in rad - - // Initialize the controller to position control - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - - // Moves the robot in the joint space - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + + vpColVector q(6); + // Set a joint position + q[0] = vpMath::rad(10); // Joint 1 position, in rad + q[1] = 0.2; // Joint 2 position, in rad + q[2] = 0.3; // Joint 3 position, in rad + q[3] = M_PI/8; // Joint 4 position, in rad + q[4] = M_PI/4; // Joint 5 position, in rad + q[5] = M_PI; // Joint 6 position, in rad + + // Initialize the controller to position control + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + + // Moves the robot in the joint space + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); + #endif + } \endcode The robot moves to the specified position with the default @@ -234,28 +250,32 @@ int main() velocity used to reach the desired position. \code -#include -#include -#include + #include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpColVector q(6); - // Set q[i] with i in [0:5] + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; - // Initialize the controller to position control - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpColVector q(6); + // Set q[i] with i in [0:5] - // Set the max velocity to 40% - robot.setPositioningVelocity(40); + // Initialize the controller to position control + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the joint space - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); -#endif -} + // Set the max velocity to 40% + robot.setPositioningVelocity(40); + + // Moves the robot in the joint space + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); + #endif + } \endcode To control the robot in velocity, you may set the controller to @@ -265,38 +285,42 @@ int main() space: \code -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; - - vpColVector qvel(6); - // Set a joint velocity - qvel[0] = 0.1; // Joint 1 velocity in rad/s - qvel[1] = vpMath::rad(15); // Joint 2 velocity in rad/s - qvel[2] = 0; // Joint 3 velocity in rad/s - qvel[3] = M_PI/8; // Joint 4 velocity in rad/s - qvel[4] = 0; // Joint 5 velocity in rad/s - qvel[5] = 0; // Joint 6 velocity in rad/s + #include + #include + #include - // Initialize the controller to position control - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - for ( ; ; ) { - // Apply a velocity in the joint space - robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); - - // Compute new velocities qvel... + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + + vpColVector qvel(6); + // Set a joint velocity + qvel[0] = 0.1; // Joint 1 velocity in rad/s + qvel[1] = vpMath::rad(15); // Joint 2 velocity in rad/s + qvel[2] = 0; // Joint 3 velocity in rad/s + qvel[3] = M_PI/8; // Joint 4 velocity in rad/s + qvel[4] = 0; // Joint 5 velocity in rad/s + qvel[5] = 0; // Joint 6 velocity in rad/s + + // Initialize the controller to position control + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + for ( ; ; ) { + // Apply a velocity in the joint space + robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); + + // Compute new velocities qvel... + } + + // Stop the robot + robot.setRobotState(vpRobot::STATE_STOP); + #endif } - - // Stop the robot - robot.setRobotState(vpRobot::STATE_STOP); -#endif -} \endcode It is also possible to specify the position of a custom tool cartesian @@ -304,24 +328,28 @@ int main() frame in \f$^e {\bf M}_c\f$ transformation. This could be done by initializing the robot thanks to init(vpViper650::vpToolType, const vpHomogeneousMatrix &) or init(vpViper650::vpToolType, const std::string &) or using set_eMc(). The - following example illustrates this usecase: + following example illustrates this use case: -\code -#include -#include + \code + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Set the transformation between the end-effector frame - // and the tool frame. - vpHomogeneousMatrix eMc(0.001, 0.0, 0.1, 0.0, 0.0, M_PI/2); + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; - robot.init(vpViper650::TOOL_CUSTOM, eMc); -#endif -} + // Set the transformation between the end-effector frame + // and the tool frame. + vpHomogeneousMatrix eMc(0.001, 0.0, 0.1, 0.0, 0.0, M_PI/2); + + robot.init(vpViper650::TOOL_CUSTOM, eMc); + #endif + } \endcode It is also possible to measure the robot current position with diff --git a/modules/robot/include/visp3/robot/vpRobotViper850.h b/modules/robot/include/visp3/robot/vpRobotViper850.h index 19b3ef13f4..561e85ca7d 100644 --- a/modules/robot/include/visp3/robot/vpRobotViper850.h +++ b/modules/robot/include/visp3/robot/vpRobotViper850.h @@ -64,7 +64,7 @@ extern "C" { #endif BEGIN_VISP_NAMESPACE -/* ! +/*! \class vpRobotViper850 \ingroup group_robot_real_arm @@ -143,14 +143,14 @@ BEGIN_VISP_NAMESPACE class by calling the default constructor: \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; -#endif -} + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; + #endif + } \endcode This initialize the robot kinematics with the \f$^e{\bf M}_c\f$ @@ -160,46 +160,54 @@ int main() distortion you need to initialize the robot with: \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Set the extrinsic camera parameters obtained with a perpective - // projection model including a distortion parameter - robot.init(vpViper850::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); -#endif -} + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; + + // Set the extrinsic camera parameters obtained with a perpective + // projection model including a distortion parameter + robot.init(vpViper850::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); + #endif + } \endcode You can get the intrinsic camera parameters of an image acquired by the camera attached to the robot, with: \code -#include -#include -#include -#include + #include + #include + #include + #include -int main() -{ -#if defined(VISP_HAVE_VIPER850) && defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g; - g.acquire(I); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotViper850 robot; + int main() + { + #if defined(VISP_HAVE_VIPER850) && defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g; + g.acquire(I); - // ... + vpRobotViper850 robot; - vpCameraParameters cam; - robot.getCameraParameters(cam, I); - // In cam, you get the intrinsic parameters of the projection model - // with distortion. -#endif -} + // ... + + vpCameraParameters cam; + robot.getCameraParameters(cam, I); + // In cam, you get the intrinsic parameters of the projection model + // with distortion. + #endif + } \endcode To control the robot in position, you may set the controller @@ -207,31 +215,35 @@ int main() frame like here in the joint space: \code -#include -#include -#include + #include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; - - vpColVector q(6); - // Set a joint position - q[0] = vpMath::rad(10); // Joint 1 position, in rad - q[1] = 0.2; // Joint 2 position, in rad - q[2] = 0.3; // Joint 3 position, in rad - q[3] = M_PI/8; // Joint 4 position, in rad - q[4] = M_PI/4; // Joint 5 position, in rad - q[5] = M_PI; // Joint 6 position, in rad - - // Initialize the controller to position control - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - - // Moves the robot in the joint space - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; + + vpColVector q(6); + // Set a joint position + q[0] = vpMath::rad(10); // Joint 1 position, in rad + q[1] = 0.2; // Joint 2 position, in rad + q[2] = 0.3; // Joint 3 position, in rad + q[3] = M_PI/8; // Joint 4 position, in rad + q[4] = M_PI/4; // Joint 5 position, in rad + q[5] = M_PI; // Joint 6 position, in rad + + // Initialize the controller to position control + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + + // Moves the robot in the joint space + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); + #endif + } \endcode The robot moves to the specified position with the default @@ -240,28 +252,32 @@ int main() velocity used to reach the desired position. \code -#include -#include -#include + #include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpColVector q(6); - // Set q[i] with i in [0:5] + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; - // Initialize the controller to position control - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpColVector q(6); + // Set q[i] with i in [0:5] - // Set the max velocity to 40% - robot.setPositioningVelocity(40); + // Initialize the controller to position control + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the joint space - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); -#endif -} + // Set the max velocity to 40% + robot.setPositioningVelocity(40); + + // Moves the robot in the joint space + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); + #endif + } \endcode To control the robot in velocity, you may set the controller to @@ -271,38 +287,42 @@ int main() space: \code -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; + #include + #include + #include - vpColVector qvel(6); - // Set a joint velocity - qvel[0] = 0.1; // Joint 1 velocity in rad/s - qvel[1] = vpMath::rad(15); // Joint 2 velocity in rad/s - qvel[2] = 0; // Joint 3 velocity in rad/s - qvel[3] = M_PI/8; // Joint 4 velocity in rad/s - qvel[4] = 0; // Joint 5 velocity in rad/s - qvel[5] = 0; // Joint 6 velocity in rad/s + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Initialize the controller to position control - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - for ( ; ; ) { - // Apply a velocity in the joint space - robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); - - // Compute new velocities qvel... + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; + + vpColVector qvel(6); + // Set a joint velocity + qvel[0] = 0.1; // Joint 1 velocity in rad/s + qvel[1] = vpMath::rad(15); // Joint 2 velocity in rad/s + qvel[2] = 0; // Joint 3 velocity in rad/s + qvel[3] = M_PI/8; // Joint 4 velocity in rad/s + qvel[4] = 0; // Joint 5 velocity in rad/s + qvel[5] = 0; // Joint 6 velocity in rad/s + + // Initialize the controller to position control + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + for ( ; ; ) { + // Apply a velocity in the joint space + robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); + + // Compute new velocities qvel... + } + + // Stop the robot + robot.setRobotState(vpRobot::STATE_STOP); + #endif } - - // Stop the robot - robot.setRobotState(vpRobot::STATE_STOP); -#endif -} \endcode It is also possible to specify the position of a custom tool cartesian @@ -313,21 +333,25 @@ int main() following example illustrates this usecase: \code -#include -#include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Set the transformation between the end-effector frame - // and the tool frame. - vpHomogeneousMatrix eMc(0.001, 0.0, 0.1, 0.0, 0.0, M_PI/2); + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; - robot.init(vpViper850::TOOL_CUSTOM, eMc); -#endif -} + // Set the transformation between the end-effector frame + // and the tool frame. + vpHomogeneousMatrix eMc(0.001, 0.0, 0.1, 0.0, 0.0, M_PI/2); + + robot.init(vpViper850::TOOL_CUSTOM, eMc); + #endif + } \endcode It is also possible to measure the robot current position with diff --git a/modules/robot/include/visp3/robot/vpServolens.h b/modules/robot/include/visp3/robot/vpServolens.h index d481c0109c..4b9fc08000 100644 --- a/modules/robot/include/visp3/robot/vpServolens.h +++ b/modules/robot/include/visp3/robot/vpServolens.h @@ -68,24 +68,27 @@ BEGIN_VISP_NAMESPACE the position of the focal lens. \code -#include -#include + #include + #include -int main() -{ - // Open the serial device to communicate with the Servolens lens - vpServolens servolens("/dev/ttyS0"); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + // Open the serial device to communicate with the Servolens lens + vpServolens servolens("/dev/ttyS0"); - // Get the current zoom position - unsigned zoom; - servolens.getPosition(vpServolens::ZOOM, zoom); - std::cout << "Actual zoom value: " << zoom << std::endl; + // Get the current zoom position + unsigned zoom; + servolens.getPosition(vpServolens::ZOOM, zoom); + std::cout << "Actual zoom value: " << zoom << std::endl; - // Set a new zoom value - servolens.setPosition(vpServolens::ZOOM, zoom+1000); -} + // Set a new zoom value + servolens.setPosition(vpServolens::ZOOM, zoom+1000); + } \endcode - */ class VISP_EXPORT vpServolens diff --git a/modules/robot/include/visp3/robot/vpSimulatorAfma6.h b/modules/robot/include/visp3/robot/vpSimulatorAfma6.h index 5db60b04a9..e1f5be05a8 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorAfma6.h +++ b/modules/robot/include/visp3/robot/vpSimulatorAfma6.h @@ -90,6 +90,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpSimulatorAfma6 robot; @@ -126,6 +130,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpSimulatorAfma6 robot; diff --git a/modules/robot/include/visp3/robot/vpSimulatorCamera.h b/modules/robot/include/visp3/robot/vpSimulatorCamera.h index e06efd9373..32f9989857 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorCamera.h +++ b/modules/robot/include/visp3/robot/vpSimulatorCamera.h @@ -72,6 +72,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpHomogeneousMatrix wMc; diff --git a/modules/robot/include/visp3/robot/vpSimulatorPioneer.h b/modules/robot/include/visp3/robot/vpSimulatorPioneer.h index 7221bc0da3..2adda80481 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorPioneer.h +++ b/modules/robot/include/visp3/robot/vpSimulatorPioneer.h @@ -71,6 +71,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpHomogeneousMatrix wMc; diff --git a/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h b/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h index 3c894164cb..1568d87a25 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h +++ b/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h @@ -72,6 +72,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpHomogeneousMatrix wMc; diff --git a/modules/robot/include/visp3/robot/vpSimulatorViper850.h b/modules/robot/include/visp3/robot/vpSimulatorViper850.h index 60722b7512..e0bb962ddc 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorViper850.h +++ b/modules/robot/include/visp3/robot/vpSimulatorViper850.h @@ -89,6 +89,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpSimulatorViper850 robot; @@ -122,6 +126,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpSimulatorViper850 robot; @@ -153,6 +161,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpSimulatorViper850 robot; diff --git a/modules/robot/include/visp3/robot/vpVirtuose.h b/modules/robot/include/visp3/robot/vpVirtuose.h index 32b851b91f..887fdccdc4 100644 --- a/modules/robot/include/visp3/robot/vpVirtuose.h +++ b/modules/robot/include/visp3/robot/vpVirtuose.h @@ -55,11 +55,10 @@ BEGIN_VISP_NAMESPACE \class vpVirtuose \ingroup group_robot_haptic - This class was tested with Haption (http://www.haption.com) Virtuose 6D -haptic device. + This class was tested with Haption (http://www.haption.com) Virtuose 6D haptic device. The class vpVirtuose allows to work with the original Virtuose API inside -ViSP. The Virtuose API supports the following devices: + ViSP. The Virtuose API supports the following devices: - Virtuose 6D35-45 - Virtuose 3D35-40 - Virtuose 3D10-20 @@ -68,53 +67,52 @@ ViSP. The Virtuose API supports the following devices: Not all Virtuose API function are implemented in the class. Original Virtuose API functions need to be called with a VirtContext object, -provided by the function getHandler(). + provided by the function getHandler(). The Virtuose library implements different control modes that could be set -using setCommandType(). The choice of the control mode depends on the -application. The following is the description of the main control modes as -described in the Virtuose API documentation. + using setCommandType(). The choice of the control mode depends on the + application. The following is the description of the main control modes as + described in the Virtuose API documentation. 1. Force/position control (impedance mode): the application sends forces and -torques to the device and reads the position and speed of the end-effector -frame. + torques to the device and reads the position and speed of the end-effector + frame. 2. Position/force control (admittance mode): this advanced control mode -allows direct coupling with virtual objects; in that case, the application -sends the position and speed of the center of the object to the device, and -reads the forces and torques to be applied to the object for dynamic -integration. Stiffness and damping are calculated by the embedded software, -knowing the mass and inertia of the object, in order to ensure control - stability. + allows direct coupling with virtual objects; in that case, the application + sends the position and speed of the center of the object to the device, and + reads the forces and torques to be applied to the object for dynamic + integration. Stiffness and damping are calculated by the embedded software, + knowing the mass and inertia of the object, in order to ensure control stability. 3. Position/force with virtual guides: this is the same as above, with -addition of virtual guides (e.g. fixed translation, fixed rotation, etc.). + addition of virtual guides (e.g. fixed translation, fixed rotation, etc.). The Virtuose library defines the following reference frames: 1. The environment frame, corresponding to the origin of the virtual scene; -it is specified by the software application independently of the Virtuose API. + it is specified by the software application independently of the Virtuose API. 2. The observation frame, corresponding generally to the position of the -camera; it is defined with respect to environment frame. This frame location -could be set using setObservationFrame(). + camera; it is defined with respect to environment frame. This frame location + could be set using setObservationFrame(). 3. The base frame, representing the center of the haptic device; it is -defined with respect to the observation frame. This frame location could be -set using setBaseFrame(). + defined with respect to the observation frame. This frame location could be + set using setBaseFrame(). 4. The tool frame corresponds to the base of the tool fixed at the end of -the haptic device, and is defined with respect to the environment frame. + the haptic device, and is defined with respect to the environment frame. 5. The end-effector (avatar) frame corresponds to the position of the user -hand on the device, taking into account the geometry of the tool, and is -defined with respect to tool frame. + hand on the device, taking into account the geometry of the tool, and is + defined with respect to tool frame. The position of the following frames can be defined only once using the API: base frame (with respect to the observation frame) thanks to setBaseFrame() -and end-effector frame (with respect to the tool frame). + and end-effector frame (with respect to the tool frame). The position of the observation frame (with respect to the environment -frame) can be modified dynamically using setObservationFrame(). + frame) can be modified dynamically using setObservationFrame(). The position of the tool frame (with respect to the environment frame) -cannot be modified. + cannot be modified. All values used in the Virtuose API are expressed in physical units using -metric conventions: + metric conventions: - Durations in seconds (s) - Dimensions in meters (m) - Angles in radians (rad) @@ -122,21 +120,25 @@ metric conventions: - Angular velocities in radians per second (rad.s -1 ) - Forces in Newtons (N) - Torques in Newton-meters (N.m) - - Masses in kilogrammes (kg) + - Masses in kilograms (kg) - Inertia components in kg.m2 The following sample code shows how to connect to the haptic device to get -its current joint position: -\code -#include - -int main() -{ - vpVirtuose virtuose; - virtuose.init(); - vpColVector q = virtuose.getArticularPosition(); - std::cout << "Joint position: " << q.t() << std::endl; -} + its current joint position: + \code + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpVirtuose virtuose; + virtuose.init(); + vpColVector q = virtuose.getArticularPosition(); + std::cout << "Joint position: " << q.t() << std::endl; + } \endcode */ class VISP_EXPORT vpVirtuose diff --git a/modules/robot/include/visp3/robot/vpWireFrameSimulator.h b/modules/robot/include/visp3/robot/vpWireFrameSimulator.h index d1e4e550ba..8c95d05041 100644 --- a/modules/robot/include/visp3/robot/vpWireFrameSimulator.h +++ b/modules/robot/include/visp3/robot/vpWireFrameSimulator.h @@ -116,6 +116,10 @@ BEGIN_VISP_NAMESPACE #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpWireFrameSimulator sim; diff --git a/modules/robot/src/haptic-device/virtuose/vpVirtuose.cpp b/modules/robot/src/haptic-device/virtuose/vpVirtuose.cpp index edda95e56a..7e9098c22e 100644 --- a/modules/robot/src/haptic-device/virtuose/vpVirtuose.cpp +++ b/modules/robot/src/haptic-device/virtuose/vpVirtuose.cpp @@ -48,7 +48,7 @@ BEGIN_VISP_NAMESPACE * Set command type to virtual mechanism by default (impedance mode). * Authorize indexing on all movements by default. */ -vpVirtuose::vpVirtuose() + vpVirtuose::vpVirtuose() : m_virtContext(nullptr), m_ip_port("localhost#5000"), m_verbose(false), m_apiMajorVersion(0), m_apiMinorVersion(0), m_ctrlMajorVersion(0), m_ctrlMinorVersion(0), m_typeCommand(COMMAND_TYPE_IMPEDANCE), m_indexType(INDEXING_ALL), m_is_init(false), m_period(0.001f), m_njoints(6) @@ -332,24 +332,28 @@ vpColVector vpVirtuose::getForce() const device joint positions. This functionality is already implemented in getArticularPosition(). \code -#include + #include -int main() -{ - vpVirtuose virtuose; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpVirtuose virtuose; - virtuose.init(); + virtuose.init(); - VirtContext handler = virtuose.getHandler(); - float q[6]; - if (virtGetArticularPosition(handler, q)) { // Use the handler to access to Haption API directly - std::cout << "Cannot get articular position" << std::endl; + VirtContext handler = virtuose.getHandler(); + float q[6]; + if (virtGetArticularPosition(handler, q)) { // Use the handler to access to Haption API directly + std::cout << "Cannot get articular position" << std::endl; + } + std::cout << "Joint position: "; + for (unsigned int i=0; i<6; i++) + std::cout << q[i] << " "; + std::cout << std::endl; } - std::cout << "Joint position: "; - for (unsigned int i=0; i<6; i++) - std::cout << q[i] << " "; - std::cout << std::endl; -} \endcode \sa getArticularPosition() @@ -838,41 +842,45 @@ void vpVirtuose::setObservationFrame(const vpPoseVector &position) /*! * Register the periodic function. * setPeriodicFunction() defines a callback function to be called at a fixed -period of time, as timing for the simulation. + * period of time, as timing for the simulation. * The callback function is synchronized with the Virtuose controller -(messages arrive at very constant time intervals from it) + * (messages arrive at very constant time intervals from it) * and generates hardware interrupts to be taken into account by the operating -system. + * system. * In practice, this function is much more efficient for timing the simulation -than common software timers. + * than common software timers. * This function is started using startPeriodicFunction() and stopped using -stopPeriodicFunction(). + * stopPeriodicFunction(). * \param CallBackVirt : Callback function. * * Example of the use of the periodic function: - \code -#include - -void CallBackVirtuose(VirtContext VC, void* ptr) -{ - (void) VC; - vpVirtuose* p_virtuose=(vpVirtuose*)ptr; - vpPoseVector position = p_virtuose->getPosition(); - return; -} - -int main() -{ - vpVirtuose virtuose; - float period = 0.001; - virtuose.setTimeStep(period); - virtuose.setPeriodicFunction(CallBackVirtuose, period, virtuose); - virtuose.startPeriodicFunction(); - virtuose.stopPeriodicFunction(); -} - \endcode - - \sa startPeriodicFunction(), stopPeriodicFunction() + * \code + * #include + * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * + * void CallBackVirtuose(VirtContext VC, void* ptr) + * { + * (void) VC; + * vpVirtuose* p_virtuose=(vpVirtuose*)ptr; + * vpPoseVector position = p_virtuose->getPosition(); + * return; + * } + * + * int main() + * { + * vpVirtuose virtuose; + * float period = 0.001; + * virtuose.setTimeStep(period); + * virtuose.setPeriodicFunction(CallBackVirtuose, period, virtuose); + * virtuose.startPeriodicFunction(); + * virtuose.stopPeriodicFunction(); + * } + * \endcode + * + * \sa startPeriodicFunction(), stopPeriodicFunction() */ void vpVirtuose::setPeriodicFunction(VirtPeriodicFunction CallBackVirt) { diff --git a/modules/robot/src/image-simulator/vpImageSimulator.cpp b/modules/robot/src/image-simulator/vpImageSimulator.cpp index 929b522f5b..a56b50d338 100644 --- a/modules/robot/src/image-simulator/vpImageSimulator.cpp +++ b/modules/robot/src/image-simulator/vpImageSimulator.cpp @@ -562,6 +562,10 @@ void vpImageSimulator::getImage(vpImage &I, const vpCameraParameters &ca #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage Icamera(480, 640, vpRGBa(0)); @@ -760,6 +764,10 @@ void vpImageSimulator::getImage(vpImage &I, std::list #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { vpImage Icamera(480, 640, vpRGBa(0)); diff --git a/modules/robot/src/real-robot/afma4/vpServolens.cpp b/modules/robot/src/real-robot/afma4/vpServolens.cpp index fd58b201f8..67a13acc20 100644 --- a/modules/robot/src/real-robot/afma4/vpServolens.cpp +++ b/modules/robot/src/real-robot/afma4/vpServolens.cpp @@ -544,25 +544,29 @@ bool vpServolens::getPosition(vpServoType servo, unsigned int &position) const /*! These parameters are computed from the Dragonfly2 DR2-COL camera sensor -pixel size (7.4 um) and from the servolens zoom position. + pixel size (7.4 um) and from the servolens zoom position. \param I : An image coming from the Dragonfly2 camera attached to the servolens. -\code -#include + \code + #include -int main() -{ - // UNIX vpServolens servolens("/dev/ttyS0"); -#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpImage I(240, 320); - vpCameraParameters cam = servolens.getCameraParameters(I); - std::cout << "Camera parameters: " << cam << std::endl; -#endif - } -\endcode + int main() + { + // UNIX vpServolens servolens("/dev/ttyS0"); + #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) + + vpImage I(240, 320); + vpCameraParameters cam = servolens.getCameraParameters(I); + std::cout << "Camera parameters: " << cam << std::endl; + #endif + } + \endcode \exception vpRobotException::communicationError : If cannot dial with Servolens. diff --git a/modules/robot/src/real-robot/afma6/vpAfma6.cpp b/modules/robot/src/real-robot/afma6/vpAfma6.cpp index 3174f11e2f..34dd820319 100644 --- a/modules/robot/src/real-robot/afma6/vpAfma6.cpp +++ b/modules/robot/src/real-robot/afma6/vpAfma6.cpp @@ -553,45 +553,49 @@ vpHomogeneousMatrix vpAfma6::getForwardKinematics(const vpColVector &q) const The code below shows how to compute the inverse geometric model: \code -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_AFMA6 - vpColVector q1(6), q2(6); - vpHomogeneousMatrix fMc; - - vpRobotAfma6 robot; - - // Get the current articular position of the robot - robot.getPosition(vpRobot::ARTICULAR_FRAME, q1); - - // Compute the pose of the camera in the reference frame using the - // direct geometric model - fMc = robot.getForwardKinematics(q1); - // this is similar to fMc = robot.get_fMc(q1); - // or robot.get_fMc(q1, fMc); - - // Compute the inverse geometric model - int nbsol; // number of solutions (0, 1 or 2) of the inverse geometric model - // get the nearest solution to the current articular position - nbsol = robot.getInverseKinematics(fMc, q1, true); - - if (nbsol == 0) - std::cout << "No solution of the inverse geometric model " << std::endl; - else if (nbsol >= 1) - std::cout << "First solution: " << q1 << std::endl; - - if (nbsol == 2) { - // Compute the other solution of the inverse geometric model - q2 = q1; - robot.getInverseKinematics(fMc, q2, false); - std::cout << "Second solution: " << q2 << std::endl; + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_AFMA6 + vpColVector q1(6), q2(6); + vpHomogeneousMatrix fMc; + + vpRobotAfma6 robot; + + // Get the current articular position of the robot + robot.getPosition(vpRobot::ARTICULAR_FRAME, q1); + + // Compute the pose of the camera in the reference frame using the + // direct geometric model + fMc = robot.getForwardKinematics(q1); + // this is similar to fMc = robot.get_fMc(q1); + // or robot.get_fMc(q1, fMc); + + // Compute the inverse geometric model + int nbsol; // number of solutions (0, 1 or 2) of the inverse geometric model + // get the nearest solution to the current articular position + nbsol = robot.getInverseKinematics(fMc, q1, true); + + if (nbsol == 0) + std::cout << "No solution of the inverse geometric model " << std::endl; + else if (nbsol >= 1) + std::cout << "First solution: " << q1 << std::endl; + + if (nbsol == 2) { + // Compute the other solution of the inverse geometric model + q2 = q1; + robot.getInverseKinematics(fMc, q2, false); + std::cout << "Second solution: " << q2 << std::endl; + } + #endif } -#endif -} \endcode \sa getForwardKinematics() @@ -1224,35 +1228,39 @@ void vpAfma6::set_eMc(const vpHomogeneousMatrix &eMc) attached to the robot. \code -#include -#include -#include -#include - -int main() -{ -#if defined(VISP_HAVE_DC1394) && defined(VISP_HAVE_AFMA6) - vpImage I; - vp1394TwoGrabber g; - - // Acquire an image to update image structure - g.acquire(I) ; - - vpRobotAfma6 robot; - vpCameraParameters cam ; - // Get the intrinsic camera parameters depending on the image size - // Camera parameters are read from - // /udd/fspindle/robot/Afma6/current/include/const_camera_Afma6.xml - // if VISP_HAVE_AFMA6_DATA macro is defined in vpConfig.h file - try { - robot.getCameraParameters (cam, I.getWidth(), I.getHeight()); - } - catch(...) { - std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) && defined(VISP_HAVE_AFMA6) + vpImage I; + vp1394TwoGrabber g; + + // Acquire an image to update image structure + g.acquire(I) ; + + vpRobotAfma6 robot; + vpCameraParameters cam ; + // Get the intrinsic camera parameters depending on the image size + // Camera parameters are read from + // /udd/fspindle/robot/Afma6/current/include/const_camera_Afma6.xml + // if VISP_HAVE_AFMA6_DATA macro is defined in vpConfig.h file + try { + robot.getCameraParameters (cam, I.getWidth(), I.getHeight()); + } + catch(...) { + std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + } + std::cout << "Camera parameters: " << cam << std::endl; + #endif } - std::cout << "Camera parameters: " << cam << std::endl; -#endif -} \endcode \exception vpRobotException::readingParametersError : If the camera @@ -1469,32 +1477,36 @@ void vpAfma6::getCameraParameters(vpCameraParameters &cam, const unsigned int &i \param I : A B&W image send by the current camera in use. \code -#include -#include -#include -#include - -int main() -{ -#if defined(VISP_HAVE_DC1394) && defined(VISP_HAVE_AFMA6) - vpImage I; - vp1394TwoGrabber g; - - // Acquire an image to update image structure - g.acquire(I) ; - - vpRobotAfma6 robot; - vpCameraParameters cam ; - // Get the intrinsic camera parameters depending on the image size - try { - robot.getCameraParameters (cam, I); - } - catch(...) { - std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) && defined(VISP_HAVE_AFMA6) + vpImage I; + vp1394TwoGrabber g; + + // Acquire an image to update image structure + g.acquire(I) ; + + vpRobotAfma6 robot; + vpCameraParameters cam ; + // Get the intrinsic camera parameters depending on the image size + try { + robot.getCameraParameters (cam, I); + } + catch(...) { + std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + } + std::cout << "Camera parameters: " << cam << std::endl; + #endif } - std::cout << "Camera parameters: " << cam << std::endl; -#endif -} \endcode \exception vpRobotException::readingParametersError : If the camera @@ -1515,32 +1527,36 @@ void vpAfma6::getCameraParameters(vpCameraParameters &cam, const vpImage -#include -#include -#include - -int main() -{ -#if defined(VISP_HAVE_DC1394) && defined(VISP_HAVE_AFMA6) - vpImage I; - vp1394TwoGrabber g; - - // Acquire an image to update image structure - g.acquire(I) ; - - vpRobotAfma6 robot; - vpCameraParameters cam ; - // Get the intrinsic camera parameters depending on the image size - try { - robot.getCameraParameters (cam, I); - } - catch(...) { - std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) && defined(VISP_HAVE_AFMA6) + vpImage I; + vp1394TwoGrabber g; + + // Acquire an image to update image structure + g.acquire(I) ; + + vpRobotAfma6 robot; + vpCameraParameters cam ; + // Get the intrinsic camera parameters depending on the image size + try { + robot.getCameraParameters (cam, I); + } + catch(...) { + std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + } + std::cout << "Camera parameters: " << cam << std::endl; + #endif } - std::cout << "Camera parameters: " << cam << std::endl; -#endif -} \endcode \exception vpRobotException::readingParametersError : If the camera diff --git a/modules/robot/src/real-robot/afma6/vpRobotAfma6.cpp b/modules/robot/src/real-robot/afma6/vpRobotAfma6.cpp index 6678162334..0e9ad96c86 100644 --- a/modules/robot/src/real-robot/afma6/vpRobotAfma6.cpp +++ b/modules/robot/src/real-robot/afma6/vpRobotAfma6.cpp @@ -420,20 +420,24 @@ void vpRobotAfma6::set_eMc(const vpHomogeneousMatrix &eMc) M}_c\f$ matrix, use the code below: \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_AFMA6 - vpRobotAfma6 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Set the transformation between the end-effector frame - // and the tool frame. - vpHomogeneousMatrix eMc(0.001, 0.0, 0.1, 0.0, 0.0, M_PI/2); + int main() + { + #ifdef VISP_HAVE_AFMA6 + vpRobotAfma6 robot; - robot.init(vpAfma6::TOOL_CUSTOM, eMc); -#endif -} + // Set the transformation between the end-effector frame + // and the tool frame. + vpHomogeneousMatrix eMc(0.001, 0.0, 0.1, 0.0, 0.0, M_PI/2); + + robot.init(vpAfma6::TOOL_CUSTOM, eMc); + #endif + } \endcode \sa vpCameraParameters, init(), init(vpAfma6::vpAfma6ToolType, @@ -483,35 +487,39 @@ void vpRobotAfma6::init(vpAfma6::vpAfma6ToolType tool, const vpHomogeneousMatrix M}_c\f$ matrix, use the code below: \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_AFMA6 - vpRobotAfma6 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Set the transformation between the end-effector frame - // and the tool frame from a file - std::string filename("./EffectorToolTransformation.cnf"); + int main() + { + #ifdef VISP_HAVE_AFMA6 + vpRobotAfma6 robot; - robot.init(vpAfma6::TOOL_CUSTOM, filename); -#endif -} + // Set the transformation between the end-effector frame + // and the tool frame from a file + std::string filename("./EffectorToolTransformation.cnf"); + + robot.init(vpAfma6::TOOL_CUSTOM, filename); + #endif + } \endcode The configuration file should have the form below: \code -# Start with any number of consecutive lines -# beginning with the symbol '#' -# -# The 3 following lines contain the name of the camera, -# the rotation parameters of the geometric transformation -# using the Euler angles in degrees with convention XYZ and -# the translation parameters expressed in meters -CAMERA CameraName -eMc_ROT_XYZ 10.0 -90.0 20.0 -eMc_TRANS_XYZ 0.05 0.01 0.06 + # Start with any number of consecutive lines + # beginning with the symbol '#' + # + # The 3 following lines contain the name of the camera, + # the rotation parameters of the geometric transformation + # using the Euler angles in degrees with convention XYZ and + # the translation parameters expressed in meters + CAMERA CameraName + eMc_ROT_XYZ 10.0 -90.0 20.0 + eMc_TRANS_XYZ 0.05 0.01 0.06 \endcode \sa init(), init(vpAfma6::vpAfma6ToolType, @@ -959,38 +967,41 @@ three last parameters are the rotations expressed as a theta u vector in position is out of range. \code -#include -#include + #include + #include -int main() -{ -#ifdef VISP_HAVE_AFMA6 - vpPoseVector pose; - // Set positions in the reference frame - pose[0] = 0.1; // x axis, in meter - pose[1] = 0.; // y axis, in meter - pose[2] = 0.3; // z axis, in meter - pose[3] = M_PI/8; // ThetaU rotation around x axis, in rad - pose[4] = M_PI/4; // ThetaU rotation around y axis, in rad - pose[5] = 0.; // ThetaU rotation around z axis, in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotAfma6 robot; + int main() + { + #ifdef VISP_HAVE_AFMA6 + vpPoseVector pose; + // Set positions in the reference frame + pose[0] = 0.1; // x axis, in meter + pose[1] = 0.; // y axis, in meter + pose[2] = 0.3; // z axis, in meter + pose[3] = M_PI/8; // ThetaU rotation around x axis, in rad + pose[4] = M_PI/4; // ThetaU rotation around y axis, in rad + pose[5] = 0.; // ThetaU rotation around z axis, in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpRobotAfma6 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the camera frame - robot.setPosition(vpRobot::REFERENCE_FRAME, pose); + // Set the max velocity to 20% + robot.setPositioningVelocity(20); - return 0; -#endif -} + // Moves the robot in the camera frame + robot.setPosition(vpRobot::REFERENCE_FRAME, pose); + + return 0; + #endif + } \endcode - To catch the exception if the position is out of range, modify the code -like: + To catch the exception if the position is out of range, modify the code like: \code try { @@ -1059,35 +1070,39 @@ void vpRobotAfma6::setPosition(const vpRobot::vpControlFrameType frame, const vp position is out of range. \code -#include -#include -#include + #include + #include + #include -int main() -{ -#ifdef VISP_HAVE_AFMA6 - vpColVector position(6); - // Set positions in the camera frame - position[0] = 0.1; // x axis, in meter - position[1] = 0.2; // y axis, in meter - position[2] = 0.3; // z axis, in meter - position[3] = M_PI/8; // rotation around x axis, in rad - position[4] = M_PI/4; // rotation around y axis, in rad - position[5] = M_PI/10;// rotation around z axis, in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotAfma6 robot; + int main() + { + #ifdef VISP_HAVE_AFMA6 + vpColVector position(6); + // Set positions in the camera frame + position[0] = 0.1; // x axis, in meter + position[1] = 0.2; // y axis, in meter + position[2] = 0.3; // z axis, in meter + position[3] = M_PI/8; // rotation around x axis, in rad + position[4] = M_PI/4; // rotation around y axis, in rad + position[5] = M_PI/10;// rotation around z axis, in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpRobotAfma6 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the camera frame - robot.setPosition(vpRobot::CAMERA_FRAME, position); + // Set the max velocity to 20% + robot.setPositioningVelocity(20); - return 0; -#endif -} + // Moves the robot in the camera frame + robot.setPosition(vpRobot::CAMERA_FRAME, position); + + return 0; + #endif + } \endcode To catch the exception if the position is out of range, modify the code @@ -1265,32 +1280,36 @@ void vpRobotAfma6::setPosition(const vpRobot::vpControlFrameType frame, const vp position is out of range. \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_AFMA6 - // Set positions in the camera frame - double pos1 = 0.1; // x axis, in meter - double pos2 = 0.2; // y axis, in meter - double pos3 = 0.3; // z axis, in meter - double pos4 = M_PI/8; // rotation around x axis, in rad - double pos5 = M_PI/4; // rotation around y axis, in rad - double pos6 = M_PI; // rotation around z axis, in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotAfma6 robot; + int main() + { + #ifdef VISP_HAVE_AFMA6 + // Set positions in the camera frame + double pos1 = 0.1; // x axis, in meter + double pos2 = 0.2; // y axis, in meter + double pos3 = 0.3; // z axis, in meter + double pos4 = M_PI/8; // rotation around x axis, in rad + double pos5 = M_PI/4; // rotation around y axis, in rad + double pos6 = M_PI; // rotation around z axis, in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpRobotAfma6 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the camera frame - robot.setPosition(vpRobot::CAMERA_FRAME, pos1, pos2, pos3, pos4, pos5, pos6); + // Set the max velocity to 20% + robot.setPositioningVelocity(20); - return 0; -#endif -} + // Moves the robot in the camera frame + robot.setPosition(vpRobot::CAMERA_FRAME, pos1, pos2, pos3, pos4, pos5, pos6); + + return 0; + #endif + } \endcode \sa setPosition() @@ -1328,22 +1347,26 @@ void vpRobotAfma6::setPosition(const vpRobot::vpControlFrameType frame, double p This method has the same behavior than the sample code given below; \code -#include -#include + #include + #include -int main() -{ -#ifdef VISP_HAVE_AFMA6 - vpRobotAfma6 robot; - vpColVector q; // joint position + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - robot.readPosFile("MyPositionFilename.pos", q); - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); + int main() + { + #ifdef VISP_HAVE_AFMA6 + vpRobotAfma6 robot; + vpColVector q; // joint position - return 0; -#endif -} + robot.readPosFile("MyPositionFilename.pos", q); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); + + return 0; + #endif + } \endcode \exception vpRobotException::lowLevelError : vpRobot::MIXT_FRAME diff --git a/modules/robot/src/real-robot/universal-robots/vpRobotUniversalRobots.cpp b/modules/robot/src/real-robot/universal-robots/vpRobotUniversalRobots.cpp index 93d275e64f..dac678390f 100644 --- a/modules/robot/src/real-robot/universal-robots/vpRobotUniversalRobots.cpp +++ b/modules/robot/src/real-robot/universal-robots/vpRobotUniversalRobots.cpp @@ -48,7 +48,7 @@ BEGIN_VISP_NAMESPACE * - set max joint speed to 180 deg/s * - set max joint acceleration to 800 deg/s^2 */ -vpRobotUniversalRobots::vpRobotUniversalRobots() : m_rtde_receive(), m_rtde_control(), m_db_client(), m_eMc() + vpRobotUniversalRobots::vpRobotUniversalRobots() : m_rtde_receive(), m_rtde_control(), m_db_client(), m_eMc() { init(); } @@ -561,38 +561,42 @@ void vpRobotUniversalRobots::setPosition(const vpRobot::vpControlFrameType frame * setMaxTranslationVelocity() and setMaxRotationVelocity(). * * \code -#include -#include -#include - -int main() -{ -#if defined(VISP_HAVE_UR_RTDE) - vpRobotUniversalRobots robot; - - vpColVector qd(6); - // Set a joint velocity - qd[0] = 0.1; // Joint 1 velocity in rad/s - qd[1] = vpMath::rad(15); // Joint 2 velocity in rad/s - qd[2] = 0; // Joint 3 velocity in rad/s - qd[3] = M_PI/8; // Joint 4 velocity in rad/s - qd[4] = 0; // Joint 5 velocity in rad/s - qd[5] = 0; // Joint 6 velocity in rad/s - - // Initialize the controller to velocity control - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - while (1) { - // Apply a velocity in the joint space - robot.setVelocity(vpRobot::JOINT_STATE, qvel); - - // Compute new velocities qvel... - } - - // Stop the robot - robot.setRobotState(vpRobot::STATE_STOP); -#endif -} + * #include + * #include + * #include + * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * + * int main() + * { + * #if defined(VISP_HAVE_UR_RTDE) + * vpRobotUniversalRobots robot; + * + * vpColVector qd(6); + * // Set a joint velocity + * qd[0] = 0.1; // Joint 1 velocity in rad/s + * qd[1] = vpMath::rad(15); // Joint 2 velocity in rad/s + * qd[2] = 0; // Joint 3 velocity in rad/s + * qd[3] = M_PI/8; // Joint 4 velocity in rad/s + * qd[4] = 0; // Joint 5 velocity in rad/s + * qd[5] = 0; // Joint 6 velocity in rad/s + * + * // Initialize the controller to velocity control + * robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + * + * while (1) { + * // Apply a velocity in the joint space + * robot.setVelocity(vpRobot::JOINT_STATE, qvel); + * + * // Compute new velocities qvel... + * } + * + * // Stop the robot + * robot.setRobotState(vpRobot::STATE_STOP); + * #endif + * } * \endcode */ void vpRobotUniversalRobots::setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) diff --git a/modules/robot/src/real-robot/viper/vpRobotViper650.cpp b/modules/robot/src/real-robot/viper/vpRobotViper650.cpp index 1b31930418..97963c103e 100644 --- a/modules/robot/src/real-robot/viper/vpRobotViper650.cpp +++ b/modules/robot/src/real-robot/viper/vpRobotViper650.cpp @@ -133,39 +133,43 @@ void emergencyStopViper650(int signo) including the distortion, use the code below: \code -#include -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; - - // Set the extrinsic camera parameters obtained with a perpective - // projection model including a distortion parameter - robot.init(vpViper650::TOOL_MARLIN_F033C_CAMERA, - vpCameraParameters::perspectiveProjWithDistortion); - \endcode + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + + // Set the extrinsic camera parameters obtained with a perpective + // projection model including a distortion parameter + robot.init(vpViper650::TOOL_MARLIN_F033C_CAMERA, + vpCameraParameters::perspectiveProjWithDistortion); + \endcode - Now, you can get the intrinsic camera parameters associated to an - image acquired by the camera attached to the robot, with: + Now, you can get the intrinsic camera parameters associated to an + image acquired by the camera attached to the robot, with: - \code - vpImage I(480, 640); + \code + vpImage I(480, 640); - // Get an image from the camera attached to the robot -#ifdef VISP_HAVE_DC1394 - vp1394TwoGrabber g; - g.acquire(I); -#endif - vpCameraParameters cam; - robot.getCameraParameters(cam, I); - // In cam, you get the intrinsic parameters of the projection model - // with distortion. -#endif -} + // Get an image from the camera attached to the robot + #ifdef VISP_HAVE_DC1394 + vp1394TwoGrabber g; + g.acquire(I); + #endif + vpCameraParameters cam; + robot.getCameraParameters(cam, I); + // In cam, you get the intrinsic parameters of the projection model + // with distortion. + #endif + } \endcode \sa vpCameraParameters, init(vpViper650::vpToolType, @@ -364,38 +368,42 @@ void vpRobotViper650::init(void) including the distortion, use the code below: \code -#include -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; - - // Set the extrinsic camera parameters obtained with a perpective - // projection model including a distortion parameter - robot.init(vpViper650::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + + // Set the extrinsic camera parameters obtained with a perpective + // projection model including a distortion parameter + robot.init(vpViper650::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); \endcode Now, you can get the intrinsic camera parameters associated to an image acquired by the camera attached to the robot, with: \code - vpImage I(480, 640); - - // Get an image from the camera attached to the robot -#ifdef VISP_HAVE_DC1394 - vp1394TwoGrabber g; - g.acquire(I); -#endif - vpCameraParameters cam; - robot.getCameraParameters(cam, I); - // In cam, you get the intrinsic parameters of the projection model - // with distortion. -#endif -} + vpImage I(480, 640); + + // Get an image from the camera attached to the robot + #ifdef VISP_HAVE_DC1394 + vp1394TwoGrabber g; + g.acquire(I); + #endif + vpCameraParameters cam; + robot.getCameraParameters(cam, I); + // In cam, you get the intrinsic parameters of the projection model + // with distortion. + #endif + } \endcode \sa vpCameraParameters, @@ -450,20 +458,24 @@ void vpRobotViper650::init(vpViper650::vpToolType tool, vpCameraParameters::vpCa M}_c\f$ matrix, use the code below: \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Set the transformation between the end-effector frame - // and the tool frame from a file - std::string filename("./EffectorToolTransformation.cnf"); + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; - robot.init(vpViper650::TOOL_CUSTOM, filename); -#endif -} + // Set the transformation between the end-effector frame + // and the tool frame from a file + std::string filename("./EffectorToolTransformation.cnf"); + + robot.init(vpViper650::TOOL_CUSTOM, filename); + #endif + } \endcode The configuration file should have the form below: @@ -530,21 +542,25 @@ void vpRobotViper650::init(vpViper650::vpToolType tool, const std::string &filen M}_c\f$ matrix, use the code below: \code -#include -#include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Set the transformation between the end-effector frame - // and the tool frame. - vpHomogeneousMatrix eMc(0.001, 0.0, 0.1, 0.0, 0.0, M_PI/2); + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; - robot.init(vpViper650::TOOL_CUSTOM, eMc); -#endif -} + // Set the transformation between the end-effector frame + // and the tool frame. + vpHomogeneousMatrix eMc(0.001, 0.0, 0.1, 0.0, 0.0, M_PI/2); + + robot.init(vpViper650::TOOL_CUSTOM, eMc); + #endif + } \endcode \sa vpCameraParameters, init(), init(vpViper650::vpToolType, @@ -1002,26 +1018,30 @@ void vpRobotViper650::get_fJe(vpMatrix &fJe) be in ]0:100]. \code -#include -#include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpColVector position(6); - position = 0; // position in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotViper650 robot; + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpColVector position(6); + position = 0; // position in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpRobotViper650 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot to the joint position [0,0,0,0,0,0] - robot.setPosition(vpRobot::ARTICULAR_FRAME, position); -#endif -} + // Set the max velocity to 20% + robot.setPositioningVelocity(20); + + // Moves the robot to the joint position [0,0,0,0,0,0] + robot.setPosition(vpRobot::ARTICULAR_FRAME, position); + #endif + } \endcode \sa getPositioningVelocity() @@ -1070,36 +1090,39 @@ double vpRobotViper650::getPositioningVelocity(void) const { return m_positionin position is out of range. \code -#include -#include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpColVector position(6); - // Set positions in the camera frame - position[0] = 0.1; // x axis, in meter - position[1] = 0.2; // y axis, in meter - position[2] = 0.3; // z axis, in meter - position[3] = M_PI/8; // rotation around x axis, in rad - position[4] = M_PI/4; // rotation around y axis, in rad - position[5] = M_PI; // rotation around z axis, in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotViper650 robot; + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpColVector position(6); + // Set positions in the camera frame + position[0] = 0.1; // x axis, in meter + position[1] = 0.2; // y axis, in meter + position[2] = 0.3; // z axis, in meter + position[3] = M_PI/8; // rotation around x axis, in rad + position[4] = M_PI/4; // rotation around y axis, in rad + position[5] = M_PI; // rotation around z axis, in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpRobotViper650 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the camera frame - robot.setPosition(vpRobot::CAMERA_FRAME, position); -#endif -} + // Set the max velocity to 20% + robot.setPositioningVelocity(20); + + // Moves the robot in the camera frame + robot.setPosition(vpRobot::CAMERA_FRAME, position); + #endif + } \endcode - To catch the exception if the position is out of range, modify the code -like: + To catch the exception if the position is out of range, modify the code like: \code try { @@ -1269,30 +1292,34 @@ void vpRobotViper650::setPosition(const vpRobot::vpControlFrameType frame, const position is out of range. \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - // Set positions in the camera frame - double pos1 = 0.1; // x axis, in meter - double pos2 = 0.2; // y axis, in meter - double pos3 = 0.3; // z axis, in meter - double pos4 = M_PI/8; // rotation around x axis, in rad - double pos5 = M_PI/4; // rotation around y axis, in rad - double pos6 = M_PI; // rotation around z axis, in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotViper650 robot; + int main() + { + #ifdef VISP_HAVE_VIPER650 + // Set positions in the camera frame + double pos1 = 0.1; // x axis, in meter + double pos2 = 0.2; // y axis, in meter + double pos3 = 0.3; // z axis, in meter + double pos4 = M_PI/8; // rotation around x axis, in rad + double pos5 = M_PI/4; // rotation around y axis, in rad + double pos6 = M_PI; // rotation around z axis, in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpRobotViper650 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the camera frame - robot.setPosition(vpRobot::CAMERA_FRAME, pos1, pos2, pos3, pos4, pos5, pos6); -#endif -} + // Set the max velocity to 20% + robot.setPositioningVelocity(20); + + // Moves the robot in the camera frame + robot.setPosition(vpRobot::CAMERA_FRAME, pos1, pos2, pos3, pos4, pos5, pos6); + #endif + } \endcode \sa setPosition() @@ -1330,20 +1357,24 @@ void vpRobotViper650::setPosition(const vpRobot::vpControlFrameType frame, doubl This method has the same behavior than the sample code given below; \code -#include -#include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpColVector q; - vpRobotViper650 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - robot.readPosFile("MyPositionFilename.pos", q); - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); -#endif -} + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpColVector q; + vpRobotViper650 robot; + + robot.readPosFile("MyPositionFilename.pos", q); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); + #endif + } \endcode \exception vpRobotException::lowLevelError : vpRobot::MIXT_FRAME @@ -1395,39 +1426,43 @@ void vpRobotViper650::setPosition(const std::string &filename) \param timestamp : Time in second since last robot power on. \code -#include -#include -#include -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; - double timestamp; - - vpColVector position; - robot.getPosition(vpRobot::REFERENCE_FRAME, position, timestamp); + #include + #include + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + double timestamp; + + vpColVector position; + robot.getPosition(vpRobot::REFERENCE_FRAME, position, timestamp); + + vpTranslationVector ftc; // reference frame to camera frame translations + vpRxyzVector frc; // reference frame to camera frame rotations + + // Update the transformation between reference frame and camera frame + for (unsigned int i=0; i < 3; i++) { + ftc[i] = position[i]; // tx, ty, tz + frc[i] = position[i+3]; // ry, ry, rz + } - vpTranslationVector ftc; // reference frame to camera frame translations - vpRxyzVector frc; // reference frame to camera frame rotations + // Create a rotation matrix from the Rxyz rotation angles + vpRotationMatrix fRc(frc); // reference frame to camera frame rotation matrix - // Update the transformation between reference frame and camera frame - for (unsigned int i=0; i < 3; i++) { - ftc[i] = position[i]; // tx, ty, tz - frc[i] = position[i+3]; // ry, ry, rz + // Create the camera to fix frame transformation in terms of a + // homogeneous matrix + vpHomogeneousMatrix fMc(ftc, fRc); + #endif } - - // Create a rotation matrix from the Rxyz rotation angles - vpRotationMatrix fRc(frc); // reference frame to camera frame rotation matrix - - // Create the camera to fix frame transformation in terms of a - // homogeneous matrix - vpHomogeneousMatrix fMc(ftc, fRc); -#endif -} \endcode \exception vpRobotException::lowLevelError : If the position cannot @@ -1612,38 +1647,42 @@ reference frame in m/s and rotations \f$ ^{c} \omega_x, ^{c} \omega_y, ^{c} setMaxTranslationVelocity() and setMaxRotationVelocity(). \code -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; - - vpColVector qvel(6); - // Set a joint velocity - qvel[0] = 0.1; // Joint 1 velocity in rad/s - qvel[1] = vpMath::rad(15); // Joint 2 velocity in rad/s - qvel[2] = 0; // Joint 3 velocity in rad/s - qvel[3] = M_PI/8; // Joint 4 velocity in rad/s - qvel[4] = 0; // Joint 5 velocity in rad/s - qvel[5] = 0; // Joint 6 velocity in rad/s - - // Initialize the controller to velocity control - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - while (1) { - // Apply a velocity in the joint space - robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + + vpColVector qvel(6); + // Set a joint velocity + qvel[0] = 0.1; // Joint 1 velocity in rad/s + qvel[1] = vpMath::rad(15); // Joint 2 velocity in rad/s + qvel[2] = 0; // Joint 3 velocity in rad/s + qvel[3] = M_PI/8; // Joint 4 velocity in rad/s + qvel[4] = 0; // Joint 5 velocity in rad/s + qvel[5] = 0; // Joint 6 velocity in rad/s + + // Initialize the controller to velocity control + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + while (1) { + // Apply a velocity in the joint space + robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); + + // Compute new velocities qvel... + } - // Compute new velocities qvel... + // Stop the robot + robot.setRobotState(vpRobot::STATE_STOP); + #endif } - - // Stop the robot - robot.setRobotState(vpRobot::STATE_STOP); -#endif -} \endcode */ void vpRobotViper650::setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) @@ -1788,40 +1827,44 @@ void vpRobotViper650::setVelocity(const vpRobot::vpControlFrameType frame, const first call is used to intialise the velocity computation for the next call. \code -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER650 - // Set requested joint velocities - vpColVector q_dot(6); - q_dot[0] = 0.1; // Joint 1 velocity in rad/s - q_dot[1] = 0.2; // Joint 2 velocity in rad/s - q_dot[2] = 0.3; // Joint 3 velocity in rad/s - q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s - q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s - q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s - - vpRobotViper650 robot; - - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - // Moves the joint in velocity - robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); - - // Initialisation of the velocity measurement - vpColVector q_dot_mes; // Measured velocities - robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); // q_dot_mes =0 - // q_dot_mes is resized to 6, the number of joint - - while (1) { - robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); - vpTime::wait(40); // wait 40 ms - // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER650 + // Set requested joint velocities + vpColVector q_dot(6); + q_dot[0] = 0.1; // Joint 1 velocity in rad/s + q_dot[1] = 0.2; // Joint 2 velocity in rad/s + q_dot[2] = 0.3; // Joint 3 velocity in rad/s + q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s + q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s + q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s + + vpRobotViper650 robot; + + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + // Moves the joint in velocity + robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); + + // Initialisation of the velocity measurement + vpColVector q_dot_mes; // Measured velocities + robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); // q_dot_mes =0 + // q_dot_mes is resized to 6, the number of joint + + while (1) { + robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); + vpTime::wait(40); // wait 40 ms + // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + } + #endif } -#endif -} \endcode */ void vpRobotViper650::getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity, double ×tamp) @@ -1964,41 +2007,45 @@ void vpRobotViper650::getVelocity(const vpRobot::vpControlFrameType frame, vpCol and rotations in rad/s. \code -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER650 - // Set requested joint velocities - vpColVector q_dot(6); - q_dot[0] = 0.1; // Joint 1 velocity in rad/s - q_dot[1] = 0.2; // Joint 2 velocity in rad/s - q_dot[2] = 0.3; // Joint 3 velocity in rad/s - q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s - q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s - q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s - - vpRobotViper650 robot; - - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - // Moves the joint in velocity - robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); - - // Initialisation of the velocity measurement - vpColVector q_dot_mes; // Measured velocities - robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); // q_dot_mes =0 - // q_dot_mes is resized to 6, the number of joint - - double timestamp; - while (1) { - q_dot_mes = robot.getVelocity(vpRobot::ARTICULAR_FRAME, timestamp); - vpTime::wait(40); // wait 40 ms - // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER650 + // Set requested joint velocities + vpColVector q_dot(6); + q_dot[0] = 0.1; // Joint 1 velocity in rad/s + q_dot[1] = 0.2; // Joint 2 velocity in rad/s + q_dot[2] = 0.3; // Joint 3 velocity in rad/s + q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s + q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s + q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s + + vpRobotViper650 robot; + + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + // Moves the joint in velocity + robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); + + // Initialisation of the velocity measurement + vpColVector q_dot_mes; // Measured velocities + robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); // q_dot_mes =0 + // q_dot_mes is resized to 6, the number of joint + + double timestamp; + while (1) { + q_dot_mes = robot.getVelocity(vpRobot::ARTICULAR_FRAME, timestamp); + vpTime::wait(40); // wait 40 ms + // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + } + #endif } -#endif -} \endcode */ vpColVector vpRobotViper650::getVelocity(vpRobot::vpControlFrameType frame, double ×tamp) @@ -2028,67 +2075,71 @@ vpColVector vpRobotViper650::getVelocity(vpRobot::vpControlFrameType frame) /*! -Read joint positions in a specific Viper650 position file. + Read joint positions in a specific Viper650 position file. -This position file has to start with a header. The six joint positions -are given after the "R:" keyword. The first 3 values correspond to the -joint translations X,Y,Z expressed in meters. The 3 last values -correspond to the joint rotations A,B,C expressed in degres to be more -representative for the user. Theses values are then converted in -radians in \e q. The character "#" starting a line indicates a -comment. + This position file has to start with a header. The six joint positions + are given after the "R:" keyword. The first 3 values correspond to the + joint translations X,Y,Z expressed in meters. The 3 last values + correspond to the joint rotations A,B,C expressed in degres to be more + representative for the user. Theses values are then converted in + radians in \e q. The character "#" starting a line indicates a + comment. -A typical content of such a file is given below: + A typical content of such a file is given below: -\code -#Viper - Position - Version 1.0 -# file: "myposition.pos " -# -# R: A B C D E F -# Joint position in degrees -# + \code + #Viper - Position - Version 1.0 + # file: "myposition.pos " + # + # R: A B C D E F + # Joint position in degrees + # + + R: 0.1 0.3 -0.25 -80.5 80 0 + \endcode -R: 0.1 0.3 -0.25 -80.5 80 0 -\endcode + \param filename : Name of the position file to read. -\param filename : Name of the position file to read. + \param q : The six joint positions. Values are expressed in radians. -\param q : The six joint positions. Values are expressed in radians. + \return true if the positions were successfully readen in the file. false, if + an error occurs. -\return true if the positions were successfully readen in the file. false, if -an error occurs. + The code below shows how to read a position from a file and move the robot to + this position. + \code + #include + #include -The code below shows how to read a position from a file and move the robot to -this position. -\code -#include -#include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; - // Enable the position control of the robot - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + // Enable the position control of the robot + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Get the current robot joint positions - vpColVector q; // Current joint position - robot.getPosition(vpRobot::ARTICULAR_FRAME, q); + // Get the current robot joint positions + vpColVector q; // Current joint position + robot.getPosition(vpRobot::ARTICULAR_FRAME, q); - // Save this position in a file named "current.pos" - robot.savePosFile("current.pos", q); + // Save this position in a file named "current.pos" + robot.savePosFile("current.pos", q); - // Get the position from a file and move to the registered position - robot.readPosFile("current.pos", q); // Set the joint position from the file + // Get the position from a file and move to the registered position + robot.readPosFile("current.pos", q); // Set the joint position from the file - robot.setPositioningVelocity(5); // Positioning velocity set to 5% - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); // Move to the joint position -#endif -} -\endcode + robot.setPositioningVelocity(5); // Positioning velocity set to 5% + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); // Move to the joint position + #endif + } + \endcode -\sa savePosFile() + \sa savePosFile() */ bool vpRobotViper650::readPosFile(const std::string &filename, vpColVector &q) @@ -2332,31 +2383,34 @@ void vpRobotViper650::biasForceTorqueSensor() const \param H: [Fx, Fy, Fz, Tx, Ty, Tz] Forces/torques measured by the sensor. - The code below shows how to get the force/torque measures after a sensor -bias. + The code below shows how to get the force/torque measures after a sensor bias. \code -#include -#include -#include + #include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpColVector H; // force/torque measures [Fx, Fy, Fz, Tx, Ty, Tz] + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotViper650 robot; + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpColVector H; // force/torque measures [Fx, Fy, Fz, Tx, Ty, Tz] + + vpRobotViper650 robot; - // Bias the force/torque sensor - robot.biasForceTorqueSensor(); + // Bias the force/torque sensor + robot.biasForceTorqueSensor(); - for (unsigned int i=0; i< 10; i++) { - robot.getForceTorque(H) ; - std::cout << "Measured force/torque: " << H.t() << std::endl; - vpTime::wait(5); + for (unsigned int i=0; i< 10; i++) { + robot.getForceTorque(H) ; + std::cout << "Measured force/torque: " << H.t() << std::endl; + vpTime::wait(5); + } + #endif } -#endif -} \endcode \exception vpRobotException::lowLevelError : If the force/torque measures @@ -2386,29 +2440,32 @@ void vpRobotViper650::getForceTorque(vpColVector &H) const \return [Fx, Fy, Fz, Tx, Ty, Tz] Forces/torques measured by the sensor. - The code below shows how to get the force/torque measures after a sensor -bias. + The code below shows how to get the force/torque measures after a sensor bias. \code -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; - - // Bias the force/torque sensor - robot.biasForceTorqueSensor(); - - for (unsigned int i=0; i< 10; i++) { - vpColVector H = robot.getForceTorque(); // Get force/torque measures [Fx, Fy, Fz, Tx, Ty, Tz] - std::cout << "Measured force/torque: " << H.t() << std::endl; - vpTime::wait(5); + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + + // Bias the force/torque sensor + robot.biasForceTorqueSensor(); + + for (unsigned int i=0; i< 10; i++) { + vpColVector H = robot.getForceTorque(); // Get force/torque measures [Fx, Fy, Fz, Tx, Ty, Tz] + std::cout << "Measured force/torque: " << H.t() << std::endl; + vpTime::wait(5); + } + #endif } -#endif -} \endcode \exception vpRobotException::lowLevelError : If the force/torque measures diff --git a/modules/robot/src/real-robot/viper/vpRobotViper850.cpp b/modules/robot/src/real-robot/viper/vpRobotViper850.cpp index 07b4243ba3..57827c3e2e 100644 --- a/modules/robot/src/real-robot/viper/vpRobotViper850.cpp +++ b/modules/robot/src/real-robot/viper/vpRobotViper850.cpp @@ -133,38 +133,42 @@ void emergencyStopViper850(int signo) including the distortion, use the code below: \code -#include -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; - - // Set the extrinsic camera parameters obtained with a perpective - // projection model including a distortion parameter - robot.init(vpViper850::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); - \endcode + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; + + // Set the extrinsic camera parameters obtained with a perpective + // projection model including a distortion parameter + robot.init(vpViper850::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); + \endcode - Now, you can get the intrinsic camera parameters associated to an - image acquired by the camera attached to the robot, with: + Now, you can get the intrinsic camera parameters associated to an + image acquired by the camera attached to the robot, with: - \code - vpImage I(480, 640); + \code + vpImage I(480, 640); - // Get an image from the camera attached to the robot -#ifdef VISP_HAVE_DC1394 - vp1394TwoGrabber g; - g.acquire(I); -#endif - vpCameraParameters cam; - robot.getCameraParameters(cam, I); - // In cam, you get the intrinsic parameters of the projection model - // with distortion. -#endif -} + // Get an image from the camera attached to the robot + #ifdef VISP_HAVE_DC1394 + vp1394TwoGrabber g; + g.acquire(I); + #endif + vpCameraParameters cam; + robot.getCameraParameters(cam, I); + // In cam, you get the intrinsic parameters of the projection model + // with distortion. + #endif + } \endcode \sa vpCameraParameters, init(vpViper850::vpToolType, @@ -380,38 +384,42 @@ void vpRobotViper850::init(void) including the distortion, use the code below: \code -#include -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; + + // Set the extrinsic camera parameters obtained with a perpective + // projection model including a distortion parameter + robot.init(vpViper850::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); + \endcode - // Set the extrinsic camera parameters obtained with a perpective - // projection model including a distortion parameter - robot.init(vpViper850::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); - \endcode + Now, you can get the intrinsic camera parameters associated to an + image acquired by the camera attached to the robot, with: - Now, you can get the intrinsic camera parameters associated to an - image acquired by the camera attached to the robot, with: + \code + vpImage I(480, 640); - \code - vpImage I(480, 640); - - // Get an image from the camera attached to the robot -#ifdef VISP_HAVE_DC1394 - vp1394TwoGrabber g; - g.acquire(I); -#endif - vpCameraParameters cam; - robot.getCameraParameters(cam, I); - // In cam, you get the intrinsic parameters of the projection model - // with distortion. -#endif -} + // Get an image from the camera attached to the robot + #ifdef VISP_HAVE_DC1394 + vp1394TwoGrabber g; + g.acquire(I); + #endif + vpCameraParameters cam; + robot.getCameraParameters(cam, I); + // In cam, you get the intrinsic parameters of the projection model + // with distortion. + #endif + } \endcode \sa vpCameraParameters, @@ -466,36 +474,40 @@ void vpRobotViper850::init(vpViper850::vpToolType tool, vpCameraParameters::vpCa M}_c\f$ matrix, use the code below: \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Set the transformation between the end-effector frame - // and the tool frame from a file - std::string filename("./EffectorToolTransformation.cnf"); + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; - robot.init(vpViper850::TOOL_CUSTOM, filename); -#endif -} + // Set the transformation between the end-effector frame + // and the tool frame from a file + std::string filename("./EffectorToolTransformation.cnf"); + + robot.init(vpViper850::TOOL_CUSTOM, filename); + #endif + } \endcode The configuration file should have the form below: \code -# Start with any number of consecutive lines -# beginning with the symbol '#' -# -# The 3 following lines contain the name of the camera, -# the rotation parameters of the geometric transformation -# using the Euler angles in degrees with convention XYZ and -# the translation parameters expressed in meters -CAMERA CameraName -eMc_ROT_XYZ 10.0 -90.0 20.0 -eMc_TRANS_XYZ 0.05 0.01 0.06 - \endcode + # Start with any number of consecutive lines + # beginning with the symbol '#' + # + # The 3 following lines contain the name of the camera, + # the rotation parameters of the geometric transformation + # using the Euler angles in degrees with convention XYZ and + # the translation parameters expressed in meters + CAMERA CameraName + eMc_ROT_XYZ 10.0 -90.0 20.0 + eMc_TRANS_XYZ 0.05 0.01 0.06 + \endcode \sa init(), init(vpViper850::vpToolType, vpCameraParameters::vpCameraParametersProjType), @@ -546,21 +558,25 @@ void vpRobotViper850::init(vpViper850::vpToolType tool, const std::string &filen M}_c\f$ matrix, use the code below: \code -#include -#include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - // Set the transformation between the end-effector frame - // and the tool frame. - vpHomogeneousMatrix eMc(0.001, 0.0, 0.1, 0.0, 0.0, M_PI/2); + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; - robot.init(vpViper850::TOOL_CUSTOM, eMc); -#endif -} + // Set the transformation between the end-effector frame + // and the tool frame. + vpHomogeneousMatrix eMc(0.001, 0.0, 0.1, 0.0, 0.0, M_PI/2); + + robot.init(vpViper850::TOOL_CUSTOM, eMc); + #endif + } \endcode \sa vpCameraParameters, init(), init(vpViper850::vpToolType, @@ -1022,26 +1038,30 @@ void vpRobotViper850::get_fJe(vpMatrix &fJe) be in ]0:100]. \code -#include -#include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpColVector position(6); - position = 0; // position in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotViper850 robot; + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpColVector position(6); + position = 0; // position in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpRobotViper850 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot to the joint position [0,0,0,0,0,0] - robot.setPosition(vpRobot::ARTICULAR_FRAME, position); -#endif -} + // Set the max velocity to 20% + robot.setPositioningVelocity(20); + + // Moves the robot to the joint position [0,0,0,0,0,0] + robot.setPosition(vpRobot::ARTICULAR_FRAME, position); + #endif + } \endcode \sa getPositioningVelocity() @@ -1089,32 +1109,36 @@ double vpRobotViper850::getPositioningVelocity(void) const { return m_positionin position is out of range. \code -#include -#include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpColVector position(6); - // Set positions in the camera frame - position[0] = 0.1; // x axis, in meter - position[1] = 0.2; // y axis, in meter - position[2] = 0.3; // z axis, in meter - position[3] = M_PI/8; // rotation around x axis, in rad - position[4] = M_PI/4; // rotation around y axis, in rad - position[5] = M_PI; // rotation around z axis, in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotViper850 robot; + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpColVector position(6); + // Set positions in the camera frame + position[0] = 0.1; // x axis, in meter + position[1] = 0.2; // y axis, in meter + position[2] = 0.3; // z axis, in meter + position[3] = M_PI/8; // rotation around x axis, in rad + position[4] = M_PI/4; // rotation around y axis, in rad + position[5] = M_PI; // rotation around z axis, in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpRobotViper850 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the camera frame - robot.setPosition(vpRobot::CAMERA_FRAME, position); -#endif -} + // Set the max velocity to 20% + robot.setPositioningVelocity(20); + + // Moves the robot in the camera frame + robot.setPosition(vpRobot::CAMERA_FRAME, position); + #endif + } \endcode To catch the exception if the position is out of range, modify the code @@ -1287,30 +1311,34 @@ void vpRobotViper850::setPosition(const vpRobot::vpControlFrameType frame, const position is out of range. \code -#include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - // Set positions in the camera frame - double pos1 = 0.1; // x axis, in meter - double pos2 = 0.2; // y axis, in meter - double pos3 = 0.3; // z axis, in meter - double pos4 = M_PI/8; // rotation around x axis, in rad - double pos5 = M_PI/4; // rotation around y axis, in rad - double pos6 = M_PI; // rotation around z axis, in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotViper850 robot; + int main() + { + #ifdef VISP_HAVE_VIPER850 + // Set positions in the camera frame + double pos1 = 0.1; // x axis, in meter + double pos2 = 0.2; // y axis, in meter + double pos3 = 0.3; // z axis, in meter + double pos4 = M_PI/8; // rotation around x axis, in rad + double pos5 = M_PI/4; // rotation around y axis, in rad + double pos6 = M_PI; // rotation around z axis, in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpRobotViper850 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the camera frame - robot.setPosition(vpRobot::CAMERA_FRAME, pos1, pos2, pos3, pos4, pos5, pos6); -#endif -} + // Set the max velocity to 20% + robot.setPositioningVelocity(20); + + // Moves the robot in the camera frame + robot.setPosition(vpRobot::CAMERA_FRAME, pos1, pos2, pos3, pos4, pos5, pos6); + #endif + } \endcode \sa setPosition() @@ -1348,20 +1376,24 @@ void vpRobotViper850::setPosition(const vpRobot::vpControlFrameType frame, doubl This method has the same behavior than the sample code given below; \code -#include -#include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpColVector q; - vpRobotViper850 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - robot.readPosFile("MyPositionFilename.pos", q); - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); -#endif -} + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpColVector q; + vpRobotViper850 robot; + + robot.readPosFile("MyPositionFilename.pos", q); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); + #endif + } \endcode \exception vpRobotException::lowLevelError : vpRobot::MIXT_FRAME @@ -1400,7 +1432,7 @@ void vpRobotViper850::setPosition(const std::string &filename) frame, and rotation in camera frame) \param position : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, a 6 dimension vector corresponding to the joint position of each dof in radians. @@ -1413,39 +1445,43 @@ void vpRobotViper850::setPosition(const std::string &filename) \param timestamp : Time in second since last robot power on. \code -#include -#include -#include -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; - - vpColVector position; - double timestamp; - robot.getPosition(vpRobot::REFERENCE_FRAME, position, timestamp); + #include + #include + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; + + vpColVector position; + double timestamp; + robot.getPosition(vpRobot::REFERENCE_FRAME, position, timestamp); + + vpTranslationVector ftc; // reference frame to camera frame translations + vpRxyzVector frc; // reference frame to camera frame rotations + + // Update the transformation between reference frame and camera frame + for (unsigned int i=0; i < 3; i++) { + ftc[i] = position[i]; // tx, ty, tz + frc[i] = position[i+3]; // ry, ry, rz + } - vpTranslationVector ftc; // reference frame to camera frame translations - vpRxyzVector frc; // reference frame to camera frame rotations + // Create a rotation matrix from the Rxyz rotation angles + vpRotationMatrix fRc(frc); // reference frame to camera frame rotation matrix - // Update the transformation between reference frame and camera frame - for (unsigned int i=0; i < 3; i++) { - ftc[i] = position[i]; // tx, ty, tz - frc[i] = position[i+3]; // ry, ry, rz + // Create the camera to fix frame transformation in terms of a + // homogeneous matrix + vpHomogeneousMatrix fMc(ftc, fRc); + #endif } - - // Create a rotation matrix from the Rxyz rotation angles - vpRotationMatrix fRc(frc); // reference frame to camera frame rotation matrix - - // Create the camera to fix frame transformation in terms of a - // homogeneous matrix - vpHomogeneousMatrix fMc(ftc, fRc); -#endif -} \endcode \exception vpRobotException::lowLevelError : If the position cannot @@ -1641,38 +1677,42 @@ reference frame in m/s and rotations \f$ ^{c} \omega_x, ^{c} \omega_y, ^{c} setMaxTranslationVelocity() and setMaxRotationVelocity(). \code -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; - - vpColVector qvel(6); - // Set a joint velocity - qvel[0] = 0.1; // Joint 1 velocity in rad/s - qvel[1] = vpMath::rad(15); // Joint 2 velocity in rad/s - qvel[2] = 0; // Joint 3 velocity in rad/s - qvel[3] = M_PI/8; // Joint 4 velocity in rad/s - qvel[4] = 0; // Joint 5 velocity in rad/s - qvel[5] = 0; // Joint 6 velocity in rad/s - - // Initialize the controller to velocity control - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - while (1) { - // Apply a velocity in the joint space - robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; + + vpColVector qvel(6); + // Set a joint velocity + qvel[0] = 0.1; // Joint 1 velocity in rad/s + qvel[1] = vpMath::rad(15); // Joint 2 velocity in rad/s + qvel[2] = 0; // Joint 3 velocity in rad/s + qvel[3] = M_PI/8; // Joint 4 velocity in rad/s + qvel[4] = 0; // Joint 5 velocity in rad/s + qvel[5] = 0; // Joint 6 velocity in rad/s + + // Initialize the controller to velocity control + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + while (1) { + // Apply a velocity in the joint space + robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); + + // Compute new velocities qvel... + } - // Compute new velocities qvel... + // Stop the robot + robot.setRobotState(vpRobot::STATE_STOP); + #endif } - - // Stop the robot - robot.setRobotState(vpRobot::STATE_STOP); -#endif -} \endcode */ void vpRobotViper850::setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) @@ -1811,47 +1851,51 @@ void vpRobotViper850::setVelocity(const vpRobot::vpControlFrameType frame, const \warning In camera frame, reference frame and mixt frame, the representation of the rotation is \f$ \theta {\bf u}\f$. In that cases, \f$velocity = [\dot -x, \dot y, \dot z, \dot {\theta u}_x, \dot {\theta u}_y, \dot {\theta -u}_z]\f$. + x, \dot y, \dot z, \dot {\theta u}_x, \dot {\theta u}_y, \dot {\theta + u}_z]\f$. \warning The first time this method is called, \e velocity is set to 0. The first call is used to intialise the velocity computation for the next call. \code -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER850 - // Set requested joint velocities - vpColVector q_dot(6); - q_dot[0] = 0.1; // Joint 1 velocity in rad/s - q_dot[1] = 0.2; // Joint 2 velocity in rad/s - q_dot[2] = 0.3; // Joint 3 velocity in rad/s - q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s - q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s - q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s - - vpRobotViper850 robot; - - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - // Moves the joint in velocity - robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); - - // Initialisation of the velocity measurement - vpColVector q_dot_mes; // Measured velocities - robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); // q_dot_mes =0 - // q_dot_mes is resized to 6, the number of joint - - while (1) { - robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); - vpTime::wait(40); // wait 40 ms - // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER850 + // Set requested joint velocities + vpColVector q_dot(6); + q_dot[0] = 0.1; // Joint 1 velocity in rad/s + q_dot[1] = 0.2; // Joint 2 velocity in rad/s + q_dot[2] = 0.3; // Joint 3 velocity in rad/s + q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s + q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s + q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s + + vpRobotViper850 robot; + + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + // Moves the joint in velocity + robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); + + // Initialisation of the velocity measurement + vpColVector q_dot_mes; // Measured velocities + robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); // q_dot_mes =0 + // q_dot_mes is resized to 6, the number of joint + + while (1) { + robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); + vpTime::wait(40); // wait 40 ms + // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + } + #endif } -#endif -} \endcode */ void vpRobotViper850::getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity, double ×tamp) @@ -1994,41 +2038,45 @@ void vpRobotViper850::getVelocity(const vpRobot::vpControlFrameType frame, vpCol and rotations in rad/s. \code -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER850 - // Set requested joint velocities - vpColVector q_dot(6); - q_dot[0] = 0.1; // Joint 1 velocity in rad/s - q_dot[1] = 0.2; // Joint 2 velocity in rad/s - q_dot[2] = 0.3; // Joint 3 velocity in rad/s - q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s - q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s - q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s - - vpRobotViper850 robot; - - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - // Moves the joint in velocity - robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); - - // Initialisation of the velocity measurement - vpColVector q_dot_mes; // Measured velocities - robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); // q_dot_mes =0 - // q_dot_mes is resized to 6, the number of joint - - double timestamp; - while (1) { - q_dot_mes = robot.getVelocity(vpRobot::ARTICULAR_FRAME, timestamp); - vpTime::wait(40); // wait 40 ms - // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER850 + // Set requested joint velocities + vpColVector q_dot(6); + q_dot[0] = 0.1; // Joint 1 velocity in rad/s + q_dot[1] = 0.2; // Joint 2 velocity in rad/s + q_dot[2] = 0.3; // Joint 3 velocity in rad/s + q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s + q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s + q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s + + vpRobotViper850 robot; + + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + // Moves the joint in velocity + robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); + + // Initialisation of the velocity measurement + vpColVector q_dot_mes; // Measured velocities + robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); // q_dot_mes =0 + // q_dot_mes is resized to 6, the number of joint + + double timestamp; + while (1) { + q_dot_mes = robot.getVelocity(vpRobot::ARTICULAR_FRAME, timestamp); + vpTime::wait(40); // wait 40 ms + // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + } + #endif } -#endif -} \endcode */ vpColVector vpRobotViper850::getVelocity(vpRobot::vpControlFrameType frame, double ×tamp) @@ -2058,67 +2106,71 @@ vpColVector vpRobotViper850::getVelocity(vpRobot::vpControlFrameType frame) /*! -Read joint positions in a specific Viper850 position file. + Read joint positions in a specific Viper850 position file. -This position file has to start with a header. The six joint positions -are given after the "R:" keyword. The first 3 values correspond to the -joint translations X,Y,Z expressed in meters. The 3 last values -correspond to the joint rotations A,B,C expressed in degres to be more -representative for the user. Theses values are then converted in -radians in \e q. The character "#" starting a line indicates a -comment. + This position file has to start with a header. The six joint positions + are given after the "R:" keyword. The first 3 values correspond to the + joint translations X,Y,Z expressed in meters. The 3 last values + correspond to the joint rotations A,B,C expressed in degres to be more + representative for the user. Theses values are then converted in + radians in \e q. The character "#" starting a line indicates a + comment. -A typical content of such a file is given below: + A typical content of such a file is given below: -\code -#Viper - Position - Version 1.0 -# file: "myposition.pos " -# -# R: A B C D E F -# Joint position in degrees -# + \code + #Viper - Position - Version 1.0 + # file: "myposition.pos " + # + # R: A B C D E F + # Joint position in degrees + # + + R: 0.1 0.3 -0.25 -80.5 80 0 + \endcode -R: 0.1 0.3 -0.25 -80.5 80 0 -\endcode + \param filename : Name of the position file to read. -\param filename : Name of the position file to read. + \param q : The six joint positions. Values are expressed in radians. -\param q : The six joint positions. Values are expressed in radians. + \return true if the positions were successfully readen in the file. false, if + an error occurs. -\return true if the positions were successfully readen in the file. false, if -an error occurs. + The code below shows how to read a position from a file and move the robot to + this position. + \code + #include + #include -The code below shows how to read a position from a file and move the robot to -this position. -\code -#include -#include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; - // Enable the position control of the robot - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + // Enable the position control of the robot + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Get the current robot joint positions - vpColVector q; // Current joint position - robot.getPosition(vpRobot::ARTICULAR_FRAME, q); + // Get the current robot joint positions + vpColVector q; // Current joint position + robot.getPosition(vpRobot::ARTICULAR_FRAME, q); - // Save this position in a file named "current.pos" - robot.savePosFile("current.pos", q); + // Save this position in a file named "current.pos" + robot.savePosFile("current.pos", q); - // Get the position from a file and move to the registered position - robot.readPosFile("current.pos", q); // Set the joint position from the file + // Get the position from a file and move to the registered position + robot.readPosFile("current.pos", q); // Set the joint position from the file - robot.setPositioningVelocity(5); // Positioning velocity set to 5% - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); // Move to the joint position -#endif -} -\endcode + robot.setPositioningVelocity(5); // Positioning velocity set to 5% + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); // Move to the joint position + #endif + } + \endcode -\sa savePosFile() + \sa savePosFile() */ bool vpRobotViper850::readPosFile(const std::string &filename, vpColVector &q) @@ -2390,27 +2442,31 @@ void vpRobotViper850::unbiasForceTorqueSensor() bias. \code -#include -#include -#include + #include + #include + #include -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpColVector H; // force/torque measures [Fx, Fy, Fz, Tx, Ty, Tz] + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotViper850 robot; + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpColVector H; // force/torque measures [Fx, Fy, Fz, Tx, Ty, Tz] + + vpRobotViper850 robot; - // Bias the force/torque sensor - robot.biasForceTorqueSensor(); + // Bias the force/torque sensor + robot.biasForceTorqueSensor(); - for (unsigned int i=0; i< 10; i++) { - robot.getForceTorque(H) ; - std::cout << "Measured force/torque: " << H.t() << std::endl; - vpTime::wait(5); + for (unsigned int i=0; i< 10; i++) { + robot.getForceTorque(H) ; + std::cout << "Measured force/torque: " << H.t() << std::endl; + vpTime::wait(5); + } + #endif } -#endif -} \endcode \exception vpRobotException::lowLevelError : If the force/torque measures @@ -2454,25 +2510,29 @@ void vpRobotViper850::getForceTorque(vpColVector &H) const bias. \code -#include -#include -#include - -int main() -{ -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; - - // Bias the force/torque sensor - robot.biasForceTorqueSensor(); - - for (unsigned int i=0; i< 10; i++) { - vpColVector H = robot.getForceTorque(); // force/torque measures [Fx, Fy, Fz, Tx, Ty, Tz] - std::cout << "Measured force/torque: " << H.t() << std::endl; - vpTime::wait(5); + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; + + // Bias the force/torque sensor + robot.biasForceTorqueSensor(); + + for (unsigned int i=0; i< 10; i++) { + vpColVector H = robot.getForceTorque(); // force/torque measures [Fx, Fy, Fz, Tx, Ty, Tz] + std::cout << "Measured force/torque: " << H.t() << std::endl; + vpTime::wait(5); + } + #endif } -#endif -} \endcode \exception vpRobotException::lowLevelError : If the force/torque measures diff --git a/modules/robot/src/real-robot/viper/vpViper.cpp b/modules/robot/src/real-robot/viper/vpViper.cpp index 4ca66c2f3a..151422bda8 100644 --- a/modules/robot/src/real-robot/viper/vpViper.cpp +++ b/modules/robot/src/real-robot/viper/vpViper.cpp @@ -688,32 +688,36 @@ void vpViper::get_fMc(const vpColVector &q, vpHomogeneousMatrix &fMc) const expressed in radians. \param fMe The homogeneous matrix \f${^f}{\bf M}_e\f$ corresponding to the -direct geometric model which expresses the transformation between the fix -frame and the end effector frame. + direct geometric model which expresses the transformation between the fix + frame and the end effector frame. Note that this transformation can also be computed by considering the wrist frame \f${^f}{\bf M}_e = {^f}{\bf M}_w *{^w}{\bf M}_e\f$. \code -#include + #include -int main() -{ - vpViper robot; - vpColVector q(6); // The measured six joint positions + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpHomogeneousMatrix fMe; // Transformation from fix frame to end-effector - robot.get_fMe(q, fMe); // Get the forward kinematics + int main() + { + vpViper robot; + vpColVector q(6); // The measured six joint positions - // The forward kinematics can also be computed by considering the wrist frame - vpHomogeneousMatrix fMw; // Transformation from fix frame to wrist frame - robot.get_fMw(q, fMw); - vpHomogeneousMatrix wMe; // Transformation from wrist frame to end-effector - robot.get_wMe(wMe); // Constant transformation + vpHomogeneousMatrix fMe; // Transformation from fix frame to end-effector + robot.get_fMe(q, fMe); // Get the forward kinematics - // Compute the forward kinematics - fMe = fMw * wMe; -} + // The forward kinematics can also be computed by considering the wrist frame + vpHomogeneousMatrix fMw; // Transformation from fix frame to wrist frame + robot.get_fMw(q, fMw); + vpHomogeneousMatrix wMe; // Transformation from wrist frame to end-effector + robot.get_wMe(wMe); // Constant transformation + + // Compute the forward kinematics + fMe = fMw * wMe; + } \endcode */ diff --git a/modules/robot/src/real-robot/viper/vpViper650.cpp b/modules/robot/src/real-robot/viper/vpViper650.cpp index c16c8c4c12..7289bfd7de 100644 --- a/modules/robot/src/real-robot/viper/vpViper650.cpp +++ b/modules/robot/src/real-robot/viper/vpViper650.cpp @@ -509,42 +509,46 @@ file. attached to the robot. \code -#include -#include -#include -#include - -int main() -{ - vpImage I(480, 640); - -#ifdef VISP_HAVE_DC1394 - vp1394TwoGrabber g; - - // Acquire an image to update image structure - g.acquire(I) ; -#endif - -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; -#else - vpViper650 robot; -#endif - - vpCameraParameters cam ; - // Get the intrinsic camera parameters depending on the image size - // Camera parameters are read from - // /udd/fspindle/robot/Viper650/current/include/const_camera_Viper650.xml - // if VISP_HAVE_VIPER650_DATA macro is defined - // in vpConfig.h file - try { - robot.getCameraParameters (cam, I.getWidth(), I.getHeight()); - } - catch(...) { - std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I(480, 640); + + #ifdef VISP_HAVE_DC1394 + vp1394TwoGrabber g; + + // Acquire an image to update image structure + g.acquire(I) ; + #endif + + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + #else + vpViper650 robot; + #endif + + vpCameraParameters cam ; + // Get the intrinsic camera parameters depending on the image size + // Camera parameters are read from + // /udd/fspindle/robot/Viper650/current/include/const_camera_Viper650.xml + // if VISP_HAVE_VIPER650_DATA macro is defined + // in vpConfig.h file + try { + robot.getCameraParameters (cam, I.getWidth(), I.getHeight()); + } + catch(...) { + std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + } + std::cout << "Camera parameters: " << cam << std::endl; } - std::cout << "Camera parameters: " << cam << std::endl; -} \endcode \exception vpRobotException::readingParametersError : If the camera @@ -722,42 +726,46 @@ file. \param I : A B&W image send by the current camera in use. \code -#include -#include -#include -#include - -int main() -{ - vpImage I(480, 640); - -#ifdef VISP_HAVE_DC1394 - vp1394TwoGrabber g; - - // Acquire an image to update image structure - g.acquire(I) ; -#endif - -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; -#else - vpViper650 robot; -#endif - - vpCameraParameters cam ; - // Get the intrinsic camera parameters depending on the image size - try { - robot.getCameraParameters (cam, I); - } - catch(...) { - std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I(480, 640); + + #ifdef VISP_HAVE_DC1394 + vp1394TwoGrabber g; + + // Acquire an image to update image structure + g.acquire(I) ; + #endif + + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + #else + vpViper650 robot; + #endif + + vpCameraParameters cam ; + // Get the intrinsic camera parameters depending on the image size + try { + robot.getCameraParameters (cam, I); + } + catch(...) { + std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + } + std::cout << "Camera parameters: " << cam << std::endl; } - std::cout << "Camera parameters: " << cam << std::endl; -} \endcode \exception vpRobotException::readingParametersError : If the camera -parameters are not found. + parameters are not found. */ void vpViper650::getCameraParameters(vpCameraParameters &cam, const vpImage &I) const @@ -786,38 +794,42 @@ file. \param I : A color image send by the current camera in use. \code -#include -#include -#include -#include - -int main() -{ - vpImage I(480, 640); - -#ifdef VISP_HAVE_DC1394 - vp1394TwoGrabber g; - - // Acquire an image to update image structure - g.acquire(I) ; -#endif - -#ifdef VISP_HAVE_VIPER650 - vpRobotViper650 robot; -#else - vpViper650 robot; -#endif - - vpCameraParameters cam ; - // Get the intrinsic camera parameters depending on the image size - try { - robot.getCameraParameters (cam, I); - } - catch(...) { - std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I(480, 640); + + #ifdef VISP_HAVE_DC1394 + vp1394TwoGrabber g; + + // Acquire an image to update image structure + g.acquire(I) ; + #endif + + #ifdef VISP_HAVE_VIPER650 + vpRobotViper650 robot; + #else + vpViper650 robot; + #endif + + vpCameraParameters cam ; + // Get the intrinsic camera parameters depending on the image size + try { + robot.getCameraParameters (cam, I); + } + catch(...) { + std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + } + std::cout << "Camera parameters: " << cam << std::endl; } - std::cout << "Camera parameters: " << cam << std::endl; -} \endcode \exception vpRobotException::readingParametersError : If the camera diff --git a/modules/robot/src/real-robot/viper/vpViper850.cpp b/modules/robot/src/real-robot/viper/vpViper850.cpp index 368890e7b7..35cdb823c2 100644 --- a/modules/robot/src/real-robot/viper/vpViper850.cpp +++ b/modules/robot/src/real-robot/viper/vpViper850.cpp @@ -492,10 +492,10 @@ void vpViper850::parseConfigFile(const std::string &filename) vpViper850::CONST_CAMERA_FILENAME and containing the camera parameters. - \warning Thid method needs also an access to the files containing the + \warning Third method needs also an access to the files containing the camera parameters in XML format. This access is available if VISP_HAVE_VIPER850_DATA macro is defined in include/visp3/core/vpConfig.h -file. + file. - If VISP_HAVE_VIPER850_DATA macro is defined, this method gets the camera parameters from const_camera_Viper850.xml config file. @@ -511,46 +511,50 @@ file. attached to the robot. \code -#include -#include -#include -#include - -int main() -{ - vpImage I(480, 640); - -#ifdef VISP_HAVE_DC1394 - vp1394TwoGrabber g; - - // Acquire an image to update image structure - g.acquire(I) ; -#endif - -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; -#else - vpViper850 robot; -#endif - - vpCameraParameters cam ; - // Get the intrinsic camera parameters depending on the image size - // Camera parameters are read from - // /udd/fspindle/robot/Viper850/current/include/const_camera_Viper850.xml - // if VISP_HAVE_VIPER850_DATA macro is defined - // in vpConfig.h file - try { - robot.getCameraParameters (cam, I.getWidth(), I.getHeight()); - } - catch(...) { - std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I(480, 640); + + #ifdef VISP_HAVE_DC1394 + vp1394TwoGrabber g; + + // Acquire an image to update image structure + g.acquire(I) ; + #endif + + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; + #else + vpViper850 robot; + #endif + + vpCameraParameters cam ; + // Get the intrinsic camera parameters depending on the image size + // Camera parameters are read from + // /udd/fspindle/robot/Viper850/current/include/const_camera_Viper850.xml + // if VISP_HAVE_VIPER850_DATA macro is defined + // in vpConfig.h file + try { + robot.getCameraParameters (cam, I.getWidth(), I.getHeight()); + } + catch(...) { + std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + } + std::cout << "Camera parameters: " << cam << std::endl; } - std::cout << "Camera parameters: " << cam << std::endl; -} \endcode \exception vpRobotException::readingParametersError : If the camera -parameters are not found. + parameters are not found. */ @@ -791,38 +795,42 @@ file. \param I : A color image send by the current camera in use. \code -#include -#include -#include -#include - -int main() -{ - vpImage I(480, 640); - -#ifdef VISP_HAVE_DC1394 - vp1394TwoGrabber g; - - // Acquire an image to update image structure - g.acquire(I) ; -#endif - -#ifdef VISP_HAVE_VIPER850 - vpRobotViper850 robot; -#else - vpViper850 robot; -#endif - - vpCameraParameters cam ; - // Get the intrinsic camera parameters depending on the image size - try { - robot.getCameraParameters (cam, I); - } - catch(...) { - std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I(480, 640); + + #ifdef VISP_HAVE_DC1394 + vp1394TwoGrabber g; + + // Acquire an image to update image structure + g.acquire(I) ; + #endif + + #ifdef VISP_HAVE_VIPER850 + vpRobotViper850 robot; + #else + vpViper850 robot; + #endif + + vpCameraParameters cam ; + // Get the intrinsic camera parameters depending on the image size + try { + robot.getCameraParameters (cam, I); + } + catch(...) { + std::cout << "Cannot get camera parameters for image: " << I.getWidth() << " x " << I.getHeight() << std::endl; + } + std::cout << "Camera parameters: " << cam << std::endl; } - std::cout << "Camera parameters: " << cam << std::endl; -} \endcode \exception vpRobotException::readingParametersError : If the camera diff --git a/modules/robot/src/robot-simulator/vpSimulatorAfma6.cpp b/modules/robot/src/robot-simulator/vpSimulatorAfma6.cpp index 3dddc7c3e7..a1858c6858 100644 --- a/modules/robot/src/robot-simulator/vpSimulatorAfma6.cpp +++ b/modules/robot/src/robot-simulator/vpSimulatorAfma6.cpp @@ -756,32 +756,31 @@ vpRobot::vpRobotStateType vpSimulatorAfma6::setRobotState(vpRobot::vpRobotStateT Apply a velocity to the robot. \param frame : Control frame in which the velocity is expressed. Velocities - could be expressed in articular, camera frame, reference frame or mixt -frame. + could be expressed in articular, camera frame, reference frame or mixt frame. \param vel : Velocity vector. The size of this vector is always 6. - In articular, \f$ vel = [\dot{q}_1, \dot{q}_2, \dot{q}_3, \dot{q}_4, - \dot{q}_5, \dot{q}_6]^t \f$ correspond to joint velocities in rad/s. + \dot{q}_5, \dot{q}_6]^t \f$ correspond to joint velocities in rad/s. - In camera frame, \f$ vel = [^{c} v_x, ^{c} v_y, ^{c} v_z, ^{c} - \omega_x, ^{c} \omega_y, ^{c} \omega_z]^t \f$ is a velocity twist vector -expressed in the camera frame, with translations velocities \f$ ^{c} v_x, ^{c} -v_y, ^{c} v_z \f$ in m/s and rotation velocities \f$ ^{c}\omega_x, ^{c} -\omega_y, ^{c} \omega_z \f$ in rad/s. + \omega_x, ^{c} \omega_y, ^{c} \omega_z]^t \f$ is a velocity twist vector + expressed in the camera frame, with translations velocities \f$ ^{c} v_x, ^{c} + v_y, ^{c} v_z \f$ in m/s and rotation velocities \f$ ^{c}\omega_x, ^{c} + \omega_y, ^{c} \omega_z \f$ in rad/s. - In reference frame, \f$ vel = [^{r} v_x, ^{r} v_y, ^{r} v_z, ^{r} - \omega_x, ^{r} \omega_y, ^{r} \omega_z]^t \f$ is a velocity twist vector -expressed in the reference frame, with translations velocities \f$ ^{c} v_x, -^{c} v_y, ^{c} v_z \f$ in m/s and rotation velocities \f$ ^{c}\omega_x, ^{c} -\omega_y, ^{c} \omega_z \f$ in rad/s. + \omega_x, ^{r} \omega_y, ^{r} \omega_z]^t \f$ is a velocity twist vector + expressed in the reference frame, with translations velocities \f$ ^{c} v_x, + ^{c} v_y, ^{c} v_z \f$ in m/s and rotation velocities \f$ ^{c}\omega_x, ^{c} + \omega_y, ^{c} \omega_z \f$ in rad/s. - In mixt frame, \f$ vel = [^{r} v_x, ^{r} v_y, ^{r} v_z, ^{c} \omega_x, - ^{c} \omega_y, ^{c} \omega_z]^t \f$ is a velocity twist vector where, -translations \f$ ^{r} v_x, ^{r} v_y, ^{r} v_z \f$ are expressed in the -reference frame in m/s and rotations \f$ ^{c} \omega_x, ^{c} \omega_y, ^{c} -\omega_z \f$ in the camera frame in rad/s. + ^{c} \omega_y, ^{c} \omega_z]^t \f$ is a velocity twist vector where, + translations \f$ ^{r} v_x, ^{r} v_y, ^{r} v_z \f$ are expressed in the + reference frame in m/s and rotations \f$ ^{c} \omega_x, ^{c} \omega_y, ^{c} + \omega_z \f$ in the camera frame in rad/s. \exception vpRobotException::wrongStateError : If a the robot is not configured to handle a velocity. The robot can handle a velocity only if the @@ -794,35 +793,39 @@ reference frame in m/s and rotations \f$ ^{c} \omega_x, ^{c} \omega_y, ^{c} setMaxTranslationVelocity() and setMaxRotationVelocity(). \code -#include -#include -#include - -int main() -{ - vpSimulatorAfma6 robot; - - vpColVector qvel(6); - // Set a joint velocity - qvel[0] = 0.1; // Joint 1 velocity in m/s - qvel[1] = 0.1; // Joint 2 velocity in m/s - qvel[2] = 0.1; // Joint 3 velocity in m/s - qvel[3] = M_PI/8; // Joint 4 velocity in rad/s - qvel[4] = 0; // Joint 5 velocity in rad/s - qvel[5] = 0; // Joint 6 velocity in rad/s - - // Initialize the controller to position control - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - for ( ; ; ) { - // Apply a velocity in the joint space - robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); - - // Compute new velocities qvel... + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpSimulatorAfma6 robot; + + vpColVector qvel(6); + // Set a joint velocity + qvel[0] = 0.1; // Joint 1 velocity in m/s + qvel[1] = 0.1; // Joint 2 velocity in m/s + qvel[2] = 0.1; // Joint 3 velocity in m/s + qvel[3] = M_PI/8; // Joint 4 velocity in rad/s + qvel[4] = 0; // Joint 5 velocity in rad/s + qvel[5] = 0; // Joint 6 velocity in rad/s + + // Initialize the controller to position control + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + for ( ; ; ) { + // Apply a velocity in the joint space + robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); + + // Compute new velocities qvel... + } + // Stop the robot + robot.setRobotState(vpRobot::STATE_STOP); } - // Stop the robot - robot.setRobotState(vpRobot::STATE_STOP); -} \endcode */ void vpSimulatorAfma6::setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) @@ -1021,39 +1024,43 @@ void vpSimulatorAfma6::computeArticularVelocity() \warning In camera frame, reference frame and mixt frame, the representation of the rotation is ThetaU. In that cases, \f$velocity = [\dot x, \dot y, -\dot z, \dot {\theta U}_x, \dot {\theta U}_y, \dot {\theta U}_z]\f$. + \dot z, \dot {\theta U}_x, \dot {\theta U}_y, \dot {\theta U}_z]\f$. \code -#include -#include - -int main() -{ - // Set requested joint velocities - vpColVector q_dot(6); - q_dot[0] = 0.1; // Joint 1 velocity in m/s - q_dot[1] = 0.2; // Joint 2 velocity in m/s - q_dot[2] = 0.3; // Joint 3 velocity in m/s - q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s - q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s - q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s - - vpSimulatorAfma6 robot; - - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - // Moves the joint in velocity - robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); - - // Initialisation of the velocity measurement - vpColVector q_dot_mes; // Measured velocities - - for ( ; ; ) { - robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); - vpTime::wait(40); // wait 40 ms - // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + // Set requested joint velocities + vpColVector q_dot(6); + q_dot[0] = 0.1; // Joint 1 velocity in m/s + q_dot[1] = 0.2; // Joint 2 velocity in m/s + q_dot[2] = 0.3; // Joint 3 velocity in m/s + q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s + q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s + q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s + + vpSimulatorAfma6 robot; + + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + // Moves the joint in velocity + robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); + + // Initialisation of the velocity measurement + vpColVector q_dot_mes; // Measured velocities + + for ( ; ; ) { + robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); + vpTime::wait(40); // wait 40 ms + // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + } } -} \endcode */ void vpSimulatorAfma6::getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &vel) @@ -1118,42 +1125,46 @@ void vpSimulatorAfma6::getVelocity(const vpRobot::vpControlFrameType frame, vpCo /*! Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \return Measured velocities. Translations are expressed in m/s and rotations in rad/s. \code -#include -#include - -int main() -{ - // Set requested joint velocities - vpColVector q_dot(6); - q_dot[0] = 0.1; // Joint 1 velocity in rad/s - q_dot[1] = 0.2; // Joint 2 velocity in rad/s - q_dot[2] = 0.3; // Joint 3 velocity in rad/s - q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s - q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s - q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s - - vpSimulatorAfma6 robot; - - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - // Moves the joint in velocity - robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); - - // Initialisation of the velocity measurement - vpColVector q_dot_mes; // Measured velocities - - for ( ; ; ) { - q_dot_mes = robot.getVelocity(vpRobot::ARTICULAR_FRAME); - vpTime::wait(40); // wait 40 ms - // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + // Set requested joint velocities + vpColVector q_dot(6); + q_dot[0] = 0.1; // Joint 1 velocity in rad/s + q_dot[1] = 0.2; // Joint 2 velocity in rad/s + q_dot[2] = 0.3; // Joint 3 velocity in rad/s + q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s + q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s + q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s + + vpSimulatorAfma6 robot; + + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + // Moves the joint in velocity + robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); + + // Initialisation of the velocity measurement + vpColVector q_dot_mes; // Measured velocities + + for ( ; ; ) { + q_dot_mes = robot.getVelocity(vpRobot::ARTICULAR_FRAME); + vpTime::wait(40); // wait 40 ms + // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + } } -} \endcode */ vpColVector vpSimulatorAfma6::getVelocity(vpRobot::vpControlFrameType frame) @@ -1232,30 +1243,34 @@ void vpSimulatorAfma6::findHighestPositioningSpeed(vpColVector &q) position is out of range. \code -#include -#include + #include + #include -int main() -{ - vpColVector position(6); - // Set positions in the camera frame - position[0] = 0.1; // x axis, in meter - position[1] = 0.2; // y axis, in meter - position[2] = 0.3; // z axis, in meter - position[3] = M_PI/8; // rotation around x axis, in rad - position[4] = M_PI/4; // rotation around y axis, in rad - position[5] = M_PI; // rotation around z axis, in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpSimulatorAfma6 robot; + int main() + { + vpColVector position(6); + // Set positions in the camera frame + position[0] = 0.1; // x axis, in meter + position[1] = 0.2; // y axis, in meter + position[2] = 0.3; // z axis, in meter + position[3] = M_PI/8; // rotation around x axis, in rad + position[4] = M_PI/4; // rotation around y axis, in rad + position[5] = M_PI; // rotation around z axis, in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpSimulatorAfma6 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the camera frame - robot.setPosition(vpRobot::CAMERA_FRAME, position); -} + // Set the max velocity to 20% + robot.setPositioningVelocity(20); + + // Moves the robot in the camera frame + robot.setPosition(vpRobot::CAMERA_FRAME, position); + } \endcode To catch the exception if the position is out of range, modify the code @@ -1444,28 +1459,32 @@ void vpSimulatorAfma6::setPosition(const vpRobot::vpControlFrameType frame, cons position is out of range. \code -#include + #include -int main() -{ - // Set positions in the camera frame - double pos1 = 0.1; // x axis, in meter - double pos2 = 0.2; // y axis, in meter - double pos3 = 0.3; // z axis, in meter - double pos4 = M_PI/8; // rotation around x axis, in rad - double pos5 = M_PI/4; // rotation around y axis, in rad - double pos6 = M_PI; // rotation around z axis, in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpSimulatorAfma6 robot; + int main() + { + // Set positions in the camera frame + double pos1 = 0.1; // x axis, in meter + double pos2 = 0.2; // y axis, in meter + double pos3 = 0.3; // z axis, in meter + double pos4 = M_PI/8; // rotation around x axis, in rad + double pos5 = M_PI/4; // rotation around y axis, in rad + double pos6 = M_PI; // rotation around z axis, in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpSimulatorAfma6 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the camera frame - robot.setPosition(vpRobot::CAMERA_FRAME, pos1, pos2, pos3, pos4, pos5, pos6); -} + // Set the max velocity to 20% + robot.setPositioningVelocity(20); + + // Moves the robot in the camera frame + robot.setPosition(vpRobot::CAMERA_FRAME, pos1, pos2, pos3, pos4, pos5, pos6); + } \endcode \sa setPosition() @@ -1502,18 +1521,22 @@ void vpSimulatorAfma6::setPosition(const vpRobot::vpControlFrameType frame, doub This method has the same behavior than the sample code given below; \code -#include -#include + #include + #include -int main() -{ - vpColVector q; - vpSimulatorAfma6 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - robot.readPosFile("MyPositionFilename.pos", q); - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); -} + int main() + { + vpColVector q; + vpSimulatorAfma6 robot; + + robot.readPosFile("MyPositionFilename.pos", q); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); + } \endcode \exception vpRobotException::lowLevelError : vpRobot::MIXT_FRAME not @@ -1561,41 +1584,44 @@ void vpSimulatorAfma6::setPosition(const char *filename) below show how to convert this position into a vpHomogeneousMatrix: \code -#include -#include -#include -#include -#include -#include - -int main() -{ - vpSimulatorAfma6 robot; - - vpColVector position; - robot.getPosition(vpRobot::REFERENCE_FRAME, position); + #include + #include + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpSimulatorAfma6 robot; + + vpColVector position; + robot.getPosition(vpRobot::REFERENCE_FRAME, position); + + vpTranslationVector ftc; // reference frame to camera frame translations + vpRxyzVector frc; // reference frame to camera frame rotations + + // Update the transformation between reference frame and camera frame + for (int i=0; i < 3; i++) { + ftc[i] = position[i]; // tx, ty, tz + frc[i] = position[i+3]; // ry, ry, rz + } - vpTranslationVector ftc; // reference frame to camera frame translations - vpRxyzVector frc; // reference frame to camera frame rotations + // Create a rotation matrix from the Rxyz rotation angles + vpRotationMatrix fRc(frc); // reference frame to camera frame rotation matrix - // Update the transformation between reference frame and camera frame - for (int i=0; i < 3; i++) { - ftc[i] = position[i]; // tx, ty, tz - frc[i] = position[i+3]; // ry, ry, rz + // Create the camera to fix frame transformation in terms of a + // homogeneous matrix + vpHomogeneousMatrix fMc(fRc, ftc); } - - // Create a rotation matrix from the Rxyz rotation angles - vpRotationMatrix fRc(frc); // reference frame to camera frame rotation matrix - - // Create the camera to fix frame transformation in terms of a - // homogeneous matrix - vpHomogeneousMatrix fMc(fRc, ftc); -} \endcode - \sa getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q, -double ×tamp) \sa setPosition(const vpRobot::vpControlFrameType frame, -const vpColVector & r) + \sa getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q, double ×tamp) + \sa setPosition(const vpRobot::vpControlFrameType frame, const vpColVector & r) */ void vpSimulatorAfma6::getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) diff --git a/modules/robot/src/robot-simulator/vpSimulatorViper850.cpp b/modules/robot/src/robot-simulator/vpSimulatorViper850.cpp index 86ebb52249..b18fc71ca3 100644 --- a/modules/robot/src/robot-simulator/vpSimulatorViper850.cpp +++ b/modules/robot/src/robot-simulator/vpSimulatorViper850.cpp @@ -692,8 +692,7 @@ vpRobot::vpRobotStateType vpSimulatorViper850::setRobotState(vpRobot::vpRobotSta Apply a velocity to the robot. \param frame : Control frame in which the velocity is expressed. Velocities - could be expressed in articular, camera frame, reference frame or mixt -frame. + could be expressed in articular, camera frame, reference frame or mixt frame. \param vel : Velocity vector. The size of this vector is always 6. @@ -702,22 +701,22 @@ frame. \dot{q}_5, \dot{q}_6]^t \f$ correspond to joint velocities in rad/s. - In camera frame, \f$ vel = [^{c} v_x, ^{c} v_y, ^{c} v_z, ^{c} - \omega_x, ^{c} \omega_y, ^{c} \omega_z]^t \f$ is a velocity twist vector -expressed in the camera frame, with translations velocities \f$ ^{c} v_x, ^{c} -v_y, ^{c} v_z \f$ in m/s and rotation velocities \f$ ^{c}\omega_x, ^{c} -\omega_y, ^{c} \omega_z \f$ in rad/s. + \omega_x, ^{c} \omega_y, ^{c} \omega_z]^t \f$ is a velocity twist vector + expressed in the camera frame, with translations velocities \f$ ^{c} v_x, ^{c} + v_y, ^{c} v_z \f$ in m/s and rotation velocities \f$ ^{c}\omega_x, ^{c} + \omega_y, ^{c} \omega_z \f$ in rad/s. - In reference frame, \f$ vel = [^{r} v_x, ^{r} v_y, ^{r} v_z, ^{r} - \omega_x, ^{r} \omega_y, ^{r} \omega_z]^t \f$ is a velocity twist vector -expressed in the reference frame, with translations velocities \f$ ^{c} v_x, -^{c} v_y, ^{c} v_z \f$ in m/s and rotation velocities \f$ ^{c}\omega_x, ^{c} -\omega_y, ^{c} \omega_z \f$ in rad/s. + \omega_x, ^{r} \omega_y, ^{r} \omega_z]^t \f$ is a velocity twist vector + expressed in the reference frame, with translations velocities \f$ ^{c} v_x, + ^{c} v_y, ^{c} v_z \f$ in m/s and rotation velocities \f$ ^{c}\omega_x, ^{c} + \omega_y, ^{c} \omega_z \f$ in rad/s. - In mixt frame, \f$ vel = [^{r} v_x, ^{r} v_y, ^{r} v_z, ^{c} \omega_x, - ^{c} \omega_y, ^{c} \omega_z]^t \f$ is a velocity twist vector where, -translations \f$ ^{r} v_x, ^{r} v_y, ^{r} v_z \f$ are expressed in the -reference frame in m/s and rotations \f$ ^{c} \omega_x, ^{c} \omega_y, ^{c} -\omega_z \f$ in the camera frame in rad/s. + ^{c} \omega_y, ^{c} \omega_z]^t \f$ is a velocity twist vector where, + translations \f$ ^{r} v_x, ^{r} v_y, ^{r} v_z \f$ are expressed in the + reference frame in m/s and rotations \f$ ^{c} \omega_x, ^{c} \omega_y, ^{c} + \omega_z \f$ in the camera frame in rad/s. \exception vpRobotException::wrongStateError : If a the robot is not configured to handle a velocity. The robot can handle a velocity only if the @@ -730,35 +729,39 @@ reference frame in m/s and rotations \f$ ^{c} \omega_x, ^{c} \omega_y, ^{c} setMaxTranslationVelocity() and setMaxRotationVelocity(). \code -#include -#include -#include - -int main() -{ - vpSimulatorViper850 robot; - - vpColVector qvel(6); - // Set a joint velocity - qvel[0] = 0.1; // Joint 1 velocity in rad/s - qvel[1] = vpMath::rad(15); // Joint 2 velocity in rad/s - qvel[2] = 0; // Joint 3 velocity in rad/s - qvel[3] = M_PI/8; // Joint 4 velocity in rad/s - qvel[4] = 0; // Joint 5 velocity in rad/s - qvel[5] = 0; // Joint 6 velocity in rad/s - - // Initialize the controller to position control - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - for ( ; ; ) { - // Apply a velocity in the joint space - robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); - - // Compute new velocities qvel... + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpSimulatorViper850 robot; + + vpColVector qvel(6); + // Set a joint velocity + qvel[0] = 0.1; // Joint 1 velocity in rad/s + qvel[1] = vpMath::rad(15); // Joint 2 velocity in rad/s + qvel[2] = 0; // Joint 3 velocity in rad/s + qvel[3] = M_PI/8; // Joint 4 velocity in rad/s + qvel[4] = 0; // Joint 5 velocity in rad/s + qvel[5] = 0; // Joint 6 velocity in rad/s + + // Initialize the controller to position control + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + for ( ; ; ) { + // Apply a velocity in the joint space + robot.setVelocity(vpRobot::ARTICULAR_FRAME, qvel); + + // Compute new velocities qvel... + } + // Stop the robot + robot.setRobotState(vpRobot::STATE_STOP); } - // Stop the robot - robot.setRobotState(vpRobot::STATE_STOP); -} \endcode */ void vpSimulatorViper850::setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) @@ -954,39 +957,43 @@ void vpSimulatorViper850::computeArticularVelocity() \warning In camera frame, reference frame and mixt frame, the representation of the rotation is ThetaU. In that cases, \f$velocity = [\dot x, \dot y, -\dot z, \dot {\theta U}_x, \dot {\theta U}_y, \dot {\theta U}_z]\f$. + \dot z, \dot {\theta U}_x, \dot {\theta U}_y, \dot {\theta U}_z]\f$. \code -#include -#include - -int main() -{ - // Set requested joint velocities - vpColVector q_dot(6); - q_dot[0] = 0.1; // Joint 1 velocity in rad/s - q_dot[1] = 0.2; // Joint 2 velocity in rad/s - q_dot[2] = 0.3; // Joint 3 velocity in rad/s - q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s - q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s - q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s - - vpSimulatorViper850 robot; - - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - // Moves the joint in velocity - robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); - - // Initialisation of the velocity measurement - vpColVector q_dot_mes; // Measured velocities - - for ( ; ; ) { - robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); - vpTime::wait(40); // wait 40 ms - // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + // Set requested joint velocities + vpColVector q_dot(6); + q_dot[0] = 0.1; // Joint 1 velocity in rad/s + q_dot[1] = 0.2; // Joint 2 velocity in rad/s + q_dot[2] = 0.3; // Joint 3 velocity in rad/s + q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s + q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s + q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s + + vpSimulatorViper850 robot; + + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + // Moves the joint in velocity + robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); + + // Initialisation of the velocity measurement + vpColVector q_dot_mes; // Measured velocities + + for ( ; ; ) { + robot.getVelocity(vpRobot::ARTICULAR_FRAME, q_dot_mes); + vpTime::wait(40); // wait 40 ms + // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + } } -} \endcode */ void vpSimulatorViper850::getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &vel) @@ -1057,36 +1064,40 @@ void vpSimulatorViper850::getVelocity(const vpRobot::vpControlFrameType frame, v and rotations in rad/s. \code -#include -#include - -int main() -{ - // Set requested joint velocities - vpColVector q_dot(6); - q_dot[0] = 0.1; // Joint 1 velocity in rad/s - q_dot[1] = 0.2; // Joint 2 velocity in rad/s - q_dot[2] = 0.3; // Joint 3 velocity in rad/s - q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s - q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s - q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s - - vpSimulatorViper850 robot; - - robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); - - // Moves the joint in velocity - robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); - - // Initialisation of the velocity measurement - vpColVector q_dot_mes; // Measured velocities - - for ( ; ; ) { - q_dot_mes = robot.getVelocity(vpRobot::ARTICULAR_FRAME); - vpTime::wait(40); // wait 40 ms - // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + // Set requested joint velocities + vpColVector q_dot(6); + q_dot[0] = 0.1; // Joint 1 velocity in rad/s + q_dot[1] = 0.2; // Joint 2 velocity in rad/s + q_dot[2] = 0.3; // Joint 3 velocity in rad/s + q_dot[3] = M_PI/8; // Joint 4 velocity in rad/s + q_dot[4] = M_PI/4; // Joint 5 velocity in rad/s + q_dot[5] = M_PI/16;// Joint 6 velocity in rad/s + + vpSimulatorViper850 robot; + + robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL); + + // Moves the joint in velocity + robot.setVelocity(vpRobot::ARTICULAR_FRAME, q_dot); + + // Initialisation of the velocity measurement + vpColVector q_dot_mes; // Measured velocities + + for ( ; ; ) { + q_dot_mes = robot.getVelocity(vpRobot::ARTICULAR_FRAME); + vpTime::wait(40); // wait 40 ms + // here q_dot_mes is equal to [0.1, 0.2, 0.3, M_PI/8, M_PI/4, M_PI/16] + } } -} \endcode */ vpColVector vpSimulatorViper850::getVelocity(vpRobot::vpControlFrameType frame) @@ -1165,30 +1176,34 @@ void vpSimulatorViper850::findHighestPositioningSpeed(vpColVector &q) position is out of range. \code -#include -#include + #include + #include -int main() -{ - vpColVector position(6); - // Set positions in the camera frame - position[0] = 0.1; // x axis, in meter - position[1] = 0.2; // y axis, in meter - position[2] = 0.3; // z axis, in meter - position[3] = M_PI/8; // rotation around x axis, in rad - position[4] = M_PI/4; // rotation around y axis, in rad - position[5] = M_PI; // rotation around z axis, in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpSimulatorViper850 robot; + int main() + { + vpColVector position(6); + // Set positions in the camera frame + position[0] = 0.1; // x axis, in meter + position[1] = 0.2; // y axis, in meter + position[2] = 0.3; // z axis, in meter + position[3] = M_PI/8; // rotation around x axis, in rad + position[4] = M_PI/4; // rotation around y axis, in rad + position[5] = M_PI; // rotation around z axis, in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpSimulatorViper850 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the camera frame - robot.setPosition(vpRobot::CAMERA_FRAME, position); -} + // Set the max velocity to 20% + robot.setPositioningVelocity(20); + + // Moves the robot in the camera frame + robot.setPosition(vpRobot::CAMERA_FRAME, position); + } \endcode To catch the exception if the position is out of range, modify the code @@ -1373,28 +1388,32 @@ void vpSimulatorViper850::setPosition(const vpRobot::vpControlFrameType frame, c position is out of range. \code -#include + #include -int main() -{ - // Set positions in the camera frame - double pos1 = 0.1; // x axis, in meter - double pos2 = 0.2; // y axis, in meter - double pos3 = 0.3; // z axis, in meter - double pos4 = M_PI/8; // rotation around x axis, in rad - double pos5 = M_PI/4; // rotation around y axis, in rad - double pos6 = M_PI; // rotation around z axis, in rad + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpRobotViper850 robot; + int main() + { + // Set positions in the camera frame + double pos1 = 0.1; // x axis, in meter + double pos2 = 0.2; // y axis, in meter + double pos3 = 0.3; // z axis, in meter + double pos4 = M_PI/8; // rotation around x axis, in rad + double pos5 = M_PI/4; // rotation around y axis, in rad + double pos6 = M_PI; // rotation around z axis, in rad - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + vpRobotViper850 robot; - // Set the max velocity to 20% - robot.setPositioningVelocity(20); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Moves the robot in the camera frame - robot.setPosition(vpRobot::CAMERA_FRAME, pos1, pos2, pos3, pos4, pos5, pos6); -} + // Set the max velocity to 20% + robot.setPositioningVelocity(20); + + // Moves the robot in the camera frame + robot.setPosition(vpRobot::CAMERA_FRAME, pos1, pos2, pos3, pos4, pos5, pos6); + } \endcode \sa setPosition() @@ -1431,18 +1450,22 @@ void vpSimulatorViper850::setPosition(const vpRobot::vpControlFrameType frame, d This method has the same behavior than the sample code given below; \code -#include -#include + #include + #include -int main() -{ - vpColVector q; - vpSimulatorViper850 robot; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - robot.readPosFile("MyPositionFilename.pos", q); - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); -} + int main() + { + vpColVector q; + vpSimulatorViper850 robot; + + robot.readPosFile("MyPositionFilename.pos", q); + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); + } \endcode \exception vpRobotException::lowLevelError : vpRobot::MIXT_FRAME not @@ -1490,41 +1513,44 @@ void vpSimulatorViper850::setPosition(const char *filename) below show how to convert this position into a vpHomogeneousMatrix: \code -#include -#include -#include -#include -#include -#include - -int main() -{ - vpSimulatorViper850 robot; - - vpColVector position; - robot.getPosition(vpRobot::REFERENCE_FRAME, position); + #include + #include + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpSimulatorViper850 robot; + + vpColVector position; + robot.getPosition(vpRobot::REFERENCE_FRAME, position); + + vpTranslationVector ftc; // reference frame to camera frame translations + vpRxyzVector frc; // reference frame to camera frame rotations + + // Update the transformation between reference frame and camera frame + for (int i=0; i < 3; i++) { + ftc[i] = position[i]; // tx, ty, tz + frc[i] = position[i+3]; // ry, ry, rz + } - vpTranslationVector ftc; // reference frame to camera frame translations - vpRxyzVector frc; // reference frame to camera frame rotations + // Create a rotation matrix from the Rxyz rotation angles + vpRotationMatrix fRc(frc); // reference frame to camera frame rotation matrix - // Update the transformation between reference frame and camera frame - for (int i=0; i < 3; i++) { - ftc[i] = position[i]; // tx, ty, tz - frc[i] = position[i+3]; // ry, ry, rz + // Create the camera to fix frame transformation in terms of a + // homogeneous matrix + vpHomogeneousMatrix fMc(fRc, ftc); } - - // Create a rotation matrix from the Rxyz rotation angles - vpRotationMatrix fRc(frc); // reference frame to camera frame rotation matrix - - // Create the camera to fix frame transformation in terms of a - // homogeneous matrix - vpHomogeneousMatrix fMc(fRc, ftc); -} \endcode - \sa getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q, -double ×tamp) \sa setPosition(const vpRobot::vpControlFrameType frame, -const vpColVector & r) + \sa getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q, double ×tamp) + \sa setPosition(const vpRobot::vpControlFrameType frame, const vpColVector & r) */ void vpSimulatorViper850::getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) @@ -1850,65 +1876,69 @@ void vpSimulatorViper850::getDisplacement(vpRobot::vpControlFrameType frame, vpC } /*! -Read joint positions in a specific Viper850 position file. + Read joint positions in a specific Viper850 position file. -This position file has to start with a header. The six joint positions -are given after the "R:" keyword. The first 3 values correspond to the -joint translations X,Y,Z expressed in meters. The 3 last values -correspond to the joint rotations A,B,C expressed in degres to be more -representative for the user. Theses values are then converted in -radians in \e q. The character "#" starting a line indicates a -comment. + This position file has to start with a header. The six joint positions + are given after the "R:" keyword. The first 3 values correspond to the + joint translations X,Y,Z expressed in meters. The 3 last values + correspond to the joint rotations A,B,C expressed in degres to be more + representative for the user. Theses values are then converted in + radians in \e q. The character "#" starting a line indicates a + comment. -A typical content of such a file is given below: + A typical content of such a file is given below: -\code -#Viper - Position - Version 1.0 -# file: "myposition.pos " -# -# R: A B C D E F -# Joint position in degrees -# + \code + #Viper - Position - Version 1.0 + # file: "myposition.pos " + # + # R: A B C D E F + # Joint position in degrees + # + + R: 0.1 0.3 -0.25 -80.5 80 0 + \endcode -R: 0.1 0.3 -0.25 -80.5 80 0 -\endcode + \param filename : Name of the position file to read. -\param filename : Name of the position file to read. + \param q : The six joint positions. Values are expressed in radians. -\param q : The six joint positions. Values are expressed in radians. + \return true if the positions were successfully readen in the file. false, if + an error occurs. -\return true if the positions were successfully readen in the file. false, if -an error occurs. + The code below shows how to read a position from a file and move the robot to + this position. + \code + #include + #include -The code below shows how to read a position from a file and move the robot to -this position. -\code -#include -#include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif -int main() -{ - vpSimulatorViper850 robot; + int main() + { + vpSimulatorViper850 robot; - // Enable the position control of the robot - robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); + // Enable the position control of the robot + robot.setRobotState(vpRobot::STATE_POSITION_CONTROL); - // Get the current robot joint positions - vpColVector q; // Current joint position - robot.getPosition(vpRobot::ARTICULAR_FRAME, q); + // Get the current robot joint positions + vpColVector q; // Current joint position + robot.getPosition(vpRobot::ARTICULAR_FRAME, q); - // Save this position in a file named "current.pos" - robot.savePosFile("current.pos", q); + // Save this position in a file named "current.pos" + robot.savePosFile("current.pos", q); - // Get the position from a file and move to the registered position - robot.readPosFile("current.pos", q); // Set the joint position from the file + // Get the position from a file and move to the registered position + robot.readPosFile("current.pos", q); // Set the joint position from the file - robot.setPositioningVelocity(5); // Positioning velocity set to 5% - robot.setPosition(vpRobot::ARTICULAR_FRAME, q); // Move to the joint position -} -\endcode + robot.setPositioningVelocity(5); // Positioning velocity set to 5% + robot.setPosition(vpRobot::ARTICULAR_FRAME, q); // Move to the joint position + } + \endcode -\sa savePosFile() + \sa savePosFile() */ bool vpSimulatorViper850::readPosFile(const std::string &filename, vpColVector &q) { diff --git a/modules/robot/src/vpRobot.cpp b/modules/robot/src/vpRobot.cpp index 546c300b63..4d432361a2 100644 --- a/modules/robot/src/vpRobot.cpp +++ b/modules/robot/src/vpRobot.cpp @@ -124,37 +124,41 @@ different dimensions. velocity skew vector. \code -#include - -#include - -int main() -{ - // Set a velocity skew vector - vpColVector v(6); - v[0] = 0.1; // vx in m/s - v[1] = 0.2; // vy - v[2] = 0.3; // vz - v[3] = vpMath::rad(10); // wx in rad/s - v[4] = vpMath::rad(-10); // wy - v[5] = vpMath::rad(20); // wz - - // Set the maximal allowed velocities - vpColVector v_max(6); - for (int i=0; i<3; i++) - v_max[i] = 0.3; // in translation (m/s) - for (int i=3; i<6; i++) - v_max[i] = vpMath::rad(10); // in rotation (rad/s) - - // Compute the saturated velocity skew vector - vpColVector v_sat = vpRobot::saturateVelocities(v, v_max, true); - - std::cout << "v : " << v.t() << std::endl; - std::cout << "v max: " << v_max.t() << std::endl; - std::cout << "v sat: " << v_sat.t() << std::endl; - - return 0; -} + #include + + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + // Set a velocity skew vector + vpColVector v(6); + v[0] = 0.1; // vx in m/s + v[1] = 0.2; // vy + v[2] = 0.3; // vz + v[3] = vpMath::rad(10); // wx in rad/s + v[4] = vpMath::rad(-10); // wy + v[5] = vpMath::rad(20); // wz + + // Set the maximal allowed velocities + vpColVector v_max(6); + for (int i=0; i<3; i++) + v_max[i] = 0.3; // in translation (m/s) + for (int i=3; i<6; i++) + v_max[i] = vpMath::rad(10); // in rotation (rad/s) + + // Compute the saturated velocity skew vector + vpColVector v_sat = vpRobot::saturateVelocities(v, v_max, true); + + std::cout << "v : " << v.t() << std::endl; + std::cout << "v max: " << v_max.t() << std::endl; + std::cout << "v sat: " << v_sat.t() << std::endl; + + return 0; + } \endcode */ vpColVector vpRobot::saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose) diff --git a/modules/sensor/include/visp3/sensor/vp1394CMUGrabber.h b/modules/sensor/include/visp3/sensor/vp1394CMUGrabber.h index c6de07b3c4..8b821061ab 100644 --- a/modules/sensor/include/visp3/sensor/vp1394CMUGrabber.h +++ b/modules/sensor/include/visp3/sensor/vp1394CMUGrabber.h @@ -93,58 +93,62 @@ grab and display images from a firewire camera under Windows. how to grab and display images from the first camera found on the bus. \code -#include + #include -#include -#include -#include - -int main() -{ -#if defined(VISP_HAVE_CMU1394) - std::cout << "ViSP Image acquisition example" << std::endl; + #include + #include + #include - vpImage I; - vp1394CMUGrabber g; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - if( g.getNumberOfConnectedCameras() > 1 ) - std::cout << "There are " << g.getNumberOfConnectedCameras() << " connected cameras." << std::endl; - if( g.getNumberOfConnectedCameras() == 1 ) - std::cout << "There is " << g.getNumberOfConnectedCameras() << " connected camera." << std::endl; - else - std::cout << "There is no connected camera." << std::endl; + int main() + { + #if defined(VISP_HAVE_CMU1394) + std::cout << "ViSP Image acquisition example" << std::endl; + + vpImage I; + vp1394CMUGrabber g; + + if( g.getNumberOfConnectedCameras() > 1 ) + std::cout << "There are " << g.getNumberOfConnectedCameras() << " connected cameras." << std::endl; + if( g.getNumberOfConnectedCameras() == 1 ) + std::cout << "There is " << g.getNumberOfConnectedCameras() << " connected camera." << std::endl; + else + std::cout << "There is no connected camera." << std::endl; + + // Setting camera parameters manually + g.selectCamera(0); + g.setGain(0); + g.setShutter(2000); + g.setFramerate(3); // 15 FPS + g.setVideoMode(0, 5); // 640x480 - MONO - // Setting camera parameters manually - g.selectCamera(0); - g.setGain(0); - g.setShutter(2000); - g.setFramerate(3); // 15 FPS - g.setVideoMode(0, 5); // 640x480 - MONO + g.acquire(I); - g.acquire(I); + // Display camera description + g.displayCameraDescription(0); + g.displayCameraModel(); + std::cout << "Height: " << g.getHeight() << " Width: " << g.getWidth() << std::endl; - // Display camera description - g.displayCameraDescription(0); - g.displayCameraModel(); - std::cout << "Height: " << g.getHeight() << " Width: " << g.getWidth() << std::endl; + vpDisplayOpenCV d(I); + vpDisplay::display(I); - vpDisplayOpenCV d(I); - vpDisplay::display(I); + for(;;) + { + g.acquire(I); + vpDisplay::display(I); + vpDisplay::flush(I); + if (vpDisplay::getClick(I, false)) // a click to exit + break; + } - for(;;) - { - g.acquire(I); - vpDisplay::display(I); - vpDisplay::flush(I); - if (vpDisplay::getClick(I, false)) // a click to exit - break; + g.close(); + #endif + std::cout << "ViSP exiting..." < #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_DC1394) @@ -141,6 +145,10 @@ BEGIN_VISP_NAMESPACE #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_DC1394) diff --git a/modules/sensor/include/visp3/sensor/vpComedi.h b/modules/sensor/include/visp3/sensor/vpComedi.h index 7caa78f634..a8fa6da514 100644 --- a/modules/sensor/include/visp3/sensor/vpComedi.h +++ b/modules/sensor/include/visp3/sensor/vpComedi.h @@ -52,56 +52,60 @@ BEGIN_VISP_NAMESPACE \ingroup group_sensor_ft Interface for data acquisition devices supported by Comedi. Comedi is a -linux control and measurement device interface. For more information see -http://www.comedi.org. + linux control and measurement device interface. For more information see + http://www.comedi.org. This class was tested with ATI Gamma 65-SI FT sensor connected to a National Instrument NI DAQmx PCI-6220 board. \warning If you experience an exception like \code -Could not open device /dev/comedi0 + Could not open device /dev/comedi0 \endcode - you may set up udev permissions for Comedi device files. Once Comedi is -installed you also need to make sure that the user has appropriate permissions -for accessing the Comedi device files. That is you need to be able to have -read and write access to the /dev/comedi* files. One elegant way to achieve -this to create a new group and tell udev to add the Comedi device files to -this group. To this end: + you may set up udev permissions for Comedi device files. Once Comedi is + installed you also need to make sure that the user has appropriate permissions + for accessing the Comedi device files. That is you need to be able to have + read and write access to the /dev/comedi* files. One elegant way to achieve + this to create a new group and tell udev to add the Comedi device files to + this group. To this end: 1. Login as root 2. Create a new group "iocard": \code -$ addgroup --system iocard + $ addgroup --system iocard \endcode 3. Add udev rules to the /etc/udev/rules.d directory: \code -$ echo 'KERNEL=="comedi*", MODE="0660", GROUP="iocard"' > -/etc/udev/rules.d/95-comedi.rules \endcode + $ echo 'KERNEL=="comedi*", MODE="0660", GROUP="iocard"' > /etc/udev/rules.d/95-comedi.rules + \endcode 4. Add users to the "iocard" group: \code -$ adduser iocard + $ adduser iocard \endcode 5. Reboot The following example shows how to run an synchronous data acquisition at -500 Hz, calling getPhyData() each 2 ms: - -\code -#include + 500 Hz, calling getPhyData() each 2 ms: -int main() -{ - vpComedi comedi; - comedi.setDevice("/dev/comedi0"); - comedi.setChannelNumbers(6); // to read a F/T tensor - comedi.open(); - - for(unsigned int i=0; i < 500; i++) { - std::cout << "Physical data (in " << comedi.getPhyDataUnits() << "): " << comedi.getPhyData().t() << std::endl; - vpTime::wait(2); + \code + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpComedi comedi; + comedi.setDevice("/dev/comedi0"); + comedi.setChannelNumbers(6); // to read a F/T tensor + comedi.open(); + + for(unsigned int i=0; i < 500; i++) { + std::cout << "Physical data (in " << comedi.getPhyDataUnits() << "): " << comedi.getPhyData().t() << std::endl; + vpTime::wait(2); + } + comedi.close(); } - comedi.close(); -} \endcode */ class VISP_EXPORT vpComedi diff --git a/modules/sensor/include/visp3/sensor/vpFlyCaptureGrabber.h b/modules/sensor/include/visp3/sensor/vpFlyCaptureGrabber.h index db29e48308..59d1588c2a 100644 --- a/modules/sensor/include/visp3/sensor/vpFlyCaptureGrabber.h +++ b/modules/sensor/include/visp3/sensor/vpFlyCaptureGrabber.h @@ -70,7 +70,7 @@ BEGIN_VISP_NAMESPACE Grab loop had an error: There is an image consistency issue with this image. \endcode follow instruction provide -[here](https://www.flir.fr/support-center/iis/machine-vision/knowledge-base/lost-ethernet-data-packets-on-linux-systems) + [here](https://www.flir.fr/support-center/iis/machine-vision/knowledge-base/lost-ethernet-data-packets-on-linux-systems) to increase receive buffer size. Once installed configure ViSP using cmake to detect FlyCapture SDK and build @@ -84,31 +84,35 @@ BEGIN_VISP_NAMESPACE The following example shows how to use this class to capture images from the first camera that is found. \code -#include -#include -#include + #include + #include + #include -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - try { - int nframes = 100; - vpImage I; - char filename[FILENAME_MAX]; - vpFlyCaptureGrabber g; - std::cout << "Number of cameras detected: " << g.getNumCameras() << std::endl; - - g.setCameraIndex(0); // Default camera is the first on the bus - g.getCameraInfo(std::cout); - g.open(I); - - for(int i=0; i< nframes; i++) { - g.acquire(I); - snprintf(filename, FILENAME_MAX, "image%04d.pgm", i); - vpImageIo::write(I, filename); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + try { + int nframes = 100; + vpImage I; + char filename[FILENAME_MAX]; + vpFlyCaptureGrabber g; + std::cout << "Number of cameras detected: " << g.getNumCameras() << std::endl; + + g.setCameraIndex(0); // Default camera is the first on the bus + g.getCameraInfo(std::cout); + g.open(I); + + for(int i=0; i< nframes; i++) { + g.acquire(I); + snprintf(filename, FILENAME_MAX, "image%04d.pgm", i); + vpImageIo::write(I, filename); + } + #endif } -#endif -} \endcode If more than one camera is detected, you can use setCamera(const unsigned int &) @@ -122,6 +126,10 @@ int main() #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_FLYCAPTURE) diff --git a/modules/sensor/include/visp3/sensor/vpForceTorqueIitSensor.h b/modules/sensor/include/visp3/sensor/vpForceTorqueIitSensor.h index 628bdf994f..4e9c8b96e5 100644 --- a/modules/sensor/include/visp3/sensor/vpForceTorqueIitSensor.h +++ b/modules/sensor/include/visp3/sensor/vpForceTorqueIitSensor.h @@ -67,81 +67,87 @@ BEGIN_VISP_NAMESPACE The following example shows how to use this class to stream force-torque data at 1kHz and print a measurement each second. \code -#include - -#include -#include - -int main() -{ -#ifdef VISP_HAVE_FT_IIT_SDK - vpForceTorqueIitSensor iit_ft; - - if ( ! iit_ft.connected() ) { - std::cout << "Unable to connect to IIT force-torque sensor" << std::endl; + #include + + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #ifdef VISP_HAVE_FT_IIT_SDK + vpForceTorqueIitSensor iit_ft; + + if ( ! iit_ft.connected() ) { + std::cout << "Unable to connect to IIT force-torque sensor" << std::endl; + return EXIT_SUCCESS; + } + + iit_ft.bias(); + iit_ft.startStreaming(); + vpColVector ft; + for(int i=0; i < 10; i++) { + ft = iit_ft.getForceTorque(); + std::cout << ft.t() << std::endl; + vpTime::sleepMs(1000); + } + iit_ft.stopStreaming(); + + #else + std::cout << "ViSP is not build with IIT force-torque SDK support" << std::endl; + #endif return EXIT_SUCCESS; } - - iit_ft.bias(); - iit_ft.startStreaming(); - vpColVector ft; - for(int i=0; i < 10; i++) { - ft = iit_ft.getForceTorque(); - std::cout << ft.t() << std::endl; - vpTime::sleepMs(1000); - } - iit_ft.stopStreaming(); - -#else - std::cout << "ViSP is not build with IIT force-torque SDK support" << std::endl; -#endif - return EXIT_SUCCESS; -} \endcode Once build, in the same folder as the binary you should find a configuration file named `configurationSettings.ini`. - Such a file is provided in `$VISP_WS/modules/sensor/test/force-torque/configurationSettings.ini` with default - settings. \include configurationSettings.ini + settings. + \include configurationSettings.ini - To modify default settings you need first to identify your Ethernet link: \code -$ ifconfig -enp0s31f6: flags=4163 mtu 1500 - inet 192.168.100.100 netmask 255.255.255.0 broadcast 192.168.100.255 + $ ifconfig + enp0s31f6: flags=4163 mtu 1500 + inet 192.168.100.100 netmask 255.255.255.0 broadcast 192.168.100.255 \endcode - and then modify accordingly the following lines: \verbatim -LOCAL_IFACE_IP = 192.168.100.100 ; Host Computer's local interface IP -LOCAL_IFACE = enp0s31f6 ; Host Computer's local interface name (it is required only in Linux) + LOCAL_IFACE_IP = 192.168.100.100 ; Host Computer's local interface IP + LOCAL_IFACE = enp0s31f6 ; Host Computer's local interface name (it is required only in Linux) \endverbatim - The sensor default IP is set to `192.168.1.1`. Browsing to this address with Firefox allows to modify it's default IP address. If the new sensor IP address is for example `192.168.100.10`, you need to modify the following line: \verbatim -USE_DEFAULT_SETTINGS = false ; If "true", the library will use the - ; DEFAULT_SETTINGS. Note that the sensor - ; needs to be in the "DEF" IP position. - ; If "false", the library will use the - ; USER_SETTINGS to initialize the communication - ; with the sensor. -[USER_SETTINGS] ; USER SETTINGS FOR USE IN SINGLE_SENSOR_MODE when USE_DEFAULT_SETTINGS=false -USER_IP = 192.168.100.10 ; User Sensor IP + USE_DEFAULT_SETTINGS = false ; If "true", the library will use the + ; DEFAULT_SETTINGS. Note that the sensor + ; needs to be in the "DEF" IP position. + ; If "false", the library will use the + ; USER_SETTINGS to initialize the communication + ; with the sensor. + [USER_SETTINGS] ; USER SETTINGS FOR USE IN SINGLE_SENSOR_MODE when USE_DEFAULT_SETTINGS=false + USER_IP = 192.168.100.10 ; User Sensor IP \endverbatim When running a binary that uses vpForceTorqueIitSensor class, - if you experience the following error: \code -$ cd $VISP_WS/modules/sensor -$ ./testForceTorqueIitSensor-simple -./testForceTorqueIitSensor-simple: error while loading shared libraries: libftSensorLib.so.0.0.1: cannot open shared -object file: No such file or directory \endcode + $ cd $VISP_WS/modules/sensor + $ ./testForceTorqueIitSensor-simple + ./testForceTorqueIitSensor-simple: error while loading shared libraries: libftSensorLib.so.0.0.1: cannot open shared + object file: No such file or directory + \endcode - it means that you need to add the location of the library in `LD_LIBRARY_PATH` environment variable. This could be achieved running: \code -$ export -LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$VISP_WS/3rdparty/FT_SDK_01_4/linux/ubuntu16.04/ftSensorLibReleaseExamples/library/bin/lin-x86_64/release + $ export + LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$VISP_WS/3rdparty/FT_SDK_01_4/linux/ubuntu16.04/ftSensorLibReleaseExamples/library/bin/lin-x86_64/release \endcode where `$VISP_WS/3rdparty/FT_SDK_01_4` contains IIT SDK. - To configure the sensor, you may access the sensor through the web interface using uour favorite browser. + To configure the sensor, you may access the sensor through the web interface using your favorite browser. \image html vpForceTorqueIitSensor-ethernet.png */ diff --git a/modules/sensor/include/visp3/sensor/vpKinect.h b/modules/sensor/include/visp3/sensor/vpKinect.h index 8d3d8ab9a9..0c35059d3b 100644 --- a/modules/sensor/include/visp3/sensor/vpKinect.h +++ b/modules/sensor/include/visp3/sensor/vpKinect.h @@ -64,47 +64,51 @@ BEGIN_VISP_NAMESPACE \brief Driver for the Kinect-1 device. To be enabled this class requires libfreenect 3rd party. Installation -instructions are provided here https://visp.inria.fr/3rd_freenect. + instructions are provided here https://visp.inria.fr/3rd_freenect. The following example shows how to use this class to acquire data (depth map and color image) from a Kinect. \code -#include -#include - -int main() { -#ifdef VISP_HAVE_LIBFREENECT_AND_DEPENDENCIES - // Init Kinect device -#ifdef VISP_HAVE_LIBFREENECT_OLD - // This is the way to initialize Freenect with an old version of libfreenect - // package under ubuntu lucid 10.04 - Freenect::Freenect freenect; - vpKinect * kinect = &freenect.createDevice(0); -#else - Freenect::Freenect freenect; - vpKinect * kinect = &freenect.createDevice(0); -#endif - kinect->start(); // Start acquisition thread - - // Set tilt angle - float angle = -5; - kinect->setTiltDegrees(angle); - - vpImage I(480,640); - vpImage Irgb(480,640); - vpImage dmap(480,640); - - // Acquisition loop - for (int i=0; i<100; i++) - { - kinect->getDepthMap(dmap,I); - kinect->getRGB(Irgb); + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() { + #ifdef VISP_HAVE_LIBFREENECT_AND_DEPENDENCIES + // Init Kinect device + #ifdef VISP_HAVE_LIBFREENECT_OLD + // This is the way to initialize Freenect with an old version of libfreenect + // package under ubuntu lucid 10.04 + Freenect::Freenect freenect; + vpKinect * kinect = &freenect.createDevice(0); + #else + Freenect::Freenect freenect; + vpKinect * kinect = &freenect.createDevice(0); + #endif + kinect->start(); // Start acquisition thread + + // Set tilt angle + float angle = -5; + kinect->setTiltDegrees(angle); + + vpImage I(480,640); + vpImage Irgb(480,640); + vpImage dmap(480,640); + + // Acquisition loop + for (int i=0; i<100; i++) + { + kinect->getDepthMap(dmap,I); + kinect->getRGB(Irgb); + } + kinect->stop(); // Stop acquisition thread + #endif + return 0; } - kinect->stop(); // Stop acquisition thread -#endif - return 0; -} \endcode */ class VISP_EXPORT vpKinect : public Freenect::FreenectDevice diff --git a/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h b/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h index 43a60d9f7c..59d7772bc1 100644 --- a/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h +++ b/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h @@ -56,151 +56,159 @@ BEGIN_VISP_NAMESPACE /*! - \class vpOccipitalStructure - - \ingroup group_sensor_rgbd - - This class provides a wrapper over the Occipital Structure SDK - library https://structure.io/developers. It allows to capture - data from the Occipital Structure Core camera. - - \note Supported devices for Occipital Structure SDK 0.9: - - Occipital Structure Core. - - The usage of vpOccipitalStructure class is enabled when libStructure 3rd party is - successfully installed. The following tutorials explain how to proceed: - - \ref tutorial-install-ubuntu - - \ref tutorial-install-win10-msvc16 - - \ref tutorial-install-osx-homebrew - - Moreover, if Point Cloud Library (PCL) 3rd party is installed, we also - propose interfaces to retrieve point cloud as pcl::PointCloud - or pcl::PointCloud data structures. - - \warning Notice that the usage of this class requires compiler and library - support for the ISO C++ 2011 standard. This support is enabled by default - in ViSP when supported by the compiler. Hereafter we give an example of a - CMakeLists.txt file that allows to build `sample-structure-core.cpp` that - uses vpOccipitalStructure class. - - \code - cmake_minimum_required(VERSION 3.5) - - project(sample) - - find_package(VISP REQUIRED) - include_directories(${VISP_INCLUDE_DIRS}) - - add_executable(sample-structure-core sample-structure-core.cpp) - target_link_libraries(sample-structure-core ${VISP_LIBRARIES}) - \endcode - - To acquire images from the Structure Core color camera and convert them into grey - level images, a good starting is to use the following code that corresponds to - the content of ``sample-structure-core.cpp`: - - \code - #include - #include - #include - - int main() - { - vpOccipitalStructure sc; - ST::CaptureSessionSettings settings; - settings.source = ST::CaptureSessionSourceId::StructureCore; - settings.structureCore.visibleEnabled = true; - - sc.open(settings); - - vpImage I(sc.getHeight(vpOccipitalStructure::visible), sc.getWidth(vpOccipitalStructure::visible)); - #ifdef VISP_HAVE_X11 - vpDisplayX d(I); - #elif defined(VISP_HAVE_GDI) - vpDisplayGDI d(I); - #endif - - while (true) { - sc.acquire(I); - vpDisplay::display(I); - vpDisplay::flush(I); - if (vpDisplay::getClick(I, false)) - break; - } - return 0; - } - \endcode - - If you want to acquire color images, in the previous sample replace: - \code - vpImage I(sc.getHeight(vpOccipitalStructure::visible), sc.getWidth(vpOccipitalStructure::visible)); - \endcode - by - \code - vpImage I(sc.getHeight(vpOccipitalStructure::visible), sc.getWidth(vpOccipitalStructure::visible)); - \endcode - - If you are interested in the point cloud and if ViSP is build with PCL - support, you can start from the following example where we use PCL library to - visualize the point cloud - - \code - #include - #include - #include - - int main() - { - vpOccipitalStructure sc; - ST::CaptureSessionSettings settings; - settings.source = ST::CaptureSessionSourceId::StructureCore; - settings.structureCore.visibleEnabled = true; - settings.applyExpensiveCorrection = true; // Apply a correction and clean filter to the depth before streaming. - - sc.open(settings); - // Calling these 2 functions to set internal variables. - sc.getCameraParameters(vpOccipitalStructure::visible); - sc.getCameraParameters(vpOccipitalStructure::depth); - - pcl::PointCloud::Ptr pointcloud(new pcl::PointCloud); - - sc.acquire(nullptr, nullptr, nullptr, pointcloud); - - pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer")); - pcl::visualization::PointCloudColorHandlerRGBField rgb(pointcloud); - viewer->setBackgroundColor(0, 0, 0); - viewer->initCameraParameters(); - viewer->setCameraPosition(0, 0, -0.5, 0, -1, 0); - - while (true) { - sc.acquire(nullptr, nullptr, nullptr, pointcloud); - - static bool update = false; - if (!update) { - viewer->addPointCloud (pointcloud, rgb, "sample cloud"); - viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud"); - update = true; - } else { - viewer->updatePointCloud (pointcloud, rgb, "sample cloud"); - } - - viewer->spinOnce(30); - } - return 0; - } - \endcode - - References to `ST::CaptureSession` and `ST::CaptureSessionSettings` can be retrieved - with (`sc.open() must be called before`): - \code - ST::CaptureSession &getCaptureSession(); - ST::CaptureSessionSettings &getCaptureSessionSettings(); - \endcode + \class vpOccipitalStructure + + \ingroup group_sensor_rgbd + + This class provides a wrapper over the Occipital Structure SDK + library https://structure.io/developers. It allows to capture + data from the Occipital Structure Core camera. + + \note Supported devices for Occipital Structure SDK 0.9: + - Occipital Structure Core. + + The usage of vpOccipitalStructure class is enabled when libStructure 3rd party is + successfully installed. The following tutorials explain how to proceed: + - \ref tutorial-install-ubuntu + - \ref tutorial-install-win10-msvc16 + - \ref tutorial-install-osx-homebrew + + Moreover, if Point Cloud Library (PCL) 3rd party is installed, we also + propose interfaces to retrieve point cloud as pcl::PointCloud + or pcl::PointCloud data structures. + + \warning Notice that the usage of this class requires compiler and library + support for the ISO C++ 2011 standard. This support is enabled by default + in ViSP when supported by the compiler. Hereafter we give an example of a + CMakeLists.txt file that allows to build `sample-structure-core.cpp` that + uses vpOccipitalStructure class. + + \code + cmake_minimum_required(VERSION 3.5) + + project(sample) + + find_package(VISP REQUIRED) + include_directories(${VISP_INCLUDE_DIRS}) + + add_executable(sample-structure-core sample-structure-core.cpp) + target_link_libraries(sample-structure-core ${VISP_LIBRARIES}) + \endcode + + To acquire images from the Structure Core color camera and convert them into grey + level images, a good starting is to use the following code that corresponds to + the content of ``sample-structure-core.cpp`: + + \code + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpOccipitalStructure sc; + ST::CaptureSessionSettings settings; + settings.source = ST::CaptureSessionSourceId::StructureCore; + settings.structureCore.visibleEnabled = true; + + sc.open(settings); + + vpImage I(sc.getHeight(vpOccipitalStructure::visible), sc.getWidth(vpOccipitalStructure::visible)); + #ifdef VISP_HAVE_X11 + vpDisplayX d(I); + #elif defined(VISP_HAVE_GDI) + vpDisplayGDI d(I); + #endif + + while (true) { + sc.acquire(I); + vpDisplay::display(I); + vpDisplay::flush(I); + if (vpDisplay::getClick(I, false)) + break; + } + return 0; + } + \endcode + + If you want to acquire color images, in the previous sample replace: + \code + vpImage I(sc.getHeight(vpOccipitalStructure::visible), sc.getWidth(vpOccipitalStructure::visible)); + \endcode + by + \code + vpImage I(sc.getHeight(vpOccipitalStructure::visible), sc.getWidth(vpOccipitalStructure::visible)); + \endcode + + If you are interested in the point cloud and if ViSP is build with PCL + support, you can start from the following example where we use PCL library to + visualize the point cloud + + \code + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpOccipitalStructure sc; + ST::CaptureSessionSettings settings; + settings.source = ST::CaptureSessionSourceId::StructureCore; + settings.structureCore.visibleEnabled = true; + settings.applyExpensiveCorrection = true; // Apply a correction and clean filter to the depth before streaming. + + sc.open(settings); + // Calling these 2 functions to set internal variables. + sc.getCameraParameters(vpOccipitalStructure::visible); + sc.getCameraParameters(vpOccipitalStructure::depth); + + pcl::PointCloud::Ptr pointcloud(new pcl::PointCloud); + + sc.acquire(nullptr, nullptr, nullptr, pointcloud); + + pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer")); + pcl::visualization::PointCloudColorHandlerRGBField rgb(pointcloud); + viewer->setBackgroundColor(0, 0, 0); + viewer->initCameraParameters(); + viewer->setCameraPosition(0, 0, -0.5, 0, -1, 0); + + while (true) { + sc.acquire(nullptr, nullptr, nullptr, pointcloud); + + static bool update = false; + if (!update) { + viewer->addPointCloud (pointcloud, rgb, "sample cloud"); + viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud"); + update = true; + } else { + viewer->updatePointCloud (pointcloud, rgb, "sample cloud"); + } + + viewer->spinOnce(30); + } + return 0; + } + \endcode + + References to `ST::CaptureSession` and `ST::CaptureSessionSettings` can be retrieved + with (`sc.open() must be called before`): + \code + ST::CaptureSession &getCaptureSession(); + ST::CaptureSessionSettings &getCaptureSessionSettings(); + \endcode */ #ifndef DOXYGEN_SHOULD_SKIP_THIS -struct SessionDelegate : ST::CaptureSessionDelegate + struct SessionDelegate : ST::CaptureSessionDelegate { std::mutex m_sampleLock; std::condition_variable cv_sampleLock; diff --git a/modules/sensor/include/visp3/sensor/vpRealSense.h b/modules/sensor/include/visp3/sensor/vpRealSense.h index 58824b0bbd..a040b9d508 100644 --- a/modules/sensor/include/visp3/sensor/vpRealSense.h +++ b/modules/sensor/include/visp3/sensor/vpRealSense.h @@ -78,51 +78,55 @@ BEGIN_VISP_NAMESPACE -std=c++11 compiler option. Hereafter we give an example of a CMakeLists.txt file that allows to build sample-realsense.cpp that uses vpRealSense class. \code -project(sample) -cmake_minimum_required(VERSION 3.5) + project(sample) + cmake_minimum_required(VERSION 3.5) -find_package(VISP REQUIRED) -include_directories(${VISP_INCLUDE_DIRS}) + find_package(VISP REQUIRED) + include_directories(${VISP_INCLUDE_DIRS}) -include(CheckCXXCompilerFlag) -check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11) -if(COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -endif() + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11) + if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + endif() -add_executable(sample-realsense sample-realsense.cpp) -target_link_libraries(sample-realsense ${VISP_LIBRARIES}) + add_executable(sample-realsense sample-realsense.cpp) + target_link_libraries(sample-realsense ${VISP_LIBRARIES}) \endcode To acquire images from the RealSense color camera and convert them into grey level images, a good starting is to use the following code that corresponds to the content of sample-realsense.cpp: \code -#include -#include -#include + #include + #include + #include -int main() -{ - vpRealSense rs; - rs.open(); - - vpImage I(rs.getIntrinsics(rs::stream::color).height, rs.getIntrinsics(rs::stream::color).width); -#ifdef VISP_HAVE_X11 - vpDisplayX d(I); -#elif defined(VISP_HAVE_GDI) - vpDisplayGDI d(I); -#endif + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - while (1) { - rs.acquire(I); - vpDisplay::display(I); - vpDisplay::flush(I); - if (vpDisplay::getClick(I, false)) - break; + int main() + { + vpRealSense rs; + rs.open(); + + vpImage I(rs.getIntrinsics(rs::stream::color).height, rs.getIntrinsics(rs::stream::color).width); + #ifdef VISP_HAVE_X11 + vpDisplayX d(I); + #elif defined(VISP_HAVE_GDI) + vpDisplayGDI d(I); + #endif + + while (1) { + rs.acquire(I); + vpDisplay::display(I); + vpDisplay::flush(I); + if (vpDisplay::getClick(I, false)) + break; + } + return 0; } - return 0; -} \endcode If you want to acquire color images, in the previous sample replace: @@ -139,45 +143,49 @@ int main() visualize the point cloud: \code -#include - -#include -#include + #include -int main() -{ - vpRealSense rs; - rs.open(); - std::cout << rs << std::endl; + #include + #include - pcl::PointCloud::Ptr pointcloud(new pcl::PointCloud); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - rs.acquire(pointcloud); + int main() + { + vpRealSense rs; + rs.open(); + std::cout << rs << std::endl; - pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer")); - pcl::visualization::PointCloudColorHandlerRGBField rgb(pointcloud); - viewer->setBackgroundColor (0, 0, 0); - viewer->addCoordinateSystem (1.0); - viewer->initCameraParameters (); - viewer->setCameraPosition(0,0,-0.5, 0,-1,0); + pcl::PointCloud::Ptr pointcloud(new pcl::PointCloud); - while (1) { rs.acquire(pointcloud); - static bool update = false; - if (! update) { - viewer->addPointCloud (pointcloud, rgb, "sample cloud"); - viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud"); - update = true; + pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer")); + pcl::visualization::PointCloudColorHandlerRGBField rgb(pointcloud); + viewer->setBackgroundColor (0, 0, 0); + viewer->addCoordinateSystem (1.0); + viewer->initCameraParameters (); + viewer->setCameraPosition(0,0,-0.5, 0,-1,0); + + while (1) { + rs.acquire(pointcloud); + + static bool update = false; + if (! update) { + viewer->addPointCloud (pointcloud, rgb, "sample cloud"); + viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud"); + update = true; + } + else { + viewer->updatePointCloud (pointcloud, rgb, "sample cloud"); + } + + viewer->spinOnce (100); } - else { - viewer->updatePointCloud (pointcloud, rgb, "sample cloud"); - } - - viewer->spinOnce (100); + return 0; } - return 0; -} \endcode If you want to change the default stream parameters, you can use \p @@ -185,134 +193,154 @@ int main() to set the stream settings. The following code allows to capture the color stream in 1920x1080 also with the infrared stream: -\code -#include -#include -#include - -int main() { - vpRealSense rs; - rs.setEnableStream(rs::stream::color, true); - rs.setEnableStream(rs::stream::depth, false); - rs.setEnableStream(rs::stream::infrared, true); - rs.setEnableStream(rs::stream::infrared2, false); - rs.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(1920, 1080, rs::format::rgba8, 30)); - rs.setStreamSettings(rs::stream::infrared, vpRealSense::vpRsStreamParams(640, 480, rs::format::y8, 30)); - rs.open(); - - vpImage Ic(rs.getIntrinsics(rs::stream::color).height, rs.getIntrinsics(rs::stream::color).width); - vpImage Ii(rs.getIntrinsics(rs::stream::infrared).height, -rs.getIntrinsics(rs::stream::infrared).width); - -#ifdef VISP_HAVE_X11 - vpDisplayX dc(Ic, 0, 0, "Color"); - vpDisplayX di(Ii, 100, 100, "Infrared"); -#elif defined(VISP_HAVE_GDI) - vpDisplayGDI dc(Ic, 0, 0, "Color"); - vpDisplayGDI di(Ii, 100, 100, "Infrared"); -#endif + \code + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - while (1) { - rs.acquire((unsigned char *) Ic.bitmap, nullptr, nullptr, Ii.bitmap); - vpDisplay::display(Ic); - vpDisplay::display(Ii); - vpDisplay::flush(Ic); - vpDisplay::flush(Ii); - if (vpDisplay::getClick(Ic, false) || vpDisplay::getClick(Ii, false)) - break; + int main() + { + vpRealSense rs; + rs.setEnableStream(rs::stream::color, true); + rs.setEnableStream(rs::stream::depth, false); + rs.setEnableStream(rs::stream::infrared, true); + rs.setEnableStream(rs::stream::infrared2, false); + rs.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(1920, 1080, rs::format::rgba8, 30)); + rs.setStreamSettings(rs::stream::infrared, vpRealSense::vpRsStreamParams(640, 480, rs::format::y8, 30)); + rs.open(); + + vpImage Ic(rs.getIntrinsics(rs::stream::color).height, rs.getIntrinsics(rs::stream::color).width); + vpImage Ii(rs.getIntrinsics(rs::stream::infrared).height, + rs.getIntrinsics(rs::stream::infrared).width); + + #ifdef VISP_HAVE_X11 + vpDisplayX dc(Ic, 0, 0, "Color"); + vpDisplayX di(Ii, 100, 100, "Infrared"); + #elif defined(VISP_HAVE_GDI) + vpDisplayGDI dc(Ic, 0, 0, "Color"); + vpDisplayGDI di(Ii, 100, 100, "Infrared"); + #endif + + while (1) { + rs.acquire((unsigned char *) Ic.bitmap, nullptr, nullptr, Ii.bitmap); + vpDisplay::display(Ic); + vpDisplay::display(Ii); + vpDisplay::flush(Ic); + vpDisplay::flush(Ii); + if (vpDisplay::getClick(Ic, false) || vpDisplay::getClick(Ii, false)) + break; + } + return 0; } - return 0; -} \endcode This example shows how to get depth stream aligned on color stream: \code -#include -#include -#include -#include - -int main() { - vpRealSense rs; - rs.setEnableStream(rs::stream::color, true); - rs.setEnableStream(rs::stream::depth, true); - rs.setEnableStream(rs::stream::infrared, false); - rs.setEnableStream(rs::stream::infrared2, false); - rs.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(640, 480, rs::format::rgba8, 30)); - rs.setStreamSettings(rs::stream::depth, vpRealSense::vpRsStreamParams(640, 480, rs::format::z16, 30)); - rs.open(); - - vpImage Ic(rs.getIntrinsics(rs::stream::color).height, rs.getIntrinsics(rs::stream::color).width); - vpImage Id_raw(rs.getIntrinsics(rs::stream::depth).height, rs.getIntrinsics(rs::stream::depth).width); - vpImage Id(rs.getIntrinsics(rs::stream::depth).height, rs.getIntrinsics(rs::stream::depth).width); - -#ifdef VISP_HAVE_X11 - vpDisplayX dc(Ic, 0, 0, "Color"); - vpDisplayX dd(Id, 100, 100, "Depth aligned to color"); -#elif defined(VISP_HAVE_GDI) - vpDisplayGDI dc(Ic, 0, 0, "Color"); - vpDisplayGDI dd(Id, 100, 100, "Depth aligned to color"); -#endif + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - while (1) { - rs.acquire((unsigned char *) Ic.bitmap, (unsigned char *) Id_raw.bitmap, nullptr, nullptr, nullptr, - rs::stream::color, rs::stream::depth_aligned_to_color); - vpImageConvert::createDepthHistogram(Id_raw, Id); - vpDisplay::display(Ic); - vpDisplay::display(Id); - vpDisplay::flush(Ic); - vpDisplay::flush(Id); - if (vpDisplay::getClick(Ic, false) || vpDisplay::getClick(Id, false)) - break; + int main() + { + vpRealSense rs; + rs.setEnableStream(rs::stream::color, true); + rs.setEnableStream(rs::stream::depth, true); + rs.setEnableStream(rs::stream::infrared, false); + rs.setEnableStream(rs::stream::infrared2, false); + rs.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(640, 480, rs::format::rgba8, 30)); + rs.setStreamSettings(rs::stream::depth, vpRealSense::vpRsStreamParams(640, 480, rs::format::z16, 30)); + rs.open(); + + vpImage Ic(rs.getIntrinsics(rs::stream::color).height, rs.getIntrinsics(rs::stream::color).width); + vpImage Id_raw(rs.getIntrinsics(rs::stream::depth).height, rs.getIntrinsics(rs::stream::depth).width); + vpImage Id(rs.getIntrinsics(rs::stream::depth).height, rs.getIntrinsics(rs::stream::depth).width); + + #ifdef VISP_HAVE_X11 + vpDisplayX dc(Ic, 0, 0, "Color"); + vpDisplayX dd(Id, 100, 100, "Depth aligned to color"); + #elif defined(VISP_HAVE_GDI) + vpDisplayGDI dc(Ic, 0, 0, "Color"); + vpDisplayGDI dd(Id, 100, 100, "Depth aligned to color"); + #endif + + while (1) { + rs.acquire((unsigned char *) Ic.bitmap, (unsigned char *) Id_raw.bitmap, nullptr, nullptr, nullptr, + rs::stream::color, rs::stream::depth_aligned_to_color); + vpImageConvert::createDepthHistogram(Id_raw, Id); + vpDisplay::display(Ic); + vpDisplay::display(Id); + vpDisplay::flush(Ic); + vpDisplay::flush(Id); + if (vpDisplay::getClick(Ic, false) || vpDisplay::getClick(Id, false)) + break; + } + return 0; } - return 0; -} \endcode This is how you get intrinsics for non native stream (the native stream has to be enabled!): -\code -#include + \code + #include -int main() { - vpRealSense rs; - rs.setEnableStream(rs::stream::color, true); - rs.setEnableStream(rs::stream::depth, true); - rs.setEnableStream(rs::stream::infrared, false); - rs.setEnableStream(rs::stream::infrared2, false); - rs.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(640, 480, rs::format::rgba8, 30)); - rs.setStreamSettings(rs::stream::depth, vpRealSense::vpRsStreamParams(640, 480, rs::format::z16, 30)); - rs.open(); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - rs::device * dev = rs.getHandler(); - rs::intrinsics depth_aligned_intrinsic = dev->get_stream_intrinsics(rs::stream::depth_aligned_to_color); - std::cout << "Intrinsics [fx, fy, ppx, ppy]: " << depth_aligned_intrinsic.fx << " ; " << depth_aligned_intrinsic.fy - << " ; " << depth_aligned_intrinsic.ppx << " ; " << depth_aligned_intrinsic.ppy << std::endl; return 0; -} + int main() + { + vpRealSense rs; + rs.setEnableStream(rs::stream::color, true); + rs.setEnableStream(rs::stream::depth, true); + rs.setEnableStream(rs::stream::infrared, false); + rs.setEnableStream(rs::stream::infrared2, false); + rs.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(640, 480, rs::format::rgba8, 30)); + rs.setStreamSettings(rs::stream::depth, vpRealSense::vpRsStreamParams(640, 480, rs::format::z16, 30)); + rs.open(); + + rs::device * dev = rs.getHandler(); + rs::intrinsics depth_aligned_intrinsic = dev->get_stream_intrinsics(rs::stream::depth_aligned_to_color); + std::cout << "Intrinsics [fx, fy, ppx, ppy]: " << depth_aligned_intrinsic.fx << " ; " << depth_aligned_intrinsic.fy + << " ; " << depth_aligned_intrinsic.ppx << " ; " << depth_aligned_intrinsic.ppy << std::endl; return 0; + } \endcode Useful information can be retrieved using \p getHandler(): \code -#include -#include + #include + #include -int main() { - vpRealSense rs; - rs.open(); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - rs::device *device = rs.getHandler(); - std::cout << "Stream width: " << device->get_stream_width(rs::stream::color) << std::endl; - std::cout << "Stream height: " << device->get_stream_height(rs::stream::color) << std::endl; - std::cout << "Stream format: " << device->get_stream_format(rs::stream::color) << std::endl; - std::cout << "Stream framerate: " << device->get_stream_framerate(rs::stream::color) << std::endl; + int main() + { + vpRealSense rs; + rs.open(); + + rs::device *device = rs.getHandler(); + std::cout << "Stream width: " << device->get_stream_width(rs::stream::color) << std::endl; + std::cout << "Stream height: " << device->get_stream_height(rs::stream::color) << std::endl; + std::cout << "Stream format: " << device->get_stream_format(rs::stream::color) << std::endl; + std::cout << "Stream framerate: " << device->get_stream_framerate(rs::stream::color) << std::endl; - std::cout << "API version: " << rs_get_api_version(nullptr) << std::endl; - std::cout << "Firmware: " << rs_get_device_firmware_version((const rs_device *) device, nullptr) << std::endl; - std::cout << "RealSense sensor characteristics: \n" << rs << std::endl; + std::cout << "API version: " << rs_get_api_version(nullptr) << std::endl; + std::cout << "Firmware: " << rs_get_device_firmware_version((const rs_device *) device, nullptr) << std::endl; + std::cout << "RealSense sensor characteristics: \n" << rs << std::endl; - return 0; -} + return 0; + } \endcode Camera parameters can be set in the following manner: diff --git a/modules/sensor/include/visp3/sensor/vpRealSense2.h b/modules/sensor/include/visp3/sensor/vpRealSense2.h index eb1996230f..16c61e6972 100644 --- a/modules/sensor/include/visp3/sensor/vpRealSense2.h +++ b/modules/sensor/include/visp3/sensor/vpRealSense2.h @@ -52,238 +52,261 @@ BEGIN_VISP_NAMESPACE /*! - \class vpRealSense2 - - \ingroup group_sensor_rgbd - - This class provides a lightweight wrapper over the Intel librealsense2 - library https://github.com/IntelRealSense/librealsense. It allows to capture - data from the Intel RealSense cameras. - - \note Supported devices for Intel® RealSenseâ„¢ SDK 2.0: - - Intel® RealSenseâ„¢ Camera D400-Series - - Intel® RealSenseâ„¢ Developer Kit SR300 - - Intel® RealSenseâ„¢ Tracking Camera T265 (librealsense2 version > 2.31.0) - - The usage of vpRealSense2 class is enabled when librealsense2 3rd party is - successfully installed. - - Moreover, if Point Cloud Library (PCL) 3rd party is installed, we also - propose interfaces to retrieve point cloud as pcl::PointCloud - or pcl::PointCloud data structures. - - \warning Notice that the usage of this class requires compiler and library - support for the ISO C++ 2011 standard. This support is enabled by default - in ViSP when supported by the compiler. Hereafter we give an example of a - CMakeLists.txt file that allows to build sample-realsense.cpp that - uses vpRealSense2 class. - - \code - cmake_minimum_required(VERSION 3.5) - - project(sample) - - find_package(VISP REQUIRED) - include_directories(${VISP_INCLUDE_DIRS}) - - add_executable(sample-realsense sample-realsense.cpp) - target_link_libraries(sample-realsense ${VISP_LIBRARIES}) - \endcode - - To acquire images from the RealSense color camera and convert them into grey - level images, a good starting is to use the following code that corresponds to - the content of sample-realsense.cpp: - - \code - #include - #include - #include - - int main() - { - vpRealSense2 rs; - rs.open(); - - vpImage I(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); - #ifdef VISP_HAVE_X11 - vpDisplayX d(I); - #elif defined(VISP_HAVE_GDI) - vpDisplayGDI d(I); - #endif - - while (true) { - rs.acquire(I); - vpDisplay::display(I); - vpDisplay::flush(I); - if (vpDisplay::getClick(I, false)) - break; - } - return 0; - } - \endcode - - If you want to acquire color images, in the previous sample replace: - \code - vpImage I(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); - \endcode - by - \code - vpImage I(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); - \endcode - - If you are interested in the point cloud and if ViSP is build with PCL - support, you can start from the following example where we use PCL library to - visualize the point cloud - - \code - #include - #include - #include - - int main() - { - vpRealSense2 rs; - rs.open(); - - pcl::PointCloud::Ptr pointcloud(new pcl::PointCloud); - - rs.acquire(nullptr, nullptr, nullptr, pointcloud); - - pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer")); - pcl::visualization::PointCloudColorHandlerRGBField rgb(pointcloud); - viewer->setBackgroundColor(0, 0, 0); - viewer->initCameraParameters(); - viewer->setCameraPosition(0, 0, -0.5, 0, -1, 0); - - while (true) { - rs.acquire(nullptr, nullptr, nullptr, pointcloud); - - static bool update = false; - if (!update) { - viewer->addPointCloud (pointcloud, rgb, "sample cloud"); - viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud"); - update = true; - } else { - viewer->updatePointCloud (pointcloud, rgb, "sample cloud"); - } - - viewer->spinOnce(30); - } - return 0; - } - \endcode - - If you want to change the default stream parameters, refer to the - librealsense2 `rs2::config` documentation. The following code allows to - capture the color stream in 1920x1080 at 30 Hz: - - \code - #include - #include - #include - - int main() { - vpRealSense2 rs; - rs2::config config; - config.enable_stream(RS2_STREAM_COLOR, 1920, 1080, RS2_FORMAT_RGBA8, 30); - config.enable_stream(RS2_STREAM_DEPTH, 640, 480, RS2_FORMAT_Z16, 30); - config.enable_stream(RS2_STREAM_INFRARED, 640, 480, RS2_FORMAT_Y8, 30); - rs.open(config); - - vpImage Ic(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); - vpImage Ii(rs.getIntrinsics(RS2_STREAM_INFRARED).height, - rs.getIntrinsics(RS2_STREAM_INFRARED).width); - - #ifdef VISP_HAVE_X11 - vpDisplayX dc(Ic, 0, 0, "Color"); - vpDisplayX di(Ii, 100, 100, "Infrared"); - #elif defined(VISP_HAVE_GDI) - vpDisplayGDI dc(Ic, 0, 0, "Color"); - vpDisplayGDI di(Ii, 100, 100, "Infrared"); - #endif - - while (true) { - rs.acquire((unsigned char *) Ic.bitmap, nullptr, nullptr, Ii.bitmap); - vpDisplay::display(Ic); - vpDisplay::display(Ii); - vpDisplay::flush(Ic); - vpDisplay::flush(Ii); - if (vpDisplay::getClick(Ic, false) || vpDisplay::getClick(Ii, false)) - break; - } - return 0; - } - \endcode - - This other example shows how to get depth stream aligned on color stream: - \code - #include - #include - #include - #include - - int main() { - vpRealSense2 rs; - rs2::config config; - config.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_RGBA8, 30); - config.enable_stream(RS2_STREAM_DEPTH, 640, 480, RS2_FORMAT_Z16, 30); - config.enable_stream(RS2_STREAM_INFRARED, 640, 480, RS2_FORMAT_Y8, 30); - rs.open(config); - - vpImage Ic(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); - vpImage Id_raw(rs.getIntrinsics(RS2_STREAM_DEPTH).height, rs.getIntrinsics(RS2_STREAM_DEPTH).width); - vpImage Id(rs.getIntrinsics(RS2_STREAM_DEPTH).height, rs.getIntrinsics(RS2_STREAM_DEPTH).width); - - #ifdef VISP_HAVE_X11 - vpDisplayX dc(Ic, 0, 0, "Color"); - vpDisplayX dd(Id, 100, 100, "Depth aligned to color"); - #elif defined(VISP_HAVE_GDI) - vpDisplayGDI dc(Ic, 0, 0, "Color"); - vpDisplayGDI dd(Id, 100, 100, "Depth aligned to color"); - #endif - - rs2::align align_to(RS2_STREAM_COLOR); - while (true) { - rs.acquire((unsigned char *) Ic.bitmap, (unsigned char *) Id_raw.bitmap, nullptr, nullptr, &align_to); - vpImageConvert::createDepthHistogram(Id_raw, Id); - vpDisplay::display(Ic); - vpDisplay::display(Id); - vpDisplay::flush(Ic); - vpDisplay::flush(Id); - if (vpDisplay::getClick(Ic, false) || vpDisplay::getClick(Id, false)) - break; - } - return 0; - } - \endcode - - References to `rs2::pipeline_profile` and `rs2::pipeline` can be retrieved - with (`rs.open() must be called before`): - \code - rs2::pipeline_profile& profile = rs.getPipelineProfile(); - rs2::pipeline& pipeline = rs.getPipeline(); - \endcode - - Information about the sensor can be printed with: - \code - #include - - int main() { - vpRealSense2 rs; - rs.open(); - std::cout << "RealSense sensor characteristics: \n" << rs << std::endl; - - return 0; - } + \class vpRealSense2 + + \ingroup group_sensor_rgbd + + This class provides a lightweight wrapper over the Intel librealsense2 + library https://github.com/IntelRealSense/librealsense. It allows to capture + data from the Intel RealSense cameras. + + \note Supported devices for Intel® RealSenseâ„¢ SDK 2.0: + - Intel® RealSenseâ„¢ Camera D400-Series + - Intel® RealSenseâ„¢ Developer Kit SR300 + - Intel® RealSenseâ„¢ Tracking Camera T265 (librealsense2 version > 2.31.0) + + The usage of vpRealSense2 class is enabled when librealsense2 3rd party is + successfully installed. + + Moreover, if Point Cloud Library (PCL) 3rd party is installed, we also + propose interfaces to retrieve point cloud as pcl::PointCloud + or pcl::PointCloud data structures. + + \warning Notice that the usage of this class requires compiler and library + support for the ISO C++ 2011 standard. This support is enabled by default + in ViSP when supported by the compiler. Hereafter we give an example of a + CMakeLists.txt file that allows to build sample-realsense.cpp that + uses vpRealSense2 class. + + \code + cmake_minimum_required(VERSION 3.5) + + project(sample) + + find_package(VISP REQUIRED) + include_directories(${VISP_INCLUDE_DIRS}) + + add_executable(sample-realsense sample-realsense.cpp) + target_link_libraries(sample-realsense ${VISP_LIBRARIES}) + \endcode + + To acquire images from the RealSense color camera and convert them into grey + level images, a good starting is to use the following code that corresponds to + the content of sample-realsense.cpp: + + \code + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRealSense2 rs; + rs.open(); + + vpImage I(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); + #ifdef VISP_HAVE_X11 + vpDisplayX d(I); + #elif defined(VISP_HAVE_GDI) + vpDisplayGDI d(I); + #endif + + while (true) { + rs.acquire(I); + vpDisplay::display(I); + vpDisplay::flush(I); + if (vpDisplay::getClick(I, false)) + break; + } + return 0; + } + \endcode + + If you want to acquire color images, in the previous sample replace: + \code + vpImage I(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); + \endcode + by + \code + vpImage I(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); + \endcode + + If you are interested in the point cloud and if ViSP is build with PCL + support, you can start from the following example where we use PCL library to + visualize the point cloud + + \code + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRealSense2 rs; + rs.open(); + + pcl::PointCloud::Ptr pointcloud(new pcl::PointCloud); + + rs.acquire(nullptr, nullptr, nullptr, pointcloud); + + pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer")); + pcl::visualization::PointCloudColorHandlerRGBField rgb(pointcloud); + viewer->setBackgroundColor(0, 0, 0); + viewer->initCameraParameters(); + viewer->setCameraPosition(0, 0, -0.5, 0, -1, 0); + + while (true) { + rs.acquire(nullptr, nullptr, nullptr, pointcloud); + + static bool update = false; + if (!update) { + viewer->addPointCloud (pointcloud, rgb, "sample cloud"); + viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud"); + update = true; + } else { + viewer->updatePointCloud (pointcloud, rgb, "sample cloud"); + } + + viewer->spinOnce(30); + } + return 0; + } + \endcode + + If you want to change the default stream parameters, refer to the + librealsense2 `rs2::config` documentation. The following code allows to + capture the color stream in 1920x1080 at 30 Hz: + + \code + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRealSense2 rs; + rs2::config config; + config.enable_stream(RS2_STREAM_COLOR, 1920, 1080, RS2_FORMAT_RGBA8, 30); + config.enable_stream(RS2_STREAM_DEPTH, 640, 480, RS2_FORMAT_Z16, 30); + config.enable_stream(RS2_STREAM_INFRARED, 640, 480, RS2_FORMAT_Y8, 30); + rs.open(config); + + vpImage Ic(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); + vpImage Ii(rs.getIntrinsics(RS2_STREAM_INFRARED).height, + rs.getIntrinsics(RS2_STREAM_INFRARED).width); + + #ifdef VISP_HAVE_X11 + vpDisplayX dc(Ic, 0, 0, "Color"); + vpDisplayX di(Ii, 100, 100, "Infrared"); + #elif defined(VISP_HAVE_GDI) + vpDisplayGDI dc(Ic, 0, 0, "Color"); + vpDisplayGDI di(Ii, 100, 100, "Infrared"); + #endif + + while (true) { + rs.acquire((unsigned char *) Ic.bitmap, nullptr, nullptr, Ii.bitmap); + vpDisplay::display(Ic); + vpDisplay::display(Ii); + vpDisplay::flush(Ic); + vpDisplay::flush(Ii); + if (vpDisplay::getClick(Ic, false) || vpDisplay::getClick(Ii, false)) + break; + } + return 0; + } + \endcode + + This other example shows how to get depth stream aligned on color stream: + \code + #include + #include + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRealSense2 rs; + rs2::config config; + config.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_RGBA8, 30); + config.enable_stream(RS2_STREAM_DEPTH, 640, 480, RS2_FORMAT_Z16, 30); + config.enable_stream(RS2_STREAM_INFRARED, 640, 480, RS2_FORMAT_Y8, 30); + rs.open(config); + + vpImage Ic(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); + vpImage Id_raw(rs.getIntrinsics(RS2_STREAM_DEPTH).height, rs.getIntrinsics(RS2_STREAM_DEPTH).width); + vpImage Id(rs.getIntrinsics(RS2_STREAM_DEPTH).height, rs.getIntrinsics(RS2_STREAM_DEPTH).width); + + #ifdef VISP_HAVE_X11 + vpDisplayX dc(Ic, 0, 0, "Color"); + vpDisplayX dd(Id, 100, 100, "Depth aligned to color"); + #elif defined(VISP_HAVE_GDI) + vpDisplayGDI dc(Ic, 0, 0, "Color"); + vpDisplayGDI dd(Id, 100, 100, "Depth aligned to color"); + #endif + + rs2::align align_to(RS2_STREAM_COLOR); + while (true) { + rs.acquire((unsigned char *) Ic.bitmap, (unsigned char *) Id_raw.bitmap, nullptr, nullptr, &align_to); + vpImageConvert::createDepthHistogram(Id_raw, Id); + vpDisplay::display(Ic); + vpDisplay::display(Id); + vpDisplay::flush(Ic); + vpDisplay::flush(Id); + if (vpDisplay::getClick(Ic, false) || vpDisplay::getClick(Id, false)) + break; + } + return 0; + } + \endcode + + References to `rs2::pipeline_profile` and `rs2::pipeline` can be retrieved + with (`rs.open() must be called before`): + \code + rs2::pipeline_profile& profile = rs.getPipelineProfile(); + rs2::pipeline& pipeline = rs.getPipeline(); + \endcode + + Information about the sensor can be printed with: + \code + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRealSense2 rs; + rs.open(); + std::cout << "RealSense sensor characteristics: \n" << rs << std::endl; + + return 0; + } \endcode - It is also possible to use several RealSense sensors at the same time. In that case, you need to create a - vpRealSense2 object for each device and use vpRealSense2::enable_device(const std::string &serial_number) - to select the device explicitly by its serial number. An example is provided - in tutorial-grabber-multiple-realsense.cpp. + It is also possible to use several RealSense sensors at the same time. In that case, you need to create a + vpRealSense2 object for each device and use vpRealSense2::enable_device(const std::string &serial_number) + to select the device explicitly by its serial number. An example is provided + in tutorial-grabber-multiple-realsense.cpp. - \note Additional information can be found in the - [librealsense wiki](https://github.com/IntelRealSense/librealsense/wiki/). + \note Additional information can be found in the + [librealsense wiki](https://github.com/IntelRealSense/librealsense/wiki/). */ class VISP_EXPORT vpRealSense2 { diff --git a/modules/sensor/include/visp3/sensor/vpScanPoint.h b/modules/sensor/include/visp3/sensor/vpScanPoint.h index 954f17d56d..006e2f92af 100644 --- a/modules/sensor/include/visp3/sensor/vpScanPoint.h +++ b/modules/sensor/include/visp3/sensor/vpScanPoint.h @@ -214,24 +214,28 @@ class /* VISP_EXPORT */ vpScanPoint // Note that here VISP_EXPORT should not The following code \code -#include -#include + #include + #include -int main() -{ - vpScanPoint p; - double radialDistance = 3; // 3 meters - double horizontalAngle = 1.12; // 1.12 radian - double verticalAngle = 0; // 0 radian for a horizontal layer + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - p.setPolar(radialDistance, horizontalAngle, verticalAngle); + int main() + { + vpScanPoint p; + double radialDistance = 3; // 3 meters + double horizontalAngle = 1.12; // 1.12 radian + double verticalAngle = 0; // 0 radian for a horizontal layer - std::cout << p << std::endl; -} + p.setPolar(radialDistance, horizontalAngle, verticalAngle); + + std::cout << p << std::endl; + } \endcode will produce the prints \code -"3 1.12 0 1.307047339 2.700301327 0" + "3 1.12 0 1.307047339 2.700301327 0" \endcode */ diff --git a/modules/sensor/include/visp3/sensor/vpSickLDMRS.h b/modules/sensor/include/visp3/sensor/vpSickLDMRS.h index c028445054..ede69dbae3 100644 --- a/modules/sensor/include/visp3/sensor/vpSickLDMRS.h +++ b/modules/sensor/include/visp3/sensor/vpSickLDMRS.h @@ -73,6 +73,10 @@ BEGIN_VISP_NAMESPACE * \code * #include "visp3/sensor/vpSickLDMRS.h" * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || diff --git a/modules/sensor/include/visp3/sensor/vpV4l2Grabber.h b/modules/sensor/include/visp3/sensor/vpV4l2Grabber.h index dafb32e2b9..155411138a 100644 --- a/modules/sensor/include/visp3/sensor/vpV4l2Grabber.h +++ b/modules/sensor/include/visp3/sensor/vpV4l2Grabber.h @@ -104,6 +104,10 @@ BEGIN_VISP_NAMESPACE #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_V4L2) diff --git a/modules/sensor/src/force-torque/vpForceTorqueAtiSensor.cpp b/modules/sensor/src/force-torque/vpForceTorqueAtiSensor.cpp index d7df89e60c..800487fe66 100644 --- a/modules/sensor/src/force-torque/vpForceTorqueAtiSensor.cpp +++ b/modules/sensor/src/force-torque/vpForceTorqueAtiSensor.cpp @@ -48,7 +48,7 @@ BEGIN_VISP_NAMESPACE /*! * Default constructor. */ -vpForceTorqueAtiSensor::vpForceTorqueAtiSensor() + vpForceTorqueAtiSensor::vpForceTorqueAtiSensor() : m_calibfile(""), m_index(1), m_num_axes(6), m_num_channels(6), m_sample_bias() { } @@ -219,14 +219,18 @@ void vpForceTorqueAtiSensor::setCalibrationFile(const std::string &calibfile, un The following example shows how to use this method. \code -#include + #include -int main() -{ - vpForceTorqueAtiSensor ati; - ati.setCalibrationFile("FT12345.cal"); - std::cout << "ATI F/T sensor characteristics: \n" << ati << std::endl; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpForceTorqueAtiSensor ati; + ati.setCalibrationFile("FT12345.cal"); + std::cout << "ATI F/T sensor characteristics: \n" << ati << std::endl; + } \endcode */ std::ostream &operator<<(std::ostream &os, const vpForceTorqueAtiSensor &ati) diff --git a/modules/sensor/src/framegrabber/1394/vp1394CMUGrabber.cpp b/modules/sensor/src/framegrabber/1394/vp1394CMUGrabber.cpp index 25e3c83554..00531e2606 100644 --- a/modules/sensor/src/framegrabber/1394/vp1394CMUGrabber.cpp +++ b/modules/sensor/src/framegrabber/1394/vp1394CMUGrabber.cpp @@ -717,14 +717,18 @@ int vp1394CMUGrabber::getFramerate() \param I : The captured image. \code -#include + #include -int main() -{ - vpImage I; - vp1394CMUGrabber g; - g >> I; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I; + vp1394CMUGrabber g; + g >> I; + } \endcode */ vp1394CMUGrabber &vp1394CMUGrabber::operator>>(vpImage &I) @@ -739,14 +743,18 @@ vp1394CMUGrabber &vp1394CMUGrabber::operator>>(vpImage &I) \param I : The captured image. \code -#include + #include -int main() -{ - vpImage I; - vp1394CMUGrabber g; - g >> I; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I; + vp1394CMUGrabber g; + g >> I; + } \endcode */ vp1394CMUGrabber &vp1394CMUGrabber::operator>>(vpImage &I) diff --git a/modules/sensor/src/framegrabber/1394/vp1394TwoGrabber.cpp b/modules/sensor/src/framegrabber/1394/vp1394TwoGrabber.cpp index d80c64a1cc..795019d23d 100644 --- a/modules/sensor/src/framegrabber/1394/vp1394TwoGrabber.cpp +++ b/modules/sensor/src/framegrabber/1394/vp1394TwoGrabber.cpp @@ -100,6 +100,10 @@ const char *vp1394TwoGrabber::strColorCoding[DC1394_COLOR_CODING_NUM] = { #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_DC1394) @@ -176,101 +180,113 @@ vp1394TwoGrabber::~vp1394TwoGrabber() Here an example of single capture from the last camera found on the bus: \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - unsigned int ncameras; // Number of cameras on the bus - vpImage I; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + unsigned int ncameras; // Number of cameras on the bus + vpImage I; - vp1394TwoGrabber g; - ncameras = g.getNumCameras(); + vp1394TwoGrabber g; + ncameras = g.getNumCameras(); - int last = 0; - if (ncameras > 1) - last = ncameras-1; + int last = 0; + if (ncameras > 1) + last = ncameras-1; - g.setCamera(last); // To dial with the last camera on the bus - while(1) - g.acquire(I);// I contains the frame captured by the last camera on the bus -#endif -} + g.setCamera(last); // To dial with the last camera on the bus + while(1) + g.acquire(I);// I contains the frame captured by the last camera on the bus + #endif + } \endcode If more than one camera is connected, it is also possible to select a -specific camera by its GUID: -\code -#include -#include -#include - -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; // Create a gray level image container - bool reset = false; // Disable bus reset during construction - vp1394TwoGrabber g(reset); // Create a grabber based on libdc1394-2.x third party lib + specific camera by its GUID: + \code + #include + #include + #include - unsigned int ncameras; // Number of cameras on the bus - ncameras = g.getNumCameras(); - std::cout << ncameras << " cameras found:" << std::endl; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - for(int i=0; i< ncameras; i++) + int main() { - g.setCamera(i); - uint64_t guid = g.getGuid(); - printf("camera %d with guid 0x%lx\n", i, guid); - } + #if defined(VISP_HAVE_DC1394) + vpImage I; // Create a gray level image container + bool reset = false; // Disable bus reset during construction + vp1394TwoGrabber g(reset); // Create a grabber based on libdc1394-2.x third party lib + + unsigned int ncameras; // Number of cameras on the bus + ncameras = g.getNumCameras(); + std::cout << ncameras << " cameras found:" << std::endl; + + for(int i=0; i< ncameras; i++) + { + g.setCamera(i); + uint64_t guid = g.getGuid(); + printf("camera %d with guid 0x%lx\n", i, guid); + } - // produce: - // 2 cameras found: - // camera 0 with guid 0xb09d01009b329c - // camera 1 with guid 0xb09d01007e0ee7 + // produce: + // 2 cameras found: + // camera 0 with guid 0xb09d01009b329c + // camera 1 with guid 0xb09d01007e0ee7 - g.setCamera( 0xb09d01009b329c ); + g.setCamera( 0xb09d01009b329c ); - printf("Use camera with GUID: 0x%lx\n", g.getGuid()); - g.acquire(I); // Acquire an image from the camera with GUID 0xb09d01009b329c + printf("Use camera with GUID: 0x%lx\n", g.getGuid()); + g.acquire(I); // Acquire an image from the camera with GUID 0xb09d01009b329c - vpImageIo::write(I, "image.pgm"); // Write image on the disk -#endif -} + vpImageIo::write(I, "image.pgm"); // Write image on the disk + #endif + } \endcode Here an example of multi camera capture: \code -#include -#include - -int main() -{ -#if defined(VISP_HAVE_DC1394) - unsigned int ncameras; // Number of cameras on the bus - vp1394TwoGrabber g; - ncameras = g.getNumCameras(); - vpImage *I = new vpImage [ncameras]; + #include + #include - // If the first camera supports vpVIDEO_MODE_640x480_YUV422 video mode - g.setCamera(0); - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_YUV422); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - if (ncameras >= 2) { - // If the second camera support 30 fps acquisition - g.setCamera(1); - g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_30); - } + int main() + { + #if defined(VISP_HAVE_DC1394) + unsigned int ncameras; // Number of cameras on the bus + vp1394TwoGrabber g; + ncameras = g.getNumCameras(); + vpImage *I = new vpImage [ncameras]; + + // If the first camera supports vpVIDEO_MODE_640x480_YUV422 video mode + g.setCamera(0); + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_YUV422); + + if (ncameras >= 2) { + // If the second camera support 30 fps acquisition + g.setCamera(1); + g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_30); + } - while(1) { - for (unsigned int camera=0; camera < ncameras; camera ++) { - g.setCamera(camera); - g.acquire(I[camera]); + while(1) { + for (unsigned int camera=0; camera < ncameras; camera ++) { + g.setCamera(camera); + g.acquire(I[camera]); + } } + delete [] I; + #endif } - delete [] I; -#endif -} \endcode \sa setFormat(), setVideoMode(), setFramerate(), getNumCameras() @@ -422,22 +438,26 @@ to the new video capture mode. Format7 with a transmission speed set to 800Mbps in 1394b mode. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g(false); // Don't reset the bus - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); - g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); - g.setAutoShutter(1600*20-1, 1600*20); // Set shutter min and max values - g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b - while(1) - g.acquire(I); -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g(false); // Don't reset the bus + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); + g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); + g.setAutoShutter(1600*20-1, 1600*20); // Set shutter min and max values + g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b + while(1) + g.acquire(I); + #endif + } \endcode \sa getVideoMode(), getVideoModeSupported(), setCamera() @@ -919,22 +939,26 @@ bool vp1394TwoGrabber::isFramerateSupported(vp1394TwoVideoModeType mode, vp1394T Format7 with a transmission speed set to 800Mbps in 1394b mode. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g(false); // Don't reset the bus - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); - g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); - g.setAutoShutter(1600*20-1, 1600*20); // Set shutter min and max values - g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b - while(1) - g.acquire(I); -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g(false); // Don't reset the bus + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); + g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); + g.setAutoShutter(1600*20-1, 1600*20); // Set shutter min and max values + g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b + while(1) + g.acquire(I); + #endif + } \endcode \sa getColorCoding(), getColorCodingSupported() , setCamera() @@ -1597,22 +1621,26 @@ the shutter as manual. Format7 with a transmission speed set to 800Mbps in 1394b mode. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g(false); // Don't reset the bus - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); - g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); - g.setAutoShutter(); // Enable auto shutter - g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b - while(1) - g.acquire(I); -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g(false); // Don't reset the bus + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); + g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); + g.setAutoShutter(); // Enable auto shutter + g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b + while(1) + g.acquire(I); + #endif + } \endcode \exception vpFrameGrabberException::settingError : If we can't set @@ -1664,22 +1692,26 @@ void vp1394TwoGrabber::setAutoShutter(bool enable) Format7 with a transmission speed set to 800Mbps in 1394b mode. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g(false); // Don't reset the bus - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); - g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); - g.setAutoShutter(1600*20-1, 1600*20); // Set shutter min and max values - g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b - while(1) - g.acquire(I); -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g(false); // Don't reset the bus + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); + g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); + g.setAutoShutter(1600*20-1, 1600*20); // Set shutter min and max values + g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b + while(1) + g.acquire(I); + #endif + } \endcode \exception vpFrameGrabberException::settingError : If we can't set @@ -1742,22 +1774,26 @@ void vp1394TwoGrabber::getAutoShutter(unsigned int &minvalue, unsigned int &maxv Format7 with a transmission speed set to 800Mbps in 1394b mode. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g(false); // Don't reset the bus - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); - g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); - g.setAutoGain(true); // Enable auto gain - g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b - while(1) - g.acquire(I); -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g(false); // Don't reset the bus + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); + g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); + g.setAutoGain(true); // Enable auto gain + g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b + while(1) + g.acquire(I); + #endif + } \endcode \exception vpFrameGrabberException::settingError : If we can't set @@ -1809,22 +1845,26 @@ void vp1394TwoGrabber::setAutoGain(bool enable) Format7 with a transmission speed set to 800Mbps in 1394b mode. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g(false); // Don't reset the bus - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); - g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); - g.setAutoGain(1600*20-1, 1600*20); // Set gain min and max values - g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b - while(1) - g.acquire(I); -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g(false); // Don't reset the bus + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); + g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); + g.setAutoGain(1600*20-1, 1600*20); // Set gain min and max values + g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b + while(1) + g.acquire(I); + #endif + } \endcode \exception vpFrameGrabberException::settingError : If we can't set @@ -1990,22 +2030,26 @@ void vp1394TwoGrabber::setTransmission(dc1394switch_t _switch) Below you will find an example that shows how to grab images in Format7 with a transmission speed set to 800Mbps in 1394b mode. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g(false); // Don't reset the bus - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); - g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); - g.setAutoShutter(1600*20-1, 1600*20); // Set shutter min and max values - g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b - while(1) - g.acquire(I); -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g(false); // Don't reset the bus + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_FORMAT7_0 ); + g.setColorCoding(vp1394TwoGrabber::vpCOLOR_CODING_MONO8); + g.setAutoShutter(1600*20-1, 1600*20); // Set shutter min and max values + g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800); // 1394b + while(1) + g.acquire(I); + #endif + } \endcode */ void vp1394TwoGrabber::setIsoTransmissionSpeed(vp1394TwoIsoSpeedType isospeed) @@ -2106,24 +2150,28 @@ void vp1394TwoGrabber::open(vpImage &I) the ring buffer to be sure that the next image is the last one. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vp1394TwoGrabber g; - dc1394video_frame_t *frame; - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8); - g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_15); - while(1) { - frame = g.dequeue(); - // Current image is now in frame structure - // Do your stuff - g.enqueue(frame); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vp1394TwoGrabber g; + dc1394video_frame_t *frame; + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8); + g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_15); + while(1) { + frame = g.dequeue(); + // Current image is now in frame structure + // Do your stuff + g.enqueue(frame); + } + #endif } -#endif -} \endcode \sa enqueue() @@ -2163,25 +2211,29 @@ dc1394video_frame_t *vp1394TwoGrabber::dequeue() the ring buffer to be sure that the next image is the last one. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g; - dc1394video_frame_t *frame; - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8); - g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_15); - while(1) { - frame = g.dequeue(I); - // Current image is now in frame structure and in I - // Do your stuff - g.enqueue(frame); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g; + dc1394video_frame_t *frame; + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8); + g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_15); + while(1) { + frame = g.dequeue(I); + // Current image is now in frame structure and in I + // Do your stuff + g.enqueue(frame); + } + #endif } -#endif -} \endcode \sa enqueue() @@ -2220,27 +2272,31 @@ dc1394video_frame_t *vp1394TwoGrabber::dequeue(vpImage &I) the ring buffer to be sure that the next image is the last one. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g; - dc1394video_frame_t *frame; - uint64_t timestamp_us; // timestamp in us - uint32_t id; - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8); - g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_15); - while(1) { - frame = g.dequeue(I, timestamp_us, id); // get the last image - // Current image is now in frame structure and in I - // Do your stuff - g.enqueue(frame); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g; + dc1394video_frame_t *frame; + uint64_t timestamp_us; // timestamp in us + uint32_t id; + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8); + g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_15); + while(1) { + frame = g.dequeue(I, timestamp_us, id); // get the last image + // Current image is now in frame structure and in I + // Do your stuff + g.enqueue(frame); + } + #endif } -#endif -} \endcode \sa enqueue() @@ -2304,7 +2360,7 @@ dc1394video_frame_t *vp1394TwoGrabber::dequeue(vpImage &I, uint64 /*! - Get an image from the active camera frame buffer. This buffer neads to be + Get an image from the active camera frame buffer. This buffer needs to be released by enqueue(). \param I : Image data structure (32 bits RGBa image). @@ -2318,25 +2374,29 @@ dc1394video_frame_t *vp1394TwoGrabber::dequeue(vpImage &I, uint64 dequeue() ensure to get the last image, while the enqueue() frees the ring buffer to be sure that the next image is the last one. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g; - dc1394video_frame_t *frame; - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8); - g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_15); - while(1) { - frame = g.dequeue(I); - // Current image is now in frame structure and in I - // Do your stuff - g.enqueue(frame); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g; + dc1394video_frame_t *frame; + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8); + g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_15); + while(1) { + frame = g.dequeue(I); + // Current image is now in frame structure and in I + // Do your stuff + g.enqueue(frame); + } + #endif } -#endif -} \endcode \sa enqueue() @@ -2375,27 +2435,31 @@ dc1394video_frame_t *vp1394TwoGrabber::dequeue(vpImage &I) the ring buffer to be sure that the next image is the last one. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - vpImage I; - vp1394TwoGrabber g; - dc1394video_frame_t *frame; - uint64_t timestamp_us; // timestamp in us - uint32_t id; - g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8); - g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_15); - while(1) { - frame = g.dequeue(I, timestamp_us, id); // get the last image - // Current image is now in frame structure and in I - // Do your stuff - g.enqueue(frame); + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + vpImage I; + vp1394TwoGrabber g; + dc1394video_frame_t *frame; + uint64_t timestamp_us; // timestamp in us + uint32_t id; + g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8); + g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_15); + while(1) { + frame = g.dequeue(I, timestamp_us, id); // get the last image + // Current image is now in frame structure and in I + // Do your stuff + g.enqueue(frame); + } + #endif } -#endif -} \endcode \sa enqueue() @@ -2953,29 +3017,33 @@ vp1394TwoGrabber::vp1394TwoColorCodingType vp1394TwoGrabber::string2colorCoding( /*! Resets the IEEE1394 bus which camera is attached to. Calling this function -is "rude" to other devices because it causes them to re-enumerate on the bus -and may cause a temporary disruption in their current activities. Thus, use -it sparingly. Its primary use is if a program shuts down uncleanly and needs -to free leftover ISO channels or bandwidth. A bus reset will free those -things as a side effect. + is "rude" to other devices because it causes them to re-enumerate on the bus + and may cause a temporary disruption in their current activities. Thus, use + it sparingly. Its primary use is if a program shuts down uncleanly and needs + to free leftover ISO channels or bandwidth. A bus reset will free those + things as a side effect. The example below shows how to reset the bus attached to the last camera found. \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_DC1394) - unsigned int ncameras; // Number of cameras on the bus - vp1394TwoGrabber g; - ncameras = g.getNumCameras(); - g.setCamera(ncameras-1); // To dial with the last camera on the bus - g.resetBus(); // Reset the bus attached to "ncameras-1" -#endif -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_DC1394) + unsigned int ncameras; // Number of cameras on the bus + vp1394TwoGrabber g; + ncameras = g.getNumCameras(); + g.setCamera(ncameras-1); // To dial with the last camera on the bus + g.resetBus(); // Reset the bus attached to "ncameras-1" + #endif + } \endcode \exception vpFrameGrabberException::initializationError : If no @@ -3360,19 +3428,23 @@ inline void vp1394TwoGrabber::updateDataStructToCam() /*! - Operator that allows to capture a grey level image. - \param I : The captured image. + Operator that allows to capture a grey level image. + \param I : The captured image. - \code -#include + \code + #include -int main() -{ - vpImage I; - vp1394TwoGrabber g; - g >> I; -} - \endcode + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I; + vp1394TwoGrabber g; + g >> I; + } + \endcode */ vp1394TwoGrabber &vp1394TwoGrabber::operator>>(vpImage &I) { @@ -3381,20 +3453,23 @@ vp1394TwoGrabber &vp1394TwoGrabber::operator>>(vpImage &I) } /*! + Operator that allows to capture a grey level image. + \param I : The captured image. - Operator that allows to capture a grey level image. - \param I : The captured image. + \code + #include - \code -#include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif -int main() -{ - vpImage I; - vp1394TwoGrabber g; - g >> I; -} - \endcode + int main() + { + vpImage I; + vp1394TwoGrabber g; + g >> I; + } + \endcode */ vp1394TwoGrabber &vp1394TwoGrabber::operator>>(vpImage &I) { diff --git a/modules/sensor/src/framegrabber/flycapture/vpFlyCaptureGrabber.cpp b/modules/sensor/src/framegrabber/flycapture/vpFlyCaptureGrabber.cpp index 45bd42d247..00108e5470 100644 --- a/modules/sensor/src/framegrabber/flycapture/vpFlyCaptureGrabber.cpp +++ b/modules/sensor/src/framegrabber/flycapture/vpFlyCaptureGrabber.cpp @@ -52,7 +52,7 @@ BEGIN_VISP_NAMESPACE Default constructor that consider the first camera found on the bus as active. */ -vpFlyCaptureGrabber::vpFlyCaptureGrabber() + vpFlyCaptureGrabber::vpFlyCaptureGrabber() : m_camera(), m_guid(), m_index(0), m_numCameras(0), m_rawImage(), m_connected(false), m_capture(false) { m_numCameras = this->getNumCameras(); @@ -103,80 +103,87 @@ std::ostream &vpFlyCaptureGrabber::getCameraInfo(std::ostream &os) /*! Return the handler to the active camera or nullptr if the camera is not -connected. This function was designed to provide a direct access to the -FlyCapture SDK to get access to advanced functionalities that are not -implemented in this class. + connected. This function was designed to provide a direct access to the + FlyCapture SDK to get access to advanced functionalities that are not + implemented in this class. We provide here after and example that shows how to use this function to -access to the camera and check if a given video mode and framerate are -supported by the camera. + access to the camera and check if a given video mode and framerate are + supported by the camera. -\code -#include -#include - -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - int nframes = 100; - vpImage I; - - vpFlyCaptureGrabber g; - g.connect(); - FlyCapture2::Camera *handler = g.getCameraHandler(); - bool supported = false; - handler->GetVideoModeAndFrameRateInfo(FlyCapture2::VIDEOMODE_1280x960Y8, FlyCapture2::FRAMERATE_60, &supported); - if (supported) - g.setVideoModeAndFrameRate(FlyCapture2::VIDEOMODE_1280x960Y8, FlyCapture2::FRAMERATE_60); g.startCapture(); - - for(int i=0; i< nframes; i++) { - g.acquire(I); + \code + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + int nframes = 100; + vpImage I; + + vpFlyCaptureGrabber g; + g.connect(); + FlyCapture2::Camera *handler = g.getCameraHandler(); + bool supported = false; + handler->GetVideoModeAndFrameRateInfo(FlyCapture2::VIDEOMODE_1280x960Y8, FlyCapture2::FRAMERATE_60, &supported); + if (supported) + g.setVideoModeAndFrameRate(FlyCapture2::VIDEOMODE_1280x960Y8, FlyCapture2::FRAMERATE_60); g.startCapture(); + + for(int i=0; i< nframes; i++) { + g.acquire(I); + } + #endif } -#endif -} -\endcode - + \endcode The following code shows how to use this function to check if a given -format7 (here MODE_0, PIXEL_FORMAT_MONO8) is supported by the camera: -\code -#include - -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - vpFlyCaptureGrabber g; - g.connect(); - FlyCapture2::Camera *handler = g.getCameraHandler(); - - // Query for available Format 7 modes - const FlyCapture2::Mode k_fmt7Mode = FlyCapture2::MODE_0; - const FlyCapture2::PixelFormat k_fmt7PixFmt = FlyCapture2::PIXEL_FORMAT_MONO8; - - FlyCapture2::Format7Info fmt7Info; - bool supported; - fmt7Info.mode = k_fmt7Mode; - FlyCapture2::Error error = handler->GetFormat7Info( &fmt7Info, &supported ); - if (error != FlyCapture2::PGRERROR_OK) { - error.PrintErrorTrace(); - return -1; - } - if (supported) { - std::cout << "Max image pixels: (" << fmt7Info.maxWidth << ", " << fmt7Info.maxHeight << ")" << std::endl; - std::cout << "Image Unit size: (" << fmt7Info.imageHStepSize << ", " << fmt7Info.imageVStepSize << ")" - << std::endl; - std::cout << "Offset Unit size: (" << fmt7Info.offsetHStepSize << ", " << fmt7Info.offsetVStepSize << ")" - << std::endl; - std::cout << "Pixel format bitfield: 0x" << fmt7Info.pixelFormatBitField << std::endl; - - if ( (k_fmt7PixFmt & fmt7Info.pixelFormatBitField) == 0 ) { - // Pixel format not supported! - std::cout << "Pixel format is not supported" << std::endl; + format7 (here MODE_0, PIXEL_FORMAT_MONO8) is supported by the camera: + \code + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + vpFlyCaptureGrabber g; + g.connect(); + FlyCapture2::Camera *handler = g.getCameraHandler(); + + // Query for available Format 7 modes + const FlyCapture2::Mode k_fmt7Mode = FlyCapture2::MODE_0; + const FlyCapture2::PixelFormat k_fmt7PixFmt = FlyCapture2::PIXEL_FORMAT_MONO8; + + FlyCapture2::Format7Info fmt7Info; + bool supported; + fmt7Info.mode = k_fmt7Mode; + FlyCapture2::Error error = handler->GetFormat7Info( &fmt7Info, &supported ); + if (error != FlyCapture2::PGRERROR_OK) { + error.PrintErrorTrace(); return -1; } + if (supported) { + std::cout << "Max image pixels: (" << fmt7Info.maxWidth << ", " << fmt7Info.maxHeight << ")" << std::endl; + std::cout << "Image Unit size: (" << fmt7Info.imageHStepSize << ", " << fmt7Info.imageVStepSize << ")" + << std::endl; + std::cout << "Offset Unit size: (" << fmt7Info.offsetHStepSize << ", " << fmt7Info.offsetVStepSize << ")" + << std::endl; + std::cout << "Pixel format bitfield: 0x" << fmt7Info.pixelFormatBitField << std::endl; + + if ( (k_fmt7PixFmt & fmt7Info.pixelFormatBitField) == 0 ) { + // Pixel format not supported! + std::cout << "Pixel format is not supported" << std::endl; + return -1; + } + } + #endif } -#endif -} \endcode */ @@ -317,29 +324,33 @@ float vpFlyCaptureGrabber::getExposure() \param index : Camera index. The following code shows how to retrieve the serial id of all the cameras -that are connected on the bus. -\code -#include - -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - vpFlyCaptureGrabber g; - unsigned int num_cameras = vpFlyCaptureGrabber::getNumCameras(); - for (unsigned int i=0; i + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + vpFlyCaptureGrabber g; + unsigned int num_cameras = vpFlyCaptureGrabber::getNumCameras(); + for (unsigned int i=0; i + The following example shows how to capture images from a camera that has + serial id 15290004. + \code + #include -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - int nframes = 100; - vpImage I; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpFlyCaptureGrabber g; - g.setCameraSerial(15290004); // Set camera with serial id - g.open(I); - g.getCameraInfo(std::cout); + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + int nframes = 100; + vpImage I; + + vpFlyCaptureGrabber g; + g.setCameraSerial(15290004); // Set camera with serial id + g.open(I); + g.getCameraInfo(std::cout); - for(int i=0; i< nframes; i++) { - g.acquire(I); + for(int i=0; i< nframes; i++) { + g.acquire(I); + } + #endif } -#endif -} \endcode \sa getCameraSerial() @@ -482,27 +497,31 @@ void vpFlyCaptureGrabber::setProperty(const FlyCapture2::PropertyType &prop_type The following example shows how to use this function. \code -#include -#include - -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - vpImage I; - - vpFlyCaptureGrabber g; - g.setCameraIndex(0); - - float framerate = g.getFrameRate(); - std::cout << "Cur frame rate: " << std::fixed << std::setprecision(3) << framerate << " fps" << std::endl; - framerate = g.setFrameRate(30); // Set framerate to 30 fps - std::cout << "New frame rate: " << std::fixed << std::setprecision(3) << framerate << " fps" << std::endl; - - g.open(I); - while (1) - g.acquire(I); -#endif -} + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + vpImage I; + + vpFlyCaptureGrabber g; + g.setCameraIndex(0); + + float framerate = g.getFrameRate(); + std::cout << "Cur frame rate: " << std::fixed << std::setprecision(3) << framerate << " fps" << std::endl; + framerate = g.setFrameRate(30); // Set framerate to 30 fps + std::cout << "New frame rate: " << std::fixed << std::setprecision(3) << framerate << " fps" << std::endl; + + g.open(I); + while (1) + g.acquire(I); + #endif + } \endcode \sa getFramerate() @@ -518,34 +537,37 @@ float vpFlyCaptureGrabber::setFrameRate(float frame_rate) /*! Set camera shutter mode and parameter. - \param auto_shutter : If true set auto shutter, if false set manual shutter -applying \e shutter_ms parameter. \param shutter_ms : This is the speed at -which the camera shutter opens and closes in manual mode. \return The measured -shutter after applying the new setting. + \param auto_shutter : If true set auto shutter, if false set manual shutter applying \e shutter_ms parameter. + \param shutter_ms : This is the speed at which the camera shutter opens and closes in manual mode. + \return The measured shutter after applying the new setting. The following example shows how to use this function: \code -#include - -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - vpImage I; - - vpFlyCaptureGrabber g; - g.setCameraIndex(0); - - float shutter_ms = g.getShutter(); - std::cout << "Shutter : " << shutter_ms << " ms" << std::endl; - shutter_ms = g.setShutter(false, 10); // Turn manual shutter on to 10ms - std::cout << "Shutter manual: " << shutter_ms << " ms" << std::endl; - shutter_ms = g.setShutter(true); // Turn auto shutter on - std::cout << "Shutter auto : " << shutter_ms << " ms" << std::endl; - - g.open(I); - ... -#endif -} + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + vpImage I; + + vpFlyCaptureGrabber g; + g.setCameraIndex(0); + + float shutter_ms = g.getShutter(); + std::cout << "Shutter : " << shutter_ms << " ms" << std::endl; + shutter_ms = g.setShutter(false, 10); // Turn manual shutter on to 10ms + std::cout << "Shutter manual: " << shutter_ms << " ms" << std::endl; + shutter_ms = g.setShutter(true); // Turn auto shutter on + std::cout << "Shutter auto : " << shutter_ms << " ms" << std::endl; + + g.open(I); + ... + #endif + } \endcode \sa getShutter() @@ -561,34 +583,38 @@ float vpFlyCaptureGrabber::setShutter(bool auto_shutter, float shutter_ms) /*! Set camera gain mode and value. - \param gain_auto : If true set auto gain, if false set manual gain applying -\e gain_value parameter. \param gain_value : The amount of amplification that -is applied to a pixel in manual mode. An increase in gain can result in an -increase in noise. \return The measured gain after applying the new setting. + \param gain_auto : If true set auto gain, if false set manual gain applying \e gain_value parameter. + \param gain_value : The amount of amplification that is applied to a pixel in manual mode. An increase in + gain can result in an increase in noise. + \return The measured gain after applying the new setting. The following example shows how to use this function: \code -#include - -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - vpImage I; - - vpFlyCaptureGrabber g; - g.setCameraIndex(0); - - float gain_db = g.getGain(); - std::cout << "Gain: " << gain_db << " db" << std::endl; - gain_db = g.setGain(false, 5); // Turn manual gain on to 5db - std::cout << "Gain manual: " << gain_db << " db" << std::endl; - gain_db = g.setGain(true); // Turn auto shutter on - std::cout << "Gain auto : " << gain_db << " db" << std::endl; - - g.open(I); - ... -#endif -} + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + vpImage I; + + vpFlyCaptureGrabber g; + g.setCameraIndex(0); + + float gain_db = g.getGain(); + std::cout << "Gain: " << gain_db << " db" << std::endl; + gain_db = g.setGain(false, 5); // Turn manual gain on to 5db + std::cout << "Gain manual: " << gain_db << " db" << std::endl; + gain_db = g.setGain(true); // Turn auto shutter on + std::cout << "Gain auto : " << gain_db << " db" << std::endl; + + g.open(I); + ... + #endif + } \endcode \sa getGain() @@ -606,34 +632,38 @@ float vpFlyCaptureGrabber::setGain(bool gain_auto, float gain_value) /*! Set camera brightness mode and parameter. \param brightness_auto : If true set auto brightness, if false set manual -brightness applying \e brightness_value parameter. \param brightness_value : -This is the level of black in an image. A high brightness will result in a low -amount of black in the image. \return The measured brightness after applying -the new setting. + brightness applying \e brightness_value parameter. + \param brightness_value : This is the level of black in an image. A high brightness will result in a low + amount of black in the image. + \return The measured brightness after applying the new setting. The following example shows how to use this function: \code -#include - -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - vpImage I; - - vpFlyCaptureGrabber g; - g.setCameraIndex(0); - - float brightness = g.getBrightness(); - std::cout << "Brightness : " << brightness << " %" << std::endl; - brightness = g.setBrightness(false, 2); // Turn manual brightness on to 2% - std::cout << "Brightness manual: " << brightness << " %" << std::endl; - brightness = g.setBrightness(true); // Turn auto brightness on - std::cout << "Brightness auto : " << brightness << " %" << std::endl; - - g.open(I); - ... -#endif -} + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + vpImage I; + + vpFlyCaptureGrabber g; + g.setCameraIndex(0); + + float brightness = g.getBrightness(); + std::cout << "Brightness : " << brightness << " %" << std::endl; + brightness = g.setBrightness(false, 2); // Turn manual brightness on to 2% + std::cout << "Brightness manual: " << brightness << " %" << std::endl; + brightness = g.setBrightness(true); // Turn auto brightness on + std::cout << "Brightness auto : " << brightness << " %" << std::endl; + + g.open(I); + ... + #endif + } \endcode \sa getBrightness() @@ -652,41 +682,46 @@ float vpFlyCaptureGrabber::setBrightness(bool brightness_auto, float brightness_ \param exposure_on : If true turn exposure on, otherwise turn off. \param exposure_auto : If true set auto exposure, if false set manual -exposure applying \e exposure_value parameter. \param exposure_value : This is -the average intensity of the image. It will use other available (non-manually -adjustable) controls to adjust the image. Specifically, when shutter and gain -are both in auto mode, manually adjusting the exposure is actually adjusting -the auto-exposure, which tries to make the average intensity of the image 1/4 -of the auto-exposure value e.g. exposure is 400, the camera will try to adjust -shutter and gain so that the average image intensity is 100. When the - auto-exposure mode is enabled for exposure, the camera tries to manipulate -shutter and gain such that 5% of the image is saturated (pixel value of 255). + exposure applying \e exposure_value parameter. + \param exposure_value : This is + the average intensity of the image. It will use other available (non-manually + adjustable) controls to adjust the image. Specifically, when shutter and gain + are both in auto mode, manually adjusting the exposure is actually adjusting + the auto-exposure, which tries to make the average intensity of the image 1/4 + of the auto-exposure value e.g. exposure is 400, the camera will try to adjust + shutter and gain so that the average image intensity is 100. When the + auto-exposure mode is enabled for exposure, the camera tries to manipulate + shutter and gain such that 5% of the image is saturated (pixel value of 255). \return The measured brightness after applying the new setting. The following example shows how to use this function: \code -#include - -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - vpImage I; - - vpFlyCaptureGrabber g; - g.setCameraIndex(0); - - float exposure = g.getExposure(); - std::cout << "Exposure : " << exposure << std::endl; - exposure = g.setExposure(true, false, 1); // Turn manual exposure on to 1 - std::cout << "Exposure manual: " << exposure << std::endl; - exposure = g.setExposure(true, true); // Turn auto exposure on - std::cout << "Exposure auto : " << exposure << std::endl; - - g.open(I); - ... -#endif -} + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + vpImage I; + + vpFlyCaptureGrabber g; + g.setCameraIndex(0); + + float exposure = g.getExposure(); + std::cout << "Exposure : " << exposure << std::endl; + exposure = g.setExposure(true, false, 1); // Turn manual exposure on to 1 + std::cout << "Exposure manual: " << exposure << std::endl; + exposure = g.setExposure(true, true); // Turn auto exposure on + std::cout << "Exposure auto : " << exposure << std::endl; + + g.open(I); + ... + #endif + } \endcode \sa getExposure() @@ -705,35 +740,40 @@ float vpFlyCaptureGrabber::setExposure(bool exposure_on, bool exposure_auto, flo \param sharpness_on : If true turn sharpness on, otherwise turn off. \param sharpness_auto : If true set auto sharpness, if false set manual -sharpness applying \e sharpness_value parameter. \param sharpness_value : -Parameter used to tune the filter applyed on the image to reduce blurred edges -in an image. + sharpness applying \e sharpness_value parameter. + \param sharpness_value : + Parameter used to tune the filter applied on the image to reduce blurred edges + in an image. \return The measured sharpness after applying the new setting. The following example shows how to use this function: \code -#include - -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - vpImage I; - - vpFlyCaptureGrabber g; - g.setCameraIndex(0); - - float sharpness = g.getSharpness(); - std::cout << "Sharpness : " << sharpness << std::endl; - sharpness = g.setSharpness(true, false, 1000); // Turn manual sharpness on to 1000 - std::cout << "Sharpness manual: " << sharpness << std::endl; - sharpness = g.setSharpness(true, true); // Turn auto sharpness on - std::cout << "Sharpness auto : " << sharpness << std::endl; - - g.open(I); - ... -#endif -} + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + vpImage I; + + vpFlyCaptureGrabber g; + g.setCameraIndex(0); + + float sharpness = g.getSharpness(); + std::cout << "Sharpness : " << sharpness << std::endl; + sharpness = g.setSharpness(true, false, 1000); // Turn manual sharpness on to 1000 + std::cout << "Sharpness manual: " << sharpness << std::endl; + sharpness = g.setSharpness(true, true); // Turn auto sharpness on + std::cout << "Sharpness auto : " << sharpness << std::endl; + + g.open(I); + ... + #endif + } \endcode \sa getSharpness() @@ -793,28 +833,32 @@ FlyCapture2::PropertyInfo vpFlyCaptureGrabber::getPropertyInfo(FlyCapture2::Prop \param frame_rate : Camera frame rate. The following example shows how to use this function to set the camera image -resolution to 1280 x 960, pixel format to Y8 and capture framerate to 60 fps. + resolution to 1280 x 960, pixel format to Y8 and capture framerate to 60 fps. \code -#include -#include - -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - int nframes = 100; - vpImage I; - vpFlyCaptureGrabber g; - - g.setCameraIndex(0); // Default camera is the first on the bus - g.setVideoModeAndFrameRate(FlyCapture2::VIDEOMODE_1280x960Y8, FlyCapture2::FRAMERATE_60); - g.open(I); - g.getCameraInfo(std::cout); - - for(int i=0; i< nframes; i++) { - g.acquire(I); + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + int nframes = 100; + vpImage I; + vpFlyCaptureGrabber g; + + g.setCameraIndex(0); // Default camera is the first on the bus + g.setVideoModeAndFrameRate(FlyCapture2::VIDEOMODE_1280x960Y8, FlyCapture2::FRAMERATE_60); + g.open(I); + g.getCameraInfo(std::cout); + + for(int i=0; i< nframes; i++) { + g.acquire(I); + } + #endif } -#endif -} \endcode */ void vpFlyCaptureGrabber::setVideoModeAndFrameRate(FlyCapture2::VideoMode video_mode, FlyCapture2::FrameRate frame_rate) @@ -868,33 +912,34 @@ std::pair vpFlyCaptureGrabber::centerRoi(unsigned in Set format7 video mode. \param format7_mode : Format 7 mode. \param pixel_format : Pixel format. - \param w,h : Width and height of the centered roi. If set to 0, use the max -allowed size. + \param w,h : Width and height of the centered roi. If set to 0, use the max allowed size. - If the format7 video mode and pixel format are not supported, return an -exception. + If the format7 video mode and pixel format are not supported, return an exception. - The following example shows how to use this function to capture a 640x480 -roi: + The following example shows how to use this function to capture a 640x480 roi: \code -#include -#include + #include + #include -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - vpImage I; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - vpFlyCaptureGrabber g; - g.setCameraIndex(0); + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + vpImage I; - g.setFormat7VideoMode(FlyCapture2::MODE_0, FlyCapture2::PIXEL_FORMAT_MONO8, 640, 480); + vpFlyCaptureGrabber g; + g.setCameraIndex(0); - g.open(I); - ... -#endif -} + g.setFormat7VideoMode(FlyCapture2::MODE_0, FlyCapture2::PIXEL_FORMAT_MONO8, 640, 480); + + g.open(I); + ... + #endif + } \endcode */ void vpFlyCaptureGrabber::setFormat7VideoMode(FlyCapture2::Mode format7_mode, FlyCapture2::PixelFormat pixel_format, @@ -1291,23 +1336,27 @@ bool vpFlyCaptureGrabber::getCameraPower() The following example shows how to turn off a camera. \code -#include + #include -int main() -{ -#if defined(VISP_HAVE_FLYCAPTURE) - vpFlyCaptureGrabber g; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - g.setCameraIndex(0); - g.connect(); + int main() + { + #if defined(VISP_HAVE_FLYCAPTURE) + vpFlyCaptureGrabber g; - bool power = g.getCameraPower(); - std::cout << "Camera is powered: " << ((power == true) ? "on" : "off") << std::endl; + g.setCameraIndex(0); + g.connect(); - if (power) - g.setCameraPower(false); // Power off the camera -#endif -} + bool power = g.getCameraPower(); + std::cout << "Camera is powered: " << ((power == true) ? "on" : "off") << std::endl; + + if (power) + g.setCameraPower(false); // Power off the camera + #endif + } \endcode \sa getCameraPower() @@ -1361,20 +1410,23 @@ void vpFlyCaptureGrabber::setCameraPower(bool on) } /*! + Operator that allows to capture a grey level image. + \param I : The captured image. - Operator that allows to capture a grey level image. - \param I : The captured image. + \code + #include - \code -#include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif -int main() -{ - vpImage I; - vpFlyCaptureGrabber g; - g >> I; -} - \endcode + int main() + { + vpImage I; + vpFlyCaptureGrabber g; + g >> I; + } + \endcode */ vpFlyCaptureGrabber &vpFlyCaptureGrabber::operator>>(vpImage &I) { @@ -1384,19 +1436,23 @@ vpFlyCaptureGrabber &vpFlyCaptureGrabber::operator>>(vpImage &I) /*! - Operator that allows to capture a grey level image. - \param I : The captured image. + Operator that allows to capture a grey level image. + \param I : The captured image. - \code -#include + \code + #include -int main() -{ - vpImage I; - vpFlyCaptureGrabber g; - g >> I; -} - \endcode + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I; + vpFlyCaptureGrabber g; + g >> I; + } + \endcode */ vpFlyCaptureGrabber &vpFlyCaptureGrabber::operator>>(vpImage &I) { diff --git a/modules/sensor/src/framegrabber/v4l2/vpV4l2Grabber.cpp b/modules/sensor/src/framegrabber/v4l2/vpV4l2Grabber.cpp index b7ab43fbb5..7d013bc268 100644 --- a/modules/sensor/src/framegrabber/v4l2/vpV4l2Grabber.cpp +++ b/modules/sensor/src/framegrabber/v4l2/vpV4l2Grabber.cpp @@ -115,6 +115,10 @@ const unsigned int vpV4l2Grabber::FRAME_SIZE = 288; #include #include + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + int main() { #if defined(VISP_HAVE_V4L2) && defined(VISP_HAVE_X11) @@ -1419,19 +1423,23 @@ void vpV4l2Grabber::printBufInfo(struct v4l2_buffer buf) /*! - Operator that allows to capture a grey level image. - \param I : The captured image. + Operator that allows to capture a grey level image. + \param I : The captured image. - \code -#include + \code + #include -int main() -{ - vpImage I; - vpV4l2Grabber g; - g >> I; -} - \endcode + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I; + vpV4l2Grabber g; + g >> I; + } + \endcode */ vpV4l2Grabber &vpV4l2Grabber::operator>>(vpImage &I) { @@ -1441,19 +1449,23 @@ vpV4l2Grabber &vpV4l2Grabber::operator>>(vpImage &I) /*! - Operator that allows to capture a grey level image. - \param I : The captured image. + Operator that allows to capture a grey level image. + \param I : The captured image. - \code -#include + \code + #include -int main() -{ - vpImage I; - vpV4l2Grabber g; - g >> I; -} - \endcode + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I; + vpV4l2Grabber g; + g >> I; + } + \endcode */ vpV4l2Grabber &vpV4l2Grabber::operator>>(vpImage &I) { diff --git a/modules/sensor/src/rgb-depth/realsense/vpRealSense.cpp b/modules/sensor/src/rgb-depth/realsense/vpRealSense.cpp index 18b8e21947..e744d5b2c3 100644 --- a/modules/sensor/src/rgb-depth/realsense/vpRealSense.cpp +++ b/modules/sensor/src/rgb-depth/realsense/vpRealSense.cpp @@ -47,7 +47,7 @@ BEGIN_VISP_NAMESPACE /*! * Default constructor. */ -vpRealSense::vpRealSense() + vpRealSense::vpRealSense() : m_context(), m_device(nullptr), m_num_devices(0), m_serial_no(), m_intrinsics(), m_max_Z(8), m_enableStreams(), m_useStreamPresets(), m_streamPresets(), m_streamParams(), m_invalidDepthValue(0.0f) { @@ -255,14 +255,18 @@ void vpRealSense::close() \param serial_no : Device serial number. \code -#include + #include -int main() -{ - vpRealSense rs; - rs.setDeviceBySerialNumber("541142003219"); - rs.open(); -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRealSense rs; + rs.setDeviceBySerialNumber("541142003219"); + rs.open(); + } \endcode */ void vpRealSense::setDeviceBySerialNumber(const std::string &serial_no) @@ -619,25 +623,29 @@ void vpRealSense::setStreamSettings(const rs::stream &stream, const rs::preset & \param params : Stream parameters to use. \note You can find the stream settings of the different Intel RealSense -cameras at this url. + cameras at this url. \code -#include + #include -int main() -{ - vpRealSense rs; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - rs.setEnableStream(rs::stream::color, true); - rs.setEnableStream(rs::stream::depth, false); - rs.setEnableStream(rs::stream::infrared, false); - rs.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(1920, 1080, rs::format::rgba8, 30)); + int main() + { + vpRealSense rs; - rs.open(); + rs.setEnableStream(rs::stream::color, true); + rs.setEnableStream(rs::stream::depth, false); + rs.setEnableStream(rs::stream::infrared, false); + rs.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(1920, 1080, rs::format::rgba8, 30)); - //[...] -} + rs.open(); + + //[...] + } \endcode */ void vpRealSense::setStreamSettings(const rs::stream &stream, const vpRsStreamParams ¶ms) @@ -652,21 +660,25 @@ void vpRealSense::setStreamSettings(const rs::stream &stream, const vpRsStreamPa \param status : Stream status. \code -#include + #include -int main() -{ - vpRealSense rs; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - rs.setEnableStream(rs::stream::color, true); - rs.setEnableStream(rs::stream::depth, false); - rs.setEnableStream(rs::stream::infrared, false); - rs.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(1920, 1080, rs::format::rgba8, 30)); + int main() + { + vpRealSense rs; - rs.open(); + rs.setEnableStream(rs::stream::color, true); + rs.setEnableStream(rs::stream::depth, false); + rs.setEnableStream(rs::stream::infrared, false); + rs.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(1920, 1080, rs::format::rgba8, 30)); - //[...] -} + rs.open(); + + //[...] + } \endcode */ void vpRealSense::setEnableStream(const rs::stream &stream, bool status) { m_enableStreams[stream] = status; } @@ -1016,15 +1028,19 @@ void vpRealSense::acquire(unsigned char *const data_image, unsigned char *const The following example shows how to use this method. \code -#include + #include -int main() -{ - vpRealSense rs; - rs.open(); - std::cout << "RealSense sensor characteristics: \n" << rs << std::endl; - return 0; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRealSense rs; + rs.open(); + std::cout << "RealSense sensor characteristics: \n" << rs << std::endl; + return 0; + } \endcode */ std::ostream &operator<<(std::ostream &os, const vpRealSense &rs) diff --git a/modules/sensor/src/rgb-depth/realsense/vpRealSense2.cpp b/modules/sensor/src/rgb-depth/realsense/vpRealSense2.cpp index afe3b41875..3b51fe78f0 100644 --- a/modules/sensor/src/rgb-depth/realsense/vpRealSense2.cpp +++ b/modules/sensor/src/rgb-depth/realsense/vpRealSense2.cpp @@ -69,7 +69,7 @@ BEGIN_VISP_NAMESPACE /*! * Default constructor. */ -vpRealSense2::vpRealSense2() + vpRealSense2::vpRealSense2() : m_depthScale(0.0f), m_invalidDepthValue(0.0f), m_max_Z(8.0f), m_pipe(), m_pipelineProfile(), m_pointcloud(), m_points(), m_pos(), m_quat(), m_rot(), m_product_line(), m_init(false) { } @@ -142,46 +142,51 @@ void vpRealSense2::acquire(unsigned char *const data_image, unsigned char *const The following code shows how to use this function to get color, infrared 1 and infrared 2 frames acquired by a D435 device: \code -#include -#include -#include + #include + #include + #include -int main() { - vpRealSense2 rs; - rs2::config config; - config.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_RGBA8, 30); - config.enable_stream(RS2_STREAM_INFRARED, 1, 640, 480, RS2_FORMAT_Y8, 30); - config.enable_stream(RS2_STREAM_INFRARED, 2, 640, 480, RS2_FORMAT_Y8, 30); - rs.open(config); - vpImage Ic(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); - vpImage Ii1(rs.getIntrinsics(RS2_STREAM_INFRARED).height, - rs.getIntrinsics(RS2_STREAM_INFRARED).width); - vpImage Ii2(rs.getIntrinsics(RS2_STREAM_INFRARED).height, - rs.getIntrinsics(RS2_STREAM_INFRARED).width); - -#ifdef VISP_HAVE_X11 - vpDisplayX dc(Ic, 0, 0, "Color"); - vpDisplayX di1(Ii1, 100, 100, "Infrared 1"); - vpDisplayX di2(Ii2, 200, 200, "Infrared 2"); -#elif defined(VISP_HAVE_GDI) - vpDisplayGDI dc(Ic, 0, 0, "Color"); - vpDisplayGDI di1(Ii1, 100, 100, "Infrared 1"); - vpDisplayGDI di2(Ii2, 100, 100, "Infrared 2"); -#endif + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif - while (true) { - rs.acquire((unsigned char *) Ic.bitmap, nullptr, nullptr, Ii1.bitmap, Ii2.bitmap, nullptr); - vpDisplay::display(Ic); - vpDisplay::display(Ii1); - vpDisplay::display(Ii2); - vpDisplay::flush(Ic); - vpDisplay::flush(Ii1); - vpDisplay::flush(Ii2); - if (vpDisplay::getClick(Ic, false) || vpDisplay::getClick(Ii1, false) || vpDisplay::getClick(Ii2, false)) - break; - } - return 0; -} + int main() + { + vpRealSense2 rs; + rs2::config config; + config.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_RGBA8, 30); + config.enable_stream(RS2_STREAM_INFRARED, 1, 640, 480, RS2_FORMAT_Y8, 30); + config.enable_stream(RS2_STREAM_INFRARED, 2, 640, 480, RS2_FORMAT_Y8, 30); + rs.open(config); + vpImage Ic(rs.getIntrinsics(RS2_STREAM_COLOR).height, rs.getIntrinsics(RS2_STREAM_COLOR).width); + vpImage Ii1(rs.getIntrinsics(RS2_STREAM_INFRARED).height, + rs.getIntrinsics(RS2_STREAM_INFRARED).width); + vpImage Ii2(rs.getIntrinsics(RS2_STREAM_INFRARED).height, + rs.getIntrinsics(RS2_STREAM_INFRARED).width); + + #ifdef VISP_HAVE_X11 + vpDisplayX dc(Ic, 0, 0, "Color"); + vpDisplayX di1(Ii1, 100, 100, "Infrared 1"); + vpDisplayX di2(Ii2, 200, 200, "Infrared 2"); + #elif defined(VISP_HAVE_GDI) + vpDisplayGDI dc(Ic, 0, 0, "Color"); + vpDisplayGDI di1(Ii1, 100, 100, "Infrared 1"); + vpDisplayGDI di2(Ii2, 100, 100, "Infrared 2"); + #endif + + while (true) { + rs.acquire((unsigned char *) Ic.bitmap, nullptr, nullptr, Ii1.bitmap, Ii2.bitmap, nullptr); + vpDisplay::display(Ic); + vpDisplay::display(Ii1); + vpDisplay::display(Ii2); + vpDisplay::flush(Ic); + vpDisplay::flush(Ii1); + vpDisplay::flush(Ii2); + if (vpDisplay::getClick(Ic, false) || vpDisplay::getClick(Ii1, false) || vpDisplay::getClick(Ii2, false)) + break; + } + return 0; + } \endcode */ void vpRealSense2::acquire(unsigned char *const data_image, unsigned char *const data_depth, @@ -1569,15 +1574,19 @@ struct stream_and_index The following example shows how to use this method. \code -#include + #include -int main() -{ - vpRealSense2 rs; - rs.open(); - std::cout << "RealSense sensor information:\n" << rs << std::endl; - return 0; -} + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpRealSense2 rs; + rs.open(); + std::cout << "RealSense sensor information:\n" << rs << std::endl; + return 0; + } \endcode */ std::ostream &operator<<(std::ostream &os, const vpRealSense2 &rs) diff --git a/modules/tracker/blob/include/visp3/blob/vpDot.h b/modules/tracker/blob/include/visp3/blob/vpDot.h index 1fd65f0dec..ba6b49c123 100644 --- a/modules/tracker/blob/include/visp3/blob/vpDot.h +++ b/modules/tracker/blob/include/visp3/blob/vpDot.h @@ -78,6 +78,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined(VISP_HAVE_DC1394) diff --git a/modules/tracker/dnn/include/visp3/dnn_tracker/vpMegaPoseTracker.h b/modules/tracker/dnn/include/visp3/dnn_tracker/vpMegaPoseTracker.h index 7dd8a783cf..155b1f2392 100644 --- a/modules/tracker/dnn/include/visp3/dnn_tracker/vpMegaPoseTracker.h +++ b/modules/tracker/dnn/include/visp3/dnn_tracker/vpMegaPoseTracker.h @@ -56,6 +56,10 @@ BEGIN_VISP_NAMESPACE * \code{.cpp} * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpCameraParameters cam; diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h index 3bbea80c3a..63968ba59d 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h @@ -81,6 +81,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined VISP_HAVE_OPENCV diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h index 4fea74f221..04f6b8f349 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h @@ -169,6 +169,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpMbEdgeTracker tracker; // Create a model based tracker. @@ -204,6 +208,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpMbEdgeTracker tracker; // Create a model based tracker. diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h index 5d92b2d757..07f5eeea3a 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h @@ -90,6 +90,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined(VISP_HAVE_NLOHMANN_JSON) diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h index bc56e7816f..dab9c8bc17 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h @@ -83,6 +83,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined VISP_HAVE_OPENCV @@ -132,6 +136,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined VISP_HAVE_OPENCV @@ -169,6 +177,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined VISP_HAVE_OPENCV diff --git a/modules/tracker/mbt/src/vpMbtPolygon.cpp b/modules/tracker/mbt/src/vpMbtPolygon.cpp index 26f8a7bf15..3628e6ecac 100644 --- a/modules/tracker/mbt/src/vpMbtPolygon.cpp +++ b/modules/tracker/mbt/src/vpMbtPolygon.cpp @@ -239,31 +239,35 @@ bool vpMbtPolygon::isVisible(const vpHomogeneousMatrix &cMo, double alpha, const The sample code below shows how to introduce this feature: \code -#include -#include + #include + #include -int main() -{ - vpImage I; + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I; - // Acquire an image - vpImageIo::read(I, "my-image.pgm"); + // Acquire an image + vpImageIo::read(I, "my-image.pgm"); - std::string object = "my-object"; - vpMbEdgeTracker tracker; - tracker.loadConfigFile( object+".xml" ); - tracker.loadModel( object+".cao" ); + std::string object = "my-object"; + vpMbEdgeTracker tracker; + tracker.loadConfigFile( object+".xml" ); + tracker.loadModel( object+".cao" ); - tracker.setLod(true); - tracker.setMinLineLengthThresh(20.); - tracker.setMinPolygonAreaThresh(20.*20.); + tracker.setLod(true); + tracker.setMinLineLengthThresh(20.); + tracker.setMinPolygonAreaThresh(20.*20.); - tracker.initClick(I, object+".init" ); + tracker.initClick(I, object+".init" ); - while (true) { - // tracking loop + while (true) { + // tracking loop + } } -} \endcode \sa setMinLineLengthThresh(), setMinPolygonAreaThresh() diff --git a/modules/tracker/me/include/visp3/me/vpMe.h b/modules/tracker/me/include/visp3/me/vpMe.h index dc3d54064d..d8fa3d0e7f 100644 --- a/modules/tracker/me/include/visp3/me/vpMe.h +++ b/modules/tracker/me/include/visp3/me/vpMe.h @@ -64,6 +64,10 @@ BEGIN_VISP_NAMESPACE * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if defined(VISP_HAVE_NLOHMANN_JSON) diff --git a/modules/tracker/me/include/visp3/me/vpMeLine.h b/modules/tracker/me/include/visp3/me/vpMeLine.h index b8a0c6d1a4..94cbcdd283 100644 --- a/modules/tracker/me/include/visp3/me/vpMeLine.h +++ b/modules/tracker/me/include/visp3/me/vpMeLine.h @@ -98,6 +98,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpImage I(240, 320); diff --git a/modules/tracker/me/include/visp3/me/vpMeNurbs.h b/modules/tracker/me/include/visp3/me/vpMeNurbs.h index 4bfe6b3916..67fe2c0b1b 100644 --- a/modules/tracker/me/include/visp3/me/vpMeNurbs.h +++ b/modules/tracker/me/include/visp3/me/vpMeNurbs.h @@ -71,6 +71,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpImage I(240, 320); diff --git a/modules/tracker/tt/src/vpTemplateTracker.cpp b/modules/tracker/tt/src/vpTemplateTracker.cpp index 6191b831f5..b9320ca4fa 100644 --- a/modules/tracker/tt/src/vpTemplateTracker.cpp +++ b/modules/tracker/tt/src/vpTemplateTracker.cpp @@ -291,28 +291,32 @@ void vpTemplateTracker::resetTracker() The following code shows how to use display capabilities: \code -#include -#include - -int main() -{ - vpImage I; - vpTemplateTrackerWarpHomography warp; - vpTemplateTrackerSSDInverseCompositional tracker(&warp); - vpTemplateTrackerZone zoneRef, zoneWarped; - - // Display the warped zone - tracker.display(I, vpColor::red); - - // Display the reference zone - zoneRef = tracker.getZoneRef(); - zoneRef.display(I, vpColor::green); - - // Display the warped zone - vpColVector p = tracker.getp(); - warp.warpZone(zoneRef, p, zoneWarped); - zoneWarped.display(I, vpColor::blue); -} + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I; + vpTemplateTrackerWarpHomography warp; + vpTemplateTrackerSSDInverseCompositional tracker(&warp); + vpTemplateTrackerZone zoneRef, zoneWarped; + + // Display the warped zone + tracker.display(I, vpColor::red); + + // Display the reference zone + zoneRef = tracker.getZoneRef(); + zoneRef.display(I, vpColor::green); + + // Display the warped zone + vpColVector p = tracker.getp(); + warp.warpZone(zoneRef, p, zoneWarped); + zoneWarped.display(I, vpColor::blue); + } \endcode */ void vpTemplateTracker::display(const vpImage &I, const vpColor &col, unsigned int thickness) @@ -333,28 +337,32 @@ void vpTemplateTracker::display(const vpImage &I, const vpColor & The following code shows how to use display capabilities: \code -#include -#include - -int main() -{ - vpImage I; - vpTemplateTrackerWarpHomography warp; - vpTemplateTrackerSSDInverseCompositional tracker(&warp); - vpTemplateTrackerZone zoneRef, zoneWarped; - - // Display the warped zone - tracker.display(I, vpColor::red); - - // Display the reference zone - zoneRef = tracker.getZoneRef(); - zoneRef.display(I, vpColor::green); - - // Display the warped zone - vpColVector p = tracker.getp(); - warp.warpZone(zoneRef, p, zoneWarped); - zoneWarped.display(I, vpColor::blue); -} + #include + #include + + #ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; + #endif + + int main() + { + vpImage I; + vpTemplateTrackerWarpHomography warp; + vpTemplateTrackerSSDInverseCompositional tracker(&warp); + vpTemplateTrackerZone zoneRef, zoneWarped; + + // Display the warped zone + tracker.display(I, vpColor::red); + + // Display the reference zone + zoneRef = tracker.getZoneRef(); + zoneRef.display(I, vpColor::green); + + // Display the warped zone + vpColVector p = tracker.getp(); + warp.warpZone(zoneRef, p, zoneWarped); + zoneWarped.display(I, vpColor::blue); + } \endcode */ void vpTemplateTracker::display(const vpImage &I, const vpColor &col, unsigned int thickness) diff --git a/modules/vision/include/visp3/vision/vpHomography.h b/modules/vision/include/visp3/vision/vpHomography.h index fef78d3132..e18120f2ee 100644 --- a/modules/vision/include/visp3/vision/vpHomography.h +++ b/modules/vision/include/visp3/vision/vpHomography.h @@ -96,6 +96,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * // Initialize in the object frame the coordinates in meters of 4 points that diff --git a/modules/vision/include/visp3/vision/vpKeyPoint.h b/modules/vision/include/visp3/vision/vpKeyPoint.h index 3fc8689679..8571bd98c0 100644 --- a/modules/vision/include/visp3/vision/vpKeyPoint.h +++ b/modules/vision/include/visp3/vision/vpKeyPoint.h @@ -124,6 +124,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if (VISP_HAVE_OPENCV_VERSION >= 0x020300) @@ -161,6 +165,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * #if (VISP_HAVE_OPENCV_VERSION >= 0x020300) diff --git a/modules/vision/include/visp3/vision/vpPoseFeatures.h b/modules/vision/include/visp3/vision/vpPoseFeatures.h index 4a79507bcd..aea9ca7f4e 100644 --- a/modules/vision/include/visp3/vision/vpPoseFeatures.h +++ b/modules/vision/include/visp3/vision/vpPoseFeatures.h @@ -678,6 +678,10 @@ class VISP_EXPORT vpPoseFeatures * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * void vp_createPoint(vpFeaturePoint &fp,const vpPoint &p) { * vpFeatureBuilder::create(fp,p); * } @@ -746,6 +750,10 @@ void vpPoseFeatures::addSpecificFeature(RetType(*fct_ptr)(ArgsFunc...), Args &&. * \code * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * class vp_createClass{ * public: * vp_createClass(){} diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureDepth.h b/modules/visual_features/include/visp3/visual_features/vpFeatureDepth.h index 41de99c559..5bcf22027e 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureDepth.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureDepth.h @@ -86,6 +86,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpServo task; // Visual servoing task @@ -132,6 +136,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpFeatureDepth s; //The current point feature. diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureLine.h b/modules/visual_features/include/visp3/visual_features/vpFeatureLine.h index 477ccad87c..12ff2ad97f 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureLine.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureLine.h @@ -94,6 +94,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpServo task; // Visual servoing task @@ -155,6 +159,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpFeatureLine sd; //The desired line feature. diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h index 0fe7e79314..2dfb2b1781 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMoment.h @@ -119,6 +119,10 @@ class vpMoment; * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpPoint p; diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCommon.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCommon.h index 6e683b8c8b..c8738b8e01 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCommon.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCommon.h @@ -103,6 +103,10 @@ class vpServo; * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * // Define source polygon diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentDatabase.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentDatabase.h index 0b86967fbd..15f873858e 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentDatabase.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentDatabase.h @@ -89,6 +89,10 @@ class vpMomentObject; * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * try { diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h index 0966928a01..c15a793a50 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h @@ -75,6 +75,10 @@ class vpMomentDatabase; * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpPoint p; diff --git a/modules/visual_features/include/visp3/visual_features/vpFeaturePoint.h b/modules/visual_features/include/visp3/visual_features/vpFeaturePoint.h index 5f27a79d42..ce584938f2 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeaturePoint.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeaturePoint.h @@ -87,6 +87,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpServo task; // Visual servoing task @@ -142,6 +146,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpFeaturePoint sd; //The desired point feature. diff --git a/modules/visual_features/include/visp3/visual_features/vpFeaturePoint3D.h b/modules/visual_features/include/visp3/visual_features/vpFeaturePoint3D.h index b77179c607..3d1cf14792 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeaturePoint3D.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeaturePoint3D.h @@ -98,6 +98,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpServo task; // Visual servoing task @@ -168,6 +172,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * // Set the 3D point coordinates in the object frame: oP diff --git a/modules/visual_features/include/visp3/visual_features/vpFeaturePointPolar.h b/modules/visual_features/include/visp3/visual_features/vpFeaturePointPolar.h index 7ff03741ed..b05e219d7f 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeaturePointPolar.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeaturePointPolar.h @@ -132,6 +132,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * // Create 4 points to specify the object of interest @@ -228,6 +232,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * // Creation of the current feature s diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureThetaU.h b/modules/visual_features/include/visp3/visual_features/vpFeatureThetaU.h index 52a00296d6..408185d2f0 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureThetaU.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureThetaU.h @@ -140,6 +140,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpServo task; // Visual servoing task @@ -196,6 +200,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpHomogeneousMatrix cdMc; diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureTranslation.h b/modules/visual_features/include/visp3/visual_features/vpFeatureTranslation.h index d95e159251..5f5f769673 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureTranslation.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureTranslation.h @@ -131,6 +131,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpServo task; // Visual servoing task @@ -187,6 +191,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpHomogeneousMatrix cdMc; @@ -223,6 +231,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpServo task; // Visual servoing task diff --git a/modules/visual_features/include/visp3/visual_features/vpGenericFeature.h b/modules/visual_features/include/visp3/visual_features/vpGenericFeature.h index adde52e73d..14bb5a731a 100644 --- a/modules/visual_features/include/visp3/visual_features/vpGenericFeature.h +++ b/modules/visual_features/include/visp3/visual_features/vpGenericFeature.h @@ -67,6 +67,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpServo task; // Visual servoing task @@ -124,6 +128,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpServo task; // Visual servoing task diff --git a/modules/visual_features/src/visual-feature/vpFeatureSegment.cpp b/modules/visual_features/src/visual-feature/vpFeatureSegment.cpp index db67d935be..ae2d05db56 100644 --- a/modules/visual_features/src/visual-feature/vpFeatureSegment.cpp +++ b/modules/visual_features/src/visual-feature/vpFeatureSegment.cpp @@ -55,7 +55,7 @@ BEGIN_VISP_NAMESPACE /*! * Initialise the memory space requested for segment visual feature. */ -void vpFeatureSegment::init() + void vpFeatureSegment::init() { // feature dimension dim_s = 4; @@ -143,6 +143,10 @@ vpFeatureSegment::vpFeatureSegment(bool normalized) * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * // Define two 3D points in the object frame diff --git a/modules/vs/include/visp3/vs/vpAdaptiveGain.h b/modules/vs/include/visp3/vs/vpAdaptiveGain.h index 898e2781a3..0fa1e9e0dc 100644 --- a/modules/vs/include/visp3/vs/vpAdaptiveGain.h +++ b/modules/vs/include/visp3/vs/vpAdaptiveGain.h @@ -79,6 +79,10 @@ class vpColVector; * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpAdaptiveGain lambda(4, 0.4, 30); // lambda(0)=4, lambda(oo)=0.4 and lambda'(0)=30 diff --git a/modules/vs/include/visp3/vs/vpServo.h b/modules/vs/include/visp3/vs/vpServo.h index b19a8d3552..6f81eaf97e 100644 --- a/modules/vs/include/visp3/vs/vpServo.h +++ b/modules/vs/include/visp3/vs/vpServo.h @@ -81,6 +81,10 @@ BEGIN_VISP_NAMESPACE * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * // Creation of an homogeneous matrix that represent the displacement @@ -908,6 +912,10 @@ class VISP_EXPORT vpServo * #include * #include * + * #ifdef ENABLE_VISP_NAMESPACE + * using namespace VISP_NAMESPACE_NAME; + * #endif + * * int main() * { * vpServo servo; From 589225ed38156a24216162972114c4fb03c89978 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 25 Jun 2024 14:00:22 +0200 Subject: [PATCH 09/11] Fix typo --- ...imuFourPoints2DPolarCamVelocityDisplay.cpp | 6 ++--- .../servoAfma4Point2DArtVelocity.cpp | 4 ++-- .../servoAfma4Point2DCamVelocity.cpp | 4 ++-- .../servoAfma4Point2DCamVelocityKalman.cpp | 4 ++-- .../servoAfma6FourPoints2DArtVelocity.cpp | 4 ++-- ...ervoAfma6FourPoints2DCamVelocityLs_cur.cpp | 4 ++-- ...ervoAfma6FourPoints2DCamVelocityLs_des.cpp | 4 ++-- .../servoAfma6Point2DArtVelocity.cpp | 4 ++-- .../servoAfma6Point2DCamVelocity.cpp | 4 ++-- .../servoAfma6Segment2DCamVelocity.cpp | 4 ++-- ...oViper650FourPoints2DArtVelocityLs_cur.cpp | 4 ++-- ...650FourPoints2DCamVelocityLs_cur-SR300.cpp | 4 ++-- ...oViper650FourPoints2DCamVelocityLs_cur.cpp | 4 ++-- .../servoViper650Point2DCamVelocity.cpp | 4 ++-- ...oViper850FourPoints2DArtVelocityLs_cur.cpp | 4 ++-- ...oViper850FourPoints2DArtVelocityLs_des.cpp | 4 ++-- ...oViper850FourPoints2DCamVelocityLs_cur.cpp | 4 ++-- .../servoViper850FourPointsKinect.cpp | 4 ++-- .../servoViper850Point2DArtVelocity.cpp | 4 ++-- .../servoViper850Point2DCamVelocity.cpp | 4 ++-- .../servoViper850Point2DCamVelocityKalman.cpp | 4 ++-- modules/core/include/visp3/core/vpBSpline.h | 4 ++-- .../core/include/visp3/core/vpMomentBasic.h | 2 +- modules/core/src/image/vpImagePoint.cpp | 6 ++--- .../vpLinearKalmanFilterInstantiation.cpp | 8 +++---- .../robot/include/visp3/robot/vpRobotAfma6.h | 2 +- .../include/visp3/robot/vpRobotViper650.h | 2 +- .../include/visp3/robot/vpRobotViper850.h | 2 +- .../src/real-robot/afma4/vpRobotAfma4.cpp | 12 +++++----- .../robot/src/real-robot/afma6/vpAfma6.cpp | 2 +- .../src/real-robot/afma6/vpRobotAfma6.cpp | 16 ++++++------- .../src/real-robot/viper/vpRobotViper650.cpp | 16 ++++++------- .../src/real-robot/viper/vpRobotViper850.cpp | 14 +++++------ .../robot/src/real-robot/viper/vpViper650.cpp | 6 ++--- .../robot/src/real-robot/viper/vpViper850.cpp | 4 ++-- .../src/robot-simulator/vpRobotCamera.cpp | 8 +++---- .../src/robot-simulator/vpSimulatorAfma6.cpp | 22 ++++++++--------- .../src/robot-simulator/vpSimulatorCamera.cpp | 8 +++---- .../robot-simulator/vpSimulatorPioneer.cpp | 8 +++---- .../robot-simulator/vpSimulatorPioneerPan.cpp | 8 +++---- .../robot-simulator/vpSimulatorViper850.cpp | 24 +++++++++---------- .../robot/test/virtuose/testVirtuoseAfma6.cpp | 2 +- .../framegrabber/1394/vp1394TwoGrabber.cpp | 8 +++---- 43 files changed, 135 insertions(+), 135 deletions(-) diff --git a/example/robot-simulator/camera/servoSimuFourPoints2DPolarCamVelocityDisplay.cpp b/example/robot-simulator/camera/servoSimuFourPoints2DPolarCamVelocityDisplay.cpp index e2eaceb36d..2cbbed1891 100644 --- a/example/robot-simulator/camera/servoSimuFourPoints2DPolarCamVelocityDisplay.cpp +++ b/example/robot-simulator/camera/servoSimuFourPoints2DPolarCamVelocityDisplay.cpp @@ -175,8 +175,8 @@ int main(int argc, const char **argv) // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed camera velocities (m/s, rad/s) to achieve the task - // - the 6 mesured camera velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured camera velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 8 values of s - s* std::string username; // Get the user login name @@ -489,5 +489,5 @@ int main() std::cout << "Tip if you are on a windows-like system:" << std::endl; std::cout << "- Install GDI, configure again ViSP using cmake and build again this example" << std::endl; return EXIT_SUCCESS; - } +} #endif diff --git a/example/servo-afma4/servoAfma4Point2DArtVelocity.cpp b/example/servo-afma4/servoAfma4Point2DArtVelocity.cpp index f573583197..96a227240e 100644 --- a/example/servo-afma4/servoAfma4Point2DArtVelocity.cpp +++ b/example/servo-afma4/servoAfma4Point2DArtVelocity.cpp @@ -97,8 +97,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed joint velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 2 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-afma4/servoAfma4Point2DCamVelocity.cpp b/example/servo-afma4/servoAfma4Point2DCamVelocity.cpp index 7d42b92cc6..78df661550 100644 --- a/example/servo-afma4/servoAfma4Point2DCamVelocity.cpp +++ b/example/servo-afma4/servoAfma4Point2DCamVelocity.cpp @@ -93,8 +93,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed cam velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 2 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-afma4/servoAfma4Point2DCamVelocityKalman.cpp b/example/servo-afma4/servoAfma4Point2DCamVelocityKalman.cpp index ed853419f3..728299e9d1 100644 --- a/example/servo-afma4/servoAfma4Point2DCamVelocityKalman.cpp +++ b/example/servo-afma4/servoAfma4Point2DCamVelocityKalman.cpp @@ -197,8 +197,8 @@ int main(int argc, const char **argv) // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed cam velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 2 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-afma6/servoAfma6FourPoints2DArtVelocity.cpp b/example/servo-afma6/servoAfma6FourPoints2DArtVelocity.cpp index dfed3fbf53..5deed9add6 100644 --- a/example/servo-afma6/servoAfma6FourPoints2DArtVelocity.cpp +++ b/example/servo-afma6/servoAfma6FourPoints2DArtVelocity.cpp @@ -101,8 +101,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed joint velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 8 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-afma6/servoAfma6FourPoints2DCamVelocityLs_cur.cpp b/example/servo-afma6/servoAfma6FourPoints2DCamVelocityLs_cur.cpp index a34fd93593..07ff6d1f0e 100644 --- a/example/servo-afma6/servoAfma6FourPoints2DCamVelocityLs_cur.cpp +++ b/example/servo-afma6/servoAfma6FourPoints2DCamVelocityLs_cur.cpp @@ -148,8 +148,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed camera velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 8 values of s - s* // - the 6 values of the pose cMo (tx,ty,tz, rx,ry,rz) with translation // in meters and rotations in radians diff --git a/example/servo-afma6/servoAfma6FourPoints2DCamVelocityLs_des.cpp b/example/servo-afma6/servoAfma6FourPoints2DCamVelocityLs_des.cpp index ce31d9306b..f12f0d2ac4 100644 --- a/example/servo-afma6/servoAfma6FourPoints2DCamVelocityLs_des.cpp +++ b/example/servo-afma6/servoAfma6FourPoints2DCamVelocityLs_des.cpp @@ -98,8 +98,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed camera velocities (m/s, rad/s) to achieve the task - // - the 6 mesured camera velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured camera velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 8 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-afma6/servoAfma6Point2DArtVelocity.cpp b/example/servo-afma6/servoAfma6Point2DArtVelocity.cpp index e0d96a6dc8..7e1d516f0f 100644 --- a/example/servo-afma6/servoAfma6Point2DArtVelocity.cpp +++ b/example/servo-afma6/servoAfma6Point2DArtVelocity.cpp @@ -95,8 +95,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed joint velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 2 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-afma6/servoAfma6Point2DCamVelocity.cpp b/example/servo-afma6/servoAfma6Point2DCamVelocity.cpp index f2cbf4c61b..ce0f876330 100644 --- a/example/servo-afma6/servoAfma6Point2DCamVelocity.cpp +++ b/example/servo-afma6/servoAfma6Point2DCamVelocity.cpp @@ -87,8 +87,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed cam velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 2 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-afma6/servoAfma6Segment2DCamVelocity.cpp b/example/servo-afma6/servoAfma6Segment2DCamVelocity.cpp index fb07398fcc..a2b38c7947 100644 --- a/example/servo-afma6/servoAfma6Segment2DCamVelocity.cpp +++ b/example/servo-afma6/servoAfma6Segment2DCamVelocity.cpp @@ -81,8 +81,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed cam velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 2 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-viper650/servoViper650FourPoints2DArtVelocityLs_cur.cpp b/example/servo-viper650/servoViper650FourPoints2DArtVelocityLs_cur.cpp index e8d0dbaaa2..8e9e8fe65c 100644 --- a/example/servo-viper650/servoViper650FourPoints2DArtVelocityLs_cur.cpp +++ b/example/servo-viper650/servoViper650FourPoints2DArtVelocityLs_cur.cpp @@ -126,8 +126,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed joint velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 8 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-viper650/servoViper650FourPoints2DCamVelocityLs_cur-SR300.cpp b/example/servo-viper650/servoViper650FourPoints2DCamVelocityLs_cur-SR300.cpp index 02a11aba34..3c7ac45cf5 100644 --- a/example/servo-viper650/servoViper650FourPoints2DCamVelocityLs_cur-SR300.cpp +++ b/example/servo-viper650/servoViper650FourPoints2DCamVelocityLs_cur-SR300.cpp @@ -129,8 +129,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed camera velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 8 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-viper650/servoViper650FourPoints2DCamVelocityLs_cur.cpp b/example/servo-viper650/servoViper650FourPoints2DCamVelocityLs_cur.cpp index 92127252a0..2f7e2ef074 100644 --- a/example/servo-viper650/servoViper650FourPoints2DCamVelocityLs_cur.cpp +++ b/example/servo-viper650/servoViper650FourPoints2DCamVelocityLs_cur.cpp @@ -127,8 +127,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed camera velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 8 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-viper650/servoViper650Point2DCamVelocity.cpp b/example/servo-viper650/servoViper650Point2DCamVelocity.cpp index 4ff6c3993a..002e2aa488 100644 --- a/example/servo-viper650/servoViper650Point2DCamVelocity.cpp +++ b/example/servo-viper650/servoViper650Point2DCamVelocity.cpp @@ -82,8 +82,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed camera velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 2 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-viper850/servoViper850FourPoints2DArtVelocityLs_cur.cpp b/example/servo-viper850/servoViper850FourPoints2DArtVelocityLs_cur.cpp index b02fd2b47f..f687e552df 100644 --- a/example/servo-viper850/servoViper850FourPoints2DArtVelocityLs_cur.cpp +++ b/example/servo-viper850/servoViper850FourPoints2DArtVelocityLs_cur.cpp @@ -129,8 +129,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed joint velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 8 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-viper850/servoViper850FourPoints2DArtVelocityLs_des.cpp b/example/servo-viper850/servoViper850FourPoints2DArtVelocityLs_des.cpp index e2f684e637..6878b007ce 100644 --- a/example/servo-viper850/servoViper850FourPoints2DArtVelocityLs_des.cpp +++ b/example/servo-viper850/servoViper850FourPoints2DArtVelocityLs_des.cpp @@ -82,8 +82,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed joint velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 8 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-viper850/servoViper850FourPoints2DCamVelocityLs_cur.cpp b/example/servo-viper850/servoViper850FourPoints2DCamVelocityLs_cur.cpp index 9021648803..2bf8f4222f 100644 --- a/example/servo-viper850/servoViper850FourPoints2DCamVelocityLs_cur.cpp +++ b/example/servo-viper850/servoViper850FourPoints2DCamVelocityLs_cur.cpp @@ -130,8 +130,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed joint velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 8 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-viper850/servoViper850FourPointsKinect.cpp b/example/servo-viper850/servoViper850FourPointsKinect.cpp index 3ff87e68b3..2195b9fce8 100644 --- a/example/servo-viper850/servoViper850FourPointsKinect.cpp +++ b/example/servo-viper850/servoViper850FourPointsKinect.cpp @@ -134,8 +134,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed joint velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 8 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-viper850/servoViper850Point2DArtVelocity.cpp b/example/servo-viper850/servoViper850Point2DArtVelocity.cpp index 9ad92b46f8..5ced809e38 100644 --- a/example/servo-viper850/servoViper850Point2DArtVelocity.cpp +++ b/example/servo-viper850/servoViper850Point2DArtVelocity.cpp @@ -85,8 +85,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed joint velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 2 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-viper850/servoViper850Point2DCamVelocity.cpp b/example/servo-viper850/servoViper850Point2DCamVelocity.cpp index f71aec8334..15c39c204f 100644 --- a/example/servo-viper850/servoViper850Point2DCamVelocity.cpp +++ b/example/servo-viper850/servoViper850Point2DCamVelocity.cpp @@ -84,8 +84,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed joint velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 2 values of s - s* std::string username; // Get the user login name diff --git a/example/servo-viper850/servoViper850Point2DCamVelocityKalman.cpp b/example/servo-viper850/servoViper850Point2DCamVelocityKalman.cpp index f1b7ae735f..44bff1775c 100644 --- a/example/servo-viper850/servoViper850Point2DCamVelocityKalman.cpp +++ b/example/servo-viper850/servoViper850Point2DCamVelocityKalman.cpp @@ -87,8 +87,8 @@ int main() // Log file creation in /tmp/$USERNAME/log.dat // This file contains by line: // - the 6 computed joint velocities (m/s, rad/s) to achieve the task - // - the 6 mesured joint velocities (m/s, rad/s) - // - the 6 mesured joint positions (m, rad) + // - the 6 measured joint velocities (m/s, rad/s) + // - the 6 measured joint positions (m, rad) // - the 2 values of s - s* std::string username; // Get the user login name diff --git a/modules/core/include/visp3/core/vpBSpline.h b/modules/core/include/visp3/core/vpBSpline.h index 7e7703ded8..d5e4110be8 100644 --- a/modules/core/include/visp3/core/vpBSpline.h +++ b/modules/core/include/visp3/core/vpBSpline.h @@ -107,13 +107,13 @@ typedef struct vpBasisFunction class VISP_EXPORT vpBSpline { public /*protected*/: -//! Vector wich contains the control points +//! Vector which contains the control points std::vector controlPoints; //! Vector which contain the knots \f$ {u0, ..., um} \f$ std::vector knots; //! Degree of the B-Spline basis functions. unsigned int p; - //! Vector wich contains the points used during the interpolation method. + //! Vector which contains the points used during the interpolation method. std::vector crossingPoints; public: diff --git a/modules/core/include/visp3/core/vpMomentBasic.h b/modules/core/include/visp3/core/vpMomentBasic.h index ffa7488ac4..b34ca9c47b 100644 --- a/modules/core/include/visp3/core/vpMomentBasic.h +++ b/modules/core/include/visp3/core/vpMomentBasic.h @@ -50,7 +50,7 @@ BEGIN_VISP_NAMESPACE \ingroup group_core_moments \brief This class defines the 2D basic moment \f$m_{ij}\f$. - This class is a wrapper for vpMomentObject wich allows to use it as a + This class is a wrapper for vpMomentObject which allows to use it as a moment. This enables all common operations such as adding to a vpMomentDatabase. diff --git a/modules/core/src/image/vpImagePoint.cpp b/modules/core/src/image/vpImagePoint.cpp index fbe1ab21f9..3dc00cb3f5 100644 --- a/modules/core/src/image/vpImagePoint.cpp +++ b/modules/core/src/image/vpImagePoint.cpp @@ -165,7 +165,7 @@ VISP_EXPORT bool operator!=(const vpImagePoint &ip1, const vpImagePoint &ip2) /*! \relates vpImagePoint - Returns a vpImagePoint wich is the sum of \f$ ip1 \f$ and \f$ ip2 \f$. + Returns a vpImagePoint which is the sum of \f$ ip1 \f$ and \f$ ip2 \f$. */ VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint &ip2) { @@ -175,7 +175,7 @@ VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint & /*! \relates vpImagePoint - Returns a vpImagePoint wich is the sum of \f$ ip1 \f$ and \f$ ip2 \f$. + Returns a vpImagePoint which is the sum of \f$ ip1 \f$ and \f$ ip2 \f$. */ VISP_EXPORT vpImagePoint operator+=(const vpImagePoint &ip1, const vpImagePoint &ip2) { @@ -269,7 +269,7 @@ VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, double offset) /*! \relates vpImagePoint - Returns a vpImagePoint wich is the difference between \f$ ip1 \f$ and \f$ + Returns a vpImagePoint which is the difference between \f$ ip1 \f$ and \f$ ip2 \f$. */ VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2) diff --git a/modules/core/src/math/kalman/vpLinearKalmanFilterInstantiation.cpp b/modules/core/src/math/kalman/vpLinearKalmanFilterInstantiation.cpp index 3ba551556a..6dca5121fe 100644 --- a/modules/core/src/math/kalman/vpLinearKalmanFilterInstantiation.cpp +++ b/modules/core/src/math/kalman/vpLinearKalmanFilterInstantiation.cpp @@ -80,7 +80,7 @@ BEGIN_VISP_NAMESPACE vpLinearKalmanFilterInstantiation::stateConstVelWithColoredNoise_MeasureVel model implemented in initStateConstVelWithColoredNoise_MeasureVel(). - \exception vpException::badValue : Bad rho value wich is not in [0:1[. + \exception vpException::badValue : Bad rho value which is not in [0:1[. \exception vpException::notInitialized : If the state model is not initialized. To initialize it you need to call setStateModel(). @@ -448,7 +448,7 @@ by the number of signal to filter. \param rho : Degree of correlation between successive accelerations. Values are in [0:1[. - \exception vpException::badValue : Bad rho value wich is not in [0:1[. + \exception vpException::badValue : Bad rho value which is not in [0:1[. The example below shows how to filter a two dimensional target trajectory with an estimation of the target velocity from velocity @@ -667,7 +667,7 @@ mutually uncorrelated stationary random variables with variance \param delta_t : Sampling time \f$\Delta t\f$ expressed is second. - \exception vpException::badValue : Bad rho value wich is not in [0:1[. + \exception vpException::badValue : Bad rho value which is not in [0:1[. The example below shows how to filter a two dimensional target trajectory with an estimation of the target velocity from velocity @@ -831,7 +831,7 @@ void vpLinearKalmanFilterInstantiation::filter(vpColVector &z) else if (iter == 1) { if (model == stateConstVel_MeasurePos) { for (unsigned int i = 0; i < size_measure * nsignal; i++) { - double z_prev = Xest[size_state * i]; // Previous mesured position + double z_prev = Xest[size_state * i]; // Previous measured position Xest[size_state * i] = z[i]; Xest[size_state * i + 1] = (z[i] - z_prev) / dt; } diff --git a/modules/robot/include/visp3/robot/vpRobotAfma6.h b/modules/robot/include/visp3/robot/vpRobotAfma6.h index 22eadd4c7b..70f836786f 100644 --- a/modules/robot/include/visp3/robot/vpRobotAfma6.h +++ b/modules/robot/include/visp3/robot/vpRobotAfma6.h @@ -121,7 +121,7 @@ BEGIN_VISP_NAMESPACE robot with: \code - // Set the extrinsic camera parameters obtained with a perpective + // Set the extrinsic camera parameters obtained with a perspective // projection model including a distortion parameter robot.init(vpAfma6::TOOL_CCMOP, vpCameraParameters::perspectiveProjWithDistortion); \endcode diff --git a/modules/robot/include/visp3/robot/vpRobotViper650.h b/modules/robot/include/visp3/robot/vpRobotViper650.h index e4f0a3c563..1cb6d96c8b 100644 --- a/modules/robot/include/visp3/robot/vpRobotViper650.h +++ b/modules/robot/include/visp3/robot/vpRobotViper650.h @@ -168,7 +168,7 @@ BEGIN_VISP_NAMESPACE #ifdef VISP_HAVE_VIPER650 vpRobotViper650 robot; - // Set the extrinsic camera parameters obtained with a perpective + // Set the extrinsic camera parameters obtained with a perspective // projection model including a distortion parameter robot.init(vpViper650::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); diff --git a/modules/robot/include/visp3/robot/vpRobotViper850.h b/modules/robot/include/visp3/robot/vpRobotViper850.h index 561e85ca7d..2953c140a4 100644 --- a/modules/robot/include/visp3/robot/vpRobotViper850.h +++ b/modules/robot/include/visp3/robot/vpRobotViper850.h @@ -171,7 +171,7 @@ BEGIN_VISP_NAMESPACE #ifdef VISP_HAVE_VIPER850 vpRobotViper850 robot; - // Set the extrinsic camera parameters obtained with a perpective + // Set the extrinsic camera parameters obtained with a perspective // projection model including a distortion parameter robot.init(vpViper850::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); #endif diff --git a/modules/robot/src/real-robot/afma4/vpRobotAfma4.cpp b/modules/robot/src/real-robot/afma4/vpRobotAfma4.cpp index 700c2edb51..908c7fe7e7 100644 --- a/modules/robot/src/real-robot/afma4/vpRobotAfma4.cpp +++ b/modules/robot/src/real-robot/afma4/vpRobotAfma4.cpp @@ -943,14 +943,14 @@ double vpRobotAfma4::getTime() const Get the current position of the robot. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param position : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, a 4 dimension vector corresponding to the joint position of each dof. position[0] @@ -1279,7 +1279,7 @@ void vpRobotAfma4::setVelocity(const vpRobot::vpControlFrameType frame, const vp Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param velocity : Measured velocities. Translations are expressed in m/s and rotations in rad/s. @@ -1439,7 +1439,7 @@ void vpRobotAfma4::getVelocity(const vpRobot::vpControlFrameType frame, vpColVec Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param timestamp : Time in second since last robot power on. diff --git a/modules/robot/src/real-robot/afma6/vpAfma6.cpp b/modules/robot/src/real-robot/afma6/vpAfma6.cpp index 34dd820319..03bcdc0fea 100644 --- a/modules/robot/src/real-robot/afma6/vpAfma6.cpp +++ b/modules/robot/src/real-robot/afma6/vpAfma6.cpp @@ -1210,7 +1210,7 @@ void vpAfma6::set_eMc(const vpHomogeneousMatrix &eMc) vpAfma6::CONST_CAMERA_AFMA6_FILENAME and containing the camera parameters. - \warning Thid method needs also an access to the files containing the + \warning Third method needs also an access to the files containing the camera parameters in XML format. This access is available if VISP_HAVE_AFMA6_DATA macro is defined in include/visp3/core/vpConfig.h file. diff --git a/modules/robot/src/real-robot/afma6/vpRobotAfma6.cpp b/modules/robot/src/real-robot/afma6/vpRobotAfma6.cpp index 0e9ad96c86..7c105910ed 100644 --- a/modules/robot/src/real-robot/afma6/vpRobotAfma6.cpp +++ b/modules/robot/src/real-robot/afma6/vpRobotAfma6.cpp @@ -135,7 +135,7 @@ void emergencyStopAfma6(int signo) \code vpRobotAfma6 robot; - // Set the extrinsic camera parameters obtained with a perpective + // Set the extrinsic camera parameters obtained with a perspective // projection model including a distortion parameter robot.init(vpAfma6::TOOL_CCMOP, vpCameraParameters::perspectiveProjWithDistortion); \endcode @@ -326,7 +326,7 @@ void vpRobotAfma6::init(void) \code vpRobotAfma6 robot; - // Set the extrinsic camera parameters obtained with a perpective + // Set the extrinsic camera parameters obtained with a perspective // projection model including a distortion parameter robot.init(vpAfma6::TOOL_CCMOP, vpCameraParameters::perspectiveProjWithDistortion); \endcode @@ -1398,14 +1398,14 @@ void vpRobotAfma6::setPosition(const std::string &filename) Get the current position of the robot. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param position : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, a 6 dimension vector corresponding to the articular position of each dof, first the 3 translations, then the 3 @@ -1732,7 +1732,7 @@ void vpRobotAfma6::setVelocity(const vpRobot::vpControlFrameType frame, const vp Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param velocity : Measured velocities. Translations are expressed in m/s and rotations in rad/s. @@ -1898,7 +1898,7 @@ void vpRobotAfma6::getVelocity(const vpRobot::vpControlFrameType frame, vpColVec Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param timestamp : Time in second since last robot power on. diff --git a/modules/robot/src/real-robot/viper/vpRobotViper650.cpp b/modules/robot/src/real-robot/viper/vpRobotViper650.cpp index 97963c103e..e478d30b04 100644 --- a/modules/robot/src/real-robot/viper/vpRobotViper650.cpp +++ b/modules/robot/src/real-robot/viper/vpRobotViper650.cpp @@ -147,7 +147,7 @@ void emergencyStopViper650(int signo) #ifdef VISP_HAVE_VIPER650 vpRobotViper650 robot; - // Set the extrinsic camera parameters obtained with a perpective + // Set the extrinsic camera parameters obtained with a perspective // projection model including a distortion parameter robot.init(vpViper650::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); @@ -382,7 +382,7 @@ void vpRobotViper650::init(void) #ifdef VISP_HAVE_VIPER650 vpRobotViper650 robot; - // Set the extrinsic camera parameters obtained with a perpective + // Set the extrinsic camera parameters obtained with a perspective // projection model including a distortion parameter robot.init(vpViper650::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); \endcode @@ -1406,14 +1406,14 @@ void vpRobotViper650::setPosition(const std::string &filename) Get the current position of the robot. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param position : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, a 6 dimension vector corresponding to the joint position of each dof in radians. @@ -1811,7 +1811,7 @@ void vpRobotViper650::setVelocity(const vpRobot::vpControlFrameType frame, const Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param velocity : Measured velocities. Translations are expressed in m/s and rotations in rad/s. @@ -1999,7 +1999,7 @@ void vpRobotViper650::getVelocity(const vpRobot::vpControlFrameType frame, vpCol Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param timestamp : Time in second since last robot power on. diff --git a/modules/robot/src/real-robot/viper/vpRobotViper850.cpp b/modules/robot/src/real-robot/viper/vpRobotViper850.cpp index 57827c3e2e..05e32a6983 100644 --- a/modules/robot/src/real-robot/viper/vpRobotViper850.cpp +++ b/modules/robot/src/real-robot/viper/vpRobotViper850.cpp @@ -147,7 +147,7 @@ void emergencyStopViper850(int signo) #ifdef VISP_HAVE_VIPER850 vpRobotViper850 robot; - // Set the extrinsic camera parameters obtained with a perpective + // Set the extrinsic camera parameters obtained with a perspective // projection model including a distortion parameter robot.init(vpViper850::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); \endcode @@ -398,7 +398,7 @@ void vpRobotViper850::init(void) #ifdef VISP_HAVE_VIPER850 vpRobotViper850 robot; - // Set the extrinsic camera parameters obtained with a perpective + // Set the extrinsic camera parameters obtained with a perspective // projection model including a distortion parameter robot.init(vpViper850::TOOL_MARLIN_F033C_CAMERA, vpCameraParameters::perspectiveProjWithDistortion); \endcode @@ -1425,10 +1425,10 @@ void vpRobotViper850::setPosition(const std::string &filename) Get the current position of the robot. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param position : Measured position of the robot: @@ -1842,7 +1842,7 @@ void vpRobotViper850::setVelocity(const vpRobot::vpControlFrameType frame, const Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param velocity : Measured velocities. Translations are expressed in m/s and rotations in rad/s. @@ -2030,7 +2030,7 @@ void vpRobotViper850::getVelocity(const vpRobot::vpControlFrameType frame, vpCol Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param timestamp : Time in second since last robot power on. diff --git a/modules/robot/src/real-robot/viper/vpViper650.cpp b/modules/robot/src/real-robot/viper/vpViper650.cpp index 7289bfd7de..fe3b27073a 100644 --- a/modules/robot/src/real-robot/viper/vpViper650.cpp +++ b/modules/robot/src/real-robot/viper/vpViper650.cpp @@ -490,7 +490,7 @@ void vpViper650::parseConfigFile(const std::string &filename) vpViper650::CONST_CAMERA_FILENAME and containing the camera parameters. - \warning Thid method needs also an access to the files containing the + \warning Third method needs also an access to the files containing the camera parameters in XML format. This access is available if VISP_HAVE_VIPER650_DATA macro is defined in include/visp3/core/vpConfig.h file. @@ -711,7 +711,7 @@ void vpViper650::getCameraParameters(vpCameraParameters &cam, const unsigned int vpViper650::CONST_CAMERA_FILENAME and containing the camera parameters. - \warning Thid method needs also an access to the files containing the + \warning Third method needs also an access to the files containing the camera parameters in XML format. This access is available if VISP_HAVE_VIPER650_DATA macro is defined in include/visp3/core/vpConfig.h file. @@ -779,7 +779,7 @@ void vpViper650::getCameraParameters(vpCameraParameters &cam, const vpImagecM Get the current position of the robot. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference frame, and rotation in + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param position : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, a 6 dimension vector corresponding to the articular position of each dof, first the 3 translations, then the 3 diff --git a/modules/robot/src/robot-simulator/vpSimulatorAfma6.cpp b/modules/robot/src/robot-simulator/vpSimulatorAfma6.cpp index a1858c6858..7d42558b0a 100644 --- a/modules/robot/src/robot-simulator/vpSimulatorAfma6.cpp +++ b/modules/robot/src/robot-simulator/vpSimulatorAfma6.cpp @@ -1017,7 +1017,7 @@ void vpSimulatorAfma6::computeArticularVelocity() /*! Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param vel : Measured velocities. Translations are expressed in m/s and rotations in rad/s. @@ -1103,7 +1103,7 @@ void vpSimulatorAfma6::getVelocity(const vpRobot::vpControlFrameType frame, vpCo /*! Get the robot time stamped velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param vel : Measured velocities. Translations are expressed in m/s and rotations in rad/s. @@ -1178,7 +1178,7 @@ vpColVector vpSimulatorAfma6::getVelocity(vpRobot::vpControlFrameType frame) /*! Get the time stamped robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param timestamp : Unix time in second since January 1st 1970. @@ -1566,14 +1566,14 @@ void vpSimulatorAfma6::setPosition(const char *filename) Get the current position of the robot. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param q : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, a 6 dimension vector corresponding to the joint position of each dof in radians. @@ -1673,14 +1673,14 @@ void vpSimulatorAfma6::getPosition(const vpRobot::vpControlFrameType frame, vpCo Get the current time stamped position of the robot. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param q : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, a 6 dimension vector corresponding to the joint position of each dof in radians. diff --git a/modules/robot/src/robot-simulator/vpSimulatorCamera.cpp b/modules/robot/src/robot-simulator/vpSimulatorCamera.cpp index f5686f11ec..f81df30a56 100644 --- a/modules/robot/src/robot-simulator/vpSimulatorCamera.cpp +++ b/modules/robot/src/robot-simulator/vpSimulatorCamera.cpp @@ -114,14 +114,14 @@ vpHomogeneousMatrix vpSimulatorCamera::getPosition() const { return (this->wMc_) Get the current position of the camera. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference frame, and rotation in + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param position : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, a 6 dimension vector corresponding to the articular position of each dof, first the 3 translations, then the 3 diff --git a/modules/robot/src/robot-simulator/vpSimulatorPioneer.cpp b/modules/robot/src/robot-simulator/vpSimulatorPioneer.cpp index d9ea150f3e..6f08e3b330 100644 --- a/modules/robot/src/robot-simulator/vpSimulatorPioneer.cpp +++ b/modules/robot/src/robot-simulator/vpSimulatorPioneer.cpp @@ -165,14 +165,14 @@ void vpSimulatorPioneer::getPosition(vpHomogeneousMatrix &wMc) const { wMc = thi Get the current position of the robot. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes (not implemented) - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference frame, and rotation in + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param position : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, this functionality is not implemented. diff --git a/modules/robot/src/robot-simulator/vpSimulatorPioneerPan.cpp b/modules/robot/src/robot-simulator/vpSimulatorPioneerPan.cpp index 9afb713811..a51ff81308 100644 --- a/modules/robot/src/robot-simulator/vpSimulatorPioneerPan.cpp +++ b/modules/robot/src/robot-simulator/vpSimulatorPioneerPan.cpp @@ -180,14 +180,14 @@ void vpSimulatorPioneerPan::getPosition(vpHomogeneousMatrix &wMc) const { wMc = Get the current position of the robot. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes (not implemented) - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference frame, and rotation in + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param position : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, this functionality is not implemented. diff --git a/modules/robot/src/robot-simulator/vpSimulatorViper850.cpp b/modules/robot/src/robot-simulator/vpSimulatorViper850.cpp index b18fc71ca3..d085f9f45e 100644 --- a/modules/robot/src/robot-simulator/vpSimulatorViper850.cpp +++ b/modules/robot/src/robot-simulator/vpSimulatorViper850.cpp @@ -950,7 +950,7 @@ void vpSimulatorViper850::computeArticularVelocity() /*! Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param vel : Measured velocities. Translations are expressed in m/s and rotations in rad/s. @@ -1036,7 +1036,7 @@ void vpSimulatorViper850::getVelocity(const vpRobot::vpControlFrameType frame, v /*! Get the robot time stamped velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param vel : Measured velocities. Translations are expressed in m/s and rotations in rad/s. @@ -1058,7 +1058,7 @@ void vpSimulatorViper850::getVelocity(const vpRobot::vpControlFrameType frame, v /*! Get the robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \return Measured velocities. Translations are expressed in m/s and rotations in rad/s. @@ -1111,7 +1111,7 @@ vpColVector vpSimulatorViper850::getVelocity(vpRobot::vpControlFrameType frame) /*! Get the time stamped robot velocities. - \param frame : Frame in wich velocities are mesured. + \param frame : Frame in which velocities are measured. \param timestamp : Unix time in second since January 1st 1970. @@ -1495,14 +1495,14 @@ void vpSimulatorViper850::setPosition(const char *filename) Get the current position of the robot. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param q : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, a 6 dimension vector corresponding to the joint position of each dof in radians. @@ -1604,14 +1604,14 @@ void vpSimulatorViper850::getPosition(const vpRobot::vpControlFrameType frame, v Get the current time stamped position of the robot. \param frame : Control frame type in which to get the position, either : - - in the camera cartesien frame, + - in the camera cartesian frame, - joint (articular) coordinates of each axes - - in a reference or fixed cartesien frame attached to the robot base - - in a mixt cartesien frame (translation in reference + - in a reference or fixed cartesian frame attached to the robot base + - in a mixt cartesian frame (translation in reference frame, and rotation in camera frame) \param q : Measured position of the robot: - - in camera cartesien frame, a 6 dimension vector, set to 0. + - in camera cartesian frame, a 6 dimension vector, set to 0. - in articular, a 6 dimension vector corresponding to the joint position of each dof in radians. diff --git a/modules/robot/test/virtuose/testVirtuoseAfma6.cpp b/modules/robot/test/virtuose/testVirtuoseAfma6.cpp index 81371e67e1..971017ccdd 100644 --- a/modules/robot/test/virtuose/testVirtuoseAfma6.cpp +++ b/modules/robot/test/virtuose/testVirtuoseAfma6.cpp @@ -76,7 +76,7 @@ int main() std::cout << "rMv:\n" << rMv << std::endl; vpVelocityTwistMatrix rVv(rMv); - // Set the extrinsic camera parameters obtained with a perpective + // Set the extrinsic camera parameters obtained with a perspective // projection model including a distortion parameter robot.init(vpAfma6::TOOL_CCMOP, vpCameraParameters::perspectiveProjWithDistortion); // Initialize the controller to position control diff --git a/modules/sensor/src/framegrabber/1394/vp1394TwoGrabber.cpp b/modules/sensor/src/framegrabber/1394/vp1394TwoGrabber.cpp index 795019d23d..0699a3ec06 100644 --- a/modules/sensor/src/framegrabber/1394/vp1394TwoGrabber.cpp +++ b/modules/sensor/src/framegrabber/1394/vp1394TwoGrabber.cpp @@ -2137,7 +2137,7 @@ void vp1394TwoGrabber::open(vpImage &I) /*! - Get an image from the active camera frame buffer. This buffer neads to be + Get an image from the active camera frame buffer. This buffer needs to be released by enqueue(). \return Pointer to the libdc1394-2.x image data structure. @@ -2196,7 +2196,7 @@ dc1394video_frame_t *vp1394TwoGrabber::dequeue() /*! - Get an image from the active camera frame buffer. This buffer neads to be + Get an image from the active camera frame buffer. This buffer needs to be released by enqueue(). \param I : Image data structure (8 bits image). @@ -2252,7 +2252,7 @@ dc1394video_frame_t *vp1394TwoGrabber::dequeue(vpImage &I) /*! - Get an image from the active camera frame buffer. This buffer neads to be + Get an image from the active camera frame buffer. This buffer needs to be released by enqueue(). \param I : Image data structure (8 bits image). @@ -2415,7 +2415,7 @@ dc1394video_frame_t *vp1394TwoGrabber::dequeue(vpImage &I) /*! - Get an image from the active camera frame buffer. This buffer neads to be + Get an image from the active camera frame buffer. This buffer needs to be released by enqueue(). \param I : Image data structure (32 bits RGBa image). From c78dfca0766d4943990b95a978b6efc32c77588d Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 25 Jun 2024 17:05:33 +0200 Subject: [PATCH 10/11] Use new macro VP_DEPRECATED and VP_OVERRIDE --- .../visp3/ar/vpPanda3DGeometryRenderer.h | 2 +- modules/ar/include/visp3/ar/vpPanda3DLight.h | 8 ++++---- .../visp3/ar/vpPanda3DPostProcessFilter.h | 4 ++-- .../include/visp3/ar/vpPanda3DRGBRenderer.h | 2 +- .../include/visp3/ar/vpPanda3DRendererSet.h | 4 ++-- .../bindings/include/visual_features.hpp | 14 ++++++------- .../visp_python_bindgen/doc_parser.py | 2 +- .../visp_python_bindgen/generator_config.py | 2 +- .../robot/include/visp3/robot/vpRobotCamera.h | 6 +++--- .../robot/include/visp3/robot/vpRobotFranka.h | 2 +- .../include/visp3/robot/vpRobotPioneer.h | 6 +++--- .../include/visp3/robot/vpRobotPololuPtu.h | 4 ++-- .../visp3/robot/vpRobotUniversalRobots.h | 6 +++--- .../include/visp3/robot/vpSimulatorAfma6.h | 2 +- .../include/visp3/robot/vpSimulatorCamera.h | 6 +++--- .../include/visp3/robot/vpSimulatorPioneer.h | 6 +++--- .../visp3/robot/vpSimulatorPioneerPan.h | 6 +++--- .../include/visp3/robot/vpSimulatorViper850.h | 2 +- .../visp3/sensor/vpOccipitalStructure.h | 4 ++-- .../include/visp3/mbt/vpMbDepthDenseTracker.h | 4 ++-- .../visp3/mbt/vpMbDepthNormalTracker.h | 4 ++-- .../include/visp3/mbt/vpMbEdgeKltTracker.h | 20 +++++++++---------- .../mbt/include/visp3/mbt/vpMbEdgeTracker.h | 10 +++++----- .../include/visp3/mbt/vpMbGenericTracker.h | 8 ++++---- .../mbt/include/visp3/mbt/vpMbKltTracker.h | 10 +++++----- .../include/visp3/vision/vpPoseFeatures.h | 20 +++++++++---------- .../vpFeatureLuminanceMapping.h | 4 ++-- .../visual_features/vpFeatureMomentAlpha.h | 4 ++-- .../visual_features/vpFeatureMomentArea.h | 4 ++-- .../vpFeatureMomentAreaNormalized.h | 8 ++++---- .../visual_features/vpFeatureMomentBasic.h | 6 +++--- .../vpFeatureMomentCInvariant.h | 8 ++++---- .../visual_features/vpFeatureMomentCentered.h | 6 +++--- .../vpFeatureMomentGravityCenter.h | 8 ++++---- .../vpFeatureMomentGravityCenterNormalized.h | 8 ++++---- 35 files changed, 110 insertions(+), 110 deletions(-) diff --git a/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h b/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h index e5eff88826..b043145960 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h +++ b/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h @@ -82,7 +82,7 @@ class VISP_EXPORT vpPanda3DGeometryRenderer : public vpPanda3DBaseRenderer */ void getRender(vpImage &depth) const; - GraphicsOutput *getMainOutputBuffer() vp_override { return m_normalDepthBuffer; } + GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return m_normalDepthBuffer; } protected: void setupScene() VP_OVERRIDE; diff --git a/modules/ar/include/visp3/ar/vpPanda3DLight.h b/modules/ar/include/visp3/ar/vpPanda3DLight.h index f225a29390..0e5fa38e8f 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DLight.h +++ b/modules/ar/include/visp3/ar/vpPanda3DLight.h @@ -111,7 +111,7 @@ class VISP_EXPORT vpPanda3DAmbientLight : public vpPanda3DLight public: vpPanda3DAmbientLight(const std::string &name, const vpRGBf &color) : vpPanda3DLight(name, color) { } - void addToScene(NodePath &scene) const vp_override + void addToScene(NodePath &scene) const VP_OVERRIDE { PT(AmbientLight) light = new AmbientLight(m_name); light->set_color(LColor(m_color.R, m_color.G, m_color.B, 1)); @@ -159,7 +159,7 @@ class VISP_EXPORT vpPanda3DPointLight : public vpPanda3DLight } } - void addToScene(NodePath &scene) const vp_override + void addToScene(NodePath &scene) const VP_OVERRIDE { PT(PointLight) light = new PointLight(m_name); light->set_color(LColor(m_color.R, m_color.G, m_color.B, 1)); @@ -204,7 +204,7 @@ class VISP_EXPORT vpPanda3DDirectionalLight : public vpPanda3DLight m_direction.normalize(); } - void addToScene(NodePath &scene) const vp_override + void addToScene(NodePath &scene) const VP_OVERRIDE { PT(DirectionalLight) light = new DirectionalLight(m_name); light->set_color(LColor(m_color.R, m_color.G, m_color.B, 1)); @@ -256,7 +256,7 @@ class VISP_EXPORT vpPanda3DLightableScene : public vpPanda3DLightable * \throws if the scene is not setup (setLightableScene or constructor with NodePath has not been called) * \param light light to add */ - void addLight(const vpPanda3DLight &light) vp_override + void addLight(const vpPanda3DLight &light) VP_OVERRIDE { if (m_lightableScene.is_empty()) { throw vpException(vpException::notInitialized, "Tried to add a light to a scene that is not initialized."); diff --git a/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h b/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h index bac794e6cc..2304919ef6 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h +++ b/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h @@ -62,12 +62,12 @@ class VISP_EXPORT vpPanda3DPostProcessFilter : public vpPanda3DBaseRenderer m_renderOrder = m_inputRenderer->getRenderOrder() + 1; } - bool isRendering3DScene() const vp_override + bool isRendering3DScene() const VP_OVERRIDE { return false; } - GraphicsOutput *getMainOutputBuffer() vp_override { return m_buffer; } + GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return m_buffer; } protected: virtual void setupScene() VP_OVERRIDE; diff --git a/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h b/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h index 38d862ca81..25a3d6ce20 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h +++ b/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h @@ -92,7 +92,7 @@ class VISP_EXPORT vpPanda3DRGBRenderer : public vpPanda3DBaseRenderer, public vp void setBackgroundImage(const vpImage &background); - GraphicsOutput *getMainOutputBuffer() vp_override { return m_colorBuffer; } + GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return m_colorBuffer; } bool isShowingSpeculars() const { return m_showSpeculars; } diff --git a/modules/ar/include/visp3/ar/vpPanda3DRendererSet.h b/modules/ar/include/visp3/ar/vpPanda3DRendererSet.h index d0eea9dd2f..9c0bded81e 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DRendererSet.h +++ b/modules/ar/include/visp3/ar/vpPanda3DRendererSet.h @@ -186,9 +186,9 @@ class VISP_EXPORT vpPanda3DRendererSet : public vpPanda3DBaseRenderer, public vp } protected: - void setupScene() vp_override { } + void setupScene() VP_OVERRIDE { } - void setupCamera() vp_override { } + void setupCamera() VP_OVERRIDE { } private: std::vector> m_subRenderers; diff --git a/modules/python/bindings/include/visual_features.hpp b/modules/python/bindings/include/visual_features.hpp index f1a46a4f41..405c317e03 100644 --- a/modules/python/bindings/include/visual_features.hpp +++ b/modules/python/bindings/include/visual_features.hpp @@ -49,7 +49,7 @@ class TrampolineBasicFeature : public vpBasicFeature virtual void display(const vpCameraParameters &cam, const vpImage &I, - const vpColor &color = vpColor::green, unsigned int thickness = 1) const vp_override + const vpColor &color = vpColor::green, unsigned int thickness = 1) const VP_OVERRIDE { PYBIND11_OVERRIDE_PURE( void, /* Return type */ @@ -59,7 +59,7 @@ class TrampolineBasicFeature : public vpBasicFeature ); } virtual void display(const vpCameraParameters &cam, const vpImage &I, const vpColor &color = vpColor::green, - unsigned int thickness = 1) const vp_override + unsigned int thickness = 1) const VP_OVERRIDE { PYBIND11_OVERRIDE_PURE( void, /* Return type */ @@ -69,7 +69,7 @@ class TrampolineBasicFeature : public vpBasicFeature ); } - virtual void init() vp_override + virtual void init() VP_OVERRIDE { PYBIND11_OVERRIDE_PURE( void, /* Return type */ @@ -78,7 +78,7 @@ class TrampolineBasicFeature : public vpBasicFeature ); } - virtual vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override + virtual vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE { PYBIND11_OVERRIDE( vpColVector, /* Return type */ @@ -90,7 +90,7 @@ class TrampolineBasicFeature : public vpBasicFeature } - virtual vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override + virtual vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE { PYBIND11_OVERRIDE_PURE( vpMatrix, /* Return type */ @@ -99,7 +99,7 @@ class TrampolineBasicFeature : public vpBasicFeature select /* Argument(s) */ ); } - virtual void print(unsigned int select = FEATURE_ALL) const vp_override + virtual void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE { PYBIND11_OVERRIDE_PURE( void, /* Return type */ @@ -109,7 +109,7 @@ class TrampolineBasicFeature : public vpBasicFeature ); } - virtual vpBasicFeature *duplicate() const vp_override + virtual vpBasicFeature *duplicate() const VP_OVERRIDE { PYBIND11_OVERRIDE_PURE( vpBasicFeature *, /* Return type */ diff --git a/modules/python/generator/visp_python_bindgen/doc_parser.py b/modules/python/generator/visp_python_bindgen/doc_parser.py index ccae166814..0fcfd15a0b 100644 --- a/modules/python/generator/visp_python_bindgen/doc_parser.py +++ b/modules/python/generator/visp_python_bindgen/doc_parser.py @@ -335,7 +335,7 @@ def __init__(self, path: Optional[Path], env_mapping: Dict[str, str]): for method_def in method_defs: is_const = False if method_def.const == 'no' else True is_static = False if method_def.static == 'no' else True - ret_type = ''.join(process_mixed_container(c, 0, escape_rst=False) for c in method_def.type_.content_).replace('vp_deprecated', '').replace('VISP_EXPORT', '') + ret_type = ''.join(process_mixed_container(c, 0, escape_rst=False) for c in method_def.type_.content_).replace('VP_DEPRECATED', '').replace('VISP_EXPORT', '') param_types = [] for param in method_def.get_param(): t = ''.join(process_mixed_container(c, 0, escape_rst=False) for c in param.type_.content_) diff --git a/modules/python/generator/visp_python_bindgen/generator_config.py b/modules/python/generator/visp_python_bindgen/generator_config.py index b82551b65e..8e9ab1e4b5 100644 --- a/modules/python/generator/visp_python_bindgen/generator_config.py +++ b/modules/python/generator/visp_python_bindgen/generator_config.py @@ -116,7 +116,7 @@ class GeneratorConfig(object): pcpp_config: Final[PreprocessorConfig] = PreprocessorConfig( defines={ 'VISP_EXPORT': '', # remove symbol as it messes up the cxxheaderparsing - 'vp_deprecated': '', # remove symbol as it messes up the cxxheaderparsing + 'VP_DEPRECATED': '', # remove symbol as it messes up the cxxheaderparsing 'DOXYGEN_SHOULD_SKIP_THIS': None, # Do not generate methods that do not appear in public api doc 'NLOHMANN_JSON_SERIALIZE_ENUM(a,...)': 'void ignored() {}', # Remove json enum serialization as it cnanot correctly be parsed 'CV_OUT': '', # In vpKeyPoint, this appears and breaks parsing diff --git a/modules/robot/include/visp3/robot/vpRobotCamera.h b/modules/robot/include/visp3/robot/vpRobotCamera.h index 15f2c81976..3605b88358 100644 --- a/modules/robot/include/visp3/robot/vpRobotCamera.h +++ b/modules/robot/include/visp3/robot/vpRobotCamera.h @@ -133,9 +133,9 @@ class VISP_EXPORT vpRobotCamera : public vpRobotSimulator void init() VP_OVERRIDE; // Non implemented virtual pure functions - void get_fJe(vpMatrix & /*_fJe */) vp_override { }; - void getDisplacement(const vpRobot::vpControlFrameType /* frame */, vpColVector & /* q */) vp_override { }; - void setPosition(const vpRobot::vpControlFrameType /* frame */, const vpColVector & /* q */) vp_override { }; + void get_fJe(vpMatrix & /*_fJe */) VP_OVERRIDE { }; + void getDisplacement(const vpRobot::vpControlFrameType /* frame */, vpColVector & /* q */) VP_OVERRIDE { }; + void setPosition(const vpRobot::vpControlFrameType /* frame */, const vpColVector & /* q */) VP_OVERRIDE { }; }; END_VISP_NAMESPACE #endif diff --git a/modules/robot/include/visp3/robot/vpRobotFranka.h b/modules/robot/include/visp3/robot/vpRobotFranka.h index 6a9f2b4c9e..a440313e1a 100644 --- a/modules/robot/include/visp3/robot/vpRobotFranka.h +++ b/modules/robot/include/visp3/robot/vpRobotFranka.h @@ -229,7 +229,7 @@ class VISP_EXPORT vpRobotFranka : public vpRobot /*! * This function is not implemented. */ - void getDisplacement(const vpRobot::vpControlFrameType, vpColVector &) vp_override { }; + void getDisplacement(const vpRobot::vpControlFrameType, vpColVector &) VP_OVERRIDE { }; void init(); diff --git a/modules/robot/include/visp3/robot/vpRobotPioneer.h b/modules/robot/include/visp3/robot/vpRobotPioneer.h index f9a8a83123..5777fd7f1b 100644 --- a/modules/robot/include/visp3/robot/vpRobotPioneer.h +++ b/modules/robot/include/visp3/robot/vpRobotPioneer.h @@ -83,14 +83,14 @@ class VISP_EXPORT vpRobotPioneer : public vpRobot, public vpPioneer, public ArRo * * \sa get_eJe() */ - void get_eJe(vpMatrix &eJe) vp_override { eJe = vpUnicycle::get_eJe(); } + void get_eJe(vpMatrix &eJe) VP_OVERRIDE { eJe = vpUnicycle::get_eJe(); } private: // Set as private since not implemented /*! * Get the robot Jacobian expressed in the robot reference (or world) frame. * \warning Not implemented. */ - void get_fJe(vpMatrix & /*fJe*/) vp_override { }; + void get_fJe(vpMatrix & /*fJe*/) VP_OVERRIDE { }; /*! * Get a displacement (frame as to ve specified) between two successive @@ -118,7 +118,7 @@ class VISP_EXPORT vpRobotPioneer : public vpRobot, public vpPioneer, public ArRo * Set a displacement (frame has to be specified) in position control. * \warning Not implemented. */ - void setPosition(const vpRobot::vpControlFrameType /*frame*/, const vpColVector & /*q*/) vp_override { }; + void setPosition(const vpRobot::vpControlFrameType /*frame*/, const vpColVector & /*q*/) VP_OVERRIDE { }; public: void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE; diff --git a/modules/robot/include/visp3/robot/vpRobotPololuPtu.h b/modules/robot/include/visp3/robot/vpRobotPololuPtu.h index 936cb11ee4..37b5d0c43f 100644 --- a/modules/robot/include/visp3/robot/vpRobotPololuPtu.h +++ b/modules/robot/include/visp3/robot/vpRobotPololuPtu.h @@ -234,7 +234,7 @@ class VISP_EXPORT vpRobotPololuPtu : public vpRobot * \exception vpRobotException::constructionError If the config file cannot be * opened. */ - void init() vp_override { }; + void init() VP_OVERRIDE { }; /*! * Get the robot displacement since the last call of this method. @@ -256,7 +256,7 @@ class VISP_EXPORT vpRobotPololuPtu : public vpRobot * \exception vpRobotException::wrongStateError If a not supported frame type * is given. */ - void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &d) vp_override + void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &d) VP_OVERRIDE { (void)frame; (void)d; diff --git a/modules/robot/include/visp3/robot/vpRobotUniversalRobots.h b/modules/robot/include/visp3/robot/vpRobotUniversalRobots.h index 4985fa432a..ceeb0c6fe8 100644 --- a/modules/robot/include/visp3/robot/vpRobotUniversalRobots.h +++ b/modules/robot/include/visp3/robot/vpRobotUniversalRobots.h @@ -119,9 +119,9 @@ class VISP_EXPORT vpRobotUniversalRobots : public vpRobot private: // Not implemented yet - void get_eJe(vpMatrix &_eJe) vp_override { }; - void get_fJe(vpMatrix &_fJe) vp_override { }; - void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q) vp_override { }; + void get_eJe(vpMatrix &_eJe) VP_OVERRIDE { }; + void get_fJe(vpMatrix &_fJe) VP_OVERRIDE { }; + void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE { }; protected: void init(); diff --git a/modules/robot/include/visp3/robot/vpSimulatorAfma6.h b/modules/robot/include/visp3/robot/vpSimulatorAfma6.h index e1f5be05a8..b7d8f622a3 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorAfma6.h +++ b/modules/robot/include/visp3/robot/vpSimulatorAfma6.h @@ -250,7 +250,7 @@ class VISP_EXPORT vpSimulatorAfma6 : public vpRobotWireFrameSimulator, public vp void compute_fMi(); void findHighestPositioningSpeed(vpColVector &q); void getExternalImage(vpImage &I); - inline void get_fMi(vpHomogeneousMatrix *fMit) vp_override + inline void get_fMi(vpHomogeneousMatrix *fMit) VP_OVERRIDE { m_mutex_fMi.lock(); for (int i = 0; i < 8; i++) { diff --git a/modules/robot/include/visp3/robot/vpSimulatorCamera.h b/modules/robot/include/visp3/robot/vpSimulatorCamera.h index 32f9989857..7ba11afbe7 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorCamera.h +++ b/modules/robot/include/visp3/robot/vpSimulatorCamera.h @@ -130,9 +130,9 @@ class VISP_EXPORT vpSimulatorCamera : public vpRobotSimulator void init() VP_OVERRIDE; // Non implemented virtual pure functions - void get_fJe(vpMatrix & /*_fJe */) vp_override { }; - void getDisplacement(const vpRobot::vpControlFrameType /* frame */, vpColVector & /* q */) vp_override { }; - void setPosition(const vpRobot::vpControlFrameType /* frame */, const vpColVector & /* q */) vp_override { }; + void get_fJe(vpMatrix & /*_fJe */) VP_OVERRIDE { }; + void getDisplacement(const vpRobot::vpControlFrameType /* frame */, vpColVector & /* q */) VP_OVERRIDE { }; + void setPosition(const vpRobot::vpControlFrameType /* frame */, const vpColVector & /* q */) VP_OVERRIDE { }; }; END_VISP_NAMESPACE #endif diff --git a/modules/robot/include/visp3/robot/vpSimulatorPioneer.h b/modules/robot/include/visp3/robot/vpSimulatorPioneer.h index 2adda80481..9c8b4c154b 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorPioneer.h +++ b/modules/robot/include/visp3/robot/vpSimulatorPioneer.h @@ -132,9 +132,9 @@ class VISP_EXPORT vpSimulatorPioneer : public vpPioneer, public vpRobotSimulator void init() VP_OVERRIDE; // Non implemented virtual pure functions - void get_fJe(vpMatrix & /*_fJe */) vp_override { }; - void getDisplacement(const vpRobot::vpControlFrameType /* frame */, vpColVector & /* q */) vp_override { }; - void setPosition(const vpRobot::vpControlFrameType /* frame */, const vpColVector & /* q */) vp_override { }; + void get_fJe(vpMatrix & /*_fJe */) VP_OVERRIDE { }; + void getDisplacement(const vpRobot::vpControlFrameType /* frame */, vpColVector & /* q */) VP_OVERRIDE { }; + void setPosition(const vpRobot::vpControlFrameType /* frame */, const vpColVector & /* q */) VP_OVERRIDE { }; }; END_VISP_NAMESPACE #endif diff --git a/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h b/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h index 1568d87a25..49d48ed6d7 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h +++ b/modules/robot/include/visp3/robot/vpSimulatorPioneerPan.h @@ -133,9 +133,9 @@ class VISP_EXPORT vpSimulatorPioneerPan : public vpPioneerPan, public vpRobotSim void init() VP_OVERRIDE; // Non implemented virtual pure functions - void get_fJe(vpMatrix & /*_fJe */) vp_override { }; - void getDisplacement(const vpRobot::vpControlFrameType /* frame */, vpColVector & /* q */) vp_override { }; - void setPosition(const vpRobot::vpControlFrameType /* frame */, const vpColVector & /* q */) vp_override { }; + void get_fJe(vpMatrix & /*_fJe */) VP_OVERRIDE { }; + void getDisplacement(const vpRobot::vpControlFrameType /* frame */, vpColVector & /* q */) VP_OVERRIDE { }; + void setPosition(const vpRobot::vpControlFrameType /* frame */, const vpColVector & /* q */) VP_OVERRIDE { }; }; END_VISP_NAMESPACE #endif diff --git a/modules/robot/include/visp3/robot/vpSimulatorViper850.h b/modules/robot/include/visp3/robot/vpSimulatorViper850.h index e0bb962ddc..6f993dec83 100644 --- a/modules/robot/include/visp3/robot/vpSimulatorViper850.h +++ b/modules/robot/include/visp3/robot/vpSimulatorViper850.h @@ -282,7 +282,7 @@ class VISP_EXPORT vpSimulatorViper850 : public vpRobotWireFrameSimulator, public void findHighestPositioningSpeed(vpColVector &q); void getExternalImage(vpImage &I); - inline void get_fMi(vpHomogeneousMatrix *fMit) vp_override + inline void get_fMi(vpHomogeneousMatrix *fMit) VP_OVERRIDE { m_mutex_fMi.lock(); for (int i = 0; i < 8; i++) { diff --git a/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h b/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h index 59d7772bc1..0f8b00aa00 100644 --- a/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h +++ b/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h @@ -224,7 +224,7 @@ BEGIN_VISP_NAMESPACE ~SessionDelegate() { } - void captureSessionEventDidOccur(ST::CaptureSession *session, ST::CaptureSessionEventId event) vp_override + void captureSessionEventDidOccur(ST::CaptureSession *session, ST::CaptureSessionEventId event) VP_OVERRIDE { switch (event) { case ST::CaptureSessionEventId::Booting: @@ -251,7 +251,7 @@ BEGIN_VISP_NAMESPACE } } - void captureSessionDidOutputSample(ST::CaptureSession *, const ST::CaptureSessionSample &sample) vp_override + void captureSessionDidOutputSample(ST::CaptureSession *, const ST::CaptureSessionSample &sample) VP_OVERRIDE { // acquire sampleLock mutex. std::lock_guard u(m_sampleLock); diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbDepthDenseTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbDepthDenseTracker.h index b9826e5439..90457b95c1 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbDepthDenseTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbDepthDenseTracker.h @@ -57,14 +57,14 @@ class VISP_EXPORT vpMbDepthDenseTracker : public virtual vpMbTracker virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; - virtual inline vpColVector getError() const vp_override { return m_error_depthDense; } + virtual inline vpColVector getError() const VP_OVERRIDE { return m_error_depthDense; } virtual std::vector > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel = false) VP_OVERRIDE; - virtual inline vpColVector getRobustWeights() const vp_override { return m_w_depthDense; } + virtual inline vpColVector getRobustWeights() const VP_OVERRIDE { return m_w_depthDense; } virtual void init(const vpImage &I) VP_OVERRIDE; diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbDepthNormalTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbDepthNormalTracker.h index b5500c8b51..c3eb11ae3e 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbDepthNormalTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbDepthNormalTracker.h @@ -61,14 +61,14 @@ class VISP_EXPORT vpMbDepthNormalTracker : public virtual vpMbTracker return m_depthNormalFeatureEstimationMethod; } - virtual inline vpColVector getError() const vp_override { return m_error_depthNormal; } + virtual inline vpColVector getError() const VP_OVERRIDE { return m_error_depthNormal; } virtual std::vector > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel = false) VP_OVERRIDE; - virtual inline vpColVector getRobustWeights() const vp_override { return m_w_depthNormal; } + virtual inline vpColVector getRobustWeights() const VP_OVERRIDE { return m_w_depthNormal; } virtual void init(const vpImage &I) VP_OVERRIDE; diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h index 63968ba59d..4b9093665e 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeKltTracker.h @@ -239,21 +239,21 @@ class VISP_EXPORT vpMbEdgeKltTracker : virtual void display(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE; - virtual inline vpColVector getError() const vp_override { return m_error_hybrid; } + virtual inline vpColVector getError() const VP_OVERRIDE { return m_error_hybrid; } virtual std::vector > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel = false) VP_OVERRIDE; - virtual inline vpColVector getRobustWeights() const vp_override { return m_w_hybrid; } + virtual inline vpColVector getRobustWeights() const VP_OVERRIDE { return m_w_hybrid; } /*! * Get the near distance for clipping. * * \return Near clipping value. */ - virtual inline double getNearClippingDistance() const vp_override { return vpMbKltTracker::getNearClippingDistance(); } + virtual inline double getNearClippingDistance() const VP_OVERRIDE { return vpMbKltTracker::getNearClippingDistance(); } virtual void loadConfigFile(const std::string &configFile, bool verbose = true) VP_OVERRIDE; @@ -270,21 +270,21 @@ class VISP_EXPORT vpMbEdgeKltTracker : * * \param flags : New clipping flags. */ - virtual void setClipping(const unsigned int &flags) vp_override { vpMbEdgeTracker::setClipping(flags); } + virtual void setClipping(const unsigned int &flags) VP_OVERRIDE { vpMbEdgeTracker::setClipping(flags); } /*! * Set the far distance for clipping. * * \param dist : Far clipping value. */ - virtual void setFarClippingDistance(const double &dist) vp_override { vpMbEdgeTracker::setFarClippingDistance(dist); } + virtual void setFarClippingDistance(const double &dist) VP_OVERRIDE { vpMbEdgeTracker::setFarClippingDistance(dist); } /*! * Set the near distance for clipping. * * \param dist : Near clipping value. */ - virtual void setNearClippingDistance(const double &dist) vp_override { vpMbEdgeTracker::setNearClippingDistance(dist); } + virtual void setNearClippingDistance(const double &dist) VP_OVERRIDE { vpMbEdgeTracker::setNearClippingDistance(dist); } /*! * Use Ogre3D for visibility tests @@ -294,7 +294,7 @@ class VISP_EXPORT vpMbEdgeKltTracker : * * \param v : True to use it, False otherwise */ - virtual void setOgreVisibilityTest(const bool &v) vp_override + virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE { vpMbTracker::setOgreVisibilityTest(v); #ifdef VISP_HAVE_OGRE @@ -307,7 +307,7 @@ class VISP_EXPORT vpMbEdgeKltTracker : * * \param v : True to use it, False otherwise */ - virtual void setScanLineVisibilityTest(const bool &v) vp_override + virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE { vpMbEdgeTracker::setScanLineVisibilityTest(v); vpMbKltTracker::setScanLineVisibilityTest(v); @@ -322,12 +322,12 @@ class VISP_EXPORT vpMbEdgeKltTracker : * \param flag : True if the projection error criteria has to be computed, * false otherwise */ - virtual void setProjectionErrorComputation(const bool &flag) vp_override + virtual void setProjectionErrorComputation(const bool &flag) VP_OVERRIDE { vpMbEdgeTracker::setProjectionErrorComputation(flag); } - virtual void testTracking() vp_override { } + virtual void testTracking() VP_OVERRIDE { } virtual void track(const vpImage &I) VP_OVERRIDE; virtual void track(const vpImage &I_color) VP_OVERRIDE; diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h index 04f6b8f349..f8073a0205 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbEdgeTracker.h @@ -373,9 +373,9 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker */ inline double getGoodMovingEdgesRatioThreshold() const { return percentageGdPt; } - virtual inline vpColVector getError() const vp_override { return m_error_edge; } + virtual inline vpColVector getError() const VP_OVERRIDE { return m_error_edge; } - virtual inline vpColVector getRobustWeights() const vp_override { return m_w_edge; } + virtual inline vpColVector getRobustWeights() const VP_OVERRIDE { return m_w_edge; } virtual void loadConfigFile(const std::string &configFile, bool verbose = true) VP_OVERRIDE; @@ -388,7 +388,7 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker * * \param cam : The new camera parameters. */ - virtual void setCameraParameters(const vpCameraParameters &cam) vp_override + virtual void setCameraParameters(const vpCameraParameters &cam) VP_OVERRIDE { m_cam = cam; @@ -424,7 +424,7 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker * * \param v : True to use it, False otherwise */ - virtual void setOgreVisibilityTest(const bool &v) vp_override + virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE { vpMbTracker::setOgreVisibilityTest(v); #ifdef VISP_HAVE_OGRE @@ -437,7 +437,7 @@ class VISP_EXPORT vpMbEdgeTracker : public virtual vpMbTracker * * \param v : True to use it, False otherwise */ - virtual void setScanLineVisibilityTest(const bool &v) vp_override + virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE { vpMbTracker::setScanLineVisibilityTest(v); diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h index 07f5eeea3a..02ce70db04 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbGenericTracker.h @@ -261,7 +261,7 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual void getClipping(unsigned int &clippingFlag1, unsigned int &clippingFlag2) const; virtual void getClipping(std::map &mapOfClippingFlags) const; - virtual inline vpColVector getError() const vp_override { return m_error; } + virtual inline vpColVector getError() const VP_OVERRIDE { return m_error; } virtual vpMbHiddenFaces &getFaces() VP_OVERRIDE; virtual vpMbHiddenFaces &getFaces(const std::string &cameraName); @@ -364,7 +364,7 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker virtual std::string getReferenceCameraName() const; - virtual inline vpColVector getRobustWeights() const vp_override { return m_w; } + virtual inline vpColVector getRobustWeights() const VP_OVERRIDE { return m_w; } virtual int getTrackerType() const; @@ -691,9 +691,9 @@ class VISP_EXPORT vpMbGenericTracker : public vpMbTracker TrackerWrapper(); explicit TrackerWrapper(int trackerType); - virtual inline vpColVector getError() const vp_override { return m_error; } + virtual inline vpColVector getError() const VP_OVERRIDE { return m_error; } - virtual inline vpColVector getRobustWeights() const vp_override { return m_w; } + virtual inline vpColVector getRobustWeights() const VP_OVERRIDE { return m_w; } virtual inline int getTrackerType() const { return m_trackerType; } diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h b/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h index dab9c8bc17..87ae54d412 100644 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbKltTracker.h @@ -321,9 +321,9 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker */ inline double getKltThresholdAcceptation() const { return threshold_outlier; } - virtual inline vpColVector getError() const vp_override { return m_error_klt; } + virtual inline vpColVector getError() const VP_OVERRIDE { return m_error_klt; } - virtual inline vpColVector getRobustWeights() const vp_override { return m_w_klt; } + virtual inline vpColVector getRobustWeights() const VP_OVERRIDE { return m_w_klt; } virtual std::vector > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, @@ -367,7 +367,7 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker * * \param v : True to use it, False otherwise */ - virtual void setOgreVisibilityTest(const bool &v) vp_override + virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE { vpMbTracker::setOgreVisibilityTest(v); #ifdef VISP_HAVE_OGRE @@ -380,7 +380,7 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker * * \param v : True to use it, False otherwise */ - virtual void setScanLineVisibilityTest(const bool &v) vp_override + virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE { vpMbTracker::setScanLineVisibilityTest(v); @@ -397,7 +397,7 @@ class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker * \param flag : True if the projection error criteria has to be computed, * false otherwise */ - virtual void setProjectionErrorComputation(const bool &flag) vp_override + virtual void setProjectionErrorComputation(const bool &flag) VP_OVERRIDE { if (flag) std::cerr << "This option is not yet implemented in vpMbKltTracker, " diff --git a/modules/vision/include/visp3/vision/vpPoseFeatures.h b/modules/vision/include/visp3/vision/vpPoseFeatures.h index aea9ca7f4e..f40e17b9b4 100644 --- a/modules/vision/include/visp3/vision/vpPoseFeatures.h +++ b/modules/vision/include/visp3/vision/vpPoseFeatures.h @@ -301,29 +301,29 @@ class vpPoseSpecificFeatureTemplate : public vpPoseSpecificFeature func_ptr = f_ptr; // std::move(f_ptr); m_tuple = new std::tuple(args...); } - virtual ~vpPoseSpecificFeatureTemplate() vp_override + virtual ~vpPoseSpecificFeatureTemplate() VP_OVERRIDE { delete m_tuple; } - virtual void createDesired() vp_override + virtual void createDesired() VP_OVERRIDE { buildDesiredFeatureWithTuple(m_desiredFeature, func_ptr, *m_tuple); } - virtual vpColVector error() vp_override + virtual vpColVector error() VP_OVERRIDE { // std::cout << "Getting S... : " << std::get<0>(*tuple).get_s() << // std::endl; return m_currentFeature.error(m_desiredFeature); } - virtual vpMatrix currentInteraction() vp_override + virtual vpMatrix currentInteraction() VP_OVERRIDE { return m_currentFeature.interaction(); } - virtual void createCurrent(const vpHomogeneousMatrix &cMo) vp_override + virtual void createCurrent(const vpHomogeneousMatrix &cMo) VP_OVERRIDE { buildCurrentFeatureWithTuple(m_currentFeature, cMo, func_ptr, *m_tuple); } @@ -358,27 +358,27 @@ class vpPoseSpecificFeatureTemplateObject : public vpPoseSpecificFeature m_obj = o; } - virtual ~vpPoseSpecificFeatureTemplateObject() vp_override + virtual ~vpPoseSpecificFeatureTemplateObject() VP_OVERRIDE { delete m_tuple; } - virtual void createDesired() vp_override + virtual void createDesired() VP_OVERRIDE { buildDesiredFeatureObjectWithTuple(m_obj, m_desiredFeature, func_ptr, *m_tuple); } - virtual vpColVector error() vp_override + virtual vpColVector error() VP_OVERRIDE { return m_currentFeature.error(m_desiredFeature); } - virtual vpMatrix currentInteraction() vp_override + virtual vpMatrix currentInteraction() VP_OVERRIDE { return m_currentFeature.interaction(); } - virtual void createCurrent(const vpHomogeneousMatrix &cMo) vp_override + virtual void createCurrent(const vpHomogeneousMatrix &cMo) VP_OVERRIDE { buildCurrentFeatureObjectWithTuple(m_obj, m_currentFeature, cMo, func_ptr, *m_tuple); } diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureLuminanceMapping.h b/modules/visual_features/include/visp3/visual_features/vpFeatureLuminanceMapping.h index ea3b0b836a..895f3bf40e 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureLuminanceMapping.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureLuminanceMapping.h @@ -402,10 +402,10 @@ class VISP_EXPORT vpFeatureLuminanceMapping : public vpBasicFeature void build(vpImage &I); void display(const vpCameraParameters &, const vpImage &, const vpColor & = vpColor::green, - unsigned int = 1) const vp_override + unsigned int = 1) const VP_OVERRIDE { } void display(const vpCameraParameters &, const vpImage &, const vpColor & = vpColor::green, - unsigned int = 1) const vp_override + unsigned int = 1) const VP_OVERRIDE { } vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE; diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h index 0445755b7d..abf4ae5190 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAlpha.h @@ -120,7 +120,7 @@ class VISP_EXPORT vpFeatureMomentAlpha : public vpFeatureMoment /*! * Associated moment name. */ - const std::string momentName() const vp_override + const std::string momentName() const VP_OVERRIDE { return "vpMomentAlpha"; } @@ -128,7 +128,7 @@ class VISP_EXPORT vpFeatureMomentAlpha : public vpFeatureMoment /*! * Feature name. */ - const std::string name() const vp_override + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentAlpha"; } diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h index 2b025fbd8c..aa575ab2be 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentArea.h @@ -76,7 +76,7 @@ class VISP_EXPORT vpFeatureMomentArea : public vpFeatureMoment /*! * Associated moment name. */ - const std::string momentName() const vp_override + const std::string momentName() const VP_OVERRIDE { return "vpMomentArea"; } @@ -84,7 +84,7 @@ class VISP_EXPORT vpFeatureMomentArea : public vpFeatureMoment /*! * Feature name. */ - const std::string name() const vp_override + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentArea"; } diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h index 44fe5fa720..116a9f56c1 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentAreaNormalized.h @@ -102,7 +102,7 @@ class VISP_EXPORT vpFeatureMomentAreaNormalized : public vpFeatureMoment /*! * Associated moment name. */ - const std::string momentName() const vp_override + const std::string momentName() const VP_OVERRIDE { return "vpMomentAreaNormalized"; } @@ -110,7 +110,7 @@ class VISP_EXPORT vpFeatureMomentAreaNormalized : public vpFeatureMoment /*! * Feature name. */ - const std::string name() const vp_override + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentAreaNormalized"; } @@ -204,7 +204,7 @@ class VISP_EXPORT vpFeatureMomentAreaNormalized : public vpFeatureMoment /*! * Associated moment name. */ - const std::string momentName() const vp_override + const std::string momentName() const VP_OVERRIDE { return "vpMomentAreaNormalized"; } @@ -212,7 +212,7 @@ class VISP_EXPORT vpFeatureMomentAreaNormalized : public vpFeatureMoment /*! * Feature name. */ - const std::string name() const vp_override + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentAreaNormalized"; } diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h index e7c10d120a..0de06f983b 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentBasic.h @@ -87,7 +87,7 @@ class VISP_EXPORT vpFeatureMomentBasic : public vpFeatureMoment #ifndef DOXYGEN_SHOULD_SKIP_THIS /* Add function due to pure virtual definition in vpBasicFeature.h */ - vpMatrix interaction(unsigned int /* select = FEATURE_ALL */) vp_override + vpMatrix interaction(unsigned int /* select = FEATURE_ALL */) VP_OVERRIDE { throw vpException(vpException::functionNotImplementedError, "Not implemented!"); } @@ -98,7 +98,7 @@ class VISP_EXPORT vpFeatureMomentBasic : public vpFeatureMoment /*! * Associated moment name. */ - const std::string momentName() const vp_override + const std::string momentName() const VP_OVERRIDE { return "vpMomentBasic"; } @@ -106,7 +106,7 @@ class VISP_EXPORT vpFeatureMomentBasic : public vpFeatureMoment /*! * Feature name. */ - const std::string name() const vp_override + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentBasic"; } diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h index 2e1d2c8ba2..eeec825386 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCInvariant.h @@ -112,7 +112,7 @@ class VISP_EXPORT vpFeatureMomentCInvariant : public vpFeatureMoment /*! * Associated moment name. */ - const std::string momentName() const vp_override + const std::string momentName() const VP_OVERRIDE { return "vpMomentCInvariant"; } @@ -120,7 +120,7 @@ class VISP_EXPORT vpFeatureMomentCInvariant : public vpFeatureMoment /*! * Feature name. */ - const std::string name() const vp_override + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentCInvariant"; } @@ -257,14 +257,14 @@ class VISP_EXPORT vpFeatureMomentCInvariant : public vpFeatureMoment /*! * Associated moment name. */ - const std::string momentName() const vp_override + const std::string momentName() const VP_OVERRIDE { return "vpMomentCInvariant"; } /*! * Feature name. */ - const std::string name() const vp_override + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentCInvariant"; } diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h index 096a7b89d2..aed4479294 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentCentered.h @@ -93,7 +93,7 @@ class VISP_EXPORT vpFeatureMomentCentered : public vpFeatureMoment #ifndef DOXYGEN_SHOULD_SKIP_THIS /* Add function due to pure virtual definition in vpBasicFeature.h */ - vpMatrix interaction(unsigned int /* select = FEATURE_ALL */) vp_override + vpMatrix interaction(unsigned int /* select = FEATURE_ALL */) VP_OVERRIDE { throw vpException(vpException::functionNotImplementedError, "Not implemented!"); } @@ -104,7 +104,7 @@ class VISP_EXPORT vpFeatureMomentCentered : public vpFeatureMoment /*! * Associated moment name */ - const std::string momentName() const vp_override + const std::string momentName() const VP_OVERRIDE { return "vpMomentCentered"; } @@ -112,7 +112,7 @@ class VISP_EXPORT vpFeatureMomentCentered : public vpFeatureMoment /*! * Feature name */ - const std::string name() const vp_override + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentCentered"; } diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h index c15a793a50..8baf3359f2 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenter.h @@ -172,12 +172,12 @@ class VISP_EXPORT vpFeatureMomentGravityCenter : public vpFeatureMoment /*! * Associated moment name. */ - const std::string momentName() const vp_override { return "vpMomentGravityCenter"; } + const std::string momentName() const VP_OVERRIDE { return "vpMomentGravityCenter"; } /*! * Feature name. */ - const std::string name() const vp_override { return "vpFeatureMomentGravityCenter"; } + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentGravityCenter"; } /*! * Shortcut selector for \f$x_g\f$. @@ -244,12 +244,12 @@ class VISP_EXPORT vpFeatureMomentGravityCenter : public vpFeatureMoment /*! * Associated moment name. */ - const std::string momentName() const vp_override { return "vpMomentGravityCenter"; } + const std::string momentName() const VP_OVERRIDE { return "vpMomentGravityCenter"; } /*! * Feature name. */ - const std::string name() const vp_override { return "vpFeatureMomentGravityCenter"; } + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentGravityCenter"; } /*! * Shortcut selector for \f$x_g\f$. diff --git a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h index 9c6c2e58ae..d038a42202 100644 --- a/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h +++ b/modules/visual_features/include/visp3/visual_features/vpFeatureMomentGravityCenterNormalized.h @@ -109,12 +109,12 @@ class VISP_EXPORT vpFeatureMomentGravityCenterNormalized : public vpFeatureMomen /*! * Associated moment name. */ - const std::string momentName() const vp_override { return "vpMomentGravityCenterNormalized"; } + const std::string momentName() const VP_OVERRIDE { return "vpMomentGravityCenterNormalized"; } /*! * Feature name. */ - const std::string name() const vp_override { return "vpFeatureMomentGravityCenterNormalized"; } + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentGravityCenterNormalized"; } /*! * Shortcut selector for \f$x_n\f$. @@ -263,12 +263,12 @@ class VISP_EXPORT vpFeatureMomentGravityCenterNormalized : public vpFeatureMomen /*! * Associated moment name. */ - const std::string momentName() const vp_override { return "vpMomentGravityCenterNormalized"; } + const std::string momentName() const VP_OVERRIDE { return "vpMomentGravityCenterNormalized"; } /*! * Feature name. */ - const std::string name() const vp_override { return "vpFeatureMomentGravityCenterNormalized"; } + const std::string name() const VP_OVERRIDE { return "vpFeatureMomentGravityCenterNormalized"; } /*! * Shortcut selector for \f$x_n\f$. From f1b79a19b8b922a7aad28705b317d286a58cdb07 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 25 Jun 2024 22:14:03 +0200 Subject: [PATCH 11/11] Fix build issue on ci --- modules/core/include/visp3/core/vpImageTools_warp.h | 1 + modules/core/test/camera/testJsonCamera.cpp | 4 ++-- modules/core/test/math/testJsonArrayConversion.cpp | 12 ++++++------ modules/tracker/me/test/testJsonMe.cpp | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/core/include/visp3/core/vpImageTools_warp.h b/modules/core/include/visp3/core/vpImageTools_warp.h index 7b314c6fff..8a7bae82de 100644 --- a/modules/core/include/visp3/core/vpImageTools_warp.h +++ b/modules/core/include/visp3/core/vpImageTools_warp.h @@ -35,6 +35,7 @@ #define VP_IMAGE_TOOLS_WARP_H // Warning: this file shouldn't be included by the user. Internal usage only to reduce length of vpImage.h +#include /*! Apply a warping (affine or perspective) transformation to an image. diff --git a/modules/core/test/camera/testJsonCamera.cpp b/modules/core/test/camera/testJsonCamera.cpp index 69f19466b1..93fb61ca57 100644 --- a/modules/core/test/camera/testJsonCamera.cpp +++ b/modules/core/test/camera/testJsonCamera.cpp @@ -72,8 +72,8 @@ class vpRandomCamGenerator : public Catch::Generators::IGenerator(next()); } - const vpCameraParameters &get() const vp_override { return current; } - bool next() vp_override + const vpCameraParameters &get() const VP_OVERRIDE { return current; } + bool next() VP_OVERRIDE { const double px = m_dist(m_rand); const double py = m_dist(m_rand); diff --git a/modules/core/test/math/testJsonArrayConversion.cpp b/modules/core/test/math/testJsonArrayConversion.cpp index 3bd5d00df8..3bb183b682 100644 --- a/modules/core/test/math/testJsonArrayConversion.cpp +++ b/modules/core/test/math/testJsonArrayConversion.cpp @@ -68,12 +68,12 @@ class vpExceptionMatcher : public Catch::Matchers::Impl::MatcherBase(next()); } - vpArray2D const &get() const vp_override { return current; } - bool next() vp_override + vpArray2D const &get() const VP_OVERRIDE { return current; } + bool next() VP_OVERRIDE { const unsigned nCols = m_dim_dist(m_rand); const unsigned nRows = m_dim_dist(m_rand); @@ -129,8 +129,8 @@ class vpRandomColVectorGenerator : public Catch::Generators::IGenerator(next()); } - const vpColVector &get() const vp_override { return current; } - bool next() vp_override + const vpColVector &get() const VP_OVERRIDE { return current; } + bool next() VP_OVERRIDE { const unsigned nRows = m_dim_dist(m_rand); current.resize(nRows); diff --git a/modules/tracker/me/test/testJsonMe.cpp b/modules/tracker/me/test/testJsonMe.cpp index b19ef98d98..659ebc2700 100644 --- a/modules/tracker/me/test/testJsonMe.cpp +++ b/modules/tracker/me/test/testJsonMe.cpp @@ -104,8 +104,8 @@ class RandomMeGenerator : public Catch::Generators::IGenerator static_cast(next()); } - vpMe const &get() const vp_override { return current; } - bool next() vp_override + vpMe const &get() const VP_OVERRIDE { return current; } + bool next() VP_OVERRIDE { current.setThreshold(m_dist(m_rand) * 255); current.setMaskNumber(m_int_dist(m_rand) * 10);