Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
TetrahedralTree.hh
Go to the documentation of this file.
1#ifndef TETRAHEDRAL_TREE_H
2#define TETRAHEDRAL_TREE_H
3
4#include <cstddef>
5#include <vector>
6
7namespace Garfield {
8
9// TODO: replace this class with ROOT's TVector3 class
10
11struct Vec3 {
12 float x = 0., y = 0., z = 0.;
13
14 Vec3() {}
15 Vec3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
16
17 Vec3 operator+(const Vec3& r) const {
18 return Vec3(x + r.x, y + r.y, z + r.z);
19 }
20
21 Vec3 operator-(const Vec3& r) const {
22 return Vec3(x - r.x, y - r.y, z - r.z);
23 }
24
25 Vec3& operator+=(const Vec3& r) {
26 x += r.x;
27 y += r.y;
28 z += r.z;
29 return *this;
30 }
31
32 Vec3& operator-=(const Vec3& r) {
33 x -= r.x;
34 y -= r.y;
35 z -= r.z;
36 return *this;
37 }
38
39 Vec3 operator*(float r) const { return Vec3(x * r, y * r, z * r); }
40
41 Vec3 operator/(float r) const { return Vec3(x / r, y / r, z / r); }
42};
43
44/**
45
46\brief Helper class for searches in field maps.
47
48This class stores the mesh nodes and elements in an Octree data
49structure to optimize the element search operations
50
51Author: Ali Sheharyar
52
53Organization: Texas A&M University at Qatar
54
55*/
57 public:
58 /// Constructor
59 TetrahedralTree(const Vec3& origin, const Vec3& halfDimension);
60
61 /// Destructor
63
64 /// Insert a mesh node (a vertex/point) to the tree.
65 void InsertMeshNode(Vec3 point, const int index);
66
67 /// Insert a mesh element with given bounding box and index to the tree.
68 void InsertMeshElement(const double bb[6], const int index);
69
70 /// Get all elements linked to a block corresponding to the given point.
71 std::vector<int> GetElementsInBlock(const Vec3& point) const;
72
73 private:
74 // Physical centre of this tree node.
75 Vec3 m_origin;
76 // Half the width/height/depth of this tree node.
77 Vec3 m_halfDimension;
78 // Storing min and max points for convenience
79 Vec3 m_min, m_max;
80
81 // The tree has up to eight children and can additionally store
82 // a list of mesh nodes and mesh elements.
83 // Pointers to child octants.
84 TetrahedralTree* children[8];
85
86 // Children follow a predictable pattern to make accesses simple.
87 // Here, - means less than 'origin' in that dimension, + means greater than.
88 // child: 0 1 2 3 4 5 6 7
89 // x: - - - - + + + +
90 // y: - - + + - - + +
91 // z: - + - + - + - +
92
93 std::vector<std::pair<Vec3, int> > nodes;
94 std::vector<int> elements;
95
96 static const size_t BlockCapacity = 10;
97
98 // Check if the given box overlaps with this tree node.
99 bool DoesBoxOverlap(const double bb[6]) const;
100
101 int GetOctantContainingPoint(const Vec3& point) const;
102
103 // Check if this tree node is a leaf or intermediate node.
104 bool IsLeafNode() const;
105
106 // Get a block containing the input point
107 const TetrahedralTree* GetBlockFromPoint(const Vec3& point) const;
108
109 // A helper function used by the function above.
110 // Called recursively on the child nodes.
111 const TetrahedralTree* GetBlockFromPointHelper(const Vec3& point) const;
112};
113}
114
115#endif
Helper class for searches in field maps.
void InsertMeshElement(const double bb[6], const int index)
Insert a mesh element with given bounding box and index to the tree.
std::vector< int > GetElementsInBlock(const Vec3 &point) const
Get all elements linked to a block corresponding to the given point.
void InsertMeshNode(Vec3 point, const int index)
Insert a mesh node (a vertex/point) to the tree.
Vec3(float _x, float _y, float _z)
Vec3 & operator+=(const Vec3 &r)
Vec3 & operator-=(const Vec3 &r)
Vec3 operator-(const Vec3 &r) const
Vec3 operator/(float r) const
Vec3 operator*(float r) const
Vec3 operator+(const Vec3 &r) const