Loading...
Searching...
No Matches
PointHashGridSearcher.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_HASH_GRID_SEARCHER_HPP
12#define CUBBYFLOW_POINT_HASH_GRID_SEARCHER_HPP
13
14#include <Core/Array/Array.hpp>
17#include <Core/Utils/Macros.hpp>
18
19namespace CubbyFlow
20{
28template <size_t N>
30{
31 public:
33
34 class Builder;
35
38
50 double gridSpacing);
51
53 ~PointHashGridSearcher() override = default;
54
57
60
63
66
70 double maxSearchRadius) override;
71
81 const Vector<double, N>& origin, double radius,
82 const ForEachNearbyPointFunc& callback) const override;
83
94 double radius) const override;
95
105 void Add(const Vector<double, N>& point);
106
116
123 [[nodiscard]] std::shared_ptr<PointNeighborSearcher<N>> Clone()
124 const override;
125
128
130 void Serialize(std::vector<uint8_t>* buffer) const override;
131
133 void Deserialize(const std::vector<uint8_t>& buffer) override;
134
137
138 private:
139 template <size_t M = N>
143
144 template <size_t M = N>
148
149 template <size_t M = N>
153
154 template <size_t M = N>
158
159 double m_gridSpacing = 1.0;
160 Vector<ssize_t, N> m_resolution = Vector<ssize_t, N>::MakeConstant(1);
161 Array1<Vector<double, N>> m_points;
162 Array1<Array1<size_t>> m_buckets;
163};
164
167
170
173
176
180template <size_t N>
183{
184 public:
186 Builder() = default;
187
189 ~Builder() override = default;
190
192 Builder(const Builder& other) = delete;
193
195 Builder(Builder&& other) noexcept = delete;
196
198 Builder& operator=(const Builder& other) = delete;
199
201 Builder& operator=(Builder&& other) noexcept = delete;
202
205
208
211
213 std::shared_ptr<PointHashGridSearcher<N>> MakeShared() const;
214
216 std::shared_ptr<PointNeighborSearcher<N>> BuildPointNeighborSearcher()
217 const override;
218
219 private:
221 double m_gridSpacing = 1.0;
222};
223} // namespace CubbyFlow
224
225#endif
#define CUBBYFLOW_REQUIRES(...)
Definition Macros.hpp:81
#define CUBBYFLOW_NEIGHBOR_SEARCHER_TYPE_NAME(DerivedClassName, N)
Definition PointNeighborSearcher.hpp:163
Definition Array.hpp:36
Generic N-dimensional array class interface.
Definition ArrayView.hpp:26
static std::enable_if_t< IsMatrixSizeStatic< Rows, Cols >(), D > MakeConstant(ValueType val)
Makes a static matrix with constant entries.
Definition MatrixDenseBase-Impl.hpp:152
Definition Matrix.hpp:30
Front-end to create PointHashGridSearcher objects step by step.
Definition PointHashGridSearcher.hpp:183
PointHashGridSearcher< N > Build() const
Builds PointHashGridSearcher instance.
Builder & WithResolution(const Vector< size_t, N > &resolution)
Returns builder with resolution.
Builder()=default
Default constructor.
~Builder() override=default
Default virtual destructor.
Builder & operator=(Builder &&other) noexcept=delete
Deleted move assignment operator.
Builder(Builder &&other) noexcept=delete
Deleted move constructor.
std::shared_ptr< PointHashGridSearcher< N > > MakeShared() const
Builds shared pointer of PointHashGridSearcher instance.
std::shared_ptr< PointNeighborSearcher< N > > BuildPointNeighborSearcher() const override
Returns shared pointer of PointNeighborSearcher3 type.
Builder & operator=(const Builder &other)=delete
Deleted copy assignment operator.
Builder(const Builder &other)=delete
Deleted copy constructor.
Builder & WithGridSpacing(double gridSpacing)
Returns builder with grid spacing.
Hash grid-based N-D point searcher.
Definition PointHashGridSearcher.hpp:30
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
const Array1< Array1< size_t > > & Buckets() const
Returns the internal bucket.
PointHashGridSearcher(const PointHashGridSearcher &other)
Copy constructor.
PointHashGridSearcher & operator=(PointHashGridSearcher &&other) noexcept
Move assignment operator.
PointHashGridSearcher(PointHashGridSearcher &&other) noexcept
Move constructor.
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
PointHashGridSearcher(const Vector< size_t, N > &resolution, double gridSpacing)
Constructs hash grid with given resolution and grid spacing.
void Add(const Vector< double, N > &point)
Adds a single point to the hash grid.
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes the neighbor searcher into the buffer.
~PointHashGridSearcher() override=default
Default virtual destructor.
void Set(const PointHashGridSearcher &other)
Copy from the other instance.
PointHashGridSearcher & operator=(const PointHashGridSearcher &other)
Copy assignment operator.
void ForEachNearbyPoint(const Vector< double, N > &origin, double radius, const ForEachNearbyPointFunc &callback) const override
static Builder GetBuilder()
Returns builder fox PointHashGridSearcher.
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:22
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:719
std::shared_ptr< PointHashGridSearcher3 > PointHashGridSearcher3Ptr
Shared pointer for the PointHashGridSearcher3 type.
Definition PointHashGridSearcher.hpp:175
std::shared_ptr< PointHashGridSearcher2 > PointHashGridSearcher2Ptr
Shared pointer for the PointHashGridSearcher2 type.
Definition PointHashGridSearcher.hpp:172