40 template <
typename T,
typename U,
bool UIsObject = false>
84 template <
typename FunctionType>
86 FunctionType fun,
size_t e1,
size_t e2,
const T& T1,
const T& T2)
88 detail::applyFunction<T, U, UIsObject, FunctionType>(
89 *
this, fun, e1, e2, T1, T2);
103 template <
typename FunctionType>
112 template <
typename FunctionType>
115 typename std::set<T>::const_iterator it =
elements.begin();
116 for (
size_t i = 0; i <
elements.size(); ++i, ++it)
118 typename std::set<T>::const_iterator jt =
elements.begin();
119 for (
size_t j = 0; j <
elements.size(); ++j, ++jt)
127 template <
typename FunctionType>
130 typename std::set<T>::const_iterator it =
elements.begin();
131 for (
size_t i = 0; i <
elements.size(); ++i, ++it)
134 typename std::set<T>::const_iterator jt = it;
136 for (
size_t j = i + 1; j <
elements.size(); ++j, ++jt)
179 typename std::set<T>::const_iterator
b =
elements.begin(),
181 typename std::set<T>::const_iterator it1 =
std::find(
b, e, t1),
183 if (it1 == e || it2 == e)
return false;
195 typename std::set<T>::const_iterator
b =
elements.begin(),
197 typename std::set<T>::const_iterator it1 =
std::find(
b, e, t1),
199 if (it1 == e || it2 == e)
throw std::domain_error(
"Element not found");
212 typename std::set<T>::const_iterator
b =
elements.begin(),
214 typename std::set<T>::const_iterator it1 =
std::find(
b, e, t1),
216 if (it1 == e || it2 == e)
throw std::domain_error(
"Element not found");
243 typename std::set<T>::const_iterator it =
elements.begin();
286 typename std::set<T>::const_iterator
b =
elements.begin(),
288 typename std::set<T>::const_iterator it =
std::find(
b, e,
t);
289 if (it == e)
throw std::domain_error(
"Element not found");
300 typename std::set<T>::const_iterator
b =
elements.begin(),
302 typename std::set<T>::const_iterator it =
std::find(
b, e,
t);
303 if (it == e)
throw std::domain_error(
"Element not found");
312 std::copy(access.
begin(), access.
end(), vec.begin());
316 typename std::set<T>::const_iterator
b =
elements.begin(),
318 typename std::set<T>::const_iterator it =
std::find(
b, e,
t);
319 if (it == e)
throw std::domain_error(
"Element not found");
329 typename std::set<T>::const_iterator
b =
elements.begin(),
331 typename std::set<T>::const_iterator it =
std::find(
b, e,
t);
332 if (it == e)
throw std::domain_error(
"Element not found");
343 typename std::set<T>::const_iterator
b =
elements.begin(),
345 typename std::set<T>::const_iterator it =
std::find(
b, e,
t);
346 if (it == e)
throw std::domain_error(
"Element not found");
355 std::copy(access.
begin(), access.
end(), vec.begin());
359 typename std::set<T>::const_iterator
b =
elements.begin(),
361 typename std::set<T>::const_iterator it =
std::find(
b, e,
t);
362 if (it == e)
throw std::domain_error(
"Element not found");
371 typename std::set<T>::const_iterator it =
elements.begin();
384 typename std::set<T>::const_iterator
b =
elements.begin(),
386 typename std::set<T>::const_iterator it =
std::find(e,
b, el);
387 if (it == e)
return false;
397 std::set<size_t> positions;
398 for (
typename std::set<T>::const_iterator it = vals.begin();
399 it != vals.end(); ++it)
401 typename std::set<T>::iterator elsIt =
407 return positions.size();
411 relation.removeRowsAndCols(poss, poss);
412 for (std::set<size_t>::const_reverse_iterator it = poss.rbegin();
413 it != poss.rend(); ++it)
415 typename std::set<T>::const_iterator it2 =
elements.begin();
416 std::advance(it2, *it);
428 std::pair<typename std::set<T>::iterator,
bool> ins =
433 std::multiset<size_t> newEls;
435 relation.insertRowsAndCols(newEls, newEls);
436 return std::make_pair(
true, dist);
439 return std::make_pair(
false, dist);
445 template <
typename FunctionType>
449 size_t pos = ins.second;
450 for (
size_t i = 0; i <
elements.size(); ++i)
464 if (els.empty())
return 0;
472 std::vector<size_t> added;
474 added.reserve(els.size());
475 for (
typename std::set<T>::const_iterator it = els.begin();
476 it != els.end(); ++it)
478 std::pair<typename std::set<T>::iterator,
bool> ins =
483 added.push_back(dist);
484 for (std::vector<size_t>::iterator it2 = added.begin();
485 it2 != added.end(); ++it2)
486 if (*it2 >= dist) ++(*it2);
492 std::sort(added.begin(), added.end());
493 for (
size_t j = 1; j < added.size(); ++j) added[j] -= j;
494 std::multiset<size_t> poss(added.begin(), added.end());
495 relation.insertRowsAndCols(poss, poss);
502 template <
typename FunctionType>
505 if (els.empty())
return 0;
507 std::set<size_t> poss;
510 typename std::set<T>::const_iterator
begin =
elements.begin(),
512 for (
typename std::set<T>::const_iterator it = els.begin();
513 it != els.end(); ++it)
516 std::set<size_t> nPoss;
517 std::set<size_t>::const_iterator
begin = poss.begin(),
end = poss.end();
518 for (
size_t i = 0; i <
elements.size(); ++i)
520 vector<const T*> proxy;
521 proxy.reserve(poss.size());
522 for (std::set<size_t>::const_iterator it =
begin; it !=
end; ++it)
525 proxy.push_back(&e1);
527 for (
typename std::set<T>::const_iterator it2 =
elements.begin();
531 for (std::set<size_t>::const_iterator it = nPoss.begin();
532 it != nPoss.end(); ++it)
535 typename std::vector<const T*>::const_iterator itV = proxy.begin();
536 for (std::set<size_t>::const_iterator it2 = poss.begin();
537 it2 != poss.end(); ++it2, ++itV)
550 relation.setSize(newEls.size(), newEls.size());
561 template <
typename T,
typename U,
bool UIsObject,
typename FunctionType>
564 const T& T1,
const T& T2)
571 template <
typename T,
typename U,
bool UIsObject>
575 size_t e1,
size_t e2,
const T& T1,
const T& T2)
CMatrixRowAccessor< U > AccessorForFirstElement
Accessor type to every value related to any element A, i.e., f(A,x).
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)
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...
const_iterator find(const KEY &key) const
#define ASSERT_BELOW_(__A, __B)
void removeElementsAt(const std::set< size_t > &poss)
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...
typename std::set< T >::const_reverse_iterator const_reverse_iterator
Constant reverse iterator through the set elements.
void(*)(const T &, const T &, U &) FunctionByReferencePass
Function type which obtains the relation value by reference pass.
size_t insertElements(const std::set< T > &els)
Inserts a set of elements into the relation.
const_iterator end() const
const_iterator begin() const
This class models a binary relation through the elements of any given set.
std::pair< bool, size_t > insertElement(const T &el)
Inserts an element.
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)
#define ASSERT_(f)
Defines an assertion mechanism.
size_t removeElements(const std::set< T > &vals)
Removes a set of elements.
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...
CConstMatrixColumnAccessor< U > ConstAccessorForSecondElement
Const accessor type to every value related to any element B, i.e., f(x,B).
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...
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.
U(*)(T, T) SimpleFunctionByReturnValue
Simple function type, used to initialize chunks of the matrix.
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)
CBinaryRelation(const std::set< T > &els, FunctionType fun)
Constructor which initializes the relation using a given function.
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(*)(const T &, const T &) FunctionByReturnValue
Function type which obtains the relation value by a return value.
const_iterator begin() const
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CBinaryRelation(const std::set< T > &els)
Default constructor, doesn't initialize the relation.
const U & getRelationValue(size_t e1, size_t e2) const
Get a relation value, given the indices.
typename std::set< T >::const_iterator const_iterator
Constant iterator through the set elements.
void initializeSymmetricallyWith(FunctionType fun)
Initialize the whole relation with a given function, assuming that the relation is symmetrical...
size_t size() const
Returns the amount of elements present in the relation.
CMatrixColumnAccessor< U > AccessorForSecondElement
Accessor type to every value related to any element B, i.e., f(x,B).
ConstAccessorForFirstElement getRelationFrom(const T &t) const
Gets an iterable constant accessor for every value related to an element A, i.e., every f(A...
const_iterator end() const
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
typename detail::MatrixWrapper< U, UIsObject >::MatrixType MatrixType
Matrix type used to store the actual relation.
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.
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)
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 distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
CConstMatrixRowAccessor< U > ConstAccessorForFirstElement
Const accessor type to every value related to any element A, i.e., f(A,x).