Skip to content

Commit 0aba1a2

Browse files
committed
Add binary operator entity Mix_of_vector
1 parent 0827cca commit 0aba1a2

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/matrix/operator.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,58 @@ namespace dynamicgraph {
764764
};
765765
REGISTER_BINARY_OP(VectorStack,Stack_of_vector);
766766

767+
/* --- STACK ------------------------------------------------------------ */
768+
struct VectorMix
769+
: public BinaryOpHeader<dynamicgraph::Vector,dynamicgraph::Vector,dynamicgraph::Vector>
770+
{
771+
public:
772+
std::vector<bool> useV1;
773+
std::vector<int> idx1, idx2;
774+
void operator()( const dynamicgraph::Vector& v1,const dynamicgraph::Vector& v2,dynamicgraph::Vector& res ) const
775+
{
776+
res.resize(useV1.size());
777+
std::size_t k1=0, k2=0;
778+
for (std::size_t i = 0; i < useV1.size(); ++i)
779+
{
780+
if (useV1[i]) {
781+
assert (k1 < idx1.size());
782+
res[i] = v1[idx1[k1]];
783+
++k1;
784+
} else {
785+
assert (k2 < idx2.size());
786+
res[i] = v2[idx2[k2]];
787+
++k2;
788+
}
789+
}
790+
assert (k1 == idx1.size());
791+
assert (k2 == idx2.size());
792+
}
793+
794+
void addSelec1( const int & i) { useV1.push_back(true ); idx1.push_back(i); }
795+
void addSelec2( const int & i) { useV1.push_back(false); idx2.push_back(i); }
796+
797+
void addSpecificCommands(Entity& ent,
798+
Entity::CommandMap_t& commandMap )
799+
{
800+
using namespace dynamicgraph::command;
801+
802+
boost::function< void( const int& ) > selec1
803+
= boost::bind( &VectorMix::addSelec1,this,_1 );
804+
boost::function< void( const int& ) > selec2
805+
= boost::bind( &VectorMix::addSelec2,this,_1 );
806+
807+
ADD_COMMAND( "addSelec1",
808+
makeCommandVoid1(ent, selec1,
809+
docCommandVoid1("append value from vector 1.",
810+
"int (index in vector 1)")));
811+
ADD_COMMAND( "addSelec2",
812+
makeCommandVoid1(ent, selec2,
813+
docCommandVoid1("append value from vector 2.",
814+
"int (index in vector 2)")));
815+
}
816+
};
817+
REGISTER_BINARY_OP(VectorMix,Mix_of_vector);
818+
767819
/* ---------------------------------------------------------------------- */
768820

769821
struct Composer

0 commit comments

Comments
 (0)