Garfield++ v2r0
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 <vector>
5
6#define BLOCK_CAPACITY 10 // k_v
7
8namespace Garfield {
9
10// TODO: replace this class with ROOT's TVector3 class
11
12struct Vec3 {
13 float x, y, z;
14
15 Vec3() {}
16 Vec3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
17
18 Vec3 operator+(const Vec3& r) const {
19 return Vec3(x + r.x, y + r.y, z + r.z);
20 }
21
22 Vec3 operator-(const Vec3& r) const {
23 return Vec3(x - r.x, y - r.y, z - r.z);
24 }
25
26 Vec3& operator+=(const Vec3& r) {
27 x += r.x;
28 y += r.y;
29 z += r.z;
30 return *this;
31 }
32
33 Vec3& operator-=(const Vec3& r) {
34 x -= r.x;
35 y -= r.y;
36 z -= r.z;
37 return *this;
38 }
39
40 Vec3 operator*(float r) const { return Vec3(x * r, y * r, z * r); }
41
42 Vec3 operator/(float r) const { return Vec3(x / r, y / r, z / r); }
43};
44
45/**
46
47\brief Helper class for searches in field maps.
48
49This class stores the mesh nodes and elements in an Octree data
50structure to optimize the element search operations
51
52Author: Ali Sheharyar
53
54Organization: Texas A&M University at Qatar
55
56*/
58
59 private:
60 // Physical position/size. This implicitly defines the bounding
61 // box of this node
62 Vec3 m_origin; // The physical center of this node
63 Vec3 m_halfDimension; // Half the width/height/depth of this node
64
65 Vec3 min, max; // storing min and max points for convenience
66
67 // The tree has up to eight children and can additionally store
68 // a list of mesh nodes and mesh elements (Tetrahedron)
69 TetrahedralTree* children[8]; // Pointers to child octants
70
71 // Children follow a predictable pattern to make accesses simple.
72 // Here, - means less than 'origin' in that dimension, + means greater than.
73 // child: 0 1 2 3 4 5 6 7
74 // x: - - - - + + + +
75 // y: - - + + - - + +
76 // z: - + - + - + - +
77
78 struct OctreeBlockElem {
79 Vec3 point;
80 int nodeIndex;
81
82 OctreeBlockElem(const Vec3& _point, const int _ni)
83 : point(_point), nodeIndex(_ni) {}
84 };
85
86 std::vector<OctreeBlockElem> iBlockElems;
87 std::vector<int> tetList;
88
89 public:
90 // Constructor
91 TetrahedralTree(const Vec3& origin, const Vec3& halfDimension);
92
93 // Destructor
95
96 // Insert a mesh node (a vertex/point) to the tree
97 void InsertMeshNode(Vec3 point, const int nodeIndex);
98
99 // Insert the mesh element (a tetrahedron) to the tree
100 void InsertTetrahedron(const double elemBoundingBox[6], const int elemIndex);
101
102 // Get all tetrahedra linked to a block corresponding to the given point
103 std::vector<int> GetTetListInBlock(const Vec3& point);
104
105 private:
106 // Check if the given box overlaps with the box corresponding to this tree
107 // node
108 bool DoesBoxOverlap(const Vec3& b_min, const Vec3& b_max) const;
109
110 int GetOctantContainingPoint(const Vec3& point) const;
111
112 // Check if the tree node is full
113 bool IsFull() const;
114
115 // Check if the tree node is empty
116 bool IsEmpty() const;
117
118 // Check if this tree node is a leaf or intermediate node
119 bool IsLeafNode() const;
120
121 // Get a block containing the input point
122 const TetrahedralTree* GetBlockFromPoint(const Vec3& point);
123
124 // A helper function used by the function above.
125 // Called recursively on the child nodes.
126 const TetrahedralTree* GetBlockFromPointHelper(const Vec3& point);
127};
128}
129
130#endif
Helper class for searches in field maps.
std::vector< int > GetTetListInBlock(const Vec3 &point)
void InsertTetrahedron(const double elemBoundingBox[6], const int elemIndex)
void InsertMeshNode(Vec3 point, const int nodeIndex)
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