Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.1.0/v0.9.0/cpp
DOLFINx  0.1.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 <xtl/xspan.hpp>
12 #include <vector>
13 
14 namespace dolfinx
15 {
16 
17 // Forward declarations
18 namespace mesh
19 {
20 class Mesh;
21 } // namespace mesh
22 
23 namespace geometry
24 {
25 
28 
30 {
31 
32 public:
41  BoundingBoxTree(const mesh::Mesh& mesh, int tdim,
42  const xtl::span<const std::int32_t>& entities,
43  double padding = 0);
44 
51  BoundingBoxTree(const mesh::Mesh& mesh, int tdim, double padding = 0);
52 
56  std::vector<std::pair<std::array<double, 3>, std::int32_t>> points);
57 
59  BoundingBoxTree(BoundingBoxTree&& tree) = default;
60 
62  BoundingBoxTree(const BoundingBoxTree& tree) = delete;
63 
65  BoundingBoxTree& operator=(BoundingBoxTree&& other) = default;
66 
68  BoundingBoxTree& operator=(const BoundingBoxTree& other) = default;
69 
71  ~BoundingBoxTree() = default;
72 
77  std::array<std::array<double, 3>, 2> get_bbox(std::size_t node) const;
78 
84  BoundingBoxTree create_global_tree(const MPI_Comm& comm) const;
85 
87  std::int32_t num_bboxes() const;
88 
90  int tdim() const;
91 
93  std::string str() const;
94 
102  std::array<int, 2> bbox(std::size_t node) const
103  {
104  assert(2 * node + 1 < _bboxes.size());
105  return {_bboxes[2 * node], _bboxes[2 * node + 1]};
106  }
107 
108 private:
109  // Constructor
110  BoundingBoxTree(std::vector<std::int32_t>&& bboxes,
111  std::vector<double>&& bbox_coords);
112 
113  // Topological dimension of leaf entities
114  int _tdim;
115 
116  // Print out recursively, for debugging
117  void tree_print(std::stringstream& s, int i) const;
118 
119  // List of bounding boxes (parent-child-entity relations)
120  std::vector<std::int32_t> _bboxes;
121 
122  // List of bounding box coordinates
123  std::vector<double> _bbox_coordinates;
124 };
125 } // namespace geometry
126 } // namespace dolfinx
dolfinx::geometry::BoundingBoxTree::num_bboxes
std::int32_t num_bboxes() const
Return number of bounding boxes.
Definition: BoundingBoxTree.cpp:332
dolfinx::geometry::BoundingBoxTree::BoundingBoxTree
BoundingBoxTree(const mesh::Mesh &mesh, int tdim, const xtl::span< const std::int32_t > &entities, double padding=0)
Constructor.
Definition: BoundingBoxTree.cpp:231
dolfinx::geometry::BoundingBoxTree::~BoundingBoxTree
~BoundingBoxTree()=default
Destructor.
dolfinx::geometry::BoundingBoxTree::operator=
BoundingBoxTree & operator=(BoundingBoxTree &&other)=default
Move assignment.
dolfinx::geometry::BoundingBoxTree
Axis-Aligned bounding box binary tree. It is used to find entities in a collection (often a mesh::Mes...
Definition: BoundingBoxTree.h:29
dolfinx::mesh::Mesh
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:55
dolfinx::geometry::BoundingBoxTree::bbox
std::array< int, 2 > bbox(std::size_t node) const
Get bounding box child nodes.
Definition: BoundingBoxTree.h:102
dolfinx::geometry::BoundingBoxTree::str
std::string str() const
Print out for debugging.
Definition: BoundingBoxTree.cpp:334
dolfinx::geometry::BoundingBoxTree::get_bbox
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
dolfinx::geometry::BoundingBoxTree::create_global_tree
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
dolfinx::geometry::BoundingBoxTree::tdim
int tdim() const
Topological dimension of leaf entities.
Definition: BoundingBoxTree.cpp:341