Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
QuadTree.hh
Go to the documentation of this file.
1#ifndef G_QUAD_TREE_H
2#define G_QUAD_TREE_H
3
4#include <cstddef>
5#include <tuple>
6#include <vector>
7
8namespace Garfield {
9
10/// Quadtree search.
11
12class QuadTree {
13 public:
14 /// Constructor
15 QuadTree(const double x0, const double y0, const double hx, const double hy);
16
17 /// Destructor
18 ~QuadTree();
19
20 /// Insert a mesh node (a vertex/point) to the tree.
21 void InsertMeshNode(const double x, const double y, const int index);
22
23 /// Insert a mesh element with given bounding box and index to the tree.
24 void InsertMeshElement(const double bb[4], const int index);
25
26 /// Get all elements linked to a block corresponding to the given point.
27 const std::vector<int>& GetElementsInBlock(const double x, const double y) const;
28
29 private:
30 static std::vector<int> emptyBlock;
31
32 // Centre of this tree node.
33 double m_x0, m_y0;
34 // Half-width in x and y of this tree node.
35 double m_hx, m_hy;
36 // Bounding box of the tree node.
37 double m_xmin, m_ymin, m_xmax, m_ymax;
38
39 // Pointers to child quadrants.
40 QuadTree* children[4];
41
42 // Children follow a predictable pattern to make accesses simple.
43 // Here, - means less than 'origin' in that dimension, + means greater than.
44 // child: 0 1 2 3
45 // x: - - + +
46 // y: - + - +
47
48 std::vector<std::tuple<float, float, int> > nodes;
49 std::vector<int> elements;
50
51 static const size_t BlockCapacity = 10;
52
53 // Check if the given box overlaps with this tree node.
54 bool DoesBoxOverlap(const double bb[4]) const;
55
56 int GetQuadrant(const double x, const double y) const;
57
58 // Check if this tree node is a leaf or intermediate node.
59 bool IsLeafNode() const;
60
61 // Get a block containing the input point
62 const QuadTree* GetBlockFromPoint(const double x, const double y) const;
63
64 // A helper function used by the function above.
65 // Called recursively on the child nodes.
66 const QuadTree* GetBlockFromPointHelper(const double x, const double y) const;
67};
68}
69
70#endif
QuadTree(const double x0, const double y0, const double hx, const double hy)
Constructor.
Definition QuadTree.cc:8
void InsertMeshElement(const double bb[4], const int index)
Insert a mesh element with given bounding box and index to the tree.
Definition QuadTree.cc:81
void InsertMeshNode(const double x, const double y, const int index)
Insert a mesh node (a vertex/point) to the tree.
Definition QuadTree.cc:43
~QuadTree()
Destructor.
Definition QuadTree.cc:20
const std::vector< int > & GetElementsInBlock(const double x, const double y) const
Get all elements linked to a block corresponding to the given point.
Definition QuadTree.cc:94