Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.3.0/v0.9.0/cpp
DOLFINx  0.3.0
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 <dolfinx/common/MPI.h>
11 #include <vector>
12 #include <xtl/xspan.hpp>
13 
14 namespace dolfinx::mesh
15 {
16 class Mesh;
17 }
18 
20 {
21 
24 
26 {
27 
28 public:
37  BoundingBoxTree(const mesh::Mesh& mesh, int tdim,
38  const xtl::span<const std::int32_t>& entities,
39  double padding = 0);
40 
47  BoundingBoxTree(const mesh::Mesh& mesh, int tdim, double padding = 0);
48 
52  std::vector<std::pair<std::array<double, 3>, std::int32_t>> points);
53 
55  BoundingBoxTree(BoundingBoxTree&& tree) = default;
56 
58  BoundingBoxTree(const BoundingBoxTree& tree) = delete;
59 
62 
64  BoundingBoxTree& operator=(const BoundingBoxTree& other) = default;
65 
67  ~BoundingBoxTree() = default;
68 
73  std::array<std::array<double, 3>, 2> get_bbox(std::size_t node) const;
74 
80  BoundingBoxTree create_global_tree(const MPI_Comm& comm) const;
81 
83  std::int32_t num_bboxes() const;
84 
86  int tdim() const;
87 
89  std::string str() const;
90 
98  std::array<int, 2> bbox(std::size_t node) const
99  {
100  assert(2 * node + 1 < _bboxes.size());
101  return {_bboxes[2 * node], _bboxes[2 * node + 1]};
102  }
103 
104 private:
105  // Constructor
106  BoundingBoxTree(std::vector<std::int32_t>&& bboxes,
107  std::vector<double>&& bbox_coords);
108 
109  // Topological dimension of leaf entities
110  int _tdim;
111 
112  // Print out recursively, for debugging
113  void tree_print(std::stringstream& s, int i) const;
114 
115  // List of bounding boxes (parent-child-entity relations)
116  std::vector<std::int32_t> _bboxes;
117 
118  // List of bounding box coordinates
119  std::vector<double> _bbox_coordinates;
120 };
121 } // 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:26
BoundingBoxTree & operator=(const BoundingBoxTree &other)=default
Copy assignment.
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:369
std::string str() const
Print out for debugging.
Definition: BoundingBoxTree.cpp:334
~BoundingBoxTree()=default
Destructor.
BoundingBoxTree(const BoundingBoxTree &tree)=delete
Copy constructor.
BoundingBoxTree create_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:298
BoundingBoxTree(const mesh::Mesh &mesh, int tdim, const xtl::span< const std::int32_t > &entities, double padding=0)
Constructor.
Definition: BoundingBoxTree.cpp:231
int tdim() const
Topological dimension of leaf entities.
Definition: BoundingBoxTree.cpp:341
BoundingBoxTree(BoundingBoxTree &&tree)=default
Move constructor.
std::array< int, 2 > bbox(std::size_t node) const
Get bounding box child nodes.
Definition: BoundingBoxTree.h:98
std::int32_t num_bboxes() const
Return number of bounding boxes.
Definition: BoundingBoxTree.cpp:332
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:53
Geometry data structures and algorithms.
Definition: BoundingBoxTree.h:20
Mesh data structures and algorithms on meshes.
Definition: DirichletBC.h:20