32 #ifndef __INDEX_HEAP_H
33 #define __INDEX_HEAP_H
51 template<
typename IT,
typename VT>
73 typedef typename Eigen::Matrix<Index, Eigen::Dynamic, 1>
IndexVector;
75 typedef typename Eigen::Matrix<Value, Eigen::Dynamic, 1>
ValueVector;
86 data(1,
Entry(0, std::numeric_limits<VT>::infinity())),
96 data.push_back(
Entry(0, std::numeric_limits<VT>::infinity()));
119 push_heap(
data.begin(),
data.end());
125 sort_heap (
data.begin(),
data.end());
131 template<
typename DI,
typename DV>
132 inline void getData(
const Eigen::MatrixBase<DI>& indices,
const Eigen::MatrixBase<DV> & values)
const
139 for (; i <
data.size(); ++i)
141 const_cast<Eigen::MatrixBase<DI>&
>(indices).coeffRef(i) =
data[i].index;
142 const_cast<Eigen::MatrixBase<DV>&
>(values).coeffRef(i) =
data[i].value;
146 const_cast<Eigen::MatrixBase<DI>&
>(indices).coeffRef(i) = 0;
147 const_cast<Eigen::MatrixBase<DV>&
>(values).coeffRef(i) = std::numeric_limits<VT>::infinity();
158 for (; i <
data.size(); ++i)
159 indexes.coeffRef(i) =
data[i].index;
160 for (; i <
data.capacity(); ++i)
161 indexes.coeffRef(i) = 0;
171 template<
typename IT,
typename VT>
172 struct IndexHeapBruteForceVector
191 typedef std::vector<Entry>
Entries;
193 typedef typename Eigen::Matrix<Index, Eigen::Dynamic, 1>
IndexVector;
205 data(size, Entry(0, std::numeric_limits<VT>::infinity())),
214 for (
typename Entries::iterator it(
data.begin()); it !=
data.end(); ++it)
215 it->value = std::numeric_limits<VT>::infinity();
227 register size_t i = 0;
230 if (
data[i + 1].value > value)
235 data[i].value = value;
236 data[i].index = index;
250 for (
size_t i = 0; i <
data.size(); ++i)
251 indexes.coeffRef(i) =
data[sizeMinusOne-i].index;
260 template<
typename IT,
typename VT>
275 Entry(
const IT index,
const VT value): index(index), value(value) {}
282 typedef typename Eigen::Matrix<Index, Eigen::Dynamic, 1>
IndexVector;
284 typedef typename Eigen::Matrix<Value, Eigen::Dynamic, 1>
ValueVector;
296 data(size,
Entry(0, std::numeric_limits<VT>::infinity())),
298 sizeMinusOne(
data.size() - 1)
305 for (
typename Entries::iterator it(
data.begin()); it !=
data.end(); ++it)
306 it->value = std::numeric_limits<VT>::infinity();
319 for (i = sizeMinusOne; i > 0; --i)
321 if (
data[i-1].value > value)
326 data[i].value = value;
327 data[i].index = index;
339 template<
typename DI,
typename DV>
340 inline void getData(
const Eigen::MatrixBase<DI>& indices,
const Eigen::MatrixBase<DV> & values)
const
346 for (
size_t i = 0; i <
data.size(); ++i)
348 const_cast<Eigen::MatrixBase<DI>&
>(indices).coeffRef(i) =
data[i].index;
349 const_cast<Eigen::MatrixBase<DV>&
>(values).coeffRef(i) =
data[i].value;
358 for (
size_t i = 0; i <
data.size(); ++i)
359 indexes.coeffRef(i) =
data[i].index;
366 #endif // __INDEX_HEAP_H
IndexHeapBruteForceVector(const size_t size)
Constructor.
Definition: index_heap.h:295
friend bool operator<(const Entry &e0, const Entry &e1)
return true if e0 is smaller than e1, false otherwise
Definition: index_heap.h:277
void replaceHead(const Index index, const Value value)
replace the largest value of the heap
Definition: index_heap.h:316
void sort()
sort the entries, from the smallest to the largest
Definition: index_heap.h:331
const VT & headValue() const
get the largest value of the heap
Definition: index_heap.h:311
void sort()
sort the entries, from the smallest to the largest
Definition: index_heap.h:123
an entry of the heap vector
Definition: index_heap.h:269
Eigen::Matrix< Value, Eigen::Dynamic, 1 > ValueVector
vector of values
Definition: index_heap.h:75
IT index
index of point
Definition: index_heap.h:62
std::vector< Entry > Entries
vector of entry, type for the storage of the tree
Definition: index_heap.h:71
const VT & headValueRef
reference to the largest value in the tree, to optimise access speed
Definition: index_heap.h:289
VT value
distance for this point
Definition: index_heap.h:272
Eigen::Matrix< Index, Eigen::Dynamic, 1 > IndexVector
vector of indices
Definition: index_heap.h:282
std::vector< Entry > Entries
vector of entry, type for the storage of the tree
Definition: index_heap.h:280
Entries data
storage for the tree
Definition: index_heap.h:287
Entry(const IT index, const VT value)
create a new entry
Definition: index_heap.h:275
Eigen::Matrix< Value, Eigen::Dynamic, 1 > ValueVector
vector of values
Definition: index_heap.h:284
const size_t nbNeighbours
number of neighbours requested
Definition: index_heap.h:80
VT Value
type of a value
Definition: index_heap.h:57
const size_t sizeMinusOne
pre-competed size minus one, to optimise access speed
Definition: index_heap.h:291
Entries data
storage for the tree
Definition: index_heap.h:78
void reset()
reset to the empty heap
Definition: index_heap.h:93
an entry of the heap tree
Definition: index_heap.h:60
void getData(const Eigen::MatrixBase< DI > &indices, const Eigen::MatrixBase< DV > &values) const
get the data from the heap
Definition: index_heap.h:340
void replaceHead(const Index index, const Value value)
put value into heap, replace the largest value if full
Definition: index_heap.h:106
balanced-tree implementation of heap
Definition: index_heap.h:52
IndexHeapSTL(const size_t size)
Constructor.
Definition: index_heap.h:85
void getData(const Eigen::MatrixBase< DI > &indices, const Eigen::MatrixBase< DV > &values) const
get the data from the heap
Definition: index_heap.h:132
IT Index
type of an index
Definition: index_heap.h:264
void reset()
reset to the empty heap
Definition: index_heap.h:303
IT index
index of point
Definition: index_heap.h:271
Entry(const IT index, const VT value)
create a new entry
Definition: index_heap.h:66
brute-force implementation of heap
Definition: index_heap.h:261
VT Value
type of a value
Definition: index_heap.h:266
VT value
distance for this point
Definition: index_heap.h:63
Eigen::Matrix< Index, Eigen::Dynamic, 1 > IndexVector
vector of indices
Definition: index_heap.h:73
friend bool operator<(const Entry &e0, const Entry &e1)
return true if e0 is of lower value than e1, false otherwise
Definition: index_heap.h:68
IT Index
type of an index
Definition: index_heap.h:55
const VT & headValue() const
get the largest value of the heap
Definition: index_heap.h:101