@@ -101,6 +101,14 @@ namespace geode
101101 index_t element_end,
102102 ACTION& action ) const ;
103103
104+ template < typename ACTION >
105+ bool triangle_intersect_recursive (
106+ const Triangle< dimension >& triangle,
107+ index_t node_index,
108+ index_t element_begin,
109+ index_t element_end,
110+ ACTION& action ) const ;
111+
104112 template < typename ACTION >
105113 bool self_intersect_recursive ( index_t node_index1,
106114 index_t element_begin1,
@@ -228,6 +236,19 @@ namespace geode
228236 line, Impl::ROOT_INDEX, 0 , nb_bboxes (), action );
229237 }
230238
239+ template < index_t dimension >
240+ template < class EvalIntersection >
241+ void AABBTree< dimension >::compute_triangle_element_bbox_intersections(
242+ const Triangle< dimension >& triangle, EvalIntersection& action ) const
243+ {
244+ if ( nb_bboxes () == 0 )
245+ {
246+ return ;
247+ }
248+ impl_->triangle_intersect_recursive (
249+ triangle, Impl::ROOT_INDEX, 0 , nb_bboxes (), action );
250+ }
251+
231252 template < index_t dimension >
232253 template < class EvalIntersection >
233254 void AABBTree< dimension >::compute_segment_element_bbox_intersections(
@@ -350,6 +371,41 @@ namespace geode
350371 box, it.child_right , it.middle_box , element_end, action );
351372 }
352373
374+ template < index_t dimension >
375+ template < typename ACTION >
376+ bool AABBTree< dimension >::Impl::triangle_intersect_recursive(
377+ const Triangle< dimension >& triangle,
378+ index_t node_index,
379+ index_t element_begin,
380+ index_t element_end,
381+ ACTION& action ) const
382+ {
383+ OPENGEODE_ASSERT ( node_index < tree_.size (), " Node out of tree range" );
384+ OPENGEODE_ASSERT (
385+ element_begin != element_end, " No iteration allowed start == end" );
386+
387+ // Prune sub-tree that does not have intersection
388+ if ( !node ( node_index ).intersects ( triangle ) )
389+ {
390+ return false ;
391+ }
392+
393+ if ( is_leaf ( element_begin, element_end ) )
394+ {
395+ return action ( mapping_morton ( element_begin ) );
396+ }
397+
398+ const auto it =
399+ get_recursive_iterators ( node_index, element_begin, element_end );
400+ if ( triangle_intersect_recursive ( triangle, it.child_left ,
401+ element_begin, it.middle_box , action ) )
402+ {
403+ return true ;
404+ }
405+ return triangle_intersect_recursive (
406+ triangle, it.child_right , it.middle_box , element_end, action );
407+ }
408+
353409 template < index_t dimension >
354410 template < typename ACTION >
355411 bool AABBTree< dimension >::Impl::self_intersect_recursive(
0 commit comments