Jet  v1.3.3
point_hash_grid_searcher2.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_POINT_HASH_GRID_SEARCHER2_H_
8 #define INCLUDE_JET_POINT_HASH_GRID_SEARCHER2_H_
9 
11 #include <jet/point2.h>
12 #include <jet/size2.h>
13 
14 #include <vector>
15 
16 namespace jet {
17 
26  public:
28 
29  class Builder;
30 
41  PointHashGridSearcher2(const Size2& resolution, double gridSpacing);
42 
55  size_t resolutionX,
56  size_t resolutionY,
57  double gridSpacing);
58 
61 
63  void build(const ConstArrayAccessor1<Vector2D>& points) override;
64 
74  const Vector2D& origin,
75  double radius,
76  const ForEachNearbyPointFunc& callback) const override;
77 
88  const Vector2D& origin, double radius) const override;
89 
99  void add(const Vector2D& point);
100 
109  const std::vector<std::vector<size_t>>& buckets() const;
110 
118  size_t getHashKeyFromBucketIndex(const Point2I& bucketIndex) const;
119 
127  Point2I getBucketIndex(const Vector2D& position) const;
128 
136 
139 
141  void set(const PointHashGridSearcher2& other);
142 
144  void serialize(std::vector<uint8_t>* buffer) const override;
145 
147  void deserialize(const std::vector<uint8_t>& buffer) override;
148 
150  static Builder builder();
151 
152  private:
153  double _gridSpacing = 1.0;
154  Point2I _resolution = Point2I(1, 1);
155  std::vector<Vector2D> _points;
156  std::vector<std::vector<size_t>> _buckets;
157 
158  size_t getHashKeyFromPosition(const Vector2D& position) const;
159 
160  void getNearbyKeys(const Vector2D& position, size_t* bucketIndices) const;
161 };
162 
164 typedef std::shared_ptr<PointHashGridSearcher2> PointHashGridSearcher2Ptr;
165 
171  public:
173  Builder& withResolution(const Size2& resolution);
174 
176  Builder& withGridSpacing(double gridSpacing);
177 
180 
183 
186 
187  private:
188  Size2 _resolution{64, 64};
189  double _gridSpacing = 1.0;
190 };
191 
192 } // namespace jet
193 
194 #endif // INCLUDE_JET_POINT_HASH_GRID_SEARCHER2_H_
jet::Point< T, 2 >
2-D point class.
Definition: point2.h:23
jet::PointHashGridSearcher2::deserialize
void deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the neighbor searcher from the buffer.
jet::PointHashGridSearcher2::hasNearbyPoint
bool hasNearbyPoint(const Vector2D &origin, double radius) const override
jet::Point2I
Point2< ssize_t > Point2I
Integer-type 2D point.
Definition: point2.h:298
JET_NEIGHBOR_SEARCHER2_TYPE_NAME
#define JET_NEIGHBOR_SEARCHER2_TYPE_NAME(DerivedClassName)
Definition: point_neighbor_searcher2.h:95
jet::PointHashGridSearcher2::add
void add(const Vector2D &point)
Adds a single point to the hash grid.
jet::ConstArrayAccessor< T, 1 >
1-D read-only array accessor class.
Definition: array_accessor1.h:184
point_neighbor_searcher2.h
jet::PointHashGridSearcher2
Hash grid-based 2-D point searcher.
Definition: point_hash_grid_searcher2.h:25
jet::PointNeighborSearcher2Ptr
std::shared_ptr< PointNeighborSearcher2 > PointNeighborSearcher2Ptr
Shared pointer for the PointNeighborSearcher2 type.
Definition: point_neighbor_searcher2.h:82
jet::PointHashGridSearcher2::PointHashGridSearcher2
PointHashGridSearcher2(const PointHashGridSearcher2 &other)
Copy constructor.
jet::PointHashGridSearcher2::forEachNearbyPoint
void forEachNearbyPoint(const Vector2D &origin, double radius, const ForEachNearbyPointFunc &callback) const override
size2.h
jet::PointHashGridSearcher2::Builder::buildPointNeighborSearcher
PointNeighborSearcher2Ptr buildPointNeighborSearcher() const override
Returns shared pointer of PointNeighborSearcher3 type.
jet::PointHashGridSearcher2::buckets
const std::vector< std::vector< size_t > > & buckets() const
Returns the internal bucket.
jet::PointHashGridSearcher2::build
void build(const ConstArrayAccessor1< Vector2D > &points) override
Builds internal acceleration structure for given points list.
jet::PointHashGridSearcher2Ptr
std::shared_ptr< PointHashGridSearcher2 > PointHashGridSearcher2Ptr
Shared pointer for the PointHashGridSearcher2 type.
Definition: point_hash_grid_searcher2.h:164
jet::PointHashGridSearcher2::Builder
Front-end to create PointHashGridSearcher2 objects step by step.
Definition: point_hash_grid_searcher2.h:170
jet::PointHashGridSearcher2::serialize
void serialize(std::vector< uint8_t > *buffer) const override
Serializes the neighbor searcher into the buffer.
jet
Definition: advection_solver2.h:18
jet::PointHashGridSearcher2::Builder::build
PointHashGridSearcher2 build() const
Builds PointHashGridSearcher2 instance.
jet::PointHashGridSearcher2::Builder::withGridSpacing
Builder & withGridSpacing(double gridSpacing)
Returns builder with grid spacing.
jet::Vector< T, 2 >
2-D vector class.
Definition: vector2.h:24
jet::PointHashGridSearcher2::builder
static Builder builder()
Returns builder fox PointHashGridSearcher2.
jet::PointHashGridSearcher2::PointHashGridSearcher2
PointHashGridSearcher2(size_t resolutionX, size_t resolutionY, double gridSpacing)
Constructs hash grid with given resolution and grid spacing.
jet::PointNeighborSearcher2::ForEachNearbyPointFunc
std::function< void(size_t, const Vector2D &)> ForEachNearbyPointFunc
Definition: point_neighbor_searcher2.h:33
jet::PointHashGridSearcher2::PointHashGridSearcher2
PointHashGridSearcher2(const Size2 &resolution, double gridSpacing)
Constructs hash grid with given resolution and grid spacing.
jet::PointNeighborSearcherBuilder2
Abstract base class for 2-D point neighbor searcher builders.
Definition: point_neighbor_searcher2.h:85
jet::PointHashGridSearcher2::set
void set(const PointHashGridSearcher2 &other)
Copy from the other instance.
jet::Size2
2-D size class.
Definition: size2.h:19
jet::PointHashGridSearcher2::getBucketIndex
Point2I getBucketIndex(const Vector2D &position) const
jet::PointHashGridSearcher2::operator=
PointHashGridSearcher2 & operator=(const PointHashGridSearcher2 &other)
Assignment operator.
jet::PointHashGridSearcher2::Builder::withResolution
Builder & withResolution(const Size2 &resolution)
Returns builder with resolution.
jet::PointNeighborSearcher2
Abstract base class for 2-D neighbor point searcher.
Definition: point_neighbor_searcher2.h:28
jet::PointHashGridSearcher2::clone
PointNeighborSearcher2Ptr clone() const override
Creates a new instance of the object with same properties than original.
jet::PointHashGridSearcher2::getHashKeyFromBucketIndex
size_t getHashKeyFromBucketIndex(const Point2I &bucketIndex) const
jet::PointHashGridSearcher2::Builder::makeShared
PointHashGridSearcher2Ptr makeShared() const
Builds shared pointer of PointHashGridSearcher2 instance.
point2.h