SPH
PointCloud.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "objects/geometry/Box.h"
5 #include <unordered_map>
6 
8 
13 class PointCloud : public Noncopyable {
14 private:
15  using Cell = Array<Vector>;
16  using HashMap = std::unordered_map<Indices, Cell, std::hash<Indices>, IndicesEqual>;
17 
18  HashMap map;
19  Size count = 0;
20  Float cellSize;
21 
22 public:
24  class Handle {
25  private:
26  Indices data;
27 
28  public:
29  Handle() = default;
30 
31  Handle(const Indices& idxs, const Size index, Badge<PointCloud>)
32  : data(idxs) {
33  data[3] = index;
34  }
35 
37  Indices coords() const {
38  return data;
39  }
40 
42  Size index() const {
43  return data[3];
44  }
45 
46  bool operator==(const Handle& other) const {
47  return all(coords() == other.coords()) && index() == other.index();
48  }
49 
50  bool operator!=(const Handle& other) const {
51  return !(*this == other);
52  }
53  };
54 
55  explicit PointCloud(const Float cellSize)
56  : cellSize(cellSize) {}
57 
61  Handle push(const Vector& p);
62 
64  void push(ArrayView<const Vector> points);
65 
67  Vector point(const Handle& handle) const;
68 
70  Array<Vector> array() const;
71 
73  Size size() const;
74 
76  Size getClosePointsCount(const Vector& center, const Float radius) const;
77 
79  void findClosePoints(const Vector& center, const Float radius, Array<Handle>& handles) const;
80 
82  void findClosePoints(const Vector& center, const Float radius, Array<Vector>& neighs) const;
83 
84 private:
85  template <typename TAdd>
86  void findClosePoints(const Vector& center, const Float radius, const TAdd& add) const;
87 
88  INLINE Box cellBox(const Indices& idxs) const {
89  return Box(Vector(idxs) * cellSize, Vector(idxs + Indices(1, 1, 1)) * cellSize);
90  }
91 };
92 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Object representing a three-dimensional axis-aligned box.
const float radius
Definition: CurveDialog.cpp:18
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
INLINE bool all(const Indices &i)
Definition: Indices.h:144
#define INLINE
Macros for conditional compilation based on selected compiler.
Definition: Object.h:31
#define NAMESPACE_SPH_END
Definition: Object.h:12
Object representing a three-dimensional sphere.
BasicVector< Float > Vector
Definition: Vector.h:539
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
Generic dynamically allocated resizable storage.
Definition: Array.h:43
Helper class used to allow calling a function only from within T.
Definition: Object.h:94
Helper object defining three-dimensional interval (box).
Definition: Box.h:17
Helper object for storing three (possibly four) int or bool values.
Definition: Indices.h:16
Identifies a point in the point cloud.
Definition: PointCloud.h:24
Indices coords() const
Grid coordinates.
Definition: PointCloud.h:37
bool operator==(const Handle &other) const
Definition: PointCloud.h:46
bool operator!=(const Handle &other) const
Definition: PointCloud.h:50
Size index() const
Index of the point within the cell.
Definition: PointCloud.h:42
Handle(const Indices &idxs, const Size index, Badge< PointCloud >)
Definition: PointCloud.h:31
Container of points with optimized search queries.
Definition: PointCloud.h:13
Size getClosePointsCount(const Vector &center, const Float radius) const
Returns the number of points within given distance from the center point.
Definition: PointCloud.cpp:37
Handle push(const Vector &p)
Adds a point into the cloud.
Definition: PointCloud.cpp:5
Size size() const
Returns the number of points in the cloud.
Definition: PointCloud.cpp:33
PointCloud(const Float cellSize)
Definition: PointCloud.h:55
Array< Vector > array() const
Returns all points in the cloud as array.
Definition: PointCloud.cpp:23
Vector point(const Handle &handle) const
Returns the point corresponding to given handle.
Definition: PointCloud.cpp:19
void findClosePoints(const Vector &center, const Float radius, Array< Handle > &handles) const
Returns point within given distance from the center point.
Definition: PointCloud.cpp:45
Object with deleted copy constructor and copy operator.
Definition: Object.h:54