Ponca  a6685bea814e743eaa6c9284aa218d7d97a6527c
Point Cloud Analysis library
Loading...
Searching...
No Matches
abstractNeighborGraph.h
1/*
2This 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 "neighborGraphTraits.h"
10
11#include <cstddef> // size_t
12
13#define WRITE_NEIGHBOR_GRAPH_ALIASES \
14 using Traits = _Traits; \
15 using DataPoint = typename Traits::DataPoint; \
16 using Scalar = typename DataPoint::Scalar; \
17 using VectorType = typename DataPoint::VectorType; \
18 using IndexType = typename Traits::IndexType; \
19 using PointContainer = typename Traits::PointContainer; \
20 using PointContainerConstRef = \
21 typename Traits::PointContainerConstRef; \
22 using IndexContainer = typename Traits::IndexContainer; \
23 using IndexContainerRef = typename Traits::IndexContainerRef;
25namespace Ponca
26{
31 template <typename _Traits>
33 {
34 WRITE_NEIGHBOR_GRAPH_ALIASES
35
40
42 size_t points_size{0};
44 size_t indices_size{0};
45
47 PONCA_MULTIARCH inline NeighborGraphBufferBase() = default;
48
51
58 };
59
76 template <typename _Traits, template <typename> typename BufferType, typename _OneConnectedIndexQuery,
77 typename _RangeIndexQuery>
79 {
80 public:
81 WRITE_NEIGHBOR_GRAPH_ALIASES
84
86 static_assert(std::is_base_of_v<NeighborGraphBufferBase<Traits>, Buffers>,
87 "BufferType must inherit NeighborGraphBufferBase");
88
89 protected:
91 PONCA_MULTIARCH inline const IndexType* getIndexPtr() const { return Traits::getIndexRawPtr(m_bufs.indices); }
93 PONCA_MULTIARCH inline IndexType* getIndexPtr() { return Traits::getIndexRawPtr(m_bufs.indices); }
94
95 public:
96 // Data --------------------------------------------------------------------
97
107 PONCA_MULTIARCH inline AbstractNeighborGraph(const Buffers& _bufs) : m_bufs(_bufs) {}
108
110 PONCA_MULTIARCH [[nodiscard]] inline IndexType edgeCount() const { return (IndexType)m_bufs.indices_size; }
112 PONCA_MULTIARCH [[nodiscard]] inline IndexType pointCount() const { return (IndexType)m_bufs.points_size; }
114 PONCA_MULTIARCH [[nodiscard]] inline PointContainer points() const { return m_bufs.points; };
116 PONCA_MULTIARCH [[nodiscard]] inline IndexContainer edges() const { return m_bufs.indices; };
118 PONCA_MULTIARCH [[nodiscard]] inline const Buffers& buffers() const { return m_bufs; }
119
120 // Query -------------------------------------------------------------------
121
129 PONCA_MULTIARCH [[nodiscard]] inline OneConnectedIndexQuery oneConnectedNeighbors(int index = 0) const
130 {
131 return OneConnectedIndexQuery(static_cast<const typename OneConnectedIndexQuery::NeighborGraph*>(this),
132 index);
133 }
134
143 PONCA_MULTIARCH [[nodiscard]] inline RangeIndexQuery rangeNeighbors(int index, Scalar r) const
144 {
145 return RangeIndexQuery(static_cast<const typename RangeIndexQuery::NeighborGraph*>(this), r, index);
146 }
147
152 PONCA_MULTIARCH [[nodiscard]] inline RangeIndexQuery rangeNeighborsIndexQuery() const
153 {
154 return RangeIndexQuery(static_cast<const typename RangeIndexQuery::NeighborGraph*>(this), 0, 0);
155 }
156
157 protected: // for friends relations
159 };
160} // namespace Ponca
161
Base class for neighbor graphs.
PointContainer points() const
Get the internal point container.
IndexType pointCount() const
Get the number of points.
Buffers m_bufs
Buffers used to store the KnnGraph.
typename DataPoint::Scalar Scalar
Scalar given by user via DataPoint
typename Traits::PointContainer PointContainer
Container for DataPoint used inside the KdTree
typename Traits::IndexContainer IndexContainer
Container for indices used inside the KdTree
AbstractNeighborGraph(const Buffers &_bufs)
Constructor that allows the use of prebuilt graph containers.
IndexType * getIndexPtr()
Accessor used by friend classes (queries) to get access to the indices whatever the buffer type.
OneConnectedIndexQuery oneConnectedNeighbors(int index=0) const
Provides a Query object to iterate over the vertices that are directly connected to the query point.
const IndexType * getIndexPtr() const
Accessor used by friend classes (queries) to get const access to the indices whatever the buffer type...
RangeIndexQuery rangeNeighborsIndexQuery() const
Convenience function to return an empty mutable range query.
IndexType edgeCount() const
Get the number of connection edges in the graph.
typename Traits::IndexType IndexType
Type used to index points into the PointContainer.
IndexContainer edges() const
Get the internal index container.
RangeIndexQuery rangeNeighbors(int index, Scalar r) const
Provides a Query object to iterate over the neighbors that are inside a given radius.
const Buffers & buffers() const
Get access to the internal buffer, for instance to prepare GPU binding.
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:283
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.
typename Traits::PointContainer PointContainer
Container for DataPoint used inside the KdTree
typename Traits::IndexContainer IndexContainer
Container for indices used inside the KdTree
size_t points_size
Number of points in the graph.
typename Traits::PointContainerConstRef PointContainerConstRef
Container for DataPoint used inside the KdTree
NeighborGraphBufferBase(PointContainerConstRef _points, IndexContainerRef _indices, const size_t _points_size, const size_t _indices_size)
Constructor allowing to set all the attributes.
NeighborGraphBufferBase(PointContainerConstRef _points)
Default constructor setting the point container.
size_t indices_size
Number of connections in the graph.
PointContainer points
Buffer storing the input points (read only)
typename Traits::IndexContainerRef IndexContainerRef
Ref type to index container.
IndexContainer indices
Buffer storing the indices associating the input points to the nodes.
NeighborGraphBufferBase()=default
Default constructor, might be deleted depending on the PointContainer type (e.g. const reference)