| 18 | |
| 19 | template<class V, class Tree, class LeafProcessor> |
| 20 | VertId 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 | } |
no test coverage detected