Jet  v1.3.3
point_hash_grid_searcher3.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_SEARCHER3_H_
8 #define INCLUDE_JET_POINT_HASH_GRID_SEARCHER3_H_
9 
11 #include <jet/point3.h>
12 #include <jet/size3.h>
13 
14 #include <vector>
15 
16 namespace jet {
17 
26  public:
28 
29  class Builder;
30 
41  PointHashGridSearcher3(const Size3& resolution, double gridSpacing);
42 
56  size_t resolutionX,
57  size_t resolutionY,
58  size_t resolutionZ,
59  double gridSpacing);
60 
63 
65  void build(const ConstArrayAccessor1<Vector3D>& points) override;
66 
76  const Vector3D& origin,
77  double radius,
78  const ForEachNearbyPointFunc& callback) const override;
79 
90  const Vector3D& origin, double radius) const override;
91 
101  void add(const Vector3D& point);
102 
111  const std::vector<std::vector<size_t>>& buckets() const;
112 
120  size_t getHashKeyFromBucketIndex(const Point3I& bucketIndex) const;
121 
129  Point3I getBucketIndex(const Vector3D& position) const;
130 
138 
141 
143  void set(const PointHashGridSearcher3& other);
144 
146  void serialize(std::vector<uint8_t>* buffer) const override;
147 
149  void deserialize(const std::vector<uint8_t>& buffer) override;
150 
152  static Builder builder();
153 
154  private:
155  double _gridSpacing = 1.0;
156  Point3I _resolution = Point3I(1, 1, 1);
157  std::vector<Vector3D> _points;
158  std::vector<std::vector<size_t>> _buckets;
159 
160  size_t getHashKeyFromPosition(const Vector3D& position) const;
161 
162  void getNearbyKeys(const Vector3D& position, size_t* bucketIndices) const;
163 };
164 
166 typedef std::shared_ptr<PointHashGridSearcher3> PointHashGridSearcher3Ptr;
167 
173  public:
175  Builder& withResolution(const Size3& resolution);
176 
178  Builder& withGridSpacing(double gridSpacing);
179 
182 
185 
188 
189  private:
190  Size3 _resolution{64, 64, 64};
191  double _gridSpacing = 1.0;
192 };
193 
194 } // namespace jet
195 
196 #endif // INCLUDE_JET_POINT_HASH_GRID_SEARCHER3_H_
jet::ConstArrayAccessor< T, 1 >
1-D read-only array accessor class.
Definition: array_accessor1.h:184
jet::PointHashGridSearcher3::hasNearbyPoint
bool hasNearbyPoint(const Vector3D &origin, double radius) const override
jet::PointHashGridSearcher3::Builder
Front-end to create PointHashGridSearcher3 objects step by step.
Definition: point_hash_grid_searcher3.h:172
jet::PointHashGridSearcher3::Builder::build
PointHashGridSearcher3 build() const
Builds PointHashGridSearcher3 instance.
jet::PointHashGridSearcher3::operator=
PointHashGridSearcher3 & operator=(const PointHashGridSearcher3 &other)
Assignment operator.
jet::Point3I
Point3< ssize_t > Point3I
Integer-type 3D point.
Definition: point3.h:306
jet::PointHashGridSearcher3::getBucketIndex
Point3I getBucketIndex(const Vector3D &position) const
size3.h
jet::PointHashGridSearcher3::forEachNearbyPoint
void forEachNearbyPoint(const Vector3D &origin, double radius, const ForEachNearbyPointFunc &callback) const override
jet::PointHashGridSearcher3::clone
PointNeighborSearcher3Ptr clone() const override
Creates a new instance of the object with same properties than original.
jet::PointHashGridSearcher3Ptr
std::shared_ptr< PointHashGridSearcher3 > PointHashGridSearcher3Ptr
Shared pointer for the PointHashGridSearcher3 type.
Definition: point_hash_grid_searcher3.h:166
jet::PointHashGridSearcher3::set
void set(const PointHashGridSearcher3 &other)
Copy from the other instance.
jet::PointHashGridSearcher3::Builder::makeShared
PointHashGridSearcher3Ptr makeShared() const
Builds shared pointer of PointHashGridSearcher3 instance.
jet::PointHashGridSearcher3::Builder::withGridSpacing
Builder & withGridSpacing(double gridSpacing)
Returns builder with grid spacing.
point_neighbor_searcher3.h
jet::PointHashGridSearcher3::builder
static Builder builder()
Returns builder fox PointHashGridSearcher3.
point3.h
jet
Definition: advection_solver2.h:18
jet::PointHashGridSearcher3::PointHashGridSearcher3
PointHashGridSearcher3(size_t resolutionX, size_t resolutionY, size_t resolutionZ, double gridSpacing)
Constructs hash grid with given resolution and grid spacing.
jet::PointHashGridSearcher3::deserialize
void deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the neighbor searcher from the buffer.
jet::PointHashGridSearcher3::PointHashGridSearcher3
PointHashGridSearcher3(const Size3 &resolution, double gridSpacing)
Constructs hash grid with given resolution and grid spacing.
jet::PointHashGridSearcher3::getHashKeyFromBucketIndex
size_t getHashKeyFromBucketIndex(const Point3I &bucketIndex) const
jet::PointNeighborSearcher3
Abstract base class for 3-D neighbor point searcher.
Definition: point_neighbor_searcher3.h:28
jet::PointHashGridSearcher3::add
void add(const Vector3D &point)
Adds a single point to the hash grid.
jet::PointNeighborSearcher3::ForEachNearbyPointFunc
std::function< void(size_t, const Vector3D &)> ForEachNearbyPointFunc
Definition: point_neighbor_searcher3.h:33
jet::PointHashGridSearcher3::build
void build(const ConstArrayAccessor1< Vector3D > &points) override
Builds internal acceleration structure for given points list.
JET_NEIGHBOR_SEARCHER3_TYPE_NAME
#define JET_NEIGHBOR_SEARCHER3_TYPE_NAME(DerivedClassName)
Definition: point_neighbor_searcher3.h:95
jet::Size3
3-D size class.
Definition: size3.h:19
jet::Point< T, 3 >
3-D point class.
Definition: point3.h:23
jet::PointNeighborSearcher3Ptr
std::shared_ptr< PointNeighborSearcher3 > PointNeighborSearcher3Ptr
Shared pointer for the PointNeighborSearcher3 type.
Definition: point_neighbor_searcher3.h:82
jet::PointHashGridSearcher3::buckets
const std::vector< std::vector< size_t > > & buckets() const
Returns the internal bucket.
jet::Vector< T, 3 >
3-D vector class.
Definition: vector3.h:25
jet::PointHashGridSearcher3::Builder::withResolution
Builder & withResolution(const Size3 &resolution)
Returns builder with resolution.
jet::PointHashGridSearcher3
Hash grid-based 3-D point searcher.
Definition: point_hash_grid_searcher3.h:25
jet::PointNeighborSearcherBuilder3
Abstract base class for 3-D point neighbor searcher builders.
Definition: point_neighbor_searcher3.h:85
jet::PointHashGridSearcher3::serialize
void serialize(std::vector< uint8_t > *buffer) const override
Serializes the neighbor searcher into the buffer.
jet::PointHashGridSearcher3::Builder::buildPointNeighborSearcher
PointNeighborSearcher3Ptr buildPointNeighborSearcher() const override
Returns shared pointer of PointHashGridSearcher3 type.
jet::PointHashGridSearcher3::PointHashGridSearcher3
PointHashGridSearcher3(const PointHashGridSearcher3 &other)
Copy constructor.