27 #include <rtt/types/Types.hpp> 35 #include <boost/lexical_cast.hpp> 37 #define DECLARE_RTT_VECTOR_EXPORTS( VectorType ) \ 38 template class RTT_EXPORT RTT::internal::DataSourceTypeInfo< VectorType >; \ 39 template class RTT_EXPORT RTT::internal::DataSource< VectorType >; \ 40 template class RTT_EXPORT RTT::internal::AssignableDataSource< VectorType >; \ 41 template class RTT_EXPORT RTT::internal::AssignCommand< VectorType >; \ 42 template class RTT_EXPORT RTT::internal::ValueDataSource< VectorType >; \ 43 template class RTT_EXPORT RTT::internal::ConstantDataSource< VectorType >; \ 44 template class RTT_EXPORT RTT::internal::ReferenceDataSource< VectorType >; \ 45 template class RTT_EXPORT RTT::OutputPort< VectorType >; \ 46 template class RTT_EXPORT RTT::InputPort< VectorType >; \ 47 template class RTT_EXPORT RTT::Property< VectorType >; \ 48 template class RTT_EXPORT RTT::Attribute< VectorType >; \ 49 template class RTT_EXPORT RTT::Constant< VectorType >; 57 #define DECLARE_RTT_MATRIX_EXPORTS( MatrixType ) \ 58 template class RTT_EXPORT RTT::internal::DataSourceTypeInfo< MatrixType >; \ 59 template class RTT_EXPORT RTT::internal::DataSource< MatrixType >; \ 60 template class RTT_EXPORT RTT::internal::AssignableDataSource< MatrixType >; \ 61 template class RTT_EXPORT RTT::internal::AssignCommand< MatrixType >; \ 62 template class RTT_EXPORT RTT::internal::ValueDataSource< MatrixType >; \ 63 template class RTT_EXPORT RTT::internal::ConstantDataSource< MatrixType >; \ 64 template class RTT_EXPORT RTT::internal::ReferenceDataSource< MatrixType >; \ 65 template class RTT_EXPORT RTT::OutputPort< MatrixType >; \ 66 template class RTT_EXPORT RTT::InputPort< MatrixType >; \ 67 template class RTT_EXPORT RTT::Property< MatrixType >; \ 68 template class RTT_EXPORT RTT::Attribute< MatrixType >; \ 69 template class RTT_EXPORT RTT::Constant< MatrixType >; 83 template<
typename Derived>
84 std::istream&
operator>>(std::istream &is, EigenBase<Derived>& v){
88 template<
typename VectorType>
91 if (index >= (
int) (v.size()) || index < 0)
96 template<
typename VectorType>
99 if (index >= (
int) (v.size()) || index < 0)
104 template<
typename VectorType>
110 template<
class VectorType>
112 #if (RTT_VERSION_MAJOR*100+RTT_VERSION_MINOR) >= 206 120 #if (RTT_VERSION_MAJOR*100+RTT_VERSION_MINOR) >= 206 121 bool installTypeInfoObject(
TypeInfo* ti) {
123 typedef typename boost::shared_ptr< VectorTypeInfo > sh_ptr;
124 sh_ptr mthis = boost::dynamic_pointer_cast<
VectorTypeInfo >( this->getSharedPtr() );
138 if (arg->isAssignable()) {
141 asarg->set().conservativeResizeLike(VectorType::Zero(size));
150 std::vector<std::string> result;
151 result.push_back(
"size");
152 result.push_back(
"capacity");
159 unsigned int indx = boost::lexical_cast<
unsigned int>(name);
173 if ( id_name->
get() ==
"size" || id_name->
get() ==
"capacity") {
182 if ( item->isAssignable() )
193 log(
Error) <<
"EigenVectorTypeInfo: No such member : " << id_name->
get() << endlog();
196 log(
Error) <<
"EigenVectorTypeInfo: Invalid index : " << id_indx->
get() <<
":"<< id_indx->
getTypeName() << endlog();
198 if ( !id_name && ! id_indx)
199 log(
Error) <<
"EigenVectorTypeInfo: Not a member or index : " <<
id <<
":"<<
id->getTypeName() << endlog();
206 targetbag.
setType(this->getTypeName());
207 int dimension = vec.rows();
210 if(!targetbag.
empty())
213 for (
int i=0; i < dimension ; i++){
214 std::stringstream out;
225 if ( bag.
getType() == this->getTypeName() ) {
226 int dimension = bag.
size();
227 result.conservativeResizeLike(VectorType::Zero(dimension));
230 for (
int i = 0; i < dimension ; i++) {
231 std::stringstream out;
235 result(i) = elem.
get();
237 log(
Error)<<
"Could not read element "<<i+1<<endlog();
242 log(
Error) <<
"Composing Property< " << this->getTypeName() <<
" > :" 243 <<
" type mismatch, got type '"<< bag.
getType()
244 <<
"', expected type "<<
"eigen_vector."<<endlog();
251 template<
typename MatrixType>
258 targetbag.
setType(this->getTypeName());
259 unsigned int dimension = mat.rows();
260 if(!targetbag.
empty())
263 for (
unsigned int i=0; i < dimension ; i++){
264 std::stringstream out;
273 if ( bag.
getType() == this->getTypeName() ) {
274 unsigned int rows = bag.
size();
275 unsigned int cols = 0;
277 for (
unsigned int i = 0; i < rows ; i++) {
278 std::stringstream out;
281 if(!row_bag.
ready()){
282 log(
Error)<<
"Could not read row "<<i+1<<endlog();
286 if(!(row_p.compose(row_bag))){
287 log(
Error)<<
"Could not compose row "<<i+1<<endlog();
292 cols = row_p.get().size();
293 result.resize(rows,cols);
295 if(row_p.get().rows()!=(int)cols){
296 log(
Error)<<
"Row "<<i+1<<
" size does not match matrix columns"<<endlog();
299 result.row(i)=row_p.get();
301 log(
Error)<<
"Property of Row "<<i+1<<
"was not ready for use"<<endlog();
306 log(
Error) <<
"Composing Property< " << this->getTypeName() <<
" > :" 307 <<
" type mismatch, got type '"<< bag.
getType()
308 <<
"', expected type "<<
"ublas_matrix."<<endlog();
315 template<
class VectorType>
317 :
public std::binary_function<const VectorType&, int, double>
321 if ( index >= (
int)(v.size()) || index < 0)
327 template<
class VectorType>
329 :
public std::unary_function<const VectorType&, int>
337 template<
class VectorType>
339 :
public std::binary_function<int,double,VectorType>
341 typedef VectorType (Signature)( int, double );
344 return VectorType::Constant(size,value);
348 template<
class VectorType>
350 :
public std::unary_function<std::vector<double>,VectorType>
352 typedef VectorType (Signature)( std::vector<double> );
355 return VectorType::Map(values.data(),values.size());
359 template<
class VectorType>
361 :
public std::unary_function<std::vector<double>,VectorType>
363 typedef VectorType (Signature)( std::vector<double> );
366 int size = VectorType::RowsAtCompileTime;
367 if(size != Eigen::Dynamic && size != values.size())
369 log(
Debug) <<
"Cannot copy an std vector of size " << values.size()
370 <<
" into an eigen vector of (fixed) size " << size
375 return VectorType::Map(values.data(),values.size());
379 template<
class VectorType>
381 :
public std::unary_function<int,VectorType>
383 typedef VectorType (Signature)( int );
386 return VectorType::Zero(size);
390 template<
typename MatrixType>
395 if ( i >= (
int)(m.rows()) || i < 0 || j<0 || j>= (
int)(m.cols()))
401 template<
typename MatrixType>
403 :
public std::binary_function<int,int,MatrixType>
405 typedef MatrixType (Signature)( int, int );
408 return MatrixType::Zero(size1,size2);
#define ORO_TYPEKIT_PLUGIN(TYPEKIT)
virtual bool loadOperators()
DataSourceType get() const
virtual bool composeTypeImpl(const PropertyBag &bag, VectorType &result) const
virtual result_t get() const =0
Matrix< double, 6, 1 > Vector6d
void add(base::PropertyBase *p)
VectorType operator()(int size, double value) const
virtual std::string getName()
virtual std::vector< std::string > getMemberNames() const
const std::string & getType() const
static shared_ptr Instance()
MatrixType operator()(int size1, int size2) const
bool composeTypeImpl(const PropertyBag &bag, MatrixType &result) const
base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, const std::string &name) const
void setType(const std::string &newtype)
VectorType operator()(std::vector< double > values) const
base::DataSourceBase * newFunctorDataSource(Function f, const std::vector< base::DataSourceBase::shared_ptr > &args)
double operator()(const MatrixType &m, int i, int j) const
#define DECLARE_RTT_VECTOR_EXPORTS(VectorType)
VectorTypeInfo(const std::string &type_name)
bool decomposeTypeImpl(const MatrixType &mat, PropertyBag &targetbag) const
bool resize(base::DataSourceBase::shared_ptr arg, int size) const
#define DECLARE_RTT_MATRIX_EXPORTS(MatrixType)
MatrixTypeInfo(const std::string &type_name)
BinaryOperator< function > * newBinaryOperator(const char *op, function f)
const std::string & getDescription() const
static AssignableDataSource< T > * narrow(base::DataSourceBase *db)
void setMemberFactory(MemberFactoryPtr mf)
TypeInfoRepository::shared_ptr Types()
VectorType operator()(std::vector< double > values) const
boost::intrusive_ptr< DataSource< T > > shared_ptr
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
VectorType operator()(int size) const
base::PropertyBase * getProperty(const std::string &name) const
static shared_ptr Instance()
virtual bool decomposeTypeImpl(const VectorType &vec, PropertyBag &targetbag) const
static DataSource< T > * narrow(base::DataSourceBase *db)
double get_item_copy(const VectorType &v, int index)
double & get_item(VectorType &v, int index)
bool installTypeInfoObject(TypeInfo *ti)
int get_size(const VectorType &v)
std::istream & operator>>(std::istream &is, EigenBase< Derived > &v)
base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, base::DataSourceBase::shared_ptr id) const
virtual std::string getTypeName() const
const std::string & getName() const
int operator()(const VectorType &cont) const
boost::intrusive_ptr< DataSourceBase > shared_ptr
double operator()(const VectorType &v, int index) const
virtual bool loadConstructors()