From 0977a8515cb49a4d1d299765fc9d97cb92cd421c Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Sat, 21 Mar 2015 13:23:02 +0100 Subject: [PATCH] Cleaning stuff --- Code/include/Geometry/MathFunctions.inl | 53 ++++--------- Code/include/Geometry/Vector.hpp | 68 ++++++++++++++++ Code/include/Skeleton/VectorFunctions.hpp | 77 ------------------- Code/include/Utility/Utility.hpp | 1 + .../DetectionAndMatching.cpp | 12 +-- 5 files changed, 90 insertions(+), 121 deletions(-) delete mode 100644 Code/include/Skeleton/VectorFunctions.hpp diff --git a/Code/include/Geometry/MathFunctions.inl b/Code/include/Geometry/MathFunctions.inl index b340643..598b69a 100644 --- a/Code/include/Geometry/MathFunctions.inl +++ b/Code/include/Geometry/MathFunctions.inl @@ -32,6 +32,7 @@ #include #include +#include "Utility/VectorFunctions.hpp" #include "Geometry/Vector.hpp" #include "Geometry/MathFunctions.hpp" @@ -41,51 +42,24 @@ namespace geo namespace detail { template - auto const& get_x(T const& t) - { - return t.x; - } + auto& get_x(T& t) { return t.x; } - template - auto const& get_x(Vector const& v) - { - return v.x(); - } + template + auto const& get_x(T const& t) { return t.x; } template - auto const& get_y(T const& t) - { - return t.y; - } - - template - auto const& get_y(Vector const& v) - { - return v.y(); - } + auto& get_y(T& t) { return t.y; } template - auto const& get_z(T const& t) - { - return t.z; - } + auto const& get_y(T const& t) { return t.y; } - template - auto const& get_z(Vector const& v) - { - return v.z(); - } + template + auto& get_z(T& t) { return t.z; } + + template + auto const& get_z(T const& t) { return t.z; } } -template -struct vector_size; - -template -struct vector_size> -{ - static constexpr std::size_t value = N; -}; - template struct vector_size> { @@ -198,6 +172,9 @@ struct distance_to_segment_helper template float distanceToSegment(T1 const& v, T2 const& p1, T3 const& p2) { + static_assert(vector_size::value == 2 || vector_size::value == 3, + "distanceToSegment is only implemented in dimensions 2 and 3"); + static_assert(vector_size::value == vector_size::value, "When computing distance between point and segment," "all elements must have the same size"); @@ -220,7 +197,7 @@ geo::Vector4 closestPlane(std::vector> const& points) float t = - (points[0].x()*vec.x() + points[0].y()*vec.y() + points[0].z()*vec.z()); return geo::Vector4f{vec.x(), vec.y(), vec.z(), t}; } - // for more points we use an PCA decomposition to find the best plane + // for more points we use a PCA to find the best plane else { Eigen::MatrixXf m{points.size(),3}; diff --git a/Code/include/Geometry/Vector.hpp b/Code/include/Geometry/Vector.hpp index 89ea888..cb290a9 100644 --- a/Code/include/Geometry/Vector.hpp +++ b/Code/include/Geometry/Vector.hpp @@ -34,6 +34,8 @@ #include #include +#include + namespace geo { @@ -363,6 +365,72 @@ std::istream& operator>>(std::istream& stream, Vector& v); template std::ostream& operator<<(std::ostream& stream, Vector const& v); +///////////////////////////////////////////////////////////////// +/// \relates Vector +/// \brief Returns the x coordinate of the vector +/// \param v the vector +/// \return a reference to the x coordinate of the vector +///////////////////////////////////////////////////////////////// +template +T& get_x(Vector& v) { return v.x(); } + +///////////////////////////////////////////////////////////////// +/// \relates Vector +/// \brief Returns the x coordinate of the vector +/// \param v the vector +/// \return a const reference to the x coordinate of the vector +///////////////////////////////////////////////////////////////// +template +T const& get_x(Vector const& v) { return v.x(); } + +///////////////////////////////////////////////////////////////// +/// \relates Vector +/// \brief Returns the y coordinate of the vector +/// \param v the vector +/// \return a reference to the y coordinate of the vector +///////////////////////////////////////////////////////////////// +template +T& get_y(Vector& v) { return v.y(); } + +///////////////////////////////////////////////////////////////// +/// \relates Vector +/// \brief Returns the y coordinate of the vector +/// \param v the vector +/// \return a const reference to the y coordinate of the vector +///////////////////////////////////////////////////////////////// +template +T const& get_y(Vector const& v) { return v.y(); } + +///////////////////////////////////////////////////////////////// +/// \relates Vector +/// \brief Returns the z coordinate of the vector +/// \param v the vector +/// \return a reference to the z coordinate of the vector +///////////////////////////////////////////////////////////////// +template +T& get_z(Vector& v) { return v.z(); } + +///////////////////////////////////////////////////////////////// +/// \relates Vector +/// \brief Returns the z coordinate of the vector +/// \param v the vector +/// \return a const reference to the z coordinate of the vector +///////////////////////////////////////////////////////////////// +template +T const& get_z(Vector const& v) { return v.z(); } + +///////////////////////////////////////////////////////////////// +/// \relates Vector +/// \brief Specialization of class vector_size +/// +/// Gives constexpr access to the size of a vector +///////////////////////////////////////////////////////////////// +template +struct vector_size> +{ + constexpr static std::size_t value = N; ///< Size of the vector +}; + ///////////////////////////////////////////////////////////////// /// \relates Vector /// \brief Smaller name for Vector of 2 coordinates diff --git a/Code/include/Skeleton/VectorFunctions.hpp b/Code/include/Skeleton/VectorFunctions.hpp deleted file mode 100644 index 875519e..0000000 --- a/Code/include/Skeleton/VectorFunctions.hpp +++ /dev/null @@ -1,77 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Paella -// Copyright (C) 2015 - Thomas FORGIONE, Emilie JALRAS, Marion LENFANT, Thierry MALON, Amandine PAILLOUX -// Authors : -// Thomas FORGIONE -// Emilie JALRAS -// Marion LENFANT -// Thierry MALON -// Amandine PAILLOUX -// -// This file is part of the project Paella -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -//////////////////////////////////////////////////////////////////////////////// -#ifndef VECTOR_FUNCTIONS_HPP -#define VECTOR_FUNCTIONS_HPP - -#include -#include - -using sf::Vector3; - -template -Vector3 makeVector(Vector3 const& from, Vector3 const& to) -{ - return to - from; -} - -template -double dotProduct(Vector3 const& v1, Vector3 const& v2) -{ - return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; -} - -template -double norm2(Vector3 const& vecteur) -{ - return dotProduct(vecteur, vecteur); -} - -template -double norm(Vector3 const& vecteur) -{ - return sqrt(norm2(vecteur)); -} - -template -void normalize(Vector3& vecteur) -{ - vecteur /= norm(vecteur); -} - -template -Vector3 crossProduct(Vector3 const& v1, Vector3 const& v2) -{ - return Vector3{v1.y * v2.z - v1.z * v2.y, - v1.z * v2.x - v1.x * v2.z, - v1.x * v2.y - v1.y * v2.x - }; -} - -#endif // VECTOR_FUNCTIONS_HPP diff --git a/Code/include/Utility/Utility.hpp b/Code/include/Utility/Utility.hpp index 0c47deb..f3f2f9a 100644 --- a/Code/include/Utility/Utility.hpp +++ b/Code/include/Utility/Utility.hpp @@ -36,6 +36,7 @@ /// Contains the function on std::tuple that we need ////////////////////////////////////////////////////// +#include #include #endif diff --git a/Code/src/DetectionAndMatching/DetectionAndMatching.cpp b/Code/src/DetectionAndMatching/DetectionAndMatching.cpp index 69ea418..842e6ae 100644 --- a/Code/src/DetectionAndMatching/DetectionAndMatching.cpp +++ b/Code/src/DetectionAndMatching/DetectionAndMatching.cpp @@ -51,11 +51,11 @@ std::vector> detectAndMatch(cv::Mat const& img_1, std::vector keypoints_1, keypoints_2; - cv::BRISK BRISKD(Threshl,Octaves,PatternScales);//initialize algoritm - BRISKD.create("Feature2D.BRISK"); + cv::BRISK briskd(Threshl,Octaves,PatternScales);//initialize algoritm + briskd.create("Feature2D.BRISK"); - BRISKD.detect(img_1, keypoints_1,masque_1); - BRISKD.detect( img_2, keypoints_2, masque_2); + briskd.detect(img_1, keypoints_1,masque_1); + briskd.detect( img_2, keypoints_2, masque_2); //-- Draw keypoints cv::Mat img_keypoints_1; cv::Mat img_keypoints_2; @@ -73,8 +73,8 @@ std::vector> detectAndMatch(cv::Mat const& img_1, //every raw from the descriptors contains a KeyPoint descriptor (128 columns per raw) cv::Mat descriptors_1, descriptors_2; - BRISKD.compute( img_1, keypoints_1, descriptors_1 ); - BRISKD.compute( img_2, keypoints_2, descriptors_2 ); + briskd.compute( img_1, keypoints_1, descriptors_1 ); + briskd.compute( img_2, keypoints_2, descriptors_2 ); //-- Step 3: Matching descriptor vectors with a brute force matcher cv::BFMatcher matcher(cv::NORM_L2);