DOLFINx
DOLFINx C++ interface
BoundingBoxTree.h
1// Copyright (C) 2013 Anders Logg
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include <array>
10#include <cassert>
11#include <cstdint>
12#include <mpi.h>
13#include <span>
14#include <string>
15#include <vector>
16
17namespace dolfinx::mesh
18{
19class Mesh;
20}
21
23{
24
28{
29
30public:
39 BoundingBoxTree(const mesh::Mesh& mesh, int tdim,
40 const std::span<const std::int32_t>& entities,
41 double padding = 0);
42
49 BoundingBoxTree(const mesh::Mesh& mesh, int tdim, double padding = 0);
50
54 std::vector<std::pair<std::array<double, 3>, std::int32_t>> points);
55
58
60 BoundingBoxTree(const BoundingBoxTree& tree) = delete;
61
64
66 BoundingBoxTree& operator=(const BoundingBoxTree& other) = default;
67
69 ~BoundingBoxTree() = default;
70
75 std::array<std::array<double, 3>, 2> get_bbox(std::size_t node) const;
76
82 BoundingBoxTree create_global_tree(MPI_Comm comm) const;
83
85 std::int32_t num_bboxes() const;
86
88 int tdim() const;
89
91 std::string str() const;
92
100 std::array<int, 2> bbox(std::size_t node) const
101 {
102 assert(2 * node + 1 < _bboxes.size());
103 return {_bboxes[2 * node], _bboxes[2 * node + 1]};
104 }
105
106private:
107 // Constructor
108 BoundingBoxTree(std::vector<std::int32_t>&& bboxes,
109 std::vector<double>&& bbox_coords);
110
111 // Topological dimension of leaf entities
112 int _tdim;
113
114 // Print out recursively, for debugging
115 void tree_print(std::stringstream& s, int i) const;
116
117 // List of bounding boxes (parent-child-entity relations)
118 std::vector<std::int32_t> _bboxes;
119
120 // List of bounding box coordinates
121 std::vector<double> _bbox_coordinates;
122};
123} // namespace dolfinx::geometry
Axis-Aligned bounding box binary tree. It is used to find entities in a collection (often a mesh::Mes...
Definition: BoundingBoxTree.h:28
std::array< std::array< double, 3 >, 2 > get_bbox(std::size_t node) const
Return bounding box coordinates for a given node in the tree.
Definition: BoundingBoxTree.cpp:366
BoundingBoxTree & operator=(const BoundingBoxTree &other)=default
Copy assignment.
BoundingBoxTree & operator=(BoundingBoxTree &&other)=default
Move assignment.
BoundingBoxTree create_global_tree(MPI_Comm comm) const
Compute a global bounding tree (collective on comm) This can be used to find which process a point mi...
Definition: BoundingBoxTree.cpp:295
int tdim() const
Topological dimension of leaf entities.
Definition: BoundingBoxTree.cpp:338
BoundingBoxTree(BoundingBoxTree &&tree)=default
Move constructor.
std::int32_t num_bboxes() const
Return number of bounding boxes.
Definition: BoundingBoxTree.cpp:329
BoundingBoxTree(const BoundingBoxTree &tree)=delete
Copy constructor.
BoundingBoxTree(const mesh::Mesh &mesh, int tdim, const std::span< const std::int32_t > &entities, double padding=0)
Constructor.
Definition: BoundingBoxTree.cpp:229
~BoundingBoxTree()=default
Destructor.
std::string str() const
Print out for debugging.
Definition: BoundingBoxTree.cpp:331
std::array< int, 2 > bbox(std::size_t node) const
Get bounding box child nodes.
Definition: BoundingBoxTree.h:100
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:33
Geometry data structures and algorithms.
Definition: BoundingBoxTree.h:23
Mesh data structures and algorithms on meshes.
Definition: DofMap.h:30