17 #include <shared_mutex>
41 template <
typename TBase>
53 : TBase(
KdNode::Type(-1)) {}
60 template <
typename TBase>
80 static_assert(
sizeof(
Size) ==
sizeof(
float),
"Sizes must match to keep this layout");
135 template <
typename TNode,
typename TMetric = Eucl
ideanMetric>
153 std::atomic_int nodeCounter;
154 std::shared_timed_mutex nodesMutex;
156 static constexpr
Size ROOT_PARENT_NODE = -1;
165 template <
bool FindAll>
170 return nodes[nodeIdx];
175 return nodes[nodeIdx];
203 const Size slidingCnt,
210 bool isSingular(
const Size from,
const Size to,
const Size splitIdx)
const;
212 bool checkBoxes(
const Size from,
const Size to,
const Size mid,
const Box& box1,
const Box& box2)
const;
231 template <IterateDirection Dir,
typename TNode,
typename TMetric,
typename TFunctor>
234 const TFunctor& functor,
235 const Size nodeIdx = 0,
239 template <IterateDirection Dir,
typename TNode,
typename TMetric,
typename TFunctor>
242 const TFunctor& functor,
243 const Size nodeIdx = 0,
#define SPH_ASSERT(x,...)
Object representing a three-dimensional axis-aligned box.
Wraps a functor and executes it once the wrapper goes out of scope.
Generic wrappers of lambdas, functors and other callables.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Helper objects allowing to iterate in reverse, iterate over multiple containeres, etc.
@ BOTTOM_UP
From leaves to root.
@ TOP_DOWN
From root to leaves.
void iterateTree(KdTree< TNode, TMetric > &tree, IScheduler &scheduler, const TFunctor &functor, const Size nodeIdx=0, const Size depthLimit=Size(-1))
Calls a functor for every node of a K-d tree tree in specified direction.
Logging routines of the run.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
Return value of function that may fail, containing either SUCCEES (true) or error message.
Template for thread-local storage.
INLINE Float getSqrLength(const Vector &v)
INLINE TCounter size() const
INLINE TCounter size() const noexcept
Helper object defining three-dimensional interval (box).
Helper template, allowing to define all three functions with a single function.
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
K-d tree, used for hierarchical clustering of particles and accelerated Kn queries.
INLINE TNode & getNode(const Size nodeIdx)
Returns the node with given index.
virtual void buildImpl(IScheduler &scheduler, ArrayView< const Vector > points) override
Builds finder from set of vectors.
INLINE const TNode & getNode(const Size nodeIdx) const
Returns the node with given index.
INLINE LeafIndexSequence getLeafIndices(const LeafNode< TNode > &leaf) const
Returns the sequence of particles indices belonging to given leaf.
KdTree(const Size leafSize=25, const Size maxParallelDepth=50)
Size find(const Vector &pos, const Size index, const Float radius, Array< NeighbourRecord > &neighs) const
Size leafSize
Maximal number of particles in the leaf node.
Outcome sanityCheck() const
Performs some checks of KdTree consistency, returns SUCCESS if everything is OK.
INLINE Size getNodeCnt() const
Returns the number of nodes in the tree.
Size maxParallelDepth
Maximal depth for which the build is parallelized.
Index iterator with given mapping (index permutation).
INLINE Size operator*() const
INLINE LeafIndexIterator(const Size idx, ArrayView< const Size > mapping)
Helper index sequence to iterate over particle indices of a leaf node.
INLINE LeafIndexIterator end() const
INLINE LeafIndexIterator begin() const
INLINE LeafIndexSequence(const Size from, const Size to, ArrayView< const Size > mapping)
INLINE Float operator()(const Vector &v) const
InnerNode(const KdNode::Type &type)
Size right
Index of right child node.
Size left
Index of left child node.
float splitPosition
Position where the selected dimension is split.
Base class for nodes of K-d tree.
Type
Here X, Y, Z must be 0, 1, 2.
INLINE bool isLeaf() const
Box box
Bounding box of particles in the node.
Leaf (bucket) node of K-d tree.
Size to
One-past-last index of particles belonging to the leaf.
LeafNode(const KdNode::Type &type)
INLINE Size size() const
Returns the number of points in the leaf. Can be zero.
Size from
First index of particlse belonging to the leaf.
Size padding
Unused, used so that LeafNode and InnerNode have the same size.
Object with deleted copy constructor and copy operator.