VTK  9.7.1
BHTree.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright (c) 2007, Los Alamos National Security, LLC
3 // SPDX-FileCopyrightText: Copyright (c) 2021, Triad National Security, LLC
4 // SPDX-License-Identifier: LicenseRef-BSD-3-Clause-LANL-Triad-USGov
5 // .NAME BHTree - Create a Barnes Hut tree from the given points
6 //
7 // .SECTION Description
8 // BHTree takes point locations and distributes them recursively in
9 // a Barnes Hut tree. The tree is a quadtree or octree, dividing on physical
10 // location such that one point or one node appears within a child
11 // so that it is essentially AMR.
12 //
13 // This is used to ensure unique points in the vtk data set and so the
14 // succeeding steps of threading the tree for iteration is not done.
15 //
16 // BHLeaf is the actual point with the index matching the vtkPoints index.
17 // BHNode are negative numbers. This allows a quick recognition of a leaf
18 // or a node. Children numbered with 0 are empty.
19 //
20 
21 #ifndef BHTree_h
22 #define BHTree_h
23 
24 #include "vtkABINamespace.h"
25 
26 #include <vector>
27 
28 VTK_ABI_NAMESPACE_BEGIN
29 const int MAX_DIM = 3;
30 const int MAX_CHILD = 8;
31 
33 //
34 // Leaf information
35 //
37 
38 class BHLeaf
39 {
40 public:
41  BHLeaf(int dim, double* loc);
42  BHLeaf();
43 
44  bool sameAs(int dim, double* loc);
45 
46  double location[MAX_DIM];
47 };
48 
50 //
51 // BH node information
52 //
53 // Barnes Hut octree structure for N-body is represented by vector
54 // of BHNode which divide space into octants which are filled with one
55 // particle or one branching node. As the tree is built the child[8]
56 // array is used. Afterwards the tree is walked linking the nodes and
57 // replacing the child structure with data about the tree. When building
58 // the tree child information is an integer which is the index of the
59 // halo particle which was put into a vector of BHLeaf, or the index
60 // of the BHNode offset by the number of particles
61 //
63 
64 class BHNode
65 {
66 public:
67  BHNode();
68  BHNode(int dim, int numChild, double* minLoc, double* maxLoc);
69  BHNode(int dim, int numChild, BHNode* parent, int child);
70 
71  double length[MAX_DIM]; // Length of octant on each side
72  double center[MAX_DIM]; // Physical center of octant
73  int child[MAX_CHILD]; // Index of leaf or node
74 };
75 
77 //
78 // Barnes Hut Tree
79 //
81 
82 class BHTree
83 {
84 public:
85  BHTree(int dimension, int numChild,
86  double* minLoc, // Bounding box of tree
87  double* maxLoc); // Bounding box of tree
88  ~BHTree();
89 
90  int insertLeaf(double* loc);
91  int getChildIndex(BHNode* node, double* loc);
92  void print();
93 
94 private:
95  int dimension;
96  int numberOfChildren;
97  int leafIndex;
98  int nodeIndex;
99 
100  double minRange[MAX_DIM]; // Physical range of data
101  double maxRange[MAX_DIM]; // Physical range of data
102 
103  std::vector<BHLeaf*> bhLeaf;
104  std::vector<BHNode*> bhNode;
105 };
106 
107 VTK_ABI_NAMESPACE_END
108 #endif
void print()
const int MAX_CHILD
Definition: BHTree.h:30
Definition: BHTree.h:64
double location[MAX_DIM]
Definition: BHTree.h:46
const int MAX_DIM
Definition: BHTree.h:29
BHTree(int dimension, int numChild, double *minLoc, double *maxLoc)
Definition: BHTree.h:38
int getChildIndex(BHNode *node, double *loc)
Definition: BHTree.h:82
double length[MAX_DIM]
Definition: BHTree.h:71
double center[MAX_DIM]
Definition: BHTree.h:72
bool sameAs(int dim, double *loc)
int child[MAX_CHILD]
Definition: BHTree.h:73
int insertLeaf(double *loc)