SPH
PointCloud.cpp
Go to the documentation of this file.
2 
4 
6  const Indices idxs = floor(p / cellSize);
7  Cell& cell = map[idxs];
8  cell.push(p);
9  count++;
10  return Handle(idxs, cell.size() - 1, {});
11 }
12 
14  for (const Vector& p : points) {
15  this->push(p);
16  }
17 }
18 
19 Vector PointCloud::point(const Handle& handle) const {
20  return map.at(handle.coords())[handle.index()];
21 }
22 
24  Array<Vector> result;
25  for (const auto& cell : map) {
26  for (const Vector& p : cell.second) {
27  result.push(p);
28  }
29  }
30  return result;
31 }
32 
34  return count;
35 }
36 
38  Size count = 0;
39  this->findClosePoints(center, radius, [&count](const Handle& UNUSED(handle)) { //
40  ++count;
41  });
42  return count;
43 }
44 
45 void PointCloud::findClosePoints(const Vector& center, const Float radius, Array<Handle>& handles) const {
46  handles.clear();
47  this->findClosePoints(center, radius, [&handles](const Handle& handle) { //
48  handles.push(handle);
49  });
50 }
51 
52 void PointCloud::findClosePoints(const Vector& center, const Float radius, Array<Vector>& neighs) const {
53  neighs.clear();
54  this->findClosePoints(center, radius, [this, &neighs](const Handle& handle) { //
55  neighs.push(point(handle));
56  });
57 }
58 
59 
60 template <typename TAdd>
61 void PointCloud::findClosePoints(const Vector& center, const Float radius, const TAdd& add) const {
62  const Sphere search(center, radius);
63  const Indices idxs0 = floor(center / cellSize);
64 
65  Indices left = idxs0;
66  Indices right = idxs0;
67  for (Size i = 0; i < 3; ++i) {
68  Indices next = idxs0;
69  while (true) {
70  next[i]++;
71  if (search.overlaps(cellBox(next))) {
72  right[i] = next[i];
73  } else {
74  break;
75  }
76  }
77 
78  next = idxs0;
79  while (true) {
80  next[i]--;
81  if (search.overlaps(cellBox(next))) {
82  left[i] = next[i];
83  } else {
84  break;
85  }
86  }
87  }
88 
89  for (int z = left[2]; z <= right[2]; ++z) {
90  for (int y = left[1]; y <= right[1]; ++y) {
91  for (int x = left[0]; x <= right[0]; ++x) {
92  const Indices idxs(x, y, z);
93  const auto iter = map.find(idxs);
94  if (iter == map.end()) {
95  continue;
96  }
97 
98  for (Size i = 0; i < iter->second.size(); ++i) {
99  const Vector& p = iter->second[i];
100  const Float distSqr = getSqrLength(p - center);
101  if (distSqr < sqr(radius)) {
102  add(Handle(idxs, i, {}));
103  }
104  }
105  }
106  }
107  }
108 }
109 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
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
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
Definition: MathUtils.h:67
INLINE auto floor(const T &f)
Definition: MathUtils.h:346
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
INLINE Float getSqrLength(const Vector &v)
Definition: Vector.h:574
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
Generic dynamically allocated resizable storage.
Definition: Array.h:43
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
Definition: Array.h:306
void clear()
Removes all elements from the array, but does NOT release the memory.
Definition: Array.h:434
INLINE TCounter size() const noexcept
Definition: Array.h:193
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
Size index() const
Index of the point within the cell.
Definition: PointCloud.h:42
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
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
Definition: Sphere.h:18