pinocchio 4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
constraints-variant.hpp
1//
2// Copyright (c) 2025 INRIA
3//
4
5#pragma once
6
7#include <boost/algorithm/string/replace.hpp>
8
9#include "pinocchio/bindings/python/algorithm/constraints/constraint-model.hpp"
10#include "pinocchio/bindings/python/algorithm/constraints/constraint-data.hpp"
11#include "pinocchio/bindings/python/algorithm/constraints/constraints-models.hpp"
12#include "pinocchio/bindings/python/algorithm/constraints/constraints-datas.hpp"
13#include "pinocchio/bindings/python/utils/std-vector.hpp"
14
15namespace pinocchio
16{
17 namespace python
18 {
19 namespace bp = boost::python;
20
21 template<typename T>
22 std::string sanitizedClassname()
23 {
24 std::string className = boost::replace_all_copy(T::classname(), "<", "_");
25 boost::replace_all(className, ">", "");
26 return className;
27 }
28
29 template<typename VariantType>
30 struct ConstraintVariantVisitor : boost::static_visitor<PyObject *>
31 {
32 static result_type convert(VariantType const & jv)
33 {
34 return apply_visitor(ConstraintVariantVisitor<VariantType>(), jv);
35 }
36
37 template<typename T>
38 result_type operator()(T const & t) const
39 {
40 return bp::incref(bp::object(t).ptr());
41 }
42 };
43
45 {
46 template<class T>
47 void operator()(T)
48 {
49 expose_constraint_data<T>(
50 bp::class_<T>(
51 sanitizedClassname<T>().c_str(), sanitizedClassname<T>().c_str(), bp::init<>())
54 .def(PrintableVisitor<T>()));
55 bp::implicitly_convertible<T, context::ConstraintData>();
56 }
57
58 void operator()(BlankConstraintData)
59 {
60 }
61 };
62
64 {
65 template<class T>
66 void operator()(T)
67 {
68 expose_constraint_model<T>(
69 bp::class_<T>(
70 sanitizedClassname<T>().c_str(), sanitizedClassname<T>().c_str(), bp::no_init)
73 .def(PrintableVisitor<T>()));
74 bp::implicitly_convertible<T, context::ConstraintModel>();
75 }
76
77 void operator()(BlankConstraintModel)
78 {
79 }
80 };
81
83 {
84 template<class T>
85 void operator()(T)
86 {
87 StdVectorPythonVisitor<std::vector<T>>::expose(
88 std::string("StdVec_") + sanitizedClassname<T>().c_str());
89 }
90
91 void operator()(BlankConstraintModel)
92 {
93 }
94
95 void operator()(BlankConstraintData)
96 {
97 }
98 };
99 } // namespace python
100} // namespace pinocchio
Main pinocchio namespace.
Definition treeview.dox:11
Set the Python method str and repr to use the overloading operator<<.
Definition printable.hpp:21