22 #include <rtt/Property.hpp> 23 #include <rtt/PropertyBag.hpp> 24 #include <rtt/TemplateTypeInfo.hpp> 25 #include <rtt/Operators.hpp> 26 #include <rtt/OperatorTypes.hpp> 27 #include <rtt/Types.hpp> 28 #include <rtt/Logger.hpp> 29 #include <rtt/DataSources.hpp> 30 #include <rtt/mystd.hpp> 31 #include <rtt/os/StartStopManager.hpp> 32 #include <rtt/Toolkit.hpp> 34 #include "../../wrappers/matrix/vector_wrapper.h" 35 #include "../../wrappers/matrix/matrix_wrapper.h" 36 #include "../../bfl_constants.h" 37 #include "../../sample/sample.h" 39 #include <rtt/VectorTemplateComposition.hpp> 57 #ifndef __PROB_STREAM__ 58 #define __PROB_STREAM__ 76 #endif //__PROBSTREAM__ 94 targetbag.setType(
"Probability");
96 targetbag.add(
new Property<double>(
"Probability",
"Probability value", probDouble ) );
101 Property<double>* probability = bag.getProperty<
double>(
"Probability");
104 prob = (probability)->
get();
111 struct VectorTypeInfo :
public TemplateContainerTypeInfo<ColumnVector,int,double,ArrayIndexChecker<ColumnVector >, VectorAssignChecker<ColumnVector >,true>
119 targetbag.setType(
"ColumnVector");
120 int dimension = vec.size();
123 for (
int i=1; i <= dimension ; i++){
124 std::stringstream out;
127 targetbag.add(
new Property<double>(str, str +
"th element of vector",vec(i)) );
135 if ( bag.getType() ==
"ColumnVector" ) {
136 int dimension = bag.size();
137 result.resize( dimension );
140 for (
int i = 1; i <= dimension ; i++) {
141 std::stringstream out;
143 Property<double>* elem = bag.getProperty<
double>(out.str());
145 result(i) = elem->get();
147 log(Error)<<
"Could not read element "<<i<<endlog();
152 log(Error) <<
"Composing Property< ColumnVector > :" 153 <<
" type mismatch, got type '"<< bag.getType()
154 <<
"', expected type "<<
"ColumnVector."<<endlog();
161 struct RVectorTypeInfo :
public TemplateContainerTypeInfo<RowVector,int,double,ArrayIndexChecker<RowVector >, VectorAssignChecker<RowVector >,true>
169 targetbag.setType(
"RowVector");
170 int dimension = vec.size();
174 for (
int i=1; i <= dimension ; i++){
175 std::stringstream out;
178 targetbag.add(
new Property<double>(str, str +
"th element of vector",vec(i)) );
186 if ( bag.getType() ==
"RowVector" ) {
187 int dimension = bag.size();
188 result.resize( dimension );
191 for (
int i = 1; i <= dimension ; i++) {
192 std::stringstream out;
194 Property<double>* elem = bag.getProperty<
double>(out.str());
196 result(i) = elem->get();
198 log(Error)<<
"Could not read element "<<i<<endlog();
203 log(Error) <<
"Composing Property< RowVector > :" 204 <<
" type mismatch, got type '"<< bag.getType()
205 <<
"', expected type "<<
"RowVector."<<endlog();
212 struct MatrixTypeInfo :
public TemplateContainerTypeInfo<Matrix,int,RowVector,MatrixIndexChecker<Matrix>, MatrixAssignChecker<Matrix>, true>
218 targetbag.setType(
"Matrix");
219 unsigned int dimension = mat.rows();
221 for (
unsigned int i=1; i <= dimension ; i++){
222 std::stringstream out;
224 Property<PropertyBag>* row_bag =
new Property<PropertyBag>(out.str(), out.str() +
"th row of matrix");
225 Property<RowVector> row(out.str(), out.str() +
"th row of matrix",mat.rowCopy(i)) ;
226 row.getTypeInfo()->decomposeType(row.getDataSource(),row_bag->value());
227 targetbag.add( row_bag );
234 if ( bag.getType() ==
"Matrix" ) {
235 unsigned int rows = bag.size();
236 unsigned int cols = 0;
238 for (
unsigned int i = 1; i <= rows ; i++) {
239 std::stringstream out;
241 Property<PropertyBag>* row_bag = bag.getProperty<PropertyBag>(out.str());
243 log(Error)<<
"Could not read row "<<i<<endlog();
246 Property<RowVector> row_p(row_bag->getName(),row_bag->getDescription());
247 if(!(row_p.getDataSource()->composeType(row_bag->getDataSource()))){
248 log(Error)<<
"Could not decompose row "<<i<<endlog();
253 cols = row_p.get().size();
254 result.resize(rows,cols);
256 if(row_p.get().size()!=cols){
257 log(Error)<<
"Row "<<i+1<<
" size does not match matrix columns"<<endlog();
260 for (
unsigned int j=1; j <= row_p.get().size() ; j++){
261 result(i,j)=row_p.get()(j);
264 log(Error)<<
"Property of Row "<<i<<
"was not ready for use"<<endlog();
269 log(Error) <<
"Composing Property< Matrix > :" 270 <<
" type mismatch, got type '"<< bag.getType()
271 <<
"', expected type "<<
"Matrix."<<endlog();
278 struct SymmetricMatrixTypeInfo :
public TemplateContainerTypeInfo<SymmetricMatrix,int,RowVector,MatrixIndexChecker<SymmetricMatrix>, MatrixAssignChecker<SymmetricMatrix>, true>
284 targetbag.setType(
"SymmetricMatrix");
285 unsigned int dimension = mat.rows();
287 for (
unsigned int i=1; i <= dimension ; i++){
288 std::stringstream out;
291 Property<PropertyBag>* row_bag =
new Property<PropertyBag>(out.str(), out.str() +
"th row of matrix");
292 Property<RowVector> row(out.str(), out.str() +
"th row of matrix",((Matrix)mat).rowCopy(i)) ;
293 row.getTypeInfo()->decomposeType(row.getDataSource(),row_bag->value());
294 targetbag.add( row_bag );
302 if ( bag.getType() ==
"SymmetricMatrix" ) {
303 unsigned int rows = bag.size();
304 unsigned int cols = 0;
306 for (
unsigned int i = 1; i <= rows ; i++) {
307 std::stringstream out;
309 Property<PropertyBag>* row_bag = bag.getProperty<PropertyBag>(out.str());
311 log(Error)<<
"Could not read row "<<i<<endlog();
314 Property<RowVector > row_p(row_bag->getName(),row_bag->getDescription());
315 if(!(row_p.getDataSource()->composeType(row_bag->getDataSource()))){
316 log(Error)<<
"Could not decompose row "<<i<<endlog();
321 cols = row_p.get().size();
322 matrix.resize(rows,cols);
324 if(row_p.get().size()!=cols){
325 log(Error)<<
"Row "<<i+1<<
" size does not match matrix columns"<<endlog();
328 for (
unsigned int j=1; j <= row_p.get().size() ; j++){
329 matrix(i,j)=row_p.get()(j);
332 log(Error)<<
"Property of Row "<<i<<
"was not ready for use"<<endlog();
337 log(Error) <<
"Composing Property< SymmetricMatrix > :" 338 <<
" type mismatch, got type '"<< bag.getType()
339 <<
"', expected type "<<
"SymmetricMatrix."<<endlog();
342 matrix.convertToSymmetricMatrix(result);
348 :
public std::binary_function<const ColumnVector&, int, double>
352 if ( index > (
int)(v.size()) || index < 1)
359 :
public std::binary_function<const RowVector&, int, double>
363 if ( index > (
int)(v.size()) || index < 1)
370 :
public std::unary_function<const ColumnVector&, int>
379 :
public std::unary_function<const RowVector&, int>
388 :
public std::unary_function<int,const ColumnVector&>
393 ptr( new ColumnVector() ){}
402 :
public std::unary_function<int,const RowVector&>
407 ptr( new RowVector() ){}
416 :
public std::binary_function<const Matrix&, int, const RowVector&>
418 const RowVector&
operator()(
const Matrix& m,
int index)
const 420 if ( index > (
int)(m.rows()) || index < 1)
422 log(Error) <<
"index error" << endlog();
425 return m.rowCopy(index);
440 :
public std::binary_function<int,int,const Matrix&>
445 ptr( new Matrix() ){}
448 ptr->resize(size1,size2);
454 :
public std::unary_function<int,const SymmetricMatrix&>
459 ptr( new SymmetricMatrix() ){}
468 :
public std::unary_function<double, const Probability&>
484 return "bfl_toolkit";
489 RTT::TypeInfoRepository::Instance()->addType(
new VectorTypeInfo() );
491 RTT::TypeInfoRepository::Instance()->addType(
new MatrixTypeInfo() );
501 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<ColumnVector,true>(
"ColumnVectors") );
502 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<RowVector,true>(
"RowVectors") );
503 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<Matrix,true>(
"Matrixs") );
504 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<SymmetricMatrix,true>(
"SymmetricMatrixs") );
505 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<
Sample<int>,
false>(
"SampleInts") );
506 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<
Sample<double>,
false>(
"SampleDoubles") );
507 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<
Sample<ColumnVector>,
false>(
"SampleColumnVectors") );
508 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<
WeightedSample<int>,
false>(
"WeightedSampleInts") );
509 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<
WeightedSample<double>,
false>(
"WeightedSampleDoubles") );
510 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<
WeightedSample<ColumnVector>,
false>(
"WeightedSampleColumnVectors") );
511 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<Probability,false>(
"Probabilitys") );
513 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<vector<
Sample<int> >,
false>(
"VecSampleInts") );
514 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<vector<
Sample<double> >,
false>(
"VecSampleDoubles") );
515 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<vector<
Sample<ColumnVector> >,
false>(
"VecSampleColumnVectors") );
516 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<vector<
WeightedSample<int> >,
false>(
"VecWeightedSampleInts") );
517 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<vector<
WeightedSample<double> >,
false>(
"VecWeightedSampleDoubles") );
518 RTT::TypeInfoRepository::Instance()->addType(
new StdVectorTemplateTypeInfo<vector<
WeightedSample<ColumnVector> >,
false>(
"VecWeightedSampleColumnVectors") );
524 RTT::TypeInfoRepository::Instance()->type(
"ColumnVector")->addConstructor(newConstructor(
vector_index_constructor()));
526 RTT::TypeInfoRepository::Instance()->type(
"Matrix")->addConstructor(newConstructor(
matrix_i_j_constructor()));
530 RTT::TypeInfoRepository::Instance()->type(
"ColumnVectors")->addConstructor(newConstructor(stdvector_ctor<ColumnVector>() ) );
531 RTT::TypeInfoRepository::Instance()->type(
"ColumnVectors")->addConstructor(newConstructor(stdvector_ctor2<ColumnVector>() ) );
532 RTT::TypeInfoRepository::Instance()->type(
"ColumnVectors")->addConstructor(
new StdVectorBuilder<ColumnVector>() );
534 RTT::TypeInfoRepository::Instance()->type(
"RowVectors")->addConstructor(newConstructor(stdvector_ctor<RowVector>() ) );
535 RTT::TypeInfoRepository::Instance()->type(
"RowVectors")->addConstructor(newConstructor(stdvector_ctor2<RowVector>() ) );
536 RTT::TypeInfoRepository::Instance()->type(
"RowVectors")->addConstructor(
new StdVectorBuilder<RowVector>() );
538 RTT::TypeInfoRepository::Instance()->type(
"Matrixs")->addConstructor(newConstructor(stdvector_ctor<Matrix>() ) );
539 RTT::TypeInfoRepository::Instance()->type(
"Matrixs")->addConstructor(newConstructor(stdvector_ctor2<Matrix>() ) );
540 RTT::TypeInfoRepository::Instance()->type(
"Matrixs")->addConstructor(
new StdVectorBuilder<Matrix>() );
542 RTT::TypeInfoRepository::Instance()->type(
"SymmetricMatrixs")->addConstructor(newConstructor(stdvector_ctor<SymmetricMatrix>() ) );
543 RTT::TypeInfoRepository::Instance()->type(
"SymmetricMatrixs")->addConstructor(newConstructor(stdvector_ctor2<SymmetricMatrix>() ) );
544 RTT::TypeInfoRepository::Instance()->type(
"SymmetricMatrixs")->addConstructor(
new StdVectorBuilder<SymmetricMatrix>() );
546 RTT::TypeInfoRepository::Instance()->type(
"SampleInts")->addConstructor(newConstructor(stdvector_ctor<
Sample<int> >() ) );
547 RTT::TypeInfoRepository::Instance()->type(
"SampleInts")->addConstructor(newConstructor(stdvector_ctor2<
Sample<int> >() ) );
548 RTT::TypeInfoRepository::Instance()->type(
"SampleInts")->addConstructor(
new StdVectorBuilder<
Sample<int> >() );
550 RTT::TypeInfoRepository::Instance()->type(
"SampleDoubles")->addConstructor(newConstructor(stdvector_ctor<
Sample<double> >() ) );
551 RTT::TypeInfoRepository::Instance()->type(
"SampleDoubles")->addConstructor(newConstructor(stdvector_ctor2<
Sample<double> >() ) );
552 RTT::TypeInfoRepository::Instance()->type(
"SampleDoubles")->addConstructor(
new StdVectorBuilder<
Sample<double> >() );
554 RTT::TypeInfoRepository::Instance()->type(
"SampleColumnVectors")->addConstructor(newConstructor(stdvector_ctor<
Sample<ColumnVector> >() ) );
555 RTT::TypeInfoRepository::Instance()->type(
"SampleColumnVectors")->addConstructor(newConstructor(stdvector_ctor2<
Sample<ColumnVector> >() ) );
556 RTT::TypeInfoRepository::Instance()->type(
"SampleColumnVectors")->addConstructor(
new StdVectorBuilder<
Sample<ColumnVector> >() );
559 RTT::TypeInfoRepository::Instance()->type(
"WeightedSampleInts")->addConstructor(newConstructor(stdvector_ctor<
WeightedSample<int> >() ) );
560 RTT::TypeInfoRepository::Instance()->type(
"WeightedSampleInts")->addConstructor(newConstructor(stdvector_ctor2<
WeightedSample<int> >() ) );
561 RTT::TypeInfoRepository::Instance()->type(
"WeightedSampleInts")->addConstructor(
new StdVectorBuilder<
WeightedSample<int> >() );
563 RTT::TypeInfoRepository::Instance()->type(
"WeightedSampleDoubles")->addConstructor(newConstructor(stdvector_ctor<
WeightedSample<double> >() ) );
564 RTT::TypeInfoRepository::Instance()->type(
"WeightedSampleDoubles")->addConstructor(newConstructor(stdvector_ctor2<
WeightedSample<double> >() ) );
565 RTT::TypeInfoRepository::Instance()->type(
"WeightedSampleDoubles")->addConstructor(
new StdVectorBuilder<
WeightedSample<double> >() );
567 RTT::TypeInfoRepository::Instance()->type(
"WeightedSampleColumnVectors")->addConstructor(newConstructor(stdvector_ctor<
WeightedSample<ColumnVector> >() ) );
568 RTT::TypeInfoRepository::Instance()->type(
"WeightedSampleColumnVectors")->addConstructor(newConstructor(stdvector_ctor2<
WeightedSample<ColumnVector> >() ) );
569 RTT::TypeInfoRepository::Instance()->type(
"WeightedSampleColumnVectors")->addConstructor(
new StdVectorBuilder<
WeightedSample<ColumnVector> >() );
571 RTT::TypeInfoRepository::Instance()->type(
"VecSampleInts")->addConstructor(newConstructor(stdvector_ctor<vector<
Sample<int> > >() ) );
572 RTT::TypeInfoRepository::Instance()->type(
"VecSampleInts")->addConstructor(newConstructor(stdvector_ctor2<vector<
Sample<int> > >() ) );
573 RTT::TypeInfoRepository::Instance()->type(
"VecSampleInts")->addConstructor(
new StdVectorBuilder<vector<
Sample<int> > >() );
575 RTT::TypeInfoRepository::Instance()->type(
"VecSampleDoubles")->addConstructor(newConstructor(stdvector_ctor<vector<
Sample<double> > >() ) );
576 RTT::TypeInfoRepository::Instance()->type(
"VecSampleDoubles")->addConstructor(newConstructor(stdvector_ctor2<vector<
Sample<double> > >() ) );
577 RTT::TypeInfoRepository::Instance()->type(
"VecSampleDoubles")->addConstructor(
new StdVectorBuilder<vector<
Sample<double> > >() );
579 RTT::TypeInfoRepository::Instance()->type(
"VecSampleColumnVectors")->addConstructor(newConstructor(stdvector_ctor<vector<
Sample<ColumnVector> > >() ) );
580 RTT::TypeInfoRepository::Instance()->type(
"VecSampleColumnVectors")->addConstructor(newConstructor(stdvector_ctor2<vector<
Sample<ColumnVector> > >() ) );
581 RTT::TypeInfoRepository::Instance()->type(
"VecSampleColumnVectors")->addConstructor(
new StdVectorBuilder<vector<
Sample<ColumnVector> > >() );
583 RTT::TypeInfoRepository::Instance()->type(
"VecWeightedSampleInts")->addConstructor(newConstructor(stdvector_ctor<vector<
WeightedSample<int> > >() ) );
584 RTT::TypeInfoRepository::Instance()->type(
"VecWeightedSampleInts")->addConstructor(newConstructor(stdvector_ctor2<vector<
WeightedSample<int> > >() ) );
585 RTT::TypeInfoRepository::Instance()->type(
"VecWeightedSampleInts")->addConstructor(
new StdVectorBuilder<vector<
WeightedSample<int> > >() );
587 RTT::TypeInfoRepository::Instance()->type(
"VecWeightedSampleDoubles")->addConstructor(newConstructor(stdvector_ctor<vector<
WeightedSample<double> > >() ) );
588 RTT::TypeInfoRepository::Instance()->type(
"VecWeightedSampleDoubles")->addConstructor(newConstructor(stdvector_ctor2<vector<
WeightedSample<double> > >() ) );
589 RTT::TypeInfoRepository::Instance()->type(
"VecWeightedSampleDoubles")->addConstructor(
new StdVectorBuilder<vector<
WeightedSample<double> > >() );
591 RTT::TypeInfoRepository::Instance()->type(
"VecWeightedSampleColumnVectors")->addConstructor(newConstructor(stdvector_ctor<vector<
WeightedSample<ColumnVector> > >() ) );
592 RTT::TypeInfoRepository::Instance()->type(
"VecWeightedSampleColumnVectors")->addConstructor(newConstructor(stdvector_ctor2<vector<
WeightedSample<ColumnVector> > >() ) );
593 RTT::TypeInfoRepository::Instance()->type(
"VecWeightedSampleColumnVectors")->addConstructor(
new StdVectorBuilder<vector<
WeightedSample<ColumnVector> > >() );
595 RTT::TypeInfoRepository::Instance()->type(
"Probabilitys")->addConstructor(newConstructor(stdvector_ctor<Probability>() ) );
596 RTT::TypeInfoRepository::Instance()->type(
"Probabilitys")->addConstructor(newConstructor(stdvector_ctor2<Probability>() ) );
597 RTT::TypeInfoRepository::Instance()->type(
"Probabilitys")->addConstructor(
new StdVectorBuilder<Probability>() );
599 RTT::OperatorRepository::Instance()->add( newBinaryOperator(
"[]", stdvector_index<ColumnVector>() ) );
600 RTT::OperatorRepository::Instance()->add( newDotOperator(
"size", RTT::get_size<
const std::vector<ColumnVector>&>() ) );
602 RTT::TypeInfoRepository::Instance()->type(
"SampleInt")->addConstructor(newConstructor(
Sample_ctor<int>() ) );
603 RTT::TypeInfoRepository::Instance()->type(
"SampleDouble")->addConstructor(newConstructor(
Sample_ctor<double>() ) );
604 RTT::TypeInfoRepository::Instance()->type(
"SampleColumnVector")->addConstructor(newConstructor(
Sample_ctor<ColumnVector>() ) );
605 RTT::TypeInfoRepository::Instance()->type(
"WeightedSampleInt")->addConstructor(newConstructor(
WeightedSample_ctor<int>() ) );
606 RTT::TypeInfoRepository::Instance()->type(
"WeightedSampleDouble")->addConstructor(newConstructor(
WeightedSample_ctor<double>() ) );
609 RTT::TypeInfoRepository::Instance()->type(
"Probability")->addConstructor(newConstructor(
Probability_ctor() ) );
616 RTT::OperatorRepository::Instance()->add( newBinaryOperator(
"[]",
vector_index() ) );
617 RTT::OperatorRepository::Instance()->add( newBinaryOperator(
"[]",
rvector_index() ) );
618 RTT::OperatorRepository::Instance()->add( newDotOperator(
"size",
get_size() ) );
619 RTT::OperatorRepository::Instance()->add( newDotOperator(
"size",
rget_size() ) );
620 RTT::OperatorRepository::Instance()->add( newBinaryOperator(
"+", std::plus<ColumnVector>() ) );
621 RTT::OperatorRepository::Instance()->add( newBinaryOperator(
"+", std::plus<RowVector>() ) );
bool composeTypeImpl(const PropertyBag &bag, Matrix &result) const
boost::shared_ptr< SymmetricMatrix > ptr
ostream & operator<<(ostream &stream, Probability &prob)
boost::shared_ptr< RowVector > ptr
boost::shared_ptr< ColumnVector > ptr
vector_index_constructor()
rvector_index_constructor()
bool composeTypeImpl(const PropertyBag &bag, ColumnVector &result) const
symmetricMatrix_index_constructor()
virtual bool decomposeTypeImpl(const Probability &prob, PropertyBag &targetbag) const
const SymmetricMatrix & operator()(int size) const
const ColumnVector & operator()(int size) const
bool composeTypeImpl(const PropertyBag &bag, RowVector &result) const
int operator()(const ColumnVector &cont) const
bool decomposeTypeImpl(const Matrix &mat, PropertyBag &targetbag) const
boost::shared_ptr< Probability > ptr
bool composeTypeImpl(const PropertyBag &bag, SymmetricMatrix &result) const
bool decomposeTypeImpl(const SymmetricMatrix &mat, PropertyBag &targetbag) const
istream & operator>>(istream &stream, Probability &prob)
const RowVector &() Signature(int)
const Probability & operator()(double value) const
const Probability &() Signature(double)
virtual bool composeTypeImpl(const PropertyBag &bag, Probability &prob) const
boost::shared_ptr< Matrix > ptr
const RowVector & operator()(int size) const
bool decomposeTypeImpl(const ColumnVector &vec, PropertyBag &targetbag) const
const ColumnVector &() Signature(int)
SymmetricMatrixTypeInfo()
const SymmetricMatrix &() Signature(int)
bflToolkitPlugin bflToolkit
const Matrix &() Signature(int, int)
Class representing a probability (a double between 0 and 1)
double operator()(const ColumnVector &v, int index) const
int operator()(const RowVector &cont) const
bool decomposeTypeImpl(const RowVector &vec, PropertyBag &targetbag) const
const RowVector & operator()(const Matrix &m, int index) const
const Matrix & operator()(int size1, int size2) const
double operator()(const RowVector &v, int index) const