idyntree icon indicating copy to clipboard operation
idyntree copied to clipboard

Support std::vector<std::string> function parameters in Matlab/Python

Open traversaro opened this issue 9 years ago • 6 comments

We started to use a lot of instances of std::vector<std::string> as input/output parameter of function and methods. We need to properly modify SWIG .i configuration files to make sure that this function can be used in Matlab. The first step (currently investigated by @nunoguedelha ) is to just instantiate the std::vector<std::string> template during the SWIG bindings generation.

A cleaner way would be to define proper typemaps between std::vector<std::string> and the appropriate data structure in the target language (cell array of strings in matlab, list of strings in python, table of strings in lua).

traversaro avatar Feb 09 '16 10:02 traversaro

:+1:


Naveen Kuppuswamy, PhD Post-doctoral Fellow, Dynamic Interaction Control Lab, iCub Facility, Istituto Italiano di Tecnologia, Genova, Italy

On Tue, Feb 9, 2016 at 11:06 AM, Silvio Traversaro <[email protected]

wrote:

We started to use a lot of instances of std::vectorstd::string as input/output parameter of function and methods. We need to properly modify SWIG .i configuration files to make sure that this function can be used in Matlab. The first step (currently investigated by @nunoguedelha https://github.com/nunoguedelha ) is to just instantiate the std::vectorstd::string template during the SWIG bindings generation.

A cleaner way would be to define proper typemaps between std::vectorstd::string and the appropriate data structure in the target language (cell array of strings in matlab, list of strings in python, table of strings in lua).

— Reply to this email directly or view it on GitHub https://github.com/robotology/idyntree/issues/135.

naveenoid avatar Feb 10 '16 11:02 naveenoid

The StringVector template instantiation can be easily populated with the push_back method, but at least in Matlab I did not find any way of retrieving its contents. I wonder if it something due that should be solved upstream in https://github.com/jaeandersson/swig/blob/matlab/Lib/matlab/std_vector.i or what.

traversaro avatar Jul 21 '16 16:07 traversaro

Any knowledge update regarding handling std::vector<T> of generic objects? Thanks in advance!

prashanthr05 avatar Jun 10 '19 09:06 prashanthr05

Like an automatic typemap that converts std::vector<iDynTree::ComplexObject> to a cell array of iDynTree.ComplexObject Matlab objects? To be honest I do not know how to handle that.

traversaro avatar Jun 10 '19 09:06 traversaro

I was trying to handle a vector of rotations like std::vector<iDynTree::Rotation>, so I created a template in iDynTree.i as %template(RotationVector) std::vector<iDynTree::Rotation>; and this enables the use of standard std::vector methods to handle iDynTree::Rotation

prashanthr05 avatar Jun 10 '19 09:06 prashanthr05

Ok, that seems to be a solution in line with the StringVector strategy.

traversaro avatar Jun 10 '19 09:06 traversaro