VTK  9.7.1
vtkHyperTree.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
121 #ifndef vtkHyperTree_h
122 #define vtkHyperTree_h
123 
124 #include "vtkCommonDataModelModule.h" // For export macro
125 #include "vtkDeprecation.h" // Include the macros.
126 #include "vtkObject.h"
127 
128 #include <cassert> // Used internally
129 #include <memory> // std::shared_ptr
130 
131 VTK_ABI_NAMESPACE_BEGIN
132 class vtkBitArray;
133 class vtkIdList;
135 class vtkTypeInt64Array;
136 
137 //=============================================================================
139 {
140  // Index of this tree in the hypertree grid
142 
143  // Number of levels in the tree
144  unsigned int NumberOfLevels;
145 
146  // Number of vertices in this tree (coarse and leaves)
148 
149  // Number of nodes (non-leaf vertices) in the tree
151 
152  // Offset start for the implicit global index mapping fixed by
153  // SetGlobalIndexStart after create a tree.
154  // If you don't choose implicit global index mapping then this
155  // value is -1. Then, you must to descrieb explicit global index
156  // mapping by using then SetGlobalIndexFromLocal for each cell
157  // in tree.
158  // The extra cost is equivalent to the cost of a field of values
159  // of cells.
161 
162  // Storage to record the parent of each tree vertex
163  std::vector<unsigned int> ParentToElderChild;
164 
165  // Storage to record the local to global id mapping
166  std::vector<vtkIdType> GlobalIndexTable;
167 };
168 
169 //=============================================================================
170 class VTKCOMMONDATAMODEL_EXPORT vtkHyperTree : public vtkObject
171 {
172 public:
173  static vtkHyperTree* New();
174  vtkTypeMacro(vtkHyperTree, vtkObject);
175  void PrintSelf(ostream& os, vtkIndent indent) override;
176 
185  "Use bool Initialize(unsigned char branchFactor, unsigned char dimension) instead.")
186  void Initialize(
187  unsigned char branchFactor, unsigned char dimension, unsigned char numberOfChildren);
188 
197  bool Initialize(unsigned char branchFactor, unsigned char dimension);
198 
218  virtual void InitializeForReader(vtkIdType numberOfLevels, vtkIdType nbVertices,
219  vtkIdType nbVerticesOfLastLevel, vtkBitArray* isParent, vtkBitArray* isMasked,
220  vtkBitArray* outIsMasked);
221 
242  virtual void BuildFromBreadthFirstOrderDescriptor(
243  vtkBitArray* descriptor, vtkIdType numberOfBits, vtkIdType startIndex = 0);
244 
284  virtual void ComputeBreadthFirstOrderDescriptor(unsigned int depthLimiter, vtkBitArray* inputMask,
285  vtkTypeInt64Array* numberOfVerticesPerDepth, vtkBitArray* descriptor,
286  vtkIdList* breadthFirstIdMap);
287 
293  void CopyStructure(vtkHyperTree* ht);
294 
295  VTK_DEPRECATED_IN_9_6_0("No effect, do not use.")
296  virtual vtkHyperTree* Freeze(const char* vtkNotUsed(mode)) { return this; };
297 
299 
303  void SetTreeIndex(vtkIdType treeIndex)
304  {
305  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
306  this->Datas->TreeIndex = treeIndex;
307  }
309  {
310  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
311  return this->Datas->TreeIndex;
312  }
314 
318  unsigned int GetNumberOfLevels() const
319  {
320  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
321  assert("post: result_greater_or_equal_to_one" && this->Datas->NumberOfLevels >= 1);
322  return this->Datas->NumberOfLevels;
323  }
324 
329  {
330  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
331  return this->Datas->NumberOfVertices;
332  }
333 
338  {
339  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
340  return this->Datas->NumberOfNodes;
341  }
342 
347  {
348  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
349  return this->Datas->NumberOfVertices - this->Datas->NumberOfNodes;
350  }
351 
355  int GetBranchFactor() const { return this->BranchFactor; }
356 
360  int GetDimension() const { return this->Dimension; }
361 
366  vtkIdType GetNumberOfChildren() const { return this->NumberOfChildren; }
367 
369 
373  void GetScale(double s[3]) const;
374  double GetScale(unsigned int d) const;
376 
382  std::shared_ptr<vtkHyperTreeGridScales> InitializeScales(
383  const double* scales, bool reinitialize = false);
384 
395  VTK_DEPRECATED_IN_9_6_0("Use vtkNew<vtkHyperTree> and Initialize instead.")
396  static vtkHyperTree* CreateInstance(unsigned char branchFactor, unsigned char dimension);
401  virtual unsigned long GetActualMemorySizeBytes();
402 
407  unsigned int GetActualMemorySize()
408  {
409  // in kilibytes
410  return static_cast<unsigned int>(this->GetActualMemorySizeBytes() / 1024);
411  }
412 
422  virtual bool IsGlobalIndexImplicit();
423 
443  virtual void SetGlobalIndexStart(vtkIdType start);
444 
450  {
451  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
452  return this->Datas->GlobalIndexStart;
453  }
454 
464  virtual void SetGlobalIndexFromLocal(vtkIdType index, vtkIdType global);
465 
474  virtual vtkIdType GetGlobalIndexFromLocal(vtkIdType index) const;
475 
480  virtual vtkIdType GetGlobalNodeIndexMax() const;
481 
486  virtual bool IsLeaf(vtkIdType index) const;
487 
493  virtual void SubdivideLeaf(vtkIdType index, unsigned int level);
494 
501  virtual bool IsTerminalNode(vtkIdType index) const;
502 
510  virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const;
511 
516  virtual const unsigned int* GetElderChildIndexArray(size_t& nbElements) const;
517 
519 
525  void SetScales(std::shared_ptr<vtkHyperTreeGridScales> scales) { this->Scales = scales; }
527 
529 
532  bool HasScales() const { return (this->Scales != nullptr); }
534 
536 
539  std::shared_ptr<vtkHyperTreeGridScales> GetScales() const
540  {
541  assert(this->Scales != nullptr);
542  return this->Scales;
543  }
545 
546 protected:
547  vtkHyperTree();
548  ~vtkHyperTree() override = default;
549 
550 private:
551  vtkHyperTree(const vtkHyperTree&) = delete;
552  void operator=(const vtkHyperTree&) = delete;
553 
554  bool IsChildLeaf(vtkIdType index_parent, unsigned int ichild) const;
555 
564  void ComputeBreadthFirstOrderDescriptorImpl(unsigned int depthLimiter, vtkBitArray* inputMask,
565  unsigned int depth, vtkIdType index, std::vector<std::vector<bool>>& descriptorPerDepth,
566  std::vector<std::vector<vtkIdType>>& breadthFirstOrderIdMapPerDepth);
567 
568  //-- Global information
569 
570  // Branching factor of tree (2 or 3)
571  unsigned char BranchFactor;
572 
573  // Dimension of tree (1, 2, or 3)
574  unsigned char Dimension;
575 
576  // Number of children for coarse cell
577  unsigned char NumberOfChildren;
578 
579  //-- Local information
580  std::shared_ptr<vtkHyperTreeData> Datas;
581 
582  // Storage of pre-computed per-level cell scales
583  // In hypertree grid, one description by hypertree.
584  // In Uniform hypertree grid, one description by hypertree grid
585  // (all cells, different hypertree, are identical by level).
586  std::shared_ptr<vtkHyperTreeGridScales> Scales;
587 };
588 
589 VTK_ABI_NAMESPACE_END
590 #endif
vtkIdType GetGlobalIndexStart() const
Get the start global index for the current tree for implicit global index mapping.
Definition: vtkHyperTree.h:449
bool HasScales() const
Return the existence scales.
Definition: vtkHyperTree.h:532
abstract base class for most VTK objects
Definition: vtkObject.h:52
vtkIdType NumberOfVertices
Definition: vtkHyperTree.h:147
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int GetDimension() const
Return the spatial dimension of the tree.
Definition: vtkHyperTree.h:360
std::vector< vtkIdType > GlobalIndexTable
Definition: vtkHyperTree.h:166
void SetScales(std::shared_ptr< vtkHyperTreeGridScales > scales)
In an hypertree, all cells are the same size by level.
Definition: vtkHyperTree.h:525
std::vector< unsigned int > ParentToElderChild
Definition: vtkHyperTree.h:163
void SetTreeIndex(vtkIdType treeIndex)
Set/Get tree index in hypertree grid.
Definition: vtkHyperTree.h:303
int vtkIdType
Definition: vtkType.h:363
vtkIdType TreeIndex
Definition: vtkHyperTree.h:141
#define VTK_DEPRECATED_IN_9_6_0(reason)
unsigned int NumberOfLevels
Definition: vtkHyperTree.h:144
a simple class to control print indentation
Definition: vtkIndent.h:28
std::shared_ptr< vtkHyperTreeGridScales > GetScales() const
Return all scales.
Definition: vtkHyperTree.h:539
list of point or cell ids
Definition: vtkIdList.h:25
vtkIdType GetNumberOfChildren() const
Return the number of children per node of the tree.
Definition: vtkHyperTree.h:366
vtkIdType GetNumberOfLeaves() const
Return the number of leaf (fine) in the tree.
Definition: vtkHyperTree.h:346
int GetBranchFactor() const
Return the branch factor of the tree.
Definition: vtkHyperTree.h:355
#define VTK_NEWINSTANCE
unsigned int GetNumberOfLevels() const
Return the number of levels.
Definition: vtkHyperTree.h:318
vtkIdType GetTreeIndex() const
Set/Get tree index in hypertree grid.
Definition: vtkHyperTree.h:308
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:32
A data object structured as a tree.
Definition: vtkHyperTree.h:170
vtkIdType GetNumberOfVertices() const
Return the number of all vertices (coarse and fine) in the tree.
Definition: vtkHyperTree.h:328
vtkIdType GetNumberOfNodes() const
Return the number of nodes (coarse) in the tree.
Definition: vtkHyperTree.h:337
Dynamic generation of scales for vtkHyperTree.
vtkIdType GlobalIndexStart
Definition: vtkHyperTree.h:160
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkIdType NumberOfNodes
Definition: vtkHyperTree.h:150