VTK  9.1.0
BHTree.h
Go to the documentation of this file.
1/*=========================================================================
2
3Copyright (c) 2007, Los Alamos National Security, LLC
4
5All rights reserved.
6
7Copyright 2007. Los Alamos National Security, LLC.
8This software was produced under U.S. Government contract DE-AC52-06NA25396
9for Los Alamos National Laboratory (LANL), which is operated by
10Los Alamos National Security, LLC for the U.S. Department of Energy.
11The U.S. Government has rights to use, reproduce, and distribute this software.
12NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY,
13EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE.
14If software is modified to produce derivative works, such modified software
15should be clearly marked, so as not to confuse it with the version available
16from LANL.
17
18Additionally, redistribution and use in source and binary forms, with or
19without modification, are permitted provided that the following conditions
20are met:
21- Redistributions of source code must retain the above copyright notice,
22 this list of conditions and the following disclaimer.
23- Redistributions in binary form must reproduce the above copyright notice,
24 this list of conditions and the following disclaimer in the documentation
25 and/or other materials provided with the distribution.
26- Neither the name of Los Alamos National Security, LLC, Los Alamos National
27 Laboratory, LANL, the U.S. Government, nor the names of its contributors
28 may be used to endorse or promote products derived from this software
29 without specific prior written permission.
30
31THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS
32"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR
35CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
43=========================================================================*/
44
45// .NAME BHTree - Create a Barnes Hut tree from the given points
46//
47// .SECTION Description
48// BHTree takes point locations and distributes them recursively in
49// a Barnes Hut tree. The tree is a quadtree or octree, dividing on physical
50// location such that one point or one node appears within a child
51// so that it is essentially AMR.
52//
53// This is used to ensure unique points in the vtk data set and so the
54// succeeding steps of threading the tree for iteration is not done.
55//
56// BHLeaf is the actual point with the index matching the vtkPoints index.
57// BHNode are negative numbers. This allows a quick recognition of a leaf
58// or a node. Children numbered with 0 are empty.
59//
60
61#ifndef BHTree_h
62#define BHTree_h
63
64#include <vector>
65
66const int MAX_DIM = 3;
67const int MAX_CHILD = 8;
68
70//
71// Leaf information
72//
74
75class BHLeaf
76{
77public:
78 BHLeaf(int dim, double* loc);
80
81 bool sameAs(int dim, double* loc);
82
84};
85
87//
88// BH node information
89//
90// Barnes Hut octree structure for N-body is represented by vector
91// of BHNode which divide space into octants which are filled with one
92// particle or one branching node. As the tree is built the child[8]
93// array is used. Afterwards the tree is walked linking the nodes and
94// replacing the child structure with data about the tree. When building
95// the tree child information is an integer which is the index of the
96// halo particle which was put into a vector of BHLeaf, or the index
97// of the BHNode offset by the number of particles
98//
100
102{
103public:
105 BHNode(int dim, int numChild, double* minLoc, double* maxLoc);
106 BHNode(int dim, int numChild, BHNode* parent, int child);
107
108 double length[MAX_DIM]; // Length of octant on each side
109 double center[MAX_DIM]; // Physical center of octant
110 int child[MAX_CHILD]; // Index of leaf or node
111};
112
114//
115// Barnes Hut Tree
116//
118
120{
121public:
122 BHTree(int dimension, int numChild,
123 double* minLoc, // Bounding box of tree
124 double* maxLoc); // Bounding box of tree
126
127 int insertLeaf(double* loc);
128 int getChildIndex(BHNode* node, double* loc);
129 void print();
130
131private:
132 int dimension;
133 int numberOfChildren;
134 int leafIndex;
135 int nodeIndex;
136
137 double minRange[MAX_DIM]; // Physical range of data
138 double maxRange[MAX_DIM]; // Physical range of data
139
140 std::vector<BHLeaf*> bhLeaf;
141 std::vector<BHNode*> bhNode;
142};
143
144#endif
const int MAX_CHILD
Definition: BHTree.h:67
const int MAX_DIM
Definition: BHTree.h:66
Definition: BHTree.h:76
bool sameAs(int dim, double *loc)
double location[MAX_DIM]
Definition: BHTree.h:83
BHLeaf(int dim, double *loc)
Definition: BHTree.h:102
BHNode(int dim, int numChild, double *minLoc, double *maxLoc)
double center[MAX_DIM]
Definition: BHTree.h:109
BHNode(int dim, int numChild, BHNode *parent, int child)
double length[MAX_DIM]
Definition: BHTree.h:108
int child[MAX_CHILD]
Definition: BHTree.h:110
Definition: BHTree.h:120
BHTree(int dimension, int numChild, double *minLoc, double *maxLoc)
int insertLeaf(double *loc)
void print()
int getChildIndex(BHNode *node, double *loc)