Main MRPT website > C++ reference
MRPT logo
CBinaryRelation.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (c) 2005-2013, Individual contributors, see AUTHORS file |
7  | Copyright (c) 2005-2013, MAPIR group, University of Malaga |
8  | Copyright (c) 2012-2013, University of Almeria |
9  | All rights reserved. |
10  | |
11  | Redistribution and use in source and binary forms, with or without |
12  | modification, are permitted provided that the following conditions are |
13  | met: |
14  | * Redistributions of source code must retain the above copyright |
15  | notice, this list of conditions and the following disclaimer. |
16  | * Redistributions in binary form must reproduce the above copyright |
17  | notice, this list of conditions and the following disclaimer in the |
18  | documentation and/or other materials provided with the distribution. |
19  | * Neither the name of the copyright holders nor the |
20  | names of its contributors may be used to endorse or promote products |
21  | derived from this software without specific prior written permission.|
22  | |
23  | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24  | 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
25  | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR|
26  | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE |
27  | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL|
28  | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR|
29  | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
30  | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
31  | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
32  | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
33  | POSSIBILITY OF SUCH DAMAGE. |
34  +---------------------------------------------------------------------------+ */
35 #ifndef CBINARYRELATION_H_
36 #define CBINARYRELATION_H_
37 
40 
41 #include <set>
42 #include <iterator>
43 #include <algorithm>
44 #include <utility>
45 
46 namespace mrpt { namespace math {
47  using std::vector;
48 
49  /**
50  * This class models a binary relation through the elements of any given set. I.e. for each pair of elements (A,B) it assigns two values, f(A,B) and f(B,A).
51  * This class is useful when calling the base function is costly, since it acts like a proxy. It's also useful if the relationship values do not correspond
52  * with the return value of a function. Although it theoretically supports objects with non-trivial constructors or destructors (indicated by specifying
53  * "true" as the thrid parameter of the template instantiation), certain operations will cause memory leaks and may even cause undefined behaviour, so it's
54  * reccomended to use only basic types for the parameter U. The parameter T may be any complex object, however, like a smart pointer.
55  * \ingroup mrpt_base_grp
56  */
57  template<typename T,typename U,bool UIsObject=false> class CBinaryRelation {
58  private:
59  //TODO: VIRTUALIZE INSERTROWSANDCOLS!!! AND REIMPLEMENT IN CMATRIXTEMPLATEOBJECTS.
60 
61  typedef typename detail::MatrixWrapper<U,UIsObject>::MatrixType MatrixType; //!<Matrix type used to store the actual relation.
62  public:
63  typedef U (*SimpleFunctionByReturnValue)(T,T); //!< Simple function type, used to initialize chunks of the matrix.
64  typedef U (*FunctionByReturnValue)(const T &,const T &); //!<Function type which obtains the relation value by a return value.
65  typedef void (*FunctionByReferencePass)(const T &,const T &,U &); //!<Function type which obtains the relation value by reference pass.
66  typedef typename std::set<T>::const_iterator const_iterator; //!<Constant iterator through the set elements.
67  typedef typename std::set<T>::const_reverse_iterator const_reverse_iterator; //!<Constant reverse iterator through the set elements.
68  typedef CMatrixRowAccessor<U> AccessorForFirstElement; //!<Accessor type to every value related to any element A, i.e., f(A,x).
69  typedef CMatrixColumnAccessor<U> AccessorForSecondElement; //!<Accessor type to every value related to any element B, i.e., f(x,B).
70  typedef CConstMatrixRowAccessor<U> ConstAccessorForFirstElement; //!<Const accessor type to every value related to any element A, i.e., f(A,x).
71  typedef CConstMatrixColumnAccessor<U> ConstAccessorForSecondElement; //!<Const accessor type to every value related to any element B, i.e., f(x,B).
72  private:
73  std::set<T> elements; //!<Actual set of elements.
74  MatrixType relation; //!<Matrix storing the relation.
75 
76  /**
77  * Template used to make the function interface independent from the function type.
78  * (wrapper for the global method - needed to make this compile under GCC).
79  */
80  template<typename FunctionType> inline void applyFunction(FunctionType fun,size_t e1,size_t e2,const T &T1,const T &T2) {
81  detail::applyFunction<T,U,UIsObject,FunctionType>(*this,fun,e1,e2,T1,T2);
82  }
83 
84  public:
85  /**
86  * Default constructor, doesn't initialize the relation.
87  */
88  explicit inline CBinaryRelation(const std::set<T> &els):elements(els),relation(els.size(),els.size()) {}
89  /**
90  * Constructor which initializes the relation using a given function.
91  */
92  template<typename FunctionType> inline CBinaryRelation(const std::set<T> &els,FunctionType fun):elements(els),relation(els.size(),els.size()) {
93  initializeWith(fun);
94  }
95  /**
96  * Initialize the whole relation with a given function.
97  */
98  template<typename FunctionType> void initializeWith(FunctionType fun) {
99  typename std::set<T>::const_iterator it=elements.begin();
100  for (size_t i=0;i<elements.size();++i,++it) {
101  typename std::set<T>::const_iterator jt=elements.begin();
102  for (size_t j=0;j<elements.size();++j,++jt) applyFunction(fun,i,j,*it,*jt);
103  }
104  }
105  /**
106  * Initialize the whole relation with a given function, assuming that the relation is symmetrical.
107  */
108  template<typename FunctionType> void initializeSymmetricallyWith(FunctionType fun) {
109  typename std::set<T>::const_iterator it=elements.begin();
110  for (size_t i=0;i<elements.size();++i,++it) {
111  applyFunction(fun,i,i,*it,*it);
112  typename std::set<T>::const_iterator jt=it;
113  jt++;
114  for (size_t j=i+1;j<elements.size();++j,++jt) {
115  applyFunction(fun,i,j,*it,*jt);
116  relation(j,i)=relation(i,j);
117  }
118  }
119  }
120  /**
121  * Manually set a relationship value, given the indices.
122  */
123  inline void setRelationValue(size_t e1,size_t e2,const U &newVal) {
124  relation.get_unsafe(e1,e2)=newVal;
125  }
126  /**
127  * Get a relation value, given the indices.
128  */
129  inline const U &getRelationValue(size_t e1,size_t e2) const {
130  return relation.get_unsafe(e1,e2);
131  }
132  inline const U &operator()(size_t e1,size_t e2) const {
133  return getRelationValue(e1,e2);
134  }
135  /**
136  * Get a reference to a relation value given its indices, which allows both querying and setting the value.
137  */
138  inline U &getRelationValue(size_t e1,size_t e2) {
139  return relation.get_unsafe(e1,e2);
140  }
141  inline U &operator()(size_t e1,size_t e2) {
142  return getRelationValue(e1,e2);
143  }
144  /**
145  * Manually set a relationship value, given the elements. Returns false if any of the elements is not present.
146  */
147  inline bool setRelationValue(const T &t1,const T &t2,const U &newVal) {
148  typename std::set<T>::const_iterator b=elements.begin(),e=elements.end();
149  typename std::set<T>::const_iterator it1=std::find(b,e,t1),it2=std::find(b,e,t2);
150  if (it1==e||it2==e) return false;
151  setRelationValue(static_cast<size_t>(std::distance(b,it1)),static_cast<size_t>(std::distance(b,it2)),newVal);
152  return true;
153  }
154  /**
155  * Get a relation value, given the elements. Throws domain_error if any of the elements is not present.
156  */
157  inline U getRelationValue(const T &t1,const T &t2) const {
158  typename std::set<T>::const_iterator b=elements.begin(),e=elements.end();
159  typename std::set<T>::const_iterator it1=std::find(b,e,t1),it2=std::find(b,e,t2);
160  if (it1==e||it2==e) throw std::domain_error("Element not found");
161  return getRelationValue(static_cast<size_t>(std::distance(b,it1)),static_cast<size_t>(std::distance(b,it2)));
162  }
163  /**
164  * Get a reference to a relation value given the elements, which allows both querying and setting. Throws domain_error if any of the elements is not
165  * present.
166  */
167  inline U &getRelationValue(const T &t1,const T &t2) {
168  typename std::set<T>::const_iterator b=elements.begin(),e=elements.end();
169  typename std::set<T>::const_iterator it1=std::find(b,e,t1),it2=std::find(b,e,t2);
170  if (it1==e||it2==e) throw std::domain_error("Element not found");
171  return getRelationValue(static_cast<size_t>(std::distance(b,it1)),static_cast<size_t>(distance(b,it2)));
172  }
173  /**
174  * Gets an iterator to the starting point of the elements set.
175  */
176  inline const_iterator begin() const {
177  return elements.begin();
178  }
179  /**
180  * Gets an iterator to the ending point of the elements set.
181  */
182  inline const_iterator end() const {
183  return elements.end();
184  }
185  /**
186  * Gets a reverse iterator to the ending point of the elements set.
187  */
189  return elements.rbegin();
190  }
191  /**
192  * Gets a reverse iterator to the starting point of the elements set.
193  */
194  inline const_reverse_iterator rend() const {
195  return elements.rend();
196  }
197  /**
198  * Operator for direct access to a element given its index.
199  */
200  T operator[](size_t i) const {
201  ASSERT_BELOW_(i,elements.size())
202  typename std::set<T>::const_iterator it=elements.begin();
203  std::advance(it,i);
204  return *it;
205  }
206  /**
207  * Gets an accessor for every value related to an element A given its index, i.e., every f(A,x). This accessor is iterable.
208  */
211  }
212  /**
213  * Gets a constant accessor for every value related to an element A given its index, i.e., every f(A,x). This accessor is iterable.
214  */
217  }
218  /**
219  * Gets an accessor for every value related to an element B given its index, i.e., every f(x,B). This accessor is iterable.
220  */
223  }
224  /**
225  * Gets a constant accessor for every value related to an element B given its index, i.e., every f(x,B). This accessor is fully iterable.
226  */
229  }
230  /**
231  * Gets an iterable accessor for every value related to an element A, i.e., every f(A,x). A domain_error will be thrown if the element is not present.
232  */
234  typename std::set<T>::const_iterator b=elements.begin(),e=elements.end();
235  typename std::set<T>::const_iterator it=std::find(b,e,t);
236  if (it==e) throw std::domain_error("Element not found");
237  return getRelationFrom(static_cast<size_t>(std::distance(b,it)));
238  }
239  /**
240  * Gets an iterable constant accessor for every value related to an element A, i.e., every f(A,x). A domain_error will be thrown if the element is not
241  * present.
242  */
244  typename std::set<T>::const_iterator b=elements.begin(),e=elements.end();
245  typename std::set<T>::const_iterator it=std::find(b,e,t);
246  if (it==e) throw std::domain_error("Element not found");
247  return getRelationFrom(static_cast<size_t>(std::distance(b,it)));
248  }
249  inline void getRelationFrom(size_t i,vector<U> &vec) {
250  size_t N=elements.size();
251  ASSERT_(i<N);
252  vec.resize(N);
254  std::copy(access.begin(),access.end(),vec.begin());
255  }
256  inline void getRelationFrom(const T &t,vector<U> &vec) {
257  typename std::set<T>::const_iterator b=elements.begin(),e=elements.end();
258  typename std::set<T>::const_iterator it=std::find(b,e,t);
259  if (it==e) throw std::domain_error("Element not found");
260  getRelationFrom(static_cast<size_t>(std::distance(b,it)),vec);
261  }
262  /**
263  * Gets an iterable accessor for every value related to an element B, i.e., every f(x,B). A domain_error will be thrown if the element is not present.
264  */
266  typename std::set<T>::const_iterator b=elements.begin(),e=elements.end();
267  typename std::set<T>::const_iterator it=std::find(b,e,t);
268  if (it==e) throw std::domain_error("Element not found");
269  return getRelationTo(static_cast<size_t>(std::distance(b,it)));
270  }
271  /**
272  * Gets an iterable constant accessor for every value related to an alement B, i.e., every f(x,B). A domain_error will be thrown if the element is not
273  * present.
274  */
276  typename std::set<T>::const_iterator b=elements.begin(),e=elements.end();
277  typename std::set<T>::const_iterator it=std::find(b,e,t);
278  if (it==e) throw std::domain_error("Element not found");
279  return getRelationTo(static_cast<size_t>(std::distance(b,it)));
280  }
281  inline void getRelationTo(size_t i,vector<U> &vec) {
282  size_t N=elements.size();
283  ASSERT_(i<N);
284  vec.resize(N);
286  std::copy(access.begin(),access.end(),vec.begin());
287  }
288  inline void getRelationTo(const T &t,vector<U> &vec) {
289  typename std::set<T>::const_iterator b=elements.begin(),e=elements.end();
290  typename std::set<T>::const_iterator it=std::find(b,e,t);
291  if (it==e) throw std::domain_error("Element not found");
292  getRelationTo(static_cast<size_t>(std::distance(b,it)),vec);
293  }
294  /**
295  * Removes an element at a concrete position.
296  */
297  void removeElementAt(size_t i) {
298  ASSERT_(i<elements.size());
299  typename std::set<T>::const_iterator it=elements.begin();
300  std::advance(it,i);
301  elements.erase(i);
302  set<size_t> ii;
303  ii.insert(i);
304  relation.removeRowsAndCols(ii,ii);
305  }
306  /**
307  * Removes an element. Returns false if the element was not present and thus could'nt be eliminated.
308  */
309  bool removeElement(const T &el) {
310  typename std::set<T>::const_iterator b=elements.begin(),e=elements.end();
311  typename std::set<T>::const_iterator it=std::find(e,b,el);
312  if (it==e) return false;
314  return true;
315  }
316  /**
317  * Removes a set of elements. Returns the number of elements which were actually erased.
318  */
319  size_t removeElements(const set<T> &vals) {
320  set<size_t> positions;
321  for (typename set<T>::const_iterator it=vals.begin();it!=vals.end();++it) {
322  typename set<T>::iterator elsIt=std::find(elements.begin(),elements.end(),*it);
323  if (elsIt!=elements.end()) positions.insert(std::distance(elements.begin(),elsIt));
324  }
325 /* for (set<size_t>::const_reverse_iterator it=positions.rbegin();it!=positions.rend();++it) {
326  typename std::set<T>::const_iterator it2=elements.begin();
327  std::advance(it2,*it);
328  elements.erase(it2);
329  }
330  relation.removeRowsAndCols(positions,positions);*/
331  removeElementsAt(positions);
332  return positions.size();
333  }
334  void removeElementsAt(const set<size_t> &poss) {
335  relation.removeRowsAndCols(poss,poss);
336  for (set<size_t>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();++it) {
337  typename std::set<T>::const_iterator it2=elements.begin();
338  std::advance(it2,*it);
339  elements.erase(it2);
340  }
341  }
342  /**
343  * Inserts an element. If the element was present, returns false and its current position. If it wasn't, returns true and the position in which it was
344  * inserted.
345  */
346  std::pair<bool,size_t> insertElement(const T &el) {
348  size_t dist=std::distance(elements.begin(),ins.first);
349  if (ins.second) {
350  std::multiset<size_t> newEls;
351  newEls.insert(dist);
352  relation.insertRowsAndCols(newEls,newEls);
353  return std::make_pair(true,dist);
354  } else return std::make_pair(false,dist);
355  }
356  /**
357  * Inserts an element and initializes its relationship values, even if it was already present.
358  */
359  template<typename FunctionType> std::pair<bool,size_t> insertElement(const T &el,FunctionType fun) {
360  std::pair<bool,size_t> ins=insertElement(el);
361  size_t pos=ins.second;
362  for (size_t i=0;i<elements.size();++i) {
363  const T &newEl=operator[](i);
364  applyFunction(fun,pos,i,el,newEl);
365  applyFunction(fun,i,pos,newEl,el);
366  }
367  return ins;
368  }
369  /**
370  * Inserts a set of elements into the relation. Does not initialize the actual relation.
371  */
372  size_t insertElements(const std::set<T> &els) {
373  if (els.empty()) return 0;
374  //This code is much more complex than it should! Trying, for efficiency, to avoid multiple calls to insertElement makes things a lot harder.
375  //It raises the complexity level to N², but alleviates it greatly by making a single memory allocation. Multiple calls to insertElement will be
376  //faster only if the number of elements in the set is really large.
377  std::vector<size_t> added;
378  //std::vector<size_t> exist;
379  added.reserve(els.size());
380  for (typename std::set<T>::const_iterator it=els.begin();it!=els.end();++it) {
382  size_t dist=std::distance(elements.begin(),ins.first);
383  if (ins.second) {
384  added.push_back(dist);
385  for (std::vector<size_t>::iterator it2=added.begin();it2!=added.end();++it2) if (*it2>=dist) ++(*it2);
386  //for (std::vector<size_t>::iterator it2=exist.begin();it2!=exist.end();++it2) if (*it2>=dist) ++(*it2);
387  }// else exist.push_back(dist);
388  }
389  std::sort(added.begin(),added.end());
390  for (size_t j=1;j<added.size();++j) added[j]-=j;
391  std::multiset<size_t> poss(added.begin(),added.end());
392  relation.insertRowsAndCols(poss,poss);
393  return added.size();
394  }
395  /**
396  * Inserts a set of elements into the relation, initializing the actual relation with a given function.
397  */
398  template<typename FunctionType> size_t insertElements(const std::set<T> &els,FunctionType fun) {
399  if (els.empty()) return 0;
400  size_t howMany=insertElements(els);
401  std::set<size_t> poss;
402  {
403  //Little scope for "begin" and "end"...
404  typename std::set<T>::const_iterator begin=elements.begin(),end=elements.end();
405  for (typename std::set<T>::const_iterator it=els.begin();it!=els.end();++it) poss.insert(std::distance(begin,find(begin,end,*it)));
406  }
407  std::set<size_t> nPoss;
408  std::set<size_t>::const_iterator begin=poss.begin(),end=poss.end();
409  for (size_t i=0;i<elements.size();++i) if (std::find(begin,end,i)==end) nPoss.insert(i);
410  vector<const T *> proxy;
411  proxy.reserve(poss.size());
412  for (std::set<size_t>::const_iterator it=begin;it!=end;++it) {
413  const T &e1=operator[](*it);
414  proxy.push_back(&e1);
415  size_t i=0;
416  for (typename std::set<T>::const_iterator it2=elements.begin();it2!=elements.end();++it2,++i) applyFunction(fun,*it,i,e1,*it2);
417  }
418  for (std::set<size_t>::const_iterator it=nPoss.begin();it!=nPoss.end();++it) {
419  const T &e1=operator[](*it);
420  typename std::vector<const T *>::const_iterator itV=proxy.begin();
421  for (std::set<size_t>::const_iterator it2=poss.begin();it2!=poss.end();++it2,++itV) applyFunction(fun,*it,*it2,e1,**itV);
422  }
423  return howMany;
424  }
425  /**
426  * Completely resets the relation, using a new set of elements. Does not initialize the relation.
427  */
428  void setElements(const std::set<T> &newEls) {
429  relation.setSize(0,0);
430  elements=newEls;
431  relation.setSize(newEls.size(),newEls.size());
432  }
433  /**
434  * Returns the amount of elements present in the relation.
435  */
436  inline size_t size() const {
437  return elements.size();
438  }
439  };
440 
441  namespace detail {
442  // generic version (specialization is after definition of CBinaryRelation):
443  template<typename T,typename U,bool UIsObject,typename FunctionType> inline void applyFunction(CBinaryRelation<T,U,UIsObject> &o, FunctionType fun,size_t e1,size_t e2,const T &T1,const T &T2) {
444  o.getRelationValue(e1,e2)=fun(T1,T2);
445  }
446 
447  /** Template specialization by reference type.
448  */
449  template<typename T,typename U,bool UIsObject> inline void applyFunction(CBinaryRelation<T,U,UIsObject> &o,typename CBinaryRelation<T,U,UIsObject>::FunctionByReferencePass fun,size_t e1,size_t e2,const T &T1,const T &T2) {
450  fun(T1,T2,o.getRelationValue(e1,e2));
451  }
452  }
453 
454 
455 }} //End of namespaces
456 #endif
A vector-like wrapper for a const Matrix for accessing the elements of a given column with a [] opera...
void applyFunction(CBinaryRelation< T, U, UIsObject > &o, FunctionType fun, size_t e1, size_t e2, const T &T1, const T &T2)
void removeElementsAt(const set< size_t > &poss)
U & getRelationValue(size_t e1, size_t e2)
Get a reference to a relation value given its indices, which allows both querying and setting the val...
const_iterator end() const
Gets an iterator to the ending point of the elements set.
This template is a trick to switch the type of a variable using a boolean variable in the template...
void setRelationValue(size_t e1, size_t e2, const U &newVal)
Manually set a relationship value, given the indices.
ConstAccessorForFirstElement getRelationFrom(size_t i) const
Gets a constant accessor for every value related to an element A given its index, i...
CConstMatrixColumnAccessor< U > ConstAccessorForSecondElement
Const accessor type to every value related to any element B, i.e., f(x,B).
CMatrixRowAccessor< U > AccessorForFirstElement
Accessor type to every value related to any element A, i.e., f(A,x).
std::pair< bool, size_t > insertElement(const T &el)
Inserts an element.
size_t insertElements(const std::set< T > &els)
Inserts a set of elements into the relation.
#define ASSERT_BELOW_(__A, __B)
Scalar * iterator
Definition: eigen_plugins.h:49
This class models a binary relation through the elements of any given set.
EIGEN_STRONG_INLINE const AdjointReturnType t() const
Transpose.
const Scalar * const_iterator
Definition: eigen_plugins.h:50
AccessorForFirstElement getRelationFrom(size_t i)
Gets an accessor for every value related to an element A given its index, i.e., every f(A...
void applyFunction(FunctionType fun, size_t e1, size_t e2, const T &T1, const T &T2)
Template used to make the function interface independent from the function type.
const_iterator begin() const
Gets an iterator to the starting point of the elements set.
void getRelationTo(size_t i, vector< U > &vec)
void getRelationFrom(size_t i, vector< U > &vec)
A vector-like wrapper for a const Matrix for accessing the elements of a given row with a [] operator...
size_t insertElements(const std::set< T > &els, FunctionType fun)
Inserts a set of elements into the relation, initializing the actual relation with a given function...
std::set< T > elements
Actual set of elements.
ConstAccessorForSecondElement getRelationTo(size_t i) const
Gets a constant accessor for every value related to an element B given its index, i...
size_t removeElements(const set< T > &vals)
Removes a set of elements.
U & getRelationValue(const T &t1, const T &t2)
Get a reference to a relation value given the elements, which allows both querying and setting...
MatrixType relation
Matrix storing the relation.
ConstAccessorForSecondElement getRelationTo(const T &t) const
Gets an iterable constant accessor for every value related to an alement B, i.e., every f(x...
detail::MatrixWrapper< U, UIsObject >::MatrixType MatrixType
Matrix type used to store the actual relation.
void initializeWith(FunctionType fun)
Initialize the whole relation with a given function.
const_reverse_iterator rend() const
Gets a reverse iterator to the starting point of the elements set.
A vector-like wrapper for a Matrix for accessing the elements of a given row with a [] operator...
void setElements(const std::set< T > &newEls)
Completely resets the relation, using a new set of elements.
void getRelationFrom(const T &t, vector< U > &vec)
void getRelationTo(const T &t, vector< U > &vec)
U(* SimpleFunctionByReturnValue)(T, T)
Simple function type, used to initialize chunks of the matrix.
CBinaryRelation(const std::set< T > &els, FunctionType fun)
Constructor which initializes the relation using a given function.
std::set< T >::const_reverse_iterator const_reverse_iterator
Constant reverse iterator through the set elements.
CConstMatrixRowAccessor< U > ConstAccessorForFirstElement
Const accessor type to every value related to any element A, i.e., f(A,x).
void removeElementAt(size_t i)
Removes an element at a concrete position.
bool removeElement(const T &el)
Removes an element.
AccessorForSecondElement getRelationTo(size_t i)
Gets an accessor for every value related to an element B given its index, i.e., every f(x...
U(* FunctionByReturnValue)(const T &, const T &)
Function type which obtains the relation value by a return value.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CBinaryRelation(const std::set< T > &els)
Default constructor, doesn&#39;t initialize the relation.
const U & getRelationValue(size_t e1, size_t e2) const
Get a relation value, given the indices.
void initializeSymmetricallyWith(FunctionType fun)
Initialize the whole relation with a given function, assuming that the relation is symmetrical...
CMatrixColumnAccessor< U > AccessorForSecondElement
Accessor type to every value related to any element B, i.e., f(x,B).
void(* FunctionByReferencePass)(const T &, const T &, U &)
Function type which obtains the relation value by reference pass.
size_t size() const
Returns the amount of elements present in the relation.
#define ASSERT_(f)
ConstAccessorForFirstElement getRelationFrom(const T &t) const
Gets an iterable constant accessor for every value related to an element A, i.e., every f(A...
bool setRelationValue(const T &t1, const T &t2, const U &newVal)
Manually set a relationship value, given the elements.
AccessorForSecondElement getRelationTo(const T &t)
Gets an iterable accessor for every value related to an element B, i.e., every f(x,B).
T operator[](size_t i) const
Operator for direct access to a element given its index.
std::pair< bool, size_t > insertElement(const T &el, FunctionType fun)
Inserts an element and initializes its relationship values, even if it was already present...
A vector-like wrapper for a Matrix for accessing the elements of a given column with a [] operator...
U & operator()(size_t e1, size_t e2)
std::set< T >::const_iterator const_iterator
Constant iterator through the set elements.
const U & operator()(size_t e1, size_t e2) const
const_reverse_iterator rbegin() const
Gets a reverse iterator to the ending point of the elements set.
AccessorForFirstElement getRelationFrom(const T &t)
Gets an iterable accessor for every value related to an element A, i.e., every f(A,x).
U getRelationValue(const T &t1, const T &t2) const
Get a relation value, given the elements.
double BASE_IMPEXP distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.



Page generated by Doxygen 1.8.14 for MRPT 1.0.2 SVN: at lun oct 28 00:52:41 CET 2019 Hosted on:
SourceForge.net Logo