Garfield++ 4.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 std::vector<int> GetElementsInBlock(const double x, const double y) const;
28
29 private:
30 // Centre of this tree node.
31 double m_x0, m_y0;
32 // Half-width in x and y of this tree node.
33 double m_hx, m_hy;
34 // Bounding box of the tree node.
35 double m_xmin, m_ymin, m_xmax, m_ymax;
36
37 // Pointers to child quadrants.
38 QuadTree* children[4];
39
40 // Children follow a predictable pattern to make accesses simple.
41 // Here, - means less than 'origin' in that dimension, + means greater than.
42 // child: 0 1 2 3
43 // x: - - + +
44 // y: - + - +
45
46 std::vector<std::tuple<float, float, int> > nodes;
47 std::vector<int> elements;
48
49 static const size_t BlockCapacity = 10;
50
51 // Check if the given box overlaps with this tree node.
52 bool DoesBoxOverlap(const double bb[4]) const;
53
54 int GetQuadrant(const double x, const double y) const;
55
56 // Check if this tree node is a leaf or intermediate node.
57 bool IsLeafNode() const;
58
59 // Get a block containing the input point
60 const QuadTree* GetBlockFromPoint(const double x, const double y) const;
61
62 // A helper function used by the function above.
63 // Called recursively on the child nodes.
64 const QuadTree* GetBlockFromPointHelper(const double x, const double y) const;
65};
66}
67
68#endif
Quadtree search.
Definition: QuadTree.hh:12
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:92
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:79
void InsertMeshNode(const double x, const double y, const int index)
Insert a mesh node (a vertex/point) to the tree.
Definition: QuadTree.cc:41
~QuadTree()
Destructor.
Definition: QuadTree.cc:18