PointSimpleListSearcher.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_SIMPLE_LIST_SEARCHER_HPP
12 #define CUBBYFLOW_POINT_SIMPLE_LIST_SEARCHER_HPP
13 
15 
16 namespace CubbyFlow
17 {
25 template <size_t N>
27 {
28  public:
30 
31  class Builder;
32 
35 
37  PointSimpleListSearcher() = default;
38 
40  ~PointSimpleListSearcher() override = default;
41 
44 
47 
50 
53  PointSimpleListSearcher&& other) noexcept;
54 
65  void Build(const ConstArrayView1<Vector<double, N>>& points,
66  double maxSearchRadius) override;
67 
76  void ForEachNearbyPoint(
77  const Vector<double, N>& origin, double radius,
78  const ForEachNearbyPointFunc& callback) const override;
79 
89  [[nodiscard]] bool HasNearbyPoint(const Vector<double, N>& origin,
90  double radius) const override;
91 
98  [[nodiscard]] std::shared_ptr<PointNeighborSearcher<N>> Clone()
99  const override;
100 
102  void Set(const PointSimpleListSearcher& other);
103 
105  void Serialize(std::vector<uint8_t>* buffer) const override;
106 
108  void Deserialize(const std::vector<uint8_t>& buffer) override;
109 
111  static Builder GetBuilder();
112 
113  private:
114  template <size_t M = N>
115  static std::enable_if_t<M == 2, void> Serialize(
116  const PointSimpleListSearcher<2>& searcher,
117  std::vector<uint8_t>* buffer);
118 
119  template <size_t M = N>
120  static std::enable_if_t<M == 3, void> Serialize(
121  const PointSimpleListSearcher<3>& searcher,
122  std::vector<uint8_t>* buffer);
123 
124  template <size_t M = N>
125  static std::enable_if_t<M == 2, void> Deserialize(
126  const std::vector<uint8_t>& buffer,
127  PointSimpleListSearcher<2>& searcher);
128 
129  template <size_t M = N>
130  static std::enable_if_t<M == 3, void> Deserialize(
131  const std::vector<uint8_t>& buffer,
132  PointSimpleListSearcher<3>& searcher);
133 
134  Array1<Vector<double, N>> m_points;
135 };
136 
139 
142 
144 using PointSimpleListSearcher2Ptr = std::shared_ptr<PointSimpleListSearcher<2>>;
145 
147 using PointSimpleListSearcher3Ptr = std::shared_ptr<PointSimpleListSearcher<3>>;
148 
152 template <size_t N>
154  : public PointNeighborSearcherBuilder<N>
155 {
156  public:
158  Builder() = default;
159 
161  ~Builder() override = default;
162 
164  Builder(const Builder& other) = delete;
165 
167  Builder(Builder&& other) noexcept = delete;
168 
170  Builder& operator=(const Builder& other) = delete;
171 
173  Builder& operator=(Builder&& other) noexcept = delete;
174 
177 
179  std::shared_ptr<PointSimpleListSearcher<N>> MakeShared() const;
180 
182  std::shared_ptr<PointNeighborSearcher<N>> BuildPointNeighborSearcher()
183  const override;
184 };
185 } // namespace CubbyFlow
186 
187 #endif
void ForEachNearbyPoint(const Vector< double, N > &origin, double radius, const ForEachNearbyPointFunc &callback) const override
PointSimpleListSearcher & operator=(const PointSimpleListSearcher &other)
Copy assignment operator.
void Build(const ConstArrayView1< Vector< double, N >> &points, double maxSearchRadius) override
Builds internal structure for given points list and max search radius.
std::shared_ptr< PointSimpleListSearcher< 3 > > PointSimpleListSearcher3Ptr
Shared pointer for the PointSimpleListSearcher3 type.
Definition: PointSimpleListSearcher.hpp:147
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
bool HasNearbyPoint(const Vector< double, N > &origin, double radius) const override
Abstract base class for N-D neighbor point searcher.
Definition: PointNeighborSearcher.hpp:32
Definition: Matrix.hpp:27
~PointSimpleListSearcher() override=default
Default virtual destructor.
void Set(const PointSimpleListSearcher &other)
Copy from the other instance.
Front-end to create PointSimpleListSearcher objects step by step.
Definition: PointSimpleListSearcher.hpp:153
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
#define CUBBYFLOW_NEIGHBOR_SEARCHER_TYPE_NAME(DerivedClassName, N)
Definition: PointNeighborSearcher.hpp:163
Simple ad-hoc N-D point searcher.
Definition: PointSimpleListSearcher.hpp:26
PointSimpleListSearcher()=default
Default constructor.
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the neighbor searcher from the buffer.
std::shared_ptr< PointNeighborSearcher< N > > Clone() const override
Creates a new instance of the object with same properties than original.
std::shared_ptr< PointSimpleListSearcher< 2 > > PointSimpleListSearcher2Ptr
Shared pointer for the PointSimpleListSearcher2 type.
Definition: PointSimpleListSearcher.hpp:144
Generic N-dimensional array class interface.
Definition: Array.hpp:32
static Builder GetBuilder()
Returns builder fox PointSimpleListSearcher.
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes the neighbor searcher into the buffer.