split the blocks into a tree that starts out as a single stem than turn a full tree. This shape is designed so that numLevels and maxNumBlocks constraint can be satisfied
| 89 | // than turn a full tree. This shape is designed so that numLevels and maxNumBlocks |
| 90 | // constraint can be satisfied |
| 91 | void Split(const vtkAMRBox& rootBox, int numLevels, int refinementRatio, int maxNumBlocks, |
| 92 | std::vector<std::vector<vtkAMRBox>>& out) |
| 93 | { |
| 94 | out.clear(); |
| 95 | out.resize(1); |
| 96 | out.back().push_back(rootBox); |
| 97 | maxNumBlocks--; |
| 98 | |
| 99 | int treeDegree = rootBox.ComputeDimension() * 2; |
| 100 | int numTreeLevels = |
| 101 | std::min(numLevels, ComputeTreeHeight(maxNumBlocks - (numLevels - 1), treeDegree)) - |
| 102 | 1; // minus one because root already has one |
| 103 | int level = 1; |
| 104 | for (; level < numLevels - numTreeLevels; level++) |
| 105 | { |
| 106 | out.emplace_back(); |
| 107 | const std::vector<vtkAMRBox>& parentBoxes = out[level - 1]; |
| 108 | std::vector<vtkAMRBox>& childBoxes = out[level]; |
| 109 | vtkAMRBox child = parentBoxes.back(); |
| 110 | child.Refine(refinementRatio); |
| 111 | childBoxes.push_back(child); |
| 112 | } |
| 113 | |
| 114 | for (; level < numLevels; level++) |
| 115 | { |
| 116 | out.emplace_back(); |
| 117 | const std::vector<vtkAMRBox>& parentBoxes = out[level - 1]; |
| 118 | std::vector<vtkAMRBox>& childBoxes = out[level]; |
| 119 | for (size_t i = 0; i < parentBoxes.size(); i++) |
| 120 | { |
| 121 | const vtkAMRBox& parent = parentBoxes[i]; |
| 122 | SplitXYZ(parent, refinementRatio, childBoxes); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // create a grid by sampling from input using the indices in box |
| 128 | vtkUniformGrid* ConstructGrid( |