Garfield++ 3.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 <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 private:
59 // Physical position/size. This implicitly defines the bounding
60 // box of this node
61 Vec3 m_origin; // The physical center of this node
62 Vec3 m_halfDimension; // Half the width/height/depth of this node
63
64 Vec3 min, max; // storing min and max points for convenience
65
66 // The tree has up to eight children and can additionally store
67 // a list of mesh nodes and mesh elements (Tetrahedron)
68 TetrahedralTree* children[8]; // Pointers to child octants
69
70 // Children follow a predictable pattern to make accesses simple.
71 // Here, - means less than 'origin' in that dimension, + means greater than.
72 // child: 0 1 2 3 4 5 6 7
73 // x: - - - - + + + +
74 // y: - - + + - - + +
75 // z: - + - + - + - +
76
77 struct OctreeBlockElem {
78 Vec3 point;
79 int nodeIndex;
80
81 OctreeBlockElem(const Vec3& _point, const int _ni)
82 : point(_point), nodeIndex(_ni) {}
83 };
84
85 std::vector<OctreeBlockElem> iBlockElems;
86 std::vector<int> tetList;
87
88 public:
89 // Constructor
90 TetrahedralTree(const Vec3& origin, const Vec3& halfDimension);
91
92 // Destructor
94
95 // Insert a mesh node (a vertex/point) to the tree
96 void InsertMeshNode(Vec3 point, const int nodeIndex);
97
98 // Insert the mesh element (a tetrahedron) to the tree
99 void InsertTetrahedron(const double elemBoundingBox[6], const int elemIndex);
100
101 // Get all tetrahedra linked to a block corresponding to the given point
102 std::vector<int> GetTetListInBlock(const Vec3& point);
103
104 private:
105 // Check if the given box overlaps with the box corresponding to this tree
106 // node
107 bool DoesBoxOverlap(const Vec3& b_min, const Vec3& b_max) const;
108
109 int GetOctantContainingPoint(const Vec3& point) const;
110
111 // Check if the tree node is full
112 bool IsFull() const;
113
114 // Check if the tree node is empty
115 bool IsEmpty() const;
116
117 // Check if this tree node is a leaf or intermediate node
118 bool IsLeafNode() const;
119
120 // Get a block containing the input point
121 const TetrahedralTree* GetBlockFromPoint(const Vec3& point);
122
123 // A helper function used by the function above.
124 // Called recursively on the child nodes.
125 const TetrahedralTree* GetBlockFromPointHelper(const Vec3& point);
126};
127}
128
129#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