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 
14 #include <Core/Geometry/KdTree.hpp>
16 
17 namespace CubbyFlow
18 {
25 template <size_t N>
27 {
28  public:
30 
31  class Builder;
32 
35 
37  PointKdTreeSearcher() = default;
38 
40  ~PointKdTreeSearcher() override = default;
41 
44 
46  PointKdTreeSearcher(PointKdTreeSearcher&& other) noexcept;
47 
50 
53 
56  void Build(const ConstArrayView1<Vector<double, N>>& points,
57  double maxSearchRadius) override;
58 
67  void ForEachNearbyPoint(
68  const Vector<double, N>& origin, double radius,
69  const ForEachNearbyPointFunc& callback) const override;
70 
80  [[nodiscard]] bool HasNearbyPoint(const Vector<double, N>& origin,
81  double radius) const override;
82 
89  [[nodiscard]] std::shared_ptr<PointNeighborSearcher<N>> Clone()
90  const override;
91 
93  void Set(const PointKdTreeSearcher& other);
94 
96  void Serialize(std::vector<uint8_t>* buffer) const override;
97 
99  void Deserialize(const std::vector<uint8_t>& buffer) override;
100 
102  static Builder GetBuilder();
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 
131 using PointKdTreeSearcher2Ptr = std::shared_ptr<PointKdTreeSearcher2>;
132 
134 using PointKdTreeSearcher3Ptr = std::shared_ptr<PointKdTreeSearcher3>;
135 
139 template <size_t N>
141  : public PointNeighborSearcherBuilder<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 
163  PointKdTreeSearcher Build() const;
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
~PointKdTreeSearcher() override=default
Default virtual destructor.
std::shared_ptr< PointNeighborSearcher< N > > Clone() const override
Creates a new instance of the object with same properties than original.
Front-end to create PointKdTreeSearcher objects step by step.
Definition: PointKdTreeSearcher.hpp:140
Abstract base class for N-D point neighbor searcher builders.
Definition: PointNeighborSearcher.hpp:119
std::function< void(size_t, const Vector< double, N > &)> ForEachNearbyPointFunc
Definition: PointNeighborSearcher.hpp:38
Abstract base class for N-D neighbor point searcher.
Definition: PointNeighborSearcher.hpp:32
static Builder GetBuilder()
Returns builder fox PointKdTreeSearcher.
PointKdTreeSearcher & operator=(const PointKdTreeSearcher &other)
Copy assignment operator.
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
#define CUBBYFLOW_NEIGHBOR_SEARCHER_TYPE_NAME(DerivedClassName, N)
Definition: PointNeighborSearcher.hpp:163
std::shared_ptr< PointKdTreeSearcher2 > PointKdTreeSearcher2Ptr
Shared pointer for the PointKdTreeSearcher2 type.
Definition: PointKdTreeSearcher.hpp:131
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the neighbor searcher from the buffer.
void Build(const ConstArrayView1< Vector< double, N >> &points, double maxSearchRadius) override
PointKdTreeSearcher()=default
Constructs an empty kD-tree instance.
void Set(const PointKdTreeSearcher &other)
Copy from the other instance.
Generic N-dimensional array class interface.
Definition: Array.hpp:32
std::shared_ptr< PointKdTreeSearcher3 > PointKdTreeSearcher3Ptr
Shared pointer for the PointKdTreeSearcher3 type.
Definition: PointKdTreeSearcher.hpp:134
bool HasNearbyPoint(const Vector< double, N > &origin, double radius) const override
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes the neighbor searcher into the buffer.
void ForEachNearbyPoint(const Vector< double, N > &origin, double radius, const ForEachNearbyPointFunc &callback) const override
KdTree-based N-D point searcher.
Definition: PointKdTreeSearcher.hpp:26