9 #ifndef CBINARYRELATION_H_ 10 #define CBINARYRELATION_H_ 41 template <
typename T,
typename U,
bool UIsObject = false>
85 template <
typename FunctionType>
87 FunctionType fun,
size_t e1,
size_t e2,
const T& T1,
const T& T2)
89 detail::applyFunction<T, U, UIsObject, FunctionType>(
90 *
this, fun, e1, e2, T1, T2);
104 template <
typename FunctionType>
113 template <
typename FunctionType>
117 for (
size_t i = 0; i <
elements.size(); ++i, ++it)
120 for (
size_t j = 0; j <
elements.size(); ++j, ++jt)
128 template <
typename FunctionType>
132 for (
size_t i = 0; i <
elements.size(); ++i, ++it)
137 for (
size_t j = i + 1; j <
elements.size(); ++j, ++jt)
149 relation.get_unsafe(e1, e2) = newVal;
184 if (it1 == e || it2 == e)
return false;
200 if (it1 == e || it2 == e)
throw std::domain_error(
"Element not found");
217 if (it1 == e || it2 == e)
throw std::domain_error(
"Element not found");
290 if (it == e)
throw std::domain_error(
"Element not found");
304 if (it == e)
throw std::domain_error(
"Element not found");
313 std::copy(access.
begin(), access.
end(), vec.begin());
320 if (it == e)
throw std::domain_error(
"Element not found");
333 if (it == e)
throw std::domain_error(
"Element not found");
347 if (it == e)
throw std::domain_error(
"Element not found");
356 std::copy(access.
begin(), access.
end(), vec.begin());
363 if (it == e)
throw std::domain_error(
"Element not found");
388 if (it == e)
return false;
398 std::set<size_t> positions;
400 it != vals.end(); ++it)
408 return positions.size();
412 relation.removeRowsAndCols(poss, poss);
413 for (std::set<size_t>::const_reverse_iterator it = poss.rbegin();
414 it != poss.rend(); ++it)
417 std::advance(it2, *it);
434 std::multiset<size_t> newEls;
436 relation.insertRowsAndCols(newEls, newEls);
437 return std::make_pair(
true, dist);
440 return std::make_pair(
false, dist);
446 template <
typename FunctionType>
450 size_t pos = ins.second;
451 for (
size_t i = 0; i <
elements.size(); ++i)
465 if (els.empty())
return 0;
473 std::vector<size_t> added;
475 added.reserve(els.size());
477 it != els.end(); ++it)
484 added.push_back(dist);
486 it2 != added.end(); ++it2)
487 if (*it2 >= dist) ++(*it2);
493 std::sort(added.begin(), added.end());
494 for (
size_t j = 1; j < added.size(); ++j) added[j] -= j;
495 std::multiset<size_t> poss(added.begin(), added.end());
496 relation.insertRowsAndCols(poss, poss);
503 template <
typename FunctionType>
506 if (els.empty())
return 0;
508 std::set<size_t> poss;
514 it != els.end(); ++it)
517 std::set<size_t> nPoss;
519 for (
size_t i = 0; i <
elements.size(); ++i)
521 vector<const T*> proxy;
522 proxy.reserve(poss.size());
526 proxy.push_back(&e1);
533 it != nPoss.end(); ++it)
538 it2 != poss.end(); ++it2, ++itV)
551 relation.setSize(newEls.size(), newEls.size());
562 template <
typename T,
typename U,
bool UIsObject,
typename FunctionType>
565 const T& T1,
const T& T2)
572 template <
typename T,
typename U,
bool UIsObject>
576 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 Scalar * const_iterator
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).