MeshLib C++ Docs
Loading...
Searching...
No Matches
MRAABBTreeBase.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRAABBTreeNode.h"
4#include "MRVector.h"
5
6namespace MR
7{
10
11
13template <typename T>
15{
16public:
17 using Traits = T;
20 using LeafTag = typename T::LeafTag;
21 using LeafId = typename T::LeafId;
22 using LeafBitSet = TaggedBitSet<LeafTag>;
24 using BoxT = typename T::BoxT;
27
28public:
30 [[nodiscard]] const NodeVec & nodes() const { return nodes_; }
31
33 [[nodiscard]] const Node & operator[]( NodeId nid ) const { return nodes_[nid]; }
34
36 [[nodiscard]] const Leaves & leaves() const { return leaves_; }
37
39 [[nodiscard]] static bool isLeaf( NodeId n ) { return Node::isLeaf( n ); }
40
42 [[nodiscard]] const Leaf & leaf( NodeId n ) const { return leaves_[Node::leafIndex( n )]; }
43
45 [[nodiscard]] LeafId leafId( NodeId n ) const { return leaf( n ).leafId; }
46
48 [[nodiscard]] const BoxT & box( NodeId n ) const { return isLeaf( n ) ? leaf( n ).box : nodes_[n].box; }
49
51 [[nodiscard]] bool empty() const { return leaves_.empty(); }
52
55 [[nodiscard]] NodeId rootNodeId() const { assert( !empty() ); return nodes_.empty() ? Node::leafChild( 0 ) : NodeId( 0 ); }
56
58 [[nodiscard]] BoxT getBoundingBox() const { return empty() ? BoxT{} : box( rootNodeId() ); }
59
61 [[nodiscard]] size_t heapBytes() const { return nodes_.heapBytes() + leaves_.capacity() * sizeof( Leaf ); }
62
64 [[nodiscard]] size_t numLeaves() const { return leaves_.size(); }
65
67 [[nodiscard]] MRMESH_API std::vector<NodeId> getSubtrees( int minNum ) const;
68
70 [[nodiscard]] MRMESH_API LeafBitSet getSubtreeLeaves( NodeId subtreeRoot ) const;
71
73 [[nodiscard]] MRMESH_API NodeBitSet getNodesFromLeaves( const LeafBitSet & leaves ) const;
74
77 MRMESH_API void getLeafOrder( LeafBMap & leafMap ) const;
78
82
83protected:
86
89};
90
91}
#define MRMESH_API
Definition MRMeshFwd.h:85
#define MRMESH_CLASS
Definition MRMeshFwd.h:92
base class for the AABB-trees of polylines and objects
Definition MRAABBTreeBase.h:15
Vector<T> is indexed by size_t.
Definition MRVector.h:24
NodeVec nodes_
Definition MRAABBTreeBase.h:87
NodeBitSet getNodesFromLeaves(const LeafBitSet &leaves) const
returns set of not-leaf nodes containing among direct or indirect children given leaves
void getLeafOrderAndReset(LeafBMap &leafMap)
Leaves leaves_
Definition MRAABBTreeBase.h:88
typename T::BoxT BoxT
Definition MRAABBTreeBase.h:24
size_t numLeaves() const
returns the number of leaves in whole tree
Definition MRAABBTreeBase.h:64
AABBTreeNode< Traits > Node
Definition MRAABBTreeBase.h:18
const NodeVec & nodes() const
const-access to all not-leaf nodes, a tree with N leaves has N-1 nodes
Definition MRAABBTreeBase.h:30
void getLeafOrder(LeafBMap &leafMap) const
T Traits
Definition MRAABBTreeBase.h:17
BMap< LeafId, LeafId > LeafBMap
Definition MRAABBTreeBase.h:23
Vector< Node, NodeId > NodeVec
Definition MRAABBTreeBase.h:19
typename T::LeafTag LeafTag
Definition MRAABBTreeBase.h:20
std::vector< NodeId > getSubtrees(int minNum) const
returns at least given number of top-level not-intersecting subtrees (some can be leaves),...
const Leaves & leaves() const
all leaves in the order of the tree right after its construction
Definition MRAABBTreeBase.h:36
BoxedLeaf< T > Leaf
Definition MRAABBTreeBase.h:25
Vector< Leaf > Leaves
Definition MRAABBTreeBase.h:26
void build_(Vector< BoxedLeaf< T > > leaves)
builds the tree from given leaves with their boxes
TaggedBitSet< LeafTag > LeafBitSet
Definition MRAABBTreeBase.h:22
LeafBitSet getSubtreeLeaves(NodeId subtreeRoot) const
returns all leaves in the subtree with given root (can be a leaf)
LeafId leafId(NodeId n) const
returns the id of the leaf encoded in given node id
Definition MRAABBTreeBase.h:45
BoxT getBoundingBox() const
returns the root node bounding box
Definition MRAABBTreeBase.h:58
const BoxT & box(NodeId n) const
returns the bounding box of given node or leaf
Definition MRAABBTreeBase.h:48
const Leaf & leaf(NodeId n) const
returns the leaf encoded in given node id
Definition MRAABBTreeBase.h:42
NodeId rootNodeId() const
Definition MRAABBTreeBase.h:55
const Node & operator[](NodeId nid) const
const-access to any not-leaf node
Definition MRAABBTreeBase.h:33
static bool isLeaf(NodeId n)
returns true if given node id is in fact a leaf (encoded as negative number)
Definition MRAABBTreeBase.h:39
bool empty() const
returns true if the tree has no leaves
Definition MRAABBTreeBase.h:51
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRAABBTreeBase.h:61
typename T::LeafId LeafId
Definition MRAABBTreeBase.h:21
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
static size_t leafIndex(NodeId child)
returns the index in the vector of leaves of the leaf encoded in given child of a node
Definition MRAABBTreeNode.h:44
static NodeId leafChild(size_t leafIndex)
encodes given index in the vector of leaves as a child of a node
Definition MRAABBTreeNode.h:46
static bool isLeaf(NodeId child)
returns true if given child of a node is a leaf rather than another node
Definition MRAABBTreeNode.h:42
Definition MRAABBTreeNode.h:51
flat map: I -> T
Definition MRBuffer.h:148
a leaf of AABB-tree: the id of an object (e.g. face) with its bounding box
Definition MRAABBTreeNode.h:30