From c8897ee929a6d5869adfd4127b12aaf1d1162c28 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 16 Nov 2023 10:49:10 +0100 Subject: [PATCH 1/9] Update with fix #1272 --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 30adc1cddd..1604acbdf1 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -27,6 +27,7 @@ ViSP 3.x.x (Version in development) . [#1251] Bug in vpDisplay::displayFrame() . [#1270] Build issue around std::clamp and optional header which are not found with cxx17 standard enabled + . [#1272] Unable to build ViSP with PCL/VTK build from source, VTK headers are not found by ViSP ---------------------------------------------- ViSP 3.6.0 (released September 22, 2023) - Contributors: From 926f64298ee6cd99e7c5017be2793353d968dbc3 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 16 Nov 2023 10:51:41 +0100 Subject: [PATCH 2/9] Initialize vpIoTools::separator in class definition --- modules/core/include/visp3/core/vpIoTools.h | 12 ++++-------- modules/core/src/tools/file/vpIoTools.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/core/include/visp3/core/vpIoTools.h b/modules/core/include/visp3/core/vpIoTools.h index 6854533379..230c5a5162 100644 --- a/modules/core/include/visp3/core/vpIoTools.h +++ b/modules/core/include/visp3/core/vpIoTools.h @@ -175,15 +175,11 @@ class VISP_EXPORT vpIoTools static bool rename(const std::string &oldfilename, const std::string &newfilename); /*! - Define the directory separator character, backslash ('\') for windows - platform or slash ('/') otherwise. + * Define the directory separator character, backslash ('\') for windows + * platform or slash ('/') otherwise. */ - static const char separator = -#if defined(_WIN32) - '\\'; -#else - '/'; -#endif + static const char separator; + static std::string toUpperCase(const std::string &input); static std::string toLowerCase(const std::string &input); static std::string getAbsolutePathname(const std::string &pathname); diff --git a/modules/core/src/tools/file/vpIoTools.cpp b/modules/core/src/tools/file/vpIoTools.cpp index 7a2c66ea11..fd192f1c26 100644 --- a/modules/core/src/tools/file/vpIoTools.cpp +++ b/modules/core/src/tools/file/vpIoTools.cpp @@ -110,6 +110,13 @@ 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 { // The following code is not working on iOS since wordexp() is not available From f104c4a8ecec5de8eb5faf539f7a28db95188b4f Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 16 Nov 2023 11:00:37 +0100 Subject: [PATCH 3/9] Improve doc presentation --- modules/core/include/visp3/core/vpIoTools.h | 206 ++++++++++---------- 1 file changed, 102 insertions(+), 104 deletions(-) diff --git a/modules/core/include/visp3/core/vpIoTools.h b/modules/core/include/visp3/core/vpIoTools.h index 230c5a5162..b0b82eeba4 100644 --- a/modules/core/include/visp3/core/vpIoTools.h +++ b/modules/core/include/visp3/core/vpIoTools.h @@ -35,9 +35,9 @@ #define _vpIoTools_h_ /*! - \file vpIoTools.h - \brief File and directories basic tools. -*/ + * \file vpIoTools.h + * \brief File and directories basic tools. + */ #include @@ -50,106 +50,104 @@ #include /*! - \class vpIoTools - \ingroup group_core_files_io - \brief File and directories basic tools. - - The example below shows how to manipulate the functions of this - class to create first a directory which name corresponds to the user - name and then create a file in this directory. - - \code -#include -#include -#include -#include - -int main() -{ - std::string username; - vpIoTools::getUserName(username); - - // Test if a username directory exist. If no try to create it - if (vpIoTools::checkDirectory(username) == false) { - try { - // Create a directory with name "username" - vpIoTools::makeDirectory(username); - } - catch (...) { - std::cout << "Cannot create " << username << " directory" << std::endl; - return EXIT_FAILURE; - } - } - // Create a empty filename with name "username/file.txt" - std::ofstream f; - std::string filename = username + "/file.txt"; - // Under Windows converts the filename string into "username\\file.txt" - filename = vpIoTools::path(filename); - std::cout << "Create: " << filename << std::endl; - f.open(filename.c_str()); - f.close(); - - // Rename the file - std::string newfilename = username + "/newfile.txt"; - std::cout << "Rename: " << filename << " in: " << newfilename << std::endl; - if (vpIoTools::rename(filename, newfilename) == false) - std::cout << "Unable to rename: " << filename << std::endl; - - // Remove the file - std::cout << "Remove: " << newfilename << std::endl; - if (vpIoTools::remove(newfilename) == false) - std::cout << "Unable to remove: " << newfilename << std::endl; - - return EXIT_SUCCESS; -} - \endcode - - The example below shows how to read a configuration file and how to create a name - for experiment files. We assume the following file "/home/user/demo/config.txt" : - \code -expNumber 2 -save 0 -lambda 0.4 -use2D 0 -use3D 1 - \endcode - - \code -#include -#include -#include - -int main() -{ - // reading configuration file - vpIoTools::loadConfigFile("/home/user/demo/config.txt"); - std::string nExp;vpIoTools::readConfigVar("expNumber", nExp); // nExp <- "2" - double lambda;vpIoTools::readConfigVar("lambda", lambda); // lambda <- 0.4 - bool use2D;vpIoTools::readConfigVar("use2D", use2D); // use2D <- false - bool use3D;vpIoTools::readConfigVar("use3D", use3D); // use3D <- true - bool doSave;vpIoTools::readConfigVar("save", doSave); // doSave <- false - - // creating name for experiment files - vpIoTools::setBaseDir("/home/user/data"); - // full name <- "/home/user/data/exp2" - vpIoTools::setBaseName("exp" + nExp); - // full name <- "/home/user/data/exp2" since use2D==false - vpIoTools::addNameElement("2D", use2D); - // full name <- "/home/user/data/exp2_3D" - vpIoTools::addNameElement("3D", use3D); - // full name <- "/home/user/data/exp2_3D_lambda0.4" - vpIoTools::addNameElement("lambda", lambda); - - // Saving file.Would copy "/home/user/demo/config.txt" to - // "/home/user/data/exp2_3D_lambda0.4_config.txt" if doSave was true - vpIoTools::saveConfigFile(doSave); - // create sub directory - vpIoTools::createBaseNamePath(); // creates "/home/user/data/exp2_3D_lambda0.4/" -} - \endcode - + * \class vpIoTools + * \ingroup group_core_files_io + * \brief File and directories basic tools. + * + * The example below shows how to manipulate the functions of this + * class to create first a directory which name corresponds to the user + * name and then create a file in this directory. + * + * \code + * #include + * #include + * #include + * #include + * + * int main() + * { + * std::string username; + * vpIoTools::getUserName(username); + * + * // Test if a username directory exist. If no try to create it + * if (vpIoTools::checkDirectory(username) == false) { + * try { + * // Create a directory with name "username" + * vpIoTools::makeDirectory(username); + * } + * catch (...) { + * std::cout << "Cannot create " << username << " directory" << std::endl; + * return EXIT_FAILURE; + * } + * } + * // Create a empty filename with name "username/file.txt" + * std::ofstream f; + * std::string filename = username + "/file.txt"; + * // Under Windows converts the filename string into "username\\file.txt" + * filename = vpIoTools::path(filename); + * std::cout << "Create: " << filename << std::endl; + * f.open(filename.c_str()); + * f.close(); + * + * // Rename the file + * std::string newfilename = username + "/newfile.txt"; + * std::cout << "Rename: " << filename << " in: " << newfilename << std::endl; + * if (vpIoTools::rename(filename, newfilename) == false) + * std::cout << "Unable to rename: " << filename << std::endl; + * + * // Remove the file + * std::cout << "Remove: " << newfilename << std::endl; + * if (vpIoTools::remove(newfilename) == false) + * std::cout << "Unable to remove: " << newfilename << std::endl; + * + * return EXIT_SUCCESS; + * } + * \endcode + * + * The example below shows how to read a configuration file and how to create a name + * for experiment files. We assume the following file "/home/user/demo/config.txt" : + * \code + * expNumber 2 + * save 0 + * lambda 0.4 + * use2D 0 + * use3D 1 + * \endcode + * + * \code + * #include + * #include + * #include + * + * int main() + * { + * // reading configuration file + * vpIoTools::loadConfigFile("/home/user/demo/config.txt"); + * std::string nExp;vpIoTools::readConfigVar("expNumber", nExp); // nExp <- "2" + * double lambda;vpIoTools::readConfigVar("lambda", lambda); // lambda <- 0.4 + * bool use2D;vpIoTools::readConfigVar("use2D", use2D); // use2D <- false + * bool use3D;vpIoTools::readConfigVar("use3D", use3D); // use3D <- true + * bool doSave;vpIoTools::readConfigVar("save", doSave); // doSave <- false + * + * // creating name for experiment files + * vpIoTools::setBaseDir("/home/user/data"); + * // full name <- "/home/user/data/exp2" + * vpIoTools::setBaseName("exp" + nExp); + * // full name <- "/home/user/data/exp2" since use2D==false + * vpIoTools::addNameElement("2D", use2D); + * // full name <- "/home/user/data/exp2_3D" + * vpIoTools::addNameElement("3D", use3D); + * // full name <- "/home/user/data/exp2_3D_lambda0.4" + * vpIoTools::addNameElement("lambda", lambda); + * + * // Saving file.Would copy "/home/user/demo/config.txt" to + * // "/home/user/data/exp2_3D_lambda0.4_config.txt" if doSave was true + * vpIoTools::saveConfigFile(doSave); + * // create sub directory + * vpIoTools::createBaseNamePath(); // creates "/home/user/data/exp2_3D_lambda0.4/" + * } + * \endcode */ - class VISP_EXPORT vpIoTools { @@ -196,8 +194,8 @@ class VISP_EXPORT vpIoTools static std::vector getDirFiles(const std::string &dirname); /*! - @name Configuration file parsing - */ + * @name Configuration file parsing + */ //@{ // read configuration file static bool loadConfigFile(const std::string &confFile); From 79b85068ae0384e9bfbfb193cef4dc4b6837dc1f Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 16 Nov 2023 11:58:50 +0100 Subject: [PATCH 4/9] Introduce capability to display a polygon defined by a vpPolygon object --- modules/core/include/visp3/core/vpDisplay.h | 5 +++ modules/core/src/display/vpDisplay_impl.h | 7 ++++ modules/core/src/display/vpDisplay_rgba.cpp | 14 +++++++ modules/core/src/display/vpDisplay_uchar.cpp | 14 +++++++ modules/gui/test/display/testDisplays.cpp | 41 ++++++++++++++------ 5 files changed, 69 insertions(+), 12 deletions(-) diff --git a/modules/core/include/visp3/core/vpDisplay.h b/modules/core/include/visp3/core/vpDisplay.h index 2e1327b895..e4d81a6775 100644 --- a/modules/core/include/visp3/core/vpDisplay.h +++ b/modules/core/include/visp3/core/vpDisplay.h @@ -45,6 +45,7 @@ #include #include #include +#include #include /*! @@ -761,6 +762,8 @@ class VISP_EXPORT vpDisplay unsigned int thickness = 1); static void displayPolygon(const vpImage &I, const std::vector &vip, const vpColor &color, unsigned int thickness = 1, bool closed = true); + static void displayPolygon(const vpImage &I, const vpPolygon &polygon, + const vpColor &color, unsigned int thickness = 1, bool closed = true); static void displayRectangle(const vpImage &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill = false, unsigned int thickness = 1); @@ -867,6 +870,8 @@ class VISP_EXPORT vpDisplay static void displayPoint(const vpImage &I, int i, int j, const vpColor &color, unsigned int thickness = 1); static void displayPolygon(const vpImage &I, const std::vector &vip, const vpColor &color, unsigned int thickness = 1, bool closed = true); + static void displayPolygon(const vpImage &I, const vpPolygon &polygon, + const vpColor &color, unsigned int thickness = 1, bool closed = true); static void displayRectangle(const vpImage &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill = false, unsigned int thickness = 1); diff --git a/modules/core/src/display/vpDisplay_impl.h b/modules/core/src/display/vpDisplay_impl.h index 33ad7819fa..8b12fa5cfe 100644 --- a/modules/core/src/display/vpDisplay_impl.h +++ b/modules/core/src/display/vpDisplay_impl.h @@ -456,6 +456,13 @@ void vp_display_display_polygon(const vpImage &I, const std::vector +void vp_display_display_polygon(const vpImage &I, const vpPolygon &polygon, const vpColor &color, + unsigned int thickness, bool closed = true) +{ + vp_display_display_polygon(I, polygon.getCorners(), color, thickness, closed); +} + template void vp_display_display_rectangle(const vpImage &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill, unsigned int thickness) diff --git a/modules/core/src/display/vpDisplay_rgba.cpp b/modules/core/src/display/vpDisplay_rgba.cpp index 1023c614a9..c3a0ceb268 100644 --- a/modules/core/src/display/vpDisplay_rgba.cpp +++ b/modules/core/src/display/vpDisplay_rgba.cpp @@ -584,6 +584,20 @@ void vpDisplay::displayPolygon(const vpImage &I, const std::vector &I, const vpPolygon &polygon, const vpColor &color, + unsigned int thickness, bool closed) +{ + vp_display_display_polygon(I, polygon, color, thickness, closed); +} + /*! Display a rectangle with \e topLeft as the top-left corner and \e width and \e height the rectangle size. diff --git a/modules/core/src/display/vpDisplay_uchar.cpp b/modules/core/src/display/vpDisplay_uchar.cpp index af42deedc4..a39acc385c 100644 --- a/modules/core/src/display/vpDisplay_uchar.cpp +++ b/modules/core/src/display/vpDisplay_uchar.cpp @@ -584,6 +584,20 @@ void vpDisplay::displayPolygon(const vpImage &I, const std::vecto vp_display_display_polygon(I, vip, color, thickness, closed); } +/*! + Display a polygon defined by a set of image points. + \param I : The image associated to the display. + \param polygon : Polygon to display. + \param color : Line color. + \param thickness : Line thickness. + \param closed : When true display a closed polygon with a segment between first and last image point. +*/ +void vpDisplay::displayPolygon(const vpImage &I, const vpPolygon &polygon, const vpColor &color, + unsigned int thickness, bool closed) +{ + vp_display_display_polygon(I, polygon, color, thickness, closed); +} + /*! Display a rectangle with \e topLeft as the top-left corner and \e width and \e height the rectangle size. diff --git a/modules/gui/test/display/testDisplays.cpp b/modules/gui/test/display/testDisplays.cpp index fe5c88ec35..f87ccdca0d 100644 --- a/modules/gui/test/display/testDisplays.cpp +++ b/modules/gui/test/display/testDisplays.cpp @@ -80,7 +80,7 @@ Test video devices or display.\n\ SYNOPSIS\n\ %s [-l] [-c] [-d] [-h]\n\ ", - name); +name); fprintf(stdout, "\n\ OPTIONS: Default\n\ @@ -247,18 +247,34 @@ template static void draw(vpImage &I) iP1.set_j(400); vpDisplay::displayRectangle(I, iP1, 45, w, h, vpColor::green, 3); - std::vector polygon; - polygon.push_back(vpImagePoint(250, 500)); - polygon.push_back(vpImagePoint(350, 600)); - polygon.push_back(vpImagePoint(450, 500)); - polygon.push_back(vpImagePoint(350, 400)); + std::vector vip; + vip.push_back(vpImagePoint(250, 500)); + vip.push_back(vpImagePoint(350, 600)); + vip.push_back(vpImagePoint(450, 500)); + vip.push_back(vpImagePoint(350, 400)); + vpDisplay::displayPolygon(I, vip, vpColor::green, 3); + + vip.clear(); + vip.push_back(vpImagePoint(300, 500)); + vip.push_back(vpImagePoint(350, 550)); + vip.push_back(vpImagePoint(400, 500)); + vip.push_back(vpImagePoint(350, 450)); + vpDisplay::displayPolygon(I, vip, vpColor::cyan, 3, false); + + vip.clear(); + vip.push_back(vpImagePoint(250, 300)); + vip.push_back(vpImagePoint(350, 400)); + vip.push_back(vpImagePoint(450, 300)); + vip.push_back(vpImagePoint(350, 200)); + vpPolygon polygon(vip); vpDisplay::displayPolygon(I, polygon, vpColor::green, 3); - polygon.clear(); - polygon.push_back(vpImagePoint(300, 500)); - polygon.push_back(vpImagePoint(350, 550)); - polygon.push_back(vpImagePoint(400, 500)); - polygon.push_back(vpImagePoint(350, 450)); + vip.clear(); + vip.push_back(vpImagePoint(300, 300)); + vip.push_back(vpImagePoint(350, 350)); + vip.push_back(vpImagePoint(400, 300)); + vip.push_back(vpImagePoint(350, 250)); + polygon.buildFrom(vip); vpDisplay::displayPolygon(I, polygon, vpColor::cyan, 3, false); } @@ -408,7 +424,8 @@ int main(int argc, const char **argv) runTest(opt_display, opt_click_allowed); return EXIT_SUCCESS; - } catch (const vpException &e) { + } + catch (const vpException &e) { std::cout << "Catch an exception: " << e.getMessage() << std::endl; return EXIT_FAILURE; } From b8bbf659bdaf9cca7308d226b6ee1fef4c115dc5 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 16 Nov 2023 12:46:06 +0100 Subject: [PATCH 5/9] Make vpDisplay::displayCharString() deprecated Instead use vpDisplay::displayText() --- modules/core/include/visp3/core/vpDisplay.h | 54 ++-- modules/core/src/display/vpDisplay_impl.h | 12 +- modules/core/src/display/vpDisplay_rgba.cpp | 12 +- modules/core/src/display/vpDisplay_uchar.cpp | 12 +- modules/gui/include/visp3/gui/vpDisplayGTK.h | 3 +- .../gui/include/visp3/gui/vpDisplayOpenCV.h | 4 +- .../gui/include/visp3/gui/vpDisplayWin32.h | 4 +- modules/gui/include/visp3/gui/vpDisplayX.h | 4 +- modules/gui/src/display/vpDisplayGTK.cpp | 13 +- modules/gui/src/display/vpDisplayOpenCV.cpp | 6 +- modules/gui/src/display/vpDisplayX.cpp | 241 +++++++++++------- .../src/display/windows/vpDisplayWin32.cpp | 29 ++- 12 files changed, 238 insertions(+), 156 deletions(-) diff --git a/modules/core/include/visp3/core/vpDisplay.h b/modules/core/include/visp3/core/vpDisplay.h index e4d81a6775..d784891c53 100644 --- a/modules/core/include/visp3/core/vpDisplay.h +++ b/modules/core/include/visp3/core/vpDisplay.h @@ -285,18 +285,6 @@ class VISP_EXPORT vpDisplay */ virtual 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) = 0; - /*! - * Display a string at the image point \e ip location. - * - * To select the font used to display the string, use setFont(). - * - * \param ip : Upper left image point location of the string in the display. - * \param text : String to display in overlay. - * \param color : String color. - * - * \sa setFont() - */ - virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color = vpColor::green) = 0; /*! * Display a circle. @@ -425,6 +413,19 @@ class VISP_EXPORT vpDisplay virtual void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) = 0; + /*! + * Display a string at the image point \e ip location. + * + * To select the font used to display the string, use setFont(). + * + * \param ip : Upper left image point location of the string in the display. + * \param text : String to display in overlay. + * \param color : String color. + * + * \sa setFont() + */ + virtual void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) = 0; + /*! * Flushes the display. * It's necessary to use this function to see the results of any drawing. @@ -672,7 +673,7 @@ class VISP_EXPORT vpDisplay /*! * Set the font used to display a text in overlay. The display is - * performed using displayCharString(). + * performed using displayText(). * * \param font : The expected font name. The available fonts are given by * the "xlsfonts" binary. To choose a font you can also use the @@ -681,7 +682,7 @@ class VISP_EXPORT vpDisplay * \note Under UNIX, to know all the available fonts, use the * "xlsfonts" binary in a terminal. You can also use the "xfontsel" binary. * - * \sa displayCharString() + * \sa displayText() */ virtual void setFont(const std::string &font) = 0; /*! @@ -714,10 +715,6 @@ class VISP_EXPORT vpDisplay unsigned int thickness = 1); static void displayCamera(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness); - static void displayCharString(const vpImage &I, const vpImagePoint &ip, const char *string, - const vpColor &color); - static void displayCharString(const vpImage &I, int i, int j, const char *string, - const vpColor &color); static void displayCircle(const vpImage &I, const vpImageCircle &circle, const vpColor &color, bool fill = false, unsigned int thickness = 1); static void displayCircle(const vpImage &I, const vpImagePoint ¢er, unsigned int radius, @@ -825,11 +822,8 @@ class VISP_EXPORT vpDisplay unsigned int thickness = 1); static void displayCamera(const vpImage &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness); - static void displayCharString(const vpImage &I, const vpImagePoint &ip, const char *string, - const vpColor &color); - static void displayCharString(const vpImage &I, int i, int j, const char *string, const vpColor &color); static void displayCircle(const vpImage &I, const vpImageCircle &circle, - const vpColor &color, bool fill = false, unsigned int thickness = 1); + const vpColor &color, bool fill = false, unsigned int thickness = 1); static void displayCircle(const vpImage &I, const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill = false, unsigned int thickness = 1); static void displayCircle(const vpImage &I, int i, int j, unsigned int radius, const vpColor &color, @@ -915,6 +909,22 @@ class VISP_EXPORT vpDisplay static void setWindowPosition(const vpImage &I, int winx, int winy); //@} +#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) + /*! + * @name Deprecated functions + */ + //@{ + 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, + const vpColor &color); + 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, + const vpColor &color); + //@} +#endif + private: //! Get the window pixmap and put it in vpRGBa image. virtual void getImage(vpImage &I) = 0; diff --git a/modules/core/src/display/vpDisplay_impl.h b/modules/core/src/display/vpDisplay_impl.h index 8b12fa5cfe..2fb96b3489 100644 --- a/modules/core/src/display/vpDisplay_impl.h +++ b/modules/core/src/display/vpDisplay_impl.h @@ -103,23 +103,23 @@ void vp_display_display_camera(const vpImage &I, const vpHomogeneousMatrix } template -void vp_display_display_char_string(const vpImage &I, const vpImagePoint &ip, const char *string, +void vp_display_display_text(const vpImage &I, const vpImagePoint &ip, const char *string, const vpColor &color) { if (I.display != nullptr) { - (I.display)->displayCharString(ip, string, color); + (I.display)->displayText(ip, string, color); } } template -void vp_display_display_char_string(const vpImage &I, int i, int j, const char *string, const vpColor &color) +void vp_display_display_text(const vpImage &I, int i, int j, const char *string, const vpColor &color) { if (I.display != nullptr) { vpImagePoint ip; ip.set_i(i); ip.set_j(j); - (I.display)->displayCharString(ip, string, color); + (I.display)->displayText(ip, string, color); } } @@ -678,7 +678,7 @@ template void vp_display_display_text(const vpImage &I, const vpImagePoint &ip, const std::string &s, const vpColor &color) { if (I.display != nullptr) { - (I.display)->displayCharString(ip, s.c_str(), color); + (I.display)->displayText(ip, s.c_str(), color); } } @@ -690,7 +690,7 @@ void vp_display_display_text(const vpImage &I, int i, int j, const std::st ip.set_i(i); ip.set_j(j); - (I.display)->displayCharString(ip, s.c_str(), color); + (I.display)->displayText(ip, s.c_str(), color); } } diff --git a/modules/core/src/display/vpDisplay_rgba.cpp b/modules/core/src/display/vpDisplay_rgba.cpp index c3a0ceb268..a35cbbfa9a 100644 --- a/modules/core/src/display/vpDisplay_rgba.cpp +++ b/modules/core/src/display/vpDisplay_rgba.cpp @@ -96,8 +96,9 @@ void vpDisplay::displayCamera(const vpImage &I, const vpHomogeneousMatri vp_display_display_camera(I, cMo, cam, size, color, thickness); } +#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) /*! - Display a string at the image point \e ip location. + \deprecated Display a string at the image point \e ip location. Use rather displayText() that does the same. To select the font used to display the string, use setFont(). @@ -112,11 +113,11 @@ void vpDisplay::displayCamera(const vpImage &I, const vpHomogeneousMatri void vpDisplay::displayCharString(const vpImage &I, const vpImagePoint &ip, const char *string, const vpColor &color) { - vp_display_display_char_string(I, ip, string, color); + vp_display_display_text(I, ip, string, color); } /*! - Display a string at the image point (i,j) location. + \deprecated Display a string at the image point (i,j) location. Use rather displayText() that does the same. To select the font used to display the string, use setFont(). @@ -130,8 +131,9 @@ void vpDisplay::displayCharString(const vpImage &I, const vpImagePoint & */ void vpDisplay::displayCharString(const vpImage &I, int i, int j, const char *string, const vpColor &color) { - vp_display_display_char_string(I, i, j, string, color); + vp_display_display_text(I, i, j, string, color); } +#endif /*! Display a circle. @@ -1265,7 +1267,7 @@ void vpDisplay::setBackground(const vpImage &I, const vpColor &color) { /*! Set the font of a text printed in the display overlay. To print a - text you may use displayCharString(). + text you may use displayText(). \param I : Image associated to the display window. \param fontname : The expected font name. diff --git a/modules/core/src/display/vpDisplay_uchar.cpp b/modules/core/src/display/vpDisplay_uchar.cpp index a39acc385c..9206db101f 100644 --- a/modules/core/src/display/vpDisplay_uchar.cpp +++ b/modules/core/src/display/vpDisplay_uchar.cpp @@ -96,8 +96,9 @@ void vpDisplay::displayCamera(const vpImage &I, const vpHomogeneo vp_display_display_camera(I, cMo, cam, size, color, thickness); } +#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) /*! - Display a string at the image point \e ip location. + \deprecated Display a string at the image point \e ip location. Use rather displayText() that does the same. To select the font used to display the string, use setFont(). @@ -112,11 +113,11 @@ void vpDisplay::displayCamera(const vpImage &I, const vpHomogeneo void vpDisplay::displayCharString(const vpImage &I, const vpImagePoint &ip, const char *string, const vpColor &color) { - vp_display_display_char_string(I, ip, string, color); + vp_display_display_text(I, ip, string, color); } /*! - Display a string at the image point (i,j) location. + \deprecated Display a string at the image point (i,j) location. Use rather displayText() that does the same. To select the font used to display the string, use setFont(). @@ -131,8 +132,9 @@ void vpDisplay::displayCharString(const vpImage &I, const vpImage void vpDisplay::displayCharString(const vpImage &I, int i, int j, const char *string, const vpColor &color) { - vp_display_display_char_string(I, i, j, string, color); + vp_display_display_text(I, i, j, string, color); } +#endif /*! Display a circle. @@ -1270,7 +1272,7 @@ void vpDisplay::setBackground(const vpImage &I, const vpColor &co /*! Set the font of a text printed in the display overlay. To print a - text you may use displayCharString(). + text you may use displayText(). \param I : Image associated to the display window. \param fontname : The expected font name. diff --git a/modules/gui/include/visp3/gui/vpDisplayGTK.h b/modules/gui/include/visp3/gui/vpDisplayGTK.h index cef6d6611a..c03b668dff 100644 --- a/modules/gui/include/visp3/gui/vpDisplayGTK.h +++ b/modules/gui/include/visp3/gui/vpDisplayGTK.h @@ -184,7 +184,6 @@ class VISP_EXPORT vpDisplayGTK : public vpDisplay 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) override; - void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color = vpColor::green) override; void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill = false, unsigned int thickness = 1) override; @@ -209,6 +208,8 @@ class VISP_EXPORT vpDisplayGTK : public vpDisplay bool fill = false, unsigned int thickness = 1) override; void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) override; + void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) override; + void flushDisplay() override; void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) override; diff --git a/modules/gui/include/visp3/gui/vpDisplayOpenCV.h b/modules/gui/include/visp3/gui/vpDisplayOpenCV.h index ddc2cdab4b..d7616526a6 100644 --- a/modules/gui/include/visp3/gui/vpDisplayOpenCV.h +++ b/modules/gui/include/visp3/gui/vpDisplayOpenCV.h @@ -225,8 +225,6 @@ class VISP_EXPORT vpDisplayOpenCV : public vpDisplay 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) override; - void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color = vpColor::green) override; - void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill = false, unsigned int thickness = 1) override; void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) override; @@ -250,6 +248,8 @@ class VISP_EXPORT vpDisplayOpenCV : public vpDisplay bool fill = false, unsigned int thickness = 1) override; void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) override; + void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) override; + void flushDisplay() override; void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) override; diff --git a/modules/gui/include/visp3/gui/vpDisplayWin32.h b/modules/gui/include/visp3/gui/vpDisplayWin32.h index 437a803b23..d78d0f2f1d 100644 --- a/modules/gui/include/visp3/gui/vpDisplayWin32.h +++ b/modules/gui/include/visp3/gui/vpDisplayWin32.h @@ -155,8 +155,6 @@ class VISP_EXPORT vpDisplayWin32 : public vpDisplay 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) override; - void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color = vpColor::green) override; - void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill = false, unsigned int thickness = 1) override; @@ -175,6 +173,8 @@ class VISP_EXPORT vpDisplayWin32 : public vpDisplay bool fill = false, unsigned int thickness = 1) override; void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) override; + void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) override; + bool getClick(bool blocking = true) override; bool getClick(vpImagePoint &ip, bool blocking = true) override; bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) override; diff --git a/modules/gui/include/visp3/gui/vpDisplayX.h b/modules/gui/include/visp3/gui/vpDisplayX.h index 3d2b2d3b55..947064f680 100644 --- a/modules/gui/include/visp3/gui/vpDisplayX.h +++ b/modules/gui/include/visp3/gui/vpDisplayX.h @@ -175,8 +175,6 @@ class VISP_EXPORT vpDisplayX : public vpDisplay 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) override; - void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color = vpColor::green) override; - void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill = false, unsigned int thickness = 1) override; void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) override; @@ -200,6 +198,8 @@ class VISP_EXPORT vpDisplayX : public vpDisplay bool fill = false, unsigned int thickness = 1) override; void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) override; + void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) override; + void flushDisplay() override; void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) override; diff --git a/modules/gui/src/display/vpDisplayGTK.cpp b/modules/gui/src/display/vpDisplayGTK.cpp index 7e4fa7da78..fc7ab4cccc 100644 --- a/modules/gui/src/display/vpDisplayGTK.cpp +++ b/modules/gui/src/display/vpDisplayGTK.cpp @@ -276,7 +276,7 @@ class vpDisplayGTK::Impl gdk_flush(); } - void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color, unsigned int scale) + void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color, unsigned int scale) { if (color.id < vpColor::id_unknown) gdk_gc_set_foreground(m_gc, m_col[color.id]); @@ -289,7 +289,7 @@ class vpDisplayGTK::Impl } if (m_font != nullptr) gdk_draw_string(m_background, m_font, m_gc, vpMath::round(ip.get_u() / scale), vpMath::round(ip.get_v() / scale), - (const gchar *)text); + (const gchar *)text.c_str()); else std::cout << "Cannot draw string: no font is selected" << std::endl; } @@ -818,14 +818,14 @@ void vpDisplayGTK::init(unsigned int win_width, unsigned int win_height, int win /*! Set the font used to display a text in overlay. The display is - performed using displayCharString(). + performed using displayText(). \param fontname : The expected font name. \note Under UNIX, to know all the available fonts, use the "xlsfonts" binary in a terminal. You can also use the "xfontsel" binary. - \sa displayCharString() + \sa displayText() */ void vpDisplayGTK::setFont(const std::string &fontname) { m_impl->setFont(fontname); } @@ -1089,15 +1089,16 @@ void vpDisplayGTK::displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2 \sa setFont() */ -void vpDisplayGTK::displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color) +void vpDisplayGTK::displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color) { if (m_displayHasBeenInitialized) { - m_impl->displayCharString(ip, text, color, m_scale); + m_impl->displayText(ip, text, color, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")); } } + /*! Display a circle. \param center : Circle center position. diff --git a/modules/gui/src/display/vpDisplayOpenCV.cpp b/modules/gui/src/display/vpDisplayOpenCV.cpp index 21b7ab1daa..f5b570e8b5 100644 --- a/modules/gui/src/display/vpDisplayOpenCV.cpp +++ b/modules/gui/src/display/vpDisplayOpenCV.cpp @@ -514,7 +514,7 @@ void vpDisplayOpenCV::init(unsigned int w, unsigned int h, int x, int y, const s \warning This method is not yet implemented. Set the font used to display a text in overlay. The display is - performed using displayCharString(). + performed using displayText(). \param font : The expected font name. The available fonts are given by the "xlsfonts" binary. To choose a font you can also use the @@ -523,7 +523,7 @@ void vpDisplayOpenCV::init(unsigned int w, unsigned int h, int x, int y, const s \note Under UNIX, to know all the available fonts, use the "xlsfonts" binary in a terminal. You can also use the "xfontsel" binary. - \sa displayCharString() + \sa displayText() */ void vpDisplayOpenCV::setFont(const std::string & /* font */) { vpERROR_TRACE("Not yet implemented"); } @@ -1137,7 +1137,7 @@ void vpDisplayOpenCV::displayArrow(const vpImagePoint &ip1, const vpImagePoint & \sa setFont() */ -void vpDisplayOpenCV::displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color) +void vpDisplayOpenCV::displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color) { if (m_displayHasBeenInitialized) { if (color.id < vpColor::id_unknown) { diff --git a/modules/gui/src/display/vpDisplayX.cpp b/modules/gui/src/display/vpDisplayX.cpp index 17892fd412..b49df221ed 100644 --- a/modules/gui/src/display/vpDisplayX.cpp +++ b/modules/gui/src/display/vpDisplayX.cpp @@ -76,12 +76,11 @@ class vpDisplayX::Impl public: Impl() : display(nullptr), window(), Ximage(nullptr), lut(), context(), screen(0), event(), pixmap(), x_color(nullptr), - screen_depth(8), xcolor(), values(), ximage_data_init(false), RMask(0), GMask(0), BMask(0), RShift(0), GShift(0), - BShift(0) - { - } + screen_depth(8), xcolor(), values(), ximage_data_init(false), RMask(0), GMask(0), BMask(0), RShift(0), GShift(0), + BShift(0) + { } - ~Impl() {} + ~Impl() { } void clearDisplay(const vpColor &color, unsigned int width, unsigned int height) { @@ -123,7 +122,7 @@ class vpDisplayX::Impl } } - void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color, unsigned int scale) + void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color, unsigned int scale) { if (color.id < vpColor::id_unknown) XSetForeground(display, context, x_color[color.id]); @@ -135,8 +134,8 @@ class vpDisplayX::Impl XAllocColor(display, lut, &xcolor); XSetForeground(display, context, xcolor.pixel); } - XDrawString(display, pixmap, context, (int)(ip.get_u() / scale), (int)(ip.get_v() / scale), text, - (int)strlen(text)); + XDrawString(display, pixmap, context, (int)(ip.get_u() / scale), (int)(ip.get_v() / scale), text.c_str(), + (int)text.size()); } void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill, @@ -159,7 +158,8 @@ class vpDisplayX::Impl XDrawArc(display, pixmap, context, vpMath::round((center.get_u() - radius) / scale), vpMath::round((center.get_v() - radius) / scale), radius * 2 / scale, radius * 2 / scale, 0, 23040); /* 23040 = 360*64 */ - } else { + } + else { XFillArc(display, pixmap, context, vpMath::round((center.get_u() - radius) / scale), vpMath::round((center.get_v() - radius) / scale), radius * 2 / scale, radius * 2 / scale, 0, 23040); /* 23040 = 360*64 */ @@ -207,9 +207,10 @@ class vpDisplayX::Impl dst_8[i] = nivGris; i++; } - } else { - // Correction de l'image de facon a liberer les niveaux de gris - // ROUGE, VERT, BLEU, JAUNE + } + else { + // Correction de l'image de facon a liberer les niveaux de gris + // ROUGE, VERT, BLEU, JAUNE unsigned char *dst_8 = (unsigned char *)Ximage->data; unsigned int k = 0; for (unsigned int i = 0; i < height; i++) { @@ -238,7 +239,8 @@ class vpDisplayX::Impl *(dst_16 + j) = (unsigned short)colortable[I[i][j]]; } } - } else { + } + else { for (unsigned int i = 0; i < height; i++) { unsigned char *dst_8 = (unsigned char *)Ximage->data + i * bytes_per_line; unsigned short *dst_16 = (unsigned short *)dst_8; @@ -272,8 +274,9 @@ class vpDisplayX::Impl *(dst_32++) = val; // Green *(dst_32++) = val; // Blue } - } else { - // little endian + } + else { + // little endian while (bitmap < n) { unsigned char val = *(bitmap++); *(dst_32++) = val; // Blue @@ -282,7 +285,8 @@ class vpDisplayX::Impl *(dst_32++) = vpRGBa::alpha_default; } } - } else { + } + else { if (XImageByteOrder(display) == 1) { // big endian for (unsigned int i = 0; i < height; i++) { @@ -294,8 +298,9 @@ class vpDisplayX::Impl *(dst_32++) = val; // Blue } } - } else { - // little endian + } + else { + // little endian for (unsigned int i = 0; i < height; i++) { for (unsigned int j = 0; j < width; j++) { unsigned char val = I[i * scale][j * scale]; @@ -333,11 +338,12 @@ class vpDisplayX::Impl g = bitmap->G; b = bitmap->B; *(dst_16 + j) = - (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask); + (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask); bitmap++; } } - } else { + } + else { for (unsigned int i = 0; i < height; i++) { unsigned char *dst_8 = (unsigned char *)Ximage->data + i * bytes_per_line; unsigned short *dst_16 = (unsigned short *)dst_8; @@ -347,7 +353,7 @@ class vpDisplayX::Impl g = val.G; b = val.B; *(dst_16 + j) = - (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask); + (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask); bitmap++; } } @@ -377,8 +383,9 @@ class vpDisplayX::Impl *(dst_32++) = bitmap->B; bitmap++; } - } else { - // little endian + } + else { + // little endian for (unsigned int i = 0; i < sizeI; i++) { *(dst_32++) = bitmap->B; *(dst_32++) = bitmap->G; @@ -387,7 +394,8 @@ class vpDisplayX::Impl bitmap++; } } - } else { + } + else { if (XImageByteOrder(display) == 1) { // big endian for (unsigned int i = 0; i < height; i++) { @@ -399,8 +407,9 @@ class vpDisplayX::Impl *(dst_32++) = val.B; } } - } else { - // little endian + } + else { + // little endian for (unsigned int i = 0; i < height; i++) { for (unsigned int j = 0; j < width; j++) { vpRGBa val = I[i * scale][j * scale]; @@ -474,9 +483,10 @@ class vpDisplayX::Impl XPutImage(display, pixmap, context, Ximage, (int)iP.get_u(), (int)iP.get_v(), (int)iP.get_u(), (int)iP.get_v(), w, h); - } else { - // Correction de l'image de facon a liberer les niveaux de gris - // ROUGE, VERT, BLEU, JAUNE + } + else { + // Correction de l'image de facon a liberer les niveaux de gris + // ROUGE, VERT, BLEU, JAUNE int i_min = (std::max)((int)ceil(iP.get_i() / scale), 0); int j_min = (std::max)((int)ceil(iP.get_j() / scale), 0); int i_max = (std::min)((int)ceil((iP.get_i() + h) / scale), (int)height); @@ -517,7 +527,8 @@ class vpDisplayX::Impl XPutImage(display, pixmap, context, Ximage, (int)iP.get_u(), (int)iP.get_v(), (int)iP.get_u(), (int)iP.get_v(), w, h); - } else { + } + else { int i_min = (std::max)((int)ceil(iP.get_i() / scale), 0); int j_min = (std::max)((int)ceil(iP.get_j() / scale), 0); int i_max = (std::min)((int)ceil((iP.get_i() + h) / scale), (int)height); @@ -567,8 +578,9 @@ class vpDisplayX::Impl dst_32 = dst_32 + 4 * width; i++; } - } else { - // little endian + } + else { + // little endian unsigned int i = 0; while (i < h) { unsigned int j = 0; @@ -588,7 +600,8 @@ class vpDisplayX::Impl XPutImage(display, pixmap, context, Ximage, (int)iP.get_u(), (int)iP.get_v(), (int)iP.get_u(), (int)iP.get_v(), w, h); - } else { + } + else { int i_min = (std::max)((int)ceil(iP.get_i() / scale), 0); int j_min = (std::max)((int)ceil(iP.get_j() / scale), 0); int i_max = (std::min)((int)ceil((iP.get_i() + h) / scale), (int)height); @@ -611,8 +624,9 @@ class vpDisplayX::Impl *(dst_32++) = val; } } - } else { - // little endian + } + else { + // little endian for (unsigned int i = i_min_; i < i_max_; i++) { unsigned char *dst_32 = (unsigned char *)Ximage->data + (int)(i * 4 * width + j_min_ * 4); for (unsigned int j = j_min_; j < j_max_; j++) { @@ -650,12 +664,13 @@ class vpDisplayX::Impl unsigned int g = val.G; unsigned int b = val.B; *(dst_16 + j) = - (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask); + (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask); } } XPutImage(display, pixmap, context, Ximage, (int)iP.get_u(), (int)iP.get_v(), (int)iP.get_u(), (int)iP.get_v(), w, h); - } else { + } + else { unsigned int bytes_per_line = (unsigned int)Ximage->bytes_per_line; int i_min = (std::max)((int)ceil(iP.get_i() / scale), 0); int j_min = (std::max)((int)ceil(iP.get_j() / scale), 0); @@ -676,7 +691,7 @@ class vpDisplayX::Impl unsigned int g = val.G; unsigned int b = val.B; *(dst_16 + j) = - (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask); + (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask); } } XPutImage(display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_); @@ -720,8 +735,9 @@ class vpDisplayX::Impl i++; } - } else { - // little endian + } + else { + // little endian while (i < h) { unsigned int j = 0; while (j < w) { @@ -740,7 +756,8 @@ class vpDisplayX::Impl XPutImage(display, pixmap, context, Ximage, (int)iP.get_u(), (int)iP.get_v(), (int)iP.get_u(), (int)iP.get_v(), w, h); - } else { + } + else { int i_min = (std::max)((int)ceil(iP.get_i() / scale), 0); int j_min = (std::max)((int)ceil(iP.get_j() / scale), 0); int i_max = (std::min)((int)ceil((iP.get_i() + h) / scale), (int)height); @@ -763,8 +780,9 @@ class vpDisplayX::Impl *(dst_32++) = val.B; } } - } else { - // little endian + } + else { + // little endian for (unsigned int i = i_min_; i < i_max_; i++) { unsigned char *dst_32 = (unsigned char *)Ximage->data + (int)(i * 4 * width + j_min_ * 4); for (unsigned int j = j_min_; j < j_max_; j++) { @@ -823,7 +841,8 @@ class vpDisplayX::Impl if (thickness == 1) { XDrawPoint(display, pixmap, context, vpMath::round(ip.get_u() / scale), vpMath::round(ip.get_v() / scale)); - } else { + } + else { XFillRectangle(display, pixmap, context, vpMath::round(ip.get_u() / scale), vpMath::round(ip.get_v() / scale), thickness, thickness); } @@ -846,7 +865,8 @@ class vpDisplayX::Impl if (fill == false) { XDrawRectangle(display, pixmap, context, vpMath::round(topLeft.get_u() / scale), vpMath::round(topLeft.get_v() / scale), w / scale, h / scale); - } else { + } + else { XFillRectangle(display, pixmap, context, vpMath::round(topLeft.get_u() / scale), vpMath::round(topLeft.get_v() / scale), w / scale, h / scale); } @@ -877,7 +897,8 @@ class vpDisplayX::Impl XCheckMaskEvent(display, ButtonReleaseMask, &event); XMaskEvent(display, ButtonPressMask, &event); ret = true; - } else { + } + else { ret = XCheckMaskEvent(display, ButtonPressMask, &event); } @@ -916,7 +937,8 @@ class vpDisplayX::Impl XCheckMaskEvent(display, ButtonReleaseMask, &event); XMaskEvent(display, ButtonReleaseMask, &event); ret = true; - } else { + } + else { ret = XCheckMaskEvent(display, ButtonReleaseMask, &event); } @@ -971,7 +993,8 @@ class vpDisplayX::Impl } } - } else { + } + else { if (XImageByteOrder(display) == 1) { // big endian for (unsigned int i = 0; i < width * height; i++) { @@ -983,8 +1006,9 @@ class vpDisplayX::Impl I.bitmap[i].G = src_32[i * 4 + 2]; I.bitmap[i].B = src_32[i * 4 + 3]; } - } else { - // little endian + } + else { + // little endian for (unsigned int i = 0; i < width * height; i++) { I.bitmap[i].B = src_32[i * 4]; I.bitmap[i].G = src_32[i * 4 + 1]; @@ -1007,7 +1031,8 @@ class vpDisplayX::Impl if (blocking) { XMaskEvent(display, KeyPressMask, &event); ret = true; - } else { + } + else { ret = XCheckMaskEvent(display, KeyPressMask, &event); } @@ -1028,7 +1053,8 @@ class vpDisplayX::Impl /* count = */ XLookupString((XKeyEvent *)&event, &buffer, 1, &keysym, &compose_status); key = buffer; ret = true; - } else { + } + else { ret = XCheckMaskEvent(display, KeyPressMask, &event); if (ret) { /* count = */ XLookupString((XKeyEvent *)&event, &buffer, 1, &keysym, &compose_status); @@ -1141,7 +1167,8 @@ class vpDisplayX::Impl // Positionnement de la fenetre dans l'ecran. if ((win_x < 0) || (win_y < 0)) { hints.flags = 0; - } else { + } + else { hints.flags = USPosition; hints.x = win_x; hints.y = win_y; @@ -1565,7 +1592,8 @@ class vpDisplayX::Impl Font stringfont; stringfont = XLoadFont(display, fontname.c_str()); //"-adobe-times-bold-r-normal--18*"); XSetFont(display, context, stringfont); - } catch (...) { + } + catch (...) { throw(vpDisplayException(vpDisplayException::notInitializedError, "Bad font")); } } @@ -1749,7 +1777,7 @@ int main() } \endcode */ -vpDisplayX::vpDisplayX() : vpDisplay(), m_impl(new Impl()) {} +vpDisplayX::vpDisplayX() : vpDisplay(), m_impl(new Impl()) { } /*! Destructor. @@ -1847,7 +1875,7 @@ void vpDisplayX::init(unsigned int win_width, unsigned int win_height, int win_x /*! Set the font used to display a text in overlay. The display is - performed using displayCharString(). + performed using displayText(). \param fontname : The expected font name. The available fonts are given by the "xlsfonts" binary. To choose a font you can also use the @@ -1856,7 +1884,7 @@ void vpDisplayX::init(unsigned int win_width, unsigned int win_height, int win_x \note Under UNIX, to know all the available fonts, use the "xlsfonts" binary in a terminal. You can also use the "xfontsel" binary. - \sa displayCharString() + \sa displayText() */ void vpDisplayX::setFont(const std::string &fontname) { @@ -1864,7 +1892,8 @@ void vpDisplayX::setFont(const std::string &fontname) if (!fontname.empty()) { m_impl->setFont(fontname); } - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -1879,7 +1908,8 @@ void vpDisplayX::setTitle(const std::string &title) m_title = title; if (!title.empty()) m_impl->setTitle(title); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -1897,7 +1927,8 @@ void vpDisplayX::setWindowPosition(int win_x, int win_y) { if (m_displayHasBeenInitialized) { m_impl->setWindowPosition(win_x, win_y); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -1917,7 +1948,8 @@ void vpDisplayX::displayImage(const vpImage &I) { if (m_displayHasBeenInitialized) { m_impl->displayImage(I, m_scale, m_width, m_height); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -1937,7 +1969,8 @@ void vpDisplayX::displayImage(const vpImage &I) { if (m_displayHasBeenInitialized) { m_impl->displayImage(I, m_scale, m_width, m_height); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -1957,7 +1990,8 @@ void vpDisplayX::displayImage(const unsigned char *bitmap) { if (m_displayHasBeenInitialized) { m_impl->displayImage(bitmap, m_width, m_height); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -1982,7 +2016,8 @@ void vpDisplayX::displayImageROI(const vpImage &I, const vpImageP { if (m_displayHasBeenInitialized) { m_impl->displayImageROI(I, iP, w, h, m_scale, m_width, m_height); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2006,7 +2041,8 @@ void vpDisplayX::displayImageROI(const vpImage &I, const vpImagePoint &i { if (m_displayHasBeenInitialized) { m_impl->displayImageROI(I, iP, w, h, m_scale, m_width, m_height); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2036,7 +2072,8 @@ void vpDisplayX::flushDisplay() { if (m_displayHasBeenInitialized) { m_impl->flushDisplay(); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2052,7 +2089,8 @@ void vpDisplayX::flushDisplayROI(const vpImagePoint &iP, unsigned int w, unsigne { if (m_displayHasBeenInitialized) { m_impl->flushDisplayROI(iP, w, h, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2065,7 +2103,8 @@ void vpDisplayX::clearDisplay(const vpColor &color) { if (m_displayHasBeenInitialized) { m_impl->clearDisplay(color, m_width, m_height); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2089,7 +2128,8 @@ void vpDisplayX::displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, if ((std::fabs(a) <= std::numeric_limits::epsilon()) && (std::fabs(b) <= std::numeric_limits::epsilon())) { // DisplayCrossLarge(i1,j1,3,col) ; - } else { + } + else { a /= lg; b /= lg; @@ -2112,7 +2152,8 @@ void vpDisplayX::displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, displayLine(ip1, ip2, color, thickness); } - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2128,11 +2169,12 @@ void vpDisplayX::displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, \sa setFont() */ -void vpDisplayX::displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color) +void vpDisplayX::displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color) { if (m_displayHasBeenInitialized) { - m_impl->displayCharString(ip, text, color, m_scale); - } else { + m_impl->displayText(ip, text, color, m_scale); + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2153,7 +2195,8 @@ void vpDisplayX::displayCircle(const vpImagePoint ¢er, unsigned int radius, if (thickness == 1) thickness = 0; m_impl->displayCircle(center, radius, color, fill, thickness, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2185,7 +2228,8 @@ void vpDisplayX::displayCross(const vpImagePoint &ip, unsigned int cross_size, c ip2.set_j(j + cross_size / 2); displayLine(ip1, ip2, color, thickness); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2203,7 +2247,8 @@ void vpDisplayX::displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2 thickness = 0; m_impl->displayDotLine(ip1, ip2, color, thickness, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2221,7 +2266,8 @@ void vpDisplayX::displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, c if (thickness == 1) thickness = 0; m_impl->displayLine(ip1, ip2, color, thickness, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2236,7 +2282,8 @@ void vpDisplayX::displayPoint(const vpImagePoint &ip, const vpColor &color, unsi { if (m_displayHasBeenInitialized) { m_impl->displayPoint(ip, color, thickness, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2262,7 +2309,8 @@ void vpDisplayX::displayRectangle(const vpImagePoint &topLeft, unsigned int w, u thickness = 0; m_impl->displayRectangle(topLeft, w, h, color, fill, thickness, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2290,7 +2338,8 @@ void vpDisplayX::displayRectangle(const vpImagePoint &topLeft, const vpImagePoin unsigned int h = static_cast(vpMath::round(bottomRight.get_v() - topLeft.get_v())); m_impl->displayRectangle(topLeft, w, h, color, fill, thickness, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2316,7 +2365,8 @@ void vpDisplayX::displayRectangle(const vpRect &rectangle, const vpColor &color, unsigned int w = static_cast(vpMath::round(rectangle.getWidth())); unsigned int h = static_cast(vpMath::round(rectangle.getHeight())); m_impl->displayRectangle(topLeft, w, h, color, fill, thickness, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2344,7 +2394,8 @@ bool vpDisplayX::getClick(bool blocking) vpImagePoint ip; vpMouseButton::vpMouseButtonType button; ret = m_impl->getClick(ip, button, blocking, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } return ret; @@ -2372,7 +2423,8 @@ bool vpDisplayX::getClick(vpImagePoint &ip, bool blocking) if (m_displayHasBeenInitialized) { vpMouseButton::vpMouseButtonType button; ret = m_impl->getClick(ip, button, blocking, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } return ret; @@ -2403,7 +2455,8 @@ bool vpDisplayX::getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &bu if (m_displayHasBeenInitialized) { ret = m_impl->getClick(ip, button, blocking, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } return ret; @@ -2438,7 +2491,8 @@ bool vpDisplayX::getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType & if (m_displayHasBeenInitialized) { ret = m_impl->getClickUp(ip, button, blocking, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } return ret; @@ -2455,7 +2509,8 @@ void vpDisplayX::getImage(vpImage &I) { if (m_displayHasBeenInitialized) { m_impl->getImage(I, m_width, m_height); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } } @@ -2517,7 +2572,8 @@ bool vpDisplayX::getKeyboardEvent(bool blocking) if (m_displayHasBeenInitialized) { ret = m_impl->getKeyboardEvent(blocking); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } return ret; @@ -2551,7 +2607,8 @@ bool vpDisplayX::getKeyboardEvent(std::string &key, bool blocking) bool ret = false; if (m_displayHasBeenInitialized) { ret = m_impl->getKeyboardEvent(key, blocking); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } return ret; @@ -2574,7 +2631,8 @@ bool vpDisplayX::getPointerMotionEvent(vpImagePoint &ip) bool ret = false; if (m_displayHasBeenInitialized) { ret = m_impl->getPointerMotionEvent(ip, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } return ret; @@ -2595,7 +2653,8 @@ bool vpDisplayX::getPointerPosition(vpImagePoint &ip) bool ret = false; if (m_displayHasBeenInitialized) { ret = m_impl->getPointerPosition(ip, m_scale); - } else { + } + else { throw(vpDisplayException(vpDisplayException::notInitializedError, "X not initialized")); } return ret; @@ -2604,5 +2663,5 @@ bool vpDisplayX::getPointerPosition(vpImagePoint &ip) #elif !defined(VISP_BUILD_SHARED_LIBS) // Work around to avoid warning: libvisp_core.a(vpDisplayX.cpp.o) has no // symbols -void dummy_vpDisplayX(){}; +void dummy_vpDisplayX() { }; #endif diff --git a/modules/gui/src/display/windows/vpDisplayWin32.cpp b/modules/gui/src/display/windows/vpDisplayWin32.cpp index dc0ffd0e4c..410db2674f 100644 --- a/modules/gui/src/display/windows/vpDisplayWin32.cpp +++ b/modules/gui/src/display/windows/vpDisplayWin32.cpp @@ -59,7 +59,7 @@ void vpCreateWindow(threadParam *param) /*! Constructor. */ -vpDisplayWin32::vpDisplayWin32(vpWin32Renderer *rend) : iStatus(false), window(rend) {} +vpDisplayWin32::vpDisplayWin32(vpWin32Renderer *rend) : iStatus(false), window(rend) { } /*! Destructor. @@ -301,7 +301,8 @@ bool vpDisplayWin32::getClick(bool blocking) WaitForSingleObject(window.semaClickUp, 0); // to erase previous events WaitForSingleObject(window.semaClick, INFINITE); ret = true; - } else { + } + else { ret = (WAIT_OBJECT_0 == WaitForSingleObject(window.semaClick, 0)); } @@ -339,7 +340,8 @@ bool vpDisplayWin32::getClick(vpImagePoint &ip, bool blocking) WaitForSingleObject(window.semaClickUp, 0); // to erase previous events WaitForSingleObject(window.semaClick, INFINITE); ret = true; - } else { + } + else { ret = (WAIT_OBJECT_0 == WaitForSingleObject(window.semaClick, 0)); } @@ -383,7 +385,8 @@ bool vpDisplayWin32::getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType WaitForSingleObject(window.semaClickUp, 0); // to erase previous events WaitForSingleObject(window.semaClick, INFINITE); ret = true; - } else + } + else ret = (WAIT_OBJECT_0 == WaitForSingleObject(window.semaClick, 0)); u = window.clickX; @@ -432,7 +435,8 @@ bool vpDisplayWin32::getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonTy WaitForSingleObject(window.semaClick, 0); // to erase previous events WaitForSingleObject(window.semaClickUp, INFINITE); ret = true; - } else + } + else ret = (WAIT_OBJECT_0 == WaitForSingleObject(window.semaClickUp, 0)); u = window.clickXUp; @@ -471,7 +475,8 @@ bool vpDisplayWin32::getKeyboardEvent(bool blocking) WaitForSingleObject(window.semaKey, 0); // key up WaitForSingleObject(window.semaKey, INFINITE); ret = true; - } else + } + else ret = (WAIT_OBJECT_0 == WaitForSingleObject(window.semaKey, 0)); return ret; @@ -507,7 +512,8 @@ bool vpDisplayWin32::getKeyboardEvent(std::string &key, bool blocking) WaitForSingleObject(window.semaKey, 0); // key up WaitForSingleObject(window.semaKey, INFINITE); ret = true; - } else { + } + else { ret = (WAIT_OBJECT_0 == WaitForSingleObject(window.semaKey, 0)); } // printf("key: %ud\n", window.key); @@ -664,7 +670,8 @@ void vpDisplayWin32::displayPoint(const vpImagePoint &ip, const vpColor &color, waitForInit(); if (thickness == 1) { window.renderer->setPixel(ip, color); - } else { + } + else { window.renderer->drawRect(ip, thickness * m_scale, thickness * m_scale, color, true, 1); } } @@ -788,11 +795,11 @@ void vpDisplayWin32::displayCircle(const vpImagePoint ¢er, unsigned int radi \param text : The string to display \param color : The text's color */ -void vpDisplayWin32::displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color) +void vpDisplayWin32::displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color) { // wait if the window is not initialized waitForInit(); - window.renderer->drawText(ip, text, color); + window.renderer->drawText(ip, text.c_str(), color); } /*! @@ -901,5 +908,5 @@ unsigned int vpDisplayWin32::getScreenHeight() #elif !defined(VISP_BUILD_SHARED_LIBS) // Work around to avoid warning: libvisp_core.a(vpDisplayWin32.cpp.o) has no // symbols -void dummy_vpDisplayWin32(){}; +void dummy_vpDisplayWin32() { }; #endif From 1e8dc60d19f425575307d1e269ab1c0c697e72b9 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 16 Nov 2023 14:47:22 +0100 Subject: [PATCH 6/9] Fix build issue when BUILD_DEPRECATED_FUNCTIONS is turned off. Closes #1273 --- ChangeLog.txt | 1 + .../visp3/detection/vpDetectorAprilTag.h | 16 +++- .../detection/src/tag/vpDetectorAprilTag.cpp | 75 ++++++++++--------- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 1604acbdf1..c066fca42c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -28,6 +28,7 @@ ViSP 3.x.x (Version in development) . [#1270] Build issue around std::clamp and optional header which are not found with cxx17 standard enabled . [#1272] Unable to build ViSP with PCL/VTK build from source, VTK headers are not found by ViSP + . [#1273] Build error in visp_java without deprecated functionalities ---------------------------------------------- ViSP 3.6.0 (released September 22, 2023) - Contributors: diff --git a/modules/detection/include/visp3/detection/vpDetectorAprilTag.h b/modules/detection/include/visp3/detection/vpDetectorAprilTag.h index e440dac32f..92fdda86f2 100644 --- a/modules/detection/include/visp3/detection/vpDetectorAprilTag.h +++ b/modules/detection/include/visp3/detection/vpDetectorAprilTag.h @@ -286,14 +286,22 @@ class VISP_EXPORT vpDetectorAprilTag : public vpDetectorBase void setAprilTagPoseEstimationMethod(const vpPoseEstimationMethod &poseEstimationMethod); void setAprilTagQuadDecimate(float quadDecimate); void setAprilTagQuadSigma(float quadSigma); - void setAprilTagRefineDecode(bool refineDecode); void setAprilTagRefineEdges(bool refineEdges); - void setAprilTagRefinePose(bool refinePose); +#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) /*! - * Allow to enable the display of overlay tag information in the windows - * (vpDisplay) associated to the input image. + * @name Deprecated functions */ + //@{ + vp_deprecated void setAprilTagRefineDecode(bool refineDecode); + vp_deprecated void setAprilTagRefinePose(bool refinePose); + //@} +#endif + +/*! + * Allow to enable the display of overlay tag information in the windows + * (vpDisplay) associated to the input image. + */ inline void setDisplayTag(bool display, const vpColor &color = vpColor::none, unsigned int thickness = 2) { m_displayTag = display; diff --git a/modules/detection/src/tag/vpDetectorAprilTag.cpp b/modules/detection/src/tag/vpDetectorAprilTag.cpp index b8feb4efdc..0b435a8449 100644 --- a/modules/detection/src/tag/vpDetectorAprilTag.cpp +++ b/modules/detection/src/tag/vpDetectorAprilTag.cpp @@ -66,7 +66,7 @@ class vpDetectorAprilTag::Impl public: Impl(const vpAprilTagFamily &tagFamily, const vpPoseEstimationMethod &method) : m_poseEstimationMethod(method), m_tagsId(), m_tagFamily(tagFamily), m_td(nullptr), m_tf(nullptr), m_detections(nullptr), - m_zAlignedWithCameraFrame(false) + m_zAlignedWithCameraFrame(false) { switch (m_tagFamily) { case TAG_36h11: @@ -135,7 +135,7 @@ class vpDetectorAprilTag::Impl Impl(const Impl &o) : m_poseEstimationMethod(o.m_poseEstimationMethod), m_tagsId(o.m_tagsId), m_tagFamily(o.m_tagFamily), m_td(nullptr), - m_tf(nullptr), m_detections(nullptr), m_zAlignedWithCameraFrame(o.m_zAlignedWithCameraFrame) + m_tf(nullptr), m_detections(nullptr), m_zAlignedWithCameraFrame(o.m_zAlignedWithCameraFrame) { switch (m_tagFamily) { case TAG_36h11: @@ -301,7 +301,7 @@ class vpDetectorAprilTag::Impl if (m_tagFamily == TAG_CIRCLE49h12 || m_tagFamily == TAG_CUSTOM48h12 || m_tagFamily == TAG_STANDARD41h12 || m_tagFamily == TAG_STANDARD52h13) { std::cerr << "TAG_CIRCLE49h12, TAG_CUSTOM48h12, TAG_STANDARD41h12 and TAG_STANDARD52h13 are disabled." - << std::endl; + << std::endl; return false; } #endif @@ -309,9 +309,9 @@ class vpDetectorAprilTag::Impl const bool computePose = (cMo_vec != nullptr); image_u8_t im = {/*.width =*/(int32_t)I.getWidth(), - /*.height =*/(int32_t)I.getHeight(), - /*.stride =*/(int32_t)I.getWidth(), - /*.buf =*/I.bitmap}; + /*.height =*/(int32_t)I.getHeight(), + /*.stride =*/(int32_t)I.getWidth(), + /*.buf =*/I.bitmap }; if (m_detections) { apriltag_detections_destroy(m_detections); @@ -458,7 +458,7 @@ class vpDetectorAprilTag::Impl if (m_tagFamily == TAG_CIRCLE49h12 || m_tagFamily == TAG_CUSTOM48h12 || m_tagFamily == TAG_STANDARD41h12 || m_tagFamily == TAG_STANDARD52h13) { std::cerr << "TAG_CIRCLE49h12, TAG_CUSTOM48h12, TAG_STANDARD41h12 and TAG_STANDARD52h13 are disabled." - << std::endl; + << std::endl; return false; } #endif @@ -563,7 +563,7 @@ class vpDetectorAprilTag::Impl vpHomogeneousMatrix cMo_dementhon, cMo_lagrange; double residual_dementhon = std::numeric_limits::max(), - residual_lagrange = std::numeric_limits::max(); + residual_lagrange = std::numeric_limits::max(); double residual_homography = pose.computeResidual(cMo_homography); double residual_homography_ortho_iter = pose.computeResidual(cMo_homography_ortho_iter); @@ -588,7 +588,8 @@ class vpDetectorAprilTag::Impl std::ptrdiff_t minIndex = std::min_element(residuals.begin(), residuals.end()) - residuals.begin(); cMo = *(poses.begin() + minIndex); - } else { + } + else { pose.computePose(m_mapOfCorrespondingPoseMethods[m_poseEstimationMethod], cMo); } } @@ -602,16 +603,16 @@ class vpDetectorAprilTag::Impl if (m_poseEstimationMethod != HOMOGRAPHY_ORTHOGONAL_ITERATION) { if (cMo2) { double scale = tagSize / 2.0; - double data_p0[] = {-scale, scale, 0}; - double data_p1[] = {scale, scale, 0}; - double data_p2[] = {scale, -scale, 0}; - double data_p3[] = {-scale, -scale, 0}; - matd_t *p[4] = {matd_create_data(3, 1, data_p0), matd_create_data(3, 1, data_p1), - matd_create_data(3, 1, data_p2), matd_create_data(3, 1, data_p3)}; + double data_p0[] = { -scale, scale, 0 }; + double data_p1[] = { scale, scale, 0 }; + double data_p2[] = { scale, -scale, 0 }; + double data_p3[] = { -scale, -scale, 0 }; + matd_t *p[4] = { matd_create_data(3, 1, data_p0), matd_create_data(3, 1, data_p1), + matd_create_data(3, 1, data_p2), matd_create_data(3, 1, data_p3) }; matd_t *v[4]; for (int i = 0; i < 4; i++) { - double data_v[] = {(det->p[i][0] - cam.get_u0()) / cam.get_px(), (det->p[i][1] - cam.get_v0()) / cam.get_py(), - 1}; + double data_v[] = { (det->p[i][0] - cam.get_u0()) / cam.get_px(), (det->p[i][1] - cam.get_v0()) / cam.get_py(), + 1 }; v[i] = matd_create_data(3, 1, data_v); } @@ -680,11 +681,13 @@ class vpDetectorAprilTag::Impl if (cMo2) { if (pose2.R) { convertHomogeneousMatrix(pose2, *cMo2); - } else { + } + else { *cMo2 = cMo1; } } - } else { + } + else { convertHomogeneousMatrix(pose2, cMo1); if (cMo2) { convertHomogeneousMatrix(pose1, *cMo2); @@ -783,7 +786,7 @@ class vpDetectorAprilTag::Impl } } - void setRefineDecode(bool) {} + void setRefineDecode(bool) { } void setRefineEdges(bool refineEdges) { @@ -792,7 +795,7 @@ class vpDetectorAprilTag::Impl } } - void setRefinePose(bool) {} + void setRefinePose(bool) { } void setPoseEstimationMethod(const vpPoseEstimationMethod &method) { m_poseEstimationMethod = method; } @@ -813,17 +816,15 @@ class vpDetectorAprilTag::Impl vpDetectorAprilTag::vpDetectorAprilTag(const vpAprilTagFamily &tagFamily, const vpPoseEstimationMethod &poseEstimationMethod) : m_displayTag(false), m_displayTagColor(vpColor::none), m_displayTagThickness(2), - m_poseEstimationMethod(poseEstimationMethod), m_tagFamily(tagFamily), m_defaultCam(), - m_impl(new Impl(tagFamily, poseEstimationMethod)) -{ -} + m_poseEstimationMethod(poseEstimationMethod), m_tagFamily(tagFamily), m_defaultCam(), + m_impl(new Impl(tagFamily, poseEstimationMethod)) +{ } vpDetectorAprilTag::vpDetectorAprilTag(const vpDetectorAprilTag &o) : vpDetectorBase(o), m_displayTag(false), m_displayTagColor(vpColor::none), m_displayTagThickness(2), - m_poseEstimationMethod(o.m_poseEstimationMethod), m_tagFamily(o.m_tagFamily), m_defaultCam(), - m_impl(new Impl(*o.m_impl)) -{ -} + m_poseEstimationMethod(o.m_poseEstimationMethod), m_tagFamily(o.m_tagFamily), m_defaultCam(), + m_impl(new Impl(*o.m_impl)) +{ } vpDetectorAprilTag &vpDetectorAprilTag::operator=(vpDetectorAprilTag o) { @@ -1026,7 +1027,8 @@ std::vector > vpDetectorAprilTag::getTagsPoints3D(const std throw(vpException(vpException::fatalError, "Tag with id %d has no 3D size or there is no default 3D size defined", tagsId[i])); } - } else { + } + else { tagSize = it->second; } std::vector points3D(4); @@ -1035,7 +1037,8 @@ std::vector > vpDetectorAprilTag::getTagsPoints3D(const std points3D[1] = vpPoint(tagSize / 2, tagSize / 2, 0); points3D[2] = vpPoint(tagSize / 2, -tagSize / 2, 0); points3D[3] = vpPoint(-tagSize / 2, -tagSize / 2, 0); - } else { + } + else { points3D[0] = vpPoint(-tagSize / 2, -tagSize / 2, 0); points3D[1] = vpPoint(tagSize / 2, -tagSize / 2, 0); points3D[2] = vpPoint(tagSize / 2, tagSize / 2, 0); @@ -1144,9 +1147,9 @@ void vpDetectorAprilTag::setAprilTagQuadSigma(float quadSigma) { m_impl->setQuad #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) /*! - Deprecated parameter from AprilTag 2 version. + \deprecated Deprecated parameter from AprilTag 2 version. */ -vp_deprecated void vpDetectorAprilTag::setAprilTagRefineDecode(bool refineDecode) +void vpDetectorAprilTag::setAprilTagRefineDecode(bool refineDecode) { m_impl->setRefineDecode(refineDecode); } @@ -1170,9 +1173,9 @@ void vpDetectorAprilTag::setAprilTagRefineEdges(bool refineEdges) { m_impl->setR #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) /*! - Deprecated parameter from AprilTag 2 version. + \deprecated Deprecated parameter from AprilTag 2 version. */ -vp_deprecated void vpDetectorAprilTag::setAprilTagRefinePose(bool refinePose) { m_impl->setRefinePose(refinePose); } +void vpDetectorAprilTag::setAprilTagRefinePose(bool refinePose) { m_impl->setRefinePose(refinePose); } #endif void swap(vpDetectorAprilTag &o1, vpDetectorAprilTag &o2) @@ -1195,5 +1198,5 @@ void vpDetectorAprilTag::setZAlignedWithCameraAxis(bool zAlignedWithCameraFrame) #elif !defined(VISP_BUILD_SHARED_LIBS) // Work around to avoid warning: libvisp_core.a(vpDetectorAprilTag.cpp.o) has // no symbols -void dummy_vpDetectorAprilTag() {} +void dummy_vpDetectorAprilTag() { } #endif From ef4e8762094c17ddd911e7efe4affa83ff79a940 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 16 Nov 2023 15:23:03 +0100 Subject: [PATCH 7/9] Fix build issue no member named clamp in namespace std. Closes #1274 --- ChangeLog.txt | 1 + modules/core/include/visp3/core/vpMath.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c066fca42c..a576aa0735 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -29,6 +29,7 @@ ViSP 3.x.x (Version in development) standard enabled . [#1272] Unable to build ViSP with PCL/VTK build from source, VTK headers are not found by ViSP . [#1273] Build error in visp_java without deprecated functionalities + . [#1274] Build issue no member named clamp in namespace std ---------------------------------------------- ViSP 3.6.0 (released September 22, 2023) - Contributors: diff --git a/modules/core/include/visp3/core/vpMath.h b/modules/core/include/visp3/core/vpMath.h index c321b18266..a5090f40c5 100644 --- a/modules/core/include/visp3/core/vpMath.h +++ b/modules/core/include/visp3/core/vpMath.h @@ -215,7 +215,10 @@ class VISP_EXPORT vpMath */ template static inline T clamp(const T &v, const T &lower, const T &upper) { -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) + // Check if std:c++17 or higher. + // Here we cannot use (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) when ViSP + // is used as a 3rdparty. See issue #1274 +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) return std::clamp(v, lower, upper); #else if (upper < lower) { From 09f41418482aada0e7c2f4c9887f2191fda41f5b Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 16 Nov 2023 16:40:13 +0100 Subject: [PATCH 8/9] Following issue #1274 stop to use VISP_CXX_STANDARD to check c++ standard - The reason is that even if ViSP is build with the required standard, when used as a 3rparty the user can explicitly downgrade the standard. Since VISP_CXX_STANDARD was used in ViSP headers, the standard set in VISP_CXX_STANDARD and the one used by the compiler may differ. - The change consists in always using the live standard provided by the compiler --- .../servo-afma6/servoAfma6MegaposePBVS.cpp | 8 +- example/servo-pixhawk/sendMocapToPixhawk.cpp | 138 ++++++++++-------- .../servo-pixhawk/servoPixhawkDroneIBVS.cpp | 119 ++++++++------- modules/core/include/visp3/core/vpMunkres.h | 32 ++-- modules/core/src/munkres/vpMunkres.cpp | 17 ++- modules/core/src/tools/geometry/vpPolygon.cpp | 6 +- modules/core/test/munkres/testMunkres.cpp | 50 +++---- .../core/test/tools/geometry/testPolygon2.cpp | 6 +- .../visp3/detection/vpDetectorDNNOpenCV.h | 6 +- .../detection/src/dnn/vpDetectorDNNOpenCV.cpp | 5 +- .../robot/include/visp3/robot/vpRobotMavsdk.h | 4 +- .../src/haptic-device/qbdevice/vpQbDevice.cpp | 34 +++-- .../src/real-robot/mavsdk/vpRobotMavsdk.cpp | 5 +- .../testPixhawkDroneKeyboard.cpp | 72 ++++----- ...estPixhawkDronePositionAbsoluteControl.cpp | 29 ++-- ...estPixhawkDronePositionRelativeControl.cpp | 29 ++-- .../servo-pixhawk/testPixhawkDroneTakeoff.cpp | 30 ++-- .../testPixhawkDroneVelocityControl.cpp | 28 ++-- .../testPixhawkRoverVelocityControl.cpp | 43 +++--- .../include/visp3/mbt/vpMbtTukeyEstimator.h | 9 +- .../include/visp3/vision/vpPlaneEstimation.h | 8 +- modules/vision/include/visp3/vision/vpPose.h | 10 +- .../plane-estimation/vpPlaneEstimation.cpp | 6 +- .../vpPoseVirtualVisualServoing.cpp | 4 +- .../tutorial-pose-from-planar-object.cpp | 126 ++++++++-------- .../tutorial-dnn-object-detection-live.cpp | 6 +- .../munkres/tutorial-munkres-assignment.cpp | 24 +-- ...l-megapose-live-single-object-tracking.cpp | 15 +- 28 files changed, 466 insertions(+), 403 deletions(-) diff --git a/example/servo-afma6/servoAfma6MegaposePBVS.cpp b/example/servo-afma6/servoAfma6MegaposePBVS.cpp index 25530a7f6d..1fde8eba31 100644 --- a/example/servo-afma6/servoAfma6MegaposePBVS.cpp +++ b/example/servo-afma6/servoAfma6MegaposePBVS.cpp @@ -77,8 +77,8 @@ #include #include - -#if defined(VISP_HAVE_REALSENSE2) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ +// Check if std:c++17 or higher +#if defined(VISP_HAVE_REALSENSE2) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) && \ (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_AFMA6) && defined(VISP_HAVE_MODULE_DNN_TRACKER) #include @@ -455,8 +455,8 @@ int main() #if !defined(VISP_HAVE_REALSENSE2) std::cout << "Install librealsense-2.x" << std::endl; #endif -#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_17) - std::cout << "Build ViSP with c++11 or higher compiler flag (cmake -DUSE_CXX_STANDARD=17)." << std::endl; +#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) + std::cout << "Build ViSP with c++17 or higher compiler flag (cmake -DUSE_CXX_STANDARD=17)." << std::endl; #endif #if !defined(VISP_HAVE_AFMA6) std::cout << "ViSP is not built with Afma-6 robot support..." << std::endl; diff --git a/example/servo-pixhawk/sendMocapToPixhawk.cpp b/example/servo-pixhawk/sendMocapToPixhawk.cpp index c2b9d296bf..67cf9fdc32 100644 --- a/example/servo-pixhawk/sendMocapToPixhawk.cpp +++ b/example/servo-pixhawk/sendMocapToPixhawk.cpp @@ -44,7 +44,8 @@ #include -#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ +// Check if std:c++17 or higher +#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) && \ (defined(VISP_HAVE_QUALISYS) || defined(VISP_HAVE_VICON)) #include @@ -92,7 +93,8 @@ bool mocap_sdk_loop(std::mutex &lock, bool qualisys, bool opt_verbose, bool opt_ std::cout << "ERROR : Qualisys not found."; return false; #endif - } else { + } + else { #ifdef VISP_HAVE_VICON mocap = std::make_shared(); #else @@ -120,11 +122,13 @@ bool mocap_sdk_loop(std::mutex &lock, bool qualisys, bool opt_verbose, bool opt_ if (!mocap->getBodiesPose(body_poses_enu_M_flu, opt_all_bodies)) { g_quit = true; } - } else { + } + else { vpHomogeneousMatrix enu_M_flu; if (!mocap->getSpecificBodyPose(opt_onlyBody, enu_M_flu)) { g_quit = true; - } else { + } + else { body_poses_enu_M_flu[opt_onlyBody] = enu_M_flu; } } @@ -132,7 +136,7 @@ bool mocap_sdk_loop(std::mutex &lock, bool qualisys, bool opt_verbose, bool opt_ lock.lock(); internal_mavlink_failure = mavlink_failure; current_body_poses_enu_M_flu = - body_poses_enu_M_flu; // Now we send directly the poses in the ENU global reference frame. + body_poses_enu_M_flu; // Now we send directly the poses in the ENU global reference frame. lock.unlock(); } return true; @@ -148,7 +152,7 @@ int top(const std::string &connection_info, std::map] [-ob]" - << " [--mocap-system /] [-ms /]" - << " [--device ] [-d]" - << " [--server-address ] [-sa]" - << " [--verbose] [-v]" - << " [--help] [-h]" << std::endl - << std::endl; + << " " << argv[0] << " [--only-body ] [-ob]" + << " [--mocap-system /] [-ms /]" + << " [--device ] [-d]" + << " [--server-address ] [-sa]" + << " [--verbose] [-v]" + << " [--help] [-h]" << std::endl + << std::endl; std::cout << "DESCRIPTION" << std::endl - << "MANDATORY PARAMETERS :" << std::endl - << " --only-body " << std::endl - << " Name of the specific body you want to be displayed." << std::endl - << std::endl - << "OPTIONAL PARAMETERS (DEFAULT VALUES)" << std::endl - << " --mocap-system, -ms" << std::endl - << " Specify the name of the mocap system : 'qualisys' / 'q' or 'vicon'/ 'v'." << std::endl - << " Default: Qualisys mode." << std::endl - << std::endl - << " --device , -d" << std::endl - << " String giving us all the informations necessary for connection." << std::endl - << " Default: serial:///dev/ttyUSB0 ." << std::endl - << " UDP example: udp://192.168.30.111:14540 (udp://IP:Port) ." << std::endl - << std::endl - << " --server-address
, -sa" << std::endl - << " Mocap server address." << std::endl - << " Default for Qualisys: 192.168.34.42 ." << std::endl - << " Default for Vicon: 192.168.34.1 ." << std::endl - << std::endl - << " --verbose, -v" << std::endl - << " Enable verbose mode." << std::endl - << std::endl - << " --help, -h" << std::endl - << " Print this helper message." << std::endl - << std::endl; + << "MANDATORY PARAMETERS :" << std::endl + << " --only-body " << std::endl + << " Name of the specific body you want to be displayed." << std::endl + << std::endl + << "OPTIONAL PARAMETERS (DEFAULT VALUES)" << std::endl + << " --mocap-system, -ms" << std::endl + << " Specify the name of the mocap system : 'qualisys' / 'q' or 'vicon'/ 'v'." << std::endl + << " Default: Qualisys mode." << std::endl + << std::endl + << " --device , -d" << std::endl + << " String giving us all the informations necessary for connection." << std::endl + << " Default: serial:///dev/ttyUSB0 ." << std::endl + << " UDP example: udp://192.168.30.111:14540 (udp://IP:Port) ." << std::endl + << std::endl + << " --server-address
, -sa" << std::endl + << " Mocap server address." << std::endl + << " Default for Qualisys: 192.168.34.42 ." << std::endl + << " Default for Vicon: 192.168.34.1 ." << std::endl + << std::endl + << " --verbose, -v" << std::endl + << " Enable verbose mode." << std::endl + << std::endl + << " --help, -h" << std::endl + << " Print this helper message." << std::endl + << std::endl; if (error) { std::cout << "Error" << std::endl - << " " - << "Unsupported parameter " << argv[error] << std::endl; + << " " + << "Unsupported parameter " << argv[error] << std::endl; } } @@ -230,31 +234,40 @@ void parse_commandline(int argc, char **argv, bool &qualisys, std::string &conne if (std::string(argv[i]) == "--only-body" || std::string(argv[i]) == "-ob") { only_body = std::string(argv[i + 1]); i++; - } else if (std::string(argv[i]) == "--mocap-system" || std::string(argv[i]) == "-ms") { + } + else if (std::string(argv[i]) == "--mocap-system" || std::string(argv[i]) == "-ms") { std::string mode = std::string(argv[i + 1]); if (mode == "qualisys" || mode == "q") { qualisys = true; - } else if (mode == "vicon" || mode == "v") { + } + else if (mode == "vicon" || mode == "v") { qualisys = false; - } else { + } + else { std::cout << "ERROR : System not recognized, exiting." << std::endl; throw EXIT_FAILURE; } i++; - } else if (std::string(argv[i]) == "--device" || std::string(argv[i]) == "-d") { + } + else if (std::string(argv[i]) == "--device" || std::string(argv[i]) == "-d") { connection_info = std::string(argv[i + 1]); i++; - } else if (std::string(argv[i]) == "--server-address" || std::string(argv[i]) == "-sa") { + } + else if (std::string(argv[i]) == "--server-address" || std::string(argv[i]) == "-sa") { server_address = std::string(argv[i + 1]); i++; - } else if (std::string(argv[i]) == "--all-bodies") { + } + else if (std::string(argv[i]) == "--all-bodies") { all_bodies = true; - } else if (std::string(argv[i]) == "--verbose" || std::string(argv[i]) == "-v") { + } + else if (std::string(argv[i]) == "--verbose" || std::string(argv[i]) == "-v") { verbose = true; - } else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") { + } + else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") { usage(argv, 0); throw EXIT_SUCCESS; - } else { + } + else { usage(argv, i); throw EXIT_FAILURE; } @@ -289,7 +302,8 @@ int main(int argc, char **argv) if (opt_qualisys && opt_serverAddress == "") { opt_serverAddress = "192.168.30.42"; - } else if (!opt_qualisys && opt_serverAddress == "") { + } + else if (!opt_qualisys && opt_serverAddress == "") { opt_serverAddress = "192.168.30.1"; } @@ -304,8 +318,8 @@ int main(int argc, char **argv) bool mavlink_failure = false; std::thread mocap_thread([&lock, &opt_qualisys, &opt_verbose, &opt_all_bodies, &opt_serverAddress, &opt_onlyBody, ¤t_body_poses_enu_M_flu, &mocap_failure, &mavlink_failure]() { - mocap_sdk_loop(lock, opt_qualisys, opt_verbose, opt_all_bodies, opt_serverAddress, opt_onlyBody, - current_body_poses_enu_M_flu, mocap_failure, mavlink_failure); + mocap_sdk_loop(lock, opt_qualisys, opt_verbose, opt_all_bodies, opt_serverAddress, opt_onlyBody, + current_body_poses_enu_M_flu, mocap_failure, mavlink_failure); }); if (mocap_failure) { std::cout << "Mocap connexion failure. Check mocap server IP address" << std::endl; @@ -318,7 +332,8 @@ int main(int argc, char **argv) try { int result = top(opt_connectionInfo, current_body_poses_enu_M_flu, lock, mocap_failure); return result; - } catch (int error) { + } + catch (int error) { fprintf(stderr, "mavlink_control threw exception %i \n", error); lock.lock(); mavlink_failure = true; @@ -331,7 +346,8 @@ int main(int argc, char **argv) mavlink_thread.join(); if (mocap_failure) { return EXIT_FAILURE; - } else { + } + else { return EXIT_SUCCESS; } } @@ -342,18 +358,18 @@ int main() { #ifndef VISP_HAVE_MAVSDK std::cout << "\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n" - << std::endl; + << std::endl; #endif #if !(defined(VISP_HAVE_QUALISYS) || defined(VISP_HAVE_VICON)) std::cout << "\nThis example requires data from a Qualisys or Vicon mocap system. You should install it, configure " - "and rebuid ViSP.\n" - << std::endl; + "and rebuid ViSP.\n" + << std::endl; #endif -#if !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) std::cout - << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " - "rebuild ViSP.\n" - << std::endl; + << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " + "rebuild ViSP.\n" + << std::endl; #endif return EXIT_SUCCESS; } diff --git a/example/servo-pixhawk/servoPixhawkDroneIBVS.cpp b/example/servo-pixhawk/servoPixhawkDroneIBVS.cpp index f7d14d15ae..54e9960052 100644 --- a/example/servo-pixhawk/servoPixhawkDroneIBVS.cpp +++ b/example/servo-pixhawk/servoPixhawkDroneIBVS.cpp @@ -37,7 +37,8 @@ #include -#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && defined(VISP_HAVE_REALSENSE2) +// Check if std:c++17 or higher +#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) && defined(VISP_HAVE_REALSENSE2) #include #include @@ -110,7 +111,8 @@ int main(int argc, char **argv) if (std::string(argv[i]) == "--co" && i + 1 < argc) { opt_connecting_info = std::string(argv[i + 1]); i++; - } else if (std::string(argv[i]) == "--distance-to-tag" && i + 1 < argc) { + } + else if (std::string(argv[i]) == "--distance-to-tag" && i + 1 < argc) { opt_distance_to_tag = std::atof(argv[i + 1]); if (opt_distance_to_tag <= 0) { std::cout << "Error : invalid distance to tag." << std::endl << "See " << argv[0] << " --help" << std::endl; @@ -119,59 +121,64 @@ int main(int argc, char **argv) opt_has_distance_to_tag = true; i++; - } else if (std::string(argv[i]) == "--display-fps" && i + 1 < argc) { + } + else if (std::string(argv[i]) == "--display-fps" && i + 1 < argc) { opt_display_fps = std::stoi(std::string(argv[i + 1])); i++; - } else if (std::string(argv[i]) == "--verbose" || std::string(argv[i]) == "-v") { + } + else if (std::string(argv[i]) == "--verbose" || std::string(argv[i]) == "-v") { opt_verbose = true; - } else { + } + else { std::cout << "Error : unknown parameter " << argv[i] << std::endl - << "See " << argv[0] << " --help" << std::endl; + << "See " << argv[0] << " --help" << std::endl; return EXIT_FAILURE; } } - } else if (argc >= 2 && (std::string(argv[1]) == "--help" || std::string(argv[1]) == "-h")) { + } + else if (argc >= 2 && (std::string(argv[1]) == "--help" || std::string(argv[1]) == "-h")) { std::cout << "\nUsage:\n" - << " " << argv[0] - << " [--tag-size ] [--co ] [--distance-to-tag ]" - << " [--display-fps ] [--verbose] [-v] [--help] [-h]\n" - << std::endl - << "Description:\n" - << " --tag-size \n" - << " The size of the tag to detect in meters, required.\n\n" - << " --co \n" - << " - UDP: udp://[host][:port]\n" - << " - TCP: tcp://[host][:port]\n" - << " - serial: serial://[path][:baudrate]\n" - << " - Default: udp://192.168.30.111:14552).\n\n" - << " --distance-to-tag \n" - << " The desired distance to the tag in meters (default: 1 meter).\n\n" - << " --display-fps \n" - << " The desired fps rate for the video display (default: 10 fps).\n\n" - << " --verbose, -v\n" - << " Enables verbosity (drone information messages and velocity commands\n" - << " are then displayed).\n\n" - << " --help, -h\n" - << " Print help message.\n" - << std::endl; + << " " << argv[0] + << " [--tag-size ] [--co ] [--distance-to-tag ]" + << " [--display-fps ] [--verbose] [-v] [--help] [-h]\n" + << std::endl + << "Description:\n" + << " --tag-size \n" + << " The size of the tag to detect in meters, required.\n\n" + << " --co \n" + << " - UDP: udp://[host][:port]\n" + << " - TCP: tcp://[host][:port]\n" + << " - serial: serial://[path][:baudrate]\n" + << " - Default: udp://192.168.30.111:14552).\n\n" + << " --distance-to-tag \n" + << " The desired distance to the tag in meters (default: 1 meter).\n\n" + << " --display-fps \n" + << " The desired fps rate for the video display (default: 10 fps).\n\n" + << " --verbose, -v\n" + << " Enables verbosity (drone information messages and velocity commands\n" + << " are then displayed).\n\n" + << " --help, -h\n" + << " Print help message.\n" + << std::endl; return EXIT_SUCCESS; - } else { + } + else { std::cout << "Error : tag size parameter required." << std::endl << "See " << argv[0] << " --help" << std::endl; return EXIT_FAILURE; } std::cout << std::endl - << "WARNING:" << std::endl - << " - This program does no sensing or avoiding of obstacles, " << std::endl - << " the drone WILL collide with any objects in the way! Make sure the " << std::endl - << " drone has approximately 3 meters of free space on all sides." << std::endl - << " - The drone uses a forward-facing camera for Apriltag detection," << std::endl - << " make sure the drone flies above a non-uniform flooring," << std::endl - << " or its movement will be inacurate and dangerous !" << std::endl - << std::endl; - - // Connect to the drone + << "WARNING:" << std::endl + << " - This program does no sensing or avoiding of obstacles, " << std::endl + << " the drone WILL collide with any objects in the way! Make sure the " << std::endl + << " drone has approximately 3 meters of free space on all sides." << std::endl + << " - The drone uses a forward-facing camera for Apriltag detection," << std::endl + << " make sure the drone flies above a non-uniform flooring," << std::endl + << " or its movement will be inacurate and dangerous !" << std::endl + << std::endl; + +// Connect to the drone vpRobotMavsdk drone(opt_connecting_info); if (drone.isRunning()) { @@ -260,7 +267,7 @@ int main(int argc, char **argv) vpRotationMatrix c1Rc(c1_rxyz_c); // Rotation between (c1) and (c) vpHomogeneousMatrix c1Mc(vpTranslationVector(), c1Rc); // Homogeneous matrix between (c1) and (c) - vpRotationMatrix c1Re{1, 0, 0, 0, 0, 1, 0, -1, 0}; // Rotation between (c1) and (e) + vpRotationMatrix c1Re { 1, 0, 0, 0, 0, 1, 0, -1, 0 }; // Rotation between (c1) and (e) vpTranslationVector c1te(0, -0.03, -0.07); // Translation between (c1) and (e) vpHomogeneousMatrix c1Me(c1te, c1Re); // Homogeneous matrix between (c1) and (e) @@ -281,8 +288,8 @@ int main(int argc, char **argv) double Z_d = (opt_has_distance_to_tag ? opt_distance_to_tag : 1.); // Define the desired polygon corresponding the the AprilTag CLOCKWISE - double X[4] = {tagSize / 2., tagSize / 2., -tagSize / 2., -tagSize / 2.}; - double Y[4] = {tagSize / 2., -tagSize / 2., -tagSize / 2., tagSize / 2.}; + double X[4] = { tagSize / 2., tagSize / 2., -tagSize / 2., -tagSize / 2. }; + double Y[4] = { tagSize / 2., -tagSize / 2., -tagSize / 2., tagSize / 2. }; std::vector vec_P, vec_P_d; for (int i = 0; i < 4; i++) { @@ -491,14 +498,16 @@ int main(int argc, char **argv) false); } - } else { + } + else { std::stringstream sserr; sserr << "Failed to detect an Apriltag, or detected multiple ones"; if (condition) { vpDisplay::displayText(I, 120, 20, sserr.str(), vpColor::red); vpDisplay::flush(I); - } else { + } + else { std::cout << sserr.str() << std::endl; } #ifdef CONTROL_UAV @@ -510,7 +519,7 @@ int main(int argc, char **argv) { std::stringstream ss; ss << "Left click to " << (send_velocities ? "stop the robot" : "servo the robot") - << ", right click to quit."; + << ", right click to quit."; vpDisplay::displayText(I, 20, 20, ss.str(), vpColor::red); } vpDisplay::flush(I); @@ -548,11 +557,13 @@ int main(int argc, char **argv) } return EXIT_SUCCESS; - } else { + } + else { std::cout << "ERROR : failed to setup drone control." << std::endl; return EXIT_FAILURE; } - } catch (const vpException &e) { + } + catch (const vpException &e) { std::cout << "Caught an exception: " << e << std::endl; return EXIT_FAILURE; } @@ -564,17 +575,17 @@ int main() { #ifndef VISP_HAVE_MAVSDK std::cout << "\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n" - << std::endl; + << std::endl; #endif #ifndef VISP_HAVE_REALSENSE2 std::cout << "\nThis example requires librealsense2 library. You should install it, configure and rebuid ViSP.\n" - << std::endl; + << std::endl; #endif -#if !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) std::cout - << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " - "rebuild ViSP.\n" - << std::endl; + << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " + "rebuild ViSP.\n" + << std::endl; #endif return EXIT_SUCCESS; } diff --git a/modules/core/include/visp3/core/vpMunkres.h b/modules/core/include/visp3/core/vpMunkres.h index 11db82c4d5..78a35dd10c 100644 --- a/modules/core/include/visp3/core/vpMunkres.h +++ b/modules/core/include/visp3/core/vpMunkres.h @@ -35,11 +35,9 @@ #include -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ - (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) - -// Visual Studio: Optionals are available from Visual Studio 2017 RTW (15.0) [1910] -// Visual Studio: Structured bindings are available from Visual Studio 2017 version 15.3 [1911] +// Check if std:c++17 or higher. +// Here we cannot use (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) in the declaration of the class +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) // System #include @@ -98,8 +96,8 @@ class VISP_EXPORT vpMunkres static STEP_T stepThree(const std::vector > &mask, std::vector &col_cover); template static std::tuple > > - stepFour(const std::vector > &costs, std::vector > &mask, - std::vector &row_cover, std::vector &col_cover); + stepFour(const std::vector > &costs, std::vector > &mask, + std::vector &row_cover, std::vector &col_cover); static STEP_T stepFive(std::vector > &mask, const std::pair &path_0, std::vector &row_cover, std::vector &col_cover); template @@ -107,7 +105,7 @@ class VISP_EXPORT vpMunkres const std::vector &col_cover); private: - static constexpr auto ZeroEpsilon{1e-6}; + static constexpr auto ZeroEpsilon { 1e-6 }; }; enum vpMunkres::ZERO_T : unsigned int { NA = 0, STARRED = 1, PRIMED = 2 }; @@ -267,12 +265,14 @@ vpMunkres::stepFour(const std::vector > &costs, std::vector >(row, col)}; + return { vpMunkres::STEP_T(4), std::nullopt }; // Repeat + } + else { + return { vpMunkres::STEP_T(5), std::make_optional >(row, col) }; } - } else { - return {vpMunkres::STEP_T(6), std::nullopt}; + } + else { + return { vpMunkres::STEP_T(6), std::nullopt }; } } @@ -323,9 +323,9 @@ inline std::vector > vpMunkres::run(std::v auto row_cover = std::vector(sq_size, false); auto col_cover = std::vector(sq_size, false); - std::optional > path_0{std::nullopt}; + std::optional > path_0 { std::nullopt }; - auto step{vpMunkres::STEP_T::ENTRY}; + auto step { vpMunkres::STEP_T::ENTRY }; while (step != vpMunkres::STEP_T::DONE) { switch (step) { case vpMunkres::STEP_T::ENTRY: @@ -357,7 +357,7 @@ inline std::vector > vpMunkres::run(std::v } // Compute the pairs - std::vector > ret{}; + std::vector > ret {}; for (auto i = 0u; i < original_row_size; i++) { if (const auto it = std::find(begin(mask.at(i)), end(mask.at(i)), vpMunkres::ZERO_T::STARRED); it != end(mask.at(i))) { diff --git a/modules/core/src/munkres/vpMunkres.cpp b/modules/core/src/munkres/vpMunkres.cpp index 70ac52abe5..fc8b3c3ec3 100644 --- a/modules/core/src/munkres/vpMunkres.cpp +++ b/modules/core/src/munkres/vpMunkres.cpp @@ -39,8 +39,8 @@ #include -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ - (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) +// Check if std:c++17 or higher +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) /*! * Find a starred zero in a specific mask matrix row. @@ -54,7 +54,7 @@ std::optional vpMunkres::findStarInRow(const std::vector(std::distance(begin(mask.at(row)), it)) - : std::nullopt; + : std::nullopt; } /*! @@ -84,7 +84,7 @@ std::optional vpMunkres::findPrimeInRow(const std::vector(std::distance(begin(mask.at(row)), it)) - : std::nullopt; + : std::nullopt; } /*! @@ -98,7 +98,7 @@ void vpMunkres::augmentPath(std::vector > &mask, { for (const auto &[row, col] : path) { mask.at(row).at(col) = - mask.at(row).at(col) == vpMunkres::ZERO_T::STARRED ? vpMunkres::ZERO_T::NA : vpMunkres::ZERO_T::STARRED; + mask.at(row).at(col) == vpMunkres::ZERO_T::STARRED ? vpMunkres::ZERO_T::NA : vpMunkres::ZERO_T::STARRED; } } @@ -172,12 +172,13 @@ vpMunkres::STEP_T vpMunkres::stepFive(std::vector const std::pair &path_0, std::vector &row_cover, std::vector &col_cover) { - std::vector > path{path_0}; // Z0 + std::vector > path { path_0 }; // Z0 while (true) { if (const auto star_in_col = findStarInCol(mask, path.back().second)) { path.emplace_back(*star_in_col, path.back().second); // Z1 - } else { + } + else { augmentPath(mask, path); erasePrimes(mask); clearCovers(row_cover, col_cover); @@ -191,4 +192,4 @@ vpMunkres::STEP_T vpMunkres::stepFive(std::vector } } -#endif // (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +#endif diff --git a/modules/core/src/tools/geometry/vpPolygon.cpp b/modules/core/src/tools/geometry/vpPolygon.cpp index ed23cd6642..0cbca328a0 100644 --- a/modules/core/src/tools/geometry/vpPolygon.cpp +++ b/modules/core/src/tools/geometry/vpPolygon.cpp @@ -63,7 +63,8 @@ template std::vector convexHull(const IpCon // Visp -> CV std::vector cv_pts; -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_14) + // Check if std:c++14 or higher +#if ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))) std::transform(cbegin(ips), cend(ips), std::back_inserter(cv_pts), [](const vpImagePoint &ip) { return cv::Point(static_cast(ip.get_u()), static_cast(ip.get_v())); }); @@ -79,7 +80,8 @@ template std::vector convexHull(const IpCon // CV -> Visp std::vector conv_hull_corners; -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_14) + // Check if std:c++14 or higher +#if ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))) std::transform(cbegin(cv_conv_hull_corners), cend(cv_conv_hull_corners), std::back_inserter(conv_hull_corners), [](const cv::Point &pt) { return vpImagePoint { static_cast(pt.y), static_cast(pt.x) }; diff --git a/modules/core/test/munkres/testMunkres.cpp b/modules/core/test/munkres/testMunkres.cpp index 3b3706cf38..9256e48a21 100644 --- a/modules/core/test/munkres/testMunkres.cpp +++ b/modules/core/test/munkres/testMunkres.cpp @@ -40,8 +40,8 @@ #include -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ - (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) +// Check if std:c++17 or higher +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) // System #include @@ -67,21 +67,21 @@ TEST_CASE("Check Munkres-based assignment", "[visp_munkres]") { auto testMunkres = [](const std::vector > &cost_matrix, const std::vector > &expected_pairs) { - const auto munkres_pairs = vpMunkres::run(cost_matrix); - REQUIRE(expected_pairs.size() == munkres_pairs.size()); - for (auto i = 0u; i < munkres_pairs.size(); i++) { - REQUIRE(expected_pairs.at(i) == munkres_pairs.at(i)); - } - }; + const auto munkres_pairs = vpMunkres::run(cost_matrix); + REQUIRE(expected_pairs.size() == munkres_pairs.size()); + for (auto i = 0u; i < munkres_pairs.size(); i++) { + REQUIRE(expected_pairs.at(i) == munkres_pairs.at(i)); + } + }; SECTION("Square cost matrix") { - std::vector > costs{}; + std::vector > costs {}; costs.push_back(std::vector{3, 1, 2}); costs.push_back(std::vector{2, 3, 1}); costs.push_back(std::vector{1, 2, 3}); - std::vector > expected_pairs{}; + std::vector > expected_pairs {}; expected_pairs.emplace_back(0, 1); expected_pairs.emplace_back(1, 2); expected_pairs.emplace_back(2, 0); @@ -91,12 +91,12 @@ TEST_CASE("Check Munkres-based assignment", "[visp_munkres]") SECTION("Horizontal cost matrix") { - std::vector > costs{}; + std::vector > costs {}; costs.push_back(std::vector{4, 1, 2, 3}); costs.push_back(std::vector{3, 4, 1, 2}); costs.push_back(std::vector{2, 3, 4, 1}); - std::vector > expected_pairs{}; + std::vector > expected_pairs {}; expected_pairs.emplace_back(0, 1); expected_pairs.emplace_back(1, 2); expected_pairs.emplace_back(2, 3); @@ -106,13 +106,13 @@ TEST_CASE("Check Munkres-based assignment", "[visp_munkres]") SECTION("Vertical cost matrix") { - std::vector > costs{}; + std::vector > costs {}; costs.push_back(std::vector{4, 1, 2}); costs.push_back(std::vector{3, 4, 1}); costs.push_back(std::vector{2, 3, 4}); costs.push_back(std::vector{1, 2, 3}); - std::vector > expected_pairs{}; + std::vector > expected_pairs {}; expected_pairs.emplace_back(0, 1); expected_pairs.emplace_back(1, 2); expected_pairs.emplace_back(3, 0); @@ -139,9 +139,9 @@ bool testMunkres(const std::vector > &costs_matrix, if (pairs.size() != expected_pairs.size()) { // clang-format off std::cerr << "Expected nb of association | Munkres nb of association: " - << expected_pairs.size() << " | " << pairs.size() - << std::endl; - // clang-format on + << expected_pairs.size() << " | " << pairs.size() + << std::endl; +// clang-format on return false; } @@ -161,8 +161,8 @@ bool testMunkres(const std::vector > &costs_matrix, // Output the pair which fails std::cerr << "FAIL: " - << "Expected association | Munkres association: " << expected_pairs.at(i) << " | " << pairs.at(i) - << std::endl; + << "Expected association | Munkres association: " << expected_pairs.at(i) << " | " << pairs.at(i) + << std::endl; return false; } @@ -173,13 +173,13 @@ bool testMunkres(const std::vector > &costs_matrix, bool testSquareMat() { - std::vector > costs{}; + std::vector > costs {}; costs.push_back(std::vector{3, 4, 1, 2}); costs.push_back(std::vector{3, 4, 2, 1}); costs.push_back(std::vector{1, 2, 3, 4}); costs.push_back(std::vector{2, 1, 4, 3}); - std::vector > pairs{}; + std::vector > pairs {}; pairs.emplace_back(0, 2); pairs.emplace_back(1, 3); pairs.emplace_back(2, 0); @@ -190,13 +190,13 @@ bool testSquareMat() bool testVertMat() { - std::vector > costs{}; + std::vector > costs {}; costs.push_back(std::vector{3, 2, 1}); costs.push_back(std::vector{4, 3, 2}); costs.push_back(std::vector{1, 4, 3}); costs.push_back(std::vector{2, 1, 4}); - std::vector > pairs{}; + std::vector > pairs {}; pairs.emplace_back(0, 2); pairs.emplace_back(2, 0); pairs.emplace_back(3, 1); @@ -206,12 +206,12 @@ bool testVertMat() bool testHorMat() { - std::vector > costs{}; + std::vector > costs {}; costs.push_back(std::vector{2, 3, 4, 1}); costs.push_back(std::vector{4, 1, 2, 3}); costs.push_back(std::vector{1, 2, 3, 4}); - std::vector > pairs{}; + std::vector > pairs {}; pairs.emplace_back(0, 3); pairs.emplace_back(1, 1); pairs.emplace_back(2, 0); diff --git a/modules/core/test/tools/geometry/testPolygon2.cpp b/modules/core/test/tools/geometry/testPolygon2.cpp index 7653e78a15..4625b7b95b 100644 --- a/modules/core/test/tools/geometry/testPolygon2.cpp +++ b/modules/core/test/tools/geometry/testPolygon2.cpp @@ -62,7 +62,8 @@ TEST_CASE("Check OpenCV-bsed convex hull") vpPolygon poly {}; poly.buildFrom(rect_corners, true); -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_14) + // Check if std:c++14 or higher +#if ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))) for (const auto &poly_corner : poly.getCorners()) { REQUIRE(std::find(cbegin(rect_corners), cend(rect_corners), poly_corner) != cend(rect_corners)); } @@ -98,7 +99,8 @@ bool testConvexHull() vpPolygon poly; poly.buildFrom(rect_corners, true); -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_14) + // Check if std:c++14 or higher +#if ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))) for (const auto &poly_corner : poly.getCorners()) { if (std::find(cbegin(rect_corners), cend(rect_corners), poly_corner) == cend(rect_corners)) { return false; diff --git a/modules/detection/include/visp3/detection/vpDetectorDNNOpenCV.h b/modules/detection/include/visp3/detection/vpDetectorDNNOpenCV.h index 4cdc12fb22..57e955e8e2 100644 --- a/modules/detection/include/visp3/detection/vpDetectorDNNOpenCV.h +++ b/modules/detection/include/visp3/detection/vpDetectorDNNOpenCV.h @@ -35,7 +35,11 @@ #include -#if (VISP_HAVE_OPENCV_VERSION >= 0x030403) && defined(HAVE_OPENCV_DNN) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +// Check if std:c++17 or higher. +// Here we cannot use (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) in the declaration of the class +#if (VISP_HAVE_OPENCV_VERSION >= 0x030403) && defined(HAVE_OPENCV_DNN) && \ + ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) + #include #include #include diff --git a/modules/detection/src/dnn/vpDetectorDNNOpenCV.cpp b/modules/detection/src/dnn/vpDetectorDNNOpenCV.cpp index 2d0c1422cc..f8babbc1f4 100644 --- a/modules/detection/src/dnn/vpDetectorDNNOpenCV.cpp +++ b/modules/detection/src/dnn/vpDetectorDNNOpenCV.cpp @@ -34,7 +34,10 @@ *****************************************************************************/ #include -#if (VISP_HAVE_OPENCV_VERSION >= 0x030403) && defined(HAVE_OPENCV_DNN) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +// Check if std:c++17 or higher +#if (VISP_HAVE_OPENCV_VERSION >= 0x030403) && defined(HAVE_OPENCV_DNN) && \ + ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) + #include #include #include diff --git a/modules/robot/include/visp3/robot/vpRobotMavsdk.h b/modules/robot/include/visp3/robot/vpRobotMavsdk.h index 217ce46729..5b6bba8156 100644 --- a/modules/robot/include/visp3/robot/vpRobotMavsdk.h +++ b/modules/robot/include/visp3/robot/vpRobotMavsdk.h @@ -38,7 +38,9 @@ #include -#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +// Check if std:c++17 or higher. +// Here we cannot use (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) in the declaration of the class +#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) #include #include diff --git a/modules/robot/src/haptic-device/qbdevice/vpQbDevice.cpp b/modules/robot/src/haptic-device/qbdevice/vpQbDevice.cpp index a3adb092f4..c806b68a9f 100644 --- a/modules/robot/src/haptic-device/qbdevice/vpQbDevice.cpp +++ b/modules/robot/src/haptic-device/qbdevice/vpQbDevice.cpp @@ -47,10 +47,10 @@ class vpQbDevice::Impl { public: - Impl() : Impl(std::make_shared()) {} + Impl() : Impl(std::make_shared()) { } Impl(std::shared_ptr device_api) : m_serial_protectors(), m_connected_devices(), m_position_limits(2), m_device_api(device_api), - m_file_descriptors(), m_max_repeats(1), m_current_max(750.) + m_file_descriptors(), m_max_repeats(1), m_current_max(750.) { // Default values updated after a call to init() m_position_limits[0] = 0; @@ -62,7 +62,8 @@ class vpQbDevice::Impl for (auto it = m_file_descriptors.begin(); it != m_file_descriptors.end();) { if (close(it->first)) { it = m_file_descriptors.erase(it); - } else { + } + else { ++it; } } @@ -112,7 +113,7 @@ class vpQbDevice::Impl public: std::map > - m_serial_protectors; // only callbacks must lock the serial resources + m_serial_protectors; // only callbacks must lock the serial resources std::map m_connected_devices; protected: @@ -228,8 +229,8 @@ int vpQbDevice::Impl::getMeasurements(const int &id, const int &max_repeats, std int vpQbDevice::Impl::getParameters(const int &id, std::vector &limits, std::vector &resolutions) { - std::vector input_mode = {-1}; - std::vector control_mode = {-1}; + std::vector input_mode = { -1 }; + std::vector control_mode = { -1 }; m_device_api->getParameters(&m_file_descriptors.at(m_connected_devices.at(id)), id, input_mode, control_mode, resolutions, limits); if (!input_mode.front() && !control_mode.front()) { // both input and control modes equals 0 are required, i.e. @@ -276,7 +277,8 @@ int vpQbDevice::Impl::getSerialPortsAndDevices(const int &max_repeats) } // 'serial_protectors_' is not cleared because of the previously acquired lock, do not do it! -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_14) + // Check if std:c++14 or higher +#if ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))) m_serial_protectors.insert(std::make_pair(serial_ports.at(i), std::make_unique())); // never override #else m_serial_protectors.insert( @@ -309,7 +311,7 @@ bool vpQbDevice::Impl::init(const int &id) { std::vector encoder_resolutions; std::vector > - serial_locks; // need to lock on all the serial resources to scan for new ports/devices + serial_locks; // need to lock on all the serial resources to scan for new ports/devices for (auto const &mutex : m_serial_protectors) { serial_locks.push_back(std::unique_lock(*mutex.second)); } @@ -326,7 +328,7 @@ bool vpQbDevice::Impl::init(const int &id) if (getParameters(id, position_limits, encoder_resolutions)) { std::cout << "fails while initializing device [" << id - << "] because it requires 'USB' input mode and 'Position' control mode." << std::endl; + << "] because it requires 'USB' input mode and 'Position' control mode." << std::endl; return false; } @@ -363,13 +365,13 @@ bool vpQbDevice::Impl::init(const int &id) failures = activate(id, m_max_repeats); if (!isReliable(failures, m_max_repeats)) { std::cout << "has not initialized device [" << id - << "] because it cannot activate its motors (please, check the motor positions)." << std::endl; + << "] because it cannot activate its motors (please, check the motor positions)." << std::endl; return false; } std::string serial_port = m_connected_devices.at(id); std::cout << "Device [" + std::to_string(id) + "] connected on port [" << serial_port << "] initialization succeeds." - << std::endl; + << std::endl; return true; } @@ -410,19 +412,19 @@ int vpQbDevice::Impl::open(const std::string &serial_port) #if (defined(__APPLE__) && defined(__MACH__)) if (!std::regex_match(serial_port, std::regex("/dev/tty.usbserial-[[:digit:]]+"))) { std::cout << "vpQbDevice fails while opening [" << serial_port - << "] because it does not match the expected pattern [/dev/tty.usbserial-*]." << std::endl; + << "] because it does not match the expected pattern [/dev/tty.usbserial-*]." << std::endl; return -1; } #elif defined(__unix__) || defined(__unix) if (!std::regex_match(serial_port, std::regex("/dev/ttyUSB[[:digit:]]+"))) { std::cout << "vpQbDevice fails while opening [" << serial_port - << "] because it does not match the expected pattern [/dev/ttyUSB*]." << std::endl; + << "] because it does not match the expected pattern [/dev/ttyUSB*]." << std::endl; return -1; } #elif defined(_WIN32) if (!std::regex_match(serial_port, std::regex("COM[[:digit:]]+"))) { std::cout << "vpQbDevice fails while opening [" << serial_port - << "] because it does not match the expected pattern [COM*]." << std::endl; + << "] because it does not match the expected pattern [COM*]." << std::endl; return -1; } #endif @@ -435,8 +437,8 @@ int vpQbDevice::Impl::open(const std::string &serial_port) m_device_api->open(&m_file_descriptors[serial_port], serial_port); // also create a pair in the map if (m_file_descriptors.at(serial_port).file_handle == INVALID_HANDLE_VALUE) { std::cout << "vpQbDevice fails while opening [" << serial_port << "] and sets errno [" << strerror(errno) << "]." - << std::endl; - // remove file descriptor entry + << std::endl; +// remove file descriptor entry m_file_descriptors.erase(serial_port); return -1; } diff --git a/modules/robot/src/real-robot/mavsdk/vpRobotMavsdk.cpp b/modules/robot/src/real-robot/mavsdk/vpRobotMavsdk.cpp index c94b8322ba..1aafc581e8 100644 --- a/modules/robot/src/real-robot/mavsdk/vpRobotMavsdk.cpp +++ b/modules/robot/src/real-robot/mavsdk/vpRobotMavsdk.cpp @@ -35,7 +35,8 @@ #include -#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +// Check if std:c++17 or higher +#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) #include #include @@ -193,7 +194,7 @@ class vpRobotMavsdk::vpRobotMavsdkImpl calibration_promise.set_value(); break; } - }; + }; } void calibrate_gyro(mavsdk::Calibration &calibration) diff --git a/modules/robot/test/servo-pixhawk/testPixhawkDroneKeyboard.cpp b/modules/robot/test/servo-pixhawk/testPixhawkDroneKeyboard.cpp index 70cf55ab82..3881565ce2 100644 --- a/modules/robot/test/servo-pixhawk/testPixhawkDroneKeyboard.cpp +++ b/modules/robot/test/servo-pixhawk/testPixhawkDroneKeyboard.cpp @@ -46,7 +46,8 @@ #include -#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +// Check if std:c++17 or higher +#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) #include #include @@ -171,7 +172,8 @@ bool handleKeyboardInput(vpRobotMavsdk &drone, int key, bool &flying, double &la break; } vpTime::wait(40); // We wait 40ms to give the drone the time to process the command - } else { + } + else { running = false; } return running; @@ -186,35 +188,37 @@ int main(int argc, char **argv) if (std::string(argv[i]) == "--co" && i + 1 < argc) { opt_connecting_info = std::string(argv[i + 1]); i++; - } else if (argc >= 2 && (std::string(argv[1]) == "--help" || std::string(argv[1]) == "-h")) { + } + else if (argc >= 2 && (std::string(argv[1]) == "--help" || std::string(argv[1]) == "-h")) { std::cout << "\nUsage:\n" - << " " << argv[0] << "[--co ] [--help] [-h]\n" - << std::endl - << "Description:\n" - << " --co \n" - << " - UDP: udp://[host][:port]\n" - << " - TCP: tcp://[host][:port]\n" - << " - serial: serial://[path][:baudrate]\n" - << " - Default: udp://192.168.30.111:14552).\n\n" - << " For example, to connect to the simulator use URL: udp://:14552\n" - << " --help, -h\n" - << " Print help message.\n" - << std::endl; + << " " << argv[0] << "[--co ] [--help] [-h]\n" + << std::endl + << "Description:\n" + << " --co \n" + << " - UDP: udp://[host][:port]\n" + << " - TCP: tcp://[host][:port]\n" + << " - serial: serial://[path][:baudrate]\n" + << " - Default: udp://192.168.30.111:14552).\n\n" + << " For example, to connect to the simulator use URL: udp://:14552\n" + << " --help, -h\n" + << " Print help message.\n" + << std::endl; return EXIT_SUCCESS; - } else { + } + else { std::cout << "Error : unknown parameter " << argv[i] << std::endl - << "See " << argv[0] << " --help" << std::endl; + << "See " << argv[0] << " --help" << std::endl; return EXIT_SUCCESS; } } std::cout << std::endl - << "WARNING: this program does no sensing or avoiding of obstacles, " - << "the drone WILL collide with any objects in the way! Make sure the " - << "drone has approximately 3 meters of free space on all sides." << std::endl - << std::endl; + << "WARNING: this program does no sensing or avoiding of obstacles, " + << "the drone WILL collide with any objects in the way! Make sure the " + << "drone has approximately 3 meters of free space on all sides." << std::endl + << std::endl; - // Connect to the drone +// Connect to the drone vpRobotMavsdk drone(opt_connecting_info); if (drone.isRunning()) { @@ -229,10 +233,10 @@ int main(int argc, char **argv) vpKeyboard keyboard; std::cout << "\n| Control the drone with the keyboard :\n" - "| 't' to takeoff / 'l' to land / 'e' for emergency stop\n" - "| ('space','u','d','g') and ('i','k','j','l') to move\n" - "| 'q' to quit.\n" - << std::endl; + "| 't' to takeoff / 'l' to land / 'e' for emergency stop\n" + "| ('space','u','d','g') and ('i','k','j','l') to move\n" + "| 'q' to quit.\n" + << std::endl; while (running && drone.isRunning()) { @@ -244,11 +248,13 @@ int main(int argc, char **argv) } std::cout << "\nQuitting ...\n" << std::endl; - } else { + } + else { std::cout << "ERROR : failed to setup drone control." << std::endl; return EXIT_FAILURE; } - } catch (const vpException &e) { + } + catch (const vpException &e) { std::cout << "\nCaught an exception: " << e << std::endl; return EXIT_FAILURE; } @@ -260,13 +266,13 @@ int main() { #ifndef VISP_HAVE_MAVSDK std::cout << "\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n" - << std::endl; + << std::endl; #endif -#if !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) std::cout - << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " - "rebuild ViSP.\n" - << std::endl; + << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " + "rebuild ViSP.\n" + << std::endl; #endif return EXIT_SUCCESS; } diff --git a/modules/robot/test/servo-pixhawk/testPixhawkDronePositionAbsoluteControl.cpp b/modules/robot/test/servo-pixhawk/testPixhawkDronePositionAbsoluteControl.cpp index 408b091c91..4b652acf43 100644 --- a/modules/robot/test/servo-pixhawk/testPixhawkDronePositionAbsoluteControl.cpp +++ b/modules/robot/test/servo-pixhawk/testPixhawkDronePositionAbsoluteControl.cpp @@ -47,18 +47,19 @@ #include -#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +// Check if std:c++17 or higher +#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) #include void usage(const std::string &bin_name) { std::cerr << "Usage : " << bin_name << " \n" - << "Connection URL format should be :\n" - << " - For TCP : tcp://[server_host][:server_port]\n" - << " - For UDP : udp://[bind_host][:bind_port]\n" - << " - For Serial : serial:///path/to/serial/dev[:baudrate]\n" - << "For example, to connect to the simulator use URL: udp://:14540\n"; + << "Connection URL format should be :\n" + << " - For TCP : tcp://[server_host][:server_port]\n" + << " - For UDP : udp://[bind_host][:bind_port]\n" + << " - For Serial : serial:///path/to/serial/dev[:baudrate]\n" + << "For example, to connect to the simulator use URL: udp://:14540\n"; } int main(int argc, char **argv) @@ -85,15 +86,15 @@ int main(int argc, char **argv) float ned_north, ned_east, ned_down, ned_yaw; drone.getPosition(ned_north, ned_east, ned_down, ned_yaw); std::cout << "Vehicle position in NED frame: " << ned_north << " " << ned_east << " " << ned_down << " [m] and " - << vpMath::deg(ned_yaw) << " [deg]" << std::endl; + << vpMath::deg(ned_yaw) << " [deg]" << std::endl; vpHomogeneousMatrix ned_M_frd; drone.getPosition(ned_M_frd); vpRxyzVector rxyz(ned_M_frd.getRotationMatrix()); std::cout << "Vehicle position in NED frame: " << ned_M_frd.getTranslationVector().t() << " [m] and " - << vpMath::deg(rxyz).t() << " [deg]" << std::endl; + << vpMath::deg(rxyz).t() << " [deg]" << std::endl; - // Set position in NED frame +// Set position in NED frame drone.setPositioningIncertitude(0.10, vpMath::rad(5.)); drone.setPosition(0.0, 1.0, ned_down, 0.0); // East @@ -113,13 +114,13 @@ int main() { #ifndef VISP_HAVE_MAVSDK std::cout << "\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n" - << std::endl; + << std::endl; #endif -#if !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) std::cout - << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " - "rebuild ViSP.\n" - << std::endl; + << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " + "rebuild ViSP.\n" + << std::endl; #endif return EXIT_SUCCESS; } diff --git a/modules/robot/test/servo-pixhawk/testPixhawkDronePositionRelativeControl.cpp b/modules/robot/test/servo-pixhawk/testPixhawkDronePositionRelativeControl.cpp index a7debdebf4..519e82574c 100644 --- a/modules/robot/test/servo-pixhawk/testPixhawkDronePositionRelativeControl.cpp +++ b/modules/robot/test/servo-pixhawk/testPixhawkDronePositionRelativeControl.cpp @@ -47,18 +47,19 @@ #include -#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +// Check if std:c++17 or higher +#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) #include void usage(const std::string &bin_name) { std::cerr << "Usage : " << bin_name << " \n" - << "Connection URL format should be :\n" - << " - For TCP : tcp://[server_host][:server_port]\n" - << " - For UDP : udp://[bind_host][:bind_port]\n" - << " - For Serial : serial:///path/to/serial/dev[:baudrate]\n" - << "For example, to connect to the simulator use URL: udp://:14540\n"; + << "Connection URL format should be :\n" + << " - For TCP : tcp://[server_host][:server_port]\n" + << " - For UDP : udp://[bind_host][:bind_port]\n" + << " - For Serial : serial:///path/to/serial/dev[:baudrate]\n" + << "For example, to connect to the simulator use URL: udp://:14540\n"; } int main(int argc, char **argv) @@ -84,15 +85,15 @@ int main(int argc, char **argv) float ned_north, ned_east, ned_down, ned_yaw; drone.getPosition(ned_north, ned_east, ned_down, ned_yaw); std::cout << "Vehicle position in NED frame: " << ned_north << " " << ned_east << " " << ned_down << " [m] and " - << vpMath::deg(ned_yaw) << " [deg]" << std::endl; + << vpMath::deg(ned_yaw) << " [deg]" << std::endl; vpHomogeneousMatrix ned_M_frd; drone.getPosition(ned_M_frd); vpRxyzVector rxyz(ned_M_frd.getRotationMatrix()); std::cout << "Vehicle position in NED frame: " << ned_M_frd.getTranslationVector().t() << " [m] and " - << vpMath::deg(rxyz).t() << " [deg]" << std::endl; + << vpMath::deg(rxyz).t() << " [deg]" << std::endl; - // Set position in NED frame +// Set position in NED frame drone.setPositioningIncertitude(0.10, vpMath::rad(5.)); drone.setPositionRelative(0.0, 1.0, 0.0, 0.0); // Right @@ -110,13 +111,13 @@ int main() { #ifndef VISP_HAVE_MAVSDK std::cout << "\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n" - << std::endl; + << std::endl; #endif -#if !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) std::cout - << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " - "rebuild ViSP.\n" - << std::endl; + << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " + "rebuild ViSP.\n" + << std::endl; #endif return EXIT_SUCCESS; } diff --git a/modules/robot/test/servo-pixhawk/testPixhawkDroneTakeoff.cpp b/modules/robot/test/servo-pixhawk/testPixhawkDroneTakeoff.cpp index baed14604f..c97e39649a 100644 --- a/modules/robot/test/servo-pixhawk/testPixhawkDroneTakeoff.cpp +++ b/modules/robot/test/servo-pixhawk/testPixhawkDroneTakeoff.cpp @@ -47,18 +47,19 @@ #include -#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +// Check if std:c++17 or higher +#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) #include void usage(const std::string &bin_name) { std::cerr << "Usage : " << bin_name << " \n" - << "Connection information format should be :\n" - << " - For TCP: tcp://[server_host][:server_port]\n" - << " - For UDP: udp://[bind_host][:bind_port]\n" - << " - For Serial: serial:///path/to/serial/dev[:baudrate]\n" - << "For example, to connect to the simulator use URL: udp://:14540\n"; + << "Connection information format should be :\n" + << " - For TCP: tcp://[server_host][:server_port]\n" + << " - For UDP: udp://[bind_host][:bind_port]\n" + << " - For Serial: serial:///path/to/serial/dev[:baudrate]\n" + << "For example, to connect to the simulator use URL: udp://:14540\n"; } int main(int argc, char **argv) @@ -75,8 +76,7 @@ int main(int argc, char **argv) drone.takeControl(); // Start off-board or guided mode // Drone takeoff - if (! drone.takeOff() ) - { + if (!drone.takeOff()) { std::cout << "Takeoff failed" << std::endl; return EXIT_FAILURE; } @@ -90,8 +90,8 @@ int main(int argc, char **argv) drone.getPosition(ned_M_frd); vpRxyzVector rxyz(ned_M_frd.getRotationMatrix()); std::cout << "Vehicle position in NED frame: " - << ned_M_frd.getTranslationVector().t() << " [m] and " - << vpMath::deg(rxyz).t() << " [deg]"<< std::endl; + << ned_M_frd.getTranslationVector().t() << " [m] and " + << vpMath::deg(rxyz).t() << " [deg]"<< std::endl; std::cout << "Hold position for 4 sec" << std::endl; drone.holdPosition(); @@ -109,13 +109,13 @@ int main() { #ifndef VISP_HAVE_MAVSDK std::cout << "\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n" - << std::endl; + << std::endl; #endif -#if !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) std::cout - << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " - "rebuild ViSP.\n" - << std::endl; + << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " + "rebuild ViSP.\n" + << std::endl; #endif return EXIT_SUCCESS; } diff --git a/modules/robot/test/servo-pixhawk/testPixhawkDroneVelocityControl.cpp b/modules/robot/test/servo-pixhawk/testPixhawkDroneVelocityControl.cpp index f37fd5fa47..6c330c7058 100644 --- a/modules/robot/test/servo-pixhawk/testPixhawkDroneVelocityControl.cpp +++ b/modules/robot/test/servo-pixhawk/testPixhawkDroneVelocityControl.cpp @@ -47,7 +47,8 @@ #include -#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +// Check if std:c++17 or higher +#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) #include #include @@ -58,11 +59,11 @@ using std::this_thread::sleep_for; void usage(const std::string &bin_name) { std::cerr << "Usage : " << bin_name << " \n" - << "Connection URL format should be :\n" - << " - For TCP : tcp://[server_host][:server_port]\n" - << " - For UDP : udp://[bind_host][:bind_port]\n" - << " - For Serial : serial:///path/to/serial/dev[:baudrate]\n" - << "For example, to connect to the simulator use URL: udp://:14540\n"; + << "Connection URL format should be :\n" + << " - For TCP : tcp://[server_host][:server_port]\n" + << " - For UDP : udp://[bind_host][:bind_port]\n" + << " - For Serial : serial:///path/to/serial/dev[:baudrate]\n" + << "For example, to connect to the simulator use URL: udp://:14540\n"; } int main(int argc, char **argv) @@ -75,12 +76,11 @@ int main(int argc, char **argv) auto drone = vpRobotMavsdk(argv[1]); drone.setTakeOffAlt(.5); - if (! drone.takeOff() ) - { + if (!drone.takeOff()) { std::cout << "Takeoff failed" << std::endl; return EXIT_FAILURE; } - vpColVector vel_command{0.0, 0.0, 0.0, 0.0}; + vpColVector vel_command { 0.0, 0.0, 0.0, 0.0 }; drone.setForwardSpeed(0.3); std::cout << "Set forward speed of 0.3 m/s for 4 sec" << std::endl; @@ -106,13 +106,13 @@ int main() { #ifndef VISP_HAVE_MAVSDK std::cout << "\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n" - << std::endl; + << std::endl; #endif -#if !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) std::cout - << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " - "rebuild ViSP.\n" - << std::endl; + << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " + "rebuild ViSP.\n" + << std::endl; #endif return EXIT_SUCCESS; } diff --git a/modules/robot/test/servo-pixhawk/testPixhawkRoverVelocityControl.cpp b/modules/robot/test/servo-pixhawk/testPixhawkRoverVelocityControl.cpp index a2cd332b8c..dffd649c22 100644 --- a/modules/robot/test/servo-pixhawk/testPixhawkRoverVelocityControl.cpp +++ b/modules/robot/test/servo-pixhawk/testPixhawkRoverVelocityControl.cpp @@ -47,7 +47,8 @@ #include -#if defined(VISP_HAVE_MAVSDK) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +// Check if std:c++17 or higher +#if defined(VISP_HAVE_MAVSDK) && ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) #include #include @@ -58,11 +59,11 @@ using std::this_thread::sleep_for; void usage(const std::string &bin_name) { std::cerr << "Usage : " << bin_name << " \n" - << "Connection URL format should be :\n" - << " - For TCP : tcp://[server_host][:server_port]\n" - << " - For UDP : udp://[bind_host][:bind_port]\n" - << " - For Serial : serial:///path/to/serial/dev[:baudrate]\n" - << "For example, to connect to the simulator use URL: udp://:14540\n"; + << "Connection URL format should be :\n" + << " - For TCP : tcp://[server_host][:server_port]\n" + << " - For UDP : udp://[bind_host][:bind_port]\n" + << " - For Serial : serial:///path/to/serial/dev[:baudrate]\n" + << "For example, to connect to the simulator use URL: udp://:14540\n"; } int main(int argc, char **argv) @@ -74,8 +75,7 @@ int main(int argc, char **argv) auto robot = vpRobotMavsdk(argv[1]); - if (! robot.setGPSGlobalOrigin(48.117266, -1.6777926, 40.0)) - { + if (!robot.setGPSGlobalOrigin(48.117266, -1.6777926, 40.0)) { return EXIT_FAILURE; } @@ -83,15 +83,15 @@ int main(int argc, char **argv) robot.arm(); double delta_north = 1.; - double delta_east = 0.; - double delta_down = 0.; - double delta_yaw = 0.; + double delta_east = 0.; + double delta_down = 0.; + double delta_yaw = 0.; std::cout << "Move 1 meter north" << std::endl;; robot.setPositionRelative(delta_north, delta_east, delta_down, delta_yaw); - vpColVector frd_vel{0.0, 0.0, 0.0, 0.0}; - frd_vel[0]= -0.3; // forward vel m/s + vpColVector frd_vel { 0.0, 0.0, 0.0, 0.0 }; + frd_vel[0] = -0.3; // forward vel m/s //frd_vel[3]= vpMath::rad(10.); std::cout << "Go at 0.3m/s backward during 3 sec.\n"; @@ -99,15 +99,14 @@ int main(int argc, char **argv) vpTime::wait(3000); std::cout << "Go at 0.3m/s forward and rotate 10 deg/s along yaw during 2 sec.\n"; - frd_vel[0]= 0.3; // forward vel m/s - frd_vel[3]= vpMath::rad(10.); // yaw vel 10 deg/s converted in rad/s + frd_vel[0] = 0.3; // forward vel m/s + frd_vel[3] = vpMath::rad(10.); // yaw vel 10 deg/s converted in rad/s double t = vpTime::measureTimeMs(); do { vpTime::sleepMs(20); robot.setVelocity(frd_vel); - } - while(vpTime::measureTimeMs() - t < 2000.); // + } while (vpTime::measureTimeMs() - t < 2000.); // robot.disarm(); return EXIT_SUCCESS; @@ -119,13 +118,13 @@ int main() { #ifndef VISP_HAVE_MAVSDK std::cout << "\nThis example requires mavsdk library. You should install it, configure and rebuid ViSP.\n" - << std::endl; + << std::endl; #endif -#if !(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +#if !((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) std::cout - << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " - "rebuild ViSP.\n" - << std::endl; + << "\nThis example requires at least cxx17. You should enable cxx17 during ViSP configuration with cmake and " + "rebuild ViSP.\n" + << std::endl; #endif return EXIT_SUCCESS; } diff --git a/modules/tracker/mbt/include/visp3/mbt/vpMbtTukeyEstimator.h b/modules/tracker/mbt/include/visp3/mbt/vpMbtTukeyEstimator.h index 7b6b694538..ed99ef4a17 100755 --- a/modules/tracker/mbt/include/visp3/mbt/vpMbtTukeyEstimator.h +++ b/modules/tracker/mbt/include/visp3/mbt/vpMbtTukeyEstimator.h @@ -113,7 +113,8 @@ template class vpMbtTukeyEstimator #if HAVE_TRANSFORM namespace { -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_14) +// Check if std:c++14 or higher +#if ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))) auto AbsDiff = [](const auto &a, const auto &b) { return std::fabs(a - b); }; #else template struct AbsDiff : public std::binary_function @@ -166,7 +167,8 @@ void vpMbtTukeyEstimator::MEstimator_impl(const std::vector &residues, std m_normres.resize(residues.size()); #if HAVE_TRANSFORM -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_14) +// Check if std:c++14 or higher +#if ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))) std::transform(residues.begin(), residues.end(), m_normres.begin(), std::bind(AbsDiff, std::placeholders::_1, med)); #else std::transform(residues.begin(), residues.end(), m_normres.begin(), @@ -270,7 +272,8 @@ inline void vpMbtTukeyEstimator::MEstimator_impl_simd(const std::vector< m_normres.resize(residues.size()); #if HAVE_TRANSFORM -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_14) +// Check if std:c++14 or higher +#if ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))) std::transform(residues.begin(), residues.end(), m_normres.begin(), std::bind(AbsDiff, std::placeholders::_1, med)); #else std::transform(residues.begin(), residues.end(), m_normres.begin(), diff --git a/modules/vision/include/visp3/vision/vpPlaneEstimation.h b/modules/vision/include/visp3/vision/vpPlaneEstimation.h index fbf7a4453f..a4a3152858 100644 --- a/modules/vision/include/visp3/vision/vpPlaneEstimation.h +++ b/modules/vision/include/visp3/vision/vpPlaneEstimation.h @@ -40,11 +40,9 @@ #include -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ - (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) - -// Visual Studio: Optionals are available from Visual Studio 2017 RTW (15.0) [1910] -// Visual Studio: Structured bindings are available from Visual Studio 2017 version 15.3 [1911] (cf .cpp) +// Check if std:c++17 or higher. +// Here we cannot use (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) in the declaration of the class +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) // System #include diff --git a/modules/vision/include/visp3/vision/vpPose.h b/modules/vision/include/visp3/vision/vpPose.h index fbc0101b5c..3c8a60589c 100644 --- a/modules/vision/include/visp3/vision/vpPose.h +++ b/modules/vision/include/visp3/vision/vpPose.h @@ -54,8 +54,9 @@ #include #include -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ - (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) +// Check if std:c++17 or higher. +// Here we cannot use (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) in the declaration of the class +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) #include #include #endif @@ -669,8 +670,9 @@ class VISP_EXPORT vpPose static double poseFromRectangle(vpPoint &p1, vpPoint &p2, vpPoint &p3, vpPoint &p4, double lx, vpCameraParameters &cam, vpHomogeneousMatrix &cMo); -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ - (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) + // Check if std:c++17 or higher. + // Here we cannot use (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) in the declaration of the class +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) /*! * Compute the pose of a planar object from corresponding 2D-3D point coordinates and plane equation. diff --git a/modules/vision/src/plane-estimation/vpPlaneEstimation.cpp b/modules/vision/src/plane-estimation/vpPlaneEstimation.cpp index 0012c09412..8fa0e6b070 100644 --- a/modules/vision/src/plane-estimation/vpPlaneEstimation.cpp +++ b/modules/vision/src/plane-estimation/vpPlaneEstimation.cpp @@ -33,8 +33,8 @@ #include -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ - (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) +// Check if std:c++17 or higher +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) // OpenMP #ifdef VISP_HAVE_OPENMP @@ -109,7 +109,7 @@ vpPlane estimatePlaneEquationSVD(const std::vector &point_cloud, vpColVe } // Compute centroid -#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_17) +#if ((__cplusplus > 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201703L))) auto [centroid, total_w] = compute_centroid(point_cloud, weights); #else // C++17 structured binding are not fully supported by clang 13.0 on macOS diff --git a/modules/vision/src/pose-estimation/vpPoseVirtualVisualServoing.cpp b/modules/vision/src/pose-estimation/vpPoseVirtualVisualServoing.cpp index ff3857dadc..9a8b6c1c48 100644 --- a/modules/vision/src/pose-estimation/vpPoseVirtualVisualServoing.cpp +++ b/modules/vision/src/pose-estimation/vpPoseVirtualVisualServoing.cpp @@ -248,8 +248,8 @@ void vpPose::poseVirtualVSrobust(vpHomogeneousMatrix &cMo) } } -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ - (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) +// Check if std:c++17 or higher +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) std::optional vpPose::poseVirtualVSWithDepth(const std::vector &points, const vpHomogeneousMatrix &cMo) { auto residu_1 { 1e8 }, r { 1e8 - 1 }; diff --git a/tutorial/computer-vision/tutorial-pose-from-planar-object.cpp b/tutorial/computer-vision/tutorial-pose-from-planar-object.cpp index 86fa403e53..5dc9ef13b7 100644 --- a/tutorial/computer-vision/tutorial-pose-from-planar-object.cpp +++ b/tutorial/computer-vision/tutorial-pose-from-planar-object.cpp @@ -20,9 +20,8 @@ #include #include -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ - (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) && \ - defined(VISP_HAVE_DISPLAY) +// Check if std:c++17 or higher +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) && defined(VISP_HAVE_DISPLAY) // Local helper namespace @@ -40,16 +39,16 @@ using Display = vpDisplayGTK; using Display = vpDisplayD3D; #endif -constexpr auto DispScaleType{vpDisplay::SCALE_AUTO}; +constexpr auto DispScaleType { vpDisplay::SCALE_AUTO }; // Model -constexpr auto ModelCommentHeader{"#"}; -constexpr auto ModelKeypointsHeader{"Keypoints"}; -constexpr auto ModelBoundsHeader{"Bounds"}; -constexpr auto ModelDataHeader{"data:"}; +constexpr auto ModelCommentHeader { "#" }; +constexpr auto ModelKeypointsHeader { "Keypoints" }; +constexpr auto ModelBoundsHeader { "Bounds" }; +constexpr auto ModelDataHeader { "data:" }; // Depth -constexpr auto DepthScale{0.001}; +constexpr auto DepthScale { 0.001 }; } // namespace #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -73,8 +72,8 @@ class Model std::map bounds(const vpHomogeneousMatrix &cMo = {}) const; private: - std::map m_keypoints{}; - std::map m_bounds{}; + std::map m_keypoints {}; + std::map m_bounds {}; }; inline Model::Model(const std::string &model_filename) @@ -82,27 +81,29 @@ inline Model::Model(const std::string &model_filename) std::fstream file; file.open(model_filename.c_str(), std::fstream::in); - std::string line{}, subs{}; - bool in_model_bounds{false}; - bool in_model_keypoints{false}; - unsigned int data_curr_line{0}; - unsigned int data_line_start_pos{0}; + std::string line {}, subs {}; + bool in_model_bounds { false }; + bool in_model_keypoints { false }; + unsigned int data_curr_line { 0 }; + unsigned int data_line_start_pos { 0 }; auto reset = [&]() { in_model_bounds = false; in_model_keypoints = false; data_curr_line = 0; data_line_start_pos = 0; - }; + }; while (getline(file, line)) { if (line.substr(0, std::string(ModelCommentHeader).size()) == ModelCommentHeader || line == ModelDataHeader) { continue; - } else if (line == ModelBoundsHeader) { + } + else if (line == ModelBoundsHeader) { reset(); in_model_bounds = true; continue; - } else if (line == ModelKeypointsHeader) { + } + else if (line == ModelKeypointsHeader) { reset(); in_model_keypoints = true; continue; @@ -116,18 +117,20 @@ inline Model::Model(const std::string &model_filename) try { std::stringstream ss(line.substr(data_line_start_pos, line.find("]") - data_line_start_pos)); unsigned int data_on_curr_line = 0; - vpColVector oXYZ({0, 0, 0, 1}); + vpColVector oXYZ({ 0, 0, 0, 1 }); while (getline(ss, subs, ',')) { oXYZ[data_on_curr_line++] = std::atof(subs.c_str()); } if (in_model_bounds) { m_bounds.try_emplace(data_curr_line, oXYZ[0], oXYZ[1], oXYZ[2]); - } else if (in_model_keypoints) { + } + else if (in_model_keypoints) { m_keypoints.try_emplace(data_curr_line, oXYZ[0], oXYZ[1], oXYZ[2]); } data_curr_line++; - } catch (...) { - // Line is empty or incomplete. We skeep it + } + catch (...) { + // Line is empty or incomplete. We skeep it } } @@ -156,20 +159,20 @@ std::ostream &operator<<(std::ostream &os, const Model &model) for (const auto &[id, bound] : model.bounds()) { // clang-format off os << std::setw(4) << std::setfill(' ') << id << ": " - << std::setw(6) << std::setfill(' ') << bound.get_X() << ", " - << std::setw(6) << std::setfill(' ') << bound.get_Y() << ", " - << std::setw(6) << std::setfill(' ') << bound.get_Z() << std::endl; - // clang-format on + << std::setw(6) << std::setfill(' ') << bound.get_X() << ", " + << std::setw(6) << std::setfill(' ') << bound.get_Y() << ", " + << std::setw(6) << std::setfill(' ') << bound.get_Z() << std::endl; + // clang-format on } os << "-Keypoints:" << std::endl; for (const auto &[id, keypoint] : model.keypoints()) { // clang-format off os << std::setw(4) << std::setfill(' ') << id << ": " - << std::setw(6) << std::setfill(' ') << keypoint.get_X() << ", " - << std::setw(6) << std::setfill(' ') << keypoint.get_Y() << ", " - << std::setw(6) << std::setfill(' ') << keypoint.get_Z() << std::endl; - // clang-format on + << std::setw(6) << std::setfill(' ') << keypoint.get_X() << ", " + << std::setw(6) << std::setfill(' ') << keypoint.get_Y() << ", " + << std::setw(6) << std::setfill(' ') << keypoint.get_Z() << std::endl; + // clang-format on } return os; @@ -190,11 +193,11 @@ readData(const std::string &input_directory, const unsigned int cpt = 0) const std::string filename_depth = buffer; // Read color - vpImage I_color{}; + vpImage I_color {}; vpImageIo::read(I_color, filename_color); // Read raw depth - vpImage I_depth_raw{}; + vpImage I_depth_raw {}; std::ifstream file_depth(filename_depth.c_str(), std::ios::in | std::ios::binary); if (file_depth.is_open()) { unsigned int height = 0, width = 0; @@ -213,8 +216,8 @@ readData(const std::string &input_directory, const unsigned int cpt = 0) ss.str(""); ss << input_directory << "/camera.xml"; - vpXmlParserCamera parser{}; - vpCameraParameters color_param{}, depth_param{}; + vpXmlParserCamera parser {}; + vpCameraParameters color_param {}, depth_param {}; parser.parse(color_param, ss.str(), "color_camera", vpCameraParameters::perspectiveProjWithDistortion); parser.parse(depth_param, ss.str(), "depth_camera", vpCameraParameters::perspectiveProjWithDistortion); @@ -223,10 +226,10 @@ readData(const std::string &input_directory, const unsigned int cpt = 0) ss << input_directory << "/depth_M_color.txt"; std::ifstream file_depth_M_color(ss.str().c_str(), std::ios::in | std::ios::binary); - vpHomogeneousMatrix depth_M_color{}; + vpHomogeneousMatrix depth_M_color {}; depth_M_color.load(file_depth_M_color); - return {I_color, I_depth_raw, color_param, depth_param, depth_M_color}; + return { I_color, I_depth_raw, color_param, depth_param, depth_M_color }; } std::vector getRoiFromUser(vpImage color_img) @@ -236,11 +239,11 @@ std::vector getRoiFromUser(vpImage color_img) disp_color.display(color_img); disp_color.flush(color_img); - std::vector v_ip{}; + std::vector v_ip {}; do { // Prepare display disp_color.display(color_img); - auto disp_lane{0}; + auto disp_lane { 0 }; vpDisplay::displayText(color_img, 15 * ++disp_lane, 15, "Select point along the d435 box boundary", vpColor::green); vpDisplay::displayText(color_img, 15 * ++disp_lane, 15, "Left click to select a point", vpColor::green); @@ -255,8 +258,8 @@ std::vector getRoiFromUser(vpImage color_img) disp_color.flush(color_img); // Wait for new point - vpImagePoint ip{}; - vpMouseButton::vpMouseButtonType button{}; + vpImagePoint ip {}; + vpMouseButton::vpMouseButtonType button {}; vpDisplay::getClick(color_img, ip, button, true); switch (button) { @@ -288,14 +291,14 @@ std::map getKeypointsFromUser(vpImage color_img disp_color.display(color_img); disp_color.flush(color_img); - vpImage I_help{}; + vpImage I_help {}; vpImageIo::read(I_help, parent_data + "/data/d435_box_keypoints_user_helper.png"); Display disp_help(I_help, disp_color.getWindowXPosition() + color_img.getWidth(), disp_color.getWindowYPosition(), "Keypoints [help]", DispScaleType); disp_help.display(I_help); disp_help.flush(I_help); - std::map keypoints{}; + std::map keypoints {}; // - The next line produces an internal compiler error with Visual Studio 2017: // tutorial-pose-from-planar-object.cpp(304): fatal error C1001: An internal error has occurred in the compiler. // [C:\projects\visp\build\tutorial\computer-vision\tutorial-pose-from-planar-object.vcxproj] (compiler file @@ -309,7 +312,7 @@ std::map getKeypointsFromUser(vpImage color_img (void)ip_unused; // Prepare display disp_color.display(color_img); - auto disp_lane{0}; + auto disp_lane { 0 }; vpDisplay::displayText(color_img, 15 * ++disp_lane, 15, "Select the keypoints " + Model::to_string(id), vpColor::green); @@ -323,7 +326,7 @@ std::map getKeypointsFromUser(vpImage color_img disp_color.flush(color_img); // Wait for new point - vpImagePoint ip{}; + vpImagePoint ip {}; vpDisplay::getClick(color_img, ip, true); keypoints.try_emplace(id, ip); } @@ -331,20 +334,18 @@ std::map getKeypointsFromUser(vpImage color_img return keypoints; } #endif // DOXYGEN_SHOULD_SKIP_THIS -#endif // #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= -// VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) && defined(VISP_HAVE_DISPLAY) +#endif int main(int, char *argv[]) { -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ - (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) #if defined(VISP_HAVE_DISPLAY) // Get prior data //! [Prior_Data] auto [color_img, depth_raw, color_param, depth_param, depth_M_color] = - readData(vpIoTools::getParent(argv[0]) + "/data/d435_not_align_depth", 0); + readData(vpIoTools::getParent(argv[0]) + "/data/d435_not_align_depth", 0); const auto model = Model(vpIoTools::getParent(argv[0]) + "/data/d435_box.model"); //! [Prior_Data] @@ -358,7 +359,7 @@ int main(int, char *argv[]) display_color.display(color_img); display_color.flush(color_img); - vpImage depth_img{}; + vpImage depth_img {}; vpImageConvert::createDepthHistogram(depth_raw, depth_img); Display display_depth(depth_img, display_color.getWindowXPosition() + display_color.getWidth(), 0, "Depth", DispScaleType); @@ -367,29 +368,29 @@ int main(int, char *argv[]) // Ask roi for plane estimation //! [Roi_Plane_Estimation] - vpPolygon roi_color_img{}; + vpPolygon roi_color_img {}; roi_color_img.buildFrom(getRoiFromUser(color_img), true); - std::vector roi_corners_depth_img{}; + std::vector roi_corners_depth_img {}; std::transform( cbegin(roi_color_img.getCorners()), cend(roi_color_img.getCorners()), std::back_inserter(roi_corners_depth_img), std::bind((vpImagePoint(*)(const vpImage &, double, double, double, const vpCameraParameters &, const vpCameraParameters &, const vpHomogeneousMatrix &, const vpHomogeneousMatrix &, const vpImagePoint &)) & - vpColorDepthConversion::projectColorToDepth, + vpColorDepthConversion::projectColorToDepth, depth_raw, DepthScale, 0.1, 0.6, depth_param, color_param, depth_M_color.inverse(), depth_M_color, std::placeholders::_1)); - const vpPolygon roi_depth_img{roi_corners_depth_img}; + const vpPolygon roi_depth_img { roi_corners_depth_img }; //! [Roi_Plane_Estimation] vpDisplay::displayPolygon(depth_img, roi_depth_img.getCorners(), vpColor::green); display_depth.flush(depth_img); // Estimate the plane - vpImage heat_map{}; + vpImage heat_map {}; //! [Plane_Estimation] const auto obj_plane_in_depth = - vpPlaneEstimation::estimatePlane(depth_raw, DepthScale, depth_param, roi_depth_img, 1000, heat_map); + vpPlaneEstimation::estimatePlane(depth_raw, DepthScale, depth_param, roi_depth_img, 1000, heat_map); if (!obj_plane_in_depth) { return EXIT_FAILURE; } @@ -417,7 +418,7 @@ int main(int, char *argv[]) //! [Pose_Estimation] // Display the model - std::vector d435_box_bound{}; + std::vector d435_box_bound {}; // - The next line produces an internal compiler error with Visual Studio 2017: // tutorial-pose-from-planar-object.cpp(428): fatal error C1001: An internal error has occurred in the compiler. // [C:\projects\visp\build\tutorial\computer-vision\tutorial-pose-from-planar-object.vcxproj] (compiler file @@ -430,14 +431,14 @@ int main(int, char *argv[]) // for ([[maybe_unused]] const auto &[_, bound] : model.bounds(*cMo)) { for (const auto &[id_unused, bound] : model.bounds(*cMo)) { (void)id_unused; - vpImagePoint ip{}; + vpImagePoint ip {}; vpMeterPixelConversion::convertPoint(color_param, bound.get_x(), bound.get_y(), ip); d435_box_bound.push_back(ip); } vpDisplay::displayPolygon(color_img, d435_box_bound, vpColor::blue); for (const auto &[id, keypoint] : model.keypoints(*cMo)) { - vpImagePoint ip{}; + vpImagePoint ip {}; vpMeterPixelConversion::convertPoint(color_param, keypoint.get_x(), keypoint.get_y(), ip); vpDisplay::displayCross(color_img, ip, 15, vpColor::orange); vpDisplay::displayText(color_img, ip + vpImagePoint(10, 10), Model::to_string(id), vpColor::orange); @@ -448,7 +449,7 @@ int main(int, char *argv[]) vpDisplay::displayFrame(color_img, *cMo, color_param, 0.05, vpColor::none, 3); // Wait before exiting - auto disp_lane{0}; + auto disp_lane { 0 }; vpDisplay::displayText(color_img, 15 * ++disp_lane, 15, "D435 box boundary [from model]", vpColor::blue); vpDisplay::displayText(color_img, 15 * ++disp_lane, 15, "Keypoints [from model]", vpColor::orange); vpDisplay::displayText(color_img, 15 * ++disp_lane, 15, "Click to quit", vpColor::green); @@ -463,8 +464,7 @@ int main(int, char *argv[]) #else (void)argv; std::cout << "c++17 should be enabled to run this tutorial." << std::endl; -#endif // (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= - // VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) +#endif return EXIT_SUCCESS; } diff --git a/tutorial/detection/dnn/tutorial-dnn-object-detection-live.cpp b/tutorial/detection/dnn/tutorial-dnn-object-detection-live.cpp index a52634f795..f8eeeb869b 100644 --- a/tutorial/detection/dnn/tutorial-dnn-object-detection-live.cpp +++ b/tutorial/detection/dnn/tutorial-dnn-object-detection-live.cpp @@ -64,9 +64,11 @@ std::string getAvailableDetectionContainer() return availableContainers; } -int main(int argc, const char *argv []) +int main(int argc, const char *argv[]) { -#if defined(HAVE_OPENCV_DNN) && defined(HAVE_OPENCV_VIDEOIO) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) + // Check if std:c++17 or higher +#if defined(HAVE_OPENCV_DNN) && defined(HAVE_OPENCV_VIDEOIO) && \ + ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) try { std::string opt_device("0"); //! [OpenCV DNN face detector] diff --git a/tutorial/munkres/tutorial-munkres-assignment.cpp b/tutorial/munkres/tutorial-munkres-assignment.cpp index 3dbe9cf8d2..712d2440b7 100644 --- a/tutorial/munkres/tutorial-munkres-assignment.cpp +++ b/tutorial/munkres/tutorial-munkres-assignment.cpp @@ -19,8 +19,8 @@ int main() { -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && \ - (!defined(_MSC_VER) || ((VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && (_MSC_VER >= 1911))) + // Check if std:c++17 or higher +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) #if defined(VISP_HAVE_DISPLAY) // Create base img @@ -28,8 +28,8 @@ int main() // Generate random points //! [Rand_Img_Pts] - vpUniRand rand{}; - std::vector rand_ips{}; + vpUniRand rand {}; + std::vector rand_ips {}; while (rand_ips.size() < 10) { rand_ips.emplace_back(rand.uniform(10, I.getHeight() - 10), rand.uniform(10, I.getWidth() - 10)); } @@ -56,11 +56,11 @@ int main() // Local helper to display a point in the image auto display_point = [&I](const vpImagePoint &ip, const vpColor &color) { I.display->displayCircle(ip, 5, color, true, 1); - }; + }; vpDisplay::display(I); - auto disp_lane{0}; + auto disp_lane { 0 }; vpDisplay::displayText(I, 15 * ++disp_lane, 15, "Left click to add a point", vpColor::black); vpDisplay::displayText(I, 15 * ++disp_lane, 15, "Middle click to continue (run Munkres)", vpColor::black); vpDisplay::displayText(I, 15 * ++disp_lane, 15, "Right click to quit", vpColor::black); @@ -70,14 +70,15 @@ int main() // Ask user to clic on point //! [User_Img_Pts] - std::vector user_ips{}; - vpMouseButton::vpMouseButtonType button{}; + std::vector user_ips {}; + vpMouseButton::vpMouseButtonType button {}; while (button != vpMouseButton::button2) { - vpImagePoint ip{}; + vpImagePoint ip {}; vpDisplay::getClick(I, ip, button, true); if (button == vpMouseButton::button1) { user_ips.push_back(ip); - } else if (button == vpMouseButton::button3) { + } + else if (button == vpMouseButton::button3) { return EXIT_SUCCESS; } @@ -112,7 +113,8 @@ int main() vpDisplay::flush(I); vpDisplay::getClick(I); - } catch (const vpException &e) { + } + catch (const vpException &e) { std::cout << "Catch an exception: " << e << std::endl; } #endif // defined(VISP_HAVE_DISPLAY) diff --git a/tutorial/tracking/dnn/tutorial-megapose-live-single-object-tracking.cpp b/tutorial/tracking/dnn/tutorial-megapose-live-single-object-tracking.cpp index e418b1eb3c..0fff291973 100644 --- a/tutorial/tracking/dnn/tutorial-megapose-live-single-object-tracking.cpp +++ b/tutorial/tracking/dnn/tutorial-megapose-live-single-object-tracking.cpp @@ -2,8 +2,11 @@ #include #include -#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) && defined(VISP_HAVE_NLOHMANN_JSON) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_VIDEOIO) && defined(HAVE_OPENCV_DNN) && \ - (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(HAVE_OPENCV_HIGHGUI)) + +// Check if std:c++17 or higher +#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) && \ + defined(VISP_HAVE_NLOHMANN_JSON) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_VIDEOIO) && \ + defined(HAVE_OPENCV_DNN) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(HAVE_OPENCV_HIGHGUI)) #include @@ -188,7 +191,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM(DetectionMethod, { ); -int main(int argc, const char *argv []) +int main(int argc, const char *argv[]) { unsigned width = 640, height = 480; vpCameraParameters cam; @@ -279,7 +282,8 @@ int main(int argc, const char *argv []) vpDisplayOpenCV d; #endif //d.setDownScalingFactor(vpDisplay::SCALE_AUTO); -#if (VISP_HAVE_OPENCV_VERSION >= 0x030403) && defined(HAVE_OPENCV_DNN) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +#if (VISP_HAVE_OPENCV_VERSION >= 0x030403) && defined(HAVE_OPENCV_DNN) && \ + ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) vpDetectorDNNOpenCV::DNNResultsParsingType detectorType = vpDetectorDNNOpenCV::dnnResultsParsingTypeFromString(detectorTypeString); vpDetectorDNNOpenCV::NetConfig netConfig(detectorConfidenceThreshold, detectorNmsThreshold, labels, @@ -367,7 +371,8 @@ int main(int argc, const char *argv []) if (!initialized) { tracking = false; std::optional detection = std::nullopt; -#if (VISP_HAVE_OPENCV_VERSION >= 0x030403) && defined(HAVE_OPENCV_DNN) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_17) +#if (VISP_HAVE_OPENCV_VERSION >= 0x030403) && defined(HAVE_OPENCV_DNN) && \ + ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) if (detectionMethod == DetectionMethod::DNN) { detection = detectObjectForInitMegaposeDnn( dnn, frame, objectName, initialized ? std::optional(megaposeEstimate) : std::nullopt); From 3b4c8826f04dcdb4cf382a83cb1eeb8339d92a59 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 16 Nov 2023 17:37:21 +0100 Subject: [PATCH 9/9] Fix warning: comparing floating point with == or != is unsafe [-Wfloat-equal] --- modules/imgproc/src/vpCircleHoughTransform.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/imgproc/src/vpCircleHoughTransform.cpp b/modules/imgproc/src/vpCircleHoughTransform.cpp index f1be206cd4..ea4839c104 100644 --- a/modules/imgproc/src/vpCircleHoughTransform.cpp +++ b/modules/imgproc/src/vpCircleHoughTransform.cpp @@ -28,6 +28,8 @@ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ +#include + #include #include #include @@ -476,9 +478,9 @@ vpCircleHoughTransform::computeCenterCandidates() for (int y = 0; y < nbRowsAccum; y++) { int left = -1; for (int x = 0; x < nbColsAccum; x++) { - if (centersAccum[y][x] >= m_algoParams.m_centerThresh - && centersAccum[y][x] == centerCandidatesMaxima[y][x] - && centersAccum[y][x] > centersAccum[y][x + 1] + if ((centersAccum[y][x] >= m_algoParams.m_centerThresh) + && (std::fabs(centersAccum[y][x] - centerCandidatesMaxima[y][x]) < std::numeric_limits::epsilon()) + && (centersAccum[y][x] > centersAccum[y][x + 1]) ) { if (left < 0) left = x;