Ponca  03745f3c84c0c8d40cec269af63efe7d3cf77f30
Point Cloud Analysis library
Loading...
Searching...
No Matches
neighborGraph.h
1/*
2 This Source Code Form is subject to the terms of the Mozilla Public
3 License, v. 2.0. If a copy of the MPL was not distributed with this
4 file, You can obtain one at http://mozilla.org/MPL/2.0/.
5*/
6
7#pragma once
8
9#include "abstractNeighborGraph.h"
10#include "Query/neighborGraphOneConnectedQuery.h"
11#include "Query/neighborGraphRangeQuery.h"
12
13#include "../KdTree/kdTree.h"
14
15namespace Ponca
16{
24 template <typename _Traits>
26 {
27 WRITE_NEIGHBOR_GRAPH_ALIASES
29
30 IndexContainer ranges;
31
32 PONCA_MULTIARCH inline NeighborGraphBuffer() = default;
34 PONCA_MULTIARCH inline NeighborGraphBuffer(PointContainer _points, typename Traits::IndexContainerRef _indices,
35 const size_t _points_size, const size_t _indices_size,
36 typename Traits::IndexContainerRef _ranges)
38 {
39 }
40 };
41
52 template <typename _Traits>
54 : public AbstractNeighborGraph<_Traits, NeighborGraphBuffer,
55 NeighborGraphOneConnectedQuery<StaticNeighborGraphBase<_Traits>>,
56 NeighborGraphRangeQuery<StaticNeighborGraphBase<_Traits>>>
57 {
58 public:
59 WRITE_NEIGHBOR_GRAPH_ALIASES
60
65
69 using Buffers = typename Base::Buffers;
70
71 PONCA_MULTIARCH inline StaticNeighborGraphBase(const Buffers& _bufs) : Base(_bufs) {}
72
75 PONCA_MULTIARCH [[nodiscard]] inline int k(int vId = 0) const { return endId(vId) * beginId(vId); }
77 PONCA_MULTIARCH [[nodiscard]] inline int beginId(int vId) const { return Base::buffers().ranges[vId]; }
79 PONCA_MULTIARCH [[nodiscard]] inline int endId(int vId) const { return Base::buffers().ranges[vId + 1]; }
81 };
82
83 template <typename _Traits>
85 {
86 public:
87 WRITE_NEIGHBOR_GRAPH_ALIASES
88
89 private:
91 using Buffers = typename Base::Buffers;
92
93 public:
105 template <typename KdTreeTraits>
106 PONCA_MULTIARCH_HOST inline NeighborGraphBase(const KdTreeBase<KdTreeTraits>& _kdtree, const Scalar range)
107 : Base(_kdtree.points())
108 {
109 Base::m_bufs.points_size = _kdtree.pointCount();
110#define CHECK_TRAITS_TYPENAME_COMPAT(A, B) \
111 static_assert(std::is_same_v<A, B> || std::is_convertible_v<A, B> || std::is_convertible_v<B, A>, \
112 "KdTreeTraits::DataPoint is not equal to Traits::DataPoint");
113
114 static_assert(std::is_same_v<typename Traits::DataPoint, typename KdTreeTraits::DataPoint>,
115 "KdTreeTraits::DataPoint is not equal to Traits::DataPoint");
116
117 CHECK_TRAITS_TYPENAME_COMPAT(typename Traits::PointContainer, typename KdTreeTraits::PointContainer)
118 CHECK_TRAITS_TYPENAME_COMPAT(typename Traits::IndexContainer, typename KdTreeTraits::IndexContainer)
119
120#undef CHECK_TRAITS_TYPENAME_COMPAT
121
122 // We need to account for the entire point set, irrespectively of the sampling. This is because the kdtree
123 // (kNearestNeighbors) return ids of the entire point set, not it sub-sampled list of ids.
124 // \fixme Update API to properly handle kdtree subsampling
125 const int cloudSize = _kdtree.pointCount();
126 {
127 const int samplesSize = _kdtree.sampleCount();
128 PONCA_ASSERT(cloudSize == samplesSize);
129 }
130
131 Base::m_bufs.ranges.resize(cloudSize + 1); // we need one more index (see StaticNeighborGraphBase::endId)
132 Base::m_bufs.ranges[0] = 0; // first element starts at 0;
133
134 for (int i = 0; i < cloudSize; ++i)
135 {
136 for (auto n : _kdtree.rangeNeighbors(typename KdTreeTraits::IndexType(i), range))
137 {
138 Base::m_bufs.indices.push_back(n);
139 }
140 Base::m_bufs.ranges[i + 1] = Base::m_bufs.indices.size();
141 }
142 Base::m_bufs.indices_size = Base::m_bufs.indices.size();
143 }
144 };
145
154 template <typename DataPoint>
156
157} // namespace Ponca
158
159#undef WRITE_TRAITS
Base class for neighbor graphs.
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:283
NeighborGraphBase(const KdTreeBase< KdTreeTraits > &_kdtree, const Scalar range)
Build a neighbor graph by connecting all points using Euclidean range queries: two points.
typename DataPoint::Scalar Scalar
Scalar given by user via DataPoint
Extension of the Query class that allows to read the neighbors that are directly connected to the que...
Extension of the Query class that allows to read the result of a range neighbor search on the KnnGrap...
Static generic neighbor graph (does not include build functions)
typename Traits::PointContainer PointContainer
Container for DataPoint used inside the KdTree
int endId(int vId) const
Index of the end of the neighborhood range (see storing convention in NeighborGraphBuffer)
_Traits Traits
Alias to the Traits type
int beginId(int vId) const
Index of the beginning of the neighborhood range (see storing convention in NeighborGraphBuffer)
int k(int vId=0) const
[Neighbor Graph Accessors]
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
Internal structure storing the buffers used by a neighbor graph.
Buffer class for StaticNeighborGraphBase.
typename Traits::IndexContainer IndexContainer
Container for indices used inside the KdTree
typename Traits::PointContainerConstRef PointContainerConstRef
Container for DataPoint used inside the KdTree