From c581f8eddfcd6e0bc6cbf121d8d4276377425496 Mon Sep 17 00:00:00 2001 From: Pierre Fernbach <pierre.fernbach@laas.fr> Date: Mon, 2 Dec 2019 14:43:31 +0100 Subject: [PATCH] [python] python-variables/python-definitions factorize code and uniformize names --- python/python_definitions.h | 32 ++++++++++++--- python/python_variables.cpp | 8 ++-- python/python_variables.h | 78 ++++++++----------------------------- 3 files changed, 47 insertions(+), 71 deletions(-) diff --git a/python/python_definitions.h b/python/python_definitions.h index d33b963..296a971 100644 --- a/python/python_definitions.h +++ b/python/python_definitions.h @@ -1,3 +1,4 @@ +#include "curves/fwd.h" #include "curves/bezier_curve.h" #include "curves/linear_variable.h" #include "curves/quadratic_variable.h" @@ -8,25 +9,44 @@ #define _DEFINITION_PYTHON_BINDINGS namespace curves { +/*** TEMPLATE SPECIALIZATION FOR PYTHON ****/ typedef double real; -typedef Eigen::Vector3d point_t; +typedef std::vector<real> t_time_t; +typedef Eigen::VectorXd time_waypoints_t; + +typedef Eigen::Matrix<double, Eigen::Dynamic, 1, 0, Eigen::Dynamic, 1> ret_pointX_t; +typedef std::pair<pointX_t, pointX_t> pair_pointX_tangent_t; +typedef Eigen::MatrixXd pointX_list_t; +typedef std::vector<pair_pointX_tangent_t, Eigen::aligned_allocator<pair_pointX_tangent_t> > t_pair_pointX_tangent_t; +typedef curves::curve_constraints<pointX_t> curve_constraints_t; +typedef curves::curve_constraints<point3_t> curve_constraints3_t; +typedef std::pair<real, pointX_t> waypoint_t; +typedef std::vector<waypoint_t> t_waypoint_t; +typedef Eigen::Matrix<real, Eigen::Dynamic, Eigen::Dynamic> point_listX_t; +typedef Eigen::Matrix<real, 3, Eigen::Dynamic> point_list3_t; +typedef Eigen::Matrix<real, 6, Eigen::Dynamic> point_list6_t; + +typedef polynomial_t::coeff_t coeff_t; +typedef curves::Bern<double> bernstein_t; +/* +typedef double real; +typedef Eigen::Vector3d point3_t; typedef Eigen::Vector3d tangent_t; typedef Eigen::VectorXd vectorX_t; -typedef std::pair<point_t, tangent_t> pair_point_tangent_t; +typedef std::pair<point3_t, tangent_t> pair_point_tangent_t; typedef Eigen::Matrix<double, 6, 1, 0, 6, 1> point6_t; typedef Eigen::Matrix<double, 3, 1, 0, 3, 1> ret_point_t; typedef Eigen::Matrix<double, 6, 1, 0, 6, 1> ret_point6_t; typedef Eigen::VectorXd time_waypoints_t; typedef Eigen::Matrix<real, 3, Eigen::Dynamic> point_list_t; typedef Eigen::Matrix<real, 6, Eigen::Dynamic> point_list6_t; -typedef std::vector<real> t_time_t; -typedef std::vector<point_t, Eigen::aligned_allocator<point_t> > t_point_t; +typedef std::vector<point3_t, Eigen::aligned_allocator<point3_t> > t_point3_t; typedef std::vector<point6_t, Eigen::aligned_allocator<point6_t> > t_point6_t; -typedef std::pair<real, point_t> Waypoint; +typedef std::pair<real, point3_t> Waypoint; typedef std::vector<Waypoint> T_Waypoint; typedef std::pair<real, point6_t> Waypoint6; typedef std::vector<Waypoint6> T_Waypoint6; - +*/ template <typename PointList, typename T_Point> T_Point vectorFromEigenArray(const PointList& array) { T_Point res; diff --git a/python/python_variables.cpp b/python/python_variables.cpp index 13e66c9..c4fdc50 100644 --- a/python/python_variables.cpp +++ b/python/python_variables.cpp @@ -4,7 +4,7 @@ #include <Eigen/Core> namespace curves { -std::vector<linear_variable_t> matrix3DFromEigenArray(const point_list_t& matrices, const point_list_t& vectors) { +std::vector<linear_variable_t> matrix3DFromEigenArray(const point_list3_t& matrices, const point_list3_t& vectors) { assert(vectors.cols() * 3 == matrices.cols()); std::vector<linear_variable_t> res; for (int i = 0; i < vectors.cols(); ++i) { @@ -19,7 +19,7 @@ linear_variable_t fillWithZeros(const linear_variable_t& var, const std::size_t return linear_variable_t(B, var.c()); } -std::vector<linear_variable_t> computeLinearControlPoints(const point_list_t& matrices, const point_list_t& vectors) { +std::vector<linear_variable_t> computeLinearControlPoints(const point_list3_t& matrices, const point_list3_t& vectors) { std::vector<linear_variable_t> res; std::vector<linear_variable_t> variables = matrix3DFromEigenArray(matrices, vectors); // now need to fill all this with zeros... @@ -29,12 +29,12 @@ std::vector<linear_variable_t> computeLinearControlPoints(const point_list_t& ma } /*linear variable control points*/ -bezier_linear_variable_t* wrapBezierLinearConstructor(const point_list_t& matrices, const point_list_t& vectors) { +bezier_linear_variable_t* wrapBezierLinearConstructor(const point_list3_t& matrices, const point_list3_t& vectors) { std::vector<linear_variable_t> asVector = computeLinearControlPoints(matrices, vectors); return new bezier_linear_variable_t(asVector.begin(), asVector.end()); } -bezier_linear_variable_t* wrapBezierLinearConstructorBounds(const point_list_t& matrices, const point_list_t& vectors, +bezier_linear_variable_t* wrapBezierLinearConstructorBounds(const point_list3_t& matrices, const point_list3_t& vectors, const real T_min, const real T_max) { std::vector<linear_variable_t> asVector = computeLinearControlPoints(matrices, vectors); return new bezier_linear_variable_t(asVector.begin(), asVector.end(), T_min, T_max); diff --git a/python/python_variables.h b/python/python_variables.h index 70ebfcb..9e4d290 100644 --- a/python/python_variables.h +++ b/python/python_variables.h @@ -1,3 +1,4 @@ +#include "curves/fwd.h" #include "curves/linear_variable.h" #include "curves/bezier_curve.h" #include "curves/polynomial.h" @@ -27,8 +28,8 @@ typedef quadratic_variable<real> quadratic_variable_t; typedef bezier_curve<real, real, true, linear_variable_t> bezier_linear_variable_t; /*linear variable control points*/ -bezier_linear_variable_t* wrapBezierLinearConstructor(const point_list_t& matrices, const point_list_t& vectors); -bezier_linear_variable_t* wrapBezierLinearConstructorBounds(const point_list_t& matrices, const point_list_t& vectors, +bezier_linear_variable_t* wrapBezierLinearConstructor(const point_list3_t& matrices, const point_list3_t& vectors); +bezier_linear_variable_t* wrapBezierLinearConstructorBounds(const point_list3_t& matrices, const point_list3_t& vectors, const real T_min, const real T_max); typedef Eigen::Matrix<real, Eigen::Dynamic, Eigen::Dynamic> matrix_x_t; @@ -57,74 +58,29 @@ struct LinearBezierVector { } }; -/*** TEMPLATE SPECIALIZATION FOR PYTHON ****/ -typedef double real; -typedef Eigen::VectorXd time_waypoints_t; - -typedef Eigen::VectorXd pointX_t; -typedef Eigen::Matrix<double, 3, 1> point3_t; -typedef Eigen::Matrix<double, Eigen::Dynamic, 1, 0, Eigen::Dynamic, 1> ret_pointX_t; -typedef std::pair<pointX_t, pointX_t> pair_pointX_tangent_t; -typedef Eigen::MatrixXd pointX_list_t; -typedef std::vector<pointX_t, Eigen::aligned_allocator<pointX_t> > t_pointX_t; -typedef std::vector<pointX_t, Eigen::aligned_allocator<point3_t> > t_point3_t; -typedef std::vector<pair_pointX_tangent_t, Eigen::aligned_allocator<pair_pointX_tangent_t> > t_pair_pointX_tangent_t; -typedef curves::curve_constraints<pointX_t> curve_constraints_t; -typedef curves::curve_constraints<point3_t> curve_constraints3_t; -typedef std::pair<real, pointX_t> waypoint_t; -typedef std::vector<waypoint_t> t_waypoint_t; -typedef Eigen::Matrix<real, 3, 3> matrix3_t; -typedef Eigen::Matrix<real, 4, 4> matrix4_t; -typedef Eigen::Transform<double, 3, Eigen::Affine> transform_t; -typedef Eigen::Quaternion<real> quaternion_t; - -// Curves -typedef curve_abc<real, real, true, pointX_t> curve_abc_t; // generic class of curve -typedef curve_abc<real, real, true, point3_t> curve_3_t; // generic class of curve of size 3 -typedef curve_abc<real, real, true, matrix3_t, point3_t> - curve_rotation_t; // templated class used for the rotation (return dimension are fixed) -typedef boost::shared_ptr<curve_abc_t> curve_ptr_t; -typedef boost::shared_ptr<curve_rotation_t> curve_rotation_ptr_t; -typedef curves::cubic_hermite_spline<real, real, true, pointX_t> cubic_hermite_spline_t; -typedef curves::bezier_curve<real, real, true, pointX_t> bezier_t; -typedef curves::bezier_curve<real, real, true, Eigen::Vector3d> bezier3_t; -typedef curves::polynomial<real, real, true, pointX_t, t_pointX_t> polynomial_t; -typedef polynomial_t::coeff_t coeff_t; -typedef curves::piecewise_curve<real, real, true, pointX_t, t_pointX_t, polynomial_t> piecewise_polynomial_curve_t; -typedef curves::piecewise_curve<real, real, true, pointX_t, t_pointX_t, bezier_t> piecewise_bezier_curve_t; -typedef curves::piecewise_curve<real, real, true, pointX_t, t_pointX_t, cubic_hermite_spline_t> - piecewise_cubic_hermite_curve_t; -typedef curves::piecewise_curve<real, real, true, linear_variable_t, - std::vector<linear_variable_t, Eigen::aligned_allocator<linear_variable_t> >, - bezier_linear_variable_t> - piecewise_bezier_linear_curve_t; -typedef curves::exact_cubic<real, real, true, pointX_t, t_pointX_t> exact_cubic_t; -typedef SO3Linear<double, double, true> SO3Linear_t; -typedef SE3Curve<double, double, true> SE3Curve_t; -typedef curves::piecewise_curve<real, real, true, SE3Curve_t::point_t, t_pointX_t, SE3Curve_t,SE3Curve_t::point_derivate_t> piecewise_SE3_curve_t; -typedef curves::Bern<double> bernstein_t; /*** TEMPLATE SPECIALIZATION FOR PYTHON ****/ } // namespace curves - EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::bernstein_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::cubic_hermite_spline_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::bezier_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::bezier3_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::polynomial_t) EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::curve_constraints_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::piecewise_polynomial_curve_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::piecewise_bezier_curve_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::piecewise_cubic_hermite_curve_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::piecewise_bezier_linear_curve_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::exact_cubic_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::SO3Linear_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::SE3Curve_t) -EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::piecewise_SE3_curve_t) EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::matrix_x_t) EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::pointX_t) EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::linear_variable_t) EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::bezier_linear_variable_t) EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::matrix_pair) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::polynomial_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::exact_cubic_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::bezier_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::cubic_hermite_spline_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::piecewise_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::polynomial3_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::exact_cubic3_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::bezier3_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::cubic_hermite_spline3_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::piecewise3_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::SO3Linear_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::SE3Curve_t) +EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(curves::piecewise_SE3_t) + #endif //_VARIABLES_PYTHON_BINDINGS -- GitLab