VTK  9.3.20240419
vtkHyperTreeGridScales.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
17 #ifndef vtkHyperTreeGridScales_h
18 #define vtkHyperTreeGridScales_h
19 
20 #include "vtkABINamespace.h"
21 
22 #include <cstring> // For memcpy
23 #include <vector> // For std::vector
24 
25 VTK_ABI_NAMESPACE_BEGIN
27 {
28 public:
32  vtkHyperTreeGridScales(double branchfactor, const double scale[3])
33  : BranchFactor(branchfactor)
34  , CurrentFailLevel(1)
35  , CellScales(scale, scale + 3)
36  {
37  }
38 
40 
41  double GetBranchFactor() const { return this->BranchFactor; }
42 
43  double* GetScale(unsigned int level) const
44  {
45  this->Update(level);
46  return this->CellScales.data() + 3 * level;
47  }
48 
49  double GetScaleX(unsigned int level) const
50  {
51  this->Update(level);
52  return this->CellScales[3 * level + 0];
53  }
54 
55  double GetScaleY(unsigned int level) const
56  {
57  this->Update(level);
58  return this->CellScales[3 * level + 1];
59  }
60 
61  double GetScaleZ(unsigned int level) const
62  {
63  this->Update(level);
64  return this->CellScales[3 * level + 2];
65  }
66 
70  void GetScale(unsigned int level, double scale[3]) const
71  {
72  this->Update(level);
73  memcpy(scale, this->CellScales.data() + 3 * level, 3 * sizeof(double));
74  }
75 
76  unsigned int GetCurrentFailLevel() const { return this->CurrentFailLevel; }
77 
78 private:
80  vtkHyperTreeGridScales& operator=(const vtkHyperTreeGridScales&) = delete;
81 
85  void Update(unsigned int level) const
86  {
87  if (level < this->CurrentFailLevel)
88  {
89  return;
90  }
91  this->CurrentFailLevel = level + 1;
92  this->CellScales.resize(3 * this->CurrentFailLevel);
93  auto current = this->CellScales.begin() + 3 * (this->CurrentFailLevel - 1);
94  auto previous = current - 3;
95  auto end = this->CellScales.end();
96  for (; current != end; ++current, ++previous)
97  {
98  *current = *previous / this->BranchFactor;
99  }
100  }
101 
105  const double BranchFactor;
106 
110  mutable unsigned int CurrentFailLevel;
111  mutable std::vector<double> CellScales;
112 };
113 
114 VTK_ABI_NAMESPACE_END
115 #endif
116 // VTK-HeaderTest-Exclude: vtkHyperTreeGridScales.h
A specifalized type of vtkHyperTreeGrid for the case when root cells have uniform sizes in each direc...
double GetScaleX(unsigned int level) const
vtkHyperTreeGridScales(double branchfactor, const double scale[3])
Build this class from the original scale mesh and subdivision factor.
~vtkHyperTreeGridScales()=default
double GetScaleY(unsigned int level) const
double * GetScale(unsigned int level) const
unsigned int GetCurrentFailLevel() const
void GetScale(unsigned int level, double scale[3]) const
Return the mesh scale at the given level.
double GetScaleZ(unsigned int level) const
@ level
Definition: vtkX3D.h:395
@ previous
Definition: vtkX3D.h:449
@ scale
Definition: vtkX3D.h:229