PointParallelHashGridSearcher.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_PARALLEL_HASH_GRID_SEARCHER_HPP
12 #define CUBBYFLOW_POINT_PARALLEL_HASH_GRID_SEARCHER_HPP
13 
14 #include <Core/Matrix/Matrix.hpp>
16 
17 namespace CubbyFlow
18 {
26 template <size_t N>
28 {
29  public:
31 
32  class Builder;
33 
36 
48  double gridSpacing);
49 
51  ~PointParallelHashGridSearcher() override = default;
52 
55 
58  PointParallelHashGridSearcher&& other) noexcept;
59 
62  const PointParallelHashGridSearcher& other);
63 
66  PointParallelHashGridSearcher&& other) noexcept;
67 
75  void Build(const ConstArrayView1<Vector<double, N>>& points) override;
76 
86  void Build(const ConstArrayView1<Vector<double, N>>& points,
87  double maxSearchRadius) override;
88 
97  void ForEachNearbyPoint(
98  const Vector<double, N>& origin, double radius,
99  const ForEachNearbyPointFunc& callback) const override;
100 
110  [[nodiscard]] bool HasNearbyPoint(const Vector<double, N>& origin,
111  double radius) const override;
112 
121  [[nodiscard]] ConstArrayView1<size_t> Keys() const;
122 
146  [[nodiscard]] ConstArrayView1<size_t> StartIndexTable() const;
147 
171  [[nodiscard]] ConstArrayView1<size_t> EndIndexTable() const;
172 
183  [[nodiscard]] ConstArrayView1<size_t> SortedIndices() const;
184 
191  [[nodiscard]] std::shared_ptr<PointNeighborSearcher<N>> Clone()
192  const override;
193 
195  void Set(const PointParallelHashGridSearcher& other);
196 
198  void Serialize(std::vector<uint8_t>* buffer) const override;
199 
201  void Deserialize(const std::vector<uint8_t>& buffer) override;
202 
204  static Builder GetBuilder();
205 
206  private:
208 
209  template <size_t M = N>
210  static std::enable_if_t<M == 2, void> Serialize(
211  const PointParallelHashGridSearcher<2>& searcher,
212  std::vector<uint8_t>* buffer);
213 
214  template <size_t M = N>
215  static std::enable_if_t<M == 3, void> Serialize(
216  const PointParallelHashGridSearcher<3>& searcher,
217  std::vector<uint8_t>* buffer);
218 
219  template <size_t M = N>
220  static std::enable_if_t<M == 2, void> Deserialize(
221  const std::vector<uint8_t>& buffer,
223 
224  template <size_t M = N>
225  static std::enable_if_t<M == 3, void> Deserialize(
226  const std::vector<uint8_t>& buffer,
228 
229  double m_gridSpacing = 1.0;
231  Array1<Vector<double, N>> m_points;
232  Array1<size_t> m_keys;
233  Array1<size_t> m_startIndexTable;
234  Array1<size_t> m_endIndexTable;
235  Array1<size_t> m_sortedIndices;
236 };
237 
240 
243 
246  std::shared_ptr<PointParallelHashGridSearcher2>;
247 
250  std::shared_ptr<PointParallelHashGridSearcher3>;
251 
256 template <size_t N>
258  : public PointNeighborSearcherBuilder<N>
259 {
260  public:
262  Builder() = default;
263 
265  ~Builder() override = default;
266 
268  Builder(const Builder& other) = delete;
269 
271  Builder(Builder&& other) noexcept = delete;
272 
274  Builder& operator=(const Builder& other) = delete;
275 
277  Builder& operator=(Builder&& other) noexcept = delete;
278 
280  Builder& WithResolution(const Vector<size_t, N>& resolution);
281 
283  Builder& WithGridSpacing(double gridSpacing);
284 
287 
289  std::shared_ptr<PointParallelHashGridSearcher<N>> MakeShared() const;
290 
292  std::shared_ptr<PointNeighborSearcher<N>> BuildPointNeighborSearcher()
293  const override;
294 
295  private:
297  double m_gridSpacing = 1.0;
298 };
299 } // namespace CubbyFlow
300 
301 #endif
ConstArrayView1< size_t > SortedIndices() const
Returns the sorted indices of the points.
static Builder GetBuilder()
Returns builder fox PointParallelHashGridSearcher.
friend class PointParallelHashGridSearcherTests
Definition: PointParallelHashGridSearcher.hpp:207
Abstract base class for N-D point neighbor searcher builders.
Definition: PointNeighborSearcher.hpp:119
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes the neighbor searcher into the buffer.
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the neighbor searcher from the buffer.
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
Parallel version of hash grid-based N-D point searcher.
Definition: PointParallelHashGridSearcher.hpp:27
void ForEachNearbyPoint(const Vector< double, N > &origin, double radius, const ForEachNearbyPointFunc &callback) const override
Definition: Matrix.hpp:27
static std::enable_if_t< IsMatrixSizeStatic< Rows, Cols >), D > MakeConstant(ValueType val)
Makes a static matrix with constant entries.
Definition: MatrixDenseBase-Impl.hpp:152
Front-end to create PointParallelHashGridSearcher objects step by step.
Definition: PointParallelHashGridSearcher.hpp:257
ConstArrayView1< size_t > StartIndexTable() const
Returns the start index table.
Definition: pybind11Utils.hpp:20
void Build(const ConstArrayView1< Vector< double, N >> &points) override
Builds internal acceleration structure for given points list.
Definition: Array-Impl.hpp:19
ConstArrayView1< size_t > Keys() const
Returns the hash key list.
#define CUBBYFLOW_NEIGHBOR_SEARCHER_TYPE_NAME(DerivedClassName, N)
Definition: PointNeighborSearcher.hpp:163
void Set(const PointParallelHashGridSearcher &other)
Copy from the other instance.
~PointParallelHashGridSearcher() override=default
Default virtual destructor.
ConstArrayView1< size_t > EndIndexTable() const
Returns the end index table.
PointParallelHashGridSearcher & operator=(const PointParallelHashGridSearcher &other)
Copy assignment operator.
Generic N-dimensional array class interface.
Definition: Array.hpp:32
std::shared_ptr< PointNeighborSearcher< N > > Clone() const override
Creates a new instance of the object with same properties than original.
bool HasNearbyPoint(const Vector< double, N > &origin, double radius) const override
std::shared_ptr< PointParallelHashGridSearcher3 > PointParallelHashGridSearcher3Ptr
Shared pointer for the PointParallelHashGridSearcher3 type.
Definition: PointParallelHashGridSearcher.hpp:250
std::shared_ptr< PointParallelHashGridSearcher2 > PointParallelHashGridSearcher2Ptr
Shared pointer for the PointParallelHashGridSearcher2 type.
Definition: PointParallelHashGridSearcher.hpp:246
PointParallelHashGridSearcher(const Vector< size_t, N > &resolution, double gridSpacing)
Constructs hash grid with given resolution and grid spacing.