Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/geode/geometry/aabb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ namespace geode

[[nodiscard]] const BoundingBox< dimension >& bounding_box() const;

/*!
* @brief Whether or not the queries run on this tree are parallelized.
*/
[[nodiscard]] bool parallel() const;

/*!
* @brief Sets whether or not the queries run on this tree are
* parallelized.
*/
void set_parallel( bool parallel );

/*!
* @brief Gets all the boxes containing a point
* @param[in] query the point to test
Expand Down
29 changes: 23 additions & 6 deletions include/geode/geometry/detail/aabb_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ namespace geode
return mapping_morton_.size();
}

[[nodiscard]] bool parallel() const
{
return parallel_;
}

void set_parallel( bool parallel )
{
parallel_ = parallel;
}

[[nodiscard]] index_t initial_depth() const
{
return parallel_ ? 0 : async_depth_ + 1;
}

[[nodiscard]] static bool is_leaf(
index_t element_begin, index_t element_end )
{
Expand Down Expand Up @@ -547,6 +562,7 @@ namespace geode
std::vector< index_t > mapping_morton_;
index_t depth_{ 1 };
index_t async_depth_{ 0 };
bool parallel_{ true };
};

template < index_t dimension >
Expand Down Expand Up @@ -586,8 +602,8 @@ namespace geode
{
return;
}
impl_->self_intersect_recursive( Impl::ROOT_INDEX, 0, nb_bboxes(), 0,
Impl::ROOT_INDEX, 0, nb_bboxes(), action );
impl_->self_intersect_recursive( Impl::ROOT_INDEX, 0, nb_bboxes(),
impl_->initial_depth(), Impl::ROOT_INDEX, 0, nb_bboxes(), action );
}

template < index_t dimension >
Expand All @@ -600,8 +616,9 @@ namespace geode
{
return;
}
impl_->other_intersect_recursive( Impl::ROOT_INDEX, 0, nb_bboxes(), 0,
other_tree, Impl::ROOT_INDEX, 0, other_tree.nb_bboxes(), action );
impl_->other_intersect_recursive( Impl::ROOT_INDEX, 0, nb_bboxes(),
impl_->initial_depth(), other_tree, Impl::ROOT_INDEX, 0,
other_tree.nb_bboxes(), action );
}

template < index_t dimension >
Expand Down Expand Up @@ -635,8 +652,8 @@ namespace geode
{
return;
}
impl_->generic_intersect_recursive(
box_filter, Impl::ROOT_INDEX, 0, nb_bboxes(), 0, action );
impl_->generic_intersect_recursive( box_filter, Impl::ROOT_INDEX, 0,
nb_bboxes(), impl_->initial_depth(), action );
}

template < index_t dimension >
Expand Down
16 changes: 14 additions & 2 deletions src/geode/geometry/aabb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ namespace geode
return impl_->node( Impl::ROOT_INDEX );
}

template < index_t dimension >
bool AABBTree< dimension >::parallel() const
{
return impl_->parallel();
}

template < index_t dimension >
void AABBTree< dimension >::set_parallel( bool parallel )
{
impl_->set_parallel( parallel );
}

template < index_t dimension >
std::vector< index_t > AABBTree< dimension >::containing_boxes(
const Point< dimension >& query ) const
Expand All @@ -84,8 +96,8 @@ namespace geode
}
std::vector< index_t > result;
std::mutex mutex;
impl_->containing_boxes_recursive(
Impl::ROOT_INDEX, 0, nb_bboxes(), 0, query, result, mutex );
impl_->containing_boxes_recursive( Impl::ROOT_INDEX, 0, nb_bboxes(),
impl_->initial_depth(), query, result, mutex );
return result;
}

Expand Down
61 changes: 36 additions & 25 deletions tests/geometry/test-aabb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,17 @@ class BoxAABBIntersection
absl::Span< const geode::BoundingBox< dimension > > bounding_boxes_;
};

template < geode::index_t dimension >
template < geode::index_t dimension, bool parallel >
void test_intersections_with_query_box()
{
geode::Logger::info(
"TEST", " Box-Box intersection AABB ", dimension, "D" );
geode::Logger::info( "TEST", " Box-Box intersection AABB ", dimension, "D ",
parallel ? "parallel" : "sequential" );
const geode::index_t nb_boxes{ 10 };
const double box_size{ 0.5 };
const auto box_vector =
create_box_vector< dimension >( nb_boxes, box_size );
const geode::AABBTree< dimension > aabb{ box_vector };
geode::AABBTree< dimension > aabb{ box_vector };
aabb.set_parallel( parallel );

BoxAABBIntersection< dimension > eval_intersection{ box_vector };

Expand Down Expand Up @@ -296,17 +297,18 @@ class RayAABBIntersection
absl::Span< const geode::BoundingBox< dimension > > bounding_boxes_;
};

template < geode::index_t dimension >
template < geode::index_t dimension, bool parallel >
void test_intersections_with_ray_trace()
{
geode::Logger::info(
"TEST", " Box-Ray intersection AABB ", dimension, "D" );
geode::Logger::info( "TEST", " Box-Ray intersection AABB ", dimension, "D ",
parallel ? "parallel" : "sequential" );

const geode::index_t nb_boxes{ 10 };
const double box_size{ 0.5 };
const auto box_vector =
create_box_vector< dimension >( nb_boxes, box_size );
const geode::AABBTree< dimension > aabb{ box_vector };
geode::AABBTree< dimension > aabb{ box_vector };
aabb.set_parallel( parallel );

RayAABBIntersection< dimension > eval_intersection{ box_vector };

Expand Down Expand Up @@ -396,11 +398,11 @@ void test_intersections_with_ray_trace()
"[Test] Box-Ray intersection - Wrong set of boxes" );
}

template < geode::index_t dimension >
template < geode::index_t dimension, bool parallel >
void test_self_intersections()
{
geode::Logger::info(
"TEST", " Box self intersection AABB ", dimension, "D" );
geode::Logger::info( "TEST", " Box self intersection AABB ", dimension,
"D ", parallel ? "parallel" : "sequential" );

const geode::index_t nb_boxes{ 10 };
// Create a grid of intersecting boxes
Expand All @@ -410,7 +412,9 @@ void test_self_intersections()
box_vector.insert(
box_vector.end(), box_vector2.begin(), box_vector2.end() );

const geode::AABBTree< dimension > aabb{ box_vector };
geode::AABBTree< dimension > aabb{ box_vector };
aabb.set_parallel( parallel );

BoxAABBIntersection< dimension > eval_intersection{ box_vector };
// investigate box inclusions
eval_intersection.included_box_.clear();
Expand Down Expand Up @@ -445,14 +449,16 @@ class OtherAABBIntersection
std::mutex mutex_;
};

template < geode::index_t dimension >
template < geode::index_t dimension, bool parallel >
void test_other_intersections()
{
geode::Logger::info(
"TEST", " Box other intersection AABB ", dimension, "D" );
geode::Logger::info( "TEST", " Box other intersection AABB ", dimension,
"D ", parallel ? "parallel" : "sequential" );

const geode::AABBTree< dimension > aabb{ create_box_vector< dimension >(
geode::AABBTree< dimension > aabb{ create_box_vector< dimension >(
5, 0.2 ) };
aabb.set_parallel( parallel );

const geode::AABBTree< dimension > other{ create_box_vector< dimension >(
2, 0.4 ) };
OtherAABBIntersection< dimension > action;
Expand All @@ -467,21 +473,26 @@ void test_other_intersections()
}
}

template < geode::index_t dimension >
template < geode::index_t dimension, bool parallel >
void do_test()
{
test_build_aabb< dimension >();
test_nearest_neighbor_search< dimension >();
test_intersections_with_query_box< dimension >();
test_intersections_with_ray_trace< dimension >();
test_self_intersections< dimension >();
test_other_intersections< dimension >();
if( !parallel )
{
test_build_aabb< dimension >();
test_nearest_neighbor_search< dimension >();
}
test_intersections_with_query_box< dimension, parallel >();
test_intersections_with_ray_trace< dimension, parallel >();
test_self_intersections< dimension, parallel >();
test_other_intersections< dimension, parallel >();
}

void test()
{
do_test< 2 >();
do_test< 3 >();
do_test< 2, false >();
do_test< 3, false >();
do_test< 2, true >();
do_test< 3, true >();
}

OPENGEODE_TEST( "aabb" )
Loading