1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkHyperTreeGridDepthLimiter.h"
#include "vtkBitArray.h"
#include "vtkCellData.h"
#include "vtkHyperTree.h"
#include "vtkHyperTreeGrid.h"
#include "vtkHyperTreeGridNonOrientedCursor.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkHyperTreeGridDepthLimiter);
//------------------------------------------------------------------------------
vtkHyperTreeGridDepthLimiter::vtkHyperTreeGridDepthLimiter()
{
// Require root-level depth by default
this->Depth = 0;
// Default mask is empty
this->OutMask = nullptr;
// Output indices begin at 0
this->CurrentId = 0;
// By default, just create a new mask
this->JustCreateNewMask = true;
// The AppropriateOutput attribute is only used when setting JustCreateNewMask.
// The AppropriateOutput attribute is inherited from the parent class
// vtkHyperTreeGridAlgorithm. If its value is true, on output an HTG of the
// same type as the one on input will be constructed.
// Note that there are two HTG representations: vtkHyperTreeGrid (it manages
// pad of different sizes on the same level) and vtkUniformHyperTreeGrid (it
// manages quads/cubes of same size on the same level).
this->AppropriateOutput = true;
}
//------------------------------------------------------------------------------
vtkHyperTreeGridDepthLimiter::~vtkHyperTreeGridDepthLimiter()
{
if (this->OutMask)
{
this->OutMask->Delete();
this->OutMask = nullptr;
}
}
//------------------------------------------------------------------------------
void vtkHyperTreeGridDepthLimiter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Depth: " << this->Depth << endl;
os << indent << "OutMask: " << this->OutMask << endl;
os << indent << "CurrentId: " << this->CurrentId << endl;
}
//------------------------------------------------------------------------------
int vtkHyperTreeGridDepthLimiter::FillOutputPortInformation(int, vtkInformation* info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkHyperTreeGrid");
return 1;
}
//------------------------------------------------------------------------------
int vtkHyperTreeGridDepthLimiter::ProcessTrees(vtkHyperTreeGrid* input, vtkDataObject* outputDO)
{
// Downcast output data object to hyper tree grid
vtkHyperTreeGrid* output = vtkHyperTreeGrid::SafeDownCast(outputDO);
if (!output)
{
vtkErrorMacro("Incorrect type of output: " << outputDO->GetClassName());
return 0;
}
if (this->JustCreateNewMask)
{
output->ShallowCopy(input);
output->SetDepthLimiter(this->Depth);
return 1;
}
// Retrieve material mask
this->InMask = input->HasMask() ? input->GetMask() : nullptr;
// Set grid parameters
output->SetDimensions(input->GetDimensions());
output->SetTransposedRootIndexing(input->GetTransposedRootIndexing());
output->SetBranchFactor(input->GetBranchFactor());
output->CopyCoordinates(input);
output->SetHasInterface(input->GetHasInterface());
output->SetInterfaceNormalsName(input->GetInterfaceNormalsName());
output->SetInterfaceInterceptsName(input->GetInterfaceInterceptsName());
// Initialize output point data
this->InData = input->GetCellData();
this->OutData = output->GetCellData();
this->OutData->CopyAllocate(this->InData);
// Create material mask bit array if one is present on input
if (!this->OutMask && input->HasMask())
{
this->OutMask = vtkBitArray::New();
}
// Output indices begin at 0
this->CurrentId = 0;
// Iterate over all input and output hyper trees
vtkIdType inIndex;
vtkHyperTreeGrid::vtkHyperTreeGridIterator it;
input->InitializeTreeIterator(it);
vtkNew<vtkHyperTreeGridNonOrientedCursor> inCursor;
vtkNew<vtkHyperTreeGridNonOrientedCursor> outCursor;
while (it.GetNextTree(inIndex))
{
if (this->CheckAbort())
{
break;
}
// Initialize new grid cursor at root of current input tree
input->InitializeNonOrientedCursor(inCursor, inIndex);
// Initialize new cursor at root of current output tree
output->InitializeNonOrientedCursor(outCursor, inIndex, true);
// Limit depth recursively
this->RecursivelyProcessTree(inCursor, outCursor);
}
// Squeeze and set output material mask if necessary
if (this->OutMask)
{
this->OutMask->Squeeze();
output->SetMask(this->OutMask);
}
return 1;
}
//------------------------------------------------------------------------------
void vtkHyperTreeGridDepthLimiter::RecursivelyProcessTree(
vtkHyperTreeGridNonOrientedCursor* inCursor, vtkHyperTreeGridNonOrientedCursor* outCursor)
{
// Retrieve global index of input cursor
vtkIdType inId = inCursor->GetGlobalNodeIndex();
// Increase index count on output: postfix is intended
vtkIdType outId = this->CurrentId++;
// Retrieve output tree and set global index of output cursor
vtkHyperTree* outTree = outCursor->GetTree();
outTree->SetGlobalIndexFromLocal(outCursor->GetVertexId(), outId);
// Update material mask if relevant
if (this->InMask)
{
this->OutMask->InsertValue(outId, this->InMask->GetValue(inId));
}
// Copy output cell data from that of input cell
this->OutData->CopyData(this->InData, inId, outId);
// Descend further into input trees only if cursor is not at leaf and depth not reached
if (!inCursor->IsLeaf() && inCursor->GetLevel() < this->Depth)
{
// Cursor is not at leaf, subdivide output tree one level further
outCursor->SubdivideLeaf();
// If input cursor is neither at leaf nor at maximum depth, recurse to all children
int numChildren = inCursor->GetNumberOfChildren();
for (int child = 0; child < numChildren; ++child)
{
if (this->CheckAbort())
{
break;
}
inCursor->ToChild(child);
// Descend into child in output grid as well
outCursor->ToChild(child);
// Recurse
this->RecursivelyProcessTree(inCursor, outCursor);
// Return to parent in output grid
inCursor->ToParent();
outCursor->ToParent();
}
}
}
VTK_ABI_NAMESPACE_END
|