Skip to content

Commit 5963877

Browse files
author
Francois Keith
committed
Reintroduce WeightAdder.
1 parent 4fe6933 commit 5963877

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed

src/matrix/operator.cpp

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -777,26 +777,53 @@ namespace dynamicgraph {
777777

778778

779779

780+
namespace dynamicgraph {
781+
namespace sot {
782+
783+
template< typename T>
784+
struct WeightedAdder
785+
: public BinaryOpHeader<T,T,T>
786+
{
787+
public:
788+
double gain1,gain2;
789+
void operator()( const T& v1,const T& v2, T& res ) const
790+
{
791+
res=v1; res*=gain1;
792+
res += gain2*v2;
793+
}
794+
795+
void addSpecificCommands(Entity& ent,
796+
Entity::CommandMap_t& commandMap)
797+
{
798+
using namespace dynamicgraph::command;
799+
std::string doc;
800+
801+
ADD_COMMAND( "setGain1",
802+
makeDirectSetter(ent,&gain1,docDirectSetter("gain1","double")));
803+
ADD_COMMAND( "setGain2",
804+
makeDirectSetter(ent,&gain2,docDirectSetter("gain2","double")));
805+
ADD_COMMAND( "getGain1",
806+
makeDirectGetter(ent,&gain1,docDirectGetter("gain1","double")));
807+
ADD_COMMAND( "getGain2",
808+
makeDirectGetter(ent,&gain2,docDirectGetter("gain2","double")));
809+
}
810+
811+
virtual std::string getDocString () const
812+
{
813+
return std::string("Weighted Combination of inputs : \n - gain{1|2} gain.");
814+
}
815+
};
816+
817+
REGISTER_BINARY_OP(WeightedAdder<ml::Matrix>,WeightAdd_of_matrix);
818+
REGISTER_BINARY_OP(WeightedAdder<ml::Vector>,WeightAdd_of_vector);
819+
REGISTER_BINARY_OP(WeightedAdder<double>,WeightAdd_of_double);
820+
}
821+
}
822+
780823
/* --- TODO ------------------------------------------------------------------*/
781824
// The following commented lines are sot-v1 entities that are still waiting
782825
// for conversion. Help yourself!
783826

784-
// struct WeightedAdder
785-
// {
786-
// public:
787-
// double gain1,gain2;
788-
// void operator()( const ml::Vector& v1,const ml::Vector& v2,ml::Vector& res ) const
789-
// {
790-
// res=v1; res*=gain1;
791-
// res += gain2*v2;
792-
// }
793-
// };
794-
// typedef BinaryOp< Vector,Vector,Vector,WeightedAdder > weightadd;
795-
// SOT_FACTORY_TEMPLATE_ENTITY_PLUGIN_ExE_E_CMD(weightadd,vector,weight_add,"WeightAdd_of_vector",else if( cmdLine=="gain1" ){ cmdArgs>>op.gain1; }
796-
// else if( cmdLine=="gain2" ){ cmdArgs>>op.gain2;}
797-
// else if( cmdLine=="print" ){os<<"WeightAdd: "<<op.gain1<<" "<<op.gain2<<std::endl; },
798-
// "WeightAdd<vector>: \n - gain{1|2} gain.")
799-
800827
// /* -------------------------------------------------------------------------- */
801828

802829
// struct WeightedDirection

0 commit comments

Comments
 (0)