MeshLib C++ Docs
Loading...
Searching...
No Matches
MRAABBTree.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRBox.h"
4#include "MRId.h"
5#include "MRVector.h"
6#include "MRMeshPart.h"
7
8namespace MR
9{
10
15
18
21{
22 Box3f box;
23 int first = 0;
24 int count = 0;
25 [[nodiscard]] bool leaf() const { return count < 0; }
26 [[nodiscard]] int numLeafTris() const { return -count; }
27};
28
35
39{
40public:
41 static constexpr int MaxChildren = 4;
42 static constexpr int MaxLeafTris = 4;
44 static constexpr int MaxDepth = 16;
45
48
50 [[nodiscard]] MRMESH_API explicit AABBTree( const MeshPart & mp );
51
54 [[nodiscard]] MRMESH_API explicit AABBTree( const TriMesh & tmesh, const FaceBitSet * region = nullptr );
55
56 AABBTree() = default;
57 AABBTree( AABBTree && ) noexcept = default;
58 AABBTree & operator =( AABBTree && ) noexcept = default;
59
61 [[nodiscard]] const Vector<Node, NodeId> & nodes() const { return nodes_; }
62
64 [[nodiscard]] Box3f getBoundingBox() const { return nodes_.empty() ? Box3f{} : nodes_.front().box; }
65
67 [[nodiscard]] const Vector<LeafTri> & leafTris() const { return leafTris_; }
68
70 [[nodiscard]] const Vector<Box3f> & leafBoxes() const { return leafBoxes_; }
71
73 [[nodiscard]] size_t heapBytes() const { return nodes_.heapBytes() + leafTris_.heapBytes() + leafBoxes_.heapBytes(); }
74
76 [[nodiscard]] MRMESH_API std::vector<NodeId> getSubtrees( int minNum ) const;
77
79 [[nodiscard]] MRMESH_API FaceBitSet getSubtreeFaces( NodeId subtreeRoot ) const;
80
82 [[nodiscard]] MRMESH_API NodeBitSet getNodesFromFaces( const FaceBitSet & faces ) const;
83
86 MRMESH_API void getLeafOrder( FaceBMap & faceMap ) const;
87
89 MRMESH_API void renumber( const FaceBMap & faceMap, const VertBMap & vertMap );
90
93 MRMESH_API void flipOrientation( const FaceBitSet * region = nullptr );
94
99 MRMESH_API void refit( const Mesh & mesh, const VertBitSet * changedVerts );
100
107 MRMESH_API void addSplitFaces( const Mesh & mesh, const FaceHashMap & new2Old );
108
109private:
110 AABBTree( const AABBTree & ) = default;
111 AABBTree & operator =( const AABBTree & ) = default;
112 friend class UniqueThreadSafeOwner<AABBTree>;
113 friend class SharedThreadSafeOwner<AABBTree>;
114
116 Vector<LeafTri> leafTris_;
117 Vector<Box3f> leafBoxes_;
118};
119
121
122}
#define MRMESH_API
Definition MRMeshFwd.h:85
static constexpr int MaxChildren
Definition MRAABBTree.h:41
const Vector< LeafTri > & leafTris() const
triangles of all leaves, the triangles of each leaf are contiguous
Definition MRAABBTree.h:67
static constexpr int MaxDepth
the deepest level of a node (the root is at 0): the stacks of the traversals are sized for it,...
Definition MRAABBTree.h:44
NodeBitSet getNodesFromFaces(const FaceBitSet &faces) const
returns the nodes having at least one of given triangles in their subtrees
FaceBitSet getSubtreeFaces(NodeId subtreeRoot) const
returns all triangles in the subtree with given root
AABBTree()=default
AABBTree(AABBTree &&) noexcept=default
Box3f getBoundingBox() const
returns the bounding box of the whole tree (empty for an empty tree)
Definition MRAABBTree.h:64
AABBTree(const TriMesh &tmesh, const FaceBitSet *region=nullptr)
AABBTreeWideNode Node
Definition MRAABBTree.h:46
AABBTree & operator=(AABBTree &&) noexcept=default
const Vector< Box3f > & leafBoxes() const
the bounding boxes of the triangles in the order of leafTris(), slightly expanded for robust searches
Definition MRAABBTree.h:70
std::vector< NodeId > getSubtrees(int minNum) const
returns at least given number of top-level not-intersecting subtrees, union of which contain all tree...
void flipOrientation(const FaceBitSet *region=nullptr)
const Vector< Node, NodeId > & nodes() const
the root is the first node, if any
Definition MRAABBTree.h:61
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRAABBTree.h:73
AABBTree(const MeshPart &mp)
creates tree for given mesh or its part
static constexpr int MaxLeafTris
Definition MRAABBTree.h:42
void refit(const Mesh &mesh, const VertBitSet *changedVerts)
AABBTreeWideLeafTri LeafTri
Definition MRAABBTree.h:47
void addSplitFaces(const Mesh &mesh, const FaceHashMap &new2Old)
void renumber(const FaceBMap &faceMap, const VertBMap &vertMap)
renumbers the triangles and their vertices after the mesh was packed with given maps from old to new ...
void getLeafOrder(FaceBMap &faceMap) const
Definition MRSharedThreadSafeOwner.h:19
Definition MRUniqueThreadSafeOwner.h:18
Vector<T> is indexed by size_t.
Definition MRVector.h:24
HashMap< FaceId, FaceId > FaceHashMap
Definition MRMeshFwd.h:636
std::array< VertId, 3 > ThreeVertIds
three vertex ids describing a triangle with the corners in vertices given by their ids
Definition MRMeshFwd.h:540
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
triangle in a leaf of AABBTree
Definition MRAABBTree.h:31
ThreeVertIds verts
in the order of mesh.topology.getTriVerts( face )
Definition MRAABBTree.h:33
FaceId face
Definition MRAABBTree.h:32
node of AABBTree (outside of the class to be default-constructible in its members)
Definition MRAABBTree.h:21
int first
the first child node, or for a leaf, the first of its triangles in leafTris()
Definition MRAABBTree.h:23
Box3f box
bounding box of whole subtree
Definition MRAABBTree.h:22
int count
the number of children, or for a leaf, minus the number of its triangles
Definition MRAABBTree.h:24
bool leaf() const
Definition MRAABBTree.h:25
int numLeafTris() const
Definition MRAABBTree.h:26
Definition MRMesh.h:24
Definition MRTriMesh.h:16