VTK  9.4.20241222
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
28VTK_ABI_NAMESPACE_BEGIN
29const int MAX_DIM = 3;
30const int MAX_CHILD = 8;
31
33//
34// Leaf information
35//
37
38class BHLeaf
39{
40public:
41 BHLeaf(int dim, double* loc);
43
44 bool sameAs(int dim, double* loc);
45
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
64class BHNode
65{
66public:
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
82class BHTree
83{
84public:
85 BHTree(int dimension, int numChild,
86 double* minLoc, // Bounding box of tree
87 double* maxLoc); // Bounding box of tree
89
90 int insertLeaf(double* loc);
91 int getChildIndex(BHNode* node, double* loc);
92 void print();
93
94private:
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
107VTK_ABI_NAMESPACE_END
108#endif
const int MAX_CHILD
Definition BHTree.h:30
const int MAX_DIM
Definition BHTree.h:29
bool sameAs(int dim, double *loc)
double location[MAX_DIM]
Definition BHTree.h:46
BHLeaf(int dim, double *loc)
BHNode(int dim, int numChild, double *minLoc, double *maxLoc)
double center[MAX_DIM]
Definition BHTree.h:72
BHNode(int dim, int numChild, BHNode *parent, int child)
double length[MAX_DIM]
Definition BHTree.h:71
int child[MAX_CHILD]
Definition BHTree.h:73
BHTree(int dimension, int numChild, double *minLoc, double *maxLoc)
int insertLeaf(double *loc)
void print()
int getChildIndex(BHNode *node, double *loc)