Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Garfield::TetrahedralTree Class Reference

Helper class for searches in field maps. More...

#include <TetrahedralTree.hh>

Public Member Functions

 TetrahedralTree (const Vec3 &origin, const Vec3 &halfDimension)
 Constructor.
 
 ~TetrahedralTree ()
 Destructor.
 
void InsertMeshNode (Vec3 point, const int index)
 Insert a mesh node (a vertex/point) to the tree.
 
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.
 

Detailed Description

Helper class for searches in field maps.

This class stores the mesh nodes and elements in an Octree data structure to optimize the element search operations

Author: Ali Sheharyar

Organization: Texas A&M University at Qatar

Definition at line 56 of file TetrahedralTree.hh.

Constructor & Destructor Documentation

◆ TetrahedralTree()

Garfield::TetrahedralTree::TetrahedralTree ( const Vec3 origin,
const Vec3 halfDimension 
)

Constructor.

TetrahedralTree.cc This class stores the mesh nodes and elements in an Octree data structure to optimize the element search operations

Author: Ali Sheharyar Organization: Texas A&M University at Qatar

Definition at line 14 of file TetrahedralTree.cc.

15 : m_origin(origin), m_halfDimension(halfDimension) {
16 m_min.x = origin.x - halfDimension.x;
17 m_min.y = origin.y - halfDimension.y;
18 m_min.z = origin.z - halfDimension.z;
19 m_max.x = origin.x + halfDimension.x;
20 m_max.y = origin.y + halfDimension.y;
21 m_max.z = origin.z + halfDimension.z;
22
23 // Initially, there are no children
24 for (int i = 0; i < 8; ++i) children[i] = nullptr;
25}

◆ ~TetrahedralTree()

Garfield::TetrahedralTree::~TetrahedralTree ( )

Destructor.

Definition at line 27 of file TetrahedralTree.cc.

27 {
28 // Recursively destroy octants
29 for (int i = 0; i < 8; ++i) delete children[i];
30}

Member Function Documentation

◆ GetElementsInBlock()

std::vector< int > Garfield::TetrahedralTree::GetElementsInBlock ( const Vec3 point) const

Get all elements linked to a block corresponding to the given point.

Definition at line 108 of file TetrahedralTree.cc.

108 {
109 const TetrahedralTree* octreeNode = GetBlockFromPoint(point);
110
111 if (octreeNode) {
112 return octreeNode->elements;
113 }
114
115 return std::vector<int>();
116}
TetrahedralTree(const Vec3 &origin, const Vec3 &halfDimension)
Constructor.

◆ InsertMeshElement()

void Garfield::TetrahedralTree::InsertMeshElement ( const double  bb[6],
const int  index 
)

Insert a mesh element with given bounding box and index to the tree.

Definition at line 92 of file TetrahedralTree.cc.

92 {
93 if (IsLeafNode()) {
94 // Add the element to the list of this octant.
95 elements.push_back(index);
96 return;
97 }
98 // Check which children overlap with the element's bounding box.
99 for (int i = 0; i < 8; i++) {
100 if (!children[i]->DoesBoxOverlap(bb)) continue;
101 children[i]->InsertMeshElement(bb, index);
102 }
103}
void InsertMeshElement(const double bb[6], const int index)
Insert a mesh element with given bounding box and index to the tree.

Referenced by InsertMeshElement().

◆ InsertMeshNode()

void Garfield::TetrahedralTree::InsertMeshNode ( Vec3  point,
const int  index 
)

Insert a mesh node (a vertex/point) to the tree.

Definition at line 54 of file TetrahedralTree.cc.

54 {
55 // Check if it is a leaf node.
56 if (!IsLeafNode()) {
57 // We are at an interior node. Insert recursively into the
58 // appropriate child octant.
59 int octant = GetOctantContainingPoint(point);
60 children[octant]->InsertMeshNode(point, index);
61 return;
62 }
63
64 // Add the new point if the block is not full.
65 if (nodes.size() < BlockCapacity) {
66 nodes.push_back(std::make_pair(point, index));
67 return;
68 }
69 // Block is full, so we need to partition it.
70 // Split the current node and create new empty trees for each child octant.
71 for (int i = 0; i < 8; ++i) {
72 // Compute new bounding box for this child
73 Vec3 newOrigin = m_origin;
74 newOrigin.x += m_halfDimension.x * (i & 4 ? .5f : -.5f);
75 newOrigin.y += m_halfDimension.y * (i & 2 ? .5f : -.5f);
76 newOrigin.z += m_halfDimension.z * (i & 1 ? .5f : -.5f);
77 children[i] = new TetrahedralTree(newOrigin, m_halfDimension * .5f);
78 }
79
80 // Move the mesh nodes from the partitioned node (now marked as interior) to
81 // its children.
82 while (!nodes.empty()) {
83 auto node = nodes.back();
84 nodes.pop_back();
85 const int oct = GetOctantContainingPoint(node.first);
86 children[oct]->InsertMeshNode(node.first, node.second);
87 }
88 // Insert the new point in the appropriate octant.
89 children[GetOctantContainingPoint(point)]->InsertMeshNode(point, index);
90}
void InsertMeshNode(Vec3 point, const int index)
Insert a mesh node (a vertex/point) to the tree.

Referenced by InsertMeshNode().


The documentation for this class was generated from the following files: