From 1f6389dbedb0f0037b902c01c85e68cb077c54d7 Mon Sep 17 00:00:00 2001 From: LAGNEAU Romain Date: Wed, 6 Nov 2024 10:38:19 +0100 Subject: [PATCH 01/31] [FIX] Fixed the memorization of the voting points for the CHT The voting points vector was not reinitialized when evaluating a new center, it remembered the voting points for the same radii but other circles --- modules/imgproc/src/vpCircleHoughTransform_circles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/imgproc/src/vpCircleHoughTransform_circles.cpp b/modules/imgproc/src/vpCircleHoughTransform_circles.cpp index ee328335c6..dfda9b692b 100644 --- a/modules/imgproc/src/vpCircleHoughTransform_circles.cpp +++ b/modules/imgproc/src/vpCircleHoughTransform_circles.cpp @@ -139,7 +139,6 @@ vpCircleHoughTransform::computeCircleCandidates() nbBins = std::max(static_cast(1), nbBins); // Avoid having 0 bins, which causes segfault std::vector radiusAccumList; // Radius accumulator for each center candidates. std::vector radiusActualValueList; // Vector that contains the actual distance between the edge points and the center candidates. - std::vector > > votingPoints(nbBins); // Vectors that contain the points voting for each radius bin float rmin2 = m_algoParams.m_minRadius * m_algoParams.m_minRadius; float rmax2 = m_algoParams.m_maxRadius * m_algoParams.m_maxRadius; @@ -153,6 +152,7 @@ vpCircleHoughTransform::computeCircleCandidates() data.m_recordVotingPoints = m_algoParams.m_recordVotingPoints; for (size_t i = 0; i < nbCenterCandidates; ++i) { + std::vector > > votingPoints(nbBins); // Vectors that contain the points voting for each radius bin std::pair centerCandidate = m_centerCandidatesList[i]; // Initialize the radius accumulator of the candidate with 0s radiusAccumList.clear(); From 53b3080dfb71efce0731caabca58afb10d4507bb Mon Sep 17 00:00:00 2001 From: LAGNEAU Romain Date: Wed, 6 Nov 2024 11:16:56 +0100 Subject: [PATCH 02/31] [CORE] Added some method to ease the use of voting points --- .../visp3/imgproc/vpCircleHoughTransform.h | 48 +++++++++++++++++++ .../src/vpCircleHoughTransform_common.cpp | 3 ++ 2 files changed, 51 insertions(+) diff --git a/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h b/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h index 7448ea4722..c39f1aa2ba 100644 --- a/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h +++ b/modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h @@ -1042,10 +1042,39 @@ class VISP_EXPORT vpCircleHoughTransform } } + /*! + * \brief Set the mask that permits to ignore some pixels when performing the circle detection. + * + * \param[in] mask A boolean image where pixels set to true means that the pixel + * must be considered and set to false means that the pixel must be ignored. + */ inline void setMask(const vpImage &mask) { mp_mask = &mask; } + + /*! + * \brief Set the mask that permits to ignore some pixels when performing the circle detection. + * + * \param[in] mask Either a boolean image where pixels set to true means that the pixel + * must be considered and set to false means that the pixel must be ignored, or nullptr + * to deactivate the mask. + */ + inline void setMask(const vpImage *mask) + { + mp_mask = mask; + } + + /*! + * \brief Permits to either activate or deactivate the memorization + * of the points that voted for the detected circles. + * + * \param[in] record True to activate the feature, false to deactivate it. + */ + inline void setRecordVotingPoints(const bool &record) + { + m_algoParams.m_recordVotingPoints = record; + } //@} /** @name Getters */ @@ -1179,6 +1208,25 @@ class VISP_EXPORT vpCircleHoughTransform { return m_finalCircleVotes; } + + /*! + * Get the points that voted for the detections that are outputed by vpCircleHoughTransform::detect(). + */ + inline std::vector > > getDetectionsVotingPoints() const + { + if (!m_algoParams.m_recordVotingPoints) { + throw(vpException(vpException::fatalError, "Asking voting points when it was not asked to remember them.")); + } + return m_finalCirclesVotingPoints; + } + + /*! + * Returns true if it was asked to record the points that voted for the detections. + */ + inline bool getRecordVotingPoints() const + { + return m_algoParams.getRecordVotingPoints(); + } //@} /*! diff --git a/modules/imgproc/src/vpCircleHoughTransform_common.cpp b/modules/imgproc/src/vpCircleHoughTransform_common.cpp index 20135a0574..e65d0e7982 100644 --- a/modules/imgproc/src/vpCircleHoughTransform_common.cpp +++ b/modules/imgproc/src/vpCircleHoughTransform_common.cpp @@ -268,8 +268,11 @@ vpCircleHoughTransform::detect(const vpImage &I) m_circleCandidates.clear(); m_circleCandidatesVotes.clear(); m_circleCandidatesProbabilities.clear(); + m_circleCandidatesVotingPoints.clear(); m_finalCircles.clear(); m_finalCircleVotes.clear(); + m_finalCirclesProbabilities.clear(); + m_finalCirclesVotingPoints.clear(); // Ensuring that the difference between the max and min radii is big enough to take into account // the pixelization of the image From fe79ec14c8180db0ee0b6882e822302172181f85 Mon Sep 17 00:00:00 2001 From: LAGNEAU Romain Date: Thu, 7 Nov 2024 16:23:14 +0100 Subject: [PATCH 03/31] [DOC] Updated DNN detection tutorial --- .../detection_dnn/tutorial-detection-dnn.dox | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/tutorial/detection_dnn/tutorial-detection-dnn.dox b/doc/tutorial/detection_dnn/tutorial-detection-dnn.dox index d97c73a9ae..b39f68352c 100644 --- a/doc/tutorial/detection_dnn/tutorial-detection-dnn.dox +++ b/doc/tutorial/detection_dnn/tutorial-detection-dnn.dox @@ -13,8 +13,8 @@ class ids and confidence values of a single or of multiple classes. For other tasks such as image segmentation or more complicated uses, you should use directly the OpenCV DNN API. -This class supports `Faster-RCNN`, `SSD-MobileNet`, `ResNet 10`, `Yolo v3`, `Yolo v4`, `Yolo v5`, `Yolo v7` and -`Yolo v8` convolutional networks that simultaneously predict object boundaries and prediction scores at each position. +This class supports `Faster-RCNN`, `SSD-MobileNet`, `ResNet 10`, `Yolo v3`, `Yolo v4`, `Yolo v5`, `Yolo v7`, +`Yolo v8` and `Yolo v11` convolutional networks that simultaneously predict object boundaries and prediction scores at each position. If you want to use another type of network, you can define your own parsing method of the DNN detection results and give it to the `vpDetectorDNNOpenCV` object. @@ -74,13 +74,13 @@ $ sudo apt install libgtk-3-dev \ libx11-dev \endcode -6. Get the sources. The \b vpDetectorDNNOpenCV has been tested with **OpenCV 4.7**. First, get the OpenCV_contrib -sources, that contain the Cuda DNN module. +6. Get the sources. The \b vpDetectorDNNOpenCV has been tested with **OpenCV 4.7** and **OpenCV 4.10**. First, +get the OpenCV_contrib sources, that contain the Cuda DNN module. On a Debian distribution, you would run: \code{.sh} $ cd ${HOME}/visp_ws/3rdparty/ -$ git clone --branch 4.7.0 https://github.com/opencv/opencv_contrib -$ git clone --branch 4.7.0 https://github.com/opencv/opencv +$ git clone --branch 4.10.0 https://github.com/opencv/opencv_contrib +$ git clone --branch 4.10.0 https://github.com/opencv/opencv \endcode 7. Compile OpenCV and install it from source. On a Debian distribution, you would run: @@ -149,6 +149,7 @@ on DNN models learned from the following networks: - Yolo v5 - Yolo v7 - Yolo v8 +- Yolo v11 It uses video capture capability from OpenCV to capture images from a camera and detect objects using a DNN model learned using one of the previous networks. From ae330f6f13ba5b1925f95a04ff9f5f71c2da01a5 Mon Sep 17 00:00:00 2001 From: Souriya Trinh Date: Tue, 12 Nov 2024 21:55:21 +0100 Subject: [PATCH 04/31] Fix scripts to print camera frame as in computer vision convention. --- .../extract_sift_sampling_Suzanne.py | 16 +++++++++------ .../render_still_image_Suzanne.py | 20 +++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/script/Blender/Keypoints_extraction/extract_sift_sampling_Suzanne.py b/script/Blender/Keypoints_extraction/extract_sift_sampling_Suzanne.py index 4f67ab41cc..cf1ca23749 100755 --- a/script/Blender/Keypoints_extraction/extract_sift_sampling_Suzanne.py +++ b/script/Blender/Keypoints_extraction/extract_sift_sampling_Suzanne.py @@ -65,9 +65,13 @@ def inv_transfo(w_T_o): return o_T_w def get_camera_pose(cameraName, objectName): - M = np.eye(4) - M[1][1] = -1 - M[2][2] = -1 + # Camera frame in OpenGL: + # X-axis to the right + # Y-axis up + # Z-axis backward + cv_M_gl = np.eye(4) + cv_M_gl[1][1] = -1 + cv_M_gl[2][2] = -1 cam = bpy.data.objects[cameraName] object_pose = bpy.data.objects[objectName].matrix_world @@ -82,13 +86,13 @@ def get_camera_pose(cameraName, objectName): w_T_o = np.array(object_pose_normalized_blender) print(f"object_pose_normalized:\n{object_pose_normalized_blender}") - w_T_c = np.array(cam.matrix_world) + w_T_c = np.array(cam.matrix_world) @ cv_M_gl print(f"w_T_c:\n{w_T_c}") - c_T_w = np.array(cam.matrix_world.inverted()) + c_T_w = cv_M_gl @ np.array(cam.matrix_world.inverted()) print(f"c_T_w:\n{c_T_w}") - c_T_o = M @ c_T_w @ w_T_o + c_T_o = c_T_w @ w_T_o print(f"c_T_o:\n{c_T_o}") return c_T_o diff --git a/script/Blender/Keypoints_extraction/render_still_image_Suzanne.py b/script/Blender/Keypoints_extraction/render_still_image_Suzanne.py index 14ae6fc3b1..644b67bf03 100755 --- a/script/Blender/Keypoints_extraction/render_still_image_Suzanne.py +++ b/script/Blender/Keypoints_extraction/render_still_image_Suzanne.py @@ -63,9 +63,13 @@ def inv_transfo(w_T_o): return o_T_w def get_camera_pose(cameraName, objectName): - M = np.eye(4) - M[1][1] = -1 - M[2][2] = -1 + # Camera frame in OpenGL: + # X-axis to the right + # Y-axis up + # Z-axis backward + cv_M_gl = np.eye(4) + cv_M_gl[1][1] = -1 + cv_M_gl[2][2] = -1 cam = bpy.data.objects[cameraName] object_pose = bpy.data.objects[objectName].matrix_world @@ -80,16 +84,16 @@ def get_camera_pose(cameraName, objectName): w_T_o = np.array(object_pose_normalized_blender) print(f"object_pose_normalized:\n{object_pose_normalized_blender}") - w_T_c = np.array(cam.matrix_world) + w_T_c = np.array(cam.matrix_world) @ cv_M_gl print(f"w_T_c:\n{w_T_c}") - c_T_w = np.array(cam.matrix_world.inverted()) + c_T_w = cv_M_gl @ np.array(cam.matrix_world.inverted()) print(f"c_T_w:\n{c_T_w}") c_T_w2 = inv_transfo(w_T_c) - print(f"c_T_w2:\n{c_T_w2}") + print(f"c_T_w2:\n{c_T_w2}") # c_T_w (using Blender inverted()) and c_T_w2 should be equal - c_T_o = M @ c_T_w @ w_T_o + c_T_o = c_T_w @ w_T_o print(f"c_T_o:\n{c_T_o}") return c_T_o @@ -111,4 +115,4 @@ def get_camera_pose(cameraName, objectName): output_pose_name = "c_T_o.txt" output_pose_filepath = os.path.join(output_dir, output_pose_name) - np.savetxt(output_pose_filepath, c_T_o) \ No newline at end of file + np.savetxt(output_pose_filepath, c_T_o) From 467d0c0da966f84acce2cc9ed4b956b0fb519eae Mon Sep 17 00:00:00 2001 From: Olivier Roussel Date: Tue, 19 Nov 2024 11:20:02 +0100 Subject: [PATCH 05/31] fix missing build tools with conda --- doc/tutorial/python/tutorial-install-python-bindings.dox | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/tutorial/python/tutorial-install-python-bindings.dox b/doc/tutorial/python/tutorial-install-python-bindings.dox index 7a7f9caf7c..b63e3dd5e3 100644 --- a/doc/tutorial/python/tutorial-install-python-bindings.dox +++ b/doc/tutorial/python/tutorial-install-python-bindings.dox @@ -115,19 +115,19 @@ We strongly recommend using Conda to build ViSP Python bindings. Below are instr - **A. On macOS**: - (visp-conda-ws) $ conda install cmake xorg-libx11 xorg-libxfixes libxml2 libdc1394 >=2.2.6 librealsense libopencv eigen libjpeg-turbo libpng libopenblas llvm-openmp pybind11 + (visp-conda-ws) $ conda install cmake cxx-compiler make xorg-libx11 xorg-libxfixes libxml2 libdc1394 librealsense libopencv eigen libjpeg-turbo libpng libopenblas llvm-openmp pybind11 - **B. On Ubuntu or other linux-like**: We recommend this minimal set of dependencies to get the main features of ViSP available: - (visp-conda-ws) $ conda install cmake xorg-libx11 xorg-libxfixes libxml2 libdc1394 >=2.2.6 librealsense libgomp libopencv eigen libjpeg-turbo libpng mkl-devel pybind11 + (visp-conda-ws) $ conda install cmake cxx-compiler make xorg-libx11 xorg-libxfixes libxml2 libdc1394 librealsense libgomp libopencv eigen libjpeg-turbo libpng mkl-devel pybind11 - **C. On Windows**: We recommend this minimal set of dependencies to get the main features of ViSP available: - (visp-conda-ws) C:\Users\User> conda install cmake llvm-openmp openmp libopencv eigen libjpeg-turbo libpng mkl-devel pybind11 + (visp-conda-ws) C:\Users\User> conda install cmake cxx-compiler llvm-openmp openmp libopencv eigen libjpeg-turbo libpng mkl-devel pybind11 \note In the previous installation commands you can also specify the Python version if desired adding for example `python=3.10` to the previous command lines. From a50276d0c81b65dc7cab0f86f87748541eb9ac6b Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 25 Nov 2024 17:24:55 +0100 Subject: [PATCH 06/31] Bump cmake minimum version to 3.10 to avoid warning with the latest version 3.31.1 --- CMakeLists.txt | 2 +- apps/CMakeLists.txt | 2 +- apps/calibration/CMakeLists.txt | 2 +- cmake/VISPGenerateConfigScript.cmake | 2 +- demo/CMakeLists.txt | 2 +- demo/wireframe-simulator/CMakeLists.txt | 2 +- example/CMakeLists.txt | 2 +- example/calibration/CMakeLists.txt | 2 +- example/coin-simulator/CMakeLists.txt | 2 +- example/device/display/CMakeLists.txt | 2 +- example/device/framegrabber/CMakeLists.txt | 2 +- example/device/kinect/CMakeLists.txt | 2 +- example/device/laserscanner/CMakeLists.txt | 2 +- example/device/light/CMakeLists.txt | 2 +- example/direct-visual-servoing/CMakeLists.txt | 2 +- example/homography/CMakeLists.txt | 2 +- example/image/CMakeLists.txt | 2 +- example/kalman/CMakeLists.txt | 2 +- example/manual/CMakeLists.txt | 2 +- example/manual/geometric-features/CMakeLists.txt | 3 +-- example/manual/hello-world/CMake/CMakeLists.txt | 2 +- example/manual/image-manipulation/CMakeLists.txt | 3 +-- example/manual/moments/CMakeLists.txt | 4 +--- example/manual/ogre/CMakeLists.txt | 2 +- example/manual/simulation/CMakeLists.txt | 3 +-- example/math/CMakeLists.txt | 2 +- example/moments/image/CMakeLists.txt | 2 +- example/moments/points/CMakeLists.txt | 2 +- example/moments/polygon/CMakeLists.txt | 2 +- example/ogre-simulator/CMakeLists.txt | 2 +- example/parse-argv/CMakeLists.txt | 2 +- example/particle-filter/CMakeLists.txt | 2 +- example/pose-estimation/CMakeLists.txt | 2 +- example/reflex-takktile/CMakeLists.txt | 2 +- example/robot-simulator/afma6/CMakeLists.txt | 2 +- example/robot-simulator/camera/CMakeLists.txt | 2 +- example/robot-simulator/viper850/CMakeLists.txt | 2 +- example/servo-afma4/CMakeLists.txt | 2 +- example/servo-afma6/CMakeLists.txt | 2 +- example/servo-bebop2/CMakeLists.txt | 2 +- example/servo-biclops/CMakeLists.txt | 2 +- example/servo-flir-ptu/CMakeLists.txt | 2 +- example/servo-franka/CMakeLists.txt | 2 +- example/servo-kinova/CMakeLists.txt | 2 +- example/servo-pioneer/CMakeLists.txt | 2 +- example/servo-pixhawk/CMakeLists.txt | 2 +- example/servo-pololu-ptu/CMakeLists.txt | 2 +- example/servo-ptu46/CMakeLists.txt | 2 +- example/servo-universal-robots/CMakeLists.txt | 2 +- example/servo-viper650/CMakeLists.txt | 2 +- example/servo-viper850/CMakeLists.txt | 2 +- example/tools/CMakeLists.txt | 2 +- example/tracking/CMakeLists.txt | 2 +- example/video/CMakeLists.txt | 2 +- example/wireframe-simulator/CMakeLists.txt | 2 +- tutorial/CMakeLists.txt | 2 +- tutorial/ar/CMakeLists.txt | 2 +- tutorial/bridge/opencv/CMakeLists.txt | 2 +- tutorial/computer-vision/CMakeLists.txt | 2 +- tutorial/detection/barcode/CMakeLists.txt | 2 +- tutorial/detection/dnn/CMakeLists.txt | 2 +- tutorial/detection/face/CMakeLists.txt | 2 +- tutorial/detection/matching/CMakeLists.txt | 2 +- tutorial/detection/object/CMakeLists.txt | 2 +- tutorial/detection/tag/CMakeLists.txt | 2 +- tutorial/grabber/CMakeLists.txt | 2 +- tutorial/gui/pcl-visualizer/CMakeLists.txt | 2 +- tutorial/image/CMakeLists.txt | 2 +- tutorial/imgproc/autothreshold/CMakeLists.txt | 2 +- tutorial/imgproc/brightness/CMakeLists.txt | 2 +- tutorial/imgproc/connected-components/CMakeLists.txt | 2 +- tutorial/imgproc/contour/CMakeLists.txt | 2 +- tutorial/imgproc/contrast-sharpening/CMakeLists.txt | 2 +- tutorial/imgproc/count-coins/CMakeLists.txt | 2 +- tutorial/imgproc/flood-fill/CMakeLists.txt | 2 +- tutorial/imgproc/hough-transform/CMakeLists.txt | 2 +- tutorial/kalman/CMakeLists.txt | 2 +- tutorial/matlab/CMakeLists.txt | 2 +- tutorial/mean-drift/CMakeLists.txt | 2 +- tutorial/misc/npz/CMakeLists.txt | 2 +- tutorial/munkres/CMakeLists.txt | 2 +- tutorial/particle-filter-curve-fitting/CMakeLists.txt | 2 +- tutorial/particle-filter/CMakeLists.txt | 2 +- tutorial/robot/flir-ptu/CMakeLists.txt | 2 +- tutorial/robot/mbot/raspberry/visp/CMakeLists.txt | 2 +- tutorial/robot/pioneer/CMakeLists.txt | 2 +- tutorial/segmentation/color/CMakeLists.txt | 2 +- tutorial/simulator/image/CMakeLists.txt | 2 +- tutorial/trace/CMakeLists.txt | 2 +- tutorial/tracking/blob/CMakeLists.txt | 2 +- tutorial/tracking/dnn/CMakeLists.txt | 2 +- tutorial/tracking/keypoint/CMakeLists.txt | 2 +- tutorial/tracking/model-based/generic-apriltag/CMakeLists.txt | 2 +- .../tracking/model-based/generic-rgbd-blender/CMakeLists.txt | 2 +- tutorial/tracking/model-based/generic-rgbd/CMakeLists.txt | 2 +- tutorial/tracking/model-based/generic-stereo/CMakeLists.txt | 2 +- tutorial/tracking/model-based/generic/CMakeLists.txt | 2 +- tutorial/tracking/model-based/old/edges/CMakeLists.txt | 2 +- tutorial/tracking/model-based/old/generic/CMakeLists.txt | 2 +- tutorial/tracking/model-based/old/hybrid/CMakeLists.txt | 2 +- tutorial/tracking/model-based/old/keypoint/CMakeLists.txt | 2 +- tutorial/tracking/moving-edges/CMakeLists.txt | 2 +- tutorial/tracking/template-tracker/CMakeLists.txt | 2 +- tutorial/visual-servo/ibvs/CMakeLists.txt | 2 +- 104 files changed, 104 insertions(+), 109 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4789c8db78..6635e2b875 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,7 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE) endif() -cmake_minimum_required(VERSION 3.5) # needs to be before project() for policy CMP0025 +cmake_minimum_required(VERSION 3.10) # needs to be before project() for policy CMP0025 # Detect if the toolchain is for Aldebaran naoqi if(CMAKE_TOOLCHAIN_FILE AND I_AM_A_ROBOT) diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 9005d98da6..2737090285 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(ViSP-apps) diff --git a/apps/calibration/CMakeLists.txt b/apps/calibration/CMakeLists.txt index f3dce0c0b1..952dacffee 100644 --- a/apps/calibration/CMakeLists.txt +++ b/apps/calibration/CMakeLists.txt @@ -1,6 +1,6 @@ project(apps-calibration) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_vision visp_io OPTIONAL_COMPONENTS visp_gui visp_robot visp_sensor) diff --git a/cmake/VISPGenerateConfigScript.cmake b/cmake/VISPGenerateConfigScript.cmake index 04489e5dce..ad3a4b944d 100644 --- a/cmake/VISPGenerateConfigScript.cmake +++ b/cmake/VISPGenerateConfigScript.cmake @@ -256,7 +256,7 @@ set(TARGET_LOCATION_${item} \"${item}${VISP_VERSION_MAJOR}${VISP_VERSION_MINOR}$ # ============================================================================= else() # DEFINED CMAKE_HELPER_SCRIPT - cmake_minimum_required(VERSION 3.5) + cmake_minimum_required(VERSION 3.10) include("${CMAKE_HELPER_SCRIPT}") include("${VISP_SOURCE_DIR}/cmake/VISPUtils.cmake") diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt index ed09ecfc80..e05c66fbc8 100644 --- a/demo/CMakeLists.txt +++ b/demo/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(ViSP-demo) diff --git a/demo/wireframe-simulator/CMakeLists.txt b/demo/wireframe-simulator/CMakeLists.txt index 1744567e5e..e1e4384292 100644 --- a/demo/wireframe-simulator/CMakeLists.txt +++ b/demo/wireframe-simulator/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(demo-wireframe-simulator) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 5e53d521a9..0e3bc34df3 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(ViSP-examples) diff --git a/example/calibration/CMakeLists.txt b/example/calibration/CMakeLists.txt index 13e257985e..5269a69ac4 100644 --- a/example/calibration/CMakeLists.txt +++ b/example/calibration/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-calibration) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_vision visp_gui visp_io) diff --git a/example/coin-simulator/CMakeLists.txt b/example/coin-simulator/CMakeLists.txt index 09e3202b93..efce508197 100644 --- a/example/coin-simulator/CMakeLists.txt +++ b/example/coin-simulator/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-coin-simulator) diff --git a/example/device/display/CMakeLists.txt b/example/device/display/CMakeLists.txt index a0e447a69d..1d8cbc60fc 100644 --- a/example/device/display/CMakeLists.txt +++ b/example/device/display/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-device-display) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_gui visp_io) diff --git a/example/device/framegrabber/CMakeLists.txt b/example/device/framegrabber/CMakeLists.txt index 49f1f039e5..ac80e54b4e 100644 --- a/example/device/framegrabber/CMakeLists.txt +++ b/example/device/framegrabber/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-device-framegrabber) diff --git a/example/device/kinect/CMakeLists.txt b/example/device/kinect/CMakeLists.txt index f3e0b1ca70..93cb732b28 100644 --- a/example/device/kinect/CMakeLists.txt +++ b/example/device/kinect/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-device-kinect) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_sensor visp_gui) diff --git a/example/device/laserscanner/CMakeLists.txt b/example/device/laserscanner/CMakeLists.txt index 27db5c1d4d..47eb6205fd 100644 --- a/example/device/laserscanner/CMakeLists.txt +++ b/example/device/laserscanner/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-device-laserscanner) diff --git a/example/device/light/CMakeLists.txt b/example/device/light/CMakeLists.txt index adc44f3adb..71c88d6902 100644 --- a/example/device/light/CMakeLists.txt +++ b/example/device/light/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-device-laserscanner) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_robot visp_io) diff --git a/example/direct-visual-servoing/CMakeLists.txt b/example/direct-visual-servoing/CMakeLists.txt index 868061c77c..806d868df3 100644 --- a/example/direct-visual-servoing/CMakeLists.txt +++ b/example/direct-visual-servoing/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-direct-vvs) diff --git a/example/homography/CMakeLists.txt b/example/homography/CMakeLists.txt index 91e6e05c8e..8fa544b466 100644 --- a/example/homography/CMakeLists.txt +++ b/example/homography/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-homography) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_vision visp_io) diff --git a/example/image/CMakeLists.txt b/example/image/CMakeLists.txt index 578b391ac3..7b1fa6a52c 100644 --- a/example/image/CMakeLists.txt +++ b/example/image/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-image) diff --git a/example/kalman/CMakeLists.txt b/example/kalman/CMakeLists.txt index 103891f971..72a8f087b6 100644 --- a/example/kalman/CMakeLists.txt +++ b/example/kalman/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-kalman) diff --git a/example/manual/CMakeLists.txt b/example/manual/CMakeLists.txt index f6aa07dc0b..20e18a669e 100644 --- a/example/manual/CMakeLists.txt +++ b/example/manual/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-manual) diff --git a/example/manual/geometric-features/CMakeLists.txt b/example/manual/geometric-features/CMakeLists.txt index 6b8a0dec87..f21caf5667 100644 --- a/example/manual/geometric-features/CMakeLists.txt +++ b/example/manual/geometric-features/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(GeometricFeatures) @@ -8,4 +8,3 @@ if(VISP_FOUND) endif() add_executable(manGeometricFeatures manGeometricFeatures.cpp) - diff --git a/example/manual/hello-world/CMake/CMakeLists.txt b/example/manual/hello-world/CMake/CMakeLists.txt index fb494a6148..336c570db5 100644 --- a/example/manual/hello-world/CMake/CMakeLists.txt +++ b/example/manual/hello-world/CMake/CMakeLists.txt @@ -1,6 +1,6 @@ project(HelloWorld) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED) if(VISP_FOUND) diff --git a/example/manual/image-manipulation/CMakeLists.txt b/example/manual/image-manipulation/CMakeLists.txt index f30596085f..3884e184d0 100644 --- a/example/manual/image-manipulation/CMakeLists.txt +++ b/example/manual/image-manipulation/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(ImageManipulation) @@ -12,4 +12,3 @@ add_executable(manGrab1394 manGrab1394.cpp) add_executable(manGrabDirectShow manGrabDirectShow.cpp) add_executable(manGrabDisk manGrabDisk.cpp) add_executable(manGrabV4l2 manGrabV4l2.cpp) - diff --git a/example/manual/moments/CMakeLists.txt b/example/manual/moments/CMakeLists.txt index d618b807de..71fdda43db 100644 --- a/example/manual/moments/CMakeLists.txt +++ b/example/manual/moments/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(man-moment) @@ -8,5 +8,3 @@ if(VISP_FOUND) endif() add_executable(manServoMomentsSimple manServoMomentsSimple.cpp) - - diff --git a/example/manual/ogre/CMakeLists.txt b/example/manual/ogre/CMakeLists.txt index d1f97d9811..915b84ae2f 100644 --- a/example/manual/ogre/CMakeLists.txt +++ b/example/manual/ogre/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(OgreTutorial) diff --git a/example/manual/simulation/CMakeLists.txt b/example/manual/simulation/CMakeLists.txt index 24d09a2551..5dd3f5f615 100644 --- a/example/manual/simulation/CMakeLists.txt +++ b/example/manual/simulation/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(ImageManipulation) @@ -10,4 +10,3 @@ endif() add_executable(manServo4PointsDisplay manServo4PointsDisplay.cpp) add_executable(manSimu4Dots manSimu4Dots.cpp) add_executable(manSimu4Points manSimu4Points.cpp) - diff --git a/example/math/CMakeLists.txt b/example/math/CMakeLists.txt index fc150f27a7..4ba0a86ced 100644 --- a/example/math/CMakeLists.txt +++ b/example/math/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-math) diff --git a/example/moments/image/CMakeLists.txt b/example/moments/image/CMakeLists.txt index 29f33b4078..795200f312 100644 --- a/example/moments/image/CMakeLists.txt +++ b/example/moments/image/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-moments-image) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_vs visp_robot visp_gui) diff --git a/example/moments/points/CMakeLists.txt b/example/moments/points/CMakeLists.txt index 3130e99edc..4cd1d692ec 100644 --- a/example/moments/points/CMakeLists.txt +++ b/example/moments/points/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-moments-points) diff --git a/example/moments/polygon/CMakeLists.txt b/example/moments/polygon/CMakeLists.txt index 5e36802fa6..d8940e4853 100644 --- a/example/moments/polygon/CMakeLists.txt +++ b/example/moments/polygon/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-moments-polygon) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_vs visp_robot visp_gui) diff --git a/example/ogre-simulator/CMakeLists.txt b/example/ogre-simulator/CMakeLists.txt index d4e37fa461..7209cc76d4 100644 --- a/example/ogre-simulator/CMakeLists.txt +++ b/example/ogre-simulator/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-ogre-simulator) diff --git a/example/parse-argv/CMakeLists.txt b/example/parse-argv/CMakeLists.txt index 2c28315bf0..51f51d60b8 100644 --- a/example/parse-argv/CMakeLists.txt +++ b/example/parse-argv/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-parse-argv) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_io) diff --git a/example/particle-filter/CMakeLists.txt b/example/particle-filter/CMakeLists.txt index a888328ea1..9fcb2d9d1d 100644 --- a/example/particle-filter/CMakeLists.txt +++ b/example/particle-filter/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-kalman) diff --git a/example/pose-estimation/CMakeLists.txt b/example/pose-estimation/CMakeLists.txt index faf47cef22..04789e535a 100644 --- a/example/pose-estimation/CMakeLists.txt +++ b/example/pose-estimation/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-pose-estimation) diff --git a/example/reflex-takktile/CMakeLists.txt b/example/reflex-takktile/CMakeLists.txt index 505ea9a81e..62128e0c2d 100644 --- a/example/reflex-takktile/CMakeLists.txt +++ b/example/reflex-takktile/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-reflex-takktile) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) if(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore) set(WINRT TRUE) diff --git a/example/robot-simulator/afma6/CMakeLists.txt b/example/robot-simulator/afma6/CMakeLists.txt index a9394ecf8d..14bc0ad498 100644 --- a/example/robot-simulator/afma6/CMakeLists.txt +++ b/example/robot-simulator/afma6/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-robot-simulator-afma6) diff --git a/example/robot-simulator/camera/CMakeLists.txt b/example/robot-simulator/camera/CMakeLists.txt index f5182b886f..2986412d99 100644 --- a/example/robot-simulator/camera/CMakeLists.txt +++ b/example/robot-simulator/camera/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-robot-simulator-camera) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) if(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore) set(WINRT TRUE) diff --git a/example/robot-simulator/viper850/CMakeLists.txt b/example/robot-simulator/viper850/CMakeLists.txt index 12b88ad0ca..f29a27327e 100644 --- a/example/robot-simulator/viper850/CMakeLists.txt +++ b/example/robot-simulator/viper850/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-robot-simulator-viper850) diff --git a/example/servo-afma4/CMakeLists.txt b/example/servo-afma4/CMakeLists.txt index b001f434d0..0fb38fb468 100644 --- a/example/servo-afma4/CMakeLists.txt +++ b/example/servo-afma4/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-servo-afma4) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_blob visp_vs visp_robot visp_sensor visp_gui) diff --git a/example/servo-afma6/CMakeLists.txt b/example/servo-afma6/CMakeLists.txt index ebab48577e..37039c6cf8 100644 --- a/example/servo-afma6/CMakeLists.txt +++ b/example/servo-afma6/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-servo-afma6) diff --git a/example/servo-bebop2/CMakeLists.txt b/example/servo-bebop2/CMakeLists.txt index 82006c1f53..8b14461b13 100644 --- a/example/servo-bebop2/CMakeLists.txt +++ b/example/servo-bebop2/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-servo-bebop2) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_vs visp_robot visp_gui visp_detection) diff --git a/example/servo-biclops/CMakeLists.txt b/example/servo-biclops/CMakeLists.txt index e3a22ceb6a..d4920983d2 100644 --- a/example/servo-biclops/CMakeLists.txt +++ b/example/servo-biclops/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-servo-biclops) diff --git a/example/servo-flir-ptu/CMakeLists.txt b/example/servo-flir-ptu/CMakeLists.txt index 04b0a0db50..794091a393 100644 --- a/example/servo-flir-ptu/CMakeLists.txt +++ b/example/servo-flir-ptu/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-servo-flir-ptu) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_robot visp_sensor visp_vision visp_gui visp_vs visp_visual_features visp_detection) diff --git a/example/servo-franka/CMakeLists.txt b/example/servo-franka/CMakeLists.txt index 8c2d5ceebb..45b822ed4d 100644 --- a/example/servo-franka/CMakeLists.txt +++ b/example/servo-franka/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-servo-franka) diff --git a/example/servo-kinova/CMakeLists.txt b/example/servo-kinova/CMakeLists.txt index e0eaea3467..d699153a23 100644 --- a/example/servo-kinova/CMakeLists.txt +++ b/example/servo-kinova/CMakeLists.txt @@ -38,7 +38,7 @@ project(example-servo-kinova) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_blob visp_vs visp_robot visp_sensor visp_gui) diff --git a/example/servo-pioneer/CMakeLists.txt b/example/servo-pioneer/CMakeLists.txt index 996a6f2431..cde4d4fdf5 100644 --- a/example/servo-pioneer/CMakeLists.txt +++ b/example/servo-pioneer/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-servo-pioneer) diff --git a/example/servo-pixhawk/CMakeLists.txt b/example/servo-pixhawk/CMakeLists.txt index b691c1e875..2d0017aeba 100644 --- a/example/servo-pixhawk/CMakeLists.txt +++ b/example/servo-pixhawk/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-servo-pixhawk) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_vs visp_robot visp_gui visp_detection visp_sensor) diff --git a/example/servo-pololu-ptu/CMakeLists.txt b/example/servo-pololu-ptu/CMakeLists.txt index 913e3097b8..c549f3a74e 100644 --- a/example/servo-pololu-ptu/CMakeLists.txt +++ b/example/servo-pololu-ptu/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-servo-biclops) diff --git a/example/servo-ptu46/CMakeLists.txt b/example/servo-ptu46/CMakeLists.txt index d780d0b335..0921290e50 100644 --- a/example/servo-ptu46/CMakeLists.txt +++ b/example/servo-ptu46/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-servo-ptu46) diff --git a/example/servo-universal-robots/CMakeLists.txt b/example/servo-universal-robots/CMakeLists.txt index d9a2acc0a8..74292dc6df 100644 --- a/example/servo-universal-robots/CMakeLists.txt +++ b/example/servo-universal-robots/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-servo-universal-robots) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_robot visp_io) diff --git a/example/servo-viper650/CMakeLists.txt b/example/servo-viper650/CMakeLists.txt index 8ecacc0bd4..679676223e 100644 --- a/example/servo-viper650/CMakeLists.txt +++ b/example/servo-viper650/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-servo-viper650) diff --git a/example/servo-viper850/CMakeLists.txt b/example/servo-viper850/CMakeLists.txt index 778f17f28f..d3e2229aae 100644 --- a/example/servo-viper850/CMakeLists.txt +++ b/example/servo-viper850/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-servo-viper850) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) if(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore) set(WINRT TRUE) diff --git a/example/tools/CMakeLists.txt b/example/tools/CMakeLists.txt index a6b5580753..318392ec6b 100644 --- a/example/tools/CMakeLists.txt +++ b/example/tools/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-servo-tools) diff --git a/example/tracking/CMakeLists.txt b/example/tracking/CMakeLists.txt index 21f4bfccc1..cad1f2ecf7 100644 --- a/example/tracking/CMakeLists.txt +++ b/example/tracking/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-tracking) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_blob visp_io visp_gui visp_mbt visp_me visp_tt visp_tt_mi) diff --git a/example/video/CMakeLists.txt b/example/video/CMakeLists.txt index 14e3c049e3..78d5b91412 100644 --- a/example/video/CMakeLists.txt +++ b/example/video/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-video) diff --git a/example/wireframe-simulator/CMakeLists.txt b/example/wireframe-simulator/CMakeLists.txt index cf4ea55194..02cac5fae6 100644 --- a/example/wireframe-simulator/CMakeLists.txt +++ b/example/wireframe-simulator/CMakeLists.txt @@ -35,7 +35,7 @@ project(example-wireframe-simulator) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_robot visp_io visp_gui) diff --git a/tutorial/CMakeLists.txt b/tutorial/CMakeLists.txt index 38d101ae34..33a706700d 100644 --- a/tutorial/CMakeLists.txt +++ b/tutorial/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(ViSP-tutorial) diff --git a/tutorial/ar/CMakeLists.txt b/tutorial/ar/CMakeLists.txt index bb3d849a2c..5caff00d84 100644 --- a/tutorial/ar/CMakeLists.txt +++ b/tutorial/ar/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-panda3d) diff --git a/tutorial/bridge/opencv/CMakeLists.txt b/tutorial/bridge/opencv/CMakeLists.txt index 012a5172da..1c2130b14c 100644 --- a/tutorial/bridge/opencv/CMakeLists.txt +++ b/tutorial/bridge/opencv/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-bridge-opencv) diff --git a/tutorial/computer-vision/CMakeLists.txt b/tutorial/computer-vision/CMakeLists.txt index d3b10a3f30..f4d90dad4e 100644 --- a/tutorial/computer-vision/CMakeLists.txt +++ b/tutorial/computer-vision/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-computer-vision) diff --git a/tutorial/detection/barcode/CMakeLists.txt b/tutorial/detection/barcode/CMakeLists.txt index 6f1d086f79..91bcfc4ad1 100644 --- a/tutorial/detection/barcode/CMakeLists.txt +++ b/tutorial/detection/barcode/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-barcode) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_detection visp_io visp_gui visp_sensor) diff --git a/tutorial/detection/dnn/CMakeLists.txt b/tutorial/detection/dnn/CMakeLists.txt index d726f78737..325700193a 100644 --- a/tutorial/detection/dnn/CMakeLists.txt +++ b/tutorial/detection/dnn/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-dnn-object-detection-live) diff --git a/tutorial/detection/face/CMakeLists.txt b/tutorial/detection/face/CMakeLists.txt index 138936ff15..b97a43add8 100644 --- a/tutorial/detection/face/CMakeLists.txt +++ b/tutorial/detection/face/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-detection-face) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_detection visp_io visp_gui visp_sensor) diff --git a/tutorial/detection/matching/CMakeLists.txt b/tutorial/detection/matching/CMakeLists.txt index ce6c88b8a0..5076d80f79 100644 --- a/tutorial/detection/matching/CMakeLists.txt +++ b/tutorial/detection/matching/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-matching-keypoint) diff --git a/tutorial/detection/object/CMakeLists.txt b/tutorial/detection/object/CMakeLists.txt index 0fe8da446d..139c97fac9 100644 --- a/tutorial/detection/object/CMakeLists.txt +++ b/tutorial/detection/object/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-detection-object) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_vision visp_mbt visp_io visp_gui) diff --git a/tutorial/detection/tag/CMakeLists.txt b/tutorial/detection/tag/CMakeLists.txt index 9ff0c7ea8b..90d26afdf9 100644 --- a/tutorial/detection/tag/CMakeLists.txt +++ b/tutorial/detection/tag/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-apriltag) diff --git a/tutorial/grabber/CMakeLists.txt b/tutorial/grabber/CMakeLists.txt index f6d2186f37..ff9fe368d4 100644 --- a/tutorial/grabber/CMakeLists.txt +++ b/tutorial/grabber/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-grabber) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_sensor visp_io visp_gui) diff --git a/tutorial/gui/pcl-visualizer/CMakeLists.txt b/tutorial/gui/pcl-visualizer/CMakeLists.txt index de775cc076..de45448cef 100644 --- a/tutorial/gui/pcl-visualizer/CMakeLists.txt +++ b/tutorial/gui/pcl-visualizer/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-gui-pcl-visualizer) diff --git a/tutorial/image/CMakeLists.txt b/tutorial/image/CMakeLists.txt index 7fd6ad0b04..219cd5f77a 100644 --- a/tutorial/image/CMakeLists.txt +++ b/tutorial/image/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-image) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_io visp_gui) diff --git a/tutorial/imgproc/autothreshold/CMakeLists.txt b/tutorial/imgproc/autothreshold/CMakeLists.txt index bd1ee8af26..88532168e1 100644 --- a/tutorial/imgproc/autothreshold/CMakeLists.txt +++ b/tutorial/imgproc/autothreshold/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-autothreshold) diff --git a/tutorial/imgproc/brightness/CMakeLists.txt b/tutorial/imgproc/brightness/CMakeLists.txt index 283980c0f0..eba0bf44c1 100644 --- a/tutorial/imgproc/brightness/CMakeLists.txt +++ b/tutorial/imgproc/brightness/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-brightness-adjustment) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_io visp_gui visp_imgproc) diff --git a/tutorial/imgproc/connected-components/CMakeLists.txt b/tutorial/imgproc/connected-components/CMakeLists.txt index 98f25c7414..f09196251b 100644 --- a/tutorial/imgproc/connected-components/CMakeLists.txt +++ b/tutorial/imgproc/connected-components/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-connected-components) diff --git a/tutorial/imgproc/contour/CMakeLists.txt b/tutorial/imgproc/contour/CMakeLists.txt index 4a86ef28b8..296514e0b9 100644 --- a/tutorial/imgproc/contour/CMakeLists.txt +++ b/tutorial/imgproc/contour/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-contour) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_io visp_gui visp_imgproc) diff --git a/tutorial/imgproc/contrast-sharpening/CMakeLists.txt b/tutorial/imgproc/contrast-sharpening/CMakeLists.txt index 51d0204a8b..b6a25e73b7 100644 --- a/tutorial/imgproc/contrast-sharpening/CMakeLists.txt +++ b/tutorial/imgproc/contrast-sharpening/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-contrast-sharpening) diff --git a/tutorial/imgproc/count-coins/CMakeLists.txt b/tutorial/imgproc/count-coins/CMakeLists.txt index 9a3fa9235a..4d72bededf 100644 --- a/tutorial/imgproc/count-coins/CMakeLists.txt +++ b/tutorial/imgproc/count-coins/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-counting-coins) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_io visp_gui visp_imgproc) diff --git a/tutorial/imgproc/flood-fill/CMakeLists.txt b/tutorial/imgproc/flood-fill/CMakeLists.txt index 50a447d94c..163b9b1f75 100644 --- a/tutorial/imgproc/flood-fill/CMakeLists.txt +++ b/tutorial/imgproc/flood-fill/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-flood-fill) diff --git a/tutorial/imgproc/hough-transform/CMakeLists.txt b/tutorial/imgproc/hough-transform/CMakeLists.txt index e62b156ccc..e79db8ca29 100644 --- a/tutorial/imgproc/hough-transform/CMakeLists.txt +++ b/tutorial/imgproc/hough-transform/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-hough) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_gui visp_imgproc visp_io) diff --git a/tutorial/kalman/CMakeLists.txt b/tutorial/kalman/CMakeLists.txt index 67158faec3..e1cbbcd137 100644 --- a/tutorial/kalman/CMakeLists.txt +++ b/tutorial/kalman/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-kalman) diff --git a/tutorial/matlab/CMakeLists.txt b/tutorial/matlab/CMakeLists.txt index 746471797e..160991474d 100644 --- a/tutorial/matlab/CMakeLists.txt +++ b/tutorial/matlab/CMakeLists.txt @@ -1,6 +1,6 @@ project(visp-matlab) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core) include_directories(${VISP_INCLUDE_DIRS}) diff --git a/tutorial/mean-drift/CMakeLists.txt b/tutorial/mean-drift/CMakeLists.txt index 61aaff4046..8345319d67 100644 --- a/tutorial/mean-drift/CMakeLists.txt +++ b/tutorial/mean-drift/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-meandrift) diff --git a/tutorial/misc/npz/CMakeLists.txt b/tutorial/misc/npz/CMakeLists.txt index 0417a06e7b..ad710170ec 100644 --- a/tutorial/misc/npz/CMakeLists.txt +++ b/tutorial/misc/npz/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-npz) diff --git a/tutorial/munkres/CMakeLists.txt b/tutorial/munkres/CMakeLists.txt index 0b7c3c7290..cc58e7ef3f 100644 --- a/tutorial/munkres/CMakeLists.txt +++ b/tutorial/munkres/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-munkres) diff --git a/tutorial/particle-filter-curve-fitting/CMakeLists.txt b/tutorial/particle-filter-curve-fitting/CMakeLists.txt index f078da7cbb..ed219f7632 100644 --- a/tutorial/particle-filter-curve-fitting/CMakeLists.txt +++ b/tutorial/particle-filter-curve-fitting/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-pf) diff --git a/tutorial/particle-filter/CMakeLists.txt b/tutorial/particle-filter/CMakeLists.txt index 51d0108929..f02232aa25 100644 --- a/tutorial/particle-filter/CMakeLists.txt +++ b/tutorial/particle-filter/CMakeLists.txt @@ -33,7 +33,7 @@ # ############################################################################# -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-pf) diff --git a/tutorial/robot/flir-ptu/CMakeLists.txt b/tutorial/robot/flir-ptu/CMakeLists.txt index 7e70a4c986..926b1aecf5 100644 --- a/tutorial/robot/flir-ptu/CMakeLists.txt +++ b/tutorial/robot/flir-ptu/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-robot-flir-ptu) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) if(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore) set(WINRT TRUE) diff --git a/tutorial/robot/mbot/raspberry/visp/CMakeLists.txt b/tutorial/robot/mbot/raspberry/visp/CMakeLists.txt index eca0f697a1..c99ce6d3b7 100644 --- a/tutorial/robot/mbot/raspberry/visp/CMakeLists.txt +++ b/tutorial/robot/mbot/raspberry/visp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(visp-mbot) diff --git a/tutorial/robot/pioneer/CMakeLists.txt b/tutorial/robot/pioneer/CMakeLists.txt index 8d16e77b28..83710b1b22 100644 --- a/tutorial/robot/pioneer/CMakeLists.txt +++ b/tutorial/robot/pioneer/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-robot) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) if(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore) set(WINRT TRUE) diff --git a/tutorial/segmentation/color/CMakeLists.txt b/tutorial/segmentation/color/CMakeLists.txt index 622ce5c254..17c2b4a11c 100644 --- a/tutorial/segmentation/color/CMakeLists.txt +++ b/tutorial/segmentation/color/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(color_segmentation) diff --git a/tutorial/simulator/image/CMakeLists.txt b/tutorial/simulator/image/CMakeLists.txt index 9bd2869db2..ebf27801e2 100644 --- a/tutorial/simulator/image/CMakeLists.txt +++ b/tutorial/simulator/image/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-simulation-image) diff --git a/tutorial/trace/CMakeLists.txt b/tutorial/trace/CMakeLists.txt index c00d576636..5f1d5e6452 100644 --- a/tutorial/trace/CMakeLists.txt +++ b/tutorial/trace/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-trace) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core) diff --git a/tutorial/tracking/blob/CMakeLists.txt b/tutorial/tracking/blob/CMakeLists.txt index 78e6111cd0..75e77c3cea 100644 --- a/tutorial/tracking/blob/CMakeLists.txt +++ b/tutorial/tracking/blob/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-tracking-blob) diff --git a/tutorial/tracking/dnn/CMakeLists.txt b/tutorial/tracking/dnn/CMakeLists.txt index f7127a9373..8b4659893e 100644 --- a/tutorial/tracking/dnn/CMakeLists.txt +++ b/tutorial/tracking/dnn/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-tracking-dnn) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_detection visp_dnn_tracker visp_io visp_gui visp_sensor) diff --git a/tutorial/tracking/keypoint/CMakeLists.txt b/tutorial/tracking/keypoint/CMakeLists.txt index 3c6d2fa051..21d12078e2 100644 --- a/tutorial/tracking/keypoint/CMakeLists.txt +++ b/tutorial/tracking/keypoint/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-tracking-keypoint) diff --git a/tutorial/tracking/model-based/generic-apriltag/CMakeLists.txt b/tutorial/tracking/model-based/generic-apriltag/CMakeLists.txt index 9228cdb133..7755fc7014 100644 --- a/tutorial/tracking/model-based/generic-apriltag/CMakeLists.txt +++ b/tutorial/tracking/model-based/generic-apriltag/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-tracking-mb-aprilTag-init) diff --git a/tutorial/tracking/model-based/generic-rgbd-blender/CMakeLists.txt b/tutorial/tracking/model-based/generic-rgbd-blender/CMakeLists.txt index fa06fcb773..7bd35f6d5e 100644 --- a/tutorial/tracking/model-based/generic-rgbd-blender/CMakeLists.txt +++ b/tutorial/tracking/model-based/generic-rgbd-blender/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-tracking-mb-generic-rgbd-blender) diff --git a/tutorial/tracking/model-based/generic-rgbd/CMakeLists.txt b/tutorial/tracking/model-based/generic-rgbd/CMakeLists.txt index 52c62d772a..48a2b89f24 100644 --- a/tutorial/tracking/model-based/generic-rgbd/CMakeLists.txt +++ b/tutorial/tracking/model-based/generic-rgbd/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-tracking-mb-generic-rgbd) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_mbt visp_io visp_gui visp_sensor) diff --git a/tutorial/tracking/model-based/generic-stereo/CMakeLists.txt b/tutorial/tracking/model-based/generic-stereo/CMakeLists.txt index d04f4246d4..bb6ca59cd3 100644 --- a/tutorial/tracking/model-based/generic-stereo/CMakeLists.txt +++ b/tutorial/tracking/model-based/generic-stereo/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-tracking-mb-generic-stereo) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_mbt visp_io visp_gui) diff --git a/tutorial/tracking/model-based/generic/CMakeLists.txt b/tutorial/tracking/model-based/generic/CMakeLists.txt index c25d5210cc..b6d059981d 100644 --- a/tutorial/tracking/model-based/generic/CMakeLists.txt +++ b/tutorial/tracking/model-based/generic/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-tracking-mb) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_mbt visp_io visp_gui visp_sensor) diff --git a/tutorial/tracking/model-based/old/edges/CMakeLists.txt b/tutorial/tracking/model-based/old/edges/CMakeLists.txt index 43ce2df611..b069c72f9c 100644 --- a/tutorial/tracking/model-based/old/edges/CMakeLists.txt +++ b/tutorial/tracking/model-based/old/edges/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-tracking-mb-edges) diff --git a/tutorial/tracking/model-based/old/generic/CMakeLists.txt b/tutorial/tracking/model-based/old/generic/CMakeLists.txt index f2593f172e..617e101903 100644 --- a/tutorial/tracking/model-based/old/generic/CMakeLists.txt +++ b/tutorial/tracking/model-based/old/generic/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-tracking-mb) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_mbt visp_io visp_gui) diff --git a/tutorial/tracking/model-based/old/hybrid/CMakeLists.txt b/tutorial/tracking/model-based/old/hybrid/CMakeLists.txt index 1de9cf3031..4d67e6b3b8 100644 --- a/tutorial/tracking/model-based/old/hybrid/CMakeLists.txt +++ b/tutorial/tracking/model-based/old/hybrid/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-tracking-mb-hybrid) diff --git a/tutorial/tracking/model-based/old/keypoint/CMakeLists.txt b/tutorial/tracking/model-based/old/keypoint/CMakeLists.txt index 1e2cd8564e..7ce1c5bd19 100644 --- a/tutorial/tracking/model-based/old/keypoint/CMakeLists.txt +++ b/tutorial/tracking/model-based/old/keypoint/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-tracking-mb-keypoint) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_mbt visp_klt visp_gui) diff --git a/tutorial/tracking/moving-edges/CMakeLists.txt b/tutorial/tracking/moving-edges/CMakeLists.txt index 4532743d12..5adc69f3a0 100644 --- a/tutorial/tracking/moving-edges/CMakeLists.txt +++ b/tutorial/tracking/moving-edges/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-tracking-me) diff --git a/tutorial/tracking/template-tracker/CMakeLists.txt b/tutorial/tracking/template-tracker/CMakeLists.txt index 33032e7502..505d6cc1c3 100644 --- a/tutorial/tracking/template-tracker/CMakeLists.txt +++ b/tutorial/tracking/template-tracker/CMakeLists.txt @@ -1,6 +1,6 @@ project(tutorial-tracking-template) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_tt visp_io visp_gui) diff --git a/tutorial/visual-servo/ibvs/CMakeLists.txt b/tutorial/visual-servo/ibvs/CMakeLists.txt index 695b38b33c..b621bd5519 100644 --- a/tutorial/visual-servo/ibvs/CMakeLists.txt +++ b/tutorial/visual-servo/ibvs/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-visual-servo-ibvs) From 2266078ba5a12ef3131908a3871f948e8470219e Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 25 Nov 2024 17:55:12 +0100 Subject: [PATCH 07/31] Add installation of python3-pip package in the instructions to install Panda3D on Ubuntu --- doc/tutorial/rendering/tutorial-panda3d.dox | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/tutorial/rendering/tutorial-panda3d.dox b/doc/tutorial/rendering/tutorial-panda3d.dox index 187031498a..ce2e939217 100644 --- a/doc/tutorial/rendering/tutorial-panda3d.dox +++ b/doc/tutorial/rendering/tutorial-panda3d.dox @@ -34,6 +34,7 @@ vpPanda3DBaseRenderer, which implements basic functions for a panda renderer. - Hereafter you will find the instructions to build and install Panda3D from source on Ubuntu 22.04 \code{.sh} + $ sudo apt install python3-pip $ mkdir -p $VISP_WS/3rdparty/panda3d $ cd $VISP_WS/3rdparty/panda3d $ git clone https://github.com/panda3d/panda3d From 3c71779f45c0490a262b4d39cc779df10f326aba Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 25 Nov 2024 17:56:59 +0100 Subject: [PATCH 08/31] Add Rendering and AR section in the list of 3rd parties supported by ViSP to mention Ogre and Panda3D installation --- .../supported-third-parties.dox | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/doc/tutorial/supported-third-parties/supported-third-parties.dox b/doc/tutorial/supported-third-parties/supported-third-parties.dox index eb05985efb..be7fa1c1f4 100644 --- a/doc/tutorial/supported-third-parties/supported-third-parties.dox +++ b/doc/tutorial/supported-third-parties/supported-third-parties.dox @@ -115,6 +115,34 @@ $ sudo apt-get install libpng-dev $ su -c "yum install libpng-devel" \endverbatim +\section soft_ar 3D Rendering and Augmented Reality + +These are the optional 3rd-parties supported by ViSP in \ref module_ar for 3D Rendering and Augmented Reality. + +\subsection soft_ar_Ogre3D Ogre3D + +- Ubuntu or debian installation since Ubuntu 24.04 +\code{.sh} +$ sudo apt-get install libogre-1.12-dev libois-dev +\endcode +- Ubuntu or debian installation for Ubuntu 22.04 or before +\code{.sh} +$ sudo apt-get install libogre-1.9-dev libois-dev +\endcode +- Fedora or RedHat installation +\code{.sh} +$ su -c "yum install ogre-devel ogre-samples ois-devel" +\endcode + +\subsection soft_ar_Panda3D Panda3D + +Panda3D installation instructions are provided in \ref tutorial-panda3d. +- \ref tutorial-panda3d-install-ubuntu + +- \ref tutorial-panda3d-install-macos + +- \ref tutorial-panda3d-install-windows + \section soft_robot Robot Control The following optional third-parties are used in \ref module_robot to enable the robot arms usage supported by ViSP. From 79adce029761c06a385835762f24b8b4e810d0a0 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 25 Nov 2024 17:57:27 +0100 Subject: [PATCH 09/31] Bump cmake minimum version to 3.10 required by cmake 3.31.1 --- doc/tutorial/bridge/matlab/tutorial-visp-matlab.dox | 2 +- doc/tutorial/developper/tutorial-add-new-dependency.dox | 4 ++-- doc/tutorial/started/tutorial-getting-started.dox | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/tutorial/bridge/matlab/tutorial-visp-matlab.dox b/doc/tutorial/bridge/matlab/tutorial-visp-matlab.dox index 533ea4c73d..d62dbc583e 100644 --- a/doc/tutorial/bridge/matlab/tutorial-visp-matlab.dox +++ b/doc/tutorial/bridge/matlab/tutorial-visp-matlab.dox @@ -29,7 +29,7 @@ In order to build a source code that mix ViSP and MATLAB you should first create find ViSP and MATLAB. In the following example we consider the case of the tutorial-matlab.cpp source file. \code -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(visp-matlab) diff --git a/doc/tutorial/developper/tutorial-add-new-dependency.dox b/doc/tutorial/developper/tutorial-add-new-dependency.dox index 58fba970db..bde5860939 100644 --- a/doc/tutorial/developper/tutorial-add-new-dependency.dox +++ b/doc/tutorial/developper/tutorial-add-new-dependency.dox @@ -305,7 +305,7 @@ $ more CMakeLists.txt \code project(example-dummy) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) find_package(VISP REQUIRED visp_core visp_robot) @@ -409,7 +409,7 @@ $ cd $VISP_WS/my-project $ more CMakeLists.txt \endcode \code -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(example-dummy) diff --git a/doc/tutorial/started/tutorial-getting-started.dox b/doc/tutorial/started/tutorial-getting-started.dox index 023ef4c227..2bdc0d94ee 100644 --- a/doc/tutorial/started/tutorial-getting-started.dox +++ b/doc/tutorial/started/tutorial-getting-started.dox @@ -228,7 +228,7 @@ example. A minimalistic `CMakeLists.txt` should contain the following lines. Open your editor and copy/paste the following lines in `VISP_WS/started/CMakeLists.txt` file. \code -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-image) @@ -248,7 +248,7 @@ The `find_package()` CMake command searches for a `VISPConfig.cmake` file that w Note that the previous `CMakeLists.txt` file can also be: \code -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(tutorial-image) From 14af8c0b92d2b5497481acd46a7503fbf0b8135d Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 25 Nov 2024 18:00:49 +0100 Subject: [PATCH 10/31] Update vpHomogeneousMatrix html doc --- .../core/include/visp3/core/vpHomogeneousMatrix.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/core/include/visp3/core/vpHomogeneousMatrix.h b/modules/core/include/visp3/core/vpHomogeneousMatrix.h index 3883dff892..41bde6a97e 100644 --- a/modules/core/include/visp3/core/vpHomogeneousMatrix.h +++ b/modules/core/include/visp3/core/vpHomogeneousMatrix.h @@ -326,6 +326,13 @@ class VISP_EXPORT vpHomogeneousMatrix : public vpArray2D * std::ofstream f("homogeneous.dat"); * M.save(f); * \endcode + * The content of "homogeneous.dat" is the following: + * \verbatim + * 0.7071067812 0.7071067812 0 1 + * 0.7071067812 -0.7071067812 -1.224646799e-16 2 + * -8.659560562e-17 8.659560562e-17 -1 3 + * 0 0 0 1 + * \endverbatim * * \sa save(const std::string &), load(std::ifstream &) */ @@ -348,6 +355,13 @@ class VISP_EXPORT vpHomogeneousMatrix : public vpArray2D * // Save the content of the matrix in "homogeneous.dat" * M.save("homogeneous.dat"); * \endcode + * The content of "homogeneous.dat" is the following: + * \verbatim + * 0.7071067812 0.7071067812 0 1 + * 0.7071067812 -0.7071067812 -1.224646799e-16 2 + * -8.659560562e-17 8.659560562e-17 -1 3 + * 0 0 0 1 + * \endverbatim * * \sa save(std::ofstream &), load(const std::string &) */ From 4c81b45d862f4c92243f7dbfa199e21eca61f301 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 25 Nov 2024 18:02:17 +0100 Subject: [PATCH 11/31] Bump cmake minimum version to 3.10 required by cmake 3.31.1 --- modules/sensor/include/visp3/sensor/vpOccipitalStructure.h | 2 +- platforms/android/android.toolchain.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h b/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h index 0f8b00aa00..9cdc487f38 100644 --- a/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h +++ b/modules/sensor/include/visp3/sensor/vpOccipitalStructure.h @@ -84,7 +84,7 @@ BEGIN_VISP_NAMESPACE uses vpOccipitalStructure class. \code - cmake_minimum_required(VERSION 3.5) + cmake_minimum_required(VERSION 3.10) project(sample) diff --git a/platforms/android/android.toolchain.cmake b/platforms/android/android.toolchain.cmake index 0096a29c99..dbf6ed6f63 100644 --- a/platforms/android/android.toolchain.cmake +++ b/platforms/android/android.toolchain.cmake @@ -189,7 +189,7 @@ # # ------------------------------------------------------------------------------ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) if( DEFINED CMAKE_CROSSCOMPILING ) # subsequent toolchain loading is not really needed From 07494150ea183a409df4e362a16889879ca84678 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 25 Nov 2024 18:02:44 +0100 Subject: [PATCH 12/31] Clean code --- .../model-based/generic/tutorial-mb-generic-tracker.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker.cpp b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker.cpp index c17236c03d..43cba451b0 100644 --- a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker.cpp +++ b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker.cpp @@ -136,8 +136,6 @@ int main(int argc, char **argv) tracker.initClick(I, objectname + ".init", true); //! [Init] - - while (!g.end()) { g.acquire(I); vpDisplay::display(I); @@ -155,8 +153,9 @@ int main(int argc, char **argv) vpDisplay::displayText(I, 10, 10, "A click to exit...", vpColor::red); vpDisplay::flush(I); - if (vpDisplay::getClick(I, false)) + if (vpDisplay::getClick(I, false)) { break; + } } vpDisplay::getClick(I); //! [Cleanup] From fe71a7ed5bf044479252e4687296fe87dec0c194 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 25 Nov 2024 18:03:58 +0100 Subject: [PATCH 13/31] Clean code and add more options (speed and force) when grasping --- example/servo-franka/frankaGripper.cpp | 96 +++++++++++++++++++++----- 1 file changed, 77 insertions(+), 19 deletions(-) diff --git a/example/servo-franka/frankaGripper.cpp b/example/servo-franka/frankaGripper.cpp index 76a5c73938..5b98186c5f 100644 --- a/example/servo-franka/frankaGripper.cpp +++ b/example/servo-franka/frankaGripper.cpp @@ -1,7 +1,6 @@ -/**************************************************************************** - * +/* * ViSP, open source Visual Servoing Platform software. - * Copyright (C) 2005 - 2023 by Inria. All rights reserved. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. * * This software is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,8 +29,7 @@ * * Description: * Franka robot tool. - * -*****************************************************************************/ + */ /*! \example frankaGripper.cpp @@ -64,11 +62,14 @@ int main(int argc, char **argv) std::string opt_robot_ip = "192.168.1.1"; double opt_grasping_width = 0.; + double opt_grasping_speed = 0.1; + double opt_grasping_force = 60; GripperState_t opt_gripper_state = Gripper_None; for (int i = 1; i < argc; i++) { if (std::string(argv[i]) == "--ip" && i + 1 < argc) { - opt_robot_ip = std::string(argv[i + 1]); + ++ i; + opt_robot_ip = std::string(argv[i]); } else if (std::string(argv[i]) == "--home") { opt_gripper_state = Gripper_Home; @@ -80,22 +81,79 @@ int main(int argc, char **argv) opt_gripper_state = Gripper_Close; } else if (std::string(argv[i]) == "--grasp" && i + 1 < argc) { + ++ i; opt_gripper_state = Gripper_Grasp; - opt_grasping_width = std::atof(argv[i + 1]); + opt_grasping_width = std::atof(argv[i]); + } + else if (std::string(argv[i]) == "--grasp-speed" && i + 1 < argc) { + ++ i; + opt_grasping_speed = std::atof(argv[i]); + } + else if (std::string(argv[i]) == "--grasp-force" && i + 1 < argc) { + ++ i; + opt_grasping_force = std::atof(argv[i]); } else if (std::string(argv[i]) == "--test" && i + 1 < argc) { + ++ i; opt_gripper_state = Gripper_Test; - opt_grasping_width = std::atof(argv[i + 1]); + opt_grasping_width = std::atof(argv[i]); } else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") { - std::cout << "Control Panda gripper." << std::endl; - std::cout << argv[0] << " [--ip ] [--home] [--open] [--close] [--grasp ] [--release] [--test ] [--help] [-h]\n" + std::cout << "SYNOPSYS" << std::endl + << " " << argv[0] + << " [--ip ]" + << " [--home]" + << " [--open]" + << " [--close]" + << " [--grasp ]" + << " [--grasp-speed ]" + << " [--grasp-force ]" + << " [--release]" + << " [--test ]" + << " [--help] [-h]\n" << std::endl; + std::cout << "DESCRIPTION" << std::endl + << " Control Panda gripper." << std::endl + << std::endl + << " --ip " << std::endl + << " Franka controller ip address" << std::endl + << " Default: " << opt_robot_ip << std::endl + << std::endl + << " --home" << std::endl + << " Performs homing of the gripper." << std::endl + << std::endl + << " --open" << std::endl + << " Performs opening of the gripper." << std::endl + << std::endl + << " --close" << std::endl + << " Performs closing of the gripper." << std::endl + << std::endl + << " --grasp " << std::endl + << " Performs grasping of an object." << std::endl + << " Object width is to specify in [m]." << std::endl + << " Default width: " << opt_grasping_width << " [m]" << std::endl + << std::endl + << " --grasp-speed " << std::endl + << " Closing speed in [m/s] applied during grasping." << std::endl + << " Default: " << opt_grasping_speed << " [m/s]" << std::endl + << std::endl + << " --grasp-force " << std::endl + << " Force in [N] applied during grasping." << std::endl + << " Default: " << opt_grasping_force << " [N]" << std::endl + << std::endl + << " --release" << std::endl + << " Release an object that is grasped." << std::endl + << std::endl + << " --test " << std::endl + << " Performs a gripper test on an object width specified in [m]." << std::endl + << " Default width: " << opt_grasping_width << " [m]" << std::endl + << std::endl + << " --help, -h" << std::endl + << " Print this helper message." << std::endl << std::endl; - std::cout << "Example to grasp a 4cm width object by first opening the gripper, then grasping the object :\n" - << argv[0] << " --ip 192.168.100.1 --open\n" - << argv[0] << " --ip 192.168.100.1 --grasp 0.04\n" + std::cout << "EXAMPLE" << std::endl + << " To grasp a 4cm width object by first opening the gripper, then grasping the object:\n" + << " " << argv[0] << " --ip 192.168.100.1 --open\n" + << " " << argv[0] << " --ip 192.168.100.1 --grasp 0.04\n" << std::endl; return EXIT_SUCCESS; @@ -131,8 +189,8 @@ int main(int argc, char **argv) robot.gripperOpen(); } else if (opt_gripper_state == Gripper_Grasp) { - std::cout << "Gripper grasp " << opt_grasping_width << "m object width..." << std::endl; - robot.gripperGrasp(opt_grasping_width); + std::cout << "Gripper grasp " << opt_grasping_width << "m object width, with speed: " << opt_grasping_speed << " and force: " << opt_grasping_force << "N..." << std::endl; + robot.gripperGrasp(opt_grasping_width, opt_grasping_speed, opt_grasping_force); } else if (opt_gripper_state == Gripper_Release) { std::cout << "Gripper release object..." << std::endl; @@ -152,8 +210,8 @@ int main(int argc, char **argv) std::cout << "- Gripper opening..." << std::endl; robot.gripperOpen(); vpTime::sleepMs(3000); - std::cout << "- Gripper grasp " << opt_grasping_width << "m object width..." << std::endl; - robot.gripperGrasp(opt_grasping_width); + std::cout << "- Gripper grasp " << opt_grasping_width << "m object width, with speed: " << opt_grasping_speed << " and force: " << opt_grasping_force << "N..." << std::endl; + robot.gripperGrasp(opt_grasping_width, opt_grasping_speed, opt_grasping_force); vpTime::sleepMs(3000); std::cout << "- Gripper release object..." << std::endl; robot.gripperRelease(); From 74d117608c5d71aa43e545dd813a3d3508f8b323 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 26 Nov 2024 18:05:02 +0100 Subject: [PATCH 14/31] Improve ViSP installation in conda environment documentation - add pkg-config package installation - in known issues, add CMake Warning: Cannot generate a safe runtime search path section --- .../tutorial-install-python-bindings.dox | 84 +++++++++++++++++-- 1 file changed, 78 insertions(+), 6 deletions(-) diff --git a/doc/tutorial/python/tutorial-install-python-bindings.dox b/doc/tutorial/python/tutorial-install-python-bindings.dox index b63e3dd5e3..d68e93ad15 100644 --- a/doc/tutorial/python/tutorial-install-python-bindings.dox +++ b/doc/tutorial/python/tutorial-install-python-bindings.dox @@ -115,13 +115,13 @@ We strongly recommend using Conda to build ViSP Python bindings. Below are instr - **A. On macOS**: - (visp-conda-ws) $ conda install cmake cxx-compiler make xorg-libx11 xorg-libxfixes libxml2 libdc1394 librealsense libopencv eigen libjpeg-turbo libpng libopenblas llvm-openmp pybind11 + (visp-conda-ws) $ conda install cmake cxx-compiler make pkg-config xorg-libx11 xorg-libxfixes libxml2 libdc1394 librealsense libopencv eigen libjpeg-turbo libpng libopenblas llvm-openmp pybind11 - **B. On Ubuntu or other linux-like**: We recommend this minimal set of dependencies to get the main features of ViSP available: - (visp-conda-ws) $ conda install cmake cxx-compiler make xorg-libx11 xorg-libxfixes libxml2 libdc1394 librealsense libgomp libopencv eigen libjpeg-turbo libpng mkl-devel pybind11 + (visp-conda-ws) $ conda install cmake cxx-compiler make pkg-config xorg-libx11 xorg-libxfixes libxml2 libdc1394 librealsense libgomp libopencv eigen libjpeg-turbo libpng mkl-devel pybind11 - **C. On Windows**: @@ -551,17 +551,89 @@ to uninstall Miniforge: and # <<< conda initialize <<< -\section py_bindings_known_errors Known build errors +\section py_bindings_known_errors Known issues -When compiling or modifying the bindings, you may encounter errors. +When configuring with CMake, compiling or modifying the bindings, you may encounter errors. -Here is a non-exhaustive list of errors. +Here is a non-exhaustive list of warnings and errors. If you encounter a compilation error, make sure to first try rebuilding after cleaning the CMake cache. Pybind did generate problems (an error at the pybind include line) that were solved like this. -\subsection py_bindings_known_errors_buil When building ViSP +\subsection py_bindings_known_warnings When configuring ViSP +\subsubsection py_bindings_known_warnings_safe-rpath CMake Warning: Cannot generate a safe runtime search path + +When building Python bindings using Conda as described in section \ref py_bindings_build_conda, you may encounter +the following CMake warning: +\code{.sh} +CMake Warning at cmake/VISPUtils.cmake:813 (add_library): + Cannot generate a safe runtime search path for target visp_ar because files + in some directories may conflict with libraries in implicit directories: + + runtime library [libm.so.6] in $HOME/miniforge3/envs/visp-conda-ws/x86_64-conda-linux-gnu/sysroot/usr/lib may be hidden by files in: + /usr/lib/x86_64-linux-gnu + runtime library [libxml2.so.2] in $HOME/miniforge3/envs/visp-conda-ws/lib may be hidden by files in: + /usr/lib/x86_64-linux-gnu + runtime library [libz.so.1] in $HOME/miniforge3/envs/visp-conda-ws/lib may be hidden by files in: + /usr/lib/x86_64-linux-gnu + runtime library [libgomp.so.1] in $HOME/miniforge3/envs/visp-conda-ws/lib may be hidden by files in: + /usr/lib/x86_64-linux-gnu + + Some of these libraries may not be found correctly. +Call Stack (most recent call first): + cmake/VISPModule.cmake:806 (vp_add_library) + cmake/VISPModule.cmake:798 (_vp_create_module) + modules/ar/CMakeLists.txt:193 (vp_create_module) +\endcode + +It means that the project requests linking with the shared libraries (`libxml2.so`, `libz.so` and +`libgomp.so`), which are contained in two directories `$HOME/miniforge3/envs/visp-conda-ws/lib` and `/usr/lib/x86_64-linux-gnu`. +The same occurs for `libm.so` that is present in +`$HOME/miniforge3/envs/visp-conda-ws/x86_64-conda-linux-gnu/sysroot/usr/lib` and in `/usr/lib/x86_64-linux-gnu`. + +CMake first searches for the 3rd parties in the Conda environment, and if they are not found, it extends +the search path to try to find them in the system path as `/usr/`. As a result, CMake cannot guarantee that, when you run +the executable, the loader will find the proper library. + +If you don't fix these warnings, the behavior of the project could be affected. + +The way to proceed is to analyse the `ViSP-third-party.txt` file which summarises the third parties found and +identify those you haven't installed in the Conda environment with `conda install <3rdparty>`. +An other solution is to call `cmake` with `--debug-find` command line option that will explicitly show the search +path for the 3rd parties: +\code{.sh} +(visp-conda-ws) $ cmake ../visp -DCMAKE_PREFIX_PATH=$CONDA_PREFIX -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX --debug-find +\endcode + +In our case, we produced the CMake warning mentioned before by installing Panda3D and Ogre as system libraries. + +The solution is to deactivate the use of these two third parties as long as they are not needed, or simply to check +that by not using them the CMake warnings disappear. After cleaning the `visp-build` folder you may run: +\code{.sh} +(visp-conda-ws) $ cmake ../visp -DCMAKE_PREFIX_PATH=$CONDA_PREFIX -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DUSE_OGRE=OFF -DUSE_PANDA3D=OFF +\endcode + +Once confirmed that the warnings were due to the disabled 3rd parties, if they exist you can try installing them in +the conda environment. + +For example: +- for Panda3d: +\code{.sh} +$ conda create --name visp-conda-ws python=3.12 +$ conda activate visp-conda-ws +(visp-conda-ws) $ conda install panda3d +\endcode +- for Ogre +\code{.sh} +(visp-conda-ws) $ conda install ogre +\endcode +- before running CMake and helping CMake to find Panda3d headers +\code{.sh} +(visp-conda-ws) $ export Panda3D_DIR=$CONDA_PREFIX/share/panda3d +(visp-conda-ws) $ cmake ../visp -DCMAKE_PREFIX_PATH=$CONDA_PREFIX -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX +\endcode +\subsection py_bindings_known_errors_build When building ViSP \subsubsection py_bindings_known_errors_build_x11 Cannot build vpDisplayX.cpp The following error may occur on macOS during a build From c60ddaed67bce78f592145e00d64d9b7088b5aaa Mon Sep 17 00:00:00 2001 From: Souriya Trinh Date: Tue, 26 Nov 2024 22:19:50 +0100 Subject: [PATCH 15/31] =?UTF-8?q?Fix=20warnings:=20"extra=20=E2=80=98;?= =?UTF-8?q?=E2=80=99=20[-Wpedantic]"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/core/src/image/vpColormap.cpp | 2 +- modules/core/src/image/vpImageConvert_yuv.cpp | 2 +- modules/core/src/math/matrix/vpColVector.cpp | 8 ++++---- modules/core/src/tools/geometry/vpPlane.cpp | 2 +- modules/core/src/tools/geometry/vpTriangle.cpp | 2 +- modules/core/src/tools/time/vpTime.cpp | 2 +- modules/robot/src/haptic-device/virtuose/vpVirtuose.cpp | 2 +- .../sensor/src/force-torque/vpForceTorqueIitSensor.cpp | 2 +- .../src/framegrabber/flycapture/vpFlyCaptureGrabber.cpp | 2 +- modules/sensor/src/framegrabber/pylon/vpPylonFactory.cpp | 2 +- .../sensor/src/framegrabber/pylon/vpPylonGrabberGigE.cpp | 2 +- .../sensor/src/framegrabber/pylon/vpPylonGrabberUsb.cpp | 2 +- modules/sensor/src/mocap/vpMocapQualisys.cpp | 2 +- modules/sensor/src/mocap/vpMocapVicon.cpp | 2 +- modules/tracker/blob/src/dots/vpDot.cpp | 2 +- 15 files changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/core/src/image/vpColormap.cpp b/modules/core/src/image/vpColormap.cpp index 5fdf8d1c9f..8d470832c4 100644 --- a/modules/core/src/image/vpColormap.cpp +++ b/modules/core/src/image/vpColormap.cpp @@ -1005,7 +1005,7 @@ unsigned char m_winterSrgbBytes[256][3] = { {0, 245, 132}, {0, 246, 131}, {0, 247, 131}, {0, 248, 131}, {0, 249, 130}, {0, 250, 130}, {0, 251, 129}, {0, 252, 129}, {0, 253, 128}, {0, 254, 128}, {0, 255, 127} }; -}; +} BEGIN_VISP_NAMESPACE /*! diff --git a/modules/core/src/image/vpImageConvert_yuv.cpp b/modules/core/src/image/vpImageConvert_yuv.cpp index 3bd4ab23db..6005982cb1 100644 --- a/modules/core/src/image/vpImageConvert_yuv.cpp +++ b/modules/core/src/image/vpImageConvert_yuv.cpp @@ -53,7 +53,7 @@ void vpSAT(int &c) c = val_255; } } -}; +} BEGIN_VISP_NAMESPACE /*! diff --git a/modules/core/src/math/matrix/vpColVector.cpp b/modules/core/src/math/matrix/vpColVector.cpp index 6c9fc1738e..0894d3e798 100644 --- a/modules/core/src/math/matrix/vpColVector.cpp +++ b/modules/core/src/math/matrix/vpColVector.cpp @@ -969,7 +969,7 @@ std::ostream &vpColVector::cppPrint(std::ostream &os, const std::string &matrixN } std::cout << std::endl; return os; -}; +} std::ostream &vpColVector::csvPrint(std::ostream &os) const { @@ -980,7 +980,7 @@ std::ostream &vpColVector::csvPrint(std::ostream &os) const os << std::endl; } return os; -}; +} std::ostream &vpColVector::maplePrint(std::ostream &os) const { @@ -993,7 +993,7 @@ std::ostream &vpColVector::maplePrint(std::ostream &os) const } os << "])" << std::endl; return os; -}; +} std::ostream &vpColVector::matlabPrint(std::ostream &os) const { @@ -1009,7 +1009,7 @@ std::ostream &vpColVector::matlabPrint(std::ostream &os) const } } return os; -}; +} #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) diff --git a/modules/core/src/tools/geometry/vpPlane.cpp b/modules/core/src/tools/geometry/vpPlane.cpp index d2fdf7805e..71d177b1cd 100644 --- a/modules/core/src/tools/geometry/vpPlane.cpp +++ b/modules/core/src/tools/geometry/vpPlane.cpp @@ -414,5 +414,5 @@ void vpPlane::changeFrame(const vpHomogeneousMatrix &cMo) VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpPlane &p) { return (os << "(" << p.getA() << "," << p.getB() << "," << p.getC() << "," << p.getD() << ") "); -}; +} END_VISP_NAMESPACE diff --git a/modules/core/src/tools/geometry/vpTriangle.cpp b/modules/core/src/tools/geometry/vpTriangle.cpp index 9b979ddf97..511bd86c4b 100644 --- a/modules/core/src/tools/geometry/vpTriangle.cpp +++ b/modules/core/src/tools/geometry/vpTriangle.cpp @@ -100,7 +100,7 @@ vpTriangle &vpTriangle::operator=(const vpTriangle &tri) apex2 = tri.apex2; apex3 = tri.apex3; return *this; -}; +} /*! Initialise the triangle thanks to the three 2D points \f$ iP1 \f$, \f$ iP2 diff --git a/modules/core/src/tools/time/vpTime.cpp b/modules/core/src/tools/time/vpTime.cpp index 9f4a36e5f4..7962dc4df7 100644 --- a/modules/core/src/tools/time/vpTime.cpp +++ b/modules/core/src/tools/time/vpTime.cpp @@ -374,7 +374,7 @@ std::string getDateTime(const std::string &format) } #ifndef DOXYGEN_SHOULD_SKIP_THIS -}; +} #endif vpChrono::vpChrono() : m_durationMs(), m_lastTimePoint() { } diff --git a/modules/robot/src/haptic-device/virtuose/vpVirtuose.cpp b/modules/robot/src/haptic-device/virtuose/vpVirtuose.cpp index 67e1e45b1e..29e36f6817 100644 --- a/modules/robot/src/haptic-device/virtuose/vpVirtuose.cpp +++ b/modules/robot/src/haptic-device/virtuose/vpVirtuose.cpp @@ -1054,5 +1054,5 @@ void vpVirtuose::stopPeriodicFunction() END_VISP_NAMESPACE #else // Work around to avoid warning -void dummy_vpVirtuose() { }; +void dummy_vpVirtuose() { } #endif diff --git a/modules/sensor/src/force-torque/vpForceTorqueIitSensor.cpp b/modules/sensor/src/force-torque/vpForceTorqueIitSensor.cpp index 0648db04b4..cd51856697 100644 --- a/modules/sensor/src/force-torque/vpForceTorqueIitSensor.cpp +++ b/modules/sensor/src/force-torque/vpForceTorqueIitSensor.cpp @@ -242,5 +242,5 @@ END_VISP_NAMESPACE #else // Work around to avoid warning: // libvisp_sensor.a(vpForceTorqueIitSensor.cpp.o) has no symbols -void dummy_vpForceTorqueIitSensor() { }; +void dummy_vpForceTorqueIitSensor() { } #endif diff --git a/modules/sensor/src/framegrabber/flycapture/vpFlyCaptureGrabber.cpp b/modules/sensor/src/framegrabber/flycapture/vpFlyCaptureGrabber.cpp index 00108e5470..f38ffce676 100644 --- a/modules/sensor/src/framegrabber/flycapture/vpFlyCaptureGrabber.cpp +++ b/modules/sensor/src/framegrabber/flycapture/vpFlyCaptureGrabber.cpp @@ -1463,5 +1463,5 @@ END_VISP_NAMESPACE #else // Work around to avoid warning: // libvisp_flycapture.a(vpFlyCaptureGrabber.cpp.o) has no symbols -void dummy_vpFlyCaptureGrabber() { }; +void dummy_vpFlyCaptureGrabber() { } #endif diff --git a/modules/sensor/src/framegrabber/pylon/vpPylonFactory.cpp b/modules/sensor/src/framegrabber/pylon/vpPylonFactory.cpp index 51e11531b0..c7a68d3671 100644 --- a/modules/sensor/src/framegrabber/pylon/vpPylonFactory.cpp +++ b/modules/sensor/src/framegrabber/pylon/vpPylonFactory.cpp @@ -86,5 +86,5 @@ END_VISP_NAMESPACE #else // Work around to avoid warning: // libvisp_pylon.a(vpPylonFactory.cpp.o) has no symbols -void dummy_vpPylonFactory() { }; +void dummy_vpPylonFactory() { } #endif // #ifdef VISP_HAVE_PYLON diff --git a/modules/sensor/src/framegrabber/pylon/vpPylonGrabberGigE.cpp b/modules/sensor/src/framegrabber/pylon/vpPylonGrabberGigE.cpp index 66b205ffcc..756e4a0184 100644 --- a/modules/sensor/src/framegrabber/pylon/vpPylonGrabberGigE.cpp +++ b/modules/sensor/src/framegrabber/pylon/vpPylonGrabberGigE.cpp @@ -815,5 +815,5 @@ END_VISP_NAMESPACE #else // Work around to avoid warning: // libvisp_pylon.a(vpPylonGrabberGigE.cpp.o) has no symbols -void dummy_vpPylonGrabberGigE() { }; +void dummy_vpPylonGrabberGigE() { } #endif // #ifdef VISP_HAVE_PYLON diff --git a/modules/sensor/src/framegrabber/pylon/vpPylonGrabberUsb.cpp b/modules/sensor/src/framegrabber/pylon/vpPylonGrabberUsb.cpp index ffd2f68530..00a90ca60d 100644 --- a/modules/sensor/src/framegrabber/pylon/vpPylonGrabberUsb.cpp +++ b/modules/sensor/src/framegrabber/pylon/vpPylonGrabberUsb.cpp @@ -797,5 +797,5 @@ END_VISP_NAMESPACE #else // Work around to avoid warning: // libvisp_pylon.a(vpPylonGrabberUsb.cpp.o) has no symbols -void dummy_vpPylonGrabberUsb() { }; +void dummy_vpPylonGrabberUsb() { } #endif // #ifdef VISP_HAVE_PYLON diff --git a/modules/sensor/src/mocap/vpMocapQualisys.cpp b/modules/sensor/src/mocap/vpMocapQualisys.cpp index 0f48be1f2b..3dfe789068 100644 --- a/modules/sensor/src/mocap/vpMocapQualisys.cpp +++ b/modules/sensor/src/mocap/vpMocapQualisys.cpp @@ -315,5 +315,5 @@ END_VISP_NAMESPACE #else // Work around to avoid warning: // libvisp_sensor.a(vpMocapQualisys.cpp.o) has no symbols -void dummy_vpMocapQualisys() { }; +void dummy_vpMocapQualisys() { } #endif diff --git a/modules/sensor/src/mocap/vpMocapVicon.cpp b/modules/sensor/src/mocap/vpMocapVicon.cpp index 22482ac5e9..5ed27fd191 100644 --- a/modules/sensor/src/mocap/vpMocapVicon.cpp +++ b/modules/sensor/src/mocap/vpMocapVicon.cpp @@ -272,5 +272,5 @@ END_VISP_NAMESPACE #else // Work around to avoid warning: // libvisp_sensor.a(vpMocapVicon.cpp.o) has no symbols -void dummy_vpMocapVicon() { }; +void dummy_vpMocapVicon() { } #endif diff --git a/modules/tracker/blob/src/dots/vpDot.cpp b/modules/tracker/blob/src/dots/vpDot.cpp index 3504d57ac3..3283c93a63 100644 --- a/modules/tracker/blob/src/dots/vpDot.cpp +++ b/modules/tracker/blob/src/dots/vpDot.cpp @@ -916,6 +916,6 @@ void vpDot::display(const vpImage &I, const vpImagePoint &cog, const std details about the orientation of the frame see the vpImagePoint documentation) to the stream \e os, and returns a reference to the stream. */ -VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpDot &d) { return (os << "(" << d.getCog() << ")"); }; +VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpDot &d) { return (os << "(" << d.getCog() << ")"); } END_VISP_NAMESPACE From 9a29a69803e2a5aef62687e7cc825a947f5bf8ae Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 27 Nov 2024 14:16:09 +0100 Subject: [PATCH 16/31] Fix warning around sprintf() usage that is deprecated --- 3rdparty/stb_image/stb_image_write.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty/stb_image/stb_image_write.h b/3rdparty/stb_image/stb_image_write.h index e4b32ed1bc..151eacaacd 100644 --- a/3rdparty/stb_image/stb_image_write.h +++ b/3rdparty/stb_image/stb_image_write.h @@ -773,7 +773,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f #ifdef __STDC_LIB_EXT1__ len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); #else - len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); + len = snprintf(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); #endif s->func(s->context, buffer, len); From 86c8d68939eb385c3aa80e6130447af62d000140 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 27 Nov 2024 14:19:01 +0100 Subject: [PATCH 17/31] Fix missing initialization of m_minStackSize var Improve quality by fixing issues reported by sonarqube --- .../core/src/image/vpCannyEdgeDetection.cpp | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/modules/core/src/image/vpCannyEdgeDetection.cpp b/modules/core/src/image/vpCannyEdgeDetection.cpp index 5d8222b963..0dbf7c2dc4 100644 --- a/modules/core/src/image/vpCannyEdgeDetection.cpp +++ b/modules/core/src/image/vpCannyEdgeDetection.cpp @@ -26,8 +26,7 @@ * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * -*****************************************************************************/ + */ #include @@ -103,17 +102,21 @@ vpCannyEdgeDetection::vpCannyEdgeDetection() , m_lowerThresholdRatio(0.6f) , m_upperThreshold(-1.f) , m_upperThresholdRatio(0.8f) +#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX + , m_minStackSize(65532000) // Maximum stack size on MacOS, see https://stackoverflow.com/a/13261334 +#endif , mp_mask(nullptr) { initGaussianFilters(); initGradientFilters(); } -vpCannyEdgeDetection::vpCannyEdgeDetection(const int &gaussianKernelSize, const float &gaussianStdev - , const unsigned int &sobelAperture, const float &lowerThreshold, const float &upperThreshold - , const float &lowerThresholdRatio, const float &upperThresholdRatio - , const vpImageFilter::vpCannyFilteringAndGradientType &filteringType - , const bool &storeEdgePoints +vpCannyEdgeDetection::vpCannyEdgeDetection(const int &gaussianKernelSize, const float &gaussianStdev, + const unsigned int &sobelAperture, const float &lowerThreshold, + const float &upperThreshold, const float &lowerThresholdRatio, + const float &upperThresholdRatio, + const vpImageFilter::vpCannyFilteringAndGradientType &filteringType, + const bool &storeEdgePoints ) : m_filteringAndGradientType(filteringType) , m_gaussianKernelSize(gaussianKernelSize) @@ -138,7 +141,10 @@ vpCannyEdgeDetection::vpCannyEdgeDetection(const int &gaussianKernelSize, const using json = nlohmann::json; -vpCannyEdgeDetection::vpCannyEdgeDetection(const std::string &jsonPath) +vpCannyEdgeDetection::vpCannyEdgeDetection(const std::string &jsonPath) : +#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX + m_minStackSize(65532000) // Maximum stack size on MacOS, see https://stackoverflow.com/a/13261334 +#endif { initFromJSON(jsonPath); } @@ -173,7 +179,8 @@ vpCannyEdgeDetection::initFromJSON(const std::string &jsonPath) void vpCannyEdgeDetection::initGaussianFilters() { - if ((m_gaussianKernelSize % 2) == 0) { + const int val_2 = 2; + if ((m_gaussianKernelSize % val_2) == 0) { throw(vpException(vpException::badValue, "The Gaussian kernel size should be odd")); } m_fg.resize(1, (m_gaussianKernelSize + 1) / 2); @@ -183,7 +190,8 @@ vpCannyEdgeDetection::initGaussianFilters() void vpCannyEdgeDetection::initGradientFilters() { - if ((m_gradientFilterKernelSize % 2) != 1) { + const int val_2 = 2; + if ((m_gradientFilterKernelSize % val_2) != 1) { throw vpException(vpException::badValue, "Gradient filters kernel size should be odd."); } m_gradientFilterX.resize(m_gradientFilterKernelSize, m_gradientFilterKernelSize); @@ -205,13 +213,13 @@ vpCannyEdgeDetection::initGradientFilters() float scaleY = 1.f; if (m_filteringAndGradientType == vpImageFilter::CANNY_GBLUR_SOBEL_FILTERING) { - scaleX = vpImageFilter::getSobelKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1) / 2); - scaleY = vpImageFilter::getSobelKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1) / 2); + scaleX = vpImageFilter::getSobelKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1) / val_2); + scaleY = vpImageFilter::getSobelKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1) / val_2); } else if (m_filteringAndGradientType == vpImageFilter::CANNY_GBLUR_SCHARR_FILTERING) { // Compute the Scharr filters - scaleX = vpImageFilter::getScharrKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1) / 2); - scaleY = vpImageFilter::getScharrKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1) / 2); + scaleX = vpImageFilter::getScharrKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1) / val_2); + scaleY = vpImageFilter::getScharrKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1) / val_2); } else { std::string errMsg = "[vpCannyEdgeDetection::initGradientFilters] Error: gradient filtering method \""; @@ -266,7 +274,7 @@ vpCannyEdgeDetection::detect(const vpImage &I) throw(vpException(vpException::fatalError, "getrlimit returned result = %d\n", result)); } #endif -// // Clearing the previous results + // // Clearing the previous results m_edgeMap.resize(I.getHeight(), I.getWidth(), 0); m_edgeCandidateAndGradient.clear(); m_edgePointsCandidates.clear(); @@ -530,11 +538,12 @@ vpCannyEdgeDetection::performHysteresisThresholding(const float &lowerThreshold, void vpCannyEdgeDetection::performEdgeTracking() { + const unsigned char var_uc_255 = 255; std::map, EdgeType>::iterator it; std::map, EdgeType>::iterator m_edgePointsCandidates_end = m_edgePointsCandidates.end(); for (it = m_edgePointsCandidates.begin(); it != m_edgePointsCandidates_end; ++it) { if (it->second == STRONG_EDGE) { - m_edgeMap[it->first.first][it->first.second] = 255; + m_edgeMap[it->first.first][it->first.second] = var_uc_255; if (m_storeListEdgePoints) { m_edgePointsList.push_back(vpImagePoint(it->first.first, it->first.second)); } @@ -599,9 +608,10 @@ vpCannyEdgeDetection::recursiveSearchForStrongEdge(const std::pair Date: Wed, 27 Nov 2024 14:20:19 +0100 Subject: [PATCH 18/31] Improve quality by fixing issues reported by sonarqube --- .../include/visp3/core/vpCannyEdgeDetection.h | 4 +- .../include/visp3/core/vpEigenConversion.h | 3 +- .../include/visp3/core/vpForceTwistMatrix.h | 2 + modules/core/include/visp3/core/vpGaussRand.h | 11 +- modules/core/include/visp3/core/vpHistogram.h | 1 + .../include/visp3/core/vpHomogeneousMatrix.h | 2 + modules/core/include/visp3/core/vpImage.h | 3 +- .../core/include/visp3/core/vpPoseVector.h | 2 + .../include/visp3/core/vpQuaternionVector.h | 1 + .../include/visp3/core/vpRotationMatrix.h | 2 + .../core/include/visp3/core/vpRxyzVector.h | 2 + .../core/include/visp3/core/vpRzyxVector.h | 2 + .../core/include/visp3/core/vpRzyzVector.h | 2 + .../core/include/visp3/core/vpThetaUVector.h | 1 + .../include/visp3/core/vpTranslationVector.h | 2 + .../visp3/core/vpVelocityTwistMatrix.h | 2 + .../core/src/camera/vpCameraParameters.cpp | 6 +- modules/core/src/camera/vpXmlParserCamera.cpp | 10 +- .../src/image/private/vpImageConvert_impl.h | 31 +-- modules/core/src/image/vpImageCircle.cpp | 21 ++- modules/core/src/image/vpImageConvert.cpp | 177 +++++++++++------- modules/core/src/image/vpImageConvert_hsv.cpp | 59 ++++-- modules/core/src/image/vpImageConvert_yuv.cpp | 46 +++-- modules/core/src/image/vpImageFilter_xy.cpp | 18 +- modules/core/src/image/vpImageTools.cpp | 30 +-- modules/core/src/image/vpRGBa.cpp | 3 +- modules/core/src/math/matrix/vpColVector.cpp | 28 ++- .../src/math/matrix/vpEigenConversion.cpp | 3 +- modules/core/src/math/matrix/vpMatrix.cpp | 6 +- .../src/math/matrix/vpMatrix_covariance.cpp | 5 +- modules/core/src/math/matrix/vpMatrix_lu.cpp | 16 +- .../src/math/matrix/vpMatrix_operations.cpp | 19 +- .../src/math/matrix/vpMatrix_operators.cpp | 16 +- .../math/matrix/vpMatrix_pseudo_inverse.cpp | 2 +- modules/core/src/math/matrix/vpRowVector.cpp | 9 +- modules/core/src/math/misc/vpMath.cpp | 10 +- .../src/math/random-generator/vpGaussRand.cpp | 9 +- .../src/math/random-generator/vpUniRand.cpp | 14 +- .../math/transformation/vpExponentialMap.cpp | 5 +- .../transformation/vpForceTwistMatrix.cpp | 39 ++-- .../transformation/vpHomogeneousMatrix.cpp | 73 +++++--- .../src/math/transformation/vpPoseVector.cpp | 25 ++- .../transformation/vpQuaternionVector.cpp | 25 +-- .../math/transformation/vpRotationMatrix.cpp | 55 +++--- .../src/math/transformation/vpRxyzVector.cpp | 25 +-- .../src/math/transformation/vpRzyxVector.cpp | 28 +-- .../src/math/transformation/vpRzyzVector.cpp | 25 +-- .../math/transformation/vpThetaUVector.cpp | 47 ++--- .../transformation/vpTranslationVector.cpp | 23 ++- .../transformation/vpVelocityTwistMatrix.cpp | 36 ++-- modules/core/src/tools/geometry/vpPlane.cpp | 6 +- modules/core/src/tools/geometry/vpPolygon.cpp | 27 ++- .../src/tools/geometry/vpRectOriented.cpp | 34 ++-- .../core/src/tools/histogram/vpHistogram.cpp | 32 ++-- .../tracking/forward-projection/vpCircle.cpp | 35 ++-- .../tracking/forward-projection/vpLine.cpp | 28 +-- .../tracking/forward-projection/vpPoint.cpp | 14 +- .../tracking/forward-projection/vpSphere.cpp | 14 +- 58 files changed, 709 insertions(+), 467 deletions(-) diff --git a/modules/core/include/visp3/core/vpCannyEdgeDetection.h b/modules/core/include/visp3/core/vpCannyEdgeDetection.h index 1a0d898e1b..74de78efdf 100644 --- a/modules/core/include/visp3/core/vpCannyEdgeDetection.h +++ b/modules/core/include/visp3/core/vpCannyEdgeDetection.h @@ -276,7 +276,7 @@ class VISP_EXPORT vpCannyEdgeDetection } /** - * \brief Set the minimum stack size, expressed in bytes, due to the recursivity of the algorithm. + * \brief Set the minimum stack size, expressed in bytes, due to the recursive algorithm. * * \note The stack size is changed back to its original value after * before leaving the detect() function. @@ -299,7 +299,7 @@ class VISP_EXPORT vpCannyEdgeDetection (void)requiredStackSize; static bool hasNotBeenDisplayed = true; if (hasNotBeenDisplayed) { - std::cerr << "setStackSize has no effect on non-POSIX systems. The stack size is defined during compilation." << std::endl; + std::cerr << "vpCannyEdgeDetection::setStackSize() has no effect on non-POSIX systems. The stack size is defined during compilation." << std::endl; hasNotBeenDisplayed = false; } } diff --git a/modules/core/include/visp3/core/vpEigenConversion.h b/modules/core/include/visp3/core/vpEigenConversion.h index 08a6f6b564..c614fa5a5d 100644 --- a/modules/core/include/visp3/core/vpEigenConversion.h +++ b/modules/core/include/visp3/core/vpEigenConversion.h @@ -57,7 +57,8 @@ void eigen2visp(const Eigen::Quaternion &src, vpQuaternionVector &dst) template void eigen2visp(const Eigen::AngleAxis &src, vpThetaUVector &dst) { - dst.buildFrom(src.angle() * src.axis()(0), src.angle() * src.axis()(1), src.angle() * src.axis()(2)); + const unsigned int val_2 = 2; + dst.buildFrom(src.angle() * src.axis()(0), src.angle() * src.axis()(1), src.angle() * src.axis()(val_2)); } VISP_EXPORT void eigen2visp(const Eigen::VectorXd &src, vpColVector &dst); diff --git a/modules/core/include/visp3/core/vpForceTwistMatrix.h b/modules/core/include/visp3/core/vpForceTwistMatrix.h index eb50c386dc..4bf00470a0 100644 --- a/modules/core/include/visp3/core/vpForceTwistMatrix.h +++ b/modules/core/include/visp3/core/vpForceTwistMatrix.h @@ -230,6 +230,8 @@ class VISP_EXPORT vpForceTwistMatrix : public vpArray2D throw(vpException(vpException::fatalError, "Cannot resize a velocity twist matrix")); } +private: + static const unsigned int constr_value_6; #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) /*! @name Deprecated functions diff --git a/modules/core/include/visp3/core/vpGaussRand.h b/modules/core/include/visp3/core/vpGaussRand.h index 00f594e6cf..723f55efda 100644 --- a/modules/core/include/visp3/core/vpGaussRand.h +++ b/modules/core/include/visp3/core/vpGaussRand.h @@ -31,8 +31,8 @@ * Generation of random number with uniform and normal probability density. */ -#ifndef vpGaussRand_hh -#define vpGaussRand_hh +#ifndef VP_GAUSSRAND_H +#define VP_GAUSSRAND_H #include #include @@ -149,12 +149,15 @@ class VISP_EXPORT vpGaussRand \param seed_val : New seed. */ - void seed(long seed_val) { m_rng.setSeed(seed_val, 0x123465789ULL); } + void seed(long seed_val) { + const unsigned long long val_ull = 0x123465789ULL; + m_rng.setSeed(seed_val, val_ull); + } /*! Return a random value from the Gaussian noise generator. */ - double operator()() { return m_sigma * gaussianDraw() + m_mean; } + double operator()() { return (m_sigma * gaussianDraw()) + m_mean; } private: double gaussianDraw(); diff --git a/modules/core/include/visp3/core/vpHistogram.h b/modules/core/include/visp3/core/vpHistogram.h index df4aeb99ae..415ff60534 100644 --- a/modules/core/include/visp3/core/vpHistogram.h +++ b/modules/core/include/visp3/core/vpHistogram.h @@ -314,6 +314,7 @@ class VISP_EXPORT vpHistogram unsigned m_size; /*!< Histogram size (max allowed 256).*/ const vpImage *mp_mask; /*!< Mask that permits to consider only the pixels for which the mask is true.*/ unsigned int m_total; /*!< Cumulated number of pixels in the input image. */ + static const unsigned int constr_val_256; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpHomogeneousMatrix.h b/modules/core/include/visp3/core/vpHomogeneousMatrix.h index 41bde6a97e..9f4b86b7f9 100644 --- a/modules/core/include/visp3/core/vpHomogeneousMatrix.h +++ b/modules/core/include/visp3/core/vpHomogeneousMatrix.h @@ -434,6 +434,8 @@ class VISP_EXPORT vpHomogeneousMatrix : public vpArray2D protected: unsigned int m_index; +private: + static const unsigned int constr_value_4; }; #ifdef VISP_HAVE_NLOHMANN_JSON diff --git a/modules/core/include/visp3/core/vpImage.h b/modules/core/include/visp3/core/vpImage.h index 59177f746f..7fb88c3bc4 100644 --- a/modules/core/include/visp3/core/vpImage.h +++ b/modules/core/include/visp3/core/vpImage.h @@ -330,7 +330,8 @@ template class vpImage friend std::ostream &operator<<(std::ostream &s, const vpImage &I); // Perform a look-up table transformation - void performLut(const Type(&lut)[256], unsigned int nbThreads = 1); + static const unsigned int val_256 = 256; + void performLut(const Type(&lut)[val_256], unsigned int nbThreads = 1); // Returns a new image that's a quarter size of the current image void quarterSizeImage(vpImage &res) const; diff --git a/modules/core/include/visp3/core/vpPoseVector.h b/modules/core/include/visp3/core/vpPoseVector.h index 4863901810..12e3e1c03a 100644 --- a/modules/core/include/visp3/core/vpPoseVector.h +++ b/modules/core/include/visp3/core/vpPoseVector.h @@ -316,6 +316,8 @@ class VISP_EXPORT vpPoseVector : public vpArray2D public: #endif +private: + static const unsigned int constr_value_6; #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) /*! @name Deprecated functions diff --git a/modules/core/include/visp3/core/vpQuaternionVector.h b/modules/core/include/visp3/core/vpQuaternionVector.h index 5b7488eb26..8ed138c013 100644 --- a/modules/core/include/visp3/core/vpQuaternionVector.h +++ b/modules/core/include/visp3/core/vpQuaternionVector.h @@ -156,6 +156,7 @@ class VISP_EXPORT vpQuaternionVector : public vpRotationVector private: static const double minimum; + static const unsigned int constr_val_4; }; END_VISP_NAMESPACE diff --git a/modules/core/include/visp3/core/vpRotationMatrix.h b/modules/core/include/visp3/core/vpRotationMatrix.h index eda483ea94..2c669d422d 100644 --- a/modules/core/include/visp3/core/vpRotationMatrix.h +++ b/modules/core/include/visp3/core/vpRotationMatrix.h @@ -228,6 +228,8 @@ class VISP_EXPORT vpRotationMatrix : public vpArray2D protected: unsigned int m_index; +private: + static const unsigned int constr_val_3; }; #ifndef DOXYGEN_SHOULD_SKIP_THIS diff --git a/modules/core/include/visp3/core/vpRxyzVector.h b/modules/core/include/visp3/core/vpRxyzVector.h index aa7de3223f..12f93eb7c7 100644 --- a/modules/core/include/visp3/core/vpRxyzVector.h +++ b/modules/core/include/visp3/core/vpRxyzVector.h @@ -210,6 +210,8 @@ class VISP_EXPORT vpRxyzVector : public vpRotationVector vpRxyzVector &operator=(const vpRxyzVector &) = default; vpRxyzVector &operator=(const std::initializer_list &list); #endif +private: + static const unsigned int constr_val_3; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpRzyxVector.h b/modules/core/include/visp3/core/vpRzyxVector.h index 810d66c333..4236f02434 100644 --- a/modules/core/include/visp3/core/vpRzyxVector.h +++ b/modules/core/include/visp3/core/vpRzyxVector.h @@ -211,6 +211,8 @@ class VISP_EXPORT vpRzyxVector : public vpRotationVector vpRzyxVector &operator=(const vpRzyxVector &) = default; vpRzyxVector &operator=(const std::initializer_list &list); #endif +private: + static const unsigned int constr_val_3; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpRzyzVector.h b/modules/core/include/visp3/core/vpRzyzVector.h index b9177b86f8..86aa46b427 100644 --- a/modules/core/include/visp3/core/vpRzyzVector.h +++ b/modules/core/include/visp3/core/vpRzyzVector.h @@ -210,6 +210,8 @@ class VISP_EXPORT vpRzyzVector : public vpRotationVector vpRzyzVector &operator=(const vpRzyzVector &) = default; vpRzyzVector &operator=(const std::initializer_list &list); #endif +private: + static const unsigned int constr_val_3; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpThetaUVector.h b/modules/core/include/visp3/core/vpThetaUVector.h index 438e4026b0..ef0e6c4fad 100644 --- a/modules/core/include/visp3/core/vpThetaUVector.h +++ b/modules/core/include/visp3/core/vpThetaUVector.h @@ -225,6 +225,7 @@ class VISP_EXPORT vpThetaUVector : public vpRotationVector private: static const double minimum; + static const unsigned int constr_val_3; }; END_VISP_NAMESPACE diff --git a/modules/core/include/visp3/core/vpTranslationVector.h b/modules/core/include/visp3/core/vpTranslationVector.h index 7d50768a9f..df89ef4be8 100644 --- a/modules/core/include/visp3/core/vpTranslationVector.h +++ b/modules/core/include/visp3/core/vpTranslationVector.h @@ -206,6 +206,8 @@ class VISP_EXPORT vpTranslationVector : public vpArray2D protected: unsigned int m_index; // index used for operator<< and operator, to fill a vector +private: + static const unsigned int constr_val_3; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpVelocityTwistMatrix.h b/modules/core/include/visp3/core/vpVelocityTwistMatrix.h index 18700db24f..feda1e6e62 100644 --- a/modules/core/include/visp3/core/vpVelocityTwistMatrix.h +++ b/modules/core/include/visp3/core/vpVelocityTwistMatrix.h @@ -244,6 +244,8 @@ class VISP_EXPORT vpVelocityTwistMatrix : public vpArray2D VP_DEPRECATED void setIdentity(); //@} #endif + private: + static const unsigned constr_val_6; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/src/camera/vpCameraParameters.cpp b/modules/core/src/camera/vpCameraParameters.cpp index f8fdab20d0..4f04070727 100644 --- a/modules/core/src/camera/vpCameraParameters.cpp +++ b/modules/core/src/camera/vpCameraParameters.cpp @@ -640,14 +640,16 @@ void vpCameraParameters::printParameters() std::ios::fmtflags original_flags(std::cout.flags()); switch (m_projModel) { case vpCameraParameters::perspectiveProjWithoutDistortion: { - std::cout.precision(10); + const unsigned int precision = 10; + std::cout.precision(precision); std::cout << "Camera parameters for perspective projection without distortion:" << std::endl; std::cout << " px = " << m_px << "\t py = " << m_py << std::endl; std::cout << " u0 = " << m_u0 << "\t v0 = " << m_v0 << std::endl; break; } case vpCameraParameters::perspectiveProjWithDistortion: { - std::cout.precision(10); + const unsigned int precision = 10; + std::cout.precision(precision); std::cout << "Camera parameters for perspective projection with distortion:" << std::endl; std::cout << " px = " << m_px << "\t py = " << m_py << std::endl; std::cout << " u0 = " << m_u0 << "\t v0 = " << m_v0 << std::endl; diff --git a/modules/core/src/camera/vpXmlParserCamera.cpp b/modules/core/src/camera/vpXmlParserCamera.cpp index 1e1e75cadd..f2e39cdabb 100644 --- a/modules/core/src/camera/vpXmlParserCamera.cpp +++ b/modules/core/src/camera/vpXmlParserCamera.cpp @@ -472,7 +472,7 @@ class vpXmlParserCamera::Impl } if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITHOUT_DISTORTION)) { - if (nb != 5 || validation != 0x001F) { + if ((nb != 5) || (validation != 0x001F)) { std::cout << "ERROR in 'model' field:\n"; std::cout << "it must contain 5 parameters\n"; @@ -481,7 +481,7 @@ class vpXmlParserCamera::Impl cam_tmp.initPersProjWithoutDistortion(px, py, u0, v0); } else if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITH_DISTORTION)) { - if (nb != 7 || validation != 0x7F) { + if ((nb != 7) || (validation != 0x7F)) { std::cout << "ERROR in 'model' field:\n"; std::cout << "it must contain 7 parameters\n"; @@ -490,7 +490,7 @@ class vpXmlParserCamera::Impl cam_tmp.initPersProjWithDistortion(px, py, u0, v0, kud, kdu); } else if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITH_KANNALA_BRANDT_DISTORTION)) { - if (nb != 10 || validation != 0x3FF) { // at least one coefficient is missing. We should know which one + if ((nb != 10) || (validation != 0x3FF)) { // at least one coefficient is missing. We should know which one std::cout << "ERROR in 'model' field:\n"; std::cout << "it must contain 10 parameters\n"; @@ -807,7 +807,7 @@ class vpXmlParserCamera::Impl node_tmp.append_child(pugi::node_pcdata).set_value(cam_name.c_str()); } - if (im_width != 0 || im_height != 0) { + if ((im_width != 0) || (im_height != 0)) { node_tmp = node_camera.append_child(pugi::node_comment); node_tmp.set_value("Size of the image on which camera " "calibration was performed"); @@ -819,7 +819,7 @@ class vpXmlParserCamera::Impl // node_tmp = node_camera.append_child(LABEL_XML_HEIGHT); node_tmp.append_child(pugi::node_pcdata).text() = im_height; - if (subsampling_width != 0 || subsampling_height != 0) { + if ((subsampling_width != 0) || (subsampling_height != 0)) { node_tmp = node_camera.append_child(pugi::node_comment); node_tmp.set_value("Subsampling used to obtain the " "current size of the image."); diff --git a/modules/core/src/image/private/vpImageConvert_impl.h b/modules/core/src/image/private/vpImageConvert_impl.h index 493fa91074..f5d7a17485 100644 --- a/modules/core/src/image/private/vpImageConvert_impl.h +++ b/modules/core/src/image/private/vpImageConvert_impl.h @@ -92,7 +92,8 @@ BEGIN_VISP_NAMESPACE } #endif - for (int i = 2; i < 0x10000; ++i) { + const unsigned int val_0x10000 = 0x10000; + for (int i = 2; i < val_0x10000; ++i) { histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF] } dest_depth.resize(src_depth.getHeight(), src_depth.getWidth()); @@ -149,7 +150,8 @@ void vp_createDepthHistogram(const vpImage &src_depth, vpImage &src_depth, vpImage &d } } - for (int i = 2; i < 0x10000; ++i) { + const unsigned int val_0x10000 = 0x10000; + for (int i = 2; i < val_0x10000; ++i) { histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF] } #ifdef VISP_HAVE_OPENMP #pragma omp parallel for #endif + const unsigned char val_uc_5 = 5; + const unsigned char val_uc_20 = 20; + const unsigned char val_uc_255 = 255; for (int i = 0; i < src_depth_size; ++i) { uint16_t d = static_cast(src_depth.bitmap[i]); if (d) { unsigned char f = static_cast((histogram[d] * 255) / histogram[0xFFFF]); // 0-255 based on histogram location - dest_depth.bitmap[i].R = 255 - f; + dest_depth.bitmap[i].R = val_uc_255 - f; dest_depth.bitmap[i].G = 0; dest_depth.bitmap[i].B = f; dest_depth.bitmap[i].A = vpRGBa::alpha_default; } else { - dest_depth.bitmap[i].R = 20; - dest_depth.bitmap[i].G = 5; + dest_depth.bitmap[i].R = val_uc_20; + dest_depth.bitmap[i].G = val_uc_5; dest_depth.bitmap[i].B = 0; dest_depth.bitmap[i].A = vpRGBa::alpha_default; } @@ -237,26 +243,29 @@ void vp_createDepthHistogram(const vpImage &src_depth, vpImage ++histogram[static_cast(src_depth.bitmap[i])]; } - for (unsigned int i = 2; i < 0x10000; ++i) { + const unsigned int val_0x10000 = 0x10000; + for (unsigned int i = 2; i < val_0x10000; ++i) { histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF] } - #ifdef VISP_HAVE_OPENMP #pragma omp parallel for #endif + const unsigned char val_uc_5 = 5; + const unsigned char val_uc_20 = 20; + const unsigned char val_uc_255 = 255; for (int i = 0; i < src_depth_size; ++i) { uint16_t d = src_depth.bitmap[i]; if (d) { unsigned char f = static_cast((histogram[d] * 255) / histogram[0xFFFF]); // 0-255 based on histogram location - dest_depth.bitmap[i].R = 255 - f; + dest_depth.bitmap[i].R = val_uc_255 - f; dest_depth.bitmap[i].G = 0; dest_depth.bitmap[i].B = f; dest_depth.bitmap[i].A = vpRGBa::alpha_default; } else { - dest_depth.bitmap[i].R = 20; - dest_depth.bitmap[i].G = 5; + dest_depth.bitmap[i].R = val_uc_20; + dest_depth.bitmap[i].G = val_uc_5; dest_depth.bitmap[i].B = 0; dest_depth.bitmap[i].A = vpRGBa::alpha_default; } diff --git a/modules/core/src/image/vpImageCircle.cpp b/modules/core/src/image/vpImageCircle.cpp index 1e3ce0d3c7..cb75dac8db 100644 --- a/modules/core/src/image/vpImageCircle.cpp +++ b/modules/core/src/image/vpImageCircle.cpp @@ -74,13 +74,14 @@ void computeIntersectionsLeftBorder(const float &u_c, const float &umin_roi, con { // --comment: umin_roi = u_c + r cos(theta) // --comment: theta = acos of of umin_roi - u_c endof / r endof + const int val_2 = 2; float theta1 = std::acos((umin_roi - u_c) / radius); theta1 = vpMath::getAngleBetweenMinPiAndPi(theta1); float theta2 = -1.f * theta1; float theta_min = std::min(theta1, theta2); float theta_max = std::max(theta1, theta2); delta_theta = theta_max - theta_min; - if ((u_c < umin_roi) && (std::abs(delta_theta - (2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { + if ((u_c < umin_roi) && (std::abs(delta_theta - (val_2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { delta_theta = 0.f; } } @@ -99,13 +100,14 @@ void computeIntersectionsRightBorder(const float &u_c, const float &umax_roi, co { // --comment: u = u_c + r cos(theta) // --comment: theta = acos of of u - u_c endof / r endof + const int val_2 = 2; float theta1 = std::acos((umax_roi - u_c) / radius); theta1 = vpMath::getAngleBetweenMinPiAndPi(theta1); float theta2 = -1.f * theta1; float theta_min = std::min(theta1, theta2); float theta_max = std::max(theta1, theta2); delta_theta = (2.f * M_PI_FLOAT) - (theta_max - theta_min); - if ((u_c > umax_roi) && (std::abs(delta_theta - (2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { + if ((u_c > umax_roi) && (std::abs(delta_theta - (val_2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { delta_theta = 0.f; } } @@ -124,6 +126,7 @@ void computeIntersectionsTopBorder(const float &v_c, const float &vmin_roi, cons { // v = vc - r sin(theta) because the v-axis goes down // theta = asin((vc - v)/r) + const int val_2 = 2; float theta1 = std::asin((v_c - vmin_roi) / radius); theta1 = vpMath::getAngleBetweenMinPiAndPi(theta1); @@ -147,7 +150,7 @@ void computeIntersectionsTopBorder(const float &v_c, const float &vmin_roi, cons else { delta_theta = theta_max - theta_min; } - if ((v_c < vmin_roi) && (std::abs(delta_theta - (2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { + if ((v_c < vmin_roi) && (std::abs(delta_theta - (val_2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { delta_theta = 0.f; } } @@ -166,6 +169,7 @@ void computeIntersBottomBorder(const float &v_c, const float &vmax_roi, const fl { // v = vc - r sin(theta) because the v-axis goes down // theta = asin((vc - v)/r) + const int val_2 = 2; float theta1 = std::asin((v_c - vmax_roi) / radius); theta1 = vpMath::getAngleBetweenMinPiAndPi(theta1); @@ -189,7 +193,7 @@ void computeIntersBottomBorder(const float &v_c, const float &vmax_roi, const fl else { delta_theta = (2.f * M_PI_FLOAT) - (theta_max - theta_min); } - if ((v_c > vmax_roi) && (std::abs(delta_theta - (2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { + if ((v_c > vmax_roi) && (std::abs(delta_theta - (val_2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { delta_theta = 0.f; } } @@ -332,6 +336,7 @@ void computeIntersectionsTopLeft(const float &u_c, const float &v_c, const float void computeIntersectionsTopRight(const float &u_c, const float &v_c, const float &vmin_roi, const float &umax_roi, const float &radius, float &delta_theta) { + const int val_2 = 2; std::pair crossing_theta_u_min, crossing_theta_u_max; std::pair crossing_theta_v_min, crossing_theta_v_max; computePerpendicularAxesInters(u_c, v_c, radius, vmin_roi, umax_roi, @@ -355,7 +360,7 @@ void computeIntersectionsTopRight(const float &u_c, const float &v_c, const floa else if ((u_umin <= umax_roi) && (v_vmin >= vmin_roi) && (u_umax <= umax_roi) && (v_vmax >= vmin_roi)) { // The circle crosses twice each axis //Case crossing twice - delta_theta = (2 * M_PI_FLOAT) - ((theta_u_min - theta_u_max) + (theta_v_min - theta_v_max)); + delta_theta = (val_2 * M_PI_FLOAT) - ((theta_u_min - theta_u_max) + (theta_v_min - theta_v_max)); } else if ((u_umin >= umax_roi) && (v_vmin >= vmin_roi) && (u_umax >= umax_roi) && (v_vmax >= vmin_roi)) { // The circle crosses the u-axis outside the roi @@ -1158,12 +1163,14 @@ vpRect vpImageCircle::getBBox() const float vpImageCircle::get_n20() const { - return (m_radius * m_radius) / 4; + const int val_4 = 4; + return (m_radius * m_radius) / val_4; } float vpImageCircle::get_n02() const { - return (m_radius * m_radius) / 4; + const int val_4 = 4; + return (m_radius * m_radius) / val_4; } float vpImageCircle::get_n11() const diff --git a/modules/core/src/image/vpImageConvert.cpp b/modules/core/src/image/vpImageConvert.cpp index 4886152dbe..e76a5bc68d 100644 --- a/modules/core/src/image/vpImageConvert.cpp +++ b/modules/core/src/image/vpImageConvert.cpp @@ -107,13 +107,14 @@ void vpImageConvert::convert(const vpImage &src, vpImage & src.getMinMaxValue(min, max); + const unsigned char var_uc_255 = 255; for (unsigned int i = 0; i < max_xy; ++i) { float val = 255.f * ((src.bitmap[i] - min) / (max - min)); if (val < 0) { dest.bitmap[i] = 0; } - else if (val > 255) { - dest.bitmap[i] = 255; + else if (val > 255.f) { + dest.bitmap[i] = var_uc_255; } else { dest.bitmap[i] = static_cast(val); @@ -134,16 +135,18 @@ void vpImageConvert::convert(const vpImage &src, vpImage &dest) vpRGBf min, max; src.getMinMaxValue(min, max); + const unsigned int val_3 = 3; + const unsigned char var_uc_255 = 255; for (unsigned int i = 0; i < srcHeight; ++i) { for (unsigned int j = 0; j < srcWidth; ++j) { - for (unsigned int c = 0; c < 3; ++c) { + for (unsigned int c = 0; c < val_3; ++c) { float val = 255.f * ((reinterpret_cast(&(src[i][j]))[c] - reinterpret_cast(&min)[c]) / (reinterpret_cast(&max)[c] - reinterpret_cast(&min)[c])); if (val < 0) { reinterpret_cast(&(dest[i][j]))[c] = 0; } - else if (val > 255) { - reinterpret_cast(&(dest[i][j]))[c] = 255; + else if (val > 255.f) { + reinterpret_cast(&(dest[i][j]))[c] = var_uc_255; } else { reinterpret_cast(&(dest[i][j]))[c] = static_cast(val); @@ -182,13 +185,14 @@ void vpImageConvert::convert(const vpImage &src, vpImage src.getMinMaxValue(min, max); + const unsigned char var_uc_255 = 255; for (unsigned int i = 0; i < max_xy; ++i) { double val = 255. * ((src.bitmap[i] - min) / (max - min)); if (val < 0) { dest.bitmap[i] = 0; } - else if (val > 255) { - dest.bitmap[i] = 255; + else if (val > 255.0) { + dest.bitmap[i] = var_uc_255; } else { dest.bitmap[i] = static_cast(val); @@ -511,13 +515,15 @@ void vpImageConvert::RGBaToGrey(unsigned char *rgba, unsigned char *grey, unsign #if defined(VISP_HAVE_SIMDLIB) SimdRgbaToGray(rgba, size, 1, size * 4, grey, size); #else + const unsigned int val_2 = 2; + const unsigned int val_4 = 4; unsigned char *pt_input = rgba; unsigned char *pt_end = rgba + (size * 4); unsigned char *pt_output = grey; while (pt_input != pt_end) { - *pt_output = static_cast((0.2126 * (*pt_input)) + (0.7152 * (*(pt_input + 1))) + (0.0722 * (*(pt_input + 2)))); - pt_input += 4; + *pt_output = static_cast((0.2126 * (*pt_input)) + (0.7152 * (*(pt_input + 1))) + (0.0722 * (*(pt_input + val_2)))); + pt_input += val_4; ++pt_output; } #endif @@ -560,6 +566,9 @@ void vpImageConvert::GreyToRGBa(unsigned char *grey, unsigned char *rgba, unsign #if defined(VISP_HAVE_SIMDLIB) GreyToRGBa(grey, rgba, size, 1); #else + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; + const unsigned int val_4 = 4; unsigned char *pt_input = grey; unsigned char *pt_end = grey + size; unsigned char *pt_output = rgba; @@ -568,11 +577,11 @@ void vpImageConvert::GreyToRGBa(unsigned char *grey, unsigned char *rgba, unsign unsigned char p = *pt_input; *pt_output = p; // R *(pt_output + 1) = p; // G - *(pt_output + 2) = p; // B - *(pt_output + 3) = vpRGBa::alpha_default; // A + *(pt_output + val_2) = p; // B + *(pt_output + val_3) = vpRGBa::alpha_default; // A ++pt_input; - pt_output += 4; + pt_output += val_4; } #endif } @@ -592,6 +601,8 @@ void vpImageConvert::GreyToRGB(unsigned char *grey, unsigned char *rgb, unsigned #if defined(VISP_HAVE_SIMDLIB) SimdGrayToBgr(grey, size, 1, size, rgb, size * 3); #else + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; unsigned char *pt_input = grey; unsigned char *pt_end = grey + size; unsigned char *pt_output = rgb; @@ -600,10 +611,10 @@ void vpImageConvert::GreyToRGB(unsigned char *grey, unsigned char *rgb, unsigned unsigned char p = *pt_input; *pt_output = p; // R *(pt_output + 1) = p; // G - *(pt_output + 2) = p; // B + *(pt_output + val_2) = p; // B ++pt_input; - pt_output += 3; + pt_output += val_3; } #endif } @@ -634,6 +645,8 @@ void vpImageConvert::BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned #endif // if we have to flip the image, we start from the end last scanline so the // step is negative + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; int lineStep = flip ? -static_cast(width * 3) : static_cast(width * 3); // starting source address = last line if we need to flip the image @@ -642,12 +655,12 @@ void vpImageConvert::BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned for (unsigned int i = 0; i < height; ++i) { unsigned char *line = src; for (unsigned int j = 0; j < width; ++j) { - *rgba++ = *(line + 2); + *rgba++ = *(line + val_2); *rgba++ = *(line + 1); *rgba++ = *(line + 0); *rgba++ = vpRGBa::alpha_default; - line += 3; + line += val_3; } // go to the next line src += lineStep; @@ -682,20 +695,23 @@ void vpImageConvert::BGRaToRGBa(unsigned char *bgra, unsigned char *rgba, unsign #endif // if we have to flip the image, we start from the end last scanline so the // step is negative + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; + const unsigned int val_4 = 4; int lineStep = flip ? -static_cast(width * 4) : static_cast(width * 4); // starting source address = last line if we need to flip the image - unsigned char *src = flip ? (bgra + (width * height * 4) + lineStep) : bgra; + unsigned char *src = flip ? (bgra + (width * height * val_4) + lineStep) : bgra; for (unsigned int i = 0; i < height; ++i) { unsigned char *line = src; for (unsigned int j = 0; j < width; ++j) { - *rgba++ = *(line + 2); + *rgba++ = *(line + val_2); *rgba++ = *(line + 1); *rgba++ = *(line + 0); - *rgba++ = *(line + 3); + *rgba++ = *(line + val_3); - line += 4; + line += val_4; } // go to the next line src += lineStep; @@ -744,6 +760,8 @@ void vpImageConvert::BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned #endif // if we have to flip the image, we start from the end last scanline so // the step is negative + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; int lineStep = flip ? -static_cast(width * 3) : static_cast(width * 3); // starting source address = last line if we need to flip the image @@ -752,8 +770,8 @@ void vpImageConvert::BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned for (unsigned int i = 0; i < height; ++i) { unsigned char *line = src; for (unsigned int j = 0; j < width; ++j) { - *grey++ = static_cast((0.2126 * *(line + 2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0))); - line += 3; + *grey++ = static_cast((0.2126 * *(line + val_2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0))); + line += val_3; } // go to the next line @@ -806,6 +824,8 @@ void vpImageConvert::BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsign #endif // if we have to flip the image, we start from the end last scanline so // the step is negative + const unsigned int val_2 = 2; + const unsigned int val_4 = 4; int lineStep = flip ? -static_cast(width * 4) : static_cast(width * 4); // starting source address = last line if we need to flip the image @@ -814,8 +834,8 @@ void vpImageConvert::BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsign for (unsigned int i = 0; i < height; ++i) { unsigned char *line = src; for (unsigned int j = 0; j < width; ++j) { - *grey++ = static_cast((0.2126 * *(line + 2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0))); - line += 4; + *grey++ = static_cast((0.2126 * *(line + val_2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0))); + line += val_4; } // go to the next line @@ -835,15 +855,16 @@ void vpImageConvert::BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsign void vpImageConvert::computeYCbCrLUT() { if (YCbCrLUTcomputed == false) { + const int val_256 = 256; int index = 256; while (index--) { int aux = index - 128; - vpImageConvert::vpCrr[index] = static_cast((364.6610 * aux) / 256); - vpImageConvert::vpCgb[index] = static_cast((-89.8779 * aux) / 256); - vpImageConvert::vpCgr[index] = static_cast((-185.8154 * aux) / 256); - vpImageConvert::vpCbb[index] = static_cast((460.5724 * aux) / 256); + vpImageConvert::vpCrr[index] = static_cast((364.6610 * aux) / val_256); + vpImageConvert::vpCgb[index] = static_cast((-89.8779 * aux) / val_256); + vpImageConvert::vpCgr[index] = static_cast((-185.8154 * aux) / val_256); + vpImageConvert::vpCbb[index] = static_cast((460.5724 * aux) / val_256); } YCbCrLUTcomputed = true; @@ -873,12 +894,16 @@ void vpImageConvert::computeYCbCrLUT() */ void vpImageConvert::YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb, unsigned int size) { + const unsigned val_2 = 2; + const unsigned val_3 = 3; + const int val_255 = 255; + const unsigned int val_255u = 255u; unsigned char *cbv; unsigned char *crv; unsigned char *pt_ycbcr = ycbcr; unsigned char *pt_rgb = rgb; cbv = pt_ycbcr + 1; - crv = pt_ycbcr + 3; + crv = pt_ycbcr + val_3; vpImageConvert::computeYCbCrLUT(); @@ -886,20 +911,20 @@ void vpImageConvert::YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb, unsign while (size--) { int val_r, val_g, val_b; - if (!(col % 2)) { + if (!(col % val_2)) { cbv = pt_ycbcr + 1; - crv = pt_ycbcr + 3; + crv = pt_ycbcr + val_3; } val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv]; val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv]; val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv]; - *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : static_cast(val_r)); // Red component. - *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : static_cast(val_g)); // Green component. - *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : static_cast(val_b)); // Blue component. + *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > val_255) ? val_255u : static_cast(val_r)); // Red component. + *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > val_255) ? val_255u : static_cast(val_g)); // Green component. + *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > val_255) ? val_255u : static_cast(val_b)); // Blue component. - pt_ycbcr += 2; + pt_ycbcr += val_2; ++col; } } @@ -931,12 +956,16 @@ void vpImageConvert::YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb, unsign */ void vpImageConvert::YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgba, unsigned int size) { + const unsigned val_2 = 2; + const unsigned val_3 = 3; + const int val_255 = 255; + const unsigned int val_255u = 255u; unsigned char *cbv; unsigned char *crv; unsigned char *pt_ycbcr = ycbcr; unsigned char *pt_rgba = rgba; cbv = pt_ycbcr + 1; - crv = pt_ycbcr + 3; + crv = pt_ycbcr + val_3; vpImageConvert::computeYCbCrLUT(); @@ -944,21 +973,21 @@ void vpImageConvert::YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgba, unsi while (size--) { int val_r, val_g, val_b; - if (!(col % 2)) { + if (!(col % val_2)) { cbv = pt_ycbcr + 1; - crv = pt_ycbcr + 3; + crv = pt_ycbcr + val_3; } val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv]; val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv]; val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv]; - *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : static_cast(val_r)); // Red component. - *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : static_cast(val_g)); // Green component. - *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : static_cast(val_b)); // Blue component. + *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > val_255) ? val_255u : static_cast(val_r)); // Red component. + *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > val_255) ? val_255u : static_cast(val_g)); // Green component. + *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > val_255) ? val_255u : static_cast(val_b)); // Blue component. *pt_rgba++ = vpRGBa::alpha_default; - pt_ycbcr += 2; + pt_ycbcr += val_2; ++col; } } @@ -984,12 +1013,14 @@ void vpImageConvert::YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgba, unsi */ void vpImageConvert::YCbCrToGrey(unsigned char *ycbcr, unsigned char *grey, unsigned int size) { + const unsigned val_2 = 2; + const unsigned val_4 = 4; unsigned int i = 0, j = 0; const unsigned int doubleSize = size * 2; while (j < doubleSize) { grey[i++] = ycbcr[j]; - grey[i++] = ycbcr[j + 2]; - j += 4; + grey[i++] = ycbcr[j + val_2]; + j += val_4; } } @@ -1016,12 +1047,16 @@ void vpImageConvert::YCbCrToGrey(unsigned char *ycbcr, unsigned char *grey, unsi */ void vpImageConvert::YCrCbToRGB(unsigned char *ycrcb, unsigned char *rgb, unsigned int size) { + const unsigned val_2 = 2; + const unsigned val_3 = 3; + const int val_255 = 255; + const unsigned int val_255u = 255u; unsigned char *cbv; unsigned char *crv; unsigned char *pt_ycbcr = ycrcb; unsigned char *pt_rgb = rgb; crv = pt_ycbcr + 1; - cbv = pt_ycbcr + 3; + cbv = pt_ycbcr + val_3; vpImageConvert::computeYCbCrLUT(); @@ -1029,20 +1064,20 @@ void vpImageConvert::YCrCbToRGB(unsigned char *ycrcb, unsigned char *rgb, unsign while (size--) { int val_r, val_g, val_b; - if (!(col % 2)) { + if (!(col % val_2)) { crv = pt_ycbcr + 1; - cbv = pt_ycbcr + 3; + cbv = pt_ycbcr + val_3; } val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv]; val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv]; val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv]; - *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : static_cast(val_r)); // Red component. - *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : static_cast(val_g)); // Green component. - *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : static_cast(val_b)); // Blue component. + *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > val_255) ? val_255u : static_cast(val_r)); // Red component. + *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > val_255) ? val_255u : static_cast(val_g)); // Green component. + *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > val_255) ? val_255u : static_cast(val_b)); // Blue component. - pt_ycbcr += 2; + pt_ycbcr += val_2; ++col; } } @@ -1073,12 +1108,16 @@ void vpImageConvert::YCrCbToRGB(unsigned char *ycrcb, unsigned char *rgb, unsign */ void vpImageConvert::YCrCbToRGBa(unsigned char *ycrcb, unsigned char *rgba, unsigned int size) { + const unsigned val_2 = 2; + const unsigned val_3 = 3; + const int val_255 = 255; + const unsigned int val_255u = 255u; unsigned char *cbv; unsigned char *crv; unsigned char *pt_ycbcr = ycrcb; unsigned char *pt_rgba = rgba; crv = pt_ycbcr + 1; - cbv = pt_ycbcr + 3; + cbv = pt_ycbcr + val_3; vpImageConvert::computeYCbCrLUT(); @@ -1086,21 +1125,21 @@ void vpImageConvert::YCrCbToRGBa(unsigned char *ycrcb, unsigned char *rgba, unsi while (size--) { int val_r, val_g, val_b; - if (!(col % 2)) { + if (!(col % val_2)) { crv = pt_ycbcr + 1; - cbv = pt_ycbcr + 3; + cbv = pt_ycbcr + val_3; } val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv]; val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv]; val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv]; - *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : static_cast(val_r)); // Red component. - *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : static_cast(val_g)); // Green component. - *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : static_cast(val_b)); // Blue component. + *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > val_255) ? val_255u : static_cast(val_r)); // Red component. + *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > val_255) ? val_255u : static_cast(val_g)); // Green component. + *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > val_255) ? val_255u : static_cast(val_b)); // Blue component. *pt_rgba++ = vpRGBa::alpha_default; - pt_ycbcr += 2; + pt_ycbcr += val_2; ++col; } } @@ -1206,6 +1245,7 @@ void vpImageConvert::split(const vpImage &src, vpImage *p tabChannel[index_3] = pa; size_t i; /* ordre */ + const unsigned int val_3 = 3; const unsigned int val_4 = 4; for (unsigned int j = 0; j < val_4; ++j) { if (tabChannel[j] != nullptr) { @@ -1217,28 +1257,28 @@ void vpImageConvert::split(const vpImage &src, vpImage *p input = (unsigned char *)src.bitmap + j; i = 0; // optimization - if (n >= 4) { - n -= 3; - for (; i < n; i += 4) { + if (n >= val_4) { + n -= val_3; + for (; i < n; i += val_4) { *dst = *input; - input += 4; + input += val_4; ++dst; *dst = *input; - input += 4; + input += val_4; ++dst; *dst = *input; - input += 4; + input += val_4; ++dst; *dst = *input; - input += 4; + input += val_4; ++dst; } - n += 3; + n += val_3; } for (; i < n; ++i) { *dst = *input; - input += 4; + input += val_4; ++dst; } } @@ -1334,12 +1374,13 @@ void vpImageConvert::merge(const vpImage *R, const vpImage(size) * 2) - 1; int j = static_cast(size) - 1; while (i >= 0) { int y = grey16[i--]; - grey[j--] = static_cast((y + (grey16[i] * 256)) / 256); + grey[j--] = static_cast((y + (grey16[i] * val_256)) / val_256); --i; } } diff --git a/modules/core/src/image/vpImageConvert_hsv.cpp b/modules/core/src/image/vpImageConvert_hsv.cpp index 88888f5856..fd08d11ce4 100644 --- a/modules/core/src/image/vpImageConvert_hsv.cpp +++ b/modules/core/src/image/vpImageConvert_hsv.cpp @@ -84,6 +84,9 @@ BEGIN_VISP_NAMESPACE double q = v * (1.0 - (s * f)); double t = v * (1.0 - (s * (1.0 - f))); + const int val_2 = 2; + const int val_3 = 3; + const int val_4 = 4; switch (static_cast(h)) { case 0: hue = v; @@ -97,19 +100,19 @@ BEGIN_VISP_NAMESPACE value = p; break; - case 2: + case val_2: hue = p; saturation = v; value = t; break; - case 3: + case val_3: hue = p; saturation = q; value = v; break; - case 4: + case val_4: hue = t; saturation = p; value = v; @@ -127,7 +130,9 @@ BEGIN_VISP_NAMESPACE rgb[i_step] = static_cast(vpMath::round(hue * 255.0)); rgb[++i_step] = static_cast(vpMath::round(saturation * 255.0)); rgb[++i_step] = static_cast(vpMath::round(value * 255.0)); - if ((++i_step) == 3) { // alpha + const int val_3 = 3; + if (i_step == val_3) { // alpha + ++i_step; rgb[i_step] = vpRGBa::alpha_default; } } @@ -148,6 +153,9 @@ BEGIN_VISP_NAMESPACE void vpImageConvert::HSV2RGB(const unsigned char *hue_, const unsigned char *saturation_, const unsigned char *value_, unsigned char *rgb, unsigned int size, unsigned int step, bool h_full) { + const int val_2 = 2; + const int val_3 = 3; + const int val_4 = 4; float h_max; if (h_full) { h_max = 255.f; @@ -194,19 +202,19 @@ void vpImageConvert::HSV2RGB(const unsigned char *hue_, const unsigned char *sat value = p; break; - case 2: + case val_2: hue = p; saturation = v; value = t; break; - case 3: + case val_3: hue = p; saturation = q; value = v; break; - case 4: + case val_4: hue = t; saturation = p; value = v; @@ -224,7 +232,8 @@ void vpImageConvert::HSV2RGB(const unsigned char *hue_, const unsigned char *sat rgb[i_step] = static_cast(hue * 255.f); rgb[++i_step] = static_cast(saturation * 255.0f); rgb[++i_step] = static_cast(value * 255.0f); - if ((++i_step) == 3) { // alpha + if (i_step == val_3) { // alpha + ++i_step; rgb[i_step] = vpRGBa::alpha_default; } } @@ -257,8 +266,10 @@ void vpImageConvert::RGB2HSV(const unsigned char *rgb, double *hue, double *satu int i_ = i * step; red = rgb[i_] / 255.0; - green = rgb[++i_] / 255.0; - blue = rgb[++i_] / 255.0; + ++i_; + green = rgb[i_] / 255.0; + ++i_; + blue = rgb[i_] / 255.0; if (red > green) { max = std::max(red, blue); @@ -288,10 +299,10 @@ void vpImageConvert::RGB2HSV(const unsigned char *rgb, double *hue, double *satu h = (green - blue) / delta; } else if (vpMath::equal(green, max, std::numeric_limits::epsilon())) { - h = 2 + ((blue - red) / delta); + h = 2.0 + ((blue - red) / delta); } else { - h = 4 + ((red - green) / delta); + h = 4.0 + ((red - green) / delta); } h /= 6.0; @@ -418,7 +429,8 @@ void vpImageConvert::RGB2HSV(const unsigned char *rgb, unsigned char *hue, unsig void vpImageConvert::HSVToRGBa(const double *hue, const double *saturation, const double *value, unsigned char *rgba, unsigned int size) { - vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, 4); + const unsigned int val_4 = 4; + vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, val_4); } /*! @@ -438,7 +450,8 @@ void vpImageConvert::HSVToRGBa(const double *hue, const double *saturation, cons void vpImageConvert::HSVToRGBa(const unsigned char *hue, const unsigned char *saturation, const unsigned char *value, unsigned char *rgba, unsigned int size, bool h_full) { - vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, 4, h_full); + const unsigned int val_4 = 4; + vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, val_4, h_full); } /*! @@ -457,7 +470,8 @@ void vpImageConvert::HSVToRGBa(const unsigned char *hue, const unsigned char *sa void vpImageConvert::RGBaToHSV(const unsigned char *rgba, double *hue, double *saturation, double *value, unsigned int size) { - vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, 4); + const unsigned int val_4 = 4; + vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, val_4); } /*! @@ -479,7 +493,8 @@ void vpImageConvert::RGBaToHSV(const unsigned char *rgba, double *hue, double *s void vpImageConvert::RGBaToHSV(const unsigned char *rgba, unsigned char *hue, unsigned char *saturation, unsigned char *value, unsigned int size, bool h_full) { - vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, 4, h_full); + const unsigned int val_4 = 4; + vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, val_4, h_full); } /*! @@ -498,7 +513,8 @@ void vpImageConvert::RGBaToHSV(const unsigned char *rgba, unsigned char *hue, un void vpImageConvert::HSVToRGB(const double *hue, const double *saturation, const double *value, unsigned char *rgb, unsigned int size) { - vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, 3); + const unsigned int val_3 = 3; + vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, val_3); } /*! @@ -518,7 +534,8 @@ void vpImageConvert::HSVToRGB(const double *hue, const double *saturation, const void vpImageConvert::HSVToRGB(const unsigned char *hue, const unsigned char *saturation, const unsigned char *value, unsigned char *rgb, unsigned int size, bool h_full) { - vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, 3, h_full); + const unsigned int val_3 = 3; + vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, val_3, h_full); } /*! @@ -536,7 +553,8 @@ void vpImageConvert::HSVToRGB(const unsigned char *hue, const unsigned char *sat void vpImageConvert::RGBToHSV(const unsigned char *rgb, double *hue, double *saturation, double *value, unsigned int size) { - vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, 3); + const unsigned int val_3 = 3; + vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, val_3); } /*! @@ -557,6 +575,7 @@ void vpImageConvert::RGBToHSV(const unsigned char *rgb, double *hue, double *sat void vpImageConvert::RGBToHSV(const unsigned char *rgb, unsigned char *hue, unsigned char *saturation, unsigned char *value, unsigned int size, bool h_full) { - vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, 3, h_full); + const unsigned int val_3 = 3; + vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, val_3, h_full); } END_VISP_NAMESPACE diff --git a/modules/core/src/image/vpImageConvert_yuv.cpp b/modules/core/src/image/vpImageConvert_yuv.cpp index 6005982cb1..1b10f06a6d 100644 --- a/modules/core/src/image/vpImageConvert_yuv.cpp +++ b/modules/core/src/image/vpImageConvert_yuv.cpp @@ -206,12 +206,14 @@ void vpImageConvert::YUYVToRGB(unsigned char *yuyv, unsigned char *rgb, unsigned */ void vpImageConvert::YUYVToGrey(unsigned char *yuyv, unsigned char *grey, unsigned int size) { + const unsigned int val_2 = 2; + const unsigned int val_4 = 4; unsigned int i = 0, j = 0; const unsigned int doubleSize = size * 2; while (j < doubleSize) { grey[i++] = yuyv[j]; - grey[i++] = yuyv[j + 2]; - j += 4; + grey[i++] = yuyv[j + val_2]; + j += val_4; } } @@ -382,16 +384,20 @@ void vpImageConvert::YUV411ToGrey(unsigned char *yuv, unsigned char *grey, unsig { unsigned int i = 0, j = 0; const unsigned int val_2 = 2; - const unsigned int iterLimit = (size * 3) / val_2; + const unsigned int val_3 = 3; + const unsigned int val_4 = 4; + const unsigned int val_5 = 5; + const unsigned int val_6 = 6; + const unsigned int iterLimit = (size * val_3) / val_2; while (j < iterLimit) { grey[i] = yuv[j + 1]; - grey[i + 1] = yuv[j + 2]; - grey[i + 2] = yuv[j + 4]; - grey[i + 3] = yuv[j + 5]; + grey[i + 1] = yuv[j + val_2]; + grey[i + val_2] = yuv[j + val_4]; + grey[i + val_3] = yuv[j + val_5]; - i += 4; + i += val_4; - j += 6; + j += val_6; } } @@ -464,13 +470,15 @@ void vpImageConvert::YUV422ToRGB(unsigned char *yuv, unsigned char *rgb, unsigne */ void vpImageConvert::YUV422ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size) { + const unsigned int val_3 = 3; + const unsigned int val_4 = 4; unsigned int i = 0, j = 0; const unsigned int doubleSize = size * 2; while (j < doubleSize) { grey[i++] = yuv[j + 1]; - grey[i++] = yuv[j + 3]; - j += 4; + grey[i++] = yuv[j + val_3]; + j += val_4; } } @@ -775,7 +783,7 @@ void vpImageConvert::YUV420ToRGB(unsigned char *yuv, unsigned char *rgb, unsigne rgb = (rgb - (val_3 * width)) + 1; } yuv += width; - rgb += 3 * width; + rgb += val_3 * width; } } @@ -886,10 +894,11 @@ void vpImageConvert::YUV444ToRGB(unsigned char *yuv, unsigned char *rgb, unsigne */ void vpImageConvert::YUV444ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size) { + const unsigned int val_3 = 3; ++yuv; for (unsigned int i = 0; i < size; ++i) { *grey++ = *yuv; - yuv = yuv + 3; + yuv = yuv + val_3; } } @@ -920,10 +929,10 @@ void vpImageConvert::YV12ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigne for (unsigned int j = 0; j < halfWidth; ++j) { U = static_cast(((*iU) - val_128) * 0.354); ++iU; - U5 = 5 * U; + U5 = val_5 * U; V = static_cast(((*iV) - val_128) * 0.707); ++iV; - V2 = 2 * V; + V2 = val_2 * V; UV = -U - V; Y0 = *yuv; ++yuv; @@ -1073,7 +1082,7 @@ void vpImageConvert::YV12ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned *rgb++ = static_cast(R); *rgb++ = static_cast(G); *rgb = static_cast(B); - rgb = rgb + ((val_3 * width) - 5); + rgb = rgb + ((val_3 * width) - val_5); //--- R = Y2 + V2; @@ -1344,6 +1353,7 @@ void vpImageConvert::YVU9ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned const unsigned int val_4 = 4; const unsigned int val_5 = 5; const unsigned int val_9 = 9; + const unsigned int val_11 = 11; const unsigned int val_16 = 16; const unsigned int val_17 = 17; unsigned int size = width * height; @@ -1419,7 +1429,7 @@ void vpImageConvert::YVU9ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned G = Y3 + UV; B = Y3 + U5; YVU9ToRGBsubroutine(rgb, R, G, B); - rgb = rgb + ((val_3 * width) - 11); + rgb = rgb + ((val_3 * width) - val_11); R = Y4 + V2; G = Y4 + UV; @@ -1443,7 +1453,7 @@ void vpImageConvert::YVU9ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned G = Y7 + UV; B = Y7 + U5; YVU9ToRGBsubroutine(rgb, R, G, B); - rgb = rgb + ((val_3 * width) - 11); + rgb = rgb + ((val_3 * width) - val_11); R = Y8 + V2; G = Y8 + UV; @@ -1467,7 +1477,7 @@ void vpImageConvert::YVU9ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned G = Y11 + UV; B = Y11 + U5; YVU9ToRGBsubroutine(rgb, R, G, B); - rgb = (rgb + (val_3 * width)) - 11; + rgb = (rgb + (val_3 * width)) - val_11; R = Y12 + V2; G = Y12 + UV; diff --git a/modules/core/src/image/vpImageFilter_xy.cpp b/modules/core/src/image/vpImageFilter_xy.cpp index fd1f946a07..0da41ffc1d 100644 --- a/modules/core/src/image/vpImageFilter_xy.cpp +++ b/modules/core/src/image/vpImageFilter_xy.cpp @@ -123,6 +123,7 @@ double vpImageFilter::filterXLeftBorderB(const vpImage &I, unsigned int double vpImageFilter::filterXRightBorderR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int stop = (size - 1) / 2; const unsigned int width = I.getWidth(); double result = 0.; @@ -132,7 +133,7 @@ double vpImageFilter::filterXRightBorderR(const vpImage &I, unsigned int result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); } else { - result += filter[i] * static_cast(I[r][((2 * width) - c) - i - 1].R + I[r][c - i].R); + result += filter[i] * static_cast(I[r][((val_2 * width) - c) - i - 1].R + I[r][c - i].R); } } return result + (filter[0] * static_cast(I[r][c].R)); @@ -141,6 +142,7 @@ double vpImageFilter::filterXRightBorderR(const vpImage &I, unsigned int double vpImageFilter::filterXRightBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int stop = (size - 1) / 2; const unsigned int width = I.getWidth(); double result = 0.; @@ -150,7 +152,7 @@ double vpImageFilter::filterXRightBorderG(const vpImage &I, unsigned int result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); } else { - result += filter[i] * static_cast(I[r][((2 * width) - c) - i - 1].G + I[r][c - i].G); + result += filter[i] * static_cast(I[r][((val_2 * width) - c) - i - 1].G + I[r][c - i].G); } } return result + (filter[0] * static_cast(I[r][c].G)); @@ -159,6 +161,7 @@ double vpImageFilter::filterXRightBorderG(const vpImage &I, unsigned int double vpImageFilter::filterXRightBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int stop = (size - 1) / 2; const unsigned int width = I.getWidth(); double result = 0.; @@ -168,7 +171,7 @@ double vpImageFilter::filterXRightBorderB(const vpImage &I, unsigned int result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); } else { - result += filter[i] * static_cast(I[r][(2 * width) - c - i - 1].B + I[r][c - i].B); + result += filter[i] * static_cast(I[r][(val_2 * width) - c - i - 1].B + I[r][c - i].B); } } return result + (filter[0] * static_cast(I[r][c].B)); @@ -258,6 +261,7 @@ double vpImageFilter::filterYTopBorderB(const vpImage &I, unsigned int r double vpImageFilter::filterYBottomBorderR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int height = I.getHeight(); const unsigned int stop = (size - 1) / 2; double result = 0.; @@ -267,7 +271,7 @@ double vpImageFilter::filterYBottomBorderR(const vpImage &I, unsigned in result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); } else { - result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].R + I[r - i][c].R); + result += filter[i] * static_cast(I[((val_2 * height) - r) - i - 1][c].R + I[r - i][c].R); } } return result + (filter[0] * static_cast(I[r][c].R)); @@ -276,6 +280,7 @@ double vpImageFilter::filterYBottomBorderR(const vpImage &I, unsigned in double vpImageFilter::filterYBottomBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int height = I.getHeight(); const unsigned int stop = (size - 1) / 2; double result = 0.; @@ -285,7 +290,7 @@ double vpImageFilter::filterYBottomBorderG(const vpImage &I, unsigned in result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); } else { - result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].G + I[r - i][c].G); + result += filter[i] * static_cast(I[((val_2 * height) - r) - i - 1][c].G + I[r - i][c].G); } } return result + (filter[0] * static_cast(I[r][c].G)); @@ -294,6 +299,7 @@ double vpImageFilter::filterYBottomBorderG(const vpImage &I, unsigned in double vpImageFilter::filterYBottomBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int height = I.getHeight(); const unsigned int stop = (size - 1) / 2; double result = 0.; @@ -303,7 +309,7 @@ double vpImageFilter::filterYBottomBorderB(const vpImage &I, unsigned in result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); } else { - result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].B + I[r - i][c].B); + result += filter[i] * static_cast(I[((val_2 * height) - r) - i - 1][c].B + I[r - i][c].B); } } return result + (filter[0] * static_cast(I[r][c].B)); diff --git a/modules/core/src/image/vpImageTools.cpp b/modules/core/src/image/vpImageTools.cpp index ad9886cc0f..8056c746cd 100644 --- a/modules/core/src/image/vpImageTools.cpp +++ b/modules/core/src/image/vpImageTools.cpp @@ -157,9 +157,11 @@ void vpImageTools::imageDifference(const vpImage &I1, const vpIma #if defined(VISP_HAVE_SIMDLIB) SimdImageDifference(I1.bitmap, I2.bitmap, I1.getSize(), Idiff.bitmap); #else - for (unsigned int i = 0; i < I1.getSize(); ++i) { + const int val_255 = 255; + unsigned int i1_size = I1.getSize(); + for (unsigned int i = 0; i < i1_size; ++i) { int diff = (I1.bitmap[i] - I2.bitmap[i]) + 128; - Idiff.bitmap[i] = static_cast(std::max(std::min(diff, 255), 0)); + Idiff.bitmap[i] = static_cast(std::max(std::min(diff, val_255), 0)); } #endif } @@ -194,16 +196,18 @@ void vpImageTools::imageDifference(const vpImage &I1, const vpImage(I1.bitmap), reinterpret_cast(I2.bitmap), I1.getSize() * 4, reinterpret_cast(Idiff.bitmap)); #else + const unsigned int val_4 = 4; + const int val_255 = 255; unsigned int i1_size = I1.getSize(); - for (unsigned int i = 0; i < (i1_size * 4); ++i) { + for (unsigned int i = 0; i < (i1_size * val_4); ++i) { int diffR = (I1.bitmap[i].R - I2.bitmap[i].R) + 128; int diffG = (I1.bitmap[i].G - I2.bitmap[i].G) + 128; int diffB = (I1.bitmap[i].B - I2.bitmap[i].B) + 128; int diffA = (I1.bitmap[i].A - I2.bitmap[i].A) + 128; - Idiff.bitmap[i].R = static_cast(vpMath::maximum(vpMath::minimum(diffR, 255), 0)); - Idiff.bitmap[i].G = static_cast(vpMath::maximum(vpMath::minimum(diffG, 255), 0)); - Idiff.bitmap[i].B = static_cast(vpMath::maximum(vpMath::minimum(diffB, 255), 0)); - Idiff.bitmap[i].A = static_cast(vpMath::maximum(vpMath::minimum(diffA, 255), 0)); + Idiff.bitmap[i].R = static_cast(vpMath::maximum(vpMath::minimum(diffR, val_255), 0)); + Idiff.bitmap[i].G = static_cast(vpMath::maximum(vpMath::minimum(diffG, val_255), 0)); + Idiff.bitmap[i].B = static_cast(vpMath::maximum(vpMath::minimum(diffB, val_255), 0)); + Idiff.bitmap[i].A = static_cast(vpMath::maximum(vpMath::minimum(diffA, val_255), 0)); } #endif } @@ -1128,11 +1132,12 @@ int vpImageTools::inMask(const vpImage &I, const vpImage(hsv_range[index_0]); unsigned char h_high = static_cast(hsv_range[index_1]); unsigned char s_low = static_cast(hsv_range[index_2]); @@ -1158,7 +1164,7 @@ int vpImageTools::inRange(const unsigned char *hue, const unsigned char *saturat bool check_s_low_high_saturation = (s_low <= saturation[i]) && (saturation[i] <= s_high); bool check_v_low_high_value = (v_low <= value[i]) && (value[i] <= v_high); if (check_h_low_high_hue && check_s_low_high_saturation && check_v_low_high_value) { - mask[i] = 255; + mask[i] = val_uchar_255; ++cpt_in_range; } else { @@ -1188,11 +1194,12 @@ int vpImageTools::inRange(const unsigned char *hue, const unsigned char *saturat int vpImageTools::inRange(const unsigned char *hue, const unsigned char *saturation, const unsigned char *value, const std::vector &hsv_range, unsigned char *mask, unsigned int size) { + const std::size_t val_6 = 6; if ((hue == nullptr) || (saturation == nullptr) || (value == nullptr)) { throw(vpImageException(vpImageException::notInitializedError, "Error in vpImageTools::inRange(): hsv pointer are empty")); } - else if (hsv_range.size() != 6) { + else if (hsv_range.size() != val_6) { throw(vpImageException(vpImageException::notInitializedError, "Error in vpImageTools::inRange(): wrong values vector size (%d)", hsv_range.size())); } @@ -1213,12 +1220,13 @@ int vpImageTools::inRange(const unsigned char *hue, const unsigned char *saturat #if defined(_OPENMP) #pragma omp parallel for reduction(+:cpt_in_range) #endif + const unsigned char val_uc_255 = 255; for (int i = 0; i < size_; ++i) { bool check_h_low_high_hue = (h_low <= hue[i]) && (hue[i] <= h_high); bool check_s_low_high_saturation = (s_low <= saturation[i]) && (saturation[i] <= s_high); bool check_v_low_high_value = (v_low <= value[i]) && (value[i] <= v_high); if (check_h_low_high_hue && check_s_low_high_saturation && check_v_low_high_value) { - mask[i] = 255; + mask[i] = val_uc_255; ++cpt_in_range; } else { diff --git a/modules/core/src/image/vpRGBa.cpp b/modules/core/src/image/vpRGBa.cpp index 1a894a2de3..5a106ff9c0 100644 --- a/modules/core/src/image/vpRGBa.cpp +++ b/modules/core/src/image/vpRGBa.cpp @@ -123,7 +123,8 @@ vpRGBa &vpRGBa::operator=(const vpRGBa &&v) */ vpRGBa &vpRGBa::operator=(const vpColVector &v) { - if (v.getRows() != 4) { + const unsigned int val_4 = 4; + if (v.getRows() != val_4) { throw(vpException(vpException::dimensionError, "Bad vector dimension ")); } const unsigned int index_0 = 0; diff --git a/modules/core/src/math/matrix/vpColVector.cpp b/modules/core/src/math/matrix/vpColVector.cpp index 0894d3e798..9321b18dda 100644 --- a/modules/core/src/math/matrix/vpColVector.cpp +++ b/modules/core/src/math/matrix/vpColVector.cpp @@ -73,13 +73,13 @@ vpColVector vpColVector::operator+(const vpColVector &v) const vpTranslationVector vpColVector::operator+(const vpTranslationVector &t) const { - if (getRows() != 3) { + const unsigned int val_3 = 3; + if (getRows() != val_3) { throw(vpException(vpException::dimensionError, "Cannot add %d-dimension column vector to a translation vector", getRows())); } vpTranslationVector s; - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { s[i] = (*this)[i] + t[i]; } @@ -285,7 +285,9 @@ vpColVector vpColVector::operator-() const for (unsigned int i = 0; i < rowNum; ++i) { // move the d++ increment/decrement into a dedicated expression-statement - *(vd++) = -(*d++); + *vd = -(*d); + ++vd; + ++d; } return A; @@ -300,7 +302,9 @@ vpColVector vpColVector::operator*(double x) const for (unsigned int i = 0; i < rowNum; ++i) { // move the d++ increment/decrement into a dedicated expression-statement - *(vd++) = (*d++) * x; + *vd = (*d) * x; + ++vd; + ++d; } return v; } @@ -330,7 +334,9 @@ vpColVector vpColVector::operator/(double x) const for (unsigned int i = 0; i < rowNum; ++i) { // move the d++ increment/decrement into a dedicated expression-statement - *(vd++) = (*d++) / x; + *vd = (*d) / x; + ++vd; + ++d; } return v; } @@ -557,7 +563,9 @@ double vpColVector::dotProd(const vpColVector &a, const vpColVector &b) unsigned int a_rows_nbr = a.getRows(); for (unsigned int i = 0; i < a_rows_nbr; ++i) { // Move the ad++ and bd++ increment/decrement into a dedicated expression-statement - c += *(ad++) * *(bd++); + c += (*ad) * (*bd); + ++ad; + ++bd; } return c; @@ -713,7 +721,8 @@ double vpColVector::stdev(const vpColVector &v, bool useBesselCorrection) #else double mean_value = v.sum() / v.size(); double sum_squared_diff = 0.0; - for (size_t i = 0; i < v.size(); i++) { + unsigned int v_size = v.size(); + for (size_t i = 0; i < v_size; ++i) { sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value); } @@ -735,7 +744,7 @@ vpMatrix vpColVector::skew(const vpColVector &v) v.getRows())); } - M.resize(3, 3, false, false); + M.resize(rows_size, rows_size, false, false); const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; @@ -754,7 +763,8 @@ vpMatrix vpColVector::skew(const vpColVector &v) vpColVector vpColVector::crossProd(const vpColVector &a, const vpColVector &b) { - if ((a.getRows() != 3) || (b.getRows() != 3)) { + const unsigned int val_3 = 3; + if ((a.getRows() != val_3) || (b.getRows() != val_3)) { throw(vpException(vpException::dimensionError, "Cannot compute the cross product between column " "vector with dimension %d and %d", diff --git a/modules/core/src/math/matrix/vpEigenConversion.cpp b/modules/core/src/math/matrix/vpEigenConversion.cpp index 2aed2b6a62..bf04754142 100644 --- a/modules/core/src/math/matrix/vpEigenConversion.cpp +++ b/modules/core/src/math/matrix/vpEigenConversion.cpp @@ -46,7 +46,8 @@ void eigen2visp(const Eigen::MatrixXd &src, vpMatrix &dst) void eigen2visp(const Eigen::MatrixXd &src, vpHomogeneousMatrix &dst) { - if ((src.rows() != 4) || (src.cols() != 4)) { + const Eigen::Index index_4 = 4; + if ((src.rows() != index_4) || (src.cols() != index_4)) { throw vpException(vpException::dimensionError, "Input Eigen Matrix must be of size (4,4)!"); } diff --git a/modules/core/src/math/matrix/vpMatrix.cpp b/modules/core/src/math/matrix/vpMatrix.cpp index 5111e52303..87893fa09e 100644 --- a/modules/core/src/math/matrix/vpMatrix.cpp +++ b/modules/core/src/math/matrix/vpMatrix.cpp @@ -1253,10 +1253,8 @@ vpColVector vpMatrix::eigenValues() const } #endif #else - { throw(vpException(vpException::functionNotImplementedError, "Eigen values computation is not implemented. " "You should install Lapack 3rd party")); - } #endif return evalue; } @@ -1388,10 +1386,8 @@ void vpMatrix::eigenValues(vpColVector &evalue, vpMatrix &evector) const } #endif // defined(VISP_HAVE_GSL) #else - { throw(vpException(vpException::functionNotImplementedError, "Eigen values computation is not implemented. " "You should install Lapack 3rd party")); - } #endif } @@ -1729,7 +1725,7 @@ vpMatrix vpMatrix::expm() const v_expE = (c * exp) + v_eye; v_expD = (-c * exp) + v_eye; for (int k = 2; k <= q; ++k) { - c = (c * (static_cast((q - k) + 1))) / (static_cast(k * (((2 * q) - k) + 1))); + c = (c * (static_cast((q - k) + 1))) / (static_cast(k * (((2.0 * q) - k) + 1))); v_expcX = exp * v_expX; v_expX = v_expcX; v_expcX = c * v_expX; diff --git a/modules/core/src/math/matrix/vpMatrix_covariance.cpp b/modules/core/src/math/matrix/vpMatrix_covariance.cpp index 942d143f34..85cc9e6925 100644 --- a/modules/core/src/math/matrix/vpMatrix_covariance.cpp +++ b/modules/core/src/math/matrix/vpMatrix_covariance.cpp @@ -213,15 +213,16 @@ void vpMatrix::computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const ctoInitSkew = ctoInitSkew * LthetauInvAnalytic; + const unsigned int index_3 = 3; for (unsigned int a = 0; a < val_3; ++a) { for (unsigned int b = 0; b < val_3; ++b) { - LpInv[a][b + 3] = ctoInitSkew[a][b]; + LpInv[a][b + index_3] = ctoInitSkew[a][b]; } } for (unsigned int a = 0; a < val_3; ++a) { for (unsigned int b = 0; b < val_3; ++b) { - LpInv[a + 3][b + 3] = LthetauInvAnalytic[a][b]; + LpInv[a + index_3][b + index_3] = LthetauInvAnalytic[a][b]; } } diff --git a/modules/core/src/math/matrix/vpMatrix_lu.cpp b/modules/core/src/math/matrix/vpMatrix_lu.cpp index 5b6e8d67f8..52620bcd51 100644 --- a/modules/core/src/math/matrix/vpMatrix_lu.cpp +++ b/modules/core/src/math/matrix/vpMatrix_lu.cpp @@ -129,6 +129,8 @@ BEGIN_VISP_NAMESPACE */ vpMatrix vpMatrix::inverseByLU() const { + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; if ((colNum == 1) && (rowNum == 1)) { vpMatrix inv; inv.resize(1, 1, false); @@ -140,9 +142,9 @@ vpMatrix vpMatrix::inverseByLU() const inv[0][0] = 1. / d; return inv; } - else if ((colNum == 2) && (rowNum == 2)) { + else if ((colNum == val_2) && (rowNum == val_2)) { vpMatrix inv; - inv.resize(2, 2, false); + inv.resize(val_2, val_2, false); double d = det(); if (std::fabs(d) < std::numeric_limits::epsilon()) { throw(vpException(vpException::fatalError, "Cannot inverse matrix %d by %d by LU. Matrix determinant is 0.", @@ -155,9 +157,9 @@ vpMatrix vpMatrix::inverseByLU() const inv[1][0] = -(*this)[1][0] * d; return inv; } - else if ((colNum == 3) && (rowNum == 3)) { + else if ((colNum == val_3) && (rowNum == val_3)) { vpMatrix inv; - inv.resize(3, 3, false); + inv.resize(val_3, val_3, false); double d = det(); if (std::fabs(d) < std::numeric_limits::epsilon()) { throw(vpException(vpException::fatalError, "Cannot inverse matrix %d by %d by LU. Matrix determinant is 0.", @@ -233,13 +235,15 @@ vpMatrix vpMatrix::inverseByLU() const */ double vpMatrix::detByLU() const { + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; if ((rowNum == 1) && (colNum == 1)) { return (*this)[0][0]; } - else if ((rowNum == 2) && (colNum == 2)) { + else if ((rowNum == val_2) && (colNum == val_2)) { return (((*this)[0][0] * (*this)[1][1]) - ((*this)[0][1] * (*this)[1][0])); } - else if ((rowNum == 3) && (colNum == 3)) { + else if ((rowNum == val_3) && (colNum == val_3)) { const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; diff --git a/modules/core/src/math/matrix/vpMatrix_operations.cpp b/modules/core/src/math/matrix/vpMatrix_operations.cpp index 8d9f029e00..45e57ebb10 100644 --- a/modules/core/src/math/matrix/vpMatrix_operations.cpp +++ b/modules/core/src/math/matrix/vpMatrix_operations.cpp @@ -66,7 +66,8 @@ void vpMatrix::transpose(vpMatrix &At) const { At.resize(colNum, rowNum, false, false); - if ((rowNum <= 16) || (colNum <= 16)) { + const unsigned int val_16 = 16; + if ((rowNum <= val_16) || (colNum <= val_16)) { for (unsigned int i = 0; i < rowNum; ++i) { for (unsigned int j = 0; j < colNum; ++j) { At[j][i] = (*this)[i][j]; @@ -209,7 +210,8 @@ void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) */ void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C) { - if ((A.colNum != 3) || (A.rowNum != 3) || (B.colNum != 3) || (B.rowNum != 3)) { + const unsigned int val_3 = 3; + if ((A.colNum != val_3) || (A.rowNum != val_3) || (B.colNum != val_3) || (B.rowNum != val_3)) { throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a " "rotation matrix", @@ -246,7 +248,8 @@ void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMat */ void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C) { - if ((A.colNum != 4) || (A.rowNum != 4) || (B.colNum != 4) || (B.rowNum != 4)) { + const unsigned int val_4 = 4; + if ((A.colNum != val_4) || (A.rowNum != val_4) || (B.colNum != val_4) || (B.rowNum != val_4)) { throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a " "rotation matrix", @@ -560,7 +563,9 @@ void vpMatrix::AAt(vpMatrix &B) const // sum (row i .* row j) double ssum = 0; for (unsigned int k = 0; k < colNum; ++k) { - ssum += *(pi++) * *(pj++); + ssum += (*pi) * (*pj); + ++pi; + ++pj; } B[i][j] = ssum; // upper triangle @@ -841,7 +846,8 @@ void vpMatrix::kron(const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out) unsigned int coffset = c * c2; for (unsigned int rr = 0; rr < r2; ++rr) { for (unsigned int cc = 0; cc < c2; ++cc) { - out[roffset + rr][coffset + cc] = alpha * *(m2ptr++); + out[roffset + rr][coffset + cc] = alpha * (*m2ptr); + ++m2ptr; } } } @@ -880,7 +886,8 @@ vpMatrix vpMatrix::kron(const vpMatrix &m1, const vpMatrix &m2) unsigned int coffset = c * c2; for (unsigned int rr = 0; rr < r2; ++rr) { for (unsigned int cc = 0; cc < c2; ++cc) { - out[roffset + rr][coffset + cc] = alpha * *(m2ptr++); + out[roffset + rr][coffset + cc] = alpha * (*m2ptr); + ++m2ptr; } } } diff --git a/modules/core/src/math/matrix/vpMatrix_operators.cpp b/modules/core/src/math/matrix/vpMatrix_operators.cpp index cbb4559f67..2137c2c6c9 100644 --- a/modules/core/src/math/matrix/vpMatrix_operators.cpp +++ b/modules/core/src/math/matrix/vpMatrix_operators.cpp @@ -397,12 +397,12 @@ vpTranslationVector vpMatrix::operator*(const vpTranslationVector &tv) const { vpTranslationVector t_out; - if ((rowNum != 3) || (colNum != 3)) { + const unsigned int val_3 = 3; + if ((rowNum != val_3) || (colNum != val_3)) { throw(vpException(vpException::dimensionError, "Cannot multiply a (%dx%d) matrix by a (%dx%d) translation vector", rowNum, colNum, tv.getRows(), tv.getCols())); } - const unsigned int val_3 = 3; for (unsigned int j = 0; j < val_3; ++j) { t_out[j] = 0; } @@ -451,7 +451,8 @@ vpMatrix vpMatrix::operator*(const vpRotationMatrix &R) const colNum)); } vpMatrix C; - C.resize(rowNum, 3, false, false); + const unsigned int val_3 = 3; + C.resize(rowNum, val_3, false, false); unsigned int RcolNum = R.getCols(); unsigned int RrowNum = R.getRows(); @@ -481,7 +482,8 @@ vpMatrix vpMatrix::operator*(const vpHomogeneousMatrix &M) const colNum)); } vpMatrix C; - C.resize(rowNum, 4, false, false); + const unsigned int val_4 = 4; + C.resize(rowNum, val_4, false, false); const unsigned int McolNum = M.getCols(); const unsigned int MrowNum = M.getRows(); @@ -512,7 +514,8 @@ vpMatrix vpMatrix::operator*(const vpVelocityTwistMatrix &V) const rowNum, colNum)); } vpMatrix M; - M.resize(rowNum, 6, false, false); + const unsigned int val_6 = 6; + M.resize(rowNum, val_6, false, false); // Considering perfMatrixMultiplication.cpp benchmark, // using either MKL, OpenBLAS, or Netlib can slow down this function with respect to the naive code. @@ -568,7 +571,8 @@ vpMatrix vpMatrix::operator*(const vpForceTwistMatrix &V) const rowNum, colNum)); } vpMatrix M; - M.resize(rowNum, 6, false, false); + const unsigned int val_6 = 6; + M.resize(rowNum, val_6, false, false); // Considering perfMatrixMultiplication.cpp benchmark, // using either MKL, OpenBLAS, or Netlib can slow down this function with respect to the naive code. diff --git a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp index d6eee1f0f2..c91e7e7869 100644 --- a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp +++ b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp @@ -1031,7 +1031,7 @@ vpMatrix vpMatrix::dampedInverse(const double &ratioOfMaxSvd) const vpMatrix I; I.eye(this->colNum); double lambda = ratioOfMaxSvd * maxSingularValue; - vpMatrix dampedInv = (lambda * I + this->transpose() * *this).inverseByLU()* this->transpose(); + vpMatrix dampedInv = ((lambda * I) + (this->transpose() * (*this))).inverseByLU()* this->transpose(); return dampedInv; } diff --git a/modules/core/src/math/matrix/vpRowVector.cpp b/modules/core/src/math/matrix/vpRowVector.cpp index ef1d0bcb67..bbbb9dd4dd 100644 --- a/modules/core/src/math/matrix/vpRowVector.cpp +++ b/modules/core/src/math/matrix/vpRowVector.cpp @@ -292,7 +292,8 @@ vpRowVector vpRowVector::operator*(double x) const double *d = data; for (unsigned int i = 0; i < colNum; ++i) { - *(vd++) = (*d++) * x; + *(vd++) = (*d) * x; + ++d; } return v; } @@ -349,7 +350,8 @@ vpRowVector vpRowVector::operator/(double x) const double *d = data; for (unsigned int i = 0; i < colNum; ++i) { - *(vd++) = (*d++) / x; + *(vd++) = (*d) / x; + ++d; } return v; } @@ -398,7 +400,8 @@ vpRowVector vpRowVector::operator-() const double *d = data; for (unsigned int i = 0; i < colNum; ++i) { - *(vd++) = -(*d++); + *(vd++) = -(*d); + ++d; } return A; diff --git a/modules/core/src/math/misc/vpMath.cpp b/modules/core/src/math/misc/vpMath.cpp index 4b08463903..eaabc82615 100644 --- a/modules/core/src/math/misc/vpMath.cpp +++ b/modules/core/src/math/misc/vpMath.cpp @@ -324,7 +324,7 @@ double vpMath::getMedian(const std::vector &v) if (v.empty()) { throw vpException(vpException::notInitialized, "Empty vector !"); } - + const size_t val_2 = 2; std::vector v_copy = v; size_t size = v_copy.size(); @@ -332,7 +332,7 @@ double vpMath::getMedian(const std::vector &v) std::nth_element(v_copy.begin(), v_copy.begin() + n, v_copy.end()); double val_n = v_copy[n]; - if ((size % 2) == 1) { + if ((size % val_2) == 1) { return val_n; } else { @@ -389,7 +389,8 @@ double vpMath::getStdev(const std::vector &v, bool useBesselCorrection) */ double vpMath::lineFitting(const std::vector &imPts, double &a, double &b, double &c) { - if (imPts.size() < 3) { + const unsigned int val_3 = 3; + if (imPts.size() < val_3) { throw vpException(vpException::dimensionError, "Number of image points must be greater or equal to 3."); } @@ -723,7 +724,8 @@ vpHomogeneousMatrix vpMath::lookAt(const vpColVector &from, const vpColVector &t */ vpColVector vpMath::deg(const vpRotationVector &r) { - if (r.size() == 4) { + const unsigned int val_4 = 4; + if (r.size() == val_4) { throw(vpException(vpException::fatalError, "Cannot convert angles of a quaternion vector in degrees!")); } vpColVector r_deg(r.size()); diff --git a/modules/core/src/math/random-generator/vpGaussRand.cpp b/modules/core/src/math/random-generator/vpGaussRand.cpp index 255947965d..429df6c03f 100644 --- a/modules/core/src/math/random-generator/vpGaussRand.cpp +++ b/modules/core/src/math/random-generator/vpGaussRand.cpp @@ -52,14 +52,15 @@ double vpGaussRand::gaussianDraw() } else { + const int val_2 = 2; double v1 = 0, v2 = 0, rsq = 0; do { - v1 = 2 * m_rng.uniform(0.0, 1.0) - 1; - v2 = 2 * m_rng.uniform(0.0, 1.0) - 1; - rsq = v1 * v1 + v2 * v2; + v1 = (val_2 * m_rng.uniform(0.0, 1.0)) - 1; + v2 = (val_2 * m_rng.uniform(0.0, 1.0)) - 1; + rsq = (v1 * v1) + (v2 * v2); } while (rsq >= 1); - double fac = sqrt(-2 * log(rsq) / rsq); + double fac = sqrt((-2 * log(rsq)) / rsq); m_x2 = v2 * fac; m_AlreadyDone = true; return v1 * fac; diff --git a/modules/core/src/math/random-generator/vpUniRand.cpp b/modules/core/src/math/random-generator/vpUniRand.cpp index b6829b8c3a..5098f6bd71 100644 --- a/modules/core/src/math/random-generator/vpUniRand.cpp +++ b/modules/core/src/math/random-generator/vpUniRand.cpp @@ -29,8 +29,8 @@ * * Description: * Pseudo random number generator. - * -*****************************************************************************/ + */ + /* * PCG Random Number Generation for C. * @@ -100,8 +100,8 @@ double vpUniRand::operator()() { return uniform(0.0, 1.0); } \note Some programmers may think that they can just run rng.next() % bound, - but doing so introduces nonuniformity when bound is not a power of two. - The code for boundedRand() avoids the nonuniformity by dropping a portion + but doing so introduces non uniformity when bound is not a power of two. + The code for boundedRand() avoids the non uniformity by dropping a portion of the RNG's output. */ @@ -144,11 +144,13 @@ uint32_t vpUniRand::boundedRand(uint32_t bound) */ uint32_t vpUniRand::next() { + const unsigned long long val_ll = 6364136223846793005ULL; + const uint32_t val_31 = 31; uint64_t oldstate = m_rng.state; - m_rng.state = (oldstate * 6364136223846793005ULL) + m_rng.inc; + m_rng.state = (oldstate * val_ll) + m_rng.inc; uint32_t xorshifted = static_cast(((oldstate >> 18u) ^ oldstate) >> 27u); uint32_t rot = oldstate >> 59u; - return (xorshifted >> rot) | (xorshifted << (static_cast((-static_cast(rot)) & 31))); + return (xorshifted >> rot) | (xorshifted << (static_cast((-static_cast(rot)) & val_31))); } /*! diff --git a/modules/core/src/math/transformation/vpExponentialMap.cpp b/modules/core/src/math/transformation/vpExponentialMap.cpp index 15c6506654..91e86b0e18 100644 --- a/modules/core/src/math/transformation/vpExponentialMap.cpp +++ b/modules/core/src/math/transformation/vpExponentialMap.cpp @@ -169,11 +169,12 @@ vpColVector vpExponentialMap::inverse(const vpHomogeneousMatrix &M, const double const unsigned int index_1 = 1; const unsigned int index_2 = 2; const unsigned int index_3 = 3; + const unsigned int val_3 = 3; M.extract(Rd); u.buildFrom(Rd); - for (i = 0; i < 3; ++i) { - v[3 + i] = u[i]; + for (i = 0; i < val_3; ++i) { + v[index_3 + i] = u[i]; } theta = sqrt((u[index_0] * u[index_0]) + (u[index_1] * u[index_1]) + (u[index_2] * u[index_2])); diff --git a/modules/core/src/math/transformation/vpForceTwistMatrix.cpp b/modules/core/src/math/transformation/vpForceTwistMatrix.cpp index e3e54d9802..fc05636c84 100644 --- a/modules/core/src/math/transformation/vpForceTwistMatrix.cpp +++ b/modules/core/src/math/transformation/vpForceTwistMatrix.cpp @@ -30,8 +30,7 @@ * Description: * Twist transformation matrix that allows to transform forces from one * frame to an other. - * -*****************************************************************************/ + **/ /*! \file vpForceTwistMatrix.cpp @@ -49,6 +48,8 @@ BEGIN_VISP_NAMESPACE +const unsigned int vpForceTwistMatrix::constr_value_6 = 6; + /*! Copy operator. @@ -56,8 +57,9 @@ BEGIN_VISP_NAMESPACE */ vpForceTwistMatrix &vpForceTwistMatrix::operator=(const vpForceTwistMatrix &M) { - for (int i = 0; i < 6; ++i) { - for (int j = 0; j < 6; ++j) { + const int val_6 = 6; + for (int i = 0; i < val_6; ++i) { + for (int j = 0; j < val_6; ++j) { rowPtrs[i][j] = M.rowPtrs[i][j]; } } @@ -86,7 +88,7 @@ void vpForceTwistMatrix::eye() /*! Initialize a force/torque twist transformation matrix to identity. */ -vpForceTwistMatrix::vpForceTwistMatrix() : vpArray2D(6, 6) { eye(); } +vpForceTwistMatrix::vpForceTwistMatrix() : vpArray2D(constr_value_6, constr_value_6) { eye(); } /*! @@ -95,7 +97,7 @@ vpForceTwistMatrix::vpForceTwistMatrix() : vpArray2D(6, 6) { eye(); } \param F : Force/torque twist matrix used as initializer. */ -vpForceTwistMatrix::vpForceTwistMatrix(const vpForceTwistMatrix &F) : vpArray2D(6, 6) { *this = F; } +vpForceTwistMatrix::vpForceTwistMatrix(const vpForceTwistMatrix &F) : vpArray2D(constr_value_6, constr_value_6) { *this = F; } /*! @@ -126,7 +128,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpForceTwistMatrix &F) : vpArray2D< \f] */ -vpForceTwistMatrix::vpForceTwistMatrix(const vpHomogeneousMatrix &M, bool full) : vpArray2D(6, 6) +vpForceTwistMatrix::vpForceTwistMatrix(const vpHomogeneousMatrix &M, bool full) : vpArray2D(constr_value_6, constr_value_6) { if (full) { buildFrom(M); @@ -156,7 +158,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpHomogeneousMatrix &M, bool full) */ vpForceTwistMatrix::vpForceTwistMatrix(const vpTranslationVector &t, const vpThetaUVector &thetau) - : vpArray2D(6, 6) + : vpArray2D(constr_value_6, constr_value_6) { buildFrom(t, thetau); } @@ -178,7 +180,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpTranslationVector &t, const vpThe \param thetau : \f$\theta u\f$ rotation vector used to initialize \f$R\f$. */ -vpForceTwistMatrix::vpForceTwistMatrix(const vpThetaUVector &thetau) : vpArray2D(6, 6) { buildFrom(thetau); } +vpForceTwistMatrix::vpForceTwistMatrix(const vpThetaUVector &thetau) : vpArray2D(constr_value_6, constr_value_6) { buildFrom(thetau); } /*! @@ -200,7 +202,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpThetaUVector &thetau) : vpArray2D */ vpForceTwistMatrix::vpForceTwistMatrix(const vpTranslationVector &t, const vpRotationMatrix &R) - : vpArray2D(6, 6) + : vpArray2D(constr_value_6, constr_value_6) { buildFrom(t, R); } @@ -222,7 +224,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpTranslationVector &t, const vpRot \param R : Rotation matrix. */ -vpForceTwistMatrix::vpForceTwistMatrix(const vpRotationMatrix &R) : vpArray2D(6, 6) { buildFrom(R); } +vpForceTwistMatrix::vpForceTwistMatrix(const vpRotationMatrix &R) : vpArray2D(constr_value_6, constr_value_6) { buildFrom(R); } /*! @@ -245,7 +247,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpRotationMatrix &R) : vpArray2D(6, 6) + : vpArray2D(constr_value_6, constr_value_6) { vpTranslationVector T(tx, ty, tz); vpThetaUVector tu(tux, tuy, tuz); @@ -368,10 +370,11 @@ vpMatrix vpForceTwistMatrix::operator*(const vpMatrix &M) const */ vpColVector vpForceTwistMatrix::operator*(const vpColVector &H) const { + const unsigned int val_6 = 6; const unsigned int nparam = 6; vpColVector Hout(nparam); - if (6 != H.getRows()) { + if (val_6 != H.getRows()) { throw(vpException(vpException::dimensionError, "Cannot multiply a (6x6) force/torque twist matrix by " "a %d dimension column vector", @@ -412,11 +415,12 @@ vpForceTwistMatrix &vpForceTwistMatrix::buildFrom(const vpTranslationVector &t, vpMatrix skewaR = t.skew(t) * R; const unsigned int val_3 = 3; + const unsigned int index_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { for (unsigned int j = 0; j < val_3; ++j) { (*this)[i][j] = R[i][j]; - (*this)[i + 3][j + 3] = R[i][j]; - (*this)[i + 3][j] = skewaR[i][j]; + (*this)[i + index_3][j + index_3] = R[i][j]; + (*this)[i + index_3][j] = skewaR[i][j]; } } return *this; @@ -440,12 +444,13 @@ vpForceTwistMatrix &vpForceTwistMatrix::buildFrom(const vpTranslationVector &t, */ vpForceTwistMatrix &vpForceTwistMatrix::buildFrom(const vpRotationMatrix &R) { + const unsigned int index_3 = 3; const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { for (unsigned int j = 0; j < val_3; ++j) { (*this)[i][j] = R[i][j]; - (*this)[i + 3][j + 3] = R[i][j]; - (*this)[i + 3][j] = 0; + (*this)[i + index_3][j + index_3] = R[i][j]; + (*this)[i + index_3][j] = 0; } } return *this; diff --git a/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp b/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp index e0d071229a..289a730f98 100644 --- a/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp +++ b/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp @@ -44,27 +44,29 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpHomogeneousMatrix::constr_value_4 = 4; /*! Construct an homogeneous matrix from a translation vector and quaternion rotation vector. */ - vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpQuaternionVector &q) - : vpArray2D(4, 4) +vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpQuaternionVector &q) + : vpArray2D(constr_value_4, constr_value_4) { + const unsigned int index_3 = 3; buildFrom(t, q); - (*this)[3][3] = 1.; + (*this)[index_3][index_3] = 1.; } /*! Default constructor that initialize an homogeneous matrix as identity. */ -vpHomogeneousMatrix::vpHomogeneousMatrix() : vpArray2D(4, 4), m_index(0) { eye(); } +vpHomogeneousMatrix::vpHomogeneousMatrix() : vpArray2D(constr_value_4, constr_value_4), m_index(0) { eye(); } /*! Copy constructor that initialize an homogeneous matrix from another homogeneous matrix. */ -vpHomogeneousMatrix::vpHomogeneousMatrix(const vpHomogeneousMatrix &M) : vpArray2D(4, 4), m_index(0) +vpHomogeneousMatrix::vpHomogeneousMatrix(const vpHomogeneousMatrix &M) : vpArray2D(constr_value_4, constr_value_4), m_index(0) { *this = M; } @@ -74,10 +76,11 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const vpHomogeneousMatrix &M) : vpArray u}\f$ rotation vector. */ vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpThetaUVector &tu) - : vpArray2D(4, 4), m_index(0) + : vpArray2D(constr_value_4, constr_value_4), m_index(0) { + const unsigned int index_3 = 3; buildFrom(t, tu); - (*this)[3][3] = 1.; + (*this)[index_3][index_3] = 1.; } /*! @@ -85,7 +88,7 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpT matrix. */ vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpRotationMatrix &R) - : vpArray2D(4, 4), m_index(0) + : vpArray2D(constr_value_4, constr_value_4), m_index(0) { const unsigned int index_3 = 3; insert(R); @@ -96,7 +99,7 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpR /*! Construct an homogeneous matrix from a pose vector. */ -vpHomogeneousMatrix::vpHomogeneousMatrix(const vpPoseVector &p) : vpArray2D(4, 4), m_index(0) +vpHomogeneousMatrix::vpHomogeneousMatrix(const vpPoseVector &p) : vpArray2D(constr_value_4, constr_value_4), m_index(0) { const unsigned int index_0 = 0; const unsigned int index_1 = 1; @@ -151,10 +154,11 @@ v: 0 -1 0 0.3 1 0 0 0.4 0 0 -1 0.5 0 0 0 1 \endcode */ -vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector &v) : vpArray2D(4, 4), m_index(0) +vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector &v) : vpArray2D(constr_value_4, constr_value_4), m_index(0) { + const unsigned int index_3 = 3; buildFrom(v); - (*this)[3][3] = 1.; + (*this)[index_3][index_3] = 1.; } #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) @@ -308,10 +312,11 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const std::initializer_list &li 0 0 0 1 \endcode */ -vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector &v) : vpArray2D(4, 4), m_index(0) +vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector &v) : vpArray2D(constr_value_4, constr_value_4), m_index(0) { + const unsigned int index_3 = 3; buildFrom(v); - (*this)[3][3] = 1.; + (*this)[index_3][index_3] = 1.; } /*! @@ -320,10 +325,11 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector &v) : vpArray u_z)^T\f$ rotation vector. */ vpHomogeneousMatrix::vpHomogeneousMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz) - : vpArray2D(4, 4), m_index(0) + : vpArray2D(constr_value_4, constr_value_4), m_index(0) { + const unsigned int index_3 = 3; buildFrom(tx, ty, tz, tux, tuy, tuz); - (*this)[3][3] = 1.; + (*this)[index_3][index_3] = 1.; } /*! @@ -439,11 +445,14 @@ vpHomogeneousMatrix &vpHomogeneousMatrix::buildFrom(const double &tx, const doub */ vpHomogeneousMatrix &vpHomogeneousMatrix::buildFrom(const std::vector &v) { - if ((v.size() != 12) && (v.size() != 16)) { + const std::size_t val_12 = 12; + const std::size_t val_16 = 16; + const unsigned int val_12ui = 12; + if ((v.size() != val_12) && (v.size() != val_16)) { throw(vpException(vpException::dimensionError, "Cannot convert std::vector to vpHomogeneousMatrix")); } - for (unsigned int i = 0; i < 12; ++i) { + for (unsigned int i = 0; i < val_12ui; ++i) { this->data[i] = static_cast(v[i]); } return *this; @@ -495,11 +504,14 @@ vpHomogeneousMatrix &vpHomogeneousMatrix::buildFrom(const std::vector &v) */ vpHomogeneousMatrix &vpHomogeneousMatrix::buildFrom(const std::vector &v) { - if ((v.size() != 12) && (v.size() != 16)) { + const std::size_t val_12 = 12; + const std::size_t val_16 = 16; + const unsigned int val_12ui = 12; + if ((v.size() != val_12) && (v.size() != val_16)) { throw(vpException(vpException::dimensionError, "Cannot convert std::vector to vpHomogeneousMatrix")); } - for (unsigned int i = 0; i < 12; ++i) { + for (unsigned int i = 0; i < val_12ui; ++i) { this->data[i] = v[i]; } return *this; @@ -512,8 +524,9 @@ vpHomogeneousMatrix &vpHomogeneousMatrix::buildFrom(const std::vector &v */ vpHomogeneousMatrix &vpHomogeneousMatrix::operator=(const vpHomogeneousMatrix &M) { - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) { + const int val_4 = 4; + for (int i = 0; i < val_4; ++i) { + for (int j = 0; j < val_4; ++j) { rowPtrs[i][j] = M.rowPtrs[i][j]; } } @@ -652,7 +665,7 @@ vpPoint vpHomogeneousMatrix::operator*(const vpPoint &bP) const v1[index_2] = ((*this)[index_2][0] * v[0]) + ((*this)[index_2][1] * v[1]) + ((*this)[index_2][index_2] * v[index_2]) + ((*this)[index_2][index_3] * v[index_3]); v1[index_3] = ((*this)[index_3][0] * v[0]) + ((*this)[index_3][1] * v[1]) + ((*this)[index_3][index_2] * v[index_2]) + ((*this)[index_3][index_3] * v[index_3]); - v1 /= v1[3]; + v1 /= v1[index_3]; // --comment: v1 equals M multiplied by v aP.set_X(v1[index_0]); @@ -1114,8 +1127,10 @@ void vpHomogeneousMatrix::print() const */ void vpHomogeneousMatrix::convert(std::vector &M) { - M.resize(12); - for (unsigned int i = 0; i < 12; ++i) { + const std::size_t val_12 = 12; + const unsigned int val_12ui = 12; + M.resize(val_12); + for (unsigned int i = 0; i < val_12ui; ++i) { M[i] = static_cast(this->data[i]); } } @@ -1126,8 +1141,10 @@ void vpHomogeneousMatrix::convert(std::vector &M) */ void vpHomogeneousMatrix::convert(std::vector &M) { - M.resize(12); - for (unsigned int i = 0; i < 12; ++i) { + const std::size_t val_12 = 12; + const unsigned int val_12ui = 12; + M.resize(val_12); + for (unsigned int i = 0; i < val_12ui; ++i) { M[i] = this->data[i]; } } @@ -1287,8 +1304,8 @@ vpHomogeneousMatrix vpHomogeneousMatrix::mean(const std::vector(R); + meanT += static_cast(vec_M[i].getTranslationVector()); } meanR /= static_cast(vec_M.size()); meanT /= static_cast(vec_M.size()); diff --git a/modules/core/src/math/transformation/vpPoseVector.cpp b/modules/core/src/math/transformation/vpPoseVector.cpp index c64a207e0d..fbbf9aeb94 100644 --- a/modules/core/src/math/transformation/vpPoseVector.cpp +++ b/modules/core/src/math/transformation/vpPoseVector.cpp @@ -30,8 +30,7 @@ * Description: * Pose object. A pose is a size 6 vector [t, tu]^T where tu is * a rotation vector (theta u representation) and t is a translation vector. - * -*****************************************************************************/ + */ /*! \file vpPoseVector.cpp @@ -49,6 +48,7 @@ BEGIN_VISP_NAMESPACE +const unsigned int vpPoseVector::constr_value_6 = 6; /*! Default constructor that construct a 6 dimension pose vector \f$ [\bf t, @@ -59,7 +59,7 @@ BEGIN_VISP_NAMESPACE The pose vector is initialized to zero. */ -vpPoseVector::vpPoseVector() : vpArray2D(6, 1) { } +vpPoseVector::vpPoseVector() : vpArray2D(constr_value_6, 1) { } /*! @@ -77,7 +77,7 @@ vpPoseVector::vpPoseVector() : vpArray2D(6, 1) { } */ vpPoseVector::vpPoseVector(double tx, double ty, double tz, double tux, double tuy, double tuz) - : vpArray2D(6, 1) + : vpArray2D(constr_value_6, 1) { const unsigned int index_0 = 0; const unsigned int index_1 = 1; @@ -104,7 +104,7 @@ vpPoseVector::vpPoseVector(double tx, double ty, double tz, double tux, double t \param tu : \f$\theta \bf u\f$ rotation vector. */ -vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpThetaUVector &tu) : vpArray2D(6, 1) +vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpThetaUVector &tu) : vpArray2D(constr_value_6, 1) { buildFrom(tv, tu); } @@ -121,7 +121,7 @@ vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpThetaUVector & u\f$ vector is extracted to initialise the pose vector. */ -vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpRotationMatrix &R) : vpArray2D(6, 1) +vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpRotationMatrix &R) : vpArray2D(constr_value_6, 1) { buildFrom(tv, R); } @@ -136,7 +136,7 @@ vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpRotationMatrix initialize the pose vector. */ -vpPoseVector::vpPoseVector(const vpHomogeneousMatrix &M) : vpArray2D(6, 1) { buildFrom(M); } +vpPoseVector::vpPoseVector(const vpHomogeneousMatrix &M) : vpArray2D(constr_value_6, 1) { buildFrom(M); } /*! @@ -239,9 +239,10 @@ vpPoseVector &vpPoseVector::buildFrom(const vpHomogeneousMatrix &M) vpPoseVector &vpPoseVector::buildFrom(const vpTranslationVector &tv, const vpThetaUVector &tu) { const unsigned int val_3 = 3; + const unsigned int index_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { (*this)[i] = tv[i]; - (*this)[i + 3] = tu[i]; + (*this)[i + index_3] = tu[i]; } return *this; } @@ -307,7 +308,13 @@ void vpPoseVector::extract(vpQuaternionVector &q) const /*! Extract the rotation as a rotation matrix. */ -void vpPoseVector::extract(vpRotationMatrix &R) const { R.buildFrom((*this)[3], (*this)[4], (*this)[5]); } +void vpPoseVector::extract(vpRotationMatrix &R) const +{ + const unsigned int index_3 = 3; + const unsigned int index_4 = 4; + const unsigned int index_5 = 5; + R.buildFrom((*this)[index_3], (*this)[index_4], (*this)[index_5]); +} /*! Return the translation vector that corresponds to the translation part of the pose vector. diff --git a/modules/core/src/math/transformation/vpQuaternionVector.cpp b/modules/core/src/math/transformation/vpQuaternionVector.cpp index 5586a60059..20fd1717d7 100644 --- a/modules/core/src/math/transformation/vpQuaternionVector.cpp +++ b/modules/core/src/math/transformation/vpQuaternionVector.cpp @@ -41,6 +41,7 @@ BEGIN_VISP_NAMESPACE // minimum value of sine const double vpQuaternionVector::minimum = 0.0001; +const unsigned int vpQuaternionVector::constr_val_4 = 4; /*! \file vpQuaternionVector.cpp @@ -48,29 +49,29 @@ const double vpQuaternionVector::minimum = 0.0001; */ /*! Default constructor that initialize all the 4 angles to zero. */ -vpQuaternionVector::vpQuaternionVector() : vpRotationVector(4) { } +vpQuaternionVector::vpQuaternionVector() : vpRotationVector(constr_val_4) { } /*! Copy constructor. */ vpQuaternionVector::vpQuaternionVector(const vpQuaternionVector &q) : vpRotationVector(q) { } //! Constructor from doubles. -vpQuaternionVector::vpQuaternionVector(double x_, double y_, double z_, double w_) : vpRotationVector(4) +vpQuaternionVector::vpQuaternionVector(double x_, double y_, double z_, double w_) : vpRotationVector(constr_val_4) { set(x_, y_, z_, w_); } //! Constructor from a 4-dimension vector of doubles. -vpQuaternionVector::vpQuaternionVector(const vpColVector &q) : vpRotationVector(4) { buildFrom(q); } +vpQuaternionVector::vpQuaternionVector(const vpColVector &q) : vpRotationVector(constr_val_4) { buildFrom(q); } //! Constructor from a 4-dimension vector of doubles. -vpQuaternionVector::vpQuaternionVector(const std::vector &q) : vpRotationVector(4) { buildFrom(q); } +vpQuaternionVector::vpQuaternionVector(const std::vector &q) : vpRotationVector(constr_val_4) { buildFrom(q); } /*! Constructs a quaternion from a rotation matrix. \param R : Matrix containing a rotation. */ -vpQuaternionVector::vpQuaternionVector(const vpRotationMatrix &R) : vpRotationVector(4) { buildFrom(R); } +vpQuaternionVector::vpQuaternionVector(const vpRotationMatrix &R) : vpRotationVector(constr_val_4) { buildFrom(R); } /*! Constructor that initialize \f$R_{xyz}=(\varphi,\theta,\psi)\f$ Euler @@ -78,7 +79,7 @@ vpQuaternionVector::vpQuaternionVector(const vpRotationMatrix &R) : vpRotationVe \param tu : \f$\theta {\bf u}\f$ representation of a rotation used here as input to initialize the Euler angles. */ -vpQuaternionVector::vpQuaternionVector(const vpThetaUVector &tu) : vpRotationVector(4) { buildFrom(tu); } +vpQuaternionVector::vpQuaternionVector(const vpThetaUVector &tu) : vpRotationVector(constr_val_4) { buildFrom(tu); } /*! Manually change values of a quaternion. @@ -133,11 +134,11 @@ vpQuaternionVector &vpQuaternionVector::buildFrom(const vpThetaUVector &tu) */ vpQuaternionVector &vpQuaternionVector::buildFrom(const vpColVector &q) { - if (q.size() != 4) { + const unsigned int val_4 = 4; + if (q.size() != val_4) { throw(vpException(vpException::dimensionError, "Cannot construct a quaternion vector from a %d-dimension col vector", q.size())); } - const unsigned int val_4 = 4; for (unsigned int i = 0; i < val_4; ++i) { data[i] = q[i]; } @@ -150,12 +151,12 @@ vpQuaternionVector &vpQuaternionVector::buildFrom(const vpColVector &q) */ vpQuaternionVector &vpQuaternionVector::buildFrom(const std::vector &q) { - if (q.size() != 4) { + const unsigned int val_4 = 4; + if (q.size() != val_4) { throw(vpException(vpException::dimensionError, "Cannot construct a quaternion vector from a %d-dimension std::vector", q.size())); } - const unsigned int val_4 = 4; for (unsigned int i = 0; i < val_4; ++i) { data[i] = q[i]; } @@ -266,11 +267,11 @@ vpQuaternionVector vpQuaternionVector::operator/(double l) const */ vpQuaternionVector &vpQuaternionVector::operator=(const vpColVector &q) { - if (q.size() != 4) { + const unsigned int val_4 = 4; + if (q.size() != val_4) { throw(vpException(vpException::dimensionError, "Cannot set a quaternion vector from a %d-dimension col vector", q.size())); } - const unsigned int val_4 = 4; for (unsigned int i = 0; i < val_4; ++i) { data[i] = q[i]; } diff --git a/modules/core/src/math/transformation/vpRotationMatrix.cpp b/modules/core/src/math/transformation/vpRotationMatrix.cpp index 8f23a4df38..d7ef975c10 100644 --- a/modules/core/src/math/transformation/vpRotationMatrix.cpp +++ b/modules/core/src/math/transformation/vpRotationMatrix.cpp @@ -50,6 +50,7 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpRotationMatrix::constr_val_3 = 3; /*! Initialize the rotation matrix as identity. @@ -161,12 +162,12 @@ vpRotationMatrix &vpRotationMatrix::operator=(const std::initializer_list(3, 3), m_index(0) { eye(); } +vpRotationMatrix::vpRotationMatrix() : vpArray2D(constr_val_3, constr_val_3), m_index(0) { eye(); } /*! Copy constructor that construct a 3-by-3 rotation matrix from another rotation matrix. */ -vpRotationMatrix::vpRotationMatrix(const vpRotationMatrix &M) : vpArray2D(3, 3), m_index(0) { (*this) = M; } +vpRotationMatrix::vpRotationMatrix(const vpRotationMatrix &M) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { (*this) = M; } /*! Construct a 3-by-3 rotation matrix from an homogeneous matrix. */ -vpRotationMatrix::vpRotationMatrix(const vpHomogeneousMatrix &M) : vpArray2D(3, 3), m_index(0) { buildFrom(M); } +vpRotationMatrix::vpRotationMatrix(const vpHomogeneousMatrix &M) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(M); } /*! Construct a 3-by-3 rotation matrix from \f$ \theta {\bf u}\f$ angle representation. */ -vpRotationMatrix::vpRotationMatrix(const vpThetaUVector &tu) : vpArray2D(3, 3), m_index(0) { buildFrom(tu); } +vpRotationMatrix::vpRotationMatrix(const vpThetaUVector &tu) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(tu); } /*! Construct a 3-by-3 rotation matrix from a pose vector. */ -vpRotationMatrix::vpRotationMatrix(const vpPoseVector &p) : vpArray2D(3, 3), m_index(0) { buildFrom(p); } +vpRotationMatrix::vpRotationMatrix(const vpPoseVector &p) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(p); } /*! Construct a 3-by-3 rotation matrix from \f$ R(z,y,z) \f$ Euler angle representation. */ -vpRotationMatrix::vpRotationMatrix(const vpRzyzVector &euler) : vpArray2D(3, 3), m_index(0) +vpRotationMatrix::vpRotationMatrix(const vpRzyzVector &euler) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(euler); } @@ -542,24 +543,24 @@ vpRotationMatrix::vpRotationMatrix(const vpRzyzVector &euler) : vpArray2D(3, 3), m_index(0) { buildFrom(Rxyz); } +vpRotationMatrix::vpRotationMatrix(const vpRxyzVector &Rxyz) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(Rxyz); } /*! Construct a 3-by-3 rotation matrix from \f$ R(z,y,x) \f$ Euler angle representation. */ -vpRotationMatrix::vpRotationMatrix(const vpRzyxVector &Rzyx) : vpArray2D(3, 3), m_index(0) { buildFrom(Rzyx); } +vpRotationMatrix::vpRotationMatrix(const vpRzyxVector &Rzyx) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(Rzyx); } /*! Construct a 3-by-3 rotation matrix from a matrix that contains values corresponding to a rotation matrix. */ -vpRotationMatrix::vpRotationMatrix(const vpMatrix &R) : vpArray2D(3, 3), m_index(0) { *this = R; } +vpRotationMatrix::vpRotationMatrix(const vpMatrix &R) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { *this = R; } /*! Construct a 3-by-3 rotation matrix from \f$ \theta {\bf u}=(\theta u_x, \theta u_y, \theta u_z)^T\f$ angle representation. */ -vpRotationMatrix::vpRotationMatrix(double tux, double tuy, double tuz) : vpArray2D(3, 3), m_index(0) +vpRotationMatrix::vpRotationMatrix(double tux, double tuy, double tuz) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(tux, tuy, tuz); } @@ -567,7 +568,7 @@ vpRotationMatrix::vpRotationMatrix(double tux, double tuy, double tuz) : vpArray /*! Construct a 3-by-3 rotation matrix from quaternion angle representation. */ -vpRotationMatrix::vpRotationMatrix(const vpQuaternionVector &q) : vpArray2D(3, 3), m_index(0) { buildFrom(q); } +vpRotationMatrix::vpRotationMatrix(const vpQuaternionVector &q) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(q); } #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) /*! @@ -880,15 +881,15 @@ vpRotationMatrix &vpRotationMatrix::buildFrom(const vpQuaternionVector &q) const unsigned int index_1 = 1; const unsigned int index_2 = 2; (*this)[index_0][index_0] = (((a * a) + (b * b)) - (c * c)) - (d * d); - (*this)[index_0][index_1] = (2 * b * c) - (2 * a * d); - (*this)[index_0][index_2] = (2 * a * c) + (2 * b * d); + (*this)[index_0][index_1] = (2.0 * b * c) - (2.0 * a * d); + (*this)[index_0][index_2] = (2.0 * a * c) + (2.0 * b * d); - (*this)[index_1][index_0] = (2 * a * d) + (2 * b * c); + (*this)[index_1][index_0] = (2.0 * a * d) + (2.0 * b * c); (*this)[index_1][index_1] = (((a * a) - (b * b)) + (c * c)) - (d * d); - (*this)[index_1][index_2] = (2 * c * d) - (2 * a * b); + (*this)[index_1][index_2] = (2.0 * c * d) - (2.0 * a * b); - (*this)[index_2][index_0] = (2 * b * d) - (2 * a * c); - (*this)[index_2][index_1] = (2 * a * b) + (2 * c * d); + (*this)[index_2][index_0] = (2.0 * b * d) - (2.0 * a * c); + (*this)[index_2][index_1] = (2.0 * a * b) + (2.0 * c * d); (*this)[index_2][index_2] = ((a * a) - (b * b) - (c * c)) + (d * d); return *this; } @@ -964,7 +965,7 @@ vpRotationMatrix vpRotationMatrix::mean(const std::vector & size_t vec_m_size = vec_M.size(); for (size_t i = 0; i < vec_m_size; ++i) { R = vec_M[i].getRotationMatrix(); - meanR += (vpMatrix)R; + meanR += static_cast(R); } meanR /= static_cast(vec_M.size()); @@ -1006,7 +1007,7 @@ vpRotationMatrix vpRotationMatrix::mean(const std::vector &vec vpRotationMatrix R; size_t vec_r_size = vec_R.size(); for (size_t i = 0; i < vec_r_size; ++i) { - meanR += (vpMatrix)vec_R[i]; + meanR += static_cast(vec_R[i]); } meanR /= static_cast(vec_R.size()); diff --git a/modules/core/src/math/transformation/vpRxyzVector.cpp b/modules/core/src/math/transformation/vpRxyzVector.cpp index ff10108495..41eddfc80d 100644 --- a/modules/core/src/math/transformation/vpRxyzVector.cpp +++ b/modules/core/src/math/transformation/vpRxyzVector.cpp @@ -43,8 +43,9 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpRxyzVector::constr_val_3 = 3; /*! Default constructor that initialize all the 3 angles to zero. */ -vpRxyzVector::vpRxyzVector() : vpRotationVector(3) { } +vpRxyzVector::vpRxyzVector() : vpRotationVector(constr_val_3) { } /*! Copy constructor. */ vpRxyzVector::vpRxyzVector(const vpRxyzVector &rxyz) : vpRotationVector(rxyz) { } @@ -55,14 +56,14 @@ vpRxyzVector::vpRxyzVector(const vpRxyzVector &rxyz) : vpRotationVector(rxyz) { \param theta : \f$\theta\f$ angle around the \f$y\f$ axis. \param psi : \f$\psi\f$ angle around the \f$z\f$ axis. */ -vpRxyzVector::vpRxyzVector(double phi, double theta, double psi) : vpRotationVector(3) { buildFrom(phi, theta, psi); } +vpRxyzVector::vpRxyzVector(double phi, double theta, double psi) : vpRotationVector(constr_val_3) { buildFrom(phi, theta, psi); } /*! Constructor that initialize \f$R_{xyz}=(\varphi,\theta,\psi)\f$ Euler angles from a rotation matrix. \param R : Rotation matrix used to initialize the Euler angles. */ -vpRxyzVector::vpRxyzVector(const vpRotationMatrix &R) : vpRotationVector(3) { buildFrom(R); } +vpRxyzVector::vpRxyzVector(const vpRotationMatrix &R) : vpRotationVector(constr_val_3) { buildFrom(R); } /*! Constructor that initialize \f$R_{xyz}=(\varphi,\theta,\psi)\f$ Euler @@ -70,13 +71,13 @@ vpRxyzVector::vpRxyzVector(const vpRotationMatrix &R) : vpRotationVector(3) { bu \param tu : \f$\theta {\bf u}\f$ representation of a rotation used here as input to initialize the Euler angles. */ -vpRxyzVector::vpRxyzVector(const vpThetaUVector &tu) : vpRotationVector(3) { buildFrom(tu); } +vpRxyzVector::vpRxyzVector(const vpThetaUVector &tu) : vpRotationVector(constr_val_3) { buildFrom(tu); } /*! Copy constructor from a 3-dimension vector. */ -vpRxyzVector::vpRxyzVector(const vpColVector &rxyz) : vpRotationVector(3) { buildFrom(rxyz); } +vpRxyzVector::vpRxyzVector(const vpColVector &rxyz) : vpRotationVector(constr_val_3) { buildFrom(rxyz); } /*! Copy constructor from a 3-dimension vector. */ -vpRxyzVector::vpRxyzVector(const std::vector &rxyz) : vpRotationVector(3) { buildFrom(rxyz); } +vpRxyzVector::vpRxyzVector(const std::vector &rxyz) : vpRotationVector(constr_val_3) { buildFrom(rxyz); } /*! Convert a rotation matrix into a \f$R_{xyz}=(\varphi,\theta,\psi)\f$ Euler @@ -147,11 +148,11 @@ vpRxyzVector &vpRxyzVector::buildFrom(const double &phi, const double &theta, co */ vpRxyzVector &vpRxyzVector::buildFrom(const vpColVector &rxyz) { - if (rxyz.size() != 3) { + const unsigned int val_3 = 3; + if (rxyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-xyz vector from a %d-dimension col vector", rxyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rxyz[i]; } @@ -164,11 +165,11 @@ vpRxyzVector &vpRxyzVector::buildFrom(const vpColVector &rxyz) */ vpRxyzVector &vpRxyzVector::buildFrom(const std::vector &rxyz) { - if (rxyz.size() != 3) { + const unsigned int val_3 = 3; + if (rxyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-xyz vector from a %d-dimension std::vector", rxyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rxyz[i]; } @@ -236,11 +237,11 @@ vpRxyzVector &vpRxyzVector::operator=(double v) */ vpRxyzVector &vpRxyzVector::operator=(const vpColVector &rxyz) { - if (rxyz.size() != 3) { + const unsigned int val_3 = 3; + if (rxyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot set a R-xyz vector from a %d-dimension col vector", rxyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rxyz[i]; } diff --git a/modules/core/src/math/transformation/vpRzyxVector.cpp b/modules/core/src/math/transformation/vpRzyxVector.cpp index 7f5b30ad9f..ea6c5ec817 100644 --- a/modules/core/src/math/transformation/vpRzyxVector.cpp +++ b/modules/core/src/math/transformation/vpRzyxVector.cpp @@ -30,8 +30,7 @@ * Description: * Rzyx angle parameterization for the rotation. * Rzyx(phi,theta,psi) = Rot(z,phi)Rot(y,theta)Rot(x,psi) - * -*****************************************************************************/ + */ /*! \file vpRzyxVector.cpp @@ -44,8 +43,9 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpRzyxVector::constr_val_3 = 3; /*! Default constructor that initialize all the 3 angles to zero. */ -vpRzyxVector::vpRzyxVector() : vpRotationVector(3) { } +vpRzyxVector::vpRzyxVector() : vpRotationVector(constr_val_3) { } /*! Copy constructor. */ vpRzyxVector::vpRzyxVector(const vpRzyxVector &rzyx) : vpRotationVector(rzyx) { } @@ -56,14 +56,14 @@ vpRzyxVector::vpRzyxVector(const vpRzyxVector &rzyx) : vpRotationVector(rzyx) { \param theta : \f$\theta\f$ angle around the \f$y\f$ axis. \param psi : \f$\psi\f$ angle around the \f$x\f$ axis. */ -vpRzyxVector::vpRzyxVector(double phi, double theta, double psi) : vpRotationVector(3) { buildFrom(phi, theta, psi); } +vpRzyxVector::vpRzyxVector(double phi, double theta, double psi) : vpRotationVector(constr_val_3) { buildFrom(phi, theta, psi); } /*! Constructor that initialize \f$R_{zyx}=(\varphi,\theta,\psi)\f$ Euler angles from a rotation matrix. \param R : Rotation matrix used to initialize the Euler angles. */ -vpRzyxVector::vpRzyxVector(const vpRotationMatrix &R) : vpRotationVector(3) { buildFrom(R); } +vpRzyxVector::vpRzyxVector(const vpRotationMatrix &R) : vpRotationVector(constr_val_3) { buildFrom(R); } /*! Constructor that initialize \f$R_{zyx}=(\varphi,\theta,\psi)\f$ Euler @@ -71,13 +71,13 @@ vpRzyxVector::vpRzyxVector(const vpRotationMatrix &R) : vpRotationVector(3) { bu \param tu : \f$\theta {\bf u}\f$ representation of a rotation used here as input to initialize the Euler angles. */ -vpRzyxVector::vpRzyxVector(const vpThetaUVector &tu) : vpRotationVector(3) { buildFrom(tu); } +vpRzyxVector::vpRzyxVector(const vpThetaUVector &tu) : vpRotationVector(constr_val_3) { buildFrom(tu); } /*! Copy constructor from a 3-dimension vector. */ -vpRzyxVector::vpRzyxVector(const vpColVector &rzyx) : vpRotationVector(3) { buildFrom(rzyx); } +vpRzyxVector::vpRzyxVector(const vpColVector &rzyx) : vpRotationVector(constr_val_3) { buildFrom(rzyx); } /*! Copy constructor from a 3-dimension vector. */ -vpRzyxVector::vpRzyxVector(const std::vector &rzyx) : vpRotationVector(3) { buildFrom(rzyx); } +vpRzyxVector::vpRzyxVector(const std::vector &rzyx) : vpRotationVector(constr_val_3) { buildFrom(rzyx); } /*! Convert a rotation matrix into a \f$R_{zyx}=(\varphi,\theta,\psi)\f$ Euler @@ -161,11 +161,11 @@ vpRzyxVector &vpRzyxVector::buildFrom(const double &phi, const double &theta, co */ vpRzyxVector &vpRzyxVector::buildFrom(const vpColVector &rzyx) { - if (rzyx.size() != 3) { + const unsigned int val_3 = 3; + if (rzyx.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension col vector", rzyx.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyx[i]; } @@ -178,11 +178,11 @@ vpRzyxVector &vpRzyxVector::buildFrom(const vpColVector &rzyx) */ vpRzyxVector &vpRzyxVector::buildFrom(const std::vector &rzyx) { - if (rzyx.size() != 3) { + const unsigned int val_3 = 3; + if (rzyx.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension std::vector", rzyx.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyx[i]; } @@ -250,11 +250,11 @@ vpRzyxVector &vpRzyxVector::operator=(double v) */ vpRzyxVector &vpRzyxVector::operator=(const vpColVector &rzyx) { - if (rzyx.size() != 3) { + const unsigned int val_3 = 3; + if (rzyx.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot set a R-zyx vector from a %d-dimension col vector", rzyx.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyx[i]; } diff --git a/modules/core/src/math/transformation/vpRzyzVector.cpp b/modules/core/src/math/transformation/vpRzyzVector.cpp index 72d6cfba7a..2f448a9754 100644 --- a/modules/core/src/math/transformation/vpRzyzVector.cpp +++ b/modules/core/src/math/transformation/vpRzyzVector.cpp @@ -42,8 +42,9 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpRzyzVector::constr_val_3 = 3; /*! Default constructor that initialize all the 3 angles to zero. */ -vpRzyzVector::vpRzyzVector() : vpRotationVector(3) { } +vpRzyzVector::vpRzyzVector() : vpRotationVector(constr_val_3) { } /*! Copy constructor. */ vpRzyzVector::vpRzyzVector(const vpRzyzVector &rzyz) : vpRotationVector(rzyz) { } @@ -53,14 +54,14 @@ vpRzyzVector::vpRzyzVector(const vpRzyzVector &rzyz) : vpRotationVector(rzyz) { \param theta : \f$\theta\f$ angle around the \f$y\f$ axis. \param psi : \f$\psi\f$ angle around the \f$z\f$ axis. */ -vpRzyzVector::vpRzyzVector(double phi, double theta, double psi) : vpRotationVector(3) { buildFrom(phi, theta, psi); } +vpRzyzVector::vpRzyzVector(double phi, double theta, double psi) : vpRotationVector(constr_val_3) { buildFrom(phi, theta, psi); } /*! Constructor that initialize \f$R_{zyz}=(\varphi,\theta,\psi)\f$ Euler angles from a rotation matrix. \param R : Rotation matrix used to initialize the Euler angles. */ -vpRzyzVector::vpRzyzVector(const vpRotationMatrix &R) : vpRotationVector(3) { buildFrom(R); } +vpRzyzVector::vpRzyzVector(const vpRotationMatrix &R) : vpRotationVector(constr_val_3) { buildFrom(R); } /*! Constructor that initialize \f$R_{zyz}=(\varphi,\theta,\psi)\f$ Euler @@ -68,13 +69,13 @@ vpRzyzVector::vpRzyzVector(const vpRotationMatrix &R) : vpRotationVector(3) { bu \param tu : \f$\theta {\bf u}\f$ representation of a rotation used here as input to initialize the Euler angles. */ -vpRzyzVector::vpRzyzVector(const vpThetaUVector &tu) : vpRotationVector(3) { buildFrom(tu); } +vpRzyzVector::vpRzyzVector(const vpThetaUVector &tu) : vpRotationVector(constr_val_3) { buildFrom(tu); } /*! Copy constructor from a 3-dimension vector. */ -vpRzyzVector::vpRzyzVector(const vpColVector &rzyz) : vpRotationVector(3) { buildFrom(rzyz); } +vpRzyzVector::vpRzyzVector(const vpColVector &rzyz) : vpRotationVector(constr_val_3) { buildFrom(rzyz); } /*! Copy constructor from a 3-dimension vector. */ -vpRzyzVector::vpRzyzVector(const std::vector &rzyz) : vpRotationVector(3) { buildFrom(rzyz); } +vpRzyzVector::vpRzyzVector(const std::vector &rzyz) : vpRotationVector(constr_val_3) { buildFrom(rzyz); } /*! Convert a rotation matrix into a \f$R_{zyz}=(\varphi,\theta,\psi)\f$ Euler @@ -127,11 +128,11 @@ vpRzyzVector &vpRzyzVector::buildFrom(const vpThetaUVector &tu) */ vpRzyzVector &vpRzyzVector::buildFrom(const vpColVector &rzyz) { - if (rzyz.size() != 3) { + const unsigned int val_3 = 3; + if (rzyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-zyz vector from a %d-dimension col vector", rzyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyz[i]; } @@ -144,11 +145,11 @@ vpRzyzVector &vpRzyzVector::buildFrom(const vpColVector &rzyz) */ vpRzyzVector &vpRzyzVector::buildFrom(const std::vector &rzyz) { - if (rzyz.size() != 3) { + const unsigned int val_3 = 3; + if (rzyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension std::vector", rzyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyz[i]; } @@ -233,11 +234,11 @@ vpRzyzVector &vpRzyzVector::operator=(double v) */ vpRzyzVector &vpRzyzVector::operator=(const vpColVector &rzyz) { - if (rzyz.size() != 3) { + const unsigned int val_3 = 3; + if (rzyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot set a R-zyz vector from a %d-dimension col vector", rzyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyz[i]; } diff --git a/modules/core/src/math/transformation/vpThetaUVector.cpp b/modules/core/src/math/transformation/vpThetaUVector.cpp index 2530e2c296..e510ee542c 100644 --- a/modules/core/src/math/transformation/vpThetaUVector.cpp +++ b/modules/core/src/math/transformation/vpThetaUVector.cpp @@ -42,43 +42,45 @@ #include BEGIN_VISP_NAMESPACE + const double vpThetaUVector::minimum = 0.0001; +const unsigned int vpThetaUVector::constr_val_3 = 3; /*! Default constructor that initialize all the 3 angles to zero. */ -vpThetaUVector::vpThetaUVector() : vpRotationVector(3) { } +vpThetaUVector::vpThetaUVector() : vpRotationVector(constr_val_3) { } /*! Copy constructor. */ vpThetaUVector::vpThetaUVector(const vpThetaUVector &tu) : vpRotationVector(tu) { } /*! Copy constructor from a 3-dimension vector. */ -vpThetaUVector::vpThetaUVector(const vpColVector &tu) : vpRotationVector(3) { buildFrom(tu); } +vpThetaUVector::vpThetaUVector(const vpColVector &tu) : vpRotationVector(constr_val_3) { buildFrom(tu); } /*! Initialize a \f$\theta {\bf u}\f$ vector from an homogeneous matrix. */ -vpThetaUVector::vpThetaUVector(const vpHomogeneousMatrix &M) : vpRotationVector(3) { buildFrom(M); } +vpThetaUVector::vpThetaUVector(const vpHomogeneousMatrix &M) : vpRotationVector(constr_val_3) { buildFrom(M); } /*! Initialize a \f$\theta {\bf u}\f$ vector from a pose vector. */ -vpThetaUVector::vpThetaUVector(const vpPoseVector &p) : vpRotationVector(3) { buildFrom(p); } +vpThetaUVector::vpThetaUVector(const vpPoseVector &p) : vpRotationVector(constr_val_3) { buildFrom(p); } /*! Initialize a \f$\theta {\bf u}\f$ vector from a rotation matrix. */ -vpThetaUVector::vpThetaUVector(const vpRotationMatrix &R) : vpRotationVector(3) { buildFrom(R); } +vpThetaUVector::vpThetaUVector(const vpRotationMatrix &R) : vpRotationVector(constr_val_3) { buildFrom(R); } /*! Initialize a \f$\theta {\bf u}\f$ vector from an Euler z-y-x representation vector. */ -vpThetaUVector::vpThetaUVector(const vpRzyxVector &rzyx) : vpRotationVector(3) { buildFrom(rzyx); } +vpThetaUVector::vpThetaUVector(const vpRzyxVector &rzyx) : vpRotationVector(constr_val_3) { buildFrom(rzyx); } /*! Initialize a \f$\theta {\bf u}\f$ vector from an Euler z-y-z representation vector. */ -vpThetaUVector::vpThetaUVector(const vpRzyzVector &rzyz) : vpRotationVector(3) { buildFrom(rzyz); } +vpThetaUVector::vpThetaUVector(const vpRzyzVector &rzyz) : vpRotationVector(constr_val_3) { buildFrom(rzyz); } /*! Initialize a \f$\theta {\bf u}\f$ vector from an Euler x-y-z representation vector. */ -vpThetaUVector::vpThetaUVector(const vpRxyzVector &rxyz) : vpRotationVector(3) { buildFrom(rxyz); } +vpThetaUVector::vpThetaUVector(const vpRxyzVector &rxyz) : vpRotationVector(constr_val_3) { buildFrom(rxyz); } /*! Initialize a \f$\theta {\bf u}\f$ vector from a quaternion representation vector. */ -vpThetaUVector::vpThetaUVector(const vpQuaternionVector &q) : vpRotationVector(3) { buildFrom(q); } +vpThetaUVector::vpThetaUVector(const vpQuaternionVector &q) : vpRotationVector(constr_val_3) { buildFrom(q); } /*! Build a \f$\theta {\bf u}\f$ vector from 3 angles in radians. @@ -100,12 +102,12 @@ vpThetaUVector::vpThetaUVector(const vpQuaternionVector &q) : vpRotationVector(3 tu: 0 1.570796327 3.141592654 \endcode */ -vpThetaUVector::vpThetaUVector(double tux, double tuy, double tuz) : vpRotationVector(3) { buildFrom(tux, tuy, tuz); } +vpThetaUVector::vpThetaUVector(double tux, double tuy, double tuz) : vpRotationVector(constr_val_3) { buildFrom(tux, tuy, tuz); } /*! Build a \f$\theta {\bf u}\f$ vector from a vector of 3 angles in radian. */ -vpThetaUVector::vpThetaUVector(const std::vector &tu) : vpRotationVector(3) { buildFrom(tu); } +vpThetaUVector::vpThetaUVector(const std::vector &tu) : vpRotationVector(constr_val_3) { buildFrom(tu); } /*! Converts an homogeneous matrix into a \f$\theta {\bf u}\f$ vector. @@ -126,8 +128,9 @@ vpThetaUVector &vpThetaUVector::buildFrom(const vpHomogeneousMatrix &M) vpThetaUVector &vpThetaUVector::buildFrom(const vpPoseVector &p) { const unsigned int val_3 = 3; + const unsigned int index_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { - data[i] = p[i + 3]; + data[i] = p[i + index_3]; } return *this; @@ -154,9 +157,9 @@ vpThetaUVector &vpThetaUVector::buildFrom(const vpRotationMatrix &R) { double sinc = vpMath::sinc(s, theta); - data[index_0] = (R[index_2][index_1] - R[index_1][index_2]) / (2 * sinc); - data[index_1] = (R[index_0][index_2] - R[index_2][index_0]) / (2 * sinc); - data[index_2] = (R[index_1][index_0] - R[index_0][index_1]) / (2 * sinc); + data[index_0] = (R[index_2][index_1] - R[index_1][index_2]) / (2.0 * sinc); + data[index_1] = (R[index_0][index_2] - R[index_2][index_0]) / (2.0 * sinc); + data[index_2] = (R[index_1][index_0] - R[index_0][index_1]) / (2.0 * sinc); } else /* theta near PI */ { @@ -262,11 +265,11 @@ vpThetaUVector &vpThetaUVector::buildFrom(const vpQuaternionVector &q) */ vpThetaUVector &vpThetaUVector::buildFrom(const std::vector &tu) { - if (tu.size() != 3) { + const unsigned int val_3 = 3; + if (tu.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a theta-u vector from a %d-dimension std::vector", tu.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = tu[i]; } @@ -279,11 +282,11 @@ vpThetaUVector &vpThetaUVector::buildFrom(const std::vector &tu) */ vpThetaUVector &vpThetaUVector::buildFrom(const vpColVector &tu) { - if (tu.size() != 3) { + const unsigned int val_3 = 3; + if (tu.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a theta-u vector from a %d-dimension std::vector", tu.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = tu[i]; } @@ -413,7 +416,8 @@ vpThetaUVector &vpThetaUVector::operator=(const vpColVector &tu) */ void vpThetaUVector::extract(double &theta, vpColVector &u) const { - u.resize(3); + const unsigned int val_3 = 3; + u.resize(val_3); theta = getTheta(); // --comment: if theta equals 0 @@ -421,7 +425,6 @@ void vpThetaUVector::extract(double &theta, vpColVector &u) const u = 0; return; } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { u[i] = data[i] / theta; } @@ -521,7 +524,7 @@ vpThetaUVector vpThetaUVector::operator*(const vpThetaUVector &tu_b) const double c = 2 * std::acos((std::cos(a_2) * std::cos(b_2)) - (vpColVector::dotProd(a_hat_sin_2, b_hat_sin_2))); vpColVector d = ((std::sin(a_2) * std::cos(b_2) * a_hat) + (std::cos(a_2) * std::sin(b_2) * b_hat)) + (std::sin(a_2) * std::sin(b_2) * vpColVector::crossProd(a_hat, b_hat)); - d = (c * d) / std::sin(c / 2); + d = (c * d) / std::sin(c / 2.0); return vpThetaUVector(d); } diff --git a/modules/core/src/math/transformation/vpTranslationVector.cpp b/modules/core/src/math/transformation/vpTranslationVector.cpp index ab41fde0d5..620fa91287 100644 --- a/modules/core/src/math/transformation/vpTranslationVector.cpp +++ b/modules/core/src/math/transformation/vpTranslationVector.cpp @@ -42,6 +42,7 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpTranslationVector::constr_val_3 = 3; /*! Construct a translation vector \f$ \bf t \f$ from 3 doubles. @@ -49,7 +50,7 @@ BEGIN_VISP_NAMESPACE in meters. */ -vpTranslationVector::vpTranslationVector(double tx, double ty, double tz) : vpArray2D(3, 1), m_index(0) +vpTranslationVector::vpTranslationVector(double tx, double ty, double tz) : vpArray2D(constr_val_3, 1), m_index(0) { const unsigned int index_0 = 0; const unsigned int index_1 = 1; @@ -66,7 +67,7 @@ vpTranslationVector::vpTranslationVector(double tx, double ty, double tz) : vpAr \param M : Homogeneous matrix where translations are in meters. */ -vpTranslationVector::vpTranslationVector(const vpHomogeneousMatrix &M) : vpArray2D(3, 1), m_index(0) +vpTranslationVector::vpTranslationVector(const vpHomogeneousMatrix &M) : vpArray2D(constr_val_3, 1), m_index(0) { M.extract(*this); } @@ -78,7 +79,7 @@ vpTranslationVector::vpTranslationVector(const vpHomogeneousMatrix &M) : vpArray \param p : Pose vector where translations are in meters. */ -vpTranslationVector::vpTranslationVector(const vpPoseVector &p) : vpArray2D(3, 1), m_index(0) +vpTranslationVector::vpTranslationVector(const vpPoseVector &p) : vpArray2D(constr_val_3, 1), m_index(0) { const unsigned int index_0 = 0; const unsigned int index_1 = 1; @@ -116,7 +117,8 @@ vpTranslationVector::vpTranslationVector(const vpTranslationVector &tv) : vpArra */ vpTranslationVector::vpTranslationVector(const vpColVector &v) : vpArray2D(v), m_index(0) { - if (v.size() != 3) { + const unsigned int val_3 = 3; + if (v.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a translation vector from a " "%d-dimension column vector", @@ -269,13 +271,13 @@ vpTranslationVector vpTranslationVector::operator+(const vpTranslationVector &tv */ vpTranslationVector vpTranslationVector::operator+(const vpColVector &v) const { - if (v.size() != 3) { + const unsigned int val_3 = 3; + if (v.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot add translation vector to a %d-dimension column vector", v.size())); } vpTranslationVector s; - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { s[i] = (*this)[i] + v[i]; } @@ -459,7 +461,8 @@ vpTranslationVector vpTranslationVector::operator/(double x) const */ vpTranslationVector &vpTranslationVector::operator=(const vpColVector &tv) { - if (tv.size() != 3) { + const unsigned int val_3 = 3; + if (tv.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot initialize a translation vector from a " "%d-dimension col vector", @@ -524,7 +527,8 @@ vpTranslationVector &vpTranslationVector::operator=(double x) { double *d = data; - for (int i = 0; i < 3; ++i) { + const int val_3 = 3; + for (int i = 0; i < val_3; ++i) { *(d++) = x; } @@ -662,7 +666,8 @@ void vpTranslationVector::skew(const vpTranslationVector &tv, vpMatrix &M) const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; - M.resize(3, 3); + const unsigned int val_3 = 3; + M.resize(val_3, val_3); M[index_0][index_0] = 0; M[index_0][index_1] = -tv[index_2]; M[index_0][index_2] = tv[index_1]; diff --git a/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp b/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp index 2dcf398bfa..1281262390 100644 --- a/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp +++ b/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp @@ -29,8 +29,7 @@ * * Description: * Velocity twist transformation matrix. - * -*****************************************************************************/ + */ /*! \file vpVelocityTwistMatrix.cpp @@ -47,6 +46,7 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpVelocityTwistMatrix::constr_val_6 = 6; /*! Copy operator that allow to set a velocity twist matrix from an other one. @@ -54,8 +54,10 @@ BEGIN_VISP_NAMESPACE */ vpVelocityTwistMatrix &vpVelocityTwistMatrix::operator=(const vpVelocityTwistMatrix &V) { - for (int i = 0; i < 6; ++i) { - for (int j = 0; j < 6; ++j) { + // why not unsigned int + const int val_6 = 6; + for (int i = 0; i < val_6; ++i) { + for (int j = 0; j < val_6; ++j) { rowPtrs[i][j] = V.rowPtrs[i][j]; } } @@ -84,7 +86,7 @@ void vpVelocityTwistMatrix::eye() /*! Initialize a velocity twist transformation matrix as identity. */ -vpVelocityTwistMatrix::vpVelocityTwistMatrix() : vpArray2D(6, 6) { eye(); } +vpVelocityTwistMatrix::vpVelocityTwistMatrix() : vpArray2D(constr_val_6, constr_val_6) { eye(); } /*! Initialize a velocity twist transformation matrix from another velocity @@ -92,7 +94,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix() : vpArray2D(6, 6) { eye() \param V : Velocity twist matrix used as initializer. */ -vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpVelocityTwistMatrix &V) : vpArray2D(6, 6) { *this = V; } +vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpVelocityTwistMatrix &V) : vpArray2D(constr_val_6, constr_val_6) { *this = V; } /*! @@ -112,7 +114,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpVelocityTwistMatrix &V) : v {\bf 0}_{3\times 3} & {\bf R} \end{array} \right] \f] */ -vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpHomogeneousMatrix &M, bool full) : vpArray2D(6, 6) +vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpHomogeneousMatrix &M, bool full) : vpArray2D(constr_val_6, constr_val_6) { if (full) { buildFrom(M); @@ -137,7 +139,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpHomogeneousMatrix &M, bool */ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpTranslationVector &t, const vpThetaUVector &thetau) - : vpArray2D(6, 6) + : vpArray2D(constr_val_6, constr_val_6) { buildFrom(t, thetau); } @@ -154,7 +156,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpTranslationVector &t, const vector \f$R\f$ . */ -vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpThetaUVector &thetau) : vpArray2D(6, 6) +vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpThetaUVector &thetau) : vpArray2D(constr_val_6, constr_val_6) { buildFrom(thetau); } @@ -173,7 +175,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpThetaUVector &thetau) : vpA */ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpTranslationVector &t, const vpRotationMatrix &R) - : vpArray2D(6, 6) + : vpArray2D(constr_val_6, constr_val_6) { buildFrom(t, R); } @@ -189,7 +191,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpTranslationVector &t, const \param R : Rotation matrix. */ -vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpRotationMatrix &R) : vpArray2D(6, 6) { buildFrom(R); } +vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpRotationMatrix &R) : vpArray2D(constr_val_6, constr_val_6) { buildFrom(R); } /*! @@ -207,7 +209,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpRotationMatrix &R) : vpArra radians used to initialize \f$R\f$. */ vpVelocityTwistMatrix::vpVelocityTwistMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz) - : vpArray2D(6, 6) + : vpArray2D(constr_val_6, constr_val_6) { vpTranslationVector t(tx, ty, tz); vpThetaUVector tu(tux, tuy, tuz); @@ -348,12 +350,13 @@ vpColVector vpVelocityTwistMatrix::operator*(const vpColVector &v) const */ vpVelocityTwistMatrix &vpVelocityTwistMatrix::buildFrom(const vpRotationMatrix &R) { + const unsigned int index_3 = 3; const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { for (unsigned int j = 0; j < val_3; ++j) { (*this)[i][j] = R[i][j]; - (*this)[i + 3][j + 3] = R[i][j]; - (*this)[i][j + 3] = 0; + (*this)[i + index_3][j + index_3] = R[i][j]; + (*this)[i][j + index_3] = 0; } } return *this; @@ -377,12 +380,13 @@ vpVelocityTwistMatrix &vpVelocityTwistMatrix::buildFrom(const vpTranslationVecto { vpMatrix skewaR = t.skew(t) * R; + const unsigned int index_3 = 3; const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { for (unsigned int j = 0; j < val_3; ++j) { (*this)[i][j] = R[i][j]; - (*this)[i + 3][j + 3] = R[i][j]; - (*this)[i][j + 3] = skewaR[i][j]; + (*this)[i + index_3][j + index_3] = R[i][j]; + (*this)[i][j + index_3] = skewaR[i][j]; } } diff --git a/modules/core/src/tools/geometry/vpPlane.cpp b/modules/core/src/tools/geometry/vpPlane.cpp index 71d177b1cd..cf199673be 100644 --- a/modules/core/src/tools/geometry/vpPlane.cpp +++ b/modules/core/src/tools/geometry/vpPlane.cpp @@ -257,7 +257,8 @@ double vpPlane::computeZ(double x, double y) const */ vpColVector vpPlane::getNormal() const { - vpColVector n(3); + const unsigned int val_3 = 3; + vpColVector n(val_3); const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; @@ -280,7 +281,8 @@ vpColVector vpPlane::getNormal() const */ void vpPlane::getNormal(vpColVector &n) const { - n.resize(3); + const unsigned int val_3 = 3; + n.resize(val_3); const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; diff --git a/modules/core/src/tools/geometry/vpPolygon.cpp b/modules/core/src/tools/geometry/vpPolygon.cpp index 9aec00c9a5..2d8ecb9d96 100644 --- a/modules/core/src/tools/geometry/vpPolygon.cpp +++ b/modules/core/src/tools/geometry/vpPolygon.cpp @@ -126,7 +126,8 @@ vpPolygon::vpPolygon() vpPolygon::vpPolygon(const std::vector &corners) : _corners(), _center(), _area(0.), _goodPoly(true), _bbox(), m_PnPolyConstants(), m_PnPolyMultiples() { - if (corners.size() < 3) { + const unsigned int val_3 = 3; + if (corners.size() < val_3) { _goodPoly = false; } init(corners); @@ -143,7 +144,8 @@ vpPolygon::vpPolygon(const std::vector &corners) vpPolygon::vpPolygon(const std::list &corners) : _corners(), _center(), _area(0.), _goodPoly(true), _bbox(), m_PnPolyConstants(), m_PnPolyMultiples() { - if (corners.size() < 3) { + const unsigned int val_3 = 3; + if (corners.size() < val_3) { _goodPoly = false; } init(corners); @@ -399,7 +401,9 @@ bool vpPolygon::testIntersectionSegments(const vpImagePoint &ip1, const vpImageP */ bool vpPolygon::isInside(const vpImagePoint &ip, const PointInPolygonMethod &method) const { - if (_corners.size() < 3) { + const int val_1000 = 1000; + const unsigned int val_3 = 3; + if (_corners.size() < val_3) { return false; } @@ -411,8 +415,8 @@ bool vpPolygon::isInside(const vpImagePoint &ip, const PointInPolygonMethod &met // we add random since it appears that sometimes infPoint may cause a degenerated case (so relaunch and // hope that result will be different). vpUniRand generator; - infPoint.set_i(infPoint.get_i() + (1000 * generator())); - infPoint.set_j(infPoint.get_j() + (1000 * generator())); + infPoint.set_i(infPoint.get_i() + (val_1000 * generator())); + infPoint.set_j(infPoint.get_j() + (val_1000 * generator())); bool oddNbIntersections = false; size_t v_corners_size = _corners.size(); @@ -452,7 +456,7 @@ bool vpPolygon::isInside(const vpImagePoint &ip, const PointInPolygonMethod &met for (size_t i = 0; i < v_corners_size; ++i) { if (((_corners[i].get_v() < ip.get_v()) && (_corners[j].get_v() >= ip.get_v())) || ((_corners[j].get_v() < ip.get_v()) && (_corners[i].get_v() >= ip.get_v()))) { - oddNodes ^= (ip.get_v() * m_PnPolyMultiples[i] + m_PnPolyConstants[i] < ip.get_u()); + oddNodes ^= ( ((ip.get_v() * m_PnPolyMultiples[i]) + m_PnPolyConstants[i]) < ip.get_u()); } j = i; @@ -468,7 +472,8 @@ bool vpPolygon::isInside(const vpImagePoint &ip, const PointInPolygonMethod &met void vpPolygon::precalcValuesPnPoly() { - if (_corners.size() < 3) { + const std::size_t val_3 = 3; + if (_corners.size() < val_3) { return; } @@ -517,7 +522,8 @@ void vpPolygon::updateArea() _area += (_corners[i].get_j() * _corners[i_p_1].get_i()) - (_corners[i_p_1].get_j() * _corners[i].get_i()); } - _area /= 2; + const int val_2 = 2; + _area /= val_2; if (_area < 0) { _area = -_area; } @@ -554,9 +560,10 @@ void vpPolygon::updateCenter() ((_corners[i_p_1].get_i() * _corners[i].get_j()) - (_corners[i_p_1].get_j() * _corners[i].get_i())); } + const int val_6 = 6; if (_area > 0) { - _center.set_i(fabs(i_tmp / (6 * _area))); - _center.set_j(fabs(j_tmp / (6 * _area))); + _center.set_i(fabs(i_tmp / (val_6 * _area))); + _center.set_j(fabs(j_tmp / (val_6 * _area))); } else { _center = _corners[0]; diff --git a/modules/core/src/tools/geometry/vpRectOriented.cpp b/modules/core/src/tools/geometry/vpRectOriented.cpp index c7e0ebe906..e8a90620ce 100644 --- a/modules/core/src/tools/geometry/vpRectOriented.cpp +++ b/modules/core/src/tools/geometry/vpRectOriented.cpp @@ -186,16 +186,17 @@ vpImagePoint vpRectOriented::getBottomRight() const { return m_bottomRight; } /// Set the size of the rectangle : performs a homothety relatively to the rectangle center. void vpRectOriented::setSize(double width, double height) { + const int val_2 = 2; m_width = width; m_height = height; - m_topLeft.set_i(m_center.get_i() - ((m_height * cos(m_theta)) / 2.0) - ((m_width * sin(m_theta)) / 2)); - m_topLeft.set_j((m_center.get_j() + ((m_height * sin(m_theta)) / 2.0)) - ((m_width * cos(m_theta)) / 2)); - m_bottomLeft.set_i((m_center.get_i() + ((m_height * cos(m_theta)) / 2.0)) - ((m_width * sin(m_theta)) / 2)); - m_bottomLeft.set_j(m_center.get_j() - ((m_height * sin(m_theta)) / 2.0) - ((m_width * cos(m_theta)) / 2)); - m_bottomRight.set_i(m_center.get_i() + ((m_height * cos(m_theta)) / 2.0) + ((m_width * sin(m_theta)) / 2)); - m_bottomRight.set_j((m_center.get_j() - ((m_height * sin(m_theta)) / 2.0)) + ((m_width * cos(m_theta)) / 2)); - m_topRight.set_i((m_center.get_i() - ((m_height * cos(m_theta)) / 2.0)) + ((m_width * sin(m_theta)) / 2)); - m_topRight.set_j(m_center.get_j() + ((m_height * sin(m_theta)) / 2.0) + ((m_width * cos(m_theta)) / 2)); + m_topLeft.set_i(m_center.get_i() - ((m_height * cos(m_theta)) / 2.0) - ((m_width * sin(m_theta)) / val_2)); + m_topLeft.set_j((m_center.get_j() + ((m_height * sin(m_theta)) / 2.0)) - ((m_width * cos(m_theta)) / val_2)); + m_bottomLeft.set_i((m_center.get_i() + ((m_height * cos(m_theta)) / 2.0)) - ((m_width * sin(m_theta)) / val_2)); + m_bottomLeft.set_j(m_center.get_j() - ((m_height * sin(m_theta)) / 2.0) - ((m_width * cos(m_theta)) / val_2)); + m_bottomRight.set_i(m_center.get_i() + ((m_height * cos(m_theta)) / 2.0) + ((m_width * sin(m_theta)) / val_2)); + m_bottomRight.set_j((m_center.get_j() - ((m_height * sin(m_theta)) / 2.0)) + ((m_width * cos(m_theta)) / val_2)); + m_topRight.set_i((m_center.get_i() - ((m_height * cos(m_theta)) / 2.0)) + ((m_width * sin(m_theta)) / val_2)); + m_topRight.set_j(m_center.get_j() + ((m_height * sin(m_theta)) / 2.0) + ((m_width * cos(m_theta)) / val_2)); } /// Get the rectangle width. @@ -207,15 +208,16 @@ double vpRectOriented::getHeight() const { return m_height; } /// Set the rectangle orientation (rad). void vpRectOriented::setOrientation(double theta) { + const int val_2 = 2; m_theta = theta; - m_topLeft.set_i(m_center.get_i() - ((m_height * cos(m_theta)) / 2.0) - ((m_width * sin(m_theta)) / 2)); - m_topLeft.set_j((m_center.get_j() + ((m_height * sin(m_theta)) / 2.0)) - ((m_width * cos(m_theta)) / 2)); - m_bottomLeft.set_i((m_center.get_i() + ((m_height * cos(m_theta)) / 2.0)) - ((m_width * sin(m_theta)) / 2)); - m_bottomLeft.set_j(m_center.get_j() - ((m_height * sin(m_theta)) / 2.0) - ((m_width * cos(m_theta)) / 2)); - m_bottomRight.set_i(m_center.get_i() + ((m_height * cos(m_theta)) / 2.0) + ((m_width * sin(m_theta)) / 2)); - m_bottomRight.set_j((m_center.get_j() - ((m_height * sin(m_theta)) / 2.0)) + ((m_width * cos(m_theta)) / 2)); - m_topRight.set_i((m_center.get_i() - ((m_height * cos(m_theta)) / 2.0)) + ((m_width * sin(m_theta)) / 2)); - m_topRight.set_j(m_center.get_j() + ((m_height * sin(m_theta)) / 2.0) + ((m_width * cos(m_theta)) / 2)); + m_topLeft.set_i(m_center.get_i() - ((m_height * cos(m_theta)) / 2.0) - ((m_width * sin(m_theta)) / val_2)); + m_topLeft.set_j((m_center.get_j() + ((m_height * sin(m_theta)) / 2.0)) - ((m_width * cos(m_theta)) / val_2)); + m_bottomLeft.set_i((m_center.get_i() + ((m_height * cos(m_theta)) / 2.0)) - ((m_width * sin(m_theta)) / val_2)); + m_bottomLeft.set_j(m_center.get_j() - ((m_height * sin(m_theta)) / 2.0) - ((m_width * cos(m_theta)) / val_2)); + m_bottomRight.set_i(m_center.get_i() + ((m_height * cos(m_theta)) / 2.0) + ((m_width * sin(m_theta)) / val_2)); + m_bottomRight.set_j((m_center.get_j() - ((m_height * sin(m_theta)) / 2.0)) + ((m_width * cos(m_theta)) / val_2)); + m_topRight.set_i((m_center.get_i() - ((m_height * cos(m_theta)) / 2.0)) + ((m_width * sin(m_theta)) / val_2)); + m_topRight.set_j(m_center.get_j() + ((m_height * sin(m_theta)) / 2.0) + ((m_width * cos(m_theta)) / val_2)); } /// Get the rectangle orientation (rad). diff --git a/modules/core/src/tools/histogram/vpHistogram.cpp b/modules/core/src/tools/histogram/vpHistogram.cpp index 98afaa87af..46cc2a408d 100644 --- a/modules/core/src/tools/histogram/vpHistogram.cpp +++ b/modules/core/src/tools/histogram/vpHistogram.cpp @@ -47,6 +47,7 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpHistogram::constr_val_256 = 256; #if defined(VISP_HAVE_THREADS) #include @@ -192,12 +193,12 @@ bool compare_vpHistogramPeak(vpHistogramPeak first, vpHistogramPeak second) /*! Default constructor for a gray level histogram. */ -vpHistogram::vpHistogram() : m_histogram(nullptr), m_size(256), mp_mask(nullptr), m_total(0) { init(); } +vpHistogram::vpHistogram() : m_histogram(nullptr), m_size(constr_val_256), mp_mask(nullptr), m_total(0) { init(); } /*! Copy constructor of a gray level histogram. */ -vpHistogram::vpHistogram(const vpHistogram &h) : m_histogram(nullptr), m_size(256), mp_mask(h.mp_mask), m_total(h.m_total) +vpHistogram::vpHistogram(const vpHistogram &h) : m_histogram(nullptr), m_size(constr_val_256), mp_mask(h.mp_mask), m_total(h.m_total) { init(h.m_size); memcpy(m_histogram, h.m_histogram, m_size * sizeof(unsigned)); @@ -210,7 +211,7 @@ vpHistogram::vpHistogram(const vpHistogram &h) : m_histogram(nullptr), m_size(25 \sa calculate() */ -vpHistogram::vpHistogram(const vpImage &I) : m_histogram(nullptr), m_size(256), mp_mask(nullptr), m_total(0) +vpHistogram::vpHistogram(const vpImage &I) : m_histogram(nullptr), m_size(constr_val_256), mp_mask(nullptr), m_total(0) { init(); @@ -225,7 +226,7 @@ vpHistogram::vpHistogram(const vpImage &I) : m_histogram(nullptr) and false that it should be ignored. \sa calculate() setMask() */ -vpHistogram::vpHistogram(const vpImage &I, const vpImage *p_mask) : m_histogram(nullptr), m_size(256), mp_mask(nullptr), m_total(0) +vpHistogram::vpHistogram(const vpImage &I, const vpImage *p_mask) : m_histogram(nullptr), m_size(constr_val_256), mp_mask(nullptr), m_total(0) { init(); setMask(p_mask); @@ -298,14 +299,15 @@ void vpHistogram::init(unsigned size_) */ void vpHistogram::calculate(const vpImage &I, unsigned int nbins, unsigned int nbThreads) { + const unsigned int val_256 = 256; if (m_size != nbins) { if (m_histogram != nullptr) { delete[] m_histogram; m_histogram = nullptr; } - m_size = nbins > 256 ? 256 : (nbins > 0 ? nbins : 256); - if ((nbins > 256) || (nbins == 0)) { + m_size = nbins > val_256 ? val_256 : (nbins > 0 ? nbins : val_256); + if ((nbins > val_256) || (nbins == 0)) { std::cerr << "nbins=" << nbins << " , nbins should be between ]0 ; 256] ; use by default nbins=256" << std::endl; } m_histogram = new unsigned int[m_size]; @@ -325,7 +327,7 @@ void vpHistogram::calculate(const vpImage &I, unsigned int nbins, } unsigned int lut[256]; - for (unsigned int i = 0; i < 256; ++i) { + for (unsigned int i = 0; i < val_256; ++i) { lut[i] = static_cast((i * m_size) / 256.0); } @@ -430,7 +432,8 @@ void vpHistogram::equalize(const vpImage &I, vpImage 0)) { @@ -638,6 +641,7 @@ unsigned vpHistogram::getPeaks(unsigned char dist, vpHistogramPeak &peak1, vpHis { std::list peaks; unsigned nbpeaks; // Number of peaks in the histogram (ie local maxima) + const unsigned int val_2 = 2; nbpeaks = getPeaks(peaks); sort(peaks); @@ -663,7 +667,7 @@ unsigned vpHistogram::getPeaks(unsigned char dist, vpHistogramPeak &peak1, vpHis if (abs(p.getLevel() - peak1.getLevel()) > dist) { // The second peak is found peak2 = p; - return 2; + return val_2; } } @@ -978,6 +982,8 @@ bool vpHistogram::getValey(const vpHistogramPeak &peak1, const vpHistogramPeak & unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak, vpHistogramValey &valeyl, vpHistogramValey &valeyr) { + const unsigned int val_ui_0x10 = 0x10; + const unsigned int val_ui_0x11 = 0x11; unsigned int ret = 0x11; unsigned int nbmini; // Minimum numbers unsigned int sumindmini; // Sum @@ -993,7 +999,7 @@ unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak, } if (peak.getLevel() == (m_size - 1)) { valeyr.set(static_cast(m_size - 1), 0); - ret &= 0x10; + ret &= val_ui_0x10; } if (ret >> 1) // consider the left part of the requested peak @@ -1063,7 +1069,7 @@ unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak, else { unsigned int minipos = sumindmini / nbmini; // position of the minimum valeyl.set(static_cast(minipos), m_histogram[minipos]); - ret &= 0x11; + ret &= val_ui_0x11; } } @@ -1121,12 +1127,12 @@ unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak, } if (nbmini == 0) { valeyr.set(static_cast(m_size - 1), 0); - ret &= 0x10; + ret &= val_ui_0x10; } else { unsigned int minipos = sumindmini / nbmini; // position of the minimum valeyr.set(static_cast(minipos), m_histogram[minipos]); - ret &= 0x11; + ret &= val_ui_0x11; } } diff --git a/modules/core/src/tracking/forward-projection/vpCircle.cpp b/modules/core/src/tracking/forward-projection/vpCircle.cpp index f6d47b8253..b8d58ac62e 100644 --- a/modules/core/src/tracking/forward-projection/vpCircle.cpp +++ b/modules/core/src/tracking/forward-projection/vpCircle.cpp @@ -39,10 +39,12 @@ BEGIN_VISP_NAMESPACE void vpCircle::init() { - oP.resize(7); - cP.resize(7); + const unsigned int val_7 = 7; + const unsigned int val_5 = 5; + oP.resize(val_7); + cP.resize(val_7); - p.resize(5); + p.resize(val_5); } /*! @@ -163,8 +165,12 @@ void vpCircle::projection() { projection(cP, p); } */ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const { + const int val_2 = 2; + const int val_4 = 4; + const unsigned int val_6 = 6; + const unsigned int val_5 = 5; double det_threshold = 1e-10; - p_.resize(5, false); + p_.resize(val_5, false); const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; @@ -172,7 +178,7 @@ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const const unsigned int index_4 = 4; const unsigned int index_5 = 5; - vpColVector K(6); + vpColVector K(val_6); { double A = cP_[index_0]; double B = cP_[index_1]; @@ -191,12 +197,12 @@ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const B = B / det; C = C / det; - K[index_0] = (1 - (2 * A * X0)) + (A * A * s); - K[index_1] = (1 - (2 * B * Y0)) + (B * B * s); + K[index_0] = (1 - (val_2 * A * X0)) + (A * A * s); + K[index_1] = (1 - (val_2 * B * Y0)) + (B * B * s); K[index_2] = ((-A * Y0) - (B * X0)) + (A * B * s); K[index_3] = ((-C * X0) - (A * Z0)) + (A * C * s); K[index_4] = ((-C * Y0) - (B * Z0)) + (B * C * s); - K[index_5] = (1 - (2 * C * Z0)) + (C * C * s); + K[index_5] = (1 - (val_2 * C * Z0)) + (C * C * s); } double det = (K[index_2] * K[index_2]) - (K[index_0] * K[index_1]); @@ -224,7 +230,7 @@ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const } } else { - E = ((K[1] - K[0]) + c) / (2 * K[index_2]); + E = ((K[1] - K[0]) + c) / (val_2 * K[index_2]); if (fabs(E) > 1.0) { A = sqrt(s / ((K[0] + K[1]) + c)); B = sqrt(s / ((K[0] + K[1]) - c)); @@ -237,7 +243,7 @@ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const } // Chaumette PhD Thesis 1990, eq 2.72 divided by 4 since n_ij = mu_ij_chaumette_thesis / 4 - det = 4 * (1.0 + vpMath::sqr(E)); + det = val_4 * (1.0 + vpMath::sqr(E)); double n20 = (vpMath::sqr(A) + vpMath::sqr(B * E)) / det; double n11 = ((vpMath::sqr(A) - vpMath::sqr(B)) * E) / det; double n02 = (vpMath::sqr(B) + vpMath::sqr(A * E)) / det; @@ -261,7 +267,8 @@ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const */ void vpCircle::changeFrame(const vpHomogeneousMatrix &noMo, vpColVector &noP) const { - noP.resize(7, false); + const unsigned int val_7 = 7; + noP.resize(val_7, false); double A, B, C; const unsigned int index_0 = 0; @@ -276,9 +283,9 @@ void vpCircle::changeFrame(const vpHomogeneousMatrix &noMo, vpColVector &noP) co C = (noMo[index_2][0] * oP[0]) + (noMo[index_2][1] * oP[1]) + (noMo[index_2][index_2] * oP[index_2]); double X0, Y0, Z0; - X0 = noMo[index_0][index_3] + (noMo[index_0][0] * oP[3]) + (noMo[index_0][1] * oP[index_4]) + (noMo[index_0][index_2] * oP[index_5]); - Y0 = noMo[index_1][index_3] + (noMo[index_1][0] * oP[3]) + (noMo[index_1][1] * oP[index_4]) + (noMo[index_1][index_2] * oP[index_5]); - Z0 = noMo[index_2][index_3] + (noMo[index_2][0] * oP[3]) + (noMo[index_2][1] * oP[index_4]) + (noMo[index_2][index_2] * oP[index_5]); + X0 = noMo[index_0][index_3] + (noMo[index_0][0] * oP[index_3]) + (noMo[index_0][1] * oP[index_4]) + (noMo[index_0][index_2] * oP[index_5]); + Y0 = noMo[index_1][index_3] + (noMo[index_1][0] * oP[index_3]) + (noMo[index_1][1] * oP[index_4]) + (noMo[index_1][index_2] * oP[index_5]); + Z0 = noMo[index_2][index_3] + (noMo[index_2][0] * oP[index_3]) + (noMo[index_2][1] * oP[index_4]) + (noMo[index_2][index_2] * oP[index_5]); double R = oP[6]; noP[index_0] = A; diff --git a/modules/core/src/tracking/forward-projection/vpLine.cpp b/modules/core/src/tracking/forward-projection/vpLine.cpp index da7b23826d..11f5c8b4e3 100644 --- a/modules/core/src/tracking/forward-projection/vpLine.cpp +++ b/modules/core/src/tracking/forward-projection/vpLine.cpp @@ -122,7 +122,8 @@ void vpLine::setWorldCoordinates(const double &oA1, const double &oB1, const dou */ void vpLine::setWorldCoordinates(const vpColVector &oP_) { - if (oP_.getRows() != 8) { + const unsigned int val_8 = 8; + if (oP_.getRows() != val_8) { throw vpException(vpException::dimensionError, "Size of oP is not equal to 8 as it should be"); } this->oP = oP_; @@ -151,16 +152,16 @@ void vpLine::setWorldCoordinates(const vpColVector &oP_) */ void vpLine::setWorldCoordinates(const vpColVector &oP1, const vpColVector &oP2) { - if (oP1.getRows() != 4) { + const unsigned int val_4 = 4; + if (oP1.getRows() != val_4) { throw vpException(vpException::dimensionError, "Size of oP1 is not equal to 4 as it should be"); } - if (oP2.getRows() != 4) { + if (oP2.getRows() != val_4) { throw vpException(vpException::dimensionError, "Size of oP2 is not equal to 4 as it should be"); } - const unsigned int val_4 = 4; for (unsigned int i = 0; i < val_4; ++i) { oP[i] = oP1[i]; - oP[i + 4] = oP2[i]; + oP[i + val_4] = oP2[i]; } } @@ -219,10 +220,12 @@ void vpLine::projection() { projection(cP, p); } */ void vpLine::projection(const vpColVector &cP_, vpColVector &p_) const { - p_.resize(2, false); + const unsigned int val_2 = 2; + const unsigned int val_8 = 8; + p_.resize(val_2, false); // projection - if (cP.getRows() != 8) { + if (cP.getRows() != val_8) { throw vpException(vpException::dimensionError, "Size of cP is not equal to 8 as it should be"); } double A1, A2, B1, B2, C1, C2, D1, D2; @@ -344,7 +347,8 @@ void vpLine::changeFrame(const vpHomogeneousMatrix &cMo) { changeFrame(cMo, cP); */ void vpLine::changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP_) const { - cP_.resize(8, false); + const unsigned int val_8 = 8; + cP_.resize(val_8, false); double a1, a2, b1, b2, c1, c2, d1, d2; double A1, A2, B1, B2, C1, C2, D1, D2; @@ -437,10 +441,10 @@ void vpLine::changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP_) const D2 = -D2; } - cP_[4] = A2; - cP_[5] = B2; - cP_[6] = C2; - cP_[7] = D2; + cP_[index_4] = A2; + cP_[index_5] = B2; + cP_[index_6] = C2; + cP_[index_7] = D2; } /*! diff --git a/modules/core/src/tracking/forward-projection/vpPoint.cpp b/modules/core/src/tracking/forward-projection/vpPoint.cpp index 19d62eee9b..cc51a7d105 100644 --- a/modules/core/src/tracking/forward-projection/vpPoint.cpp +++ b/modules/core/src/tracking/forward-projection/vpPoint.cpp @@ -43,15 +43,17 @@ BEGIN_VISP_NAMESPACE void vpPoint::init() { + const unsigned int val_3 = 3; + const unsigned int val_4 = 4; const unsigned int index_2 = 2; const unsigned int index_3 = 3; - p.resize(3); + p.resize(val_3); p = 0; p[index_2] = 1.; - oP.resize(4); + oP.resize(val_4); oP = 0.; oP[index_3] = 1.; - cP.resize(4); + cP.resize(val_4); cP = 0.; cP[index_3] = 1.; @@ -246,10 +248,11 @@ vpColVector vpPoint::getWorldCoordinates(void) { return this->oP; } */ void vpPoint::projection(const vpColVector &v_cP, vpColVector &v_p) const { + const unsigned int val_3 = 3; const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; - v_p.resize(3, false); + v_p.resize(val_3, false); v_p[index_0] = v_cP[index_0] / v_cP[index_2]; v_p[index_1] = v_cP[index_1] / v_cP[index_2]; @@ -266,11 +269,12 @@ void vpPoint::projection(const vpColVector &v_cP, vpColVector &v_p) const */ void vpPoint::changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &v_cP) const { + const unsigned int val_4 = 4; const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; const unsigned int index_3 = 3; - v_cP.resize(4, false); + v_cP.resize(val_4, false); v_cP[index_0] = (cMo[index_0][index_0] * oP[index_0]) + (cMo[index_0][index_1] * oP[index_1]) + (cMo[index_0][index_2] * oP[index_2]) + (cMo[index_0][index_3] * oP[index_3]); v_cP[index_1] = (cMo[index_1][index_0] * oP[index_0]) + (cMo[index_1][index_1] * oP[index_1]) + (cMo[index_1][index_2] * oP[index_2]) + (cMo[index_1][index_3] * oP[index_3]); diff --git a/modules/core/src/tracking/forward-projection/vpSphere.cpp b/modules/core/src/tracking/forward-projection/vpSphere.cpp index 4a1aebd246..68da430f3c 100644 --- a/modules/core/src/tracking/forward-projection/vpSphere.cpp +++ b/modules/core/src/tracking/forward-projection/vpSphere.cpp @@ -41,10 +41,12 @@ BEGIN_VISP_NAMESPACE */ void vpSphere::init() { - oP.resize(4); - cP.resize(4); + const unsigned int val_4 = 4; + const unsigned int val_5 = 5; + oP.resize(val_4); + cP.resize(val_4); - p.resize(5); + p.resize(val_5); } /*! @@ -138,7 +140,8 @@ void vpSphere::projection() { projection(cP, p); } */ void vpSphere::projection(const vpColVector &cP_, vpColVector &p_) const { - p_.resize(5, false); + const unsigned int val_5 = 5; + p_.resize(val_5, false); double x0, y0, z0; double E, A, B; const unsigned int index_0 = 0; @@ -217,7 +220,8 @@ void vpSphere::changeFrame(const vpHomogeneousMatrix &cMo) { changeFrame(cMo, cP */ void vpSphere::changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP_) const { - cP_.resize(4, false); + const unsigned int val_4 = 4; + cP_.resize(val_4, false); const unsigned int index_0 = 0; const unsigned int index_1 = 1; From 2d0712215fe38dca27e654e4dc7c4ca6ff47fb75 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 27 Nov 2024 15:50:39 +0100 Subject: [PATCH 19/31] Fix build issue detected by ci and due to previous changes --- .../src/image/private/vpImageConvert_impl.h | 19 ++++++++++--------- modules/core/src/image/vpImageTools.cpp | 3 ++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/core/src/image/private/vpImageConvert_impl.h b/modules/core/src/image/private/vpImageConvert_impl.h index f5d7a17485..b3fce17d6c 100644 --- a/modules/core/src/image/private/vpImageConvert_impl.h +++ b/modules/core/src/image/private/vpImageConvert_impl.h @@ -93,7 +93,7 @@ BEGIN_VISP_NAMESPACE #endif const unsigned int val_0x10000 = 0x10000; - for (int i = 2; i < val_0x10000; ++i) { + for (unsigned int i = 2; i < val_0x10000; ++i) { histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF] } dest_depth.resize(src_depth.getHeight(), src_depth.getWidth()); @@ -151,7 +151,7 @@ void vp_createDepthHistogram(const vpImage &src_depth, vpImage &src_depth, vpImage &d } const unsigned int val_0x10000 = 0x10000; - for (int i = 2; i < val_0x10000; ++i) { + for (unsigned int i = 2; i < val_0x10000; ++i) { histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF] } -#ifdef VISP_HAVE_OPENMP -#pragma omp parallel for -#endif + const unsigned char val_uc_5 = 5; const unsigned char val_uc_20 = 20; const unsigned char val_uc_255 = 255; +#ifdef VISP_HAVE_OPENMP +#pragma omp parallel for +#endif for (int i = 0; i < src_depth_size; ++i) { uint16_t d = static_cast(src_depth.bitmap[i]); if (d) { @@ -247,13 +248,13 @@ void vp_createDepthHistogram(const vpImage &src_depth, vpImage for (unsigned int i = 2; i < val_0x10000; ++i) { histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF] } -#ifdef VISP_HAVE_OPENMP -#pragma omp parallel for -#endif const unsigned char val_uc_5 = 5; const unsigned char val_uc_20 = 20; const unsigned char val_uc_255 = 255; +#ifdef VISP_HAVE_OPENMP +#pragma omp parallel for +#endif for (int i = 0; i < src_depth_size; ++i) { uint16_t d = src_depth.bitmap[i]; if (d) { diff --git a/modules/core/src/image/vpImageTools.cpp b/modules/core/src/image/vpImageTools.cpp index 8056c746cd..9e591d7ac8 100644 --- a/modules/core/src/image/vpImageTools.cpp +++ b/modules/core/src/image/vpImageTools.cpp @@ -1217,10 +1217,11 @@ int vpImageTools::inRange(const unsigned char *hue, const unsigned char *saturat unsigned char v_high = static_cast(hsv_range[index_5]); int size_ = static_cast(size); int cpt_in_range = 0; + + const unsigned char val_uc_255 = 255; #if defined(_OPENMP) #pragma omp parallel for reduction(+:cpt_in_range) #endif - const unsigned char val_uc_255 = 255; for (int i = 0; i < size_; ++i) { bool check_h_low_high_hue = (h_low <= hue[i]) && (hue[i] <= h_high); bool check_s_low_high_saturation = (s_low <= saturation[i]) && (saturation[i] <= s_high); From 2df7042a73bcb0263770e3ccf82fad75f2c4c025 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 27 Nov 2024 16:13:42 +0100 Subject: [PATCH 20/31] Fix build issue in vpImage::performLut() Issue reported by CI vpImage_lut.h:176:43: error: out-of-line definition of 'performLut' does not match any declaration in 'vpImage' template void vpImage::performLut(const Type(&)[256], unsigned int) --- modules/core/include/visp3/core/vpImage.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/core/include/visp3/core/vpImage.h b/modules/core/include/visp3/core/vpImage.h index 7fb88c3bc4..a43bdada3a 100644 --- a/modules/core/include/visp3/core/vpImage.h +++ b/modules/core/include/visp3/core/vpImage.h @@ -330,8 +330,9 @@ template class vpImage friend std::ostream &operator<<(std::ostream &s, const vpImage &I); // Perform a look-up table transformation - static const unsigned int val_256 = 256; - void performLut(const Type(&lut)[val_256], unsigned int nbThreads = 1); + // static const unsigned int val_256 = 256; + // void performLut(const Type(&lut)[val_256], unsigned int nbThreads = 1); // Doesn't pass CI + void performLut(const Type(&lut)[256], unsigned int nbThreads = 1); // Returns a new image that's a quarter size of the current image void quarterSizeImage(vpImage &res) const; From f3b41c1073f09dfb0b8ff775e8c9faa807aa5c33 Mon Sep 17 00:00:00 2001 From: LAGNEAU Romain Date: Thu, 28 Nov 2024 14:55:24 +0100 Subject: [PATCH 21/31] [CORE] Deactivated stack change by default in Canny --- .../include/visp3/core/vpCannyEdgeDetection.h | 2 + .../core/src/image/vpCannyEdgeDetection.cpp | 47 ++++++++++--------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/modules/core/include/visp3/core/vpCannyEdgeDetection.h b/modules/core/include/visp3/core/vpCannyEdgeDetection.h index 74de78efdf..79c614d4fa 100644 --- a/modules/core/include/visp3/core/vpCannyEdgeDetection.h +++ b/modules/core/include/visp3/core/vpCannyEdgeDetection.h @@ -277,6 +277,8 @@ class VISP_EXPORT vpCannyEdgeDetection /** * \brief Set the minimum stack size, expressed in bytes, due to the recursive algorithm. + * If not called, the stack size is left at its default value when running the + * Canny edge detection algorithm. * * \note The stack size is changed back to its original value after * before leaving the detect() function. diff --git a/modules/core/src/image/vpCannyEdgeDetection.cpp b/modules/core/src/image/vpCannyEdgeDetection.cpp index 0dbf7c2dc4..c1394923bf 100644 --- a/modules/core/src/image/vpCannyEdgeDetection.cpp +++ b/modules/core/src/image/vpCannyEdgeDetection.cpp @@ -103,7 +103,7 @@ vpCannyEdgeDetection::vpCannyEdgeDetection() , m_upperThreshold(-1.f) , m_upperThresholdRatio(0.8f) #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX - , m_minStackSize(65532000) // Maximum stack size on MacOS, see https://stackoverflow.com/a/13261334 + , m_minStackSize(0) // Deactivated by default #endif , mp_mask(nullptr) { @@ -128,7 +128,7 @@ vpCannyEdgeDetection::vpCannyEdgeDetection(const int &gaussianKernelSize, const , m_upperThreshold(upperThreshold) , m_upperThresholdRatio(upperThresholdRatio) #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX - , m_minStackSize(65532000) // Maximum stack size on MacOS, see https://stackoverflow.com/a/13261334 + , m_minStackSize(0) // Deactivated by default #endif , m_storeListEdgePoints(storeEdgePoints) , mp_mask(nullptr) @@ -143,7 +143,7 @@ using json = nlohmann::json; vpCannyEdgeDetection::vpCannyEdgeDetection(const std::string &jsonPath) : #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX - m_minStackSize(65532000) // Maximum stack size on MacOS, see https://stackoverflow.com/a/13261334 + m_minStackSize(0) // Deactivated by default #endif { initFromJSON(jsonPath); @@ -255,23 +255,26 @@ vpImage vpCannyEdgeDetection::detect(const vpImage &I) { #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX - // Increase stack size due to the recursive algorithm rlim_t initialStackSize; struct rlimit rl; int result; - result = getrlimit(RLIMIT_STACK, &rl); - if (result == 0) { - initialStackSize = rl.rlim_cur; - if (rl.rlim_cur < m_minStackSize) { - rl.rlim_cur = m_minStackSize; - result = setrlimit(RLIMIT_STACK, &rl); - if (result != 0) { - throw(vpException(vpException::fatalError, "setrlimit returned result = %d\n", result)); + if (m_minStackSize > 0) { + // Check the current stack size + result = getrlimit(RLIMIT_STACK, &rl); + if (result == 0) { + initialStackSize = rl.rlim_cur; + if (rl.rlim_cur < m_minStackSize) { + // Increase stack size due to the recursive algorithm + rl.rlim_cur = m_minStackSize; + result = setrlimit(RLIMIT_STACK, &rl); + if (result != 0) { + throw(vpException(vpException::fatalError, "setrlimit returned result = %d\n", result)); + } } } - } - else { - throw(vpException(vpException::fatalError, "getrlimit returned result = %d\n", result)); + else { + throw(vpException(vpException::fatalError, "getrlimit returned result = %d\n", result)); + } } #endif // // Clearing the previous results @@ -309,13 +312,15 @@ vpCannyEdgeDetection::detect(const vpImage &I) performEdgeTracking(); #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX - // Reset stack size to its original value - if (rl.rlim_cur > initialStackSize) { - rl.rlim_cur = initialStackSize; - result = setrlimit(RLIMIT_STACK, &rl); - if (result != 0) { - throw(vpException(vpException::fatalError, "setrlimit returned result = %d\n", result)); + if (m_minStackSize > 0) { + if (rl.rlim_cur > initialStackSize) { + // Reset stack size to its original value + rl.rlim_cur = initialStackSize; + result = setrlimit(RLIMIT_STACK, &rl); + if (result != 0) { + throw(vpException(vpException::fatalError, "setrlimit returned result = %d\n", result)); + } } } #endif From 6f52d6ab9dcd76fd671250f1f2a9f27b7e3e25b0 Mon Sep 17 00:00:00 2001 From: LAGNEAU Romain Date: Thu, 28 Nov 2024 14:55:58 +0100 Subject: [PATCH 22/31] [CLEAN] Corrected compilation warning in tutorial-canny --- tutorial/image/tutorial-canny.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tutorial/image/tutorial-canny.cpp b/tutorial/image/tutorial-canny.cpp index 238b4f883a..74480de950 100644 --- a/tutorial/image/tutorial-canny.cpp +++ b/tutorial/image/tutorial-canny.cpp @@ -171,7 +171,8 @@ void checkEdgeList(const vpCannyEdgeDetection &cannyDetector, const vpImage cpyListEdgePoints = listEdgePoints; std::sort(cpyListEdgePoints.begin(), cpyListEdgePoints.end(), sortImagePoints); - std::unique(cpyListEdgePoints.begin(), cpyListEdgePoints.end()); + std::vector::iterator last = std::unique(cpyListEdgePoints.begin(), cpyListEdgePoints.end()); + static_cast(cpyListEdgePoints.erase(last, cpyListEdgePoints.end())); if (listEdgePoints.size() != cpyListEdgePoints.size()) { throw(vpException(vpException::fatalError, "There are duplicated points in the edge points list !")); } From ee3c1471a25cb64d3d4f9a06b49091b3e5530b87 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 28 Nov 2024 17:30:56 +0100 Subject: [PATCH 23/31] Fix warnings reported when -Wpedantic is used --- 3rdparty/clipper/clipper.cpp | 8 ++++---- .../simdlib/Simd/SimdBaseImageLoadPng.cpp | 3 ++- .../simdlib/Simd/SimdBaseImageSaveJpeg.cpp | 3 ++- .../simdlib/Simd/SimdBaseImageSavePng.cpp | 3 ++- 3rdparty/simdlib/Simd/SimdLib.h | 20 +++++++++---------- 3rdparty/simdlib/Simd/SimdMath.h | 4 ++-- .../core/src/image/vpCannyEdgeDetection.cpp | 2 +- modules/core/src/image/vpImageCircle.cpp | 2 +- modules/core/src/math/matrix/vpMatrix_mul.cpp | 2 +- modules/vision/include/visp3/vision/vpPose.h | 2 +- 10 files changed, 26 insertions(+), 23 deletions(-) diff --git a/3rdparty/clipper/clipper.cpp b/3rdparty/clipper/clipper.cpp index d0e5ba2577..1444408884 100644 --- a/3rdparty/clipper/clipper.cpp +++ b/3rdparty/clipper/clipper.cpp @@ -4329,10 +4329,10 @@ double DistanceFromLineSqrd( const IntPoint& pt, const IntPoint& ln1, const IntPoint& ln2) { //The equation of a line in general form (Ax + By + C = 0) - //given 2 points (x¹,y¹) & (x²,y²) is ... - //(y¹ - y²)x + (x² - x¹)y + (y² - y¹)x¹ - (x² - x¹)y¹ = 0 - //A = (y¹ - y²); B = (x² - x¹); C = (y² - y¹)x¹ - (x² - x¹)y¹ - //perpendicular distance of point (x³,y³) = (Ax³ + By³ + C)/Sqrt(A² + B²) + //given 2 points (x1,y1) & (x1,y1) is ... + //(y1 - y1)x + (x1 - x1)y + (y1 - y1)x1 - (x1 - x1)y1 = 0 + //A = (y1 - y1); B = (x2 - x1); C = (y2 - y1)x1 - (x2 - x1)y1 + //perpendicular distance of point (x3,y3) = (Ax3 + By3 + C)/Sqrt(A*A + B*B) //see http://en.wikipedia.org/wiki/Perpendicular_distance double A = double(ln1.Y - ln2.Y); double B = double(ln2.X - ln1.X); diff --git a/3rdparty/simdlib/Simd/SimdBaseImageLoadPng.cpp b/3rdparty/simdlib/Simd/SimdBaseImageLoadPng.cpp index d5fd24a6a1..548a06e05d 100644 --- a/3rdparty/simdlib/Simd/SimdBaseImageLoadPng.cpp +++ b/3rdparty/simdlib/Simd/SimdBaseImageLoadPng.cpp @@ -1148,4 +1148,5 @@ namespace Simd } } } -} \ No newline at end of file +} + diff --git a/3rdparty/simdlib/Simd/SimdBaseImageSaveJpeg.cpp b/3rdparty/simdlib/Simd/SimdBaseImageSaveJpeg.cpp index db2b86ee9b..2eac5cbcd8 100644 --- a/3rdparty/simdlib/Simd/SimdBaseImageSaveJpeg.cpp +++ b/3rdparty/simdlib/Simd/SimdBaseImageSaveJpeg.cpp @@ -601,4 +601,5 @@ namespace Simd return NULL; } } -} \ No newline at end of file +} + diff --git a/3rdparty/simdlib/Simd/SimdBaseImageSavePng.cpp b/3rdparty/simdlib/Simd/SimdBaseImageSavePng.cpp index 7b172a046f..42b066dc8c 100644 --- a/3rdparty/simdlib/Simd/SimdBaseImageSavePng.cpp +++ b/3rdparty/simdlib/Simd/SimdBaseImageSavePng.cpp @@ -376,4 +376,5 @@ namespace Simd WriteCrc32(_stream, 0); } } -} \ No newline at end of file +} + diff --git a/3rdparty/simdlib/Simd/SimdLib.h b/3rdparty/simdlib/Simd/SimdLib.h index 14a3e9205e..b396f0d39d 100644 --- a/3rdparty/simdlib/Simd/SimdLib.h +++ b/3rdparty/simdlib/Simd/SimdLib.h @@ -71,7 +71,7 @@ typedef unsigned __int64 uint64_t; typedef enum { SimdFalse = 0, /*!< False value. */ - SimdTrue = 1, /*!< True value. */ + SimdTrue = 1 /*!< True value. */ } SimdBool; /*! @ingroup c_types @@ -91,7 +91,7 @@ typedef enum /*! equal to: a < b */ SimdCompareLesser, /*! equal to: a <= b */ - SimdCompareLesserOrEqual, + SimdCompareLesserOrEqual } SimdCompareType; /*! @ingroup c_types @@ -111,7 +111,7 @@ typedef enum SimdCpuInfoAvx512bw, /*!< Availability of AVX-512BW (x86). */ SimdCpuInfoVmx, /*!< Availability of VMX or Altivec (PowerPC). */ SimdCpuInfoVsx, /*!< Availability of VSX (PowerPC). */ - SimdCpuInfoNeon, /*!< Availability of NEON (ARM). */ + SimdCpuInfoNeon /*!< Availability of NEON (ARM). */ } SimdCpuInfoType; /*! @ingroup c_types @@ -132,7 +132,7 @@ typedef enum /*! A PNG (Portable Network Graphics) image file format. */ SimdImageFilePng, /*! A JPEG (Joint Photographic Experts Group) image file format. */ - SimdImageFileJpeg, + SimdImageFileJpeg } SimdImageFileType; /*! @ingroup c_types @@ -158,7 +158,7 @@ typedef enum /*! Subtracts unsigned 8-bit integer b from unsigned 8-bit integer a (for every channel of every point of the images). */ SimdOperationBinary8uSubtraction, /*! Adds unsigned 8-bit integer b from unsigned 8-bit integer a (for every channel of every point of the images). */ - SimdOperationBinary8uAddition, + SimdOperationBinary8uAddition } SimdOperationBinary8uType; /*! @ingroup c_types @@ -189,7 +189,7 @@ typedef enum /*! A 24-bit (3 8-bit channels) RGB (Red, Green, Blue) pixel format. */ SimdPixelFormatRgb24, /*! A 32-bit (4 8-bit channels) RGBA (Red, Green, Blue, Alpha) pixel format. */ - SimdPixelFormatRgba32, + SimdPixelFormatRgba32 } SimdPixelFormatType; /*! @ingroup c_types @@ -200,7 +200,7 @@ enum SimdReduceType SimdReduce2x2, /*!< Using of function ::SimdReduceGray2x2 for image reducing. */ SimdReduce3x3, /*!< Using of function ::SimdReduceGray3x3 for image reducing. */ SimdReduce4x4, /*!< Using of function ::SimdReduceGray4x4 for image reducing. */ - SimdReduce5x5, /*!< Using of function ::SimdReduceGray5x5 for image reducing. */ + SimdReduce5x5 /*!< Using of function ::SimdReduceGray5x5 for image reducing. */ }; /*! @ingroup resizing @@ -213,7 +213,7 @@ typedef enum /*! 16-bit integer channel type. */ SimdResizeChannelShort, /*! 32-bit float channel type. */ - SimdResizeChannelFloat, + SimdResizeChannelFloat } SimdResizeChannelType; /*! @ingroup resizing @@ -236,7 +236,7 @@ typedef enum /*! Area method. */ SimdResizeMethodArea, /*! Area method for previously reduced in 2 times image. */ - SimdResizeMethodAreaFast, + SimdResizeMethodAreaFast } SimdResizeMethodType; /*! @ingroup yuv_conversion @@ -248,7 +248,7 @@ typedef enum SimdYuvBt601, /*!< Corresponds to BT.601 standard. Uses Kr=0.299, Kb=0.114. Restricts Y to range [16..235], U and V to [16..240]. */ SimdYuvBt709, /*!< Corresponds to BT.709 standard. Uses Kr=0.2126, Kb=0.0722. Restricts Y to range [16..235], U and V to [16..240]. */ SimdYuvBt2020, /*!< Corresponds to BT.2020 standard. Uses Kr=0.2627, Kb=0.0593. Restricts Y to range [16..235], U and V to [16..240]. */ - SimdYuvTrect871, /*!< Corresponds to T-REC-T.871 standard. Uses Kr=0.299, Kb=0.114. Y, U and V use full range [0..255]. */ + SimdYuvTrect871 /*!< Corresponds to T-REC-T.871 standard. Uses Kr=0.299, Kb=0.114. Y, U and V use full range [0..255]. */ } SimdYuvType; // ViSP custom SIMD code diff --git a/3rdparty/simdlib/Simd/SimdMath.h b/3rdparty/simdlib/Simd/SimdMath.h index c1851a61c0..251cf7cd3c 100644 --- a/3rdparty/simdlib/Simd/SimdMath.h +++ b/3rdparty/simdlib/Simd/SimdMath.h @@ -953,7 +953,7 @@ namespace Simd vst1q_f32(_a, a); float r[4] = { 1.0f / _a[0], 1.0f / _a[1], 1.0f / _a[2], 1.0f / _a[3] }; return vld1q_f32(r); - }; + } template<> SIMD_INLINE float32x4_t Reciprocal<0>(const float32x4_t & a) { @@ -985,7 +985,7 @@ namespace Simd vst1q_f32(_b, b); float c[4] = { _a[0] / _b[0], _a[1] / _b[1], _a[2] / _b[2], _a[3] / _b[3] }; return vld1q_f32(c); - }; + } template SIMD_INLINE float32x4_t ReciprocalSqrt(const float32x4_t & a); diff --git a/modules/core/src/image/vpCannyEdgeDetection.cpp b/modules/core/src/image/vpCannyEdgeDetection.cpp index 0dbf7c2dc4..d142a3c364 100644 --- a/modules/core/src/image/vpCannyEdgeDetection.cpp +++ b/modules/core/src/image/vpCannyEdgeDetection.cpp @@ -55,7 +55,7 @@ static void scaleFilter( } } } -}; +} #endif BEGIN_VISP_NAMESPACE diff --git a/modules/core/src/image/vpImageCircle.cpp b/modules/core/src/image/vpImageCircle.cpp index cb75dac8db..8ba135fd64 100644 --- a/modules/core/src/image/vpImageCircle.cpp +++ b/modules/core/src/image/vpImageCircle.cpp @@ -1049,7 +1049,7 @@ void incrementIfIsInMask(const vpImage &mask, const int &width, const int ++count; } } -}; +} #endif unsigned int vpImageCircle::computePixelsInMask(const vpImage &mask) const diff --git a/modules/core/src/math/matrix/vpMatrix_mul.cpp b/modules/core/src/math/matrix/vpMatrix_mul.cpp index fb54a085a2..643574f9c4 100644 --- a/modules/core/src/math/matrix/vpMatrix_mul.cpp +++ b/modules/core/src/math/matrix/vpMatrix_mul.cpp @@ -115,7 +115,7 @@ END_VISP_NAMESPACE #else // Work around to avoid warning LNK4221: This object file does not define any // previously undefined public symbols -void dummy_vpMatrix_blas() { }; +void dummy_vpMatrix_blas() { } #endif #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS diff --git a/modules/vision/include/visp3/vision/vpPose.h b/modules/vision/include/visp3/vision/vpPose.h index 752c6f8ce1..151e534523 100644 --- a/modules/vision/include/visp3/vision/vpPose.h +++ b/modules/vision/include/visp3/vision/vpPose.h @@ -95,7 +95,7 @@ class VISP_EXPORT vpPose initialized by Dementhon approach */ LAGRANGE_VIRTUAL_VS, /*!< Non linear virtual visual servoing approach initialized by Lagrange approach */ - DEMENTHON_LAGRANGE_VIRTUAL_VS, /*!< Non linear virtual visual servoing approach + DEMENTHON_LAGRANGE_VIRTUAL_VS /*!< Non linear virtual visual servoing approach initialized by either Dementhon or Lagrange approach, depending on which method has the smallest residual. */ } vpPoseMethodType; From a08f9293a55cbb1778e88a4e4625e9cf6dde6a1c Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 28 Nov 2024 18:47:20 +0100 Subject: [PATCH 24/31] Improve franka gripper tool - add missing "--release" command line option - add "--grasp-time " option to keep the force applied to the grasped object for a given duration --- example/servo-franka/frankaGripper.cpp | 36 +++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/example/servo-franka/frankaGripper.cpp b/example/servo-franka/frankaGripper.cpp index 5b98186c5f..deeccaccda 100644 --- a/example/servo-franka/frankaGripper.cpp +++ b/example/servo-franka/frankaGripper.cpp @@ -64,11 +64,12 @@ int main(int argc, char **argv) double opt_grasping_width = 0.; double opt_grasping_speed = 0.1; double opt_grasping_force = 60; + double opt_grasping_time = 0; GripperState_t opt_gripper_state = Gripper_None; for (int i = 1; i < argc; i++) { if (std::string(argv[i]) == "--ip" && i + 1 < argc) { - ++ i; + ++i; opt_robot_ip = std::string(argv[i]); } else if (std::string(argv[i]) == "--home") { @@ -80,21 +81,28 @@ int main(int argc, char **argv) else if (std::string(argv[i]) == "--close") { opt_gripper_state = Gripper_Close; } + else if (std::string(argv[i]) == "--release") { + opt_gripper_state = Gripper_Release; + } else if (std::string(argv[i]) == "--grasp" && i + 1 < argc) { - ++ i; + ++i; opt_gripper_state = Gripper_Grasp; opt_grasping_width = std::atof(argv[i]); } else if (std::string(argv[i]) == "--grasp-speed" && i + 1 < argc) { - ++ i; + ++i; opt_grasping_speed = std::atof(argv[i]); } else if (std::string(argv[i]) == "--grasp-force" && i + 1 < argc) { - ++ i; + ++i; opt_grasping_force = std::atof(argv[i]); } + else if (std::string(argv[i]) == "--grasp-time" && i + 1 < argc) { + ++i; + opt_grasping_time = std::atof(argv[i]); + } else if (std::string(argv[i]) == "--test" && i + 1 < argc) { - ++ i; + ++i; opt_gripper_state = Gripper_Test; opt_grasping_width = std::atof(argv[i]); } @@ -107,7 +115,8 @@ int main(int argc, char **argv) << " [--close]" << " [--grasp ]" << " [--grasp-speed ]" - << " [--grasp-force ]" + << " [--grasp-force ]" + << " [--grasp-time ]" << " [--release]" << " [--test ]" << " [--help] [-h]\n" << std::endl; @@ -140,6 +149,11 @@ int main(int argc, char **argv) << " Force in [N] applied during grasping." << std::endl << " Default: " << opt_grasping_force << " [N]" << std::endl << std::endl + << " --grasp-time " << std::endl + << " Duration in [s] the grasping force will be applied before releasing the object." << std::endl + << " When duration is set to -1, grasping will be applied until stopped by CTRL-C." << std::endl + << " Default: " << opt_grasping_time << " [s]" << std::endl + << std::endl << " --release" << std::endl << " Release an object that is grasped." << std::endl << std::endl @@ -191,6 +205,16 @@ int main(int argc, char **argv) else if (opt_gripper_state == Gripper_Grasp) { std::cout << "Gripper grasp " << opt_grasping_width << "m object width, with speed: " << opt_grasping_speed << " and force: " << opt_grasping_force << "N..." << std::endl; robot.gripperGrasp(opt_grasping_width, opt_grasping_speed, opt_grasping_force); + if (opt_grasping_time < 0) { + std::cout << "Hit CTRL-C to quit. The grasping force will continue to be applied..." << std::endl; + while (1) { + vpTime::sleepMs(1000); + } + } + else { + std::cout << "Wait " << 1000 * opt_grasping_time << " seconds before releasing the object" << std::endl; + vpTime::sleepMs(1000 * opt_grasping_time); + } } else if (opt_gripper_state == Gripper_Release) { std::cout << "Gripper release object..." << std::endl; From f9d886de70f56bbe7cb7b7226c7917d711276807 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Thu, 28 Nov 2024 18:49:36 +0100 Subject: [PATCH 25/31] Fix command line options management --- example/servo-franka/servoFrankaIBVS.cpp | 29 ++++++++++++------------ example/servo-franka/servoFrankaPBVS.cpp | 26 +++++++++++---------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/example/servo-franka/servoFrankaIBVS.cpp b/example/servo-franka/servoFrankaIBVS.cpp index 6b89eaf987..be6503f7ca 100644 --- a/example/servo-franka/servoFrankaIBVS.cpp +++ b/example/servo-franka/servoFrankaIBVS.cpp @@ -116,14 +116,17 @@ int main(int argc, char **argv) double convergence_threshold = 0.00005; for (int i = 1; i < argc; i++) { - if (std::string(argv[i]) == "--tag_size" && i + 1 < argc) { + if ((std::string(argv[i]) == "--tag_size") && (i + 1 < argc)) { opt_tagSize = std::stod(argv[i + 1]); + ++i; } - else if (std::string(argv[i]) == "--ip" && i + 1 < argc) { + else if ((std::string(argv[i]) == "--ip") && (i + 1 < argc)) { opt_robot_ip = std::string(argv[i + 1]); + ++i; } - else if (std::string(argv[i]) == "--eMc" && i + 1 < argc) { + else if ((std::string(argv[i]) == "--eMc") && (i + 1 < argc)) { opt_eMc_filename = std::string(argv[i + 1]); + ++i; } else if (std::string(argv[i]) == "--verbose") { opt_verbose = true; @@ -137,19 +140,20 @@ int main(int argc, char **argv) else if (std::string(argv[i]) == "--task_sequencing") { opt_task_sequencing = true; } - else if (std::string(argv[i]) == "--quad_decimate" && i + 1 < argc) { + else if ((std::string(argv[i]) == "--quad_decimate") && (i + 1 < argc)) { opt_quad_decimate = std::stoi(argv[i + 1]); + ++i; } else if (std::string(argv[i]) == "--no-convergence-threshold") { convergence_threshold = 0.; } - else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") { + else if ((std::string(argv[i]) == "--help") || (std::string(argv[i]) == "-h")) { std::cout << argv[0] << " [--ip ] [--tag_size ] [--eMc ] " << "[--quad_decimate ] [--adaptive_gain] [--plot] [--task_sequencing] [--no-convergence-threshold] [--verbose] [--help] [-h]" - << "\n"; + << std::endl; return EXIT_SUCCESS; } } @@ -182,16 +186,14 @@ int main(int argc, char **argv) ePc.loadYAML(opt_eMc_filename, ePc); } else { - std::cout << "Warning, opt_eMc_filename is empty! Use hard coded values." - << "\n"; + std::cout << "Warning, opt_eMc_filename is empty! Use hard coded values." << std::endl; } vpHomogeneousMatrix eMc(ePc); - std::cout << "eMc:\n" << eMc << "\n"; + std::cout << "eMc:\n" << eMc << std::endl; // Get camera intrinsics - vpCameraParameters cam = - rs.getCameraParameters(RS2_STREAM_COLOR, vpCameraParameters::perspectiveProjWithDistortion); - std::cout << "cam:\n" << cam << "\n"; + vpCameraParameters cam = rs.getCameraParameters(RS2_STREAM_COLOR, vpCameraParameters::perspectiveProjWithDistortion); + std::cout << "cam:\n" << cam << std::endl; vpImage I(height, width); @@ -394,8 +396,7 @@ int main(int argc, char **argv) if (error < convergence_threshold) { has_converged = true; - std::cout << "Servo task has converged" - << "\n"; + std::cout << "Servo task has converged" << std::endl; vpDisplay::displayText(I, 100, 20, "Servo task has converged", vpColor::red); } if (first_time) { diff --git a/example/servo-franka/servoFrankaPBVS.cpp b/example/servo-franka/servoFrankaPBVS.cpp index 1594db60cc..31a7e44161 100644 --- a/example/servo-franka/servoFrankaPBVS.cpp +++ b/example/servo-franka/servoFrankaPBVS.cpp @@ -114,14 +114,17 @@ int main(int argc, char **argv) double convergence_threshold_tu = 0.5; // Value in [deg] for (int i = 1; i < argc; i++) { - if (std::string(argv[i]) == "--tag_size" && i + 1 < argc) { + if ((std::string(argv[i]) == "--tag_size") && (i + 1 < argc)) { opt_tagSize = std::stod(argv[i + 1]); + ++i; } - else if (std::string(argv[i]) == "--ip" && i + 1 < argc) { + else if ((std::string(argv[i]) == "--ip") && (i + 1 < argc)) { opt_robot_ip = std::string(argv[i + 1]); + ++i; } - else if (std::string(argv[i]) == "--eMc" && i + 1 < argc) { + else if ((std::string(argv[i]) == "--eMc") && (i + 1 < argc)) { opt_eMc_filename = std::string(argv[i + 1]); + ++i; } else if (std::string(argv[i]) == "--verbose") { opt_verbose = true; @@ -135,20 +138,21 @@ int main(int argc, char **argv) else if (std::string(argv[i]) == "--task_sequencing") { opt_task_sequencing = true; } - else if (std::string(argv[i]) == "--quad_decimate" && i + 1 < argc) { + else if ((std::string(argv[i]) == "--quad_decimate") && (i + 1 < argc)) { opt_quad_decimate = std::stoi(argv[i + 1]); + ++i; } else if (std::string(argv[i]) == "--no-convergence-threshold") { convergence_threshold_t = 0.; convergence_threshold_tu = 0.; } - else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") { + else if ((std::string(argv[i]) == "--help") || (std::string(argv[i]) == "-h")) { std::cout << argv[0] << " [--ip ] [--tag_size ] [--eMc ] " << "[--quad_decimate ] [--adaptive_gain] [--plot] [--task_sequencing] [--no-convergence-threshold] [--verbose] [--help] [-h]" - << "\n"; + << std::endl; return EXIT_SUCCESS; } } @@ -181,16 +185,14 @@ int main(int argc, char **argv) ePc.loadYAML(opt_eMc_filename, ePc); } else { - std::cout << "Warning, opt_eMc_filename is empty! Use hard coded values." - << "\n"; + std::cout << "Warning, opt_eMc_filename is empty! Use hard coded values." << std::endl; } vpHomogeneousMatrix eMc(ePc); - std::cout << "eMc:\n" << eMc << "\n"; + std::cout << "eMc:\n" << eMc << std::endl; // Get camera intrinsics - vpCameraParameters cam = - rs.getCameraParameters(RS2_STREAM_COLOR, vpCameraParameters::perspectiveProjWithDistortion); - std::cout << "cam:\n" << cam << "\n"; + vpCameraParameters cam = rs.getCameraParameters(RS2_STREAM_COLOR, vpCameraParameters::perspectiveProjWithDistortion); + std::cout << "cam:\n" << cam << std::endl; vpImage I(height, width); From b9c09a10ee922bdb2eab8760e5241b52e224cafd Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Fri, 29 Nov 2024 16:23:17 +0100 Subject: [PATCH 26/31] Fix warning reported by ros ci: line 316 maybe uninitialized var --- modules/core/src/image/vpCannyEdgeDetection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/image/vpCannyEdgeDetection.cpp b/modules/core/src/image/vpCannyEdgeDetection.cpp index d023df5150..1cfe10c271 100644 --- a/modules/core/src/image/vpCannyEdgeDetection.cpp +++ b/modules/core/src/image/vpCannyEdgeDetection.cpp @@ -255,7 +255,7 @@ vpImage vpCannyEdgeDetection::detect(const vpImage &I) { #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX - rlim_t initialStackSize; + rlim_t initialStackSize = 0; struct rlimit rl; int result; if (m_minStackSize > 0) { From 67738254472ae84cb3c84dd63d13b746931785c5 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 2 Dec 2024 17:00:56 +0100 Subject: [PATCH 27/31] Modify franka destructor to be able to continue applying a force on the gripper --- modules/robot/src/real-robot/franka/vpRobotFranka.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/robot/src/real-robot/franka/vpRobotFranka.cpp b/modules/robot/src/real-robot/franka/vpRobotFranka.cpp index bfcc2de660..69f5090a84 100644 --- a/modules/robot/src/real-robot/franka/vpRobotFranka.cpp +++ b/modules/robot/src/real-robot/franka/vpRobotFranka.cpp @@ -104,8 +104,6 @@ vpRobotFranka::~vpRobotFranka() delete m_handler; if (m_gripper) { - std::cout << "Grasped object, will release it now." << std::endl; - m_gripper->stop(); delete m_gripper; } From 55e401ac06e32e50d19042dfd8118da93f0e2d9b Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 2 Dec 2024 17:01:20 +0100 Subject: [PATCH 28/31] Clean and improve helper messages --- example/servo-franka/frankaGripper.cpp | 23 +-------- example/servo-franka/servoFrankaIBVS.cpp | 63 ++++++++++++++++++++---- example/servo-franka/servoFrankaPBVS.cpp | 54 ++++++++++++++++++-- 3 files changed, 104 insertions(+), 36 deletions(-) diff --git a/example/servo-franka/frankaGripper.cpp b/example/servo-franka/frankaGripper.cpp index deeccaccda..cfc66a1888 100644 --- a/example/servo-franka/frankaGripper.cpp +++ b/example/servo-franka/frankaGripper.cpp @@ -64,7 +64,6 @@ int main(int argc, char **argv) double opt_grasping_width = 0.; double opt_grasping_speed = 0.1; double opt_grasping_force = 60; - double opt_grasping_time = 0; GripperState_t opt_gripper_state = Gripper_None; for (int i = 1; i < argc; i++) { @@ -97,10 +96,6 @@ int main(int argc, char **argv) ++i; opt_grasping_force = std::atof(argv[i]); } - else if (std::string(argv[i]) == "--grasp-time" && i + 1 < argc) { - ++i; - opt_grasping_time = std::atof(argv[i]); - } else if (std::string(argv[i]) == "--test" && i + 1 < argc) { ++i; opt_gripper_state = Gripper_Test; @@ -109,14 +104,13 @@ int main(int argc, char **argv) else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") { std::cout << "SYNOPSYS" << std::endl << " " << argv[0] - << " [--ip ]" + << " [--ip ]" << " [--home]" << " [--open]" << " [--close]" << " [--grasp ]" << " [--grasp-speed ]" << " [--grasp-force ]" - << " [--grasp-time ]" << " [--release]" << " [--test ]" << " [--help] [-h]\n" << std::endl; @@ -149,11 +143,6 @@ int main(int argc, char **argv) << " Force in [N] applied during grasping." << std::endl << " Default: " << opt_grasping_force << " [N]" << std::endl << std::endl - << " --grasp-time " << std::endl - << " Duration in [s] the grasping force will be applied before releasing the object." << std::endl - << " When duration is set to -1, grasping will be applied until stopped by CTRL-C." << std::endl - << " Default: " << opt_grasping_time << " [s]" << std::endl - << std::endl << " --release" << std::endl << " Release an object that is grasped." << std::endl << std::endl @@ -205,16 +194,6 @@ int main(int argc, char **argv) else if (opt_gripper_state == Gripper_Grasp) { std::cout << "Gripper grasp " << opt_grasping_width << "m object width, with speed: " << opt_grasping_speed << " and force: " << opt_grasping_force << "N..." << std::endl; robot.gripperGrasp(opt_grasping_width, opt_grasping_speed, opt_grasping_force); - if (opt_grasping_time < 0) { - std::cout << "Hit CTRL-C to quit. The grasping force will continue to be applied..." << std::endl; - while (1) { - vpTime::sleepMs(1000); - } - } - else { - std::cout << "Wait " << 1000 * opt_grasping_time << " seconds before releasing the object" << std::endl; - vpTime::sleepMs(1000 * opt_grasping_time); - } } else if (opt_gripper_state == Gripper_Release) { std::cout << "Gripper release object..." << std::endl; diff --git a/example/servo-franka/servoFrankaIBVS.cpp b/example/servo-franka/servoFrankaIBVS.cpp index be6503f7ca..1fd7d89f2f 100644 --- a/example/servo-franka/servoFrankaIBVS.cpp +++ b/example/servo-franka/servoFrankaIBVS.cpp @@ -116,7 +116,7 @@ int main(int argc, char **argv) double convergence_threshold = 0.00005; for (int i = 1; i < argc; i++) { - if ((std::string(argv[i]) == "--tag_size") && (i + 1 < argc)) { + if ((std::string(argv[i]) == "--tag-size") && (i + 1 < argc)) { opt_tagSize = std::stod(argv[i + 1]); ++i; } @@ -134,13 +134,13 @@ int main(int argc, char **argv) else if (std::string(argv[i]) == "--plot") { opt_plot = true; } - else if (std::string(argv[i]) == "--adaptive_gain") { + else if (std::string(argv[i]) == "--adaptive-gain") { opt_adaptive_gain = true; } - else if (std::string(argv[i]) == "--task_sequencing") { + else if (std::string(argv[i]) == "--task-sequencing") { opt_task_sequencing = true; } - else if ((std::string(argv[i]) == "--quad_decimate") && (i + 1 < argc)) { + else if ((std::string(argv[i]) == "--quad-decimate") && (i + 1 < argc)) { opt_quad_decimate = std::stoi(argv[i + 1]); ++i; } @@ -148,12 +148,57 @@ int main(int argc, char **argv) convergence_threshold = 0.; } else if ((std::string(argv[i]) == "--help") || (std::string(argv[i]) == "-h")) { - std::cout - << argv[0] << " [--ip ] [--tag_size ] [--eMc ] " - << "[--quad_decimate ] [--adaptive_gain] [--plot] [--task_sequencing] [--no-convergence-threshold] [--verbose] [--help] [-h]" + std::cout << "SYNOPSYS" << std::endl + << " " << argv[0] + << " [--ip ]" + << " [--tag-size ]" + << " [--eMc ]" + << " [--quad-decimate ]" + << " [--adaptive-gain]" + << " [--plot]" + << " [--task-sequencing]" + << " [--no-convergence-threshold]" + << " [--verbose]" + << " [--help] [-h]\n" << std::endl; + std::cout << "DESCRIPTION" << std::endl + << " Use an image-based visual-servoing scheme to position the camera in front of an Apriltag." << std::endl + << std::endl + << " --ip " << std::endl + << " Franka controller ip address" << std::endl + << " Default: " << opt_robot_ip << std::endl + << std::endl + << " --tag-size " << std::endl + << " Apriltag size in [m]." << std::endl + << " Default: " << opt_tagSize << " [m]" << std::endl + << std::endl + << " --eMc " << std::endl + << " File containing the homogeneous transformation matrix between" << std::endl + << " robot end-effector and camera frame." << std::endl + << std::endl + << " --quad-decimate " << std::endl + << " Decimation factor used during Apriltag detection." << std::endl + << " Default: " << opt_quad_decimate << std::endl + << std::endl + << " --adaptive-gain" << std::endl + << " Flag to enable adaptive gain to speed up visual servo near convergence." << std::endl + << std::endl + << " --plot" << std::endl + << " Flag to enable curve plotter." << std::endl + << std::endl + << " --task-sequencing" << std::endl + << " Flag to enable task sequencing scheme." << std::endl + << std::endl + << " --no-convergence-threshold" << std::endl + << " Flag to disable convergence threshold used to stop the visual servo." << std::endl + << std::endl + << " --verbose" << std::endl + << " Flag to enable extra verbosity." << std::endl + << std::endl + << " --help, -h" << std::endl + << " Print this helper message." << std::endl + << std::endl; + return EXIT_SUCCESS; } } diff --git a/example/servo-franka/servoFrankaPBVS.cpp b/example/servo-franka/servoFrankaPBVS.cpp index 31a7e44161..ba6edba196 100644 --- a/example/servo-franka/servoFrankaPBVS.cpp +++ b/example/servo-franka/servoFrankaPBVS.cpp @@ -147,11 +147,55 @@ int main(int argc, char **argv) convergence_threshold_tu = 0.; } else if ((std::string(argv[i]) == "--help") || (std::string(argv[i]) == "-h")) { - std::cout - << argv[0] << " [--ip ] [--tag_size ] [--eMc ] " - << "[--quad_decimate ] [--adaptive_gain] [--plot] [--task_sequencing] [--no-convergence-threshold] [--verbose] [--help] [-h]" + std::cout << "SYNOPSYS" << std::endl + << " " << argv[0] + << " [--ip ]" + << " [--tag-size ]" + << " [--eMc ]" + << " [--quad-decimate ]" + << " [--adaptive-gain]" + << " [--plot]" + << " [--task-sequencing]" + << " [--no-convergence-threshold]" + << " [--verbose]" + << " [--help] [-h]\n" + << std::endl; + std::cout << "DESCRIPTION" << std::endl + << " Use a position-based visual-servoing scheme to position the camera in front of an Apriltag." << std::endl + << std::endl + << " --ip " << std::endl + << " Franka controller ip address" << std::endl + << " Default: " << opt_robot_ip << std::endl + << std::endl + << " --tag-size " << std::endl + << " Apriltag size in [m]." << std::endl + << " Default: " << opt_tagSize << " [m]" << std::endl + << std::endl + << " --eMc " << std::endl + << " File containing the homogeneous transformation matrix between" << std::endl + << " robot end-effector and camera frame." << std::endl + << std::endl + << " --quad-decimate " << std::endl + << " Decimation factor used during Apriltag detection." << std::endl + << " Default: " << opt_quad_decimate << std::endl + << std::endl + << " --adaptive-gain" << std::endl + << " Flag to enable adaptive gain to speed up visual servo near convergence." << std::endl + << std::endl + << " --plot" << std::endl + << " Flag to enable curve plotter." << std::endl + << std::endl + << " --task-sequencing" << std::endl + << " Flag to enable task sequencing scheme." << std::endl + << std::endl + << " --no-convergence-threshold" << std::endl + << " Flag to disable convergence threshold used to stop the visual servo." << std::endl + << std::endl + << " --verbose" << std::endl + << " Flag to enable extra verbosity." << std::endl + << std::endl + << " --help, -h" << std::endl + << " Print this helper message." << std::endl << std::endl; return EXIT_SUCCESS; } From b59f16471875010e5835224cff1b2de74e10ef67 Mon Sep 17 00:00:00 2001 From: LAGNEAU Romain Date: Tue, 3 Dec 2024 16:52:20 +0100 Subject: [PATCH 29/31] [CORE] Created an implementation class for the OpenCV-based display in order to remove the inclusion of opencv in the header --- .../gui/include/visp3/gui/vpDisplayOpenCV.h | 62 +- modules/gui/src/display/vpDisplayOpenCV.cpp | 1538 +++++++++-------- 2 files changed, 794 insertions(+), 806 deletions(-) diff --git a/modules/gui/include/visp3/gui/vpDisplayOpenCV.h b/modules/gui/include/visp3/gui/vpDisplayOpenCV.h index 5779a4bcd4..3eec5aa8ec 100644 --- a/modules/gui/include/visp3/gui/vpDisplayOpenCV.h +++ b/modules/gui/include/visp3/gui/vpDisplayOpenCV.h @@ -44,9 +44,6 @@ #include #include -#include -#include - BEGIN_VISP_NAMESPACE /*! @@ -140,58 +137,6 @@ BEGIN_VISP_NAMESPACE */ class VISP_EXPORT vpDisplayOpenCV : public vpDisplay { -private: - cv::Mat m_background; - cv::Scalar *col; - cv::Scalar cvcolor; - int font; - float fontScale; - static std::vector m_listTitles; - static unsigned int m_nbWindows; - int fontHeight; - int x_move; - int y_move; - bool move; - int x_lbuttondown; - int y_lbuttondown; - bool lbuttondown; - int x_mbuttondown; - int y_mbuttondown; - bool mbuttondown; - int x_rbuttondown; - int y_rbuttondown; - bool rbuttondown; - int x_lbuttonup; - int y_lbuttonup; - bool lbuttonup; - int x_mbuttonup; - int y_mbuttonup; - bool mbuttonup; - int x_rbuttonup; - int y_rbuttonup; - bool rbuttonup; - - // private: - //#ifndef DOXYGEN_SHOULD_SKIP_THIS - // vpDisplayOpenCV(const vpDisplayOpenCV &) - // : vpDisplay(), background(), col(nullptr), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), - // fontScale(0.8f), fontHeight(10), x_move(0), y_move(0) , move(false), - // x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false), - // x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), - // x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false), - // x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), - // x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), - // x_rbuttonup(0), y_rbuttonup(0), rbuttonup(false) - // { - // throw vpException(vpException::functionNotImplementedError, "Not - // implemented!"); - // } - // vpDisplayOpenCV &operator=(const vpDisplayOpenCV &){ - // throw vpException(vpException::functionNotImplementedError, "Not - // implemented!"); return *this; - // } - //#endif - public: vpDisplayOpenCV(); vpDisplayOpenCV(int winx, int winy, const std::string &title = ""); @@ -263,9 +208,10 @@ class VISP_EXPORT vpDisplayOpenCV : public vpDisplay bool getPointerMotionEvent(vpImagePoint &ip) VP_OVERRIDE; bool getPointerPosition(vpImagePoint &ip) VP_OVERRIDE; - static void on_mouse(int event, int x, int y, int flags, void *param); - - void overlay(std::function overlay_function, double opacity); +private: + // Implementation + class Impl; + Impl *m_impl; }; END_VISP_NAMESPACE diff --git a/modules/gui/src/display/vpDisplayOpenCV.cpp b/modules/gui/src/display/vpDisplayOpenCV.cpp index 653de7caf2..4b53e811b6 100644 --- a/modules/gui/src/display/vpDisplayOpenCV.cpp +++ b/modules/gui/src/display/vpDisplayOpenCV.cpp @@ -57,6 +57,8 @@ // debug / exception #include +#include +#include #include // for CV_FILLED versus cv::FILLED #if defined(HAVE_OPENCV_IMGPROC) @@ -75,8 +77,735 @@ BEGIN_VISP_NAMESPACE -std::vector vpDisplayOpenCV::m_listTitles = std::vector(); -unsigned int vpDisplayOpenCV::m_nbWindows = 0; +#ifndef DOXYGEN_SHOULD_SKIP_THIS +class vpDisplayOpenCV::Impl +{ +private: + cv::Mat m_background; + cv::Scalar *col; + cv::Scalar cvcolor; + int font; + float fontScale; + static std::vector m_listTitles; + static unsigned int m_nbWindows; + int fontHeight; + int x_move; + int y_move; + bool move; + int x_lbuttondown; + int y_lbuttondown; + bool lbuttondown; + int x_mbuttondown; + int y_mbuttondown; + bool mbuttondown; + int x_rbuttondown; + int y_rbuttondown; + bool rbuttondown; + int x_lbuttonup; + int y_lbuttonup; + bool lbuttonup; + int x_mbuttonup; + int y_mbuttonup; + bool mbuttonup; + int x_rbuttonup; + int y_rbuttonup; + bool rbuttonup; + + friend class vpDisplayOpenCV; + +public: + Impl() : + m_background(), col(nullptr), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f), + fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false), + x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false), + x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0), + y_rbuttonup(0), rbuttonup(false) + { } + + virtual ~Impl() + { + if (col != nullptr) { + delete[] col; + col = nullptr; + } + } + + void getImage(vpImage &I) + { + // Should be optimized + vpImageConvert::convert(m_background, I); + } + + std::string init(const std::string &title, const int &windowXPosition, const int &windowYPosition) + { + int flags = cv::WINDOW_AUTOSIZE; + std::string outTitle = title; + if (outTitle.empty()) { + std::ostringstream s; + s << m_nbWindows++; + outTitle = std::string("Window ") + s.str(); + } + + bool isInList; + do { + isInList = false; + size_t i = 0; + while (i < m_listTitles.size() && !isInList) { + if (m_listTitles[i] == outTitle) { + std::ostringstream s; + s << m_nbWindows++; + outTitle = std::string("Window ") + s.str(); + isInList = true; + } + i++; + } + } while (isInList); + + m_listTitles.push_back(outTitle); + + + /* Create the window*/ + cv::namedWindow(outTitle, flags); + cv::moveWindow(outTitle.c_str(), windowXPosition, windowYPosition); + + move = false; + lbuttondown = false; + mbuttondown = false; + rbuttondown = false; + lbuttonup = false; + mbuttonup = false; + rbuttonup = false; + + cv::setMouseCallback(outTitle, on_mouse, this); + col = new cv::Scalar[vpColor::id_unknown]; + + /* Create color */ + vpColor pcolor; // Predefined colors + pcolor = vpColor::lightBlue; + col[vpColor::id_lightBlue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::blue; + col[vpColor::id_blue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::darkBlue; + col[vpColor::id_darkBlue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::lightRed; + col[vpColor::id_lightRed] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::red; + col[vpColor::id_red] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::darkRed; + col[vpColor::id_darkRed] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::lightGreen; + col[vpColor::id_lightGreen] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::green; + col[vpColor::id_green] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::darkGreen; + col[vpColor::id_darkGreen] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::yellow; + col[vpColor::id_yellow] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::cyan; + col[vpColor::id_cyan] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::orange; + col[vpColor::id_orange] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::purple; + col[vpColor::id_purple] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::white; + col[vpColor::id_white] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::black; + col[vpColor::id_black] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::lightGray; + col[vpColor::id_lightGray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::gray; + col[vpColor::id_gray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + pcolor = vpColor::darkGray; + col[vpColor::id_darkGray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); + + int thickness = 1; + cv::Size fontSize; + int baseline; + fontSize = cv::getTextSize("A", font, fontScale, thickness, &baseline); + + fontHeight = fontSize.height + baseline; + return outTitle; + } + + void closeDisplay(const std::string &title) + { + if (col != nullptr) { + delete[] col; + col = nullptr; + } + + cv::destroyWindow(title); + for (size_t i = 0; i < m_listTitles.size(); i++) { + if (title == m_listTitles[i]) { + m_listTitles.erase(m_listTitles.begin() + (long int)i); + break; + } + } + } + + void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, + const unsigned int &w, const unsigned int &h, const unsigned int &thickness, const unsigned int &scale) + { + double a = ip2.get_i() - ip1.get_i(); + double b = ip2.get_j() - ip1.get_j(); + double lg = sqrt(vpMath::sqr(a) + vpMath::sqr(b)); + + if ((std::fabs(a) <= std::numeric_limits::epsilon()) && + (std::fabs(b) <= std::numeric_limits::epsilon())) { + } + else { + a /= lg; + b /= lg; + + vpImagePoint ip3; + ip3.set_i(ip2.get_i() - w * a); + ip3.set_j(ip2.get_j() - w * b); + + vpImagePoint ip4; + ip4.set_i(ip3.get_i() - b * h); + ip4.set_j(ip3.get_j() + a * h); + + if (lg > 2 * vpImagePoint::distance(ip2, ip4)) + displayLine(ip2, ip4, color, thickness, scale); + + ip4.set_i(ip3.get_i() + b * h); + ip4.set_j(ip3.get_j() - a * h); + + if (lg > 2 * vpImagePoint::distance(ip2, ip4)) + displayLine(ip2, ip4, color, thickness, scale); + + displayLine(ip1, ip2, color, thickness, scale); + } + } + + void displayCircle(const vpImagePoint ¢er, const unsigned int &radius, const vpColor &color, const bool &fill, + const unsigned int &thickness, const unsigned int &scale) + { + int x = vpMath::round(center.get_u() / scale); + int y = vpMath::round(center.get_v() / scale); + int r = static_cast(radius / scale); + cv::Scalar cv_color; + if (color.id < vpColor::id_unknown) { + cv_color = col[color.id]; + } + else { + cv_color = CV_RGB(color.R, color.G, color.B); + } + + if (fill == false) { + int cv_thickness = static_cast(thickness); + cv::circle(m_background, cv::Point(x, y), r, cv_color, cv_thickness); + } + else { +#if VISP_HAVE_OPENCV_VERSION >= 0x030000 + int filled = cv::FILLED; +#else + int filled = CV_FILLED; +#endif + double opacity = static_cast(color.A) / 255.0; + overlay([x, y, r, cv_color, filled](cv::Mat image) { cv::circle(image, cv::Point(x, y), r, cv_color, filled); }, + opacity); + } + } + + void displayCross(const vpImagePoint &ip, const unsigned int &size, const vpColor &color, const unsigned int &thickness, const unsigned int &scale) + { + vpImagePoint top, bottom, left, right; + top.set_i(ip.get_i() - size / 2); + top.set_j(ip.get_j()); + bottom.set_i(ip.get_i() + size / 2); + bottom.set_j(ip.get_j()); + left.set_i(ip.get_i()); + left.set_j(ip.get_j() - size / 2); + right.set_i(ip.get_i()); + right.set_j(ip.get_j() + size / 2); + displayLine(top, bottom, color, thickness, scale); + displayLine(left, right, color, thickness, scale); + } + + void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, + const unsigned int &thickness, const unsigned int &scale) + { + vpImagePoint ip1_ = ip1; + vpImagePoint ip2_ = ip2; + + double size = 10. * scale; + double length = sqrt(vpMath::sqr(ip2_.get_i() - ip1_.get_i()) + vpMath::sqr(ip2_.get_j() - ip1_.get_j())); + bool vertical_line = (int)ip2_.get_j() == (int)ip1_.get_j(); + if (vertical_line) { + if (ip2_.get_i() < ip1_.get_i()) { + std::swap(ip1_, ip2_); + } + } + else if (ip2_.get_j() < ip1_.get_j()) { + std::swap(ip1_, ip2_); + } + + double diff_j = vertical_line ? 1 : ip2_.get_j() - ip1_.get_j(); + double deltaj = size / length * diff_j; + double deltai = size / length * (ip2_.get_i() - ip1_.get_i()); + double slope = (ip2_.get_i() - ip1_.get_i()) / diff_j; + double orig = ip1_.get_i() - slope * ip1_.get_j(); + + if (vertical_line) { + for (unsigned int i = (unsigned int)ip1_.get_i(); i < ip2_.get_i(); i += (unsigned int)(2 * deltai)) { + double j = ip1_.get_j(); + displayLine(vpImagePoint(i, j), vpImagePoint(i + deltai, j), color, thickness, scale); + } + } + else { + for (unsigned int j = (unsigned int)ip1_.get_j(); j < ip2_.get_j(); j += (unsigned int)(2 * deltaj)) { + double i = slope * j + orig; + displayLine(vpImagePoint(i, j), vpImagePoint(i + deltai, j + deltaj), color, thickness, scale); + } + } + } + + void displayImage(const vpImage &I, const unsigned int &scale, const unsigned int &width, const unsigned int &height) + { + int depth = CV_8U; + int channels = 3; + cv::Size size((int)width, (int)height); + if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)height || + m_background.cols != (int)width) { + m_background = cv::Mat(size, CV_MAKETYPE(depth, channels)); + } + + if (scale == 1) { + for (unsigned int i = 0; i < height; i++) { + unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * width); + for (unsigned int j = 0; j < width; j++) { + unsigned char val = I[i][j]; + *(dst_24++) = val; + *(dst_24++) = val; + *(dst_24++) = val; + } + } + } + else { + for (unsigned int i = 0; i < height; i++) { + unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * width); + for (unsigned int j = 0; j < width; j++) { + unsigned char val = I[i * scale][j * scale]; + *(dst_24++) = val; + *(dst_24++) = val; + *(dst_24++) = val; + } + } + } + } + + void displayImage(const vpImage &I, const unsigned int &scale, const unsigned int &width, const unsigned int &height) + { + int depth = CV_8U; + int channels = 3; + cv::Size size((int)width, (int)height); + if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)height || + m_background.cols != (int)width) { + m_background = cv::Mat(size, CV_MAKETYPE(depth, channels)); + } + + if (scale == 1) { + for (unsigned int i = 0; i < height; i++) { + unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * width); + for (unsigned int j = 0; j < width; j++) { + vpRGBa val = I[i][j]; + *(dst_24++) = val.B; + *(dst_24++) = val.G; + *(dst_24++) = val.R; + } + } + } + else { + for (unsigned int i = 0; i < height; i++) { + unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * width); + for (unsigned int j = 0; j < width; j++) { + vpRGBa val = I[i * scale][j * scale]; + *(dst_24++) = val.B; + *(dst_24++) = val.G; + *(dst_24++) = val.R; + } + } + } + } + + void displayImageROI(const vpImage &I, const vpImagePoint &iP, const unsigned int &w, + const unsigned int &h, const unsigned int &imgWidth, const unsigned int &imgHeight, const unsigned int &scale) + { + int depth = CV_8U; + int channels = 3; + cv::Size size((int)imgWidth, (int)imgHeight); + if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)imgHeight || + m_background.cols != (int)imgWidth) { + m_background = cv::Mat(size, CV_MAKETYPE(depth, channels)); + } + + if (scale == 1) { + unsigned int i_min = (unsigned int)iP.get_i(); + unsigned int j_min = (unsigned int)iP.get_j(); + unsigned int i_max = std::min(i_min + h, imgHeight); + unsigned int j_max = std::min(j_min + w, imgWidth); + for (unsigned int i = i_min; i < i_max; i++) { + unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * imgWidth + j_min * 3); + for (unsigned int j = j_min; j < j_max; j++) { + unsigned char val = I[i][j]; + *(dst_24++) = val; + *(dst_24++) = val; + *(dst_24++) = val; + } + } + } + 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)imgHeight); + int j_max = std::min((int)ceil((iP.get_j() + w) / scale), (int)imgWidth); + for (int i = i_min; i < i_max; i++) { + unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * imgWidth + j_min * 3); + for (int j = j_min; j < j_max; j++) { + unsigned char val = I[i * scale][j * scale]; + *(dst_24++) = val; + *(dst_24++) = val; + *(dst_24++) = val; + } + } + } + } + + void displayImageROI(const vpImage &I, const vpImagePoint &iP, const unsigned int &w, const unsigned int &h, const unsigned int &imgWidth, const unsigned int &imgHeight, const unsigned int &scale) + { + int depth = CV_8U; + int channels = 3; + cv::Size size((int)imgWidth, (int)imgHeight); + if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)imgHeight || + m_background.cols != (int)imgWidth) { + m_background = cv::Mat(size, CV_MAKETYPE(depth, channels)); + } + + if (scale == 1) { + unsigned int i_min = (unsigned int)iP.get_i(); + unsigned int j_min = (unsigned int)iP.get_j(); + unsigned int i_max = std::min(i_min + h, imgHeight); + unsigned int j_max = std::min(j_min + w, imgWidth); + for (unsigned int i = i_min; i < i_max; i++) { + unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * imgWidth + j_min * 3); + for (unsigned int j = j_min; j < j_max; j++) { + vpRGBa val = I[i][j]; + *(dst_24++) = val.B; + *(dst_24++) = val.G; + *(dst_24++) = val.R; + } + } + } + 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)imgHeight); + int j_max = std::min((int)ceil((iP.get_j() + w) / scale), (int)imgWidth); + for (int i = i_min; i < i_max; i++) { + unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * imgWidth + j_min * 3); + for (int j = j_min; j < j_max; j++) { + vpRGBa val = I[i * scale][j * scale]; + *(dst_24++) = val.B; + *(dst_24++) = val.G; + *(dst_24++) = val.R; + } + } + } + } + + void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, const unsigned int &thickness, const unsigned int &scale) + { + if (color.id < vpColor::id_unknown) { + cv::line(m_background, cv::Point(vpMath::round(ip1.get_u() / scale), vpMath::round(ip1.get_v() / scale)), + cv::Point(vpMath::round(ip2.get_u() / scale), vpMath::round(ip2.get_v() / scale)), col[color.id], + (int)thickness); + } + else { + cvcolor = CV_RGB(color.R, color.G, color.B); + cv::line(m_background, cv::Point(vpMath::round(ip1.get_u() / scale), vpMath::round(ip1.get_v() / scale)), + cv::Point(vpMath::round(ip2.get_u() / scale), vpMath::round(ip2.get_v() / scale)), cvcolor, + (int)thickness); + } + } + + void displayPoint(const vpImagePoint &ip, const vpColor &color, const unsigned int &thickness, const unsigned int &scale) + { + for (unsigned int i = 0; i < thickness; i++) { + if (color.id < vpColor::id_unknown) { + cv::line(m_background, cv::Point(vpMath::round(ip.get_u() / scale), vpMath::round(ip.get_v() / scale)), + cv::Point(vpMath::round(ip.get_u() / scale + thickness - 1), vpMath::round(ip.get_v() / scale)), + col[color.id], (int)thickness); + } + else { + cvcolor = CV_RGB(color.R, color.G, color.B); + cv::line(m_background, cv::Point(vpMath::round(ip.get_u() / scale), vpMath::round(ip.get_v() / scale)), + cv::Point(vpMath::round(ip.get_u() / scale + thickness - 1), vpMath::round(ip.get_v() / scale)), + cvcolor, (int)thickness); + } + } + } + + void displayRectangle(const vpImagePoint &topLeft, const unsigned int &w, const unsigned int &h, const vpColor &color, + const bool &fill, const unsigned int &thickness, const unsigned int &scale) + { + int left = vpMath::round(topLeft.get_u() / scale); + int top = vpMath::round(topLeft.get_v() / scale); + int right = vpMath::round((topLeft.get_u() + w) / scale); + int bottom = vpMath::round((topLeft.get_v() + h) / scale); + cv::Scalar cv_color; + if (color.id < vpColor::id_unknown) { + cv_color = col[color.id]; + } + else { + cv_color = CV_RGB(color.R, color.G, color.B); + } + + if (fill == false) { + int cv_thickness = static_cast(thickness); + cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness); + } + else { +#if VISP_HAVE_OPENCV_VERSION >= 0x030000 + int filled = cv::FILLED; +#else + int filled = CV_FILLED; +#endif + double opacity = static_cast(color.A) / 255.0; + overlay([left, top, right, bottom, cv_color, filled](cv::Mat image) { + cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled); + }, + opacity); + } + } + + void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color, const unsigned int &scale) + { + if (color.id < vpColor::id_unknown) { + cv::putText(m_background, text, + cv::Point(vpMath::round(ip.get_u() / scale), vpMath::round(ip.get_v() / scale + fontHeight)), + font, fontScale, col[color.id]); + } + else { + cvcolor = CV_RGB(color.R, color.G, color.B); + cv::putText(m_background, text, + cv::Point(vpMath::round(ip.get_u() / scale), vpMath::round(ip.get_v() / scale + fontHeight)), + font, fontScale, cvcolor); + } + } + + void flushDisplay(const std::string &title) + { + cv::imshow(title, m_background); + cv::waitKey(5); + } + + void flushDisplayROI(const std::string &title) + { + cv::imshow(title.c_str(), m_background); + cv::waitKey(5); + } + + bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, const bool &blocking, const std::string &title, const unsigned int &scale) + { + flushDisplay(title); + bool ret = false; + double u, v; + if (blocking) { + lbuttondown = false; + mbuttondown = false; + rbuttondown = false; + } + do { + if (lbuttondown) { + ret = true; + u = (unsigned int)x_lbuttondown * scale; + v = (unsigned int)y_lbuttondown * scale; + ip.set_u(u); + ip.set_v(v); + button = vpMouseButton::button1; + lbuttondown = false; + } + if (mbuttondown) { + ret = true; + u = (unsigned int)x_mbuttondown * scale; + v = (unsigned int)y_mbuttondown * scale; + ip.set_u(u); + ip.set_v(v); + button = vpMouseButton::button2; + mbuttondown = false; + } + if (rbuttondown) { + ret = true; + u = (unsigned int)x_rbuttondown * scale; + v = (unsigned int)y_rbuttondown * scale; + ip.set_u(u); + ip.set_v(v); + button = vpMouseButton::button3; + rbuttondown = false; + } + if (blocking) { + cv::waitKey(10); + } + } while (ret == false && blocking == true); + return ret; + } + + bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, const bool &blocking, const unsigned int &scale) + { + bool ret = false; + double u, v; + if (blocking) { + lbuttonup = false; + mbuttonup = false; + rbuttonup = false; + } + do { + if (lbuttonup) { + ret = true; + u = (unsigned int)x_lbuttonup * scale; + v = (unsigned int)y_lbuttonup * scale; + ip.set_u(u); + ip.set_v(v); + button = vpMouseButton::button1; + lbuttonup = false; + } + if (mbuttonup) { + ret = true; + u = (unsigned int)x_mbuttonup * scale; + v = (unsigned int)y_mbuttonup * scale; + ip.set_u(u); + ip.set_v(v); + button = vpMouseButton::button2; + mbuttonup = false; + } + if (rbuttonup) { + ret = true; + u = (unsigned int)x_rbuttonup * scale; + v = (unsigned int)y_rbuttonup * scale; + ip.set_u(u); + ip.set_v(v); + button = vpMouseButton::button3; + rbuttonup = false; + } + if (blocking) { + cv::waitKey(10); + } + } while (ret == false && blocking == true); + return ret; + } + + bool getPointerMotionEvent(vpImagePoint &ip, const unsigned int &scale) + { + bool ret = false; + if (move) { + ret = true; + double u = (unsigned int)x_move / scale; + double v = (unsigned int)y_move / scale; + ip.set_u(u); + ip.set_v(v); + move = false; + } + return ret; + } + + void getPointerPosition(vpImagePoint &ip, const unsigned int &scale) + { + bool moved = getPointerMotionEvent(ip, scale); + if (!moved) { + double u, v; + u = (unsigned int)x_move / scale; + v = (unsigned int)y_move / scale; + ip.set_u(u); + ip.set_v(v); + } + } + + static void on_mouse(int event, int x, int y, int /*flags*/, void *display) + { + Impl *disp = static_cast(display); + + switch (event) { + case cv::EVENT_MOUSEMOVE: + { + disp->move = true; + disp->x_move = x; + disp->y_move = y; + break; + } + case cv::EVENT_LBUTTONDOWN: + { + disp->lbuttondown = true; + disp->x_lbuttondown = x; + disp->y_lbuttondown = y; + break; + } + case cv::EVENT_MBUTTONDOWN: + { + disp->mbuttondown = true; + disp->x_mbuttondown = x; + disp->y_mbuttondown = y; + break; + } + case cv::EVENT_RBUTTONDOWN: + { + disp->rbuttondown = true; + disp->x_rbuttondown = x; + disp->y_rbuttondown = y; + break; + } + case cv::EVENT_LBUTTONUP: + { + disp->lbuttonup = true; + disp->x_lbuttonup = x; + disp->y_lbuttonup = y; + break; + } + case cv::EVENT_MBUTTONUP: + { + disp->mbuttonup = true; + disp->x_mbuttonup = x; + disp->y_mbuttonup = y; + break; + } + case cv::EVENT_RBUTTONUP: + { + disp->rbuttonup = true; + disp->x_rbuttonup = x; + disp->y_rbuttonup = y; + break; + } + + default: + break; + } + } + + void overlay(std::function overlay_function, const double &opacity) + { + // Initialize overlay layer for transparency + cv::Mat overlay; + if (opacity < 1.0) { + // Deep copy + overlay = m_background.clone(); + } + else { + // Shallow copy + overlay = m_background; + } + + overlay_function(overlay); + + // Blend background and overlay + if (opacity < 1.0) { + cv::addWeighted(overlay, opacity, m_background, 1.0 - opacity, 0.0, m_background); + } + } +}; + +std::vector vpDisplayOpenCV::Impl::m_listTitles = std::vector(); +unsigned int vpDisplayOpenCV::Impl::m_nbWindows = 0; +#endif // DOXYGEN_SHOULD_SKIP_THIS /*! @@ -100,12 +829,8 @@ unsigned int vpDisplayOpenCV::m_nbWindows = 0; */ vpDisplayOpenCV::vpDisplayOpenCV(vpImage &I, vpScaleType scaleType) - : vpDisplay(), - m_background(), col(nullptr), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f), - fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false), - x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false), - x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0), - y_rbuttonup(0), rbuttonup(false) + : vpDisplay() + , m_impl(new Impl()) { setScale(scaleType, I.getWidth(), I.getHeight()); init(I); @@ -136,12 +861,8 @@ vpDisplayOpenCV::vpDisplayOpenCV(vpImage &I, vpScaleType scaleTyp */ vpDisplayOpenCV::vpDisplayOpenCV(vpImage &I, int x, int y, const std::string &title, vpScaleType scaleType) - : vpDisplay(), - m_background(), col(nullptr), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f), - fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false), - x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false), - x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0), - y_rbuttonup(0), rbuttonup(false) + : vpDisplay() + , m_impl(new Impl()) { setScale(scaleType, I.getWidth(), I.getHeight()); init(I, x, y, title); @@ -166,12 +887,8 @@ vpDisplayOpenCV::vpDisplayOpenCV(vpImage &I, int x, int y, const and the columns. */ vpDisplayOpenCV::vpDisplayOpenCV(vpImage &I, vpScaleType scaleType) - : - m_background(), col(nullptr), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f), - fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false), - x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false), - x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0), - y_rbuttonup(0), rbuttonup(false) + : vpDisplay() + , m_impl(new Impl()) { setScale(scaleType, I.getWidth(), I.getHeight()); init(I); @@ -198,12 +915,8 @@ vpDisplayOpenCV::vpDisplayOpenCV(vpImage &I, vpScaleType scaleType) and the columns. */ vpDisplayOpenCV::vpDisplayOpenCV(vpImage &I, int x, int y, const std::string &title, vpScaleType scaleType) - : - m_background(), col(nullptr), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f), - fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false), - x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false), - x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0), - y_rbuttonup(0), rbuttonup(false) + : vpDisplay() + , m_impl(new Impl()) { setScale(scaleType, I.getWidth(), I.getHeight()); init(I, x, y, title); @@ -236,12 +949,8 @@ vpDisplayOpenCV::vpDisplayOpenCV(vpImage &I, int x, int y, const std::st \endcode */ vpDisplayOpenCV::vpDisplayOpenCV(int x, int y, const std::string &title) - : - m_background(), col(nullptr), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f), - fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false), - x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false), - x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0), - y_rbuttonup(0), rbuttonup(false) + : vpDisplay() + , m_impl(new Impl()) { m_windowXPosition = x; m_windowYPosition = y; @@ -251,17 +960,17 @@ vpDisplayOpenCV::vpDisplayOpenCV(int x, int y, const std::string &title) } else { std::ostringstream s; - s << m_nbWindows++; + s << vpDisplayOpenCV::Impl::m_nbWindows++; m_title = std::string("Window ") + s.str(); } bool isInList; do { isInList = false; - for (size_t i = 0; i < m_listTitles.size(); i++) { - if (m_listTitles[i] == m_title) { + for (size_t i = 0; i < vpDisplayOpenCV::Impl::m_listTitles.size(); i++) { + if (vpDisplayOpenCV::Impl::m_listTitles[i] == m_title) { std::ostringstream s; - s << m_nbWindows++; + s << vpDisplayOpenCV::Impl::m_nbWindows++; m_title = std::string("Window ") + s.str(); isInList = true; break; @@ -269,7 +978,7 @@ vpDisplayOpenCV::vpDisplayOpenCV(int x, int y, const std::string &title) } } while (isInList); - m_listTitles.push_back(m_title); + vpDisplayOpenCV::Impl::m_listTitles.push_back(m_title); } /*! @@ -296,12 +1005,8 @@ vpDisplayOpenCV::vpDisplayOpenCV(int x, int y, const std::string &title) \endcode */ vpDisplayOpenCV::vpDisplayOpenCV() - : - m_background(), col(nullptr), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f), - fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false), - x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false), - x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0), - y_rbuttonup(0), rbuttonup(false) + : vpDisplay() + , m_impl(new Impl()) { } /*! @@ -310,6 +1015,7 @@ vpDisplayOpenCV::vpDisplayOpenCV() vpDisplayOpenCV::~vpDisplayOpenCV() { closeDisplay(); + delete m_impl; } /*! @@ -375,96 +1081,14 @@ void vpDisplayOpenCV::init(unsigned int w, unsigned int h, int x, int y, const s if (y != -1) { this->m_windowYPosition = y; } - int flags = cv::WINDOW_AUTOSIZE; if (m_title.empty()) { if (!title.empty()) { m_title = std::string(title); } - else { - - std::ostringstream s; - s << m_nbWindows++; - m_title = std::string("Window ") + s.str(); - } - - bool isInList; - do { - isInList = false; - for (size_t i = 0; i < m_listTitles.size(); i++) { - if (m_listTitles[i] == m_title) { - std::ostringstream s; - s << m_nbWindows++; - m_title = std::string("Window ") + s.str(); - isInList = true; - break; - } - } - } while (isInList); + } + m_title = m_impl->init(m_title, m_windowXPosition, m_windowYPosition); - m_listTitles.push_back(m_title); - } - - /* Create the window*/ - cv::namedWindow(this->m_title, flags); - cv::moveWindow(this->m_title.c_str(), this->m_windowXPosition, this->m_windowYPosition); - - move = false; - lbuttondown = false; - mbuttondown = false; - rbuttondown = false; - lbuttonup = false; - mbuttonup = false; - rbuttonup = false; - - cv::setMouseCallback(this->m_title, on_mouse, this); - col = new cv::Scalar[vpColor::id_unknown]; - - /* Create color */ - vpColor pcolor; // Predefined colors - pcolor = vpColor::lightBlue; - col[vpColor::id_lightBlue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::blue; - col[vpColor::id_blue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::darkBlue; - col[vpColor::id_darkBlue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::lightRed; - col[vpColor::id_lightRed] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::red; - col[vpColor::id_red] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::darkRed; - col[vpColor::id_darkRed] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::lightGreen; - col[vpColor::id_lightGreen] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::green; - col[vpColor::id_green] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::darkGreen; - col[vpColor::id_darkGreen] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::yellow; - col[vpColor::id_yellow] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::cyan; - col[vpColor::id_cyan] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::orange; - col[vpColor::id_orange] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::purple; - col[vpColor::id_purple] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::white; - col[vpColor::id_white] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::black; - col[vpColor::id_black] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::lightGray; - col[vpColor::id_lightGray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::gray; - col[vpColor::id_gray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - pcolor = vpColor::darkGray; - col[vpColor::id_darkGray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B); - - int thickness = 1; - cv::Size fontSize; - int baseline; - fontSize = cv::getTextSize("A", font, fontScale, thickness, &baseline); - - fontHeight = fontSize.height + baseline; m_displayHasBeenInitialized = true; } @@ -520,6 +1144,7 @@ void vpDisplayOpenCV::setWindowPosition(int winx, int winy) throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); } } + /*! Display the gray level image \e I (8bits). @@ -534,36 +1159,7 @@ void vpDisplayOpenCV::setWindowPosition(int winx, int winy) void vpDisplayOpenCV::displayImage(const vpImage &I) { if (m_displayHasBeenInitialized) { - int depth = CV_8U; - int channels = 3; - cv::Size size((int)m_width, (int)m_height); - if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height || - m_background.cols != (int)m_width) { - m_background = cv::Mat(size, CV_MAKETYPE(depth, channels)); - } - - if (m_scale == 1) { - for (unsigned int i = 0; i < m_height; i++) { - unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width); - for (unsigned int j = 0; j < m_width; j++) { - unsigned char val = I[i][j]; - *(dst_24++) = val; - *(dst_24++) = val; - *(dst_24++) = val; - } - } - } - else { - for (unsigned int i = 0; i < m_height; i++) { - unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width); - for (unsigned int j = 0; j < m_width; j++) { - unsigned char val = I[i * m_scale][j * m_scale]; - *(dst_24++) = val; - *(dst_24++) = val; - *(dst_24++) = val; - } - } - } + m_impl->displayImage(I, m_scale, m_width, m_height); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -589,44 +1185,7 @@ void vpDisplayOpenCV::displayImageROI(const vpImage &I, const vpI unsigned int h) { if (m_displayHasBeenInitialized) { - int depth = CV_8U; - int channels = 3; - cv::Size size((int)m_width, (int)m_height); - if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height || - m_background.cols != (int)m_width) { - m_background = cv::Mat(size, CV_MAKETYPE(depth, channels)); - } - - if (m_scale == 1) { - unsigned int i_min = (unsigned int)iP.get_i(); - unsigned int j_min = (unsigned int)iP.get_j(); - unsigned int i_max = std::min(i_min + h, m_height); - unsigned int j_max = std::min(j_min + w, m_width); - for (unsigned int i = i_min; i < i_max; i++) { - unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width + j_min * 3); - for (unsigned int j = j_min; j < j_max; j++) { - unsigned char val = I[i][j]; - *(dst_24++) = val; - *(dst_24++) = val; - *(dst_24++) = val; - } - } - } - else { - int i_min = std::max((int)ceil(iP.get_i() / m_scale), 0); - int j_min = std::max((int)ceil(iP.get_j() / m_scale), 0); - int i_max = std::min((int)ceil((iP.get_i() + h) / m_scale), (int)m_height); - int j_max = std::min((int)ceil((iP.get_j() + w) / m_scale), (int)m_width); - for (int i = i_min; i < i_max; i++) { - unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width + j_min * 3); - for (int j = j_min; j < j_max; j++) { - unsigned char val = I[i * m_scale][j * m_scale]; - *(dst_24++) = val; - *(dst_24++) = val; - *(dst_24++) = val; - } - } - } + m_impl->displayImageROI(I, iP, w, h, m_width, m_height, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -648,36 +1207,7 @@ void vpDisplayOpenCV::displayImage(const vpImage &I) { if (m_displayHasBeenInitialized) { - int depth = CV_8U; - int channels = 3; - cv::Size size((int)this->m_width, (int)this->m_height); - if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height || - m_background.cols != (int)m_width) { - m_background = cv::Mat(size, CV_MAKETYPE(depth, channels)); - } - - if (m_scale == 1) { - for (unsigned int i = 0; i < m_height; i++) { - unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width); - for (unsigned int j = 0; j < m_width; j++) { - vpRGBa val = I[i][j]; - *(dst_24++) = val.B; - *(dst_24++) = val.G; - *(dst_24++) = val.R; - } - } - } - else { - for (unsigned int i = 0; i < m_height; i++) { - unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width); - for (unsigned int j = 0; j < m_width; j++) { - vpRGBa val = I[i * m_scale][j * m_scale]; - *(dst_24++) = val.B; - *(dst_24++) = val.G; - *(dst_24++) = val.R; - } - } - } + m_impl->displayImage(I, m_scale, m_width, m_height); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -702,44 +1232,7 @@ void vpDisplayOpenCV::displayImage(const vpImage &I) void vpDisplayOpenCV::displayImageROI(const vpImage &I, const vpImagePoint &iP, unsigned int w, unsigned int h) { if (m_displayHasBeenInitialized) { - int depth = CV_8U; - int channels = 3; - cv::Size size((int)this->m_width, (int)this->m_height); - if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height || - m_background.cols != (int)m_width) { - m_background = cv::Mat(size, CV_MAKETYPE(depth, channels)); - } - - if (m_scale == 1) { - unsigned int i_min = (unsigned int)iP.get_i(); - unsigned int j_min = (unsigned int)iP.get_j(); - unsigned int i_max = std::min(i_min + h, m_height); - unsigned int j_max = std::min(j_min + w, m_width); - for (unsigned int i = i_min; i < i_max; i++) { - unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width + j_min * 3); - for (unsigned int j = j_min; j < j_max; j++) { - vpRGBa val = I[i][j]; - *(dst_24++) = val.B; - *(dst_24++) = val.G; - *(dst_24++) = val.R; - } - } - } - else { - int i_min = std::max((int)ceil(iP.get_i() / m_scale), 0); - int j_min = std::max((int)ceil(iP.get_j() / m_scale), 0); - int i_max = std::min((int)ceil((iP.get_i() + h) / m_scale), (int)m_height); - int j_max = std::min((int)ceil((iP.get_j() + w) / m_scale), (int)m_width); - for (int i = i_min; i < i_max; i++) { - unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width + j_min * 3); - for (int j = j_min; j < j_max; j++) { - vpRGBa val = I[i * m_scale][j * m_scale]; - *(dst_24++) = val.B; - *(dst_24++) = val.G; - *(dst_24++) = val.R; - } - } - } + m_impl->displayImageROI(I, iP, w, h, m_width, m_height, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -765,18 +1258,8 @@ void vpDisplayOpenCV::displayImage(const unsigned char * /* I */) */ void vpDisplayOpenCV::closeDisplay() { - if (col != nullptr) { - delete[] col; - col = nullptr; - } if (m_displayHasBeenInitialized) { - cv::destroyWindow(this->m_title); - for (size_t i = 0; i < m_listTitles.size(); i++) { - if (m_title == m_listTitles[i]) { - m_listTitles.erase(m_listTitles.begin() + (long int)i); - break; - } - } + m_impl->closeDisplay(m_title); m_title.clear(); @@ -792,8 +1275,7 @@ void vpDisplayOpenCV::closeDisplay() void vpDisplayOpenCV::flushDisplay() { if (m_displayHasBeenInitialized) { - cv::imshow(this->m_title, m_background); - cv::waitKey(5); + m_impl->flushDisplay(m_title); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -809,8 +1291,7 @@ void vpDisplayOpenCV::flushDisplayROI(const vpImagePoint & /*iP*/, const unsigne const unsigned int /*height*/) { if (m_displayHasBeenInitialized) { - cv::imshow(this->m_title.c_str(), m_background); - cv::waitKey(5); + m_impl->flushDisplayROI(m_title); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -836,38 +1317,7 @@ void vpDisplayOpenCV::displayArrow(const vpImagePoint &ip1, const vpImagePoint & unsigned int w, unsigned int h, unsigned int thickness) { if (m_displayHasBeenInitialized) { - double a = ip2.get_i() - ip1.get_i(); - double b = ip2.get_j() - ip1.get_j(); - double lg = sqrt(vpMath::sqr(a) + vpMath::sqr(b)); - - // if ((a==0)&&(b==0)) - if ((std::fabs(a) <= std::numeric_limits::epsilon()) && - (std::fabs(b) <= std::numeric_limits::epsilon())) { - // DisplayCrossLarge(i1,j1,3,col) ; - } - else { - a /= lg; - b /= lg; - - vpImagePoint ip3; - ip3.set_i(ip2.get_i() - w * a); - ip3.set_j(ip2.get_j() - w * b); - - vpImagePoint ip4; - ip4.set_i(ip3.get_i() - b * h); - ip4.set_j(ip3.get_j() + a * h); - - if (lg > 2 * vpImagePoint::distance(ip2, ip4)) - displayLine(ip2, ip4, color, thickness); - - ip4.set_i(ip3.get_i() + b * h); - ip4.set_j(ip3.get_j() - a * h); - - if (lg > 2 * vpImagePoint::distance(ip2, ip4)) - displayLine(ip2, ip4, color, thickness); - - displayLine(ip1, ip2, color, thickness); - } + m_impl->displayArrow(ip1, ip2, color, w, h, thickness, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -888,22 +1338,13 @@ void vpDisplayOpenCV::displayArrow(const vpImagePoint &ip1, const vpImagePoint & void vpDisplayOpenCV::displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color) { if (m_displayHasBeenInitialized) { - if (color.id < vpColor::id_unknown) { - cv::putText(m_background, text, - cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)), - font, fontScale, col[color.id]); - } - else { - cvcolor = CV_RGB(color.R, color.G, color.B); - cv::putText(m_background, text, - cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)), - font, fontScale, cvcolor); - } + m_impl->displayText(ip, text, color, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); } } + /*! Display a circle. \param center : Circle center position. @@ -920,31 +1361,7 @@ void vpDisplayOpenCV::displayCircle(const vpImagePoint ¢er, unsigned int rad unsigned int thickness) { if (m_displayHasBeenInitialized) { - int x = vpMath::round(center.get_u() / m_scale); - int y = vpMath::round(center.get_v() / m_scale); - int r = static_cast(radius / m_scale); - cv::Scalar cv_color; - if (color.id < vpColor::id_unknown) { - cv_color = col[color.id]; - } - else { - cv_color = CV_RGB(color.R, color.G, color.B); - } - - if (fill == false) { - int cv_thickness = static_cast(thickness); - cv::circle(m_background, cv::Point(x, y), r, cv_color, cv_thickness); - } - else { -#if VISP_HAVE_OPENCV_VERSION >= 0x030000 - int filled = cv::FILLED; -#else - int filled = CV_FILLED; -#endif - double opacity = static_cast(color.A) / 255.0; - overlay([x, y, r, cv_color, filled](cv::Mat image) { cv::circle(image, cv::Point(x, y), r, cv_color, filled); }, - opacity); - } + m_impl->displayCircle(center, radius, color, fill, thickness, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -962,17 +1379,7 @@ void vpDisplayOpenCV::displayCross(const vpImagePoint &ip, unsigned int size, co unsigned int thickness) { if (m_displayHasBeenInitialized) { - vpImagePoint top, bottom, left, right; - top.set_i(ip.get_i() - size / 2); - top.set_j(ip.get_j()); - bottom.set_i(ip.get_i() + size / 2); - bottom.set_j(ip.get_j()); - left.set_i(ip.get_i()); - left.set_j(ip.get_j() - size / 2); - right.set_i(ip.get_i()); - right.set_j(ip.get_j() + size / 2); - displayLine(top, bottom, color, thickness); - displayLine(left, right, color, thickness); + m_impl->displayCross(ip, size, color, thickness, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -983,46 +1390,14 @@ void vpDisplayOpenCV::displayCross(const vpImagePoint &ip, unsigned int size, co Display a dashed line from image point \e ip1 to image point \e ip2. \param ip1,ip2 : Initial and final image points. - \param color : Line color. - \param thickness : Line thickness. -*/ -void vpDisplayOpenCV::displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, - unsigned int thickness) -{ - if (m_displayHasBeenInitialized) { - vpImagePoint ip1_ = ip1; - vpImagePoint ip2_ = ip2; - - double size = 10. * m_scale; - double length = sqrt(vpMath::sqr(ip2_.get_i() - ip1_.get_i()) + vpMath::sqr(ip2_.get_j() - ip1_.get_j())); - bool vertical_line = (int)ip2_.get_j() == (int)ip1_.get_j(); - if (vertical_line) { - if (ip2_.get_i() < ip1_.get_i()) { - std::swap(ip1_, ip2_); - } - } - else if (ip2_.get_j() < ip1_.get_j()) { - std::swap(ip1_, ip2_); - } - - double diff_j = vertical_line ? 1 : ip2_.get_j() - ip1_.get_j(); - double deltaj = size / length * diff_j; - double deltai = size / length * (ip2_.get_i() - ip1_.get_i()); - double slope = (ip2_.get_i() - ip1_.get_i()) / diff_j; - double orig = ip1_.get_i() - slope * ip1_.get_j(); - - if (vertical_line) { - for (unsigned int i = (unsigned int)ip1_.get_i(); i < ip2_.get_i(); i += (unsigned int)(2 * deltai)) { - double j = ip1_.get_j(); - displayLine(vpImagePoint(i, j), vpImagePoint(i + deltai, j), color, thickness); - } - } - else { - for (unsigned int j = (unsigned int)ip1_.get_j(); j < ip2_.get_j(); j += (unsigned int)(2 * deltaj)) { - double i = slope * j + orig; - displayLine(vpImagePoint(i, j), vpImagePoint(i + deltai, j + deltaj), color, thickness); - } - } + \param color : Line color. + \param thickness : Line thickness. +*/ +void vpDisplayOpenCV::displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, + unsigned int thickness) +{ + if (m_displayHasBeenInitialized) { + m_impl->displayDotLine(ip1, ip2, color, thickness, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -1039,17 +1414,7 @@ void vpDisplayOpenCV::displayLine(const vpImagePoint &ip1, const vpImagePoint &i unsigned int thickness) { if (m_displayHasBeenInitialized) { - if (color.id < vpColor::id_unknown) { - cv::line(m_background, cv::Point(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)), - cv::Point(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), col[color.id], - (int)thickness); - } - else { - cvcolor = CV_RGB(color.R, color.G, color.B); - cv::line(m_background, cv::Point(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)), - cv::Point(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), cvcolor, - (int)thickness); - } + m_impl->displayLine(ip1, ip2, color, thickness, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -1065,19 +1430,7 @@ void vpDisplayOpenCV::displayLine(const vpImagePoint &ip1, const vpImagePoint &i void vpDisplayOpenCV::displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness) { if (m_displayHasBeenInitialized) { - for (unsigned int i = 0; i < thickness; i++) { - if (color.id < vpColor::id_unknown) { - cv::line(m_background, cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)), - cv::Point(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)), - col[color.id], (int)thickness); - } - else { - cvcolor = CV_RGB(color.R, color.G, color.B); - cv::line(m_background, cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)), - cv::Point(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)), - cvcolor, (int)thickness); - } - } + m_impl->displayPoint(ip, color, thickness, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -1103,34 +1456,7 @@ void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, unsigned int const vpColor &color, bool fill, unsigned int thickness) { if (m_displayHasBeenInitialized) { - int left = vpMath::round(topLeft.get_u() / m_scale); - int top = vpMath::round(topLeft.get_v() / m_scale); - int right = vpMath::round((topLeft.get_u() + w) / m_scale); - int bottom = vpMath::round((topLeft.get_v() + h) / m_scale); - cv::Scalar cv_color; - if (color.id < vpColor::id_unknown) { - cv_color = col[color.id]; - } - else { - cv_color = CV_RGB(color.R, color.G, color.B); - } - - if (fill == false) { - int cv_thickness = static_cast(thickness); - cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness); - } - else { -#if VISP_HAVE_OPENCV_VERSION >= 0x030000 - int filled = cv::FILLED; -#else - int filled = CV_FILLED; -#endif - double opacity = static_cast(color.A) / 255.0; - overlay([left, top, right, bottom, cv_color, filled](cv::Mat image) { - cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled); - }, - opacity); - } + m_impl->displayRectangle(topLeft, w, h, color, fill, thickness, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -1154,34 +1480,9 @@ void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, const vpImag const vpColor &color, bool fill, unsigned int thickness) { if (m_displayHasBeenInitialized) { - int left = vpMath::round(topLeft.get_u() / m_scale); - int top = vpMath::round(topLeft.get_v() / m_scale); - int right = vpMath::round(bottomRight.get_u() / m_scale); - int bottom = vpMath::round(bottomRight.get_v() / m_scale); - cv::Scalar cv_color; - if (color.id < vpColor::id_unknown) { - cv_color = col[color.id]; - } - else { - cv_color = CV_RGB(color.R, color.G, color.B); - } - - if (fill == false) { - int cv_thickness = static_cast(thickness); - cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness); - } - else { -#if VISP_HAVE_OPENCV_VERSION >= 0x030000 - int filled = cv::FILLED; -#else - int filled = CV_FILLED; -#endif - double opacity = static_cast(color.A) / 255.0; - overlay([left, top, right, bottom, cv_color, filled](cv::Mat image) { - cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled); - }, - opacity); - } + unsigned int w = bottomRight.get_u() - topLeft.get_u() + 1; + unsigned int h = bottomRight.get_v() - topLeft.get_v() + 1; + displayRectangle(topLeft, w, h, color, fill, thickness); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -1204,34 +1505,7 @@ void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, const vpImag void vpDisplayOpenCV::displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill, unsigned int thickness) { if (m_displayHasBeenInitialized) { - int left = vpMath::round(rectangle.getLeft() / m_scale); - int top = vpMath::round(rectangle.getTop() / m_scale); - int right = vpMath::round(rectangle.getRight() / m_scale); - int bottom = vpMath::round(rectangle.getBottom() / m_scale); - cv::Scalar cv_color; - if (color.id < vpColor::id_unknown) { - cv_color = col[color.id]; - } - else { - cv_color = CV_RGB(color.R, color.G, color.B); - } - - if (fill == false) { - int cv_thickness = static_cast(thickness); - cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness); - } - else { -#if VISP_HAVE_OPENCV_VERSION >= 0x030000 - int filled = cv::FILLED; -#else - int filled = CV_FILLED; -#endif - double opacity = static_cast(color.A) / 255.0; - overlay([left, top, right, bottom, cv_color, filled](cv::Mat image) { - cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled); - }, - opacity); - } + displayRectangle(rectangle.getTopLeft(), rectangle.getWidth(), rectangle.getHeight(), color, fill, thickness); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -1257,29 +1531,9 @@ bool vpDisplayOpenCV::getClick(bool blocking) { bool ret = false; if (m_displayHasBeenInitialized) { - flushDisplay(); - if (blocking) { - lbuttondown = false; - mbuttondown = false; - rbuttondown = false; - } - do { - if (lbuttondown) { - ret = true; - lbuttondown = false; - } - if (mbuttondown) { - ret = true; - mbuttondown = false; - } - if (rbuttondown) { - ret = true; - rbuttondown = false; - } - if (blocking) { - cv::waitKey(10); - } - } while (ret == false && blocking == true); + vpImagePoint ip; + vpMouseButton::vpMouseButtonType button; + ret = getClick(ip, button, blocking); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -1307,44 +1561,8 @@ bool vpDisplayOpenCV::getClick(vpImagePoint &ip, bool blocking) bool ret = false; if (m_displayHasBeenInitialized) { - flushDisplay(); - - double u, v; - - if (blocking) { - lbuttondown = false; - mbuttondown = false; - rbuttondown = false; - } - do { - if (lbuttondown) { - ret = true; - u = (unsigned int)x_lbuttondown * m_scale; - v = (unsigned int)y_lbuttondown * m_scale; - ip.set_u(u); - ip.set_v(v); - lbuttondown = false; - } - if (mbuttondown) { - ret = true; - u = (unsigned int)x_mbuttondown * m_scale; - v = (unsigned int)y_mbuttondown * m_scale; - ip.set_u(u); - ip.set_v(v); - mbuttondown = false; - } - if (rbuttondown) { - ret = true; - u = (unsigned int)x_rbuttondown * m_scale; - v = (unsigned int)y_rbuttondown * m_scale; - ip.set_u(u); - ip.set_v(v); - rbuttondown = false; - } - if (blocking) { - cv::waitKey(10); - } - } while (ret == false && blocking == true); + vpMouseButton::vpMouseButtonType button; + ret = getClick(ip, button, blocking); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -1375,45 +1593,7 @@ bool vpDisplayOpenCV::getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonTyp bool ret = false; if (m_displayHasBeenInitialized) { - // flushDisplay() ; - double u, v; - if (blocking) { - lbuttondown = false; - mbuttondown = false; - rbuttondown = false; - } - do { - if (lbuttondown) { - ret = true; - u = (unsigned int)x_lbuttondown * m_scale; - v = (unsigned int)y_lbuttondown * m_scale; - ip.set_u(u); - ip.set_v(v); - button = vpMouseButton::button1; - lbuttondown = false; - } - if (mbuttondown) { - ret = true; - u = (unsigned int)x_mbuttondown * m_scale; - v = (unsigned int)y_mbuttondown * m_scale; - ip.set_u(u); - ip.set_v(v); - button = vpMouseButton::button2; - mbuttondown = false; - } - if (rbuttondown) { - ret = true; - u = (unsigned int)x_rbuttondown * m_scale; - v = (unsigned int)y_rbuttondown * m_scale; - ip.set_u(u); - ip.set_v(v); - button = vpMouseButton::button3; - rbuttondown = false; - } - if (blocking) { - cv::waitKey(10); - } - } while (ret == false && blocking == true); + ret = m_impl->getClick(ip, button, blocking, m_title, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -1446,45 +1626,7 @@ bool vpDisplayOpenCV::getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonT { bool ret = false; if (m_displayHasBeenInitialized) { - // flushDisplay() ; - double u, v; - if (blocking) { - lbuttonup = false; - mbuttonup = false; - rbuttonup = false; - } - do { - if (lbuttonup) { - ret = true; - u = (unsigned int)x_lbuttonup * m_scale; - v = (unsigned int)y_lbuttonup * m_scale; - ip.set_u(u); - ip.set_v(v); - button = vpMouseButton::button1; - lbuttonup = false; - } - if (mbuttonup) { - ret = true; - u = (unsigned int)x_mbuttonup * m_scale; - v = (unsigned int)y_mbuttonup * m_scale; - ip.set_u(u); - ip.set_v(v); - button = vpMouseButton::button2; - mbuttonup = false; - } - if (rbuttonup) { - ret = true; - u = (unsigned int)x_rbuttonup * m_scale; - v = (unsigned int)y_rbuttonup * m_scale; - ip.set_u(u); - ip.set_v(v); - button = vpMouseButton::button3; - rbuttonup = false; - } - if (blocking) { - cv::waitKey(10); - } - } while (ret == false && blocking == true); + ret = m_impl->getClickUp(ip, button, blocking, m_scale); } else { throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")); @@ -1498,67 +1640,7 @@ bool vpDisplayOpenCV::getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonT */ void vpDisplayOpenCV::getImage(vpImage &I) { - vpImageConvert::convert(m_background, I); - // should certainly be optimized. -} - -void vpDisplayOpenCV::on_mouse(int event, int x, int y, int /*flags*/, void *display) -{ - vpDisplayOpenCV *disp = static_cast(display); - switch (event) { - case cv::EVENT_MOUSEMOVE: - { - disp->move = true; - disp->x_move = x; - disp->y_move = y; - break; - } - case cv::EVENT_LBUTTONDOWN: - { - disp->lbuttondown = true; - disp->x_lbuttondown = x; - disp->y_lbuttondown = y; - break; - } - case cv::EVENT_MBUTTONDOWN: - { - disp->mbuttondown = true; - disp->x_mbuttondown = x; - disp->y_mbuttondown = y; - break; - } - case cv::EVENT_RBUTTONDOWN: - { - disp->rbuttondown = true; - disp->x_rbuttondown = x; - disp->y_rbuttondown = y; - break; - } - case cv::EVENT_LBUTTONUP: - { - disp->lbuttonup = true; - disp->x_lbuttonup = x; - disp->y_lbuttonup = y; - break; - } - case cv::EVENT_MBUTTONUP: - { - disp->mbuttonup = true; - disp->x_mbuttonup = x; - disp->y_mbuttonup = y; - break; - } - case cv::EVENT_RBUTTONUP: - { - disp->rbuttonup = true; - disp->x_rbuttonup = x; - disp->y_rbuttonup = y; - break; - } - - default: - break; - } + m_impl->getImage(I); } /*! @@ -1597,6 +1679,7 @@ bool vpDisplayOpenCV::getKeyboardEvent(bool blocking) } // return false; // Never reached after throw() } + /*! Get a keyboard event. @@ -1657,15 +1740,7 @@ bool vpDisplayOpenCV::getPointerMotionEvent(vpImagePoint &ip) bool ret = false; if (m_displayHasBeenInitialized) { - // flushDisplay() ; - if (move) { - ret = true; - double u = (unsigned int)x_move / m_scale; - double v = (unsigned int)y_move / m_scale; - ip.set_u(u); - ip.set_v(v); - move = false; - } + ret = m_impl->getPointerMotionEvent(ip, m_scale); } else { @@ -1687,14 +1762,7 @@ bool vpDisplayOpenCV::getPointerMotionEvent(vpImagePoint &ip) bool vpDisplayOpenCV::getPointerPosition(vpImagePoint &ip) { if (m_displayHasBeenInitialized) { - bool moved = getPointerMotionEvent(ip); - if (!moved) { - double u, v; - u = (unsigned int)x_move / m_scale; - v = (unsigned int)y_move / m_scale; - ip.set_u(u); - ip.set_v(v); - } + m_impl->getPointerPosition(ip, m_scale); return false; } else { @@ -1769,32 +1837,6 @@ unsigned int vpDisplayOpenCV::getScreenHeight() return height; } -/*! - * Initialize display overlay layer for transparency. - * \param overlay_function : Overlay function - * \param opacity : Opacity between 0 and 1. - */ -void vpDisplayOpenCV::overlay(std::function overlay_function, double opacity) -{ - // Initialize overlay layer for transparency - cv::Mat overlay; - if (opacity < 1.0) { - // Deep copy - overlay = m_background.clone(); - } - else { - // Shallow copy - overlay = m_background; - } - - overlay_function(overlay); - - // Blend background and overlay - if (opacity < 1.0) { - cv::addWeighted(overlay, opacity, m_background, 1.0 - opacity, 0.0, m_background); - } -} - END_VISP_NAMESPACE #elif !defined(VISP_BUILD_SHARED_LIBS) From e6bad6b87ce81c945fe5501a7c30156c52e8b3b3 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 4 Dec 2024 09:02:02 +0100 Subject: [PATCH 30/31] Update copyright header --- modules/gui/src/display/vpDisplayOpenCV.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/gui/src/display/vpDisplayOpenCV.cpp b/modules/gui/src/display/vpDisplayOpenCV.cpp index 4b53e811b6..cfbe2b170a 100644 --- a/modules/gui/src/display/vpDisplayOpenCV.cpp +++ b/modules/gui/src/display/vpDisplayOpenCV.cpp @@ -29,8 +29,7 @@ * * Description: * Image display. - * -*****************************************************************************/ + */ /*! \file vpDisplayOpenCV.cpp From be5071b846b97d77d2b4c13c661d56a95bfe7fd4 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 4 Dec 2024 10:01:03 +0100 Subject: [PATCH 31/31] Fix build when nlohmann is not detected (reported by cdash ci on windows) --- modules/core/src/image/vpCannyEdgeDetection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/image/vpCannyEdgeDetection.cpp b/modules/core/src/image/vpCannyEdgeDetection.cpp index 1cfe10c271..b43d719fc9 100644 --- a/modules/core/src/image/vpCannyEdgeDetection.cpp +++ b/modules/core/src/image/vpCannyEdgeDetection.cpp @@ -141,9 +141,9 @@ vpCannyEdgeDetection::vpCannyEdgeDetection(const int &gaussianKernelSize, const using json = nlohmann::json; -vpCannyEdgeDetection::vpCannyEdgeDetection(const std::string &jsonPath) : +vpCannyEdgeDetection::vpCannyEdgeDetection(const std::string &jsonPath) #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX - m_minStackSize(0) // Deactivated by default + : m_minStackSize(0) // Deactivated by default #endif { initFromJSON(jsonPath);