MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / findDirMaxT

Function findDirMaxT

source/MRMesh/MRDirMax.cpp:20–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19template<class V, class Tree, class LeafProcessor>
20VertId findDirMaxT( const V & dir, const Tree & tree, LeafProcessor && lp )
21{
22 VertId res;
23 if ( tree.nodes().empty() )
24 return res;
25
26 struct SubTask
27 {
28 NoInitNodeId n;
29 float furthestBoxProj;
30 };
31
32 const auto maxCorner = Box<V>::getMaxBoxCorner( dir );
33
34 InplaceStack<SubTask, 32> subtasks;
35 float furthestProj = -FLT_MAX;
36
37 auto addSubTask = [&]( const SubTask & s )
38 {
39 if ( s.furthestBoxProj > furthestProj )
40 subtasks.push( s );
41 };
42
43 auto getSubTask = [&]( NodeId n )
44 {
45 return SubTask { n, dot( dir, tree.nodes()[n].box.corner( maxCorner ) ) };
46 };
47
48 addSubTask( getSubTask( tree.rootNodeId() ) );
49
50 while ( !subtasks.empty() )
51 {
52 const auto s = subtasks.top();
53 subtasks.pop();
54 const auto & node = tree[s.n];
55 if ( s.furthestBoxProj < furthestProj )
56 continue;
57
58 if ( node.leaf() )
59 {
60 lp( node, furthestProj, res );
61 continue;
62 }
63
64 auto s1 = getSubTask( node.l );
65 auto s2 = getSubTask( node.r );
66 // add task with larger projection on line last to descend there first
67 if ( s1.furthestBoxProj > s2.furthestBoxProj )
68 {
69 addSubTask( s2 );
70 addSubTask( s1 );
71 }
72 else
73 {
74 addSubTask( s1 );
75 addSubTask( s2 );
76 }
77 }

Callers 1

findDirMaxFunction · 0.85

Calls 12

findDirMaxBruteForceFunction · 0.85
rootNodeIdMethod · 0.80
leafIdMethod · 0.80
dotFunction · 0.70
emptyMethod · 0.45
pushMethod · 0.45
cornerMethod · 0.45
popMethod · 0.45
leafMethod · 0.45
getAABBTreeNotCreateMethod · 0.45
orgMethod · 0.45
destMethod · 0.45

Tested by

no test coverage detected