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