Commit 14e11dfc authored by JasonChmn's avatar JasonChmn
Browse files

Add conversion functions from piecewise curve to python bindings, Test OK

parent ccc49820
Pipeline #5850 passed with stage
in 3 minutes and 25 seconds
......@@ -367,6 +367,10 @@ namespace curves
"Add a new curve to piecewise curve, which should be defined in T_{min},T_{max}] "
"where T_{min} is equal toT_{max} of the actual piecewise curve.")
.def("is_continuous", &piecewise_polynomial_curve_t::is_continuous,"Check if the curve is continuous at the given order.")
.def("convert_piecewise_curve_to_bezier", &piecewise_polynomial_curve_t::convert_piecewise_curve_to_bezier<bezier_t>,
"Convert a piecewise polynomial curve to to a piecewise bezier curve")
.def("convert_piecewise_curve_to_cubic_hermite", &piecewise_polynomial_curve_t::convert_piecewise_curve_to_cubic_hermite<cubic_hermite_spline_t>,
"Convert a piecewise polynomial curve to to a piecewise cubic hermite spline")
.def("saveAsText", &piecewise_polynomial_curve_t::saveAsText<piecewise_polynomial_curve_t>,bp::args("filename"),"Saves *this inside a text file.")
.def("loadFromText",&piecewise_polynomial_curve_t::loadFromText<piecewise_polynomial_curve_t>,bp::args("filename"),"Loads *this from a text file.")
.def("saveAsXML",&piecewise_polynomial_curve_t::saveAsXML<piecewise_polynomial_curve_t>,bp::args("filename","tag_name"),"Saves *this inside a XML file.")
......@@ -385,6 +389,10 @@ namespace curves
.def("derivate", &piecewise_bezier_curve_t::derivate)
.def("add_curve", &piecewise_bezier_curve_t::add_curve)
.def("is_continuous", &piecewise_bezier_curve_t::is_continuous)
.def("convert_piecewise_curve_to_polynomial", &piecewise_bezier_curve_t::convert_piecewise_curve_to_polynomial<polynomial_t>,
"Convert a piecewise bezier curve to to a piecewise polynomial curve")
.def("convert_piecewise_curve_to_cubic_hermite", &piecewise_bezier_curve_t::convert_piecewise_curve_to_cubic_hermite<cubic_hermite_spline_t>,
"Convert a piecewise bezier curve to to a piecewise cubic hermite spline")
.def("saveAsText", &piecewise_bezier_curve_t::saveAsText<piecewise_bezier_curve_t>,bp::args("filename"),"Saves *this inside a text file.")
.def("loadFromText",&piecewise_bezier_curve_t::loadFromText<piecewise_bezier_curve_t>,bp::args("filename"),"Loads *this from a text file.")
.def("saveAsXML",&piecewise_bezier_curve_t::saveAsXML<piecewise_bezier_curve_t>,bp::args("filename","tag_name"),"Saves *this inside a XML file.")
......@@ -403,6 +411,10 @@ namespace curves
.def("derivate", &piecewise_cubic_hermite_curve_t::derivate)
.def("add_curve", &piecewise_cubic_hermite_curve_t::add_curve)
.def("is_continuous", &piecewise_cubic_hermite_curve_t::is_continuous)
.def("convert_piecewise_curve_to_polynomial", &piecewise_cubic_hermite_curve_t::convert_piecewise_curve_to_polynomial<polynomial_t>,
"Convert a piecewise cubic hermite spline to to a piecewise polynomial curve")
.def("convert_piecewise_curve_to_bezier", &piecewise_cubic_hermite_curve_t::convert_piecewise_curve_to_bezier<bezier_t>,
"Convert a piecewise cubic hermite spline to to a piecewise bezier curve")
.def("saveAsText", &piecewise_cubic_hermite_curve_t::saveAsText<piecewise_cubic_hermite_curve_t>,bp::args("filename"),"Saves *this inside a text file.")
.def("loadFromText",&piecewise_cubic_hermite_curve_t::loadFromText<piecewise_cubic_hermite_curve_t>,bp::args("filename"),"Loads *this from a text file.")
.def("saveAsXML",&piecewise_cubic_hermite_curve_t::saveAsXML<piecewise_cubic_hermite_curve_t>,bp::args("filename","tag_name"),"Saves *this inside a XML file.")
......
......@@ -338,6 +338,24 @@ class TestCurves(unittest.TestCase):
self.assertTrue(norm(a(0.3) - a_bc(0.3)) < __EPS)
return
def test_conversion_piecewise_curves(self):
__EPS = 1e-6
waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
a = bezier(waypoints, 0., 1.)
b = bezier(waypoints, 1., 2.)
pc = piecewise_bezier_curve(a)
pc.add_curve(b)
# Convert to piecewise polynomial
pc_pol = pc.convert_piecewise_curve_to_polynomial()
self.assertTrue(norm(pc_pol(0.3) - pc(0.3)) < __EPS)
# Convert to piecewise cubic hermite
pc_chs = pc.convert_piecewise_curve_to_cubic_hermite()
self.assertTrue(norm(pc_chs(0.3) - pc(0.3)) < __EPS)
# Convert to piecewise bezier
pc_bc = pc_chs.convert_piecewise_curve_to_bezier()
self.assertTrue(norm(pc_bc(0.3) - pc(0.3)) < __EPS)
return
if __name__ == '__main__':
unittest.main()
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