141 lines
5.0 KiB
C++
141 lines
5.0 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// 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 MATHFUNCTIONS_HPP
|
|
#define MATHFUNCTIONS_HPP
|
|
|
|
#include <vector>
|
|
|
|
#include <Geometry/Vector.hpp>
|
|
|
|
namespace geo
|
|
{
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
/// \ingroup geometry
|
|
/// \brief Compute the projection of an element on a container
|
|
///
|
|
/// \param elementToProject element to project
|
|
///
|
|
/// \param first Iterator to the first element of the container
|
|
///
|
|
/// \param last Iterator after the last element
|
|
///
|
|
/// \param distance Function that takes for argument a T and a element of the
|
|
/// container and that returns the distance between these elements.
|
|
///
|
|
/// \return An iterator the closest element in the array
|
|
///
|
|
/// \deprecated Use min_element instead
|
|
///
|
|
//////////////////////////////////////////////////////////////////
|
|
template<typename InputIt, typename T, typename Distance>
|
|
InputIt project(T const& elementToProject, InputIt first, InputIt last, Distance const& distance);
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
/// \ingroup geometry
|
|
/// \brief Template utility for Segments
|
|
//////////////////////////////////////////////////////////////////
|
|
template <typename T, std::size_t N>
|
|
using Segment = std::pair<Vector<T,N>, Vector<T,N>>;
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
/// \ingroup geometry
|
|
/// \brief Compute the distance between a point and a segment
|
|
///
|
|
/// \param v The point
|
|
///
|
|
/// \param p1 The first point of the segment
|
|
/// \param p2 The second point of the segment
|
|
///
|
|
/// \return The norm-2 distance between v and the closest point in s
|
|
///
|
|
/// To use this function, the template class vector_size must be
|
|
/// defined on T1, T2, and T3, with a value containing the size
|
|
/// of the vector, and the functions `get_x`, `get_y` and `get_z`
|
|
/// (if the size is high enough). There will be an error if the
|
|
/// vector_size<T>::value are different for two vectors.
|
|
/// For example
|
|
///
|
|
/// \code
|
|
/// struct my_vector
|
|
/// {
|
|
/// float my_x;
|
|
/// float my_y;
|
|
/// };
|
|
///
|
|
/// template<>
|
|
/// struct vector_size<my_vector>
|
|
/// {
|
|
/// constexpr std::size_t N = 2;
|
|
/// };
|
|
///
|
|
/// template<>
|
|
/// float const& get_x<my_vector>(my_vector const& v)
|
|
/// {
|
|
/// return v.my_x;
|
|
/// }
|
|
///
|
|
/// // And the same for y...
|
|
/// \endcode
|
|
//////////////////////////////////////////////////////////////////
|
|
template<typename T1, typename T2, typename T3>
|
|
float distanceToSegment(T1 const& v, T2 const& p1, T3 const& p2);
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
/// \ingroup geometry
|
|
/// \brief compute on which side of the plane is the point (depending on the orientation of the plane
|
|
///
|
|
/// \param plane the caracteristic elements of the plane a, b, c, d in the plane equation : ax + by + cz + d = 0.
|
|
/// \param point the point that need to be evaluated
|
|
///
|
|
/// \return a boolean which is true when : a*point.x() + b*point.y() + c*point.z() < -d.
|
|
/////////////////////////////////////////////////////////////
|
|
template<typename T>
|
|
bool whichSide(geo::Vector<T,4> const& plane, geo::Vector3<T> const& point);
|
|
|
|
//////////////////////////////////////////////////////////
|
|
/// \ingroup meshing
|
|
/// \relates pae::Skeleton3D
|
|
/// \brief compute the equation of the optimal plane for a given set of points. For 3 points it only computes the equation of a plane, beyond 3 points with ACP decomposition it returns the mean plane.
|
|
///
|
|
/// \param points the given set of points to estimate the equation of the plane
|
|
///
|
|
/// \return the caracteristic elements of the plane a, b, c, d in the plane equation : ax + by + cz + d = 0.)
|
|
/////////////////////////////////////////////////////////
|
|
template<typename T>
|
|
geo::Vector<T,4> closestPlane(std::vector<geo::Vector3<T>> const& points);
|
|
|
|
} // namespace geo
|
|
|
|
#include "Geometry/MathFunctions.inl"
|
|
|
|
#endif // MATHFUNCTIONS_HPP
|
|
|