paella/Code/include/Geometry/Spline.hpp

113 lines
4.3 KiB
C++
Raw Normal View History

#ifndef SPLINE_HPP
#define SPLINE_HPP
#include <vector>
#include <tuple>
#include <cmath>
#include <Geometry/Circle.hpp>
#include <Utility/TupleFunctions.hpp>
namespace geo
{
///////////////////////////////////////////////////////////////
/// \brief Utility template class for manipulating B-splines
//////////////////////////////////////////////////////////////
template<typename... Types>
class Spline
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Creates an empty spline (with no control points)
///////////////////////////////////////////////////////////
Spline();
///////////////////////////////////////////////////////////
/// \brief Evaluates the spline at a certain time
///
/// \param t Time at which you want to evaluate the spline. Must be between 0 and 1
///
/// \return Tuple that corresponds to the points of the spline at time t
///////////////////////////////////////////////////////////
std::tuple<Types...> operator()(float t) const;
///////////////////////////////////////////////////////////
/// \brief Evaluates the derivative of the spline at a certain time
///
/// \param t Time at which you want to evaluate the derivative of the
/// spline. Must be between 0 and 1
///
/// \return Tuple that corresponds to the derivative of each
/// coordinates of the spline at time t
///////////////////////////////////////////////////////////
std::tuple<Types...> prime(float t) const;
///////////////////////////////////////////////////////////
/// \brief Prints the spline to the stream
///
/// \param t Time at which you want to evaluate the derivative of the
/// spline. Must be between 0 and 1
///
/// \return Tuple that corresponds to the derivative of each
/// coordinates of the spline at time t
///
/// Prints first the degree of the spline, than the nodes and finally
/// the control points. For example
/// \code
/// d 3
///
/// n 0 0 0 0 0.333333 0.666667 1 1 1 1
///
/// p 0.60 0.43 0.51 0.142
/// p 0.60 0.89 0.36 0.135
/// p 0.72 1.28 0.24 0.129
/// p 0.96 1.72 0.14 0.125
/// p 1.27 2.10 0.06 0.122
/// p 1.69 2.29 0 0.12
/// \endcode
///////////////////////////////////////////////////////////
template<typename... T>
friend std::ostream& operator<<( std::ostream& out, Spline<T...> const& spline);
geo::Circle<float> computeCircle(float t, unsigned int const nbPoints, geo::Vector3<float>& v, unsigned int const offset = 0) const;
std::vector<geo::Circle<float>> computeCircles(unsigned int nbCircles, unsigned int const nbPoints, unsigned int const globalOffset = 0) const;
// private:
///////////////////////////////////////////////////////////
/// \brief Add a control point to the spline
///
/// \param node String representation of the node to be added
///////////////////////////////////////////////////////////
void addControlPoint(std::string const& node);
std::vector<std::tuple<Types...>> controlPoints; ///< Vector of the control points of the spline
std::vector<float> nodes; ///< Vector of nodes of the spline
int degree; ///< Degree of the spline
};
namespace detail
{
template<typename... Types>
std::tuple<Types...> evalSpline(std::vector<std::tuple<Types...>> const& controlPoints , std::vector<float> const& nodes, int degree, float f);
template<typename... Types>
std::tuple<Types...> evalDerivativeSpline(std::vector<std::tuple<Types...>> const& controlPoints , std::vector<float> const& nodes, int degree, float f);
} // namespace detail
} // namespace geo
#include "Spline.inl"
#endif // SPLINE_HPP
2015-03-01 18:20:52 +01:00
////////////////////////////////////////////////////////////
/// \class geo::Spline
/// \ingroup geometry
///
/// A class that can manage splines and generates points on the splines
////////////////////////////////////////////////////////////