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
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
/**
* @class vtkHyperTreeGridScales
* @brief A specifalized type of vtkHyperTreeGrid for the case
* when root cells have uniform sizes in each direction *
*
* @sa
* vtkHyperTree vtkHyperTreeGrid vtkRectilinearGrid
*
* @par Thanks:
* This class was written by Jacques-Bernard Lekien (CEA)
* This work was supported by Commissariat a l'Energie Atomique
* CEA, DAM, DIF, F-91297 Arpajon, France.
*/
#ifndef vtkHyperTreeGridScales_h
#define vtkHyperTreeGridScales_h
#include "vtkABINamespace.h"
#include <cstring> // For memcpy
#include <vector> // For std::vector
VTK_ABI_NAMESPACE_BEGIN
class vtkHyperTreeGridScales
{
public:
/**
* Build this class from the original scale mesh and subdivision factor
*/
vtkHyperTreeGridScales(double branchfactor, const double scale[3])
: BranchFactor(branchfactor)
, CurrentFailLevel(1)
, CellScales(scale, scale + 3)
{
}
~vtkHyperTreeGridScales() = default;
double GetBranchFactor() const { return this->BranchFactor; }
double* GetScale(unsigned int level) const
{
this->Update(level);
return this->CellScales.data() + 3 * level;
}
double GetScaleX(unsigned int level) const
{
this->Update(level);
return this->CellScales[3 * level + 0];
}
double GetScaleY(unsigned int level) const
{
this->Update(level);
return this->CellScales[3 * level + 1];
}
double GetScaleZ(unsigned int level) const
{
this->Update(level);
return this->CellScales[3 * level + 2];
}
/**
* Return the mesh scale at the given level
*/
void GetScale(unsigned int level, double scale[3]) const
{
this->Update(level);
memcpy(scale, this->CellScales.data() + 3 * level, 3 * sizeof(double));
}
unsigned int GetCurrentFailLevel() const { return this->CurrentFailLevel; }
private:
vtkHyperTreeGridScales(const vtkHyperTreeGridScales&) = delete;
vtkHyperTreeGridScales& operator=(const vtkHyperTreeGridScales&) = delete;
/**
* Update the cell scale table in order for the table to return the mesh at the given level.
*/
void Update(unsigned int level) const
{
if (level < this->CurrentFailLevel)
{
return;
}
this->CurrentFailLevel = level + 1;
this->CellScales.resize(3 * this->CurrentFailLevel);
auto current = this->CellScales.begin() + 3 * (this->CurrentFailLevel - 1);
auto previous = current - 3;
auto end = this->CellScales.end();
for (; current != end; ++current, ++previous)
{
*current = *previous / this->BranchFactor;
}
}
/**
* The subdivision factor in the grid refinement scheme
*/
const double BranchFactor;
/**
* The cache cell scales table
*/
mutable unsigned int CurrentFailLevel;
mutable std::vector<double> CellScales;
};
VTK_ABI_NAMESPACE_END
#endif
// VTK-HeaderTest-Exclude: vtkHyperTreeGridScales.h
|