Go to the documentation of this file.
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)
void setElements(const std::set< T > &newEls)
Completely resets the relation, using a new set of elements.
const_iterator end() const
CBinaryRelation(const std::set< T > &els, FunctionType fun)
Constructor which initializes the relation using a given function.
const_reverse_iterator rend() const
Gets a reverse iterator to the starting point of the elements set.
const Scalar * const_iterator
void getRelationTo(const T &t, vector< U > &vec)
CBinaryRelation(const std::set< T > &els)
Default constructor, doesn't initialize the relation.
U(*)(const T &, const T &) FunctionByReturnValue
Function type which obtains the relation value by a return value.
const_iterator begin() const
typename std::set< T >::const_iterator const_iterator
Constant iterator through the set elements.
void removeElementAt(size_t i)
Removes an element at a concrete position.
This class models a binary relation through the elements of any given set.
AccessorForSecondElement getRelationTo(size_t i)
Gets an accessor for every value related to an element B given its index, i.e., every f(x,...
CMatrixColumnAccessor< U > AccessorForSecondElement
Accessor type to every value related to any element B, i.e., f(x,B).
const U & getRelationValue(size_t e1, size_t e2) const
Get a relation value, given the indices.
void applyFunction(CBinaryRelation< T, U, UIsObject > &o, FunctionType fun, size_t e1, size_t e2, const T &T1, const T &T2)
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.
const_iterator find(const KEY &key) const
ConstAccessorForFirstElement getRelationFrom(const T &t) const
Gets an iterable constant accessor for every value related to an element A, i.e., every f(A,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
T operator[](size_t i) const
Operator for direct access to a element given its index.
AccessorForSecondElement getRelationTo(const T &t)
Gets an iterable accessor for every value related to an element B, i.e., every f(x,...
#define ASSERT_(f)
Defines an assertion mechanism.
A vector-like wrapper for a Matrix for accessing the elements of a given row with a [] operator.
bool setRelationValue(const T &t1, const T &t2, const U &newVal)
Manually set a relationship value, given the elements.
typename detail::MatrixWrapper< U, UIsObject >::MatrixType MatrixType
Matrix type used to store the actual relation.
const U & operator()(size_t e1, size_t e2) const
U & operator()(size_t e1, size_t e2)
U getRelationValue(const T &t1, const T &t2) const
Get a relation value, given the elements.
#define ASSERT_BELOW_(__A, __B)
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.
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,...
CConstMatrixRowAccessor< U > ConstAccessorForFirstElement
Const accessor type to every value related to any element A, i.e., f(A,x).
void setRelationValue(size_t e1, size_t e2, const U &newVal)
Manually set a relationship value, given the indices.
void removeElementsAt(const std::set< size_t > &poss)
This template is a trick to switch the type of a variable using a boolean variable in the template.
void(*)(const T &, const T &, U &) FunctionByReferencePass
Function type which obtains the relation value by reference pass.
CMatrixRowAccessor< U > AccessorForFirstElement
Accessor type to every value related to any element A, i.e., f(A,x).
size_t insertElements(const std::set< T > &els)
Inserts a set of elements into the relation.
A vector-like wrapper for a Matrix for accessing the elements of a given column with a [] operator.
ConstAccessorForFirstElement getRelationFrom(size_t i) const
Gets a constant accessor for every value related to an element A given its index, i....
A vector-like wrapper for a const Matrix for accessing the elements of a given row with a [] operator...
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.
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.
typename std::set< T >::const_reverse_iterator const_reverse_iterator
Constant reverse iterator through the set elements.
AccessorForFirstElement getRelationFrom(size_t i)
Gets an accessor for every value related to an element A given its index, i.e., every f(A,...
const_iterator end() const
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
void getRelationTo(size_t i, vector< U > &vec)
const_iterator begin() const
Gets an iterator to the starting point of the elements set.
std::pair< bool, size_t > insertElement(const T &el)
Inserts an element.
void getRelationFrom(size_t i, vector< U > &vec)
std::set< T > elements
Actual set of elements.
A vector-like wrapper for a const Matrix for accessing the elements of a given column with a [] opera...
ConstAccessorForSecondElement getRelationTo(size_t i) const
Gets a constant accessor for every value related to an element B given its index, i....
ConstAccessorForSecondElement getRelationTo(const T &t) const
Gets an iterable constant accessor for every value related to an alement B, i.e., every f(x,...
const_iterator begin() const
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.
CConstMatrixColumnAccessor< U > ConstAccessorForSecondElement
Const accessor type to every value related to any element B, i.e., f(x,B).
MatrixType relation
Matrix storing the relation.
void getRelationFrom(const T &t, vector< U > &vec)
size_t removeElements(const std::set< T > &vals)
Removes a set of elements.
bool removeElement(const T &el)
Removes an element.
void initializeWith(FunctionType fun)
Initialize the whole relation with a given function.
U & getRelationValue(const T &t1, const T &t2)
Get a reference to a relation value given the elements, which allows both querying and setting.
U(*)(T, T) SimpleFunctionByReturnValue
Simple function type, used to initialize chunks of the matrix.
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |