Skip to content

Commit a1a90e6

Browse files
yo35BotellaA
authored andcommitted
Re-impl existing queries with the generic one
1 parent d8424ea commit a1a90e6

File tree

1 file changed

+20
-176
lines changed

1 file changed

+20
-176
lines changed

include/geode/geometry/detail/aabb_impl.hpp

Lines changed: 20 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -260,104 +260,6 @@ namespace geode
260260
}
261261
}
262262

263-
template < typename ACTION >
264-
bool bbox_intersect_recursive( const BoundingBox< dimension >& box,
265-
index_t node_index,
266-
index_t element_begin,
267-
index_t element_end,
268-
index_t depth,
269-
ACTION& action ) const
270-
271-
{
272-
OPENGEODE_ASSERT(
273-
node_index < tree_.size(), "Node out of tree range" );
274-
OPENGEODE_ASSERT( element_begin != element_end,
275-
"No iteration allowed start == end" );
276-
277-
// Prune sub-tree that does not have intersection
278-
if( !box.intersects( node( node_index ) ) )
279-
{
280-
return false;
281-
}
282-
283-
if( is_leaf( element_begin, element_end ) )
284-
{
285-
return action( mapping_morton( element_begin ) );
286-
}
287-
288-
const auto it = get_recursive_iterators(
289-
node_index, element_begin, element_end );
290-
if( depth > async_depth_ )
291-
{
292-
if( bbox_intersect_recursive( box, it.child_left, element_begin,
293-
it.element_middle, depth + 1, action ) )
294-
{
295-
return true;
296-
}
297-
return bbox_intersect_recursive( box, it.child_right,
298-
it.element_middle, element_end, depth + 1, action );
299-
}
300-
auto task = async::local_spawn( [&] {
301-
return bbox_intersect_recursive( box, it.child_left,
302-
element_begin, it.element_middle, depth + 1, action );
303-
} );
304-
if( bbox_intersect_recursive( box, it.child_right,
305-
it.element_middle, element_end, depth + 1, action ) )
306-
{
307-
return true;
308-
}
309-
return task.get();
310-
}
311-
312-
template < typename ACTION >
313-
bool triangle_intersect_recursive(
314-
const Triangle< dimension >& triangle,
315-
index_t node_index,
316-
index_t element_begin,
317-
index_t element_end,
318-
index_t depth,
319-
ACTION& action ) const
320-
{
321-
OPENGEODE_ASSERT(
322-
node_index < tree_.size(), "Node out of tree range" );
323-
OPENGEODE_ASSERT( element_begin != element_end,
324-
"No iteration allowed start == end" );
325-
326-
// Prune sub-tree that does not have intersection
327-
if( !node( node_index ).intersects( triangle ) )
328-
{
329-
return false;
330-
}
331-
332-
if( is_leaf( element_begin, element_end ) )
333-
{
334-
return action( mapping_morton( element_begin ) );
335-
}
336-
337-
const auto it = get_recursive_iterators(
338-
node_index, element_begin, element_end );
339-
if( depth > async_depth_ )
340-
{
341-
if( triangle_intersect_recursive( triangle, it.child_left,
342-
element_begin, it.element_middle, depth + 1, action ) )
343-
{
344-
return true;
345-
}
346-
return triangle_intersect_recursive( triangle, it.child_right,
347-
it.element_middle, element_end, depth + 1, action );
348-
}
349-
auto task = async::local_spawn( [&] {
350-
return triangle_intersect_recursive( triangle, it.child_left,
351-
element_begin, it.element_middle, depth + 1, action );
352-
} );
353-
if( triangle_intersect_recursive( triangle, it.child_right,
354-
it.element_middle, element_end, depth + 1, action ) )
355-
{
356-
return true;
357-
}
358-
return task.get();
359-
}
360-
361263
template < typename ACTION >
362264
bool self_intersect_recursive( index_t node_index1,
363265
index_t element_begin1,
@@ -523,54 +425,6 @@ namespace geode
523425
return task.get();
524426
}
525427

526-
template < typename Line, typename ACTION >
527-
bool line_intersect_recursive( const Line& line,
528-
index_t node_index,
529-
index_t element_begin,
530-
index_t element_end,
531-
index_t depth,
532-
ACTION& action ) const
533-
{
534-
OPENGEODE_ASSERT(
535-
node_index < tree_.size(), "Node out of tree range" );
536-
OPENGEODE_ASSERT( element_begin != element_end,
537-
"No iteration allowed start == end" );
538-
539-
// Prune sub-tree that does not have intersection
540-
if( !node( node_index ).intersects( line ) )
541-
{
542-
return false;
543-
}
544-
545-
if( is_leaf( element_begin, element_end ) )
546-
{
547-
return action( mapping_morton( element_begin ) );
548-
}
549-
550-
const auto it = get_recursive_iterators(
551-
node_index, element_begin, element_end );
552-
if( depth > async_depth_ )
553-
{
554-
if( line_intersect_recursive( line, it.child_left,
555-
element_begin, it.element_middle, depth + 1, action ) )
556-
{
557-
return true;
558-
}
559-
return line_intersect_recursive( line, it.child_right,
560-
it.element_middle, element_end, depth + 1, action );
561-
}
562-
auto task = async::local_spawn( [&] {
563-
return line_intersect_recursive( line, it.child_left,
564-
element_begin, it.element_middle, depth + 1, action );
565-
} );
566-
if( line_intersect_recursive( line, it.child_right,
567-
it.element_middle, element_end, depth + 1, action ) )
568-
{
569-
return true;
570-
}
571-
return task.get();
572-
}
573-
574428
template < typename BOX_FILTER, typename ACTION >
575429
bool generic_intersect_recursive( BOX_FILTER& box_filter,
576430
index_t node_index,
@@ -717,12 +571,10 @@ namespace geode
717571
void AABBTree< dimension >::compute_bbox_element_bbox_intersections(
718572
const BoundingBox< dimension >& box, EvalIntersection& action ) const
719573
{
720-
if( nb_bboxes() == 0 )
721-
{
722-
return;
723-
}
724-
impl_->bbox_intersect_recursive(
725-
box, Impl::ROOT_INDEX, 0, nb_bboxes(), 0, action );
574+
auto box_filter = [&box]( const BoundingBox< dimension >& inner_box ) {
575+
return inner_box.intersects( box );
576+
};
577+
compute_generic_element_bbox_intersections( box_filter, action );
726578
}
727579

728580
template < index_t dimension >
@@ -757,25 +609,21 @@ namespace geode
757609
void AABBTree< dimension >::compute_ray_element_bbox_intersections(
758610
const Ray< dimension >& ray, EvalIntersection& action ) const
759611
{
760-
if( nb_bboxes() == 0 )
761-
{
762-
return;
763-
}
764-
impl_->line_intersect_recursive(
765-
ray, Impl::ROOT_INDEX, 0, nb_bboxes(), 0, action );
612+
auto box_filter = [&ray]( const BoundingBox< dimension >& box ) {
613+
return box.intersects( ray );
614+
};
615+
compute_generic_element_bbox_intersections( box_filter, action );
766616
}
767617

768618
template < index_t dimension >
769619
template < class EvalIntersection >
770620
void AABBTree< dimension >::compute_line_element_bbox_intersections(
771621
const InfiniteLine< dimension >& line, EvalIntersection& action ) const
772622
{
773-
if( nb_bboxes() == 0 )
774-
{
775-
return;
776-
}
777-
impl_->line_intersect_recursive(
778-
line, Impl::ROOT_INDEX, 0, nb_bboxes(), 0, action );
623+
auto box_filter = [&line]( const BoundingBox< dimension >& box ) {
624+
return box.intersects( line );
625+
};
626+
compute_generic_element_bbox_intersections( box_filter, action );
779627
}
780628

781629
template < index_t dimension >
@@ -796,24 +644,20 @@ namespace geode
796644
void AABBTree< dimension >::compute_triangle_element_bbox_intersections(
797645
const Triangle< dimension >& triangle, EvalIntersection& action ) const
798646
{
799-
if( nb_bboxes() == 0 )
800-
{
801-
return;
802-
}
803-
impl_->triangle_intersect_recursive(
804-
triangle, Impl::ROOT_INDEX, 0, nb_bboxes(), 0, action );
647+
auto box_filter = [&triangle]( const BoundingBox< dimension >& box ) {
648+
return box.intersects( triangle );
649+
};
650+
compute_generic_element_bbox_intersections( box_filter, action );
805651
}
806652

807653
template < index_t dimension >
808654
template < class EvalIntersection >
809655
void AABBTree< dimension >::compute_segment_element_bbox_intersections(
810656
const Segment< dimension >& segment, EvalIntersection& action ) const
811657
{
812-
if( nb_bboxes() == 0 )
813-
{
814-
return;
815-
}
816-
impl_->line_intersect_recursive(
817-
segment, Impl::ROOT_INDEX, 0, nb_bboxes(), 0, action );
658+
auto box_filter = [&segment]( const BoundingBox< dimension >& box ) {
659+
return box.intersects( segment );
660+
};
661+
compute_generic_element_bbox_intersections( box_filter, action );
818662
}
819663
} // namespace geode

0 commit comments

Comments
 (0)