Garfield++ 5.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 const std::vector<int>& GetElementsInBlock(const Vec3& point) const;
72
73 private:
74 static std::vector<int> emptyBlock;
75
76 // Physical centre of this tree node.
77 Vec3 m_origin;
78 // Half the width/height/depth of this tree node.
79 Vec3 m_halfDimension;
80 // Storing min and max points for convenience
81 Vec3 m_min, m_max;
82
83 // The tree has up to eight children and can additionally store
84 // a list of mesh nodes and mesh elements.
85 // Pointers to child octants.
86 TetrahedralTree* children[8];
87
88 // Children follow a predictable pattern to make accesses simple.
89 // Here, - means less than 'origin' in that dimension, + means greater than.
90 // child: 0 1 2 3 4 5 6 7
91 // x: - - - - + + + +
92 // y: - - + + - - + +
93 // z: - + - + - + - +
94
95 std::vector<std::pair<Vec3, int> > nodes;
96 std::vector<int> elements;
97
98 static const size_t BlockCapacity = 10;
99
100 // Check if the given box overlaps with this tree node.
101 bool DoesBoxOverlap(const double bb[6]) const;
102
103 int GetOctantContainingPoint(const Vec3& point) const;
104
105 // Check if this tree node is a leaf or intermediate node.
106 bool IsLeafNode() const;
107
108 // Get a block containing the input point
109 const TetrahedralTree* GetBlockFromPoint(const Vec3& point) const;
110
111 // A helper function used by the function above.
112 // Called recursively on the child nodes.
113 const TetrahedralTree* GetBlockFromPointHelper(const Vec3& point) const;
114};
115}
116
117#endif
void InsertMeshElement(const double bb[6], const int index)
Insert a mesh element with given bounding box and index to the tree.
TetrahedralTree(const Vec3 &origin, const Vec3 &halfDimension)
Constructor.
void InsertMeshNode(Vec3 point, const int index)
Insert a mesh node (a vertex/point) to the tree.
const std::vector< int > & GetElementsInBlock(const Vec3 &point) const
Get all elements linked to a block corresponding to the given point.
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