VTK  9.3.20240419
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
126 #ifndef vtkHyperTree_h
127 #define vtkHyperTree_h
128 
129 #include "vtkCommonDataModelModule.h" // For export macro
130 #include "vtkObject.h"
131 
132 #include <cassert> // Used internally
133 #include <memory> // std::shared_ptr
134 
135 VTK_ABI_NAMESPACE_BEGIN
136 class vtkBitArray;
137 class vtkIdList;
139 class vtkTypeInt64Array;
140 
141 //=============================================================================
143 {
144  // Index of this tree in the hypertree grid
146 
147  // Number of levels in the tree
148  unsigned int NumberOfLevels;
149 
150  // Number of vertices in this tree (coarse and leaves)
152 
153  // Number of nodes (non-leaf vertices) in the tree
155 
156  // Offset start for the implicit global index mapping fixed by
157  // SetGlobalIndexStart after create a tree.
158  // If you don't choose implicit global index mapping then this
159  // value is -1. Then, you must to descrieb explicit global index
160  // mapping by using then SetGlobalIndexFromLocal for each cell
161  // in tree.
162  // The extra cost is equivalent to the cost of a field of values
163  // of cells.
165 };
166 
167 //=============================================================================
168 class VTKCOMMONDATAMODEL_EXPORT vtkHyperTree : public vtkObject
169 {
170 public:
171  vtkTypeMacro(vtkHyperTree, vtkObject);
172  void PrintSelf(ostream& os, vtkIndent indent) override;
173 
182  unsigned char branchFactor, unsigned char dimension, unsigned char numberOfChildren);
183 
203  virtual void InitializeForReader(vtkIdType numberOfLevels, vtkIdType nbVertices,
204  vtkIdType nbVerticesOfLastLevel, vtkBitArray* isParent, vtkBitArray* isMasked,
205  vtkBitArray* outIsMasked) = 0;
206 
228  vtkBitArray* descriptor, vtkIdType numberOfBits, vtkIdType startIndex = 0) = 0;
229 
268  vtkTypeInt64Array* numberOfVerticesPerDepth, vtkBitArray* descriptor,
269  vtkIdList* breadthFirstIdMap) = 0;
270 
277 
285  virtual vtkHyperTree* Freeze(const char* mode) = 0;
286 
288 
292  void SetTreeIndex(vtkIdType treeIndex)
293  {
294  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
295  this->Datas->TreeIndex = treeIndex;
296  }
298  {
299  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
300  return this->Datas->TreeIndex;
301  }
303 
307  unsigned int GetNumberOfLevels() const
308  {
309  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
310  assert("post: result_greater_or_equal_to_one" && this->Datas->NumberOfLevels >= 1);
311  return this->Datas->NumberOfLevels;
312  }
313 
318  {
319  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
320  return this->Datas->NumberOfVertices;
321  }
322 
327  {
328  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
329  return this->Datas->NumberOfNodes;
330  }
331 
336  {
337  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
338  return this->Datas->NumberOfVertices - this->Datas->NumberOfNodes;
339  }
340 
344  int GetBranchFactor() const { return this->BranchFactor; }
345 
349  int GetDimension() const { return this->Dimension; }
350 
355  vtkIdType GetNumberOfChildren() const { return this->NumberOfChildren; }
356 
358 
362  void GetScale(double s[3]) const;
363 
364  double GetScale(unsigned int d) const;
366 
372  std::shared_ptr<vtkHyperTreeGridScales> InitializeScales(
373  const double* scales, bool reinitialize = false) const;
374 
385  static vtkHyperTree* CreateInstance(unsigned char branchFactor, unsigned char dimension);
390  virtual unsigned long GetActualMemorySizeBytes() = 0;
391 
396  unsigned int GetActualMemorySize()
397  {
398  // in kilibytes
399  return static_cast<unsigned int>(this->GetActualMemorySizeBytes() / 1024);
400  }
401 
411  virtual bool IsGlobalIndexImplicit() = 0;
412 
432  virtual void SetGlobalIndexStart(vtkIdType start) = 0;
433 
439  {
440  assert("pre: datas_non_nullptr" && this->Datas != nullptr);
441  return this->Datas->GlobalIndexStart;
442  }
443 
454 
464 
469  virtual vtkIdType GetGlobalNodeIndexMax() const = 0;
470 
475  virtual bool IsLeaf(vtkIdType index) const = 0;
476 
482  virtual void SubdivideLeaf(vtkIdType index, unsigned int level) = 0;
483 
490  virtual bool IsTerminalNode(vtkIdType index) const = 0;
491 
499  virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const = 0;
500 
505  virtual const unsigned int* GetElderChildIndexArray(size_t& nbElements) const = 0;
506 
508 
514  void SetScales(std::shared_ptr<vtkHyperTreeGridScales> scales) const { this->Scales = scales; }
516 
518 
521  bool HasScales() const { return (this->Scales != nullptr); }
523 
525 
528  std::shared_ptr<vtkHyperTreeGridScales> GetScales() const
529  {
530  assert(this->Scales != nullptr);
531  return this->Scales;
532  }
534 
535 protected:
537 
538  ~vtkHyperTree() override = default;
539 
540  virtual void InitializePrivate() = 0;
541  virtual void PrintSelfPrivate(ostream& os, vtkIndent indent) = 0;
542  virtual void CopyStructurePrivate(vtkHyperTree* ht) = 0;
543 
544  //-- Global information
545 
546  // Branching factor of tree (2 or 3)
547  unsigned char BranchFactor;
548 
549  // Dimension of tree (1, 2, or 3)
550  unsigned char Dimension;
551 
552  // Number of children for coarse cell
553  unsigned char NumberOfChildren;
554 
555  //-- Local information
556  std::shared_ptr<vtkHyperTreeData> Datas;
557 
558  // Storage of pre-computed per-level cell scales
559  // In hypertree grid, one description by hypertree.
560  // In Uniform hypertree grid, one description by hypertree grid
561  // (all cells, different hypertree, are identical by level).
562  mutable std::shared_ptr<vtkHyperTreeGridScales> Scales;
563 
564 private:
565  void InitializeBase(
566  unsigned char branchFactor, unsigned char dimension, unsigned char numberOfChildren);
567  vtkHyperTree(const vtkHyperTree&) = delete;
568  void operator=(const vtkHyperTree&) = delete;
569 };
570 
571 VTK_ABI_NAMESPACE_END
572 #endif
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:29
A specifalized type of vtkHyperTreeGrid for the case when root cells have uniform sizes in each direc...
A data object structured as a tree.
Definition: vtkHyperTree.h:169
virtual vtkHyperTree * Freeze(const char *mode)=0
Return a freeze instance (a priori compact but potentially unmodifiable).
std::shared_ptr< vtkHyperTreeGridScales > Scales
Definition: vtkHyperTree.h:562
virtual vtkIdType GetGlobalIndexFromLocal(vtkIdType index) const =0
Get the global id of a local node identified by index.
unsigned char BranchFactor
Definition: vtkHyperTree.h:547
virtual void BuildFromBreadthFirstOrderDescriptor(vtkBitArray *descriptor, vtkIdType numberOfBits, vtkIdType startIndex=0)=0
This method builds the indexing of this tree given a breadth first order descriptor.
void GetScale(double s[3]) const
Set/Get scale of the tree in each direction for the ground level (0).
virtual void PrintSelfPrivate(ostream &os, vtkIndent indent)=0
virtual void SubdivideLeaf(vtkIdType index, unsigned int level)=0
Subdivide a vertice, only if its a leaf.
virtual void SetGlobalIndexFromLocal(vtkIdType index, vtkIdType global)=0
Set the mapping between a node index in tree and a explicit global index mapping.
vtkIdType GetNumberOfVertices() const
Return the number of all vertices (coarse and fine) in the tree.
Definition: vtkHyperTree.h:317
static vtkHyperTree * CreateInstance(unsigned char branchFactor, unsigned char dimension)
Return an instance of an implementation of a hypertree for given branch factor and dimension.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual const unsigned int * GetElderChildIndexArray(size_t &nbElements) const =0
Return the elder child index array, internals of the tree structure Should be used with great care,...
vtkIdType GetGlobalIndexStart() const
Get the start global index for the current tree for implicit global index mapping.
Definition: vtkHyperTree.h:438
unsigned int GetNumberOfLevels() const
Return the number of levels.
Definition: vtkHyperTree.h:307
virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const =0
Return the elder child index, local index node of first child, of node, coarse cell,...
std::shared_ptr< vtkHyperTreeGridScales > InitializeScales(const double *scales, bool reinitialize=false) const
In an hypertree, all cells are the same size by level.
double GetScale(unsigned int d) const
Set/Get scale of the tree in each direction for the ground level (0).
unsigned char Dimension
Definition: vtkHyperTree.h:550
unsigned int GetActualMemorySize()
Return memory used in kibibytes (1024 bytes).
Definition: vtkHyperTree.h:396
bool HasScales() const
Return the existence scales.
Definition: vtkHyperTree.h:521
vtkIdType GetNumberOfNodes() const
Return the number of nodes (coarse) in the tree.
Definition: vtkHyperTree.h:326
int GetBranchFactor() const
Return the branch factor of the tree.
Definition: vtkHyperTree.h:344
virtual void SetGlobalIndexStart(vtkIdType start)=0
Set the start implicit global index mapping for the first cell in the current tree.
virtual void InitializePrivate()=0
std::shared_ptr< vtkHyperTreeGridScales > GetScales() const
Return all scales.
Definition: vtkHyperTree.h:528
std::shared_ptr< vtkHyperTreeData > Datas
Definition: vtkHyperTree.h:556
unsigned char NumberOfChildren
Definition: vtkHyperTree.h:553
void CopyStructure(vtkHyperTree *ht)
Copy the structure by sharing the decomposition description of the tree.
virtual bool IsGlobalIndexImplicit()=0
Return if implicit global index mapping has been used.
virtual bool IsTerminalNode(vtkIdType index) const =0
Return if a vertice identified by index in tree as a terminal node.
virtual void CopyStructurePrivate(vtkHyperTree *ht)=0
vtkIdType GetTreeIndex() const
Set/Get tree index in hypertree grid.
Definition: vtkHyperTree.h:297
void Initialize(unsigned char branchFactor, unsigned char dimension, unsigned char numberOfChildren)
Restore the initial state: only one vertice is then a leaf: the root cell for the hypertree.
void SetScales(std::shared_ptr< vtkHyperTreeGridScales > scales) const
In an hypertree, all cells are the same size by level.
Definition: vtkHyperTree.h:514
vtkIdType GetNumberOfLeaves() const
Return the number of leaf (fine) in the tree.
Definition: vtkHyperTree.h:335
int GetDimension() const
Return the spatial dimension of the tree.
Definition: vtkHyperTree.h:349
virtual void ComputeBreadthFirstOrderDescriptor(vtkBitArray *inputMask, vtkTypeInt64Array *numberOfVerticesPerDepth, vtkBitArray *descriptor, vtkIdList *breadthFirstIdMap)=0
This method computes the breadth first order descriptor of the current tree.
~vtkHyperTree() override=default
vtkIdType GetNumberOfChildren() const
Return the number of children per node of the tree.
Definition: vtkHyperTree.h:355
virtual vtkIdType GetGlobalNodeIndexMax() const =0
Return the maximum value reached by global index mapping (implicit or explicit).
virtual void InitializeForReader(vtkIdType numberOfLevels, vtkIdType nbVertices, vtkIdType nbVerticesOfLastLevel, vtkBitArray *isParent, vtkBitArray *isMasked, vtkBitArray *outIsMasked)=0
Restore a state from read data, without using a cursor Call after create hypertree with initialize.
virtual unsigned long GetActualMemorySizeBytes()=0
Return memory used in bytes.
virtual bool IsLeaf(vtkIdType index) const =0
Return if a vertice identified by index in tree as being leaf.
void SetTreeIndex(vtkIdType treeIndex)
Set/Get tree index in hypertree grid.
Definition: vtkHyperTree.h:292
list of point or cell ids
Definition: vtkIdList.h:133
a simple class to control print indentation
Definition: vtkIndent.h:108
abstract base class for most VTK objects
Definition: vtkObject.h:162
@ level
Definition: vtkX3D.h:395
@ mode
Definition: vtkX3D.h:247
@ index
Definition: vtkX3D.h:246
unsigned int NumberOfLevels
Definition: vtkHyperTree.h:148
vtkIdType NumberOfVertices
Definition: vtkHyperTree.h:151
vtkIdType TreeIndex
Definition: vtkHyperTree.h:145
vtkIdType NumberOfNodes
Definition: vtkHyperTree.h:154
vtkIdType GlobalIndexStart
Definition: vtkHyperTree.h:164
int vtkIdType
Definition: vtkType.h:315
#define VTK_NEWINSTANCE