DOLFIN-X
DOLFIN-X 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 <Eigen/Dense>
10 #include <array>
11 #include <dolfinx/common/MPI.h>
12 #include <memory>
13 #include <vector>
14 
15 namespace dolfinx
16 {
17 
18 // Forward declarations
19 namespace mesh
20 {
21 class Mesh;
22 } // namespace mesh
23 
24 namespace geometry
25 {
26 
29 
31 {
32 
33 public:
42  BoundingBoxTree(const mesh::Mesh& mesh, int tdim,
43  const std::vector<std::int32_t>& entity_indices,
44  double padding = 0);
45 
52  BoundingBoxTree(const mesh::Mesh& mesh, int tdim, double padding = 0);
53 
57  BoundingBoxTree(const std::vector<Eigen::Vector3d>& points);
58 
60  BoundingBoxTree(BoundingBoxTree&& tree) = default;
61 
63  BoundingBoxTree(const BoundingBoxTree& tree) = delete;
64 
67 
69  ~BoundingBoxTree() = default;
70 
75  Eigen::Array<double, 2, 3, Eigen::RowMajor> get_bbox(int node) const;
76 
82  BoundingBoxTree compute_global_tree(const MPI_Comm& comm) const;
83 
85  int num_bboxes() const;
86 
88  int tdim() const;
89 
91  std::string str() const;
92 
99  std::array<int, 2> bbox(int node) const
100  {
101  assert(node < (int)_bboxes.rows());
102  return {_bboxes(node, 0), _bboxes(node, 1)};
103  }
104 
111  void remap_entity_indices(const std::vector<std::int32_t>& entity_indices);
112 
113 private:
114  // Constructor
116  const Eigen::Array<int, Eigen::Dynamic, 2, Eigen::RowMajor>& bboxes,
117  const Eigen::Array<double, Eigen::Dynamic, 3, Eigen::RowMajor>&
118  bbox_coords);
119 
120  // Topological dimension of leaf entities
121  int _tdim;
122 
123  // Print out recursively, for debugging
124  void tree_print(std::stringstream& s, int i) const;
125 
126  // List of bounding boxes (parent-child-entity relations)
127  Eigen::Array<int, Eigen::Dynamic, 2, Eigen::RowMajor> _bboxes;
128 
129  // List of bounding box coordinates
130  Eigen::Array<double, Eigen::Dynamic, 3, Eigen::RowMajor> _bbox_coordinates;
131 };
132 } // namespace geometry
133 } // namespace dolfinx
Axis-Aligned bounding box binary tree. It is used to find entities in a collection (often a mesh::Mes...
Definition: BoundingBoxTree.h:31
std::string str() const
Print out for debugging.
Definition: BoundingBoxTree.cpp:385
BoundingBoxTree(const mesh::Mesh &mesh, int tdim, const std::vector< std::int32_t > &entity_indices, double padding=0)
Constructor.
Definition: BoundingBoxTree.cpp:289
~BoundingBoxTree()=default
Destructor.
BoundingBoxTree(const BoundingBoxTree &tree)=delete
Copy constructor.
int num_bboxes() const
Return number of bounding boxes.
Definition: BoundingBoxTree.cpp:383
void remap_entity_indices(const std::vector< std::int32_t > &entity_indices)
Remap entity indices for bounding box trees that does not span a whole mesh. Each leaf node should co...
Definition: BoundingBoxTree.cpp:274
int tdim() const
Topological dimension of leaf entities.
Definition: BoundingBoxTree.cpp:392
BoundingBoxTree(BoundingBoxTree &&tree)=default
Move constructor.
BoundingBoxTree compute_global_tree(const 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:331
Eigen::Array< double, 2, 3, Eigen::RowMajor > get_bbox(int node) const
Return bounding box coordinates for a given node in the tree.
Definition: BoundingBoxTree.cpp:422
std::array< int, 2 > bbox(int node) const
Get bounding box child nodes.
Definition: BoundingBoxTree.h:99
BoundingBoxTree & operator=(BoundingBoxTree &&other)=default
Move assignment.
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:57