Drake
rigidBodyTreeMexConversions.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "KinematicsCache.h"
5 #include "KinematicPath.h"
6 #include "drake/util/mexify.h"
7 
8 template <typename T>
10  enum { value = -1 };
11 };
12 template <>
14  enum { value = 1 };
15 };
16 template <>
18  enum { value = 2 };
19 };
20 template <>
22  KinematicsCache<Eigen::AutoDiffScalar<Eigen::VectorXd>>> {
23  enum { value = 3 };
24 };
25 template <>
28  enum { value = 4 };
29 };
30 
31 template <typename T>
32 bool isDrakeMexPointerOfCorrectType(const mxArray *source, T *,
33  std::ostream *log) NOEXCEPT {
34  if (!mxIsClass(source, "DrakeMexPointer")) {
35  if (log) *log << "Expected DrakeMexPointer";
36  return false;
37  }
38  int type_id =
39  static_cast<int>(mxGetScalar(mxGetProperty(source, 0, "type_id")));
40  if (type_id != DrakeMexPointerTypeId<T>::value) {
41  if (log) *log << "Expected DrakeMexPointer to " << typeid(T).name() << ".";
42  return false;
43  }
44  return true;
45 }
46 
50 bool isConvertibleFromMex(const mxArray *source, RigidBodyTree *ptr,
51  std::ostream *log) NOEXCEPT {
52  return isDrakeMexPointerOfCorrectType(source, ptr, log);
53 }
54 
55 RigidBodyTree &fromMexUnsafe(const mxArray *source, RigidBodyTree *) {
56  return *static_cast<RigidBodyTree *>(getDrakeMexPointer(source));
57 }
58 
59 template <typename Scalar>
60 bool isConvertibleFromMex(const mxArray *mex, KinematicsCache<Scalar> *ptr,
61  std::ostream *log) NOEXCEPT {
62  return isDrakeMexPointerOfCorrectType(mex, ptr, log);
63 }
64 
65 template <typename Scalar>
68  return *static_cast<KinematicsCache<Scalar> *>(getDrakeMexPointer(mex));
69 }
70 
71 // set<int>: not of sufficient quality yet
72 bool isConvertibleFromMex(const mxArray *source, std::set<int> *,
73  std::ostream *log) NOEXCEPT {
74  return true; // TODO(tkoolen): improve
75 }
76 
77 std::set<int> fromMexUnsafe(const mxArray *source, std::set<int> *) {
78  std::set<int> ret;
79  int num_robot = static_cast<int>(mxGetNumberOfElements(source));
80  double *data = mxGetPrSafe(source);
81  for (int i = 0; i < num_robot; i++) {
82  ret.insert((int)data[i]);
83  }
84  return ret;
85 }
86 
90 void toMex(const KinematicPath &path, mxArray *dest[], int nlhs) {
91  if (nlhs > 0) {
92  dest[0] = stdVectorToMatlab(path.body_path);
93  }
94  if (nlhs > 1) {
95  dest[1] = stdVectorToMatlab(path.joint_path);
96  }
97  if (nlhs > 2) {
99  }
100 }
Definition: KinematicPath.h:6
Definition: rigidBodyTreeMexConversions.h:10
DrakeJoint::AutoDiffFixedMaxSize AutoDiffFixedMaxSize
Definition: contactConstraintsmex.cpp:16
bool isDrakeMexPointerOfCorrectType(const mxArray *source, T *, std::ostream *log) NOEXCEPT
Definition: rigidBodyTreeMexConversions.h:32
FunctionalForm log(FunctionalForm const &x)
Definition: functional_form.cc:198
Definition: DrakeJoint.h:48
RigidBodyTree & fromMexUnsafe(const mxArray *source, RigidBodyTree *)
Definition: rigidBodyTreeMexConversions.h:55
double * mxGetPrSafe(const mxArray *pobj)
Definition: drakeMexUtil.cpp:236
mxArray * stdVectorToMatlab(const std::vector< Scalar > &vec)
Definition: drakeMexUtil.h:170
bool isConvertibleFromMex(const mxArray *source, RigidBodyTree *ptr, std::ostream *log) NOEXCEPT
fromMex specializations
Definition: rigidBodyTreeMexConversions.h:50
void toMex(const KinematicPath &path, mxArray *dest[], int nlhs)
toMex specializations
Definition: rigidBodyTreeMexConversions.h:90
std::vector< int > body_path
Definition: KinematicPath.h:9
std::vector< int > joint_direction_signs
Definition: KinematicPath.h:8
std::vector< int > joint_path
Definition: KinematicPath.h:7
void * getDrakeMexPointer(const mxArray *mx)
Definition: drakeMexUtil.cpp:122
Definition: rigidBodyTreeMexConversions.h:9
Definition: KinematicsCache.h:70
Definition: RigidBodyTree.h:72
#define NOEXCEPT
Definition: mexify.h:15