123 lines
5.0 KiB
C++
123 lines
5.0 KiB
C++
#ifndef SPLINE_HPP
|
|
#define SPLINE_HPP
|
|
|
|
#include <vector>
|
|
#include <tuple>
|
|
#include <cmath>
|
|
#include <Geometry/Circle.hpp>
|
|
#include <Utility/TupleFunctions.hpp>
|
|
|
|
namespace geo
|
|
{
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
/// \ingroup geometry
|
|
/// \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);
|
|
|
|
///////////////////////////////////////////////////////////
|
|
/// \brief Computes a circle around a spline
|
|
///
|
|
/// \param t instant of the spline where the circle will be computed
|
|
/// \param nbPoints number of the points on the circle
|
|
/// \param v up vector (the first point of the circle will be center + v)
|
|
/// \param offset offset for the indices in the mesh
|
|
/// \return a circle containing the center and the points of the circle
|
|
///////////////////////////////////////////////////////////
|
|
geo::Circle<float> computeCircle(float t, unsigned int const nbPoints, geo::Vector3<float>& v, unsigned int const offset = 0) const;
|
|
|
|
///////////////////////////////////////////////////////////
|
|
/// \brief Computes circles around the spline
|
|
/// \parap nbCircles number of circles on the spline
|
|
/// \param nbPoints number of points on the circles
|
|
/// \param globalOffset offset for the indices in the mesh
|
|
/// \return a vector of the circles
|
|
///////////////////////////////////////////////////////////
|
|
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
|