|
Robotics Library
0.7.0
|
Go to the documentation of this file.
27 #ifndef RL_MATH_LINEARNEARESTNEIGHBORS_H
28 #define RL_MATH_LINEARNEARESTNEIGHBORS_H
40 template<
typename MetricT,
typename ContainerT = ::std::vector<
typename MetricT::Value>>
50 typedef typename ContainerT::iterator
iterator;
64 typedef typename MetricT::Value
Value;
80 template<
typename InputIterator>
87 template<
typename InputIterator>
158 const_iterator
end()
const
178 template<
typename InputIterator>
179 void insert(InputIterator first, InputIterator last)
189 ::std::vector<Neighbor>
nearest(
const Value& query, const ::std::size_t& k,
const bool& sorted =
true)
const
191 return this->
search(query, &k,
nullptr, sorted);
243 return lhs.first < rhs.first;
249 ::std::vector<Neighbor> neighbors;
250 neighbors.reserve(
nullptr != k ? *k : this->
size());
252 ::std::vector<Distance> distances(this->
container.size());
254 #pragma omp parallel for
255 #if defined(_OPENMP) && _OPENMP < 200805
256 for (::std::ptrdiff_t i = 0; i < this->
container.size(); ++i)
258 for (::std::size_t i = 0; i < this->
container.size(); ++i)
264 for (::std::size_t i = 0; i < this->
container.size(); ++i)
266 if (
nullptr == k || neighbors.size() < *k || distances[i] < neighbors.front().first)
270 if (
nullptr != k && *k == neighbors.size())
272 ::std::pop_heap(neighbors.begin(), neighbors.end(), NeighborCompare());
273 neighbors.pop_back();
276 #if defined(_MSC_VER) && _MSC_VER < 1800
277 neighbors.push_back(::std::make_pair(distances[i], this->
container[i]));
279 neighbors.emplace_back(distances[i], this->
container[i]);
281 ::std::push_heap(neighbors.begin(), neighbors.end(), NeighborCompare());
288 ::std::sort_heap(neighbors.begin(), neighbors.end(), NeighborCompare());
301 #endif // RL_MATH_LINEARNEARESTNEIGHBORS_H
::std::pair< Distance, Value > Neighbor
Definition: LinearNearestNeighbors.h:66
::std::size_t capacity() const
Definition: LinearNearestNeighbors.h:128
::std::vector< Neighbor > search(const Value &query, const ::std::size_t *k, const Distance *radius, const bool &sorted) const
Definition: LinearNearestNeighbors.h:247
ContainerT::iterator iterator
Definition: LinearNearestNeighbors.h:50
dummy cpp endif() if(CMAKE_SIZEOF_VOID_P EQUAL 4) target_compile_definitions(math INTERFACE -DEIGEN_DONT_ALIGN_STATICALLY) endif() if(NOT CMAKE_VERSION VERSION_LESS 3.8) target_compile_features(math INTERFACE cxx_std_11) endif() target_include_directories(math INTERFACE $< BUILD_INTERFACE
Definition: CMakeLists.txt:66
bool empty() const
Definition: LinearNearestNeighbors.h:148
const_iterator cend() const
Definition: LinearNearestNeighbors.h:138
Value & operator[](const ::std::size_t &i)
Definition: LinearNearestNeighbors.h:194
const Value & back() const
Definition: LinearNearestNeighbors.h:113
MetricT::Value & reference
Definition: LinearNearestNeighbors.h:52
void push(const Value &value)
Definition: LinearNearestNeighbors.h:204
const Value & operator[](const ::std::size_t &i) const
Definition: LinearNearestNeighbors.h:199
::std::size_t max_size() const
Definition: LinearNearestNeighbors.h:184
ContainerT::size_type size_type
Definition: LinearNearestNeighbors.h:54
LinearNearestNeighbors(const Metric &metric)
Definition: LinearNearestNeighbors.h:68
Container container
Definition: LinearNearestNeighbors.h:294
~LinearNearestNeighbors()
Definition: LinearNearestNeighbors.h:94
iterator end()
Definition: LinearNearestNeighbors.h:153
void clear()
Definition: LinearNearestNeighbors.h:143
LinearNearestNeighbors(Metric &&metric=Metric())
Definition: LinearNearestNeighbors.h:74
::std::vector< Neighbor > radius(const Value &query, const Distance &radius, const bool &sorted=true) const
Definition: LinearNearestNeighbors.h:209
::std::size_t size() const
Definition: LinearNearestNeighbors.h:219
const_iterator begin() const
Definition: LinearNearestNeighbors.h:123
MetricT::Value value_type
Definition: LinearNearestNeighbors.h:56
const Value & at(const ::std::size_t &i) const
Definition: LinearNearestNeighbors.h:103
MetricT Metric
Definition: LinearNearestNeighbors.h:62
ContainerT::const_iterator const_iterator
Definition: LinearNearestNeighbors.h:44
void erase(const_iterator pos)
Definition: LinearNearestNeighbors.h:163
Definition: LinearNearestNeighbors.h:240
LinearNearestNeighbors(InputIterator first, InputIterator last, Metric &&metric=Metric())
Definition: LinearNearestNeighbors.h:88
void swap(::rl::util::rtai::thread &x, ::rl::util::rtai::thread &y)
Definition: thread.h:492
const_iterator cbegin() const
Definition: LinearNearestNeighbors.h:133
void reserve(const ::std::size_t &capacity)
Definition: LinearNearestNeighbors.h:214
iterator begin()
Definition: LinearNearestNeighbors.h:118
Linear nearest neighbor search.
Definition: LinearNearestNeighbors.h:42
MetricT::Distance Distance
Definition: LinearNearestNeighbors.h:60
LinearNearestNeighbors(InputIterator first, InputIterator last, const Metric &metric)
Definition: LinearNearestNeighbors.h:81
const_iterator end() const
Definition: LinearNearestNeighbors.h:158
ContainerT Container
Definition: LinearNearestNeighbors.h:58
MetricT::Value Value
Definition: LinearNearestNeighbors.h:64
Metric metric
Definition: LinearNearestNeighbors.h:296
bool operator()(const Neighbor &lhs, const Neighbor &rhs) const
Definition: LinearNearestNeighbors.h:241
const Value & front() const
Definition: LinearNearestNeighbors.h:173
Value & back()
Definition: LinearNearestNeighbors.h:108
Value & front()
Definition: LinearNearestNeighbors.h:168
void swap(LinearNearestNeighbors &other)
Definition: LinearNearestNeighbors.h:224
::std::vector< Neighbor > nearest(const Value &query, const ::std::size_t &k, const bool &sorted=true) const
Definition: LinearNearestNeighbors.h:189
const MetricT::Value & const_reference
Definition: LinearNearestNeighbors.h:46
ContainerT::difference_type difference_type
Definition: LinearNearestNeighbors.h:48
friend void swap(LinearNearestNeighbors &lhs, LinearNearestNeighbors &rhs)
Definition: LinearNearestNeighbors.h:231
Value & at(const ::std::size_t &i)
Definition: LinearNearestNeighbors.h:98
void insert(InputIterator first, InputIterator last)
Definition: LinearNearestNeighbors.h:179
Robotics Library.
Definition: AnalogInput.cpp:30