MeshLib C++ Docs
Loading...
Searching...
No Matches
MRAABBTreePoints.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 "MRVector3.h"
7
8namespace MR
9{
10
13
15class AABBTreePoints
16{
17public:
18 struct Node
19 {
24 bool leaf() const { return !l.valid(); }
26 std::pair<int, int> getLeafPointRange() const { assert( leaf() ); return { -( l + 1 ),-( r + 1 ) }; }
28 void setLeafPointRange( int first, int last ) { l = NodeId( -( first + 1 ) ); r = NodeId( -( last + 1 ) ); }
29 };
30 using NodeVec = Vector<Node, NodeId>;
31 using NodeBitSet = TaggedBitSet<NodeTag>;
32 [[nodiscard]] const NodeVec& nodes() const { return nodes_; }
33 [[nodiscard]] const Node& operator[]( NodeId nid ) const { return nodes_[nid]; }
34 [[nodiscard]] static NodeId rootNodeId() { return NodeId{0}; }
36 [[nodiscard]] Box3f getBoundingBox() const { return nodes_.empty() ? Box3f{} : nodes_[rootNodeId()].box; }
37
38 struct Point
39 {
42 };
43 [[nodiscard]] const std::vector<Point>& orderedPoints() const { return orderedPoints_; }
44
46 MRMESH_API AABBTreePoints( const PointCloud& pointCloud );
48 MRMESH_API AABBTreePoints( const Mesh& mesh );
50 MRMESH_API AABBTreePoints( const VertCoords & points, const VertBitSet * validPoints = nullptr );
51
54 MR_BIND_IGNORE AABBTreePoints( const VertCoords & points, const VertBitSet & validPoints ) : AABBTreePoints( points, &validPoints ) {}
55
57 constexpr static int MaxNumPointsInLeaf = 16;
58
59 AABBTreePoints( AABBTreePoints && ) noexcept = default;
60 AABBTreePoints & operator =( AABBTreePoints && ) noexcept = default;
61
64 MRMESH_API void getLeafOrder( VertBMap & vertMap ) const;
68 MRMESH_API void getLeafOrderAndReset( VertBMap & vertMap );
69
71 [[nodiscard]] MRMESH_API size_t heapBytes() const;
72
77 MRMESH_API void refit( const VertCoords & newCoords, const VertBitSet & changedVerts );
78
79private:
80 std::vector<Point> orderedPoints_;
81 NodeVec nodes_;
82
83 AABBTreePoints( const AABBTreePoints & ) = default;
84 AABBTreePoints & operator =( const AABBTreePoints & ) = default;
85 friend class UniqueThreadSafeOwner<AABBTreePoints>;
86 friend class SharedThreadSafeOwner<AABBTreePoints>;
87};
88
89// returns the number of nodes in the binary tree with given number of points
90inline int getNumNodesPoints( int numPoints )
91{
92 assert( numPoints > 0 );
93 return 2 * ( ( numPoints + AABBTreePoints::MaxNumPointsInLeaf - 1 ) / AABBTreePoints::MaxNumPointsInLeaf ) - 1;
94}
95
97
98} // namespace MR
#define MRMESH_API
Definition MRMeshFwd.h:80
Definition MRAABBTreePoints.h:16
unsafe void refit(MR.Const_VertCoords newCoords, MR.Const_VertBitSet changedVerts)
unsafe AABBTreePoints(MR._ByValue_AABBTreePoints _other)
unsafe void getLeafOrderAndReset(MR.VertBMap vertMap)
Definition MRMesh/MRMesh.h:23
Definition MRMesh/MRPointCloud.h:17
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:19
bool empty() const
Definition MRVector.h:49
int getNumNodesPoints(int numPoints)
Definition MRAABBTreePoints.h:90
Definition MRCameraOrientationPlugin.h:8
Definition MRAABBTreePoints.h:19
void setLeafPointRange(int first, int last)
sets [first,last) to this node (leaf)
Definition MRAABBTreePoints.h:28
Box3f box
bounding box of whole subtree
Definition MRAABBTreePoints.h:20
std::pair< int, int > getLeafPointRange() const
returns [first,last) indices of leaf points
Definition MRAABBTreePoints.h:26
bool leaf() const
returns true if node represent real points, false if it has child nodes
Definition MRAABBTreePoints.h:24
NodeId r
Definition MRAABBTreePoints.h:22
NodeId l
left child node for an inner node, or -(l+1) is the index of the first point in a leaf node
Definition MRAABBTreePoints.h:21
Definition MRAABBTreePoints.h:39
Vector3f coord
Definition MRAABBTreePoints.h:40
VertId id
Definition MRAABBTreePoints.h:41
readonly unsafe bool valid()