PointHashGridSearcher3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: PointHashGridSearcher3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Hash grid-based 3-D point searcher.
6 > Created Time: 2017/05/23
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_POINT_HASH_GRID_SEARCHER3_H
10 #define CUBBYFLOW_POINT_HASH_GRID_SEARCHER3_H
11 
13 #include <Core/Size/Size3.h>
14 
15 #include <vector>
16 
17 namespace CubbyFlow
18 {
27  {
28  public:
30 
31  class Builder;
32 
43  PointHashGridSearcher3(const Size3& resolution, double gridSpacing);
44 
57  PointHashGridSearcher3(size_t resolutionX, size_t resolutionY, size_t resolutionZ, double gridSpacing);
58 
61 
63  void Build(const ConstArrayAccessor1<Vector3D>& points) override;
64 
73  void ForEachNearbyPoint(
74  const Vector3D& origin,
75  double radius,
76  const ForEachNearbyPointFunc& callback) const override;
77 
87  bool HasNearbyPoint(const Vector3D& origin, double radius) const override;
88 
98  void Add(const Vector3D& point);
99 
108  const std::vector<std::vector<size_t>>& GetBuckets() const;
109 
117  size_t GetHashKeyFromBucketIndex(const Point3I& bucketIndex) const;
118 
126  Point3I GetBucketIndex(const Vector3D& position) const;
127 
134  PointNeighborSearcher3Ptr Clone() const override;
135 
138 
140  void Set(const PointHashGridSearcher3& other);
141 
143  void Serialize(std::vector<uint8_t>* buffer) const override;
144 
146  void Deserialize(const std::vector<uint8_t>& buffer) override;
147 
149  static Builder GetBuilder();
150 
151  private:
152  double m_gridSpacing = 1.0;
153  Point3I m_resolution = Point3I(1, 1, 1);
154  std::vector<Vector3D> m_points;
155  std::vector<std::vector<size_t>> m_buckets;
156 
157  size_t GetHashKeyFromPosition(const Vector3D& position) const;
158 
159  void GetNearbyKeys(const Vector3D& position, size_t* nearbyKeys) const;
160  };
161 
163  using PointHashGridSearcher3Ptr = std::shared_ptr<PointHashGridSearcher3>;
164 
169  {
170  public:
172  Builder& WithResolution(const Size3& resolution);
173 
175  Builder& WithGridSpacing(double gridSpacing);
176 
179 
182 
185 
186  private:
187  Size3 m_resolution{ 64, 64, 64 };
188  double m_gridSpacing = 1.0;
189  };
190 }
191 
192 #endif
3-D vector class.
Definition: Vector3.h:26
void ForEachNearbyPoint(const Vector3D &origin, double radius, const ForEachNearbyPointFunc &callback) const override
std::function< void(size_t, const Vector3D &)> ForEachNearbyPointFunc
Definition: PointNeighborSearcher3.h:34
void Build(const ConstArrayAccessor1< Vector3D > &points) override
Builds internal acceleration structure for given points list.
std::shared_ptr< PointNeighborSearcher3 > PointNeighborSearcher3Ptr
Shared pointer for the PointNeighborSearcher3 type.
Definition: PointNeighborSearcher3.h:79
PointNeighborSearcher3Ptr Clone() const override
Creates a new instance of the object with same properties than original.
Builder & WithGridSpacing(double gridSpacing)
Returns builder with grid spacing.
3-D point class.
Definition: Point3.h:26
PointHashGridSearcher3 Build() const
Builds PointHashGridSearcher3 instance.
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
const std::vector< std::vector< size_t > > & GetBuckets() const
Returns the internal bucket.
PointHashGridSearcher3Ptr MakeShared() const
Builds shared pointer of PointHashGridSearcher3 instance.
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes the neighbor searcher into the buffer.
bool HasNearbyPoint(const Vector3D &origin, double radius) const override
PointHashGridSearcher3 & operator=(const PointHashGridSearcher3 &other)
Assignment operator.
Definition: pybind11Utils.h:24
Builder & WithResolution(const Size3 &resolution)
Returns builder with resolution.
void Add(const Vector3D &point)
Adds a single point to the hash grid.
Point3I GetBucketIndex(const Vector3D &position) const
Abstract base class for 3-D point neighbor searcher builders.
Definition: PointNeighborSearcher3.h:82
Hash grid-based 3-D point searcher.
Definition: PointHashGridSearcher3.h:26
Abstract base class for 3-D neighbor point searcher.
Definition: PointNeighborSearcher3.h:29
size_t GetHashKeyFromBucketIndex(const Point3I &bucketIndex) const
Front-end to create PointHashGridSearcher3 objects step by step.
Definition: PointHashGridSearcher3.h:168
#define CUBBYFLOW_NEIGHBOR_SEARCHER3_TYPE_NAME(DerivedClassName)
Definition: PointNeighborSearcher3.h:94
PointNeighborSearcher3Ptr BuildPointNeighborSearcher() const override
Returns shared pointer of PointHashGridSearcher3 type.
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the neighbor searcher from the buffer.
static Builder GetBuilder()
Returns builder fox PointHashGridSearcher3.
std::shared_ptr< PointHashGridSearcher3 > PointHashGridSearcher3Ptr
Shared pointer for the PointHashGridSearcher3 type.
Definition: PointHashGridSearcher3.h:163
Point3< ssize_t > Point3I
Integer-type 3D point.
Definition: Point3.h:325
void Set(const PointHashGridSearcher3 &other)
Copy from the other instance.
PointHashGridSearcher3(const Size3 &resolution, double gridSpacing)
Constructs hash grid with given resolution and grid spacing.