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

[Serialization] Add serialization of Dim getter for all curves

parent c61f7bc5
......@@ -440,6 +440,7 @@ namespace curves
if (version) {
// Do something depending on version ?
}
ar & boost::serialization::make_nvp("dim", dim_);
ar & boost::serialization::make_nvp("T_min", T_min_);
ar & boost::serialization::make_nvp("T_max", T_max_);
ar & boost::serialization::make_nvp("mult_T", mult_T_);
......
......@@ -43,7 +43,7 @@ namespace curves
/// \brief Empty constructor. Curve obtained this way can not perform other class functions.
///
cubic_hermite_spline()
: T_min_(0), T_max_(0)
: dim_(0), T_min_(0), T_max_(0)
{}
/// \brief Constructor.
......@@ -66,12 +66,18 @@ namespace curves
{
control_points_.push_back(*it);
}
// Set dimension according to size of points
if (control_points_.size()!=0)
{
dim_ = control_points_[0].first.size();
}
// Set time
setTime(time_control_points);
}
cubic_hermite_spline(const cubic_hermite_spline& other)
: control_points_(other.control_points_), time_control_points_(other.time_control_points_),
: dim_(other.dim_), control_points_(other.control_points_), time_control_points_(other.time_control_points_),
duration_splines_(other.duration_splines_), T_min_(other.T_min_), T_max_(other.T_max_),
size_(other.size_), degree_(other.degree_)
{}
......@@ -88,7 +94,7 @@ namespace curves
///
virtual Point operator()(const Time t) const
{
check_if_not_empty();
check_conditions();
if(Safe &! (T_min_ <= t && t <= T_max_))
{
throw std::invalid_argument("can't evaluate cubic hermite spline, out of range");
......@@ -110,7 +116,7 @@ namespace curves
///
virtual Point derivate(const Time t, const std::size_t order) const
{
check_if_not_empty();
check_conditions();
return evalCubicHermiteSpline(t, order);
}
......@@ -314,12 +320,16 @@ namespace curves
return left_id-1;
}
void check_if_not_empty() const
void check_conditions() 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 ?");
}
else if(dim_ == 0)
{
throw std::runtime_error("Error in cubic hermite : Dimension of points is zero / did you use empty constructor ?");
}
}
/// \brief compute duration of each spline.
......@@ -399,6 +409,7 @@ namespace curves
if (version) {
// Do something depending on version ?
}
ar & boost::serialization::make_nvp("dim", dim_);
ar & boost::serialization::make_nvp("control_points", control_points_);
ar & boost::serialization::make_nvp("time_control_points", time_control_points_);
ar & boost::serialization::make_nvp("duration_splines", duration_splines_);
......
......@@ -334,6 +334,7 @@ namespace curves
if (version) {
// Do something depending on version ?
}
ar & boost::serialization::make_nvp("dim", dim_);
ar & boost::serialization::make_nvp("curves", curves_);
ar & boost::serialization::make_nvp("time_curves", time_curves_);
ar & boost::serialization::make_nvp("size", size_);
......
......@@ -257,6 +257,7 @@ namespace curves
if (version) {
// Do something depending on version ?
}
ar & boost::serialization::make_nvp("dim", dim_);
ar & boost::serialization::make_nvp("coefficients", coefficients_);
ar & boost::serialization::make_nvp("dim", dim_);
ar & boost::serialization::make_nvp("degree", degree_);
......
......@@ -1071,18 +1071,13 @@ void CubicHermitePairsPositionDerivativeTest(bool& error)
{
std::cout << "Cubic hermite spline test, Error when calling getTime\n";
}
// Test derivative : three pairs, time default
res1 = cubic_hermite_spline_2Pairs.derivate(0.,1);
ComparePoints(t0, res1, errmsg3, error);
res1 = cubic_hermite_spline_2Pairs.derivate(0.5,1);
ComparePoints(t1, res1, errmsg3, error);
res1 = cubic_hermite_spline_2Pairs.derivate(1.,1);
ComparePoints(t2, res1, errmsg3, error);
}
void piecewiseCurveTest(bool& error)
{
try
{
// TEST WITH POLYNOMIALS
std::string errmsg1("in piecewise polynomial curve test, Error While checking value of point on curve : ");
point_t a(1,1,1); // in [0,1[
......@@ -1236,6 +1231,12 @@ void piecewiseCurveTest(bool& error)
CompareCurves<piecewise_polynomial_curve_t, piecewise_cubic_hermite_curve_t>(pc, pc_hermite, errmsg5, error);
piecewise_polynomial_curve_t pc_polynomial_same = pc.convert_piecewise_curve_to_polynomial<polynomial_t>();
CompareCurves<piecewise_polynomial_curve_t, piecewise_polynomial_curve_t>(pc, pc_polynomial_same, errmsg5, error);
}
catch(...)
{
error = true;
std::cout<<"Error in piecewiseCurveTest"<<std::endl;
}
}
void curveAbcDimDynamicTest(bool& error)
......@@ -1331,6 +1332,8 @@ void curveAbcDimDynamicTest(bool& error)
void piecewiseCurveConversionFromDiscretePointsTest(bool& error)
{
try
{
std::string errMsg("piecewiseCurveConversionFromDiscretePointsTest, Error, value on curve is wrong : ");
point_t p0(0.,0.,0.);
point_t p1(1.,2.,3.);
......@@ -1357,10 +1360,18 @@ void piecewiseCurveConversionFromDiscretePointsTest(bool& error)
ComparePoints(p1, ppc(T_min+timestep), errMsg, error);
ComparePoints(p2, ppc(T_min+2*timestep), errMsg, error);
ComparePoints(p3, ppc(T_max), errMsg, error);
}
catch(...)
{
error = true;
std::cout<<"Error in piecewiseCurveConversionFromDiscretePointsTest"<<std::endl;
}
}
void serializationCurvesTest(bool& error)
{
try
{
std::string errMsg1("in serializationCurveTest, Error While serializing Polynomial : ");
std::string errMsg2("in serializationCurveTest, Error While serializing Bezier : ");
std::string errMsg3("in serializationCurveTest, Error While serializing Cubic Hermite : ");
......@@ -1458,6 +1469,12 @@ void serializationCurvesTest(bool& error)
CompareCurves<piecewise_polynomial_curve_t,piecewise_polynomial_curve_t>(ppc,
(*dynamic_cast<piecewise_polynomial_curve_t*>(pt_1)),
errMsg6, error);
}
catch(...)
{
error = true;
std::cout<<"Error in serializationCurvesTest"<<std::endl;
}
}
int main(int /*argc*/, char** /*argv[]*/)
......
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