Commit fd9f3b64 authored by JasonChmn's avatar JasonChmn Committed by Pierre Fernbach
Browse files

Add function to check if a curve is empty (no coeff/control points/curves)

parent 93a9491c
......@@ -45,7 +45,8 @@ namespace curves
/* Constructors - destructors */
public:
/// \brief Empty constructor. Curve obtained this way can not perform other class functions.
///
bezier_curve()
: T_min_(0), T_max_(0)
{}
......@@ -125,6 +126,7 @@ namespace curves
/// \return \f$x(t)\f$ point corresponding on curve at time t.
virtual point_t operator()(const time_t t) const
{
check_if_not_empty();
if(Safe &! (T_min_ <= t && t <= T_max_))
{
throw std::invalid_argument("can't evaluate bezier curve, time t is out of range"); // TODO
......@@ -145,6 +147,7 @@ namespace curves
/// \return \f$\frac{d^Nx(t)}{dt^N}\f$ derivative order N of the curve.
bezier_curve_t compute_derivate(const std::size_t order) const
{
check_if_not_empty();
if(order == 0)
{
return *this;
......@@ -169,6 +172,7 @@ namespace curves
/// \return primitive at order N of x(t).
bezier_curve_t compute_primitive(const std::size_t order) const
{
check_if_not_empty();
if(order == 0)
{
return *this;
......@@ -315,6 +319,7 @@ namespace curves
///
std::pair<bezier_curve_t,bezier_curve_t> split(const Numeric t)
{
check_if_not_empty();
if (fabs(t-T_max_)<MARGIN)
{
throw std::runtime_error("can't split curve, interval range is equal to original curve");
......@@ -385,6 +390,14 @@ namespace curves
res.push_back(PN);
return res;
}
void check_if_not_empty() const
{
if (control_points_.size() == 0)
{
throw std::runtime_error("Error in beziercurve : there is no control points set / did you use empty constructor ?");
}
}
/*Operations*/
public:
......
......@@ -44,7 +44,8 @@ namespace curves
typedef Numeric num_t;
public:
/// \brief Empty constructor. Curve obtained this way can not perform other class functions.
///
cubic_hermite_spline()
: T_min_(0), T_max_(0)
{}
......@@ -91,6 +92,7 @@ namespace curves
///
virtual Point operator()(const Time t) const
{
check_if_not_empty();
if(Safe &! (T_min_ <= t && t <= T_max_))
{
throw std::invalid_argument("can't evaluate cubic hermite spline, out of range");
......@@ -112,6 +114,7 @@ namespace curves
///
virtual Point derivate(const Time t, const std::size_t order) const
{
check_if_not_empty();
return evalCubicHermiteSpline(t, order);
}
......@@ -315,6 +318,14 @@ namespace curves
return left_id-1;
}
void check_if_not_empty() const
{
if (control_points_.size() == 0)
{
throw std::runtime_error("Error in cubic hermite : there is no control points set / did you use empty constructor ?");
}
}
/// \brief compute duration of each spline.
/// For N control points with time \f$T_{P_0}, T_{P_1}, T_{P_2}, ..., T_{P_N}\f$ respectively,
/// Duration of each subspline is : ( T_{P_1}-T_{P_0}, T_{P_2}-T_{P_1}, ..., T_{P_N}-T_{P_{N-1} ).
......
......@@ -64,7 +64,8 @@ namespace curves
/* Constructors - destructors */
public:
/// \brief Empty constructor. Add at least one curve to call other class functions.
///
exact_cubic()
: piecewise_curve_t()
{}
......
......@@ -40,7 +40,8 @@ namespace curves
typedef typename std::vector< Time > t_time_t;
public:
/// \brief Empty constructor. Add at least one curve to call other class functions.
///
piecewise_curve()
: size_(0), T_min_(0), T_max_(0)
{}
......@@ -73,6 +74,7 @@ namespace curves
virtual Point operator()(const Time t) const
{
check_if_not_empty();
if(Safe &! (T_min_ <= t && t <= T_max_))
{
//std::cout<<"[Min,Max]=["<<T_min_<<","<<T_max_<<"]"<<" t="<<t<<std::endl;
......@@ -88,6 +90,7 @@ namespace curves
///
virtual Point derivate(const Time t, const std::size_t order) const
{
check_if_not_empty();
if(Safe &! (T_min_ <= t && t <= T_max_))
{
throw std::invalid_argument("can't evaluate piecewise curve, out of range");
......@@ -125,6 +128,7 @@ namespace curves
///
bool is_continuous(const std::size_t order)
{
check_if_not_empty();
bool isContinuous = true;
std::size_t i=0;
point_t value_end, value_start;
......@@ -154,6 +158,7 @@ namespace curves
template<typename Bezier>
piecewise_curve<Time, Numeric, Dim, Safe, Point, T_Point, Bezier> convert_piecewise_curve_to_bezier()
{
check_if_not_empty();
typedef piecewise_curve<Time, Numeric, Dim, Safe, Point, T_Point, Bezier> piecewise_curve_out_t;
// Get first curve (segment)
curve_t first_curve = curves_.at(0);
......@@ -171,6 +176,7 @@ namespace curves
template<typename Hermite>
piecewise_curve<Time, Numeric, Dim, Safe, Point, T_Point, Hermite> convert_piecewise_curve_to_cubic_hermite()
{
check_if_not_empty();
typedef piecewise_curve<Time, Numeric, Dim, Safe, Point, T_Point, Hermite> piecewise_curve_out_t;
// Get first curve (segment)
curve_t first_curve = curves_.at(0);
......@@ -188,6 +194,7 @@ namespace curves
template<typename Polynomial>
piecewise_curve<Time, Numeric, Dim, Safe, Point, T_Point, Polynomial> convert_piecewise_curve_to_polynomial()
{
check_if_not_empty();
typedef piecewise_curve<Time, Numeric, Dim, Safe, Point, T_Point, Polynomial> piecewise_curve_out_t;
// Get first curve (segment)
curve_t first_curve = curves_.at(0);
......@@ -290,6 +297,14 @@ namespace curves
return left_id-1;
}
void check_if_not_empty() const
{
if (curves_.size() == 0)
{
throw std::runtime_error("Error in piecewise curve : No curve added");
}
}
/*Helpers*/
public:
......
......@@ -49,7 +49,8 @@ namespace curves
/* Constructors - destructors */
public:
/// \brief Empty constructor. Curve obtained this way can not perform other class functions.
///
polynomial()
: T_min_(0), T_max_(0)
{}
......@@ -140,6 +141,7 @@ namespace curves
/// \return \f$x(t)\f$ point corresponding on spline at time t.
virtual point_t operator()(const time_t t) const
{
check_if_not_empty();
if((t < T_min_ || t > T_max_) && Safe)
{
throw std::invalid_argument("error in polynomial : time t to evaluate should be in range [Tmin, Tmax] of the curve");
......@@ -160,6 +162,7 @@ namespace curves
/// \return \f$\frac{d^Nx(t)}{dt^N}\f$ point corresponding on derivative spline at time t.
virtual point_t derivate(const time_t t, const std::size_t order) const
{
check_if_not_empty();
if((t < T_min_ || t > T_max_) && Safe)
{
throw std::invalid_argument("error in polynomial : time t to evaluate derivative should be in range [Tmin, Tmax] of the curve");
......@@ -176,6 +179,7 @@ namespace curves
polynomial_t compute_derivate(const std::size_t order) const
{
check_if_not_empty();
if(order == 0)
{
return *this;
......@@ -204,6 +208,14 @@ namespace curves
}
return coeff_derivated;
}
void check_if_not_empty() const
{
if (coefficients_.size() == 0)
{
throw std::runtime_error("Error in polynomial : there is no coefficients set / did you use empty constructor ?");
}
}
/*Operations*/
public:
......
......@@ -5,7 +5,6 @@
#define __curves_python_serialization_archive_hpp__
#include <boost/python.hpp>
#include "curves/curve_abc.h"
namespace curves
{
......@@ -14,20 +13,18 @@ namespace curves
struct SerializableVisitor
: public boost::python::def_visitor< SerializableVisitor<Derived> >
{
// TO DO !!!!! Try to fix and remove all the .def for serialization in curves_python
template<class PyClass>
void visit(PyClass& cl) const
{
cl
// TO DO : try to define save and load functions with template
/*
.def("saveAsText",&Derived::saveAsText<Derived>,bp::args("filename"),"Saves *this inside a text file.")
.def("loadFromText",Derived::loadFromText<Derived>,bp::args("filename"),"Loads *this from a text file.")
.def("saveAsXML",Derived::saveAsXML<Derived>,bp::args("filename","tag_name"),"Saves *this inside a XML file.")
.def("loadFromXML",Derived::loadFromXML<Derived>,bp::args("filename","tag_name"),"Loads *this from a XML file.")
.def("saveAsBinary",Derived::saveAsBinary<Derived>,bp::args("filename"),"Saves *this inside a binary file.")
.def("loadFromBinary",Derived::loadFromBinary<Derived>,bp::args("filename"),"Loads *this from a binary file.")
.def("saveAsText",&Derived::saveAsText,bp::args("filename"),"Saves *this inside a text file.")
.def("loadFromText",&Derived::loadFromText,bp::args("filename"),"Loads *this from a text file.")
.def("saveAsXML",&Derived::saveAsXML,bp::args("filename","tag_name"),"Saves *this inside a XML file.")
.def("loadFromXML",&Derived::loadFromXML,bp::args("filename","tag_name"),"Loads *this from a XML file.")
.def("saveAsBinary",&Derived::saveAsBinary,bp::args("filename"),"Saves *this inside a binary file.")
.def("loadFromBinary",&Derived::loadFromBinary,bp::args("filename"),"Loads *this from a binary file.")
*/
;
}
......
......@@ -283,6 +283,8 @@ namespace curves
/* End wrap exact cubic spline */
// TO DO : Replace all load and save function for serialization in class by using
// SerializableVisitor in archive_python_binding.
BOOST_PYTHON_MODULE(curves)
{
/** BEGIN eigenpy init**/
......@@ -318,7 +320,7 @@ namespace curves
.def("loadFromBinary",&bezier6_t::loadFromBinary<bezier6_t>,bp::args("filename"),"Loads *this from a binary file.")
.def_readonly("degree", &bezier6_t::degree_)
.def_readonly("nbWaypoints", &bezier6_t::size_)
.def(SerializableVisitor<bezier6_t>())
//.def(SerializableVisitor<bezier6_t>())
;
/** END bezier curve**/
/** BEGIN bezier curve**/
......
......@@ -1465,7 +1465,6 @@ int main(int /*argc*/, char** /*argv[]*/)
std::cout << "performing tests... \n";
bool error = false;
PolynomialCubicFunctionTest(error);
/*
ExactCubicNoErrorTest(error);
ExactCubicPointsCrossedTest(error); // checks that given wayPoints are crossed
ExactCubicTwoPointsTest(error);
......@@ -1489,7 +1488,6 @@ int main(int /*argc*/, char** /*argv[]*/)
toPolynomialConversionTest(error);
cubicConversionTest(error);
curveAbcDimDynamicTest(error);
*/
serializationCurvesTest(error);
if(error)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment