@@ -95,13 +95,25 @@ namespace dynamicgraph {
95
95
{
96
96
void operator ()( const Tin& m,Vector& res ) const
97
97
{
98
- assert ( (imin<=imax) && (imax <= m.size ()) );
99
- res.resize ( imax-imin );
100
- for ( int i=imin;i<imax;++i ) res (i-imin)=m (i);
98
+ res.resize (size);
99
+ Vector::Index r=0 ;
100
+ for (std::size_t i = 0 ; i < idxs.size (); ++i) {
101
+ const Vector::Index& R = idxs[i].first ;
102
+ const Vector::Index& nr = idxs[i].second ;
103
+ assert ( (nr>=0 ) && (R+nr <= m.size ()) );
104
+ res.segment (r,nr) = m.segment (R,nr);
105
+ r += nr;
106
+ }
107
+ assert (r == size);
101
108
}
102
109
103
- int imin,imax;
104
- void setBounds ( const int & m,const int & M ) { imin = m; imax = M; }
110
+ typedef std::pair <Vector::Index,Vector::Index> segment_t ;
111
+ typedef std::vector <segment_t > segments_t ;
112
+ segments_t idxs;
113
+ Vector::Index size;
114
+
115
+ void setBounds ( const int & m,const int & M ) { idxs = segments_t (1 , segment_t (m, M-m)); size = M-m; }
116
+ void addBounds ( const int & m,const int & M ) { idxs .push_back ( segment_t (m, M-m)); size += M-m; }
105
117
106
118
void addSpecificCommands (Entity& ent,
107
119
Entity::CommandMap_t& commandMap )
@@ -113,7 +125,12 @@ namespace dynamicgraph {
113
125
= boost::bind ( &VectorSelecter::setBounds,this ,_1,_2 );
114
126
doc = docCommandVoid2 (" Set the bound of the selection [m,M[." ," int (min)" ," int (max)" );
115
127
ADD_COMMAND ( " selec" , makeCommandVoid2 (ent,setBound,doc) );
128
+ boost::function< void ( const int &, const int & ) > addBound
129
+ = boost::bind ( &VectorSelecter::setBounds,this ,_1,_2 );
130
+ doc = docCommandVoid2 (" Add a segment to be selected [m,M[." ," int (min)" ," int (max)" );
131
+ ADD_COMMAND ( " addSelec" , makeCommandVoid2 (ent,setBound,doc) );
116
132
}
133
+ VectorSelecter () : size (0 ) {}
117
134
};
118
135
REGISTER_UNARY_OP ( VectorSelecter,Selec_of_vector );
119
136
@@ -829,14 +846,12 @@ namespace dynamicgraph {
829
846
: public BinaryOpHeader <T1, T2, bool >
830
847
{
831
848
// TODO T1 or T2 could be a scalar type.
832
- typedef Eigen::Array<bool , T1::RowsAtCompileTime, T1::ColsAtCompileTime> Array;
833
849
void operator ()( const T1& a,const T2& b, bool & res ) const
834
850
{
835
- Array r;
836
- if (equal) r = (a.array () <= b.array ());
837
- else r = (a.array () < b.array ());
838
- if (any) res = r.any ();
839
- else res = r.all ();
851
+ if ( equal && any) res = (a.array () <= b.array ()).any ();
852
+ else if ( equal && !any) res = (a.array () <= b.array ()).all ();
853
+ else if (!equal && any) res = (a.array () < b.array ()).any ();
854
+ else if (!equal && !any) res = (a.array () < b.array ()).all ();
840
855
}
841
856
virtual std::string getDocString () const
842
857
{
0 commit comments