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 <memory>
12 #include <vector>
13 
14 namespace dolfinx
15 {
16 
17 // Forward declarations
18 namespace mesh
19 {
20 class Mesh;
21 class MeshEntity;
22 } // namespace mesh
23 
24 namespace geometry
25 {
26 
29 
31 {
32 
33 public:
38  BoundingBoxTree(const mesh::Mesh& mesh, int tdim);
39 
43  BoundingBoxTree(const std::vector<Eigen::Vector3d>& points);
44 
46  BoundingBoxTree(BoundingBoxTree&& tree) = default;
47 
49  BoundingBoxTree(const BoundingBoxTree& tree) = delete;
50 
52  BoundingBoxTree& operator=(BoundingBoxTree&& other) = default;
53 
55  ~BoundingBoxTree() = default;
56 
61  Eigen::Array<double, 2, 3, Eigen::RowMajor> get_bbox(int node) const;
62 
64  int num_bboxes() const;
65 
67  int tdim() const;
68 
70  std::string str() const;
71 
78  std::array<int, 2> bbox(int node) const
79  {
80  assert(node < (int)_bboxes.rows());
81  return {_bboxes(node, 0), _bboxes(node, 1)};
82  }
83 
84 private:
85  // Constructor
86  BoundingBoxTree(const std::vector<double>& leaf_bboxes,
87  const std::vector<int>::iterator partition_begin,
88  const std::vector<int>::iterator partition_end);
89 
90  // Topological dimension of leaf entities
91  int _tdim;
92 
93  // Print out recursively, for debugging
94  void tree_print(std::stringstream& s, int i) const;
95 
96  // List of bounding boxes (parent-child-entity relations)
97  Eigen::Array<int, Eigen::Dynamic, 2, Eigen::RowMajor> _bboxes;
98 
99  // List of bounding box coordinates
100  Eigen::Array<double, Eigen::Dynamic, 3, Eigen::RowMajor> _bbox_coordinates;
101 
102 public:
105  std::unique_ptr<BoundingBoxTree> global_tree;
106 };
107 } // namespace geometry
108 } // namespace dolfinx
dolfinx::geometry::BoundingBoxTree::get_bbox
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:396
dolfinx::geometry::BoundingBoxTree::num_bboxes
int num_bboxes() const
Return number of bounding boxes.
Definition: BoundingBoxTree.cpp:365
dolfinx::geometry::BoundingBoxTree::bbox
std::array< int, 2 > bbox(int node) const
Get bounding box child nodes.
Definition: BoundingBoxTree.h:78
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:30
dolfinx::geometry::BoundingBoxTree::BoundingBoxTree
BoundingBoxTree(const mesh::Mesh &mesh, int tdim)
Constructor.
Definition: BoundingBoxTree.cpp:268
dolfinx::geometry::BoundingBoxTree::global_tree
std::unique_ptr< BoundingBoxTree > global_tree
Global tree for mesh ownership of each process (same on all processes)
Definition: BoundingBoxTree.h:105
dolfinx::mesh::Mesh
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:46
dolfinx::geometry::BoundingBoxTree::str
std::string str() const
Print out for debugging.
Definition: BoundingBoxTree.cpp:367
dolfinx::geometry::BoundingBoxTree::tdim
int tdim() const
Topological dimension of leaf entities.
Definition: BoundingBoxTree.cpp:374