PointParallelHashGridSearcher2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: PointParallelHashGridSearcher2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Parallel version of hash grid-based 2-D point searcher.
6 > Created Time: 2017/04/30
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_POINT_PARALLEL_HASH_GRID_SEARCHER2_H
10 #define CUBBYFLOW_POINT_PARALLEL_HASH_GRID_SEARCHER2_H
11 
13 #include <Core/Size/Size2.h>
14 
15 namespace CubbyFlow
16 {
25  {
26  public:
28 
29  class Builder;
30 
41  PointParallelHashGridSearcher2(const Size2& resolution, double gridSpacing);
42 
54  PointParallelHashGridSearcher2(size_t resolutionX, size_t resolutionY, double gridSpacing);
55 
58 
66  void Build(const ConstArrayAccessor1<Vector2D>& points) override;
67 
76  void ForEachNearbyPoint(const Vector2D& origin, double radius, const ForEachNearbyPointFunc& callback) const override;
77 
87  bool HasNearbyPoint(const Vector2D& origin, double radius) const override;
88 
97  const std::vector<size_t>& Keys() const;
98 
122  const std::vector<size_t>& StartIndexTable() const;
123 
147  const std::vector<size_t>& EndIndexTable() const;
148 
159  const std::vector<size_t>& SortedIndices() const;
160 
168  size_t GetHashKeyFromBucketIndex(const Point2I& bucketIndex) const;
169 
177  Point2I GetBucketIndex(const Vector2D& position) const;
178 
185  PointNeighborSearcher2Ptr Clone() const override;
186 
189 
191  void Set(const PointParallelHashGridSearcher2& other);
192 
194  void Serialize(std::vector<uint8_t>* buffer) const override;
195 
197  void Deserialize(const std::vector<uint8_t>& buffer) override;
198 
200  static Builder GetBuilder();
201 
202  private:
203  double m_gridSpacing = 1.0;
204  Point2I m_resolution = Point2I(1, 1);
205  std::vector<Vector2D> m_points;
206  std::vector<size_t> m_keys;
207  std::vector<size_t> m_startIndexTable;
208  std::vector<size_t> m_endIndexTable;
209  std::vector<size_t> m_sortedIndices;
210 
211  size_t GetHashKeyFromPosition(const Vector2D& position) const;
212 
213  void GetNearbyKeys(const Vector2D& position, size_t* bucketIndices) const;
214  };
215 
217  using PointParallelHashGridSearcher2Ptr = std::shared_ptr<PointParallelHashGridSearcher2>;
218 
223  {
224  public:
226  Builder& WithResolution(const Size2& resolution);
227 
229  Builder& WithGridSpacing(double gridSpacing);
230 
233 
236 
239 
240  private:
241  Size2 m_resolution{ 64, 64 };
242  double m_gridSpacing = 1.0;
243  };
244 }
245 
246 #endif
Builder & WithResolution(const Size2 &resolution)
Returns builder with resolution.
Builder & WithGridSpacing(double gridSpacing)
Returns builder with grid spacing.
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes the neighbor searcher into the buffer.
PointParallelHashGridSearcher2 Build() const
Builds PointParallelHashGridSearcher2 instance.
size_t GetHashKeyFromBucketIndex(const Point2I &bucketIndex) const
PointParallelHashGridSearcher2(const Size2 &resolution, double gridSpacing)
Constructs hash grid with given resolution and grid spacing.
const std::vector< size_t > & SortedIndices() const
Returns the sorted indices of the points.
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the neighbor searcher from the buffer.
Point2< ssize_t > Point2I
Integer-type 2D point.
Definition: Point2.h:312
const std::vector< size_t > & EndIndexTable() const
Returns the end index table.
2-D point class.
Definition: Point2.h:25
std::function< void(size_t, const Vector2D &)> ForEachNearbyPointFunc
Definition: PointNeighborSearcher2.h:34
#define CUBBYFLOW_NEIGHBOR_SEARCHER2_TYPE_NAME(DerivedClassName)
Definition: PointNeighborSearcher2.h:94
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
bool HasNearbyPoint(const Vector2D &origin, double radius) const override
Abstract base class for 2-D point neighbor searcher builders.
Definition: PointNeighborSearcher2.h:82
Definition: pybind11Utils.h:24
Abstract base class for 2-D neighbor point searcher.
Definition: PointNeighborSearcher2.h:29
PointParallelHashGridSearcher2Ptr MakeShared() const
Builds shared pointer of PointParallelHashGridSearcher2 instance.
const std::vector< size_t > & StartIndexTable() const
Returns the start index table.
PointNeighborSearcher2Ptr Clone() const override
Creates a new instance of the object with same properties than original.
PointParallelHashGridSearcher2 & operator=(const PointParallelHashGridSearcher2 &other)
Assignment operator.
void Build(const ConstArrayAccessor1< Vector2D > &points) override
Builds internal acceleration structure for given points list.
void ForEachNearbyPoint(const Vector2D &origin, double radius, const ForEachNearbyPointFunc &callback) const override
Point2I GetBucketIndex(const Vector2D &position) const
2-D vector class.
Definition: Vector2.h:26
std::shared_ptr< PointNeighborSearcher2 > PointNeighborSearcher2Ptr
Shared pointer for the PointNeighborSearcher2 type.
Definition: PointNeighborSearcher2.h:79
const std::vector< size_t > & Keys() const
Returns the hash key list.
void Set(const PointParallelHashGridSearcher2 &other)
Copy from the other instance.
static Builder GetBuilder()
Returns builder fox PointParallelHashGridSearcher2.
PointNeighborSearcher2Ptr BuildPointNeighborSearcher() const override
Returns shared pointer of PointNeighborSearcher3 type.
Front-end to create PointParallelHashGridSearcher2 objects step by step.
Definition: PointParallelHashGridSearcher2.h:222
Parallel version of hash grid-based 2-D point searcher.
Definition: PointParallelHashGridSearcher2.h:24
std::shared_ptr< PointParallelHashGridSearcher2 > PointParallelHashGridSearcher2Ptr
Shared pointer for the PointParallelHashGridSearcher2 type.
Definition: PointParallelHashGridSearcher2.h:217