62 template < index_t DIMENSION >
99 template <
typename EvalDistance >
103 index_t nearest_box = NO_ID;
106 std::tie( nearest_box, nearest_point, distance ) =
108 closest_element_box_recursive< EvalDistance >( query, nearest_box,
111 return std::make_tuple( nearest_box, nearest_point, distance );
125 template <
class EvalIntersection >
129 bbox_intersect_recursive< EvalIntersection >(
141 template <
class EvalIntersection >
143 EvalIntersection& action )
const 145 self_intersect_recursive< EvalIntersection >(
ROOT_INDEX, 0,
161 bool is_leaf( index_t box_begin, index_t box_end )
const 163 return box_begin + 1 == box_end;
170 index_t& child_right )
const 172 middle_box = box_begin + ( box_end - box_begin ) / 2;
173 child_left = 2 * node_index;
174 child_right = 2 * node_index + 1;
194 index_t node_index, index_t box_begin, index_t box_end );
201 index_t element_begin,
202 index_t element_end );
207 template <
typename ACTION >
209 index_t& nearest_box,
213 index_t element_begin,
215 const ACTION& action )
const;
217 template <
class ACTION >
220 index_t element_begin,
222 ACTION& action )
const;
224 template <
class ACTION >
226 index_t element_begin1,
227 index_t element_end1,
229 index_t element_begin2,
230 index_t element_end2,
231 ACTION& action )
const;
241 std::tuple< index_t, vecn< DIMENSION >,
double >
253 std::vector< Box< DIMENSION > >
tree_{};
257 template < index_t DIMENSION >
274 template < index_t DIMENSION >
288 std::tuple< index_t, vecn< DIMENSION >,
double > closest_edge(
310 std::tuple< double, vecn< DIMENSION > > operator()(
323 template < index_t DIMENSION >
338 std::tuple< index_t, vecn< DIMENSION >,
double > closest_triangle(
361 std::tuple< double, vecn< DIMENSION > > operator()(
374 template < index_t DIMENSION >
400 index_t box_end )
const;
408 template < index_t DIMENSION >
412 template < index_t DIMENSION >
416 template < index_t DIMENSION >
417 template <
typename ACTION >
420 index_t& nearest_box,
426 const ACTION& action )
const 433 if(
is_leaf( box_begin, box_end ) )
438 std::tie( cur_distance, cur_nearest_point ) =
439 action( query, cur_box );
440 if( cur_distance < distance )
442 nearest_box = cur_box;
443 nearest_point = cur_nearest_point;
444 distance = cur_distance;
448 index_t box_middle, child_left, child_right;
450 child_left, child_right );
452 double distance_left =
454 double distance_right =
459 if( distance_left < distance_right )
461 if( distance_left < distance )
463 closest_element_box_recursive< ACTION >( query, nearest_box,
464 nearest_point, distance, child_left, box_begin, box_middle,
467 if( distance_right < distance )
469 closest_element_box_recursive< ACTION >( query, nearest_box,
470 nearest_point, distance, child_right, box_middle, box_end,
476 if( distance_right < distance )
478 closest_element_box_recursive< ACTION >( query, nearest_box,
479 nearest_point, distance, child_right, box_middle, box_end,
482 if( distance_left < distance )
484 closest_element_box_recursive< ACTION >( query, nearest_box,
485 nearest_point, distance, child_left, box_begin, box_middle,
491 template < index_t DIMENSION >
492 template <
typename ACTION >
496 index_t element_begin,
498 ACTION& action )
const 510 if(
is_leaf( element_begin, element_end ) )
518 index_t box_middle, child_left, child_right;
520 box_middle, child_left, child_right );
522 bbox_intersect_recursive< ACTION >(
523 box, child_left, element_begin, box_middle, action );
524 bbox_intersect_recursive< ACTION >(
525 box, child_right, box_middle, element_end, action );
528 template < index_t DIMENSION >
529 template <
class ACTION >
531 index_t element_begin1,
532 index_t element_end1,
534 index_t element_begin2,
535 index_t element_end2,
536 ACTION& action )
const 545 if( element_end2 <= element_begin1 )
551 if( !
node( node_index1 ).bboxes_overlap(
node( node_index2 ) ) )
557 if(
is_leaf( element_begin1, element_end1 )
558 &&
is_leaf( element_begin2, element_end2 ) )
560 if( node_index1 == node_index2 )
573 if( element_end2 - element_begin2 > element_end1 - element_begin1 )
575 index_t middle_box2, child_left2, child_right2;
577 middle_box2, child_left2, child_right2 );
578 self_intersect_recursive< ACTION >( node_index1, element_begin1,
579 element_end1, child_left2, element_begin2, middle_box2,
581 self_intersect_recursive< ACTION >( node_index1, element_begin1,
582 element_end1, child_right2, middle_box2, element_end2, action );
586 index_t middle_box1, child_left1, child_right1;
588 middle_box1, child_left1, child_right1 );
589 self_intersect_recursive< ACTION >( child_left1, element_begin1,
590 middle_box1, node_index2, element_begin2, element_end2,
592 self_intersect_recursive< ACTION >( child_right1, middle_box1,
593 element_end1, node_index2, element_begin2, element_end2,
ringmesh_disable_copy_and_move(AABBTree)
GEO::vecng< DIMENSION, double > vecn
const LineMesh< DIMENSION > & mesh_
void compute_bbox_element_bbox_intersections(const Box< DIMENSION > &box, EvalIntersection &action) const
double point_box_signed_distance(const vecn< DIMENSION > &p, const Box< DIMENSION > &B)
void get_recursive_iterators(index_t node_index, index_t box_begin, index_t box_end, index_t &middle_box, index_t &child_left, index_t &child_right) const
ringmesh_template_assert_2d_or_3d(DIMENSION)
std::vector< index_t > mapping_morton_
bool bboxes_overlap(const Box< DIMENSION > &B) const
Box< DIMENSION > & node(index_t i)
std::vector< Box< DIMENSION > > tree_
const LineMesh< DIMENSION > & mesh_
#define ringmesh_template_assert_3d(type)
const SurfaceMeshBase< DIMENSION > & mesh_
DistanceToEdge(const LineMesh< DIMENSION > &mesh)
virtual vecn< DIMENSION > get_point_hint_from_box(const Box< DIMENSION > &box, index_t element_id) const =0
Gets an element point from its box.
std::tuple< index_t, vecn< DIMENSION >, double > get_nearest_element_box_hint(const vecn< DIMENSION > &query) const
Gets an hint of the result.
const SurfaceMeshBase< DIMENSION > & mesh_
void bbox_intersect_recursive(const Box< DIMENSION > &box, index_t node_index, index_t element_begin, index_t element_end, ACTION &action) const
double inner_point_box_distance(const vecn< DIMENSION > &p, const Box< DIMENSION > &B)
void initialize_tree_recursive(const std::vector< Box< DIMENSION > > &bboxes, index_t node_index, index_t element_begin, index_t element_end)
The recursive instruction used in initialize_tree()
void closest_element_box_recursive(const vecn< DIMENSION > &query, index_t &nearest_box, vecn< DIMENSION > &nearest_point, double &distance, index_t node_index, index_t element_begin, index_t element_end, const ACTION &action) const
The recursive instruction used in closest_element_box()
static const index_t ROOT_INDEX
const VolumeMesh< DIMENSION > & mesh_
index_t max_node_index(index_t node_index, index_t box_begin, index_t box_end)
Gets the number of nodes in the tree subset.
#define ringmesh_assert(x)
bool is_leaf(index_t box_begin, index_t box_end) const
DistanceToTriangle(const SurfaceMeshBase< DIMENSION > &mesh)
index_t nb_bboxes() const
Classes to build GeoModel from various inputs.
void compute_self_element_bbox_intersections(EvalIntersection &action) const
void self_intersect_recursive(index_t node_index1, index_t element_begin1, index_t element_end1, index_t node_index2, index_t element_begin2, index_t element_end2, ACTION &action) const
void initialize_tree(const std::vector< Box< DIMENSION > > &bboxes)
Builds the tree.
FORWARD_DECLARATION_DIMENSION_CLASS(GeoModelMeshEntityAccess)
std::tuple< index_t, vecn< DIMENSION >, double > closest_element_box(const vecn< DIMENSION > &query, const EvalDistance &action) const
Gets the closest element box to a point.
virtual ~AABBTree()=default
const Box< DIMENSION > & node(index_t i) const