Cleaning stuff

This commit is contained in:
Thomas FORGIONE 2015-03-21 13:23:02 +01:00
parent 75c37579b1
commit 0977a8515c
5 changed files with 90 additions and 121 deletions

View File

@ -32,6 +32,7 @@
#include <opencv2/features2d/features2d.hpp>
#include <eigen3/Eigen/Dense>
#include "Utility/VectorFunctions.hpp"
#include "Geometry/Vector.hpp"
#include "Geometry/MathFunctions.hpp"
@ -41,51 +42,24 @@ namespace geo
namespace detail
{
template<typename T>
auto const& get_x(T const& t)
{
return t.x;
}
auto& get_x(T& t) { return t.x; }
template<typename T, std::size_t N>
auto const& get_x(Vector<T,N> const& v)
{
return v.x();
}
template<typename T>
auto const& get_x(T const& t) { return t.x; }
template <typename T>
auto const& get_y(T const& t)
{
return t.y;
}
template<typename T, std::size_t N>
auto const& get_y(Vector<T,N> const& v)
{
return v.y();
}
auto& get_y(T& t) { return t.y; }
template <typename T>
auto const& get_z(T const& t)
{
return t.z;
}
auto const& get_y(T const& t) { return t.y; }
template<typename T, std::size_t N>
auto const& get_z(Vector<T,N> const& v)
{
return v.z();
}
template <typename T>
auto& get_z(T& t) { return t.z; }
template <typename T>
auto const& get_z(T const& t) { return t.z; }
}
template<typename T>
struct vector_size;
template<typename T, std::size_t N>
struct vector_size<Vector<T,N>>
{
static constexpr std::size_t value = N;
};
template<typename T>
struct vector_size<cv::Point_<T>>
{
@ -198,6 +172,9 @@ struct distance_to_segment_helper<T1,T2,T3,3>
template<typename T1, typename T2, typename T3>
float distanceToSegment(T1 const& v, T2 const& p1, T3 const& p2)
{
static_assert(vector_size<T1>::value == 2 || vector_size<T1>::value == 3,
"distanceToSegment is only implemented in dimensions 2 and 3");
static_assert(vector_size<T1>::value == vector_size<T2>::value,
"When computing distance between point and segment,"
"all elements must have the same size");
@ -220,7 +197,7 @@ geo::Vector4<T> closestPlane(std::vector<geo::Vector3<T>> 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};

View File

@ -34,6 +34,8 @@
#include <array>
#include <istream>
#include <Utility/VectorFunctions.hpp>
namespace geo
{
@ -363,6 +365,72 @@ std::istream& operator>>(std::istream& stream, Vector<T,N>& v);
template<typename T, std::size_t N>
std::ostream& operator<<(std::ostream& stream, Vector<T,N> 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<typename T, std::size_t N>
T& get_x(Vector<T,N>& 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<typename T, std::size_t N>
T const& get_x(Vector<T,N> 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<typename T, std::size_t N>
T& get_y(Vector<T,N>& 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<typename T, std::size_t N>
T const& get_y(Vector<T,N> 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<typename T, std::size_t N>
T& get_z(Vector<T,N>& 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<typename T, std::size_t N>
T const& get_z(Vector<T,N> const& v) { return v.z(); }
/////////////////////////////////////////////////////////////////
/// \relates Vector
/// \brief Specialization of class vector_size
///
/// Gives constexpr access to the size of a vector
/////////////////////////////////////////////////////////////////
template<typename T, std::size_t N>
struct vector_size<Vector<T,N>>
{
constexpr static std::size_t value = N; ///< Size of the vector
};
/////////////////////////////////////////////////////////////////
/// \relates Vector
/// \brief Smaller name for Vector of 2 coordinates

View File

@ -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 <cmath>
#include <SFML/System/Vector3.hpp>
using sf::Vector3;
template <class T>
Vector3<T> makeVector(Vector3<T> const& from, Vector3<T> const& to)
{
return to - from;
}
template <class T>
double dotProduct(Vector3<T> const& v1, Vector3<T> const& v2)
{
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}
template <class T>
double norm2(Vector3<T> const& vecteur)
{
return dotProduct(vecteur, vecteur);
}
template <class T>
double norm(Vector3<T> const& vecteur)
{
return sqrt(norm2(vecteur));
}
template <class T>
void normalize(Vector3<T>& vecteur)
{
vecteur /= norm(vecteur);
}
template <class T>
Vector3<T> crossProduct(Vector3<T> const& v1, Vector3<T> const& v2)
{
return Vector3<T>{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

View File

@ -36,6 +36,7 @@
/// Contains the function on std::tuple that we need
//////////////////////////////////////////////////////
#include <Utility/VectorFunctions.hpp>
#include <Utility/TupleFunctions.hpp>
#endif

View File

@ -51,11 +51,11 @@ std::vector<std::pair<cv::Point,cv::Point>> detectAndMatch(cv::Mat const& img_1,
std::vector<cv::KeyPoint> 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<std::pair<cv::Point,cv::Point>> 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);