Loading...
Searching...
No Matches
PointKdTreeSearcher.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_POINT_KDTREE_SEARCHER_HPP
12#define CUBBYFLOW_POINT_KDTREE_SEARCHER_HPP
13
16
17namespace CubbyFlow
18{
25template <size_t N>
27{
28 public:
30
31 class Builder;
32
35
38
40 ~PointKdTreeSearcher() override = default;
41
44
47
50
53
57 double maxSearchRadius) override;
58
68 const Vector<double, N>& origin, double radius,
69 const ForEachNearbyPointFunc& callback) const override;
70
81 double radius) const override;
82
89 [[nodiscard]] std::shared_ptr<PointNeighborSearcher<N>> Clone()
90 const override;
91
94
96 void Serialize(std::vector<uint8_t>* buffer) const override;
97
99 void Deserialize(const std::vector<uint8_t>& buffer) override;
100
103
104 private:
105 template <size_t M = N>
106 static std::enable_if_t<M == 2, void> Serialize(
107 const PointKdTreeSearcher<2>& searcher, std::vector<uint8_t>* buffer);
108
109 template <size_t M = N>
110 static std::enable_if_t<M == 3, void> Serialize(
111 const PointKdTreeSearcher<3>& searcher, std::vector<uint8_t>* buffer);
112
113 template <size_t M = N>
114 static std::enable_if_t<M == 2, void> Deserialize(
115 const std::vector<uint8_t>& buffer, PointKdTreeSearcher<2>& searcher);
116
117 template <size_t M = N>
118 static std::enable_if_t<M == 3, void> Deserialize(
119 const std::vector<uint8_t>& buffer, PointKdTreeSearcher<3>& searcher);
120
121 KdTree<double, N> m_tree;
122};
123
126
129
131using PointKdTreeSearcher2Ptr = std::shared_ptr<PointKdTreeSearcher2>;
132
134using PointKdTreeSearcher3Ptr = std::shared_ptr<PointKdTreeSearcher3>;
135
139template <size_t N>
142{
143 public:
145 Builder() = default;
146
148 ~Builder() override = default;
149
151 Builder(const Builder& other) = delete;
152
154 Builder(Builder&& other) noexcept = delete;
155
157 Builder& operator=(const Builder& other) = delete;
158
160 Builder& operator=(Builder&& other) noexcept = delete;
161
164
166 std::shared_ptr<PointKdTreeSearcher<N>> MakeShared() const;
167
169 std::shared_ptr<PointNeighborSearcher<N>> BuildPointNeighborSearcher()
170 const override;
171};
172} // namespace CubbyFlow
173
174#endif
#define CUBBYFLOW_NEIGHBOR_SEARCHER_TYPE_NAME(DerivedClassName, N)
Definition PointNeighborSearcher.hpp:163
Generic N-dimensional array class interface.
Definition ArrayView.hpp:26
Definition Matrix.hpp:30
Front-end to create PointKdTreeSearcher objects step by step.
Definition PointKdTreeSearcher.hpp:142
Builder & operator=(Builder &&other) noexcept=delete
Deleted move assignment operator.
std::shared_ptr< PointKdTreeSearcher< N > > MakeShared() const
Builds shared pointer of PointKdTreeSearcher instance.
~Builder() override=default
Default virtual destructor.
Builder(Builder &&other) noexcept=delete
Deleted move constructor.
Builder(const Builder &other)=delete
Deleted copy constructor.
PointKdTreeSearcher Build() const
Builds PointKdTreeSearcher instance.
Builder & operator=(const Builder &other)=delete
Deleted copy assignment operator.
Builder()=default
Default constructor.
std::shared_ptr< PointNeighborSearcher< N > > BuildPointNeighborSearcher() const override
Returns shared pointer of PointNeighborSearcher3 type.
KdTree-based N-D point searcher.
Definition PointKdTreeSearcher.hpp:27
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the neighbor searcher from the buffer.
PointKdTreeSearcher & operator=(const PointKdTreeSearcher &other)
Copy assignment operator.
bool HasNearbyPoint(const Vector< double, N > &origin, double radius) const override
PointKdTreeSearcher()=default
Constructs an empty kD-tree instance.
static Builder GetBuilder()
Returns builder fox PointKdTreeSearcher.
void Set(const PointKdTreeSearcher &other)
Copy from the other instance.
~PointKdTreeSearcher() override=default
Default virtual destructor.
PointKdTreeSearcher & operator=(PointKdTreeSearcher &&other) noexcept
Move assignment operator.
void Build(const ConstArrayView1< Vector< double, N > > &points, double maxSearchRadius) override
void ForEachNearbyPoint(const Vector< double, N > &origin, double radius, const ForEachNearbyPointFunc &callback) const override
PointKdTreeSearcher(const PointKdTreeSearcher &other)
Copy constructor.
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes the neighbor searcher into the buffer.
PointKdTreeSearcher(PointKdTreeSearcher &&other) noexcept
Move constructor.
std::shared_ptr< PointNeighborSearcher< N > > Clone() const override
Creates a new instance of the object with same properties than original.
Abstract base class for N-D point neighbor searcher builders.
Definition PointNeighborSearcher.hpp:120
Abstract base class for N-D neighbor point searcher.
Definition PointNeighborSearcher.hpp:33
std::function< void(size_t, const Vector< double, N > &)> ForEachNearbyPointFunc
Definition PointNeighborSearcher.hpp:38
Definition pybind11Utils.hpp:21
std::shared_ptr< PointKdTreeSearcher2 > PointKdTreeSearcher2Ptr
Shared pointer for the PointKdTreeSearcher2 type.
Definition PointKdTreeSearcher.hpp:131
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
std::shared_ptr< PointKdTreeSearcher3 > PointKdTreeSearcher3Ptr
Shared pointer for the PointKdTreeSearcher3 type.
Definition PointKdTreeSearcher.hpp:134