Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added RotationSpline pybind11 interface #339

Merged
merged 4 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ if (PYTHONLIBS_FOUND)
PID_TEST
Plane_TEST
python_TEST
RotationSpline_TEST
SignalStats_TEST
Sphere_TEST
SphericalCoordinates_TEST
Expand Down
2 changes: 2 additions & 0 deletions src/python_pybind11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if (${pybind11_FOUND})
src/Material.cc
src/Rand.cc
src/RollingMean.cc
src/RotationSpline.cc
src/SemanticVersion.cc
src/Spline.cc
src/StopWatch.cc
Expand Down Expand Up @@ -90,6 +91,7 @@ if (${pybind11_FOUND})
Quaternion_TEST
Rand_TEST
RollingMean_TEST
RotationSpline_TEST
SemanticVersion_TEST
Spline_TEST
StopWatch_TEST
Expand Down
72 changes: 72 additions & 0 deletions src/python_pybind11/src/RotationSpline.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <string>
#include "RotationSpline.hh"
#include <ignition/math/RotationSpline.hh>

namespace ignition
{
namespace math
{
namespace python
{
void defineMathRotationSpline(py::module &m, const std::string &typestr)
{
using Class = ignition::math::RotationSpline;
std::string pyclass_name = typestr;
py::class_<Class>(m,
pyclass_name.c_str(),
py::buffer_protocol(),
py::dynamic_attr())
.def(py::init<>())
.def("add_point",
&Class::AddPoint,
"Adds a control point to the end of the spline.")
.def("point",
&Class::Point,
py::return_value_policy::reference,
"Gets the detail of one of the control points of the spline.")
.def("point_count",
&Class::PointCount,
"Gets the number of control points in the spline.")
.def("clear",
&Class::Clear,
"Clears all the points in the spline.")
.def("update_point",
&Class::UpdatePoint,
"Updates a single point in the spline.")
.def("interpolate",
py::overload_cast<double, const bool>(&Class::Interpolate),
py::arg("_t") = 0, py::arg("_useShortestPath") = true,
"Returns an interpolated point based on a parametric "
"value over the whole series.")
.def("interpolate",
py::overload_cast<const unsigned int, const double, const bool>
(&Class::Interpolate),
py::arg("_fromIndex") = 0,
py::arg("_t") = 0, py::arg("_useShortestPath") = true,
"Interpolates a single segment of the spline "
"given a parametric value.")
.def("auto_calculate", &Class::AutoCalculate,
"Tells the spline whether it should automatically calculate "
"tangents on demand as points are added.")
.def("recalc_tangents", &Class::RecalcTangents,
"Recalculates the tangents associated with this spline.");
}
} // namespace python
} // namespace math
} // namespace ignition
42 changes: 42 additions & 0 deletions src/python_pybind11/src/RotationSpline.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef IGNITION_MATH_PYTHON__ROTATIONSPLINE_HH_
#define IGNITION_MATH_PYTHON__ROTATIONSPLINE_HH_

#include <pybind11/pybind11.h>
#include <string>

namespace py = pybind11;

namespace ignition
{
namespace math
{
namespace python
{
/// Define a pybind11 wrapper for an ignition::math::RotationSpline
/**
* \param[in] module a pybind11 module to add the definition to
* \param[in] typestr name of the type used by Python
*/
void defineMathRotationSpline(py::module &m, const std::string &typestr);
} // namespace python
} // namespace math
} // namespace ignition

#endif // IGNITION_MATH_PYTHON__ROTATIONSPLINE_HH_
3 changes: 3 additions & 0 deletions src/python_pybind11/src/_ignition_math_pybind11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "Quaternion.hh"
#include "Rand.hh"
#include "RollingMean.hh"
#include "RotationSpline.hh"
#include "SemanticVersion.hh"
#include "Spline.hh"
#include "StopWatch.hh"
Expand Down Expand Up @@ -64,6 +65,8 @@ PYBIND11_MODULE(math, m)

ignition::math::python::defineMathRollingMean(m, "RollingMean");

ignition::math::python::defineMathRotationSpline(m, "RotationSpline");

ignition::math::python::defineMathSemanticVersion(m, "SemanticVersion");

ignition::math::python::defineMathSpline(m, "Spline");
Expand Down