hpp-corbaserver  4.15.1
Corba server for Humanoid Path Planner applications
conversions.hh
Go to the documentation of this file.
1 // Copyright (c) 2016, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // 1. Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28 
29 #ifndef HPP_CORBASERVER_CONVERSIONS_HH
30 #define HPP_CORBASERVER_CONVERSIONS_HH
31 
32 #include <hpp/common-idl.hh>
33 #include <hpp/corbaserver/fwd.hh>
34 #include <hpp/core/parameter.hh>
35 #include <hpp/util/exception-factory.hh>
36 
37 namespace hpp {
38 namespace corbaServer {
39 typedef Eigen::Matrix<CORBA::Long, Eigen::Dynamic, Eigen::Dynamic> IntMatrix_t;
40 
41 void toTransform3f(const Transform_ in, Transform3f& out);
42 
44 
45 std::vector<Transform3f> toTransform3f(const TransformSeq in);
46 
47 void toHppTransform(const Transform3f& in, Transform_ out);
48 
50 
51 void toIntSeq(std::vector<int> const& in, intSeq& out);
52 
53 floatSeq* vectorToFloatSeq(core::vectorIn_t input);
54 
55 void vectorToFloatSeq(core::vectorIn_t input, floatSeq& output);
56 
58  if (!input) return NULL;
59  return vectorToFloatSeq(*input);
60 }
61 
63 // Return [ [input.row(0)], [input.row(1)], ...]
64 floatSeqSeq* matrixToFloatSeqSeq(core::matrixIn_t input);
65 
66 intSeqSeq* matrixToIntSeqSeq(Eigen::Ref<const IntMatrix_t> input);
67 
68 std::vector<int> intSeqToVector(const intSeq& dofArray);
69 
70 vector3_t floatSeqToVector3(const floatSeq& dofArray);
71 
72 vector_t floatSeqToVector(const floatSeq& dofArray,
73  const size_type expectedSize = -1);
74 
76  const floatSeq& dofArray,
77  bool throwIfNotNormalized);
78 
80  const floatSeq& dofArray,
81  bool throwIfNotNormalized);
82 
84  const size_type expectedRows = -1,
85  const size_type expectedCols = -1);
86 
88  const size_type expectedRows = -1,
89  const size_type expectedCols = -1);
90 
91 std::vector<bool> boolSeqToVector(const hpp::boolSeq& mask,
92  unsigned int length = 3);
93 
94 stringSeqSeq* vectorToStringSeqSeq(std::vector<std::vector<std::string>> input);
95 
96 inline char* c_str(const std::string& in) {
97  char* out = new char[in.length() + 1];
98  strcpy(out, in.c_str());
99  return out;
100 }
101 
102 template <typename InputIt>
103 inline Names_t* toNames_t(InputIt begin, InputIt end) {
104  std::size_t len = std::distance(begin, end);
105  char** nameList = Names_t::allocbuf((CORBA::ULong)len);
106  Names_t* ret =
107  new Names_t((CORBA::ULong)len, (CORBA::ULong)len, nameList, true);
108 
109  std::size_t i = 0;
110  while (begin != end) {
111  nameList[i] = c_str(*begin);
112  ++begin;
113  ++i;
114  }
115  return ret;
116 }
117 
118 template <typename Iterable>
119 inline Names_t* toNames_t(const Iterable& iterable) {
120  return toNames_t(iterable.begin(), iterable.end());
121 }
122 
123 template <typename InputIt>
124 inline intSeq* toIntSeq(InputIt begin, InputIt end) {
125  std::size_t len = std::distance(begin, end);
126  intSeq* indexes = new intSeq();
127  indexes->length((CORBA::ULong)len);
128 
129  std::size_t i = 0;
130  while (begin != end) {
131  (*indexes)[(CORBA::ULong)i] = *begin;
132  ++begin;
133  ++i;
134  }
135  return indexes;
136 }
137 
138 intSeq* toIntSeq(std::vector<int> const& in);
139 
140 template <typename InputIt>
141 inline boolSeq* toBoolSeq(InputIt begin, InputIt end) {
142  std::size_t len = std::distance(begin, end);
143  boolSeq* indexes = new boolSeq();
144  indexes->length((CORBA::ULong)len);
145 
146  std::size_t i = 0;
147  while (begin != end) {
148  (*indexes)[(CORBA::ULong)i] = *begin;
149  ++begin;
150  ++i;
151  }
152  return indexes;
153 }
154 
155 template <typename OutputType>
156 inline OutputType toStrings(const Names_t& names) {
157  OutputType ret;
158  for (CORBA::ULong i = 0; i < names.length(); ++i)
159  ret.push_back(std::string(names[i]));
160  return ret;
161 }
162 
165 
168 
169 core::Parameter toParameter(const CORBA::Any& any);
170 
171 CORBA::Any toCorbaAny(const core::Parameter& parameter);
172 
173 inline CORBA::Any* toCorbaAnyPtr(const core::Parameter& parameter) {
174  CORBA::Any* ap = new CORBA::Any;
175  *ap = toCorbaAny(parameter);
176  return ap;
177 }
178 
179 } // namespace corbaServer
180 } // namespace hpp
181 
182 #endif // HPP_CORBASERVER_CONVERSIONS_HH
CORBA::Any * toCorbaAnyPtr(const core::Parameter &parameter)
Definition: conversions.hh:173
pinocchio::DevicePtr_t DevicePtr_t
Definition: fwd.hh:74
void toIntSeq(std::vector< int > const &in, intSeq &out)
boolSeq * toBoolSeq(InputIt begin, InputIt end)
Definition: conversions.hh:141
Definition: common-idl.hh:965
core::matrix_t floatSeqSeqToMatrix(const floatSeqSeq &input, const size_type expectedRows=-1, const size_type expectedCols=-1)
ConfigurationPtr_t floatSeqToConfigPtr(const DevicePtr_t &robot, const floatSeq &dofArray, bool throwIfNotNormalized)
Definition: common-idl.hh:461
Implement CORBA interface `‘Obstacle’&#39;.
Definition: client.hh:46
constraints::ComparisonTypes_t convertComparison(hpp::ComparisonTypes_t comp)
Convert CORBA comparison types to C++ comparison type.
std::vector< bool > boolSeqToVector(const hpp::boolSeq &mask, unsigned int length=3)
std::vector< int > intSeqToVector(const intSeq &dofArray)
vector_t floatSeqToVector(const floatSeq &dofArray, const size_type expectedSize=-1)
char * c_str(const std::string &in)
Definition: conversions.hh:96
sequence< string > Names_t
Sequence of names.
Definition: common.idl:23
sequence< long > intSeq
Definition: common.idl:31
pinocchio::vector_t vector_t
Definition: fwd.hh:109
Definition: common-idl.hh:78
Eigen::Matrix< CORBA::Long, Eigen::Dynamic, Eigen::Dynamic > IntMatrix_t
Definition: conversions.hh:39
Definition: common-idl.hh:803
core::ConfigurationPtr_t ConfigurationPtr_t
Definition: fwd.hh:67
Definition: common-idl.hh:347
stringSeqSeq * vectorToStringSeqSeq(std::vector< std::vector< std::string >> input)
sequence< boolean > boolSeq
Definition: common.idl:30
pinocchio::Configuration_t Configuration_t
Definition: fwd.hh:66
void toHppTransform(const Transform3f &in, Transform_ out)
Names_t * toNames_t(InputIt begin, InputIt end)
Definition: conversions.hh:103
intSeqSeq * matrixToIntSeqSeq(Eigen::Ref< const IntMatrix_t > input)
OutputType toStrings(const Names_t &names)
Definition: conversions.hh:156
core::Parameter toParameter(const CORBA::Any &any)
Definition: common-idl.hh:575
IntMatrix_t intSeqSeqToMatrix(const intSeqSeq &input, const size_type expectedRows=-1, const size_type expectedCols=-1)
double Transform_[7]
Element of SE(3) represented by a vector and a unit quaternion.
Definition: common.idl:38
pinocchio::matrix_t matrix_t
Definition: fwd.hh:107
pinocchio::vector3_t vector3_t
Definition: fwd.hh:110
vector3_t floatSeqToVector3(const floatSeq &dofArray)
floatSeqSeq * matrixToFloatSeqSeq(core::matrixIn_t input)
Returns a sequence of the rows of the input matrix.
floatSeq * vectorToFloatSeq(core::vectorIn_t input)
_CORBA_MODULE hpp _CORBA_MODULE_BEG _CORBA_MODULE core_idl _CORBA_MODULE_BEG typedef ::CORBA::ULongLong size_t
Definition: paths-idl.hh:75
Definition: common-idl.hh:192
Definition: common-idl.hh:689
sequence< ComparisonType > ComparisonTypes_t
Definition: common.idl:50
Configuration_t floatSeqToConfig(const DevicePtr_t &robot, const floatSeq &dofArray, bool throwIfNotNormalized)
void toTransform3f(const Transform_ in, Transform3f &out)
pinocchio::Transform3f Transform3f
Definition: fwd.hh:103
::CORBA::Double Transform__slice
Definition: common-idl.hh:916
long long size_type
Definition: common.idl:19
CORBA::Any toCorbaAny(const core::Parameter &parameter)