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 } // namespace mesh
22 
23 namespace geometry
24 {
25 
28 
30 {
31 
32 public:
37  BoundingBoxTree(const mesh::Mesh& mesh, int tdim);
38 
42  BoundingBoxTree(const std::vector<Eigen::Vector3d>& points);
43 
45  BoundingBoxTree(BoundingBoxTree&& tree) = default;
46 
48  BoundingBoxTree(const BoundingBoxTree& tree) = delete;
49 
51  BoundingBoxTree& operator=(BoundingBoxTree&& other) = default;
52 
54  ~BoundingBoxTree() = default;
55 
60  Eigen::Array<double, 2, 3, Eigen::RowMajor> get_bbox(int node) const;
61 
63  int num_bboxes() const;
64 
66  int tdim() const;
67 
69  std::string str() const;
70 
77  std::array<int, 2> bbox(int node) const
78  {
79  assert(node < (int)_bboxes.rows());
80  return {_bboxes(node, 0), _bboxes(node, 1)};
81  }
82 
83 private:
84  // Constructor
86  const Eigen::Array<int, Eigen::Dynamic, 2, Eigen::RowMajor>& bboxes,
87  const Eigen::Array<double, Eigen::Dynamic, 3, Eigen::RowMajor>&
88  bbox_coords);
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:368
dolfinx::geometry::BoundingBoxTree::num_bboxes
int num_bboxes() const
Return number of bounding boxes.
Definition: BoundingBoxTree.cpp:337
dolfinx::geometry::BoundingBoxTree::bbox
std::array< int, 2 > bbox(int node) const
Get bounding box child nodes.
Definition: BoundingBoxTree.h:77
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::geometry::BoundingBoxTree::BoundingBoxTree
BoundingBoxTree(const mesh::Mesh &mesh, int tdim)
Constructor.
Definition: BoundingBoxTree.cpp:262
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:339
dolfinx::geometry::BoundingBoxTree::tdim
int tdim() const
Topological dimension of leaf entities.
Definition: BoundingBoxTree.cpp:346