PointParallelHashGridSearcher3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: PointParallelHashGridSearcher3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Parallel version of hash grid-based 3-D point searcher.
6 > Created Time: 2017/05/07
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_POINT_PARALLEL_HASH_GRID_SEARCHER3_H
10 #define CUBBYFLOW_POINT_PARALLEL_HASH_GRID_SEARCHER3_H
11 
13 #include <Core/Size/Size3.h>
14 
15 namespace CubbyFlow
16 {
25  {
26  public:
28 
29  class Builder;
30 
41  PointParallelHashGridSearcher3(const Size3& resolution, double gridSpacing);
42 
55  PointParallelHashGridSearcher3(size_t resolutionX, size_t resolutionY, size_t resolutionZ, double gridSpacing);
56 
59 
67  void Build(const ConstArrayAccessor1<Vector3D>& points) override;
68 
77  void ForEachNearbyPoint(const Vector3D& origin, double radius, const ForEachNearbyPointFunc& callback) const override;
78 
88  bool HasNearbyPoint(const Vector3D& origin, double radius) const override;
89 
98  const std::vector<size_t>& Keys() const;
99 
123  const std::vector<size_t>& StartIndexTable() const;
124 
148  const std::vector<size_t>& EndIndexTable() const;
149 
160  const std::vector<size_t>& SortedIndices() const;
161 
169  size_t GetHashKeyFromBucketIndex(const Point3I& bucketIndex) const;
170 
178  Point3I GetBucketIndex(const Vector3D& position) const;
179 
186  PointNeighborSearcher3Ptr Clone() const override;
187 
190 
192  void Set(const PointParallelHashGridSearcher3& other);
193 
195  void Serialize(std::vector<uint8_t>* buffer) const override;
196 
198  void Deserialize(const std::vector<uint8_t>& buffer) override;
199 
201  static Builder GetBuilder();
202 
203  private:
204  double m_gridSpacing = 1.0;
205  Point3I m_resolution = Point3I(1, 1, 1);
206  std::vector<Vector3D> m_points;
207  std::vector<size_t> m_keys;
208  std::vector<size_t> m_startIndexTable;
209  std::vector<size_t> m_endIndexTable;
210  std::vector<size_t> m_sortedIndices;
211 
212  size_t GetHashKeyFromPosition(const Vector3D& position) const;
213 
214  void GetNearbyKeys(const Vector3D& position, size_t* bucketIndices) const;
215  };
216 
218  using PointParallelHashGridSearcher3Ptr = std::shared_ptr<PointParallelHashGridSearcher3>;
219 
224  {
225  public:
227  Builder& WithResolution(const Size3& resolution);
228 
230  Builder& WithGridSpacing(double gridSpacing);
231 
234 
237 
240 
241  private:
242  Size3 m_resolution{ 64, 64, 64 };
243  double m_gridSpacing = 1.0;
244  };
245 }
246 
247 #endif
3-D vector class.
Definition: Vector3.h:26
std::function< void(size_t, const Vector3D &)> ForEachNearbyPointFunc
Definition: PointNeighborSearcher3.h:34
PointParallelHashGridSearcher3 Build() const
Builds PointParallelHashGridSearcher3 instance.
PointParallelHashGridSearcher3(const Size3 &resolution, double gridSpacing)
Constructs hash grid with given resolution and grid spacing.
const std::vector< size_t > & EndIndexTable() const
Returns the end index table.
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the neighbor searcher from the buffer.
std::shared_ptr< PointNeighborSearcher3 > PointNeighborSearcher3Ptr
Shared pointer for the PointNeighborSearcher3 type.
Definition: PointNeighborSearcher3.h:79
Point3I GetBucketIndex(const Vector3D &position) const
3-D point class.
Definition: Point3.h:26
size_t GetHashKeyFromBucketIndex(const Point3I &bucketIndex) const
PointParallelHashGridSearcher3 & operator=(const PointParallelHashGridSearcher3 &other)
Assignment operator.
PointParallelHashGridSearcher3Ptr MakeShared() const
Builds shared pointer of PointParallelHashGridSearcher3 instance.
void ForEachNearbyPoint(const Vector3D &origin, double radius, const ForEachNearbyPointFunc &callback) const override
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes the neighbor searcher into the buffer.
const std::vector< size_t > & Keys() const
Returns the hash key list.
Builder & WithGridSpacing(double gridSpacing)
Returns builder with grid spacing.
Definition: pybind11Utils.h:24
const std::vector< size_t > & StartIndexTable() const
Returns the start index table.
PointNeighborSearcher3Ptr Clone() const override
Creates a new instance of the object with same properties than original.
Abstract base class for 3-D point neighbor searcher builders.
Definition: PointNeighborSearcher3.h:82
PointNeighborSearcher3Ptr BuildPointNeighborSearcher() const override
Returns shared pointer of PointNeighborSearcher3 type.
Abstract base class for 3-D neighbor point searcher.
Definition: PointNeighborSearcher3.h:29
Front-end to create PointParallelHashGridSearcher3 objects step by step.
Definition: PointParallelHashGridSearcher3.h:223
Parallel version of hash grid-based 3-D point searcher.
Definition: PointParallelHashGridSearcher3.h:24
void Build(const ConstArrayAccessor1< Vector3D > &points) override
Builds internal acceleration structure for given points list.
static Builder GetBuilder()
Returns builder fox PointParallelHashGridSearcher3.
#define CUBBYFLOW_NEIGHBOR_SEARCHER3_TYPE_NAME(DerivedClassName)
Definition: PointNeighborSearcher3.h:94
Builder & WithResolution(const Size3 &resolution)
Returns builder with resolution.
const std::vector< size_t > & SortedIndices() const
Returns the sorted indices of the points.
std::shared_ptr< PointParallelHashGridSearcher3 > PointParallelHashGridSearcher3Ptr
Shared pointer for the PointParallelHashGridSearcher3 type.
Definition: PointParallelHashGridSearcher3.h:218
Point3< ssize_t > Point3I
Integer-type 3D point.
Definition: Point3.h:325
bool HasNearbyPoint(const Vector3D &origin, double radius) const override
void Set(const PointParallelHashGridSearcher3 &other)
Copy from the other instance.