VTK  9.1.0
vtkHyperTree.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkHyperTree.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
135 #ifndef vtkHyperTree_h
136 #define vtkHyperTree_h
137 
138 #include "vtkCommonDataModelModule.h" // For export macro
139 #include "vtkObject.h"
140 
141 #include <cassert> // Used internally
142 #include <memory> // std::shared_ptr
143 
144 class vtkBitArray;
145 class vtkIdList;
147 class vtkTypeInt64Array;
148 
149 //=============================================================================
151 {
152  // Index of this tree in the hypertree grid
154 
155  // Number of levels in the tree
156  unsigned int NumberOfLevels;
157 
158  // Number of vertices in this tree (coarse and leaves)
160 
161  // Number of nodes (non-leaf vertices) in the tree
163 
164  // Offset start for the implicit global index mapping fixed by
165  // SetGlobalIndexStart after create a tree.
166  // If you don't choose implicit global index mapping then this
167  // value is -1. Then, you must to describ explicit global index
168  // mapping by using then SetGlobalIndexFromLocal for each cell
169  // in tree.
170  // The extra cost is equivalent to the cost of a field of values
171  // of cells.
173 };
174 
175 //=============================================================================
176 class VTKCOMMONDATAMODEL_EXPORT vtkHyperTree : public vtkObject
177 {
178 public:
179  vtkTypeMacro(vtkHyperTree, vtkObject);
180 
181  void PrintSelf(ostream& os, vtkIndent indent) override;
182 
191  unsigned char branchFactor, unsigned char dimension, unsigned char numberOfChildren);
192 
212  virtual void InitializeForReader(vtkIdType numberOfLevels, vtkIdType nbVertices,
213  vtkIdType nbVerticesOfLastLevel, vtkBitArray* isParent, vtkBitArray* isMasked,
214  vtkBitArray* outIsMasked) = 0;
215 
237  vtkBitArray* descriptor, vtkIdType numberOfBits, vtkIdType startIndex = 0) = 0;
238 
277  vtkTypeInt64Array* numberOfVerticesPerDepth, vtkBitArray* descriptor,
278  vtkIdList* breadthFirstIdMap) = 0;
279 
286 
294  virtual vtkHyperTree* Freeze(const char* mode) = 0;
295 
297 
301  void SetTreeIndex(vtkIdType treeIndex) { this->Datas->TreeIndex = treeIndex; }
302  vtkIdType GetTreeIndex() const { return this->Datas->TreeIndex; }
304 
308  unsigned int GetNumberOfLevels() const
309  {
310  assert("post: result_greater_or_equal_to_one" && this->Datas->NumberOfLevels >= 1);
311  return this->Datas->NumberOfLevels;
312  }
313 
317  vtkIdType GetNumberOfVertices() const { return this->Datas->NumberOfVertices; }
318 
322  vtkIdType GetNumberOfNodes() const { return this->Datas->NumberOfNodes; }
323 
328  {
329  return this->Datas->NumberOfVertices - this->Datas->NumberOfNodes;
330  }
331 
335  int GetBranchFactor() const { return this->BranchFactor; }
336 
340  int GetDimension() const { return this->Dimension; }
341 
346  vtkIdType GetNumberOfChildren() const { return this->NumberOfChildren; }
347 
349 
353  void GetScale(double s[3]) const;
354 
355  double GetScale(unsigned int d) const;
357 
363  std::shared_ptr<vtkHyperTreeGridScales> InitializeScales(
364  const double* scales, bool reinitialize = false) const;
365 
376  static vtkHyperTree* CreateInstance(unsigned char branchFactor, unsigned char dimension);
381  virtual unsigned long GetActualMemorySizeBytes() = 0;
382 
387  unsigned int GetActualMemorySize()
388  {
389  // in kilibytes
390  return static_cast<unsigned int>(this->GetActualMemorySizeBytes() / 1024);
391  }
392 
402  virtual bool IsGlobalIndexImplicit() = 0;
403 
423  virtual void SetGlobalIndexStart(vtkIdType start) = 0;
424 
429  vtkIdType GetGlobalIndexStart() const { return this->Datas->GlobalIndexStart; }
430 
441 
451 
456  virtual vtkIdType GetGlobalNodeIndexMax() const = 0;
457 
462  virtual bool IsLeaf(vtkIdType index) const = 0;
463 
469  virtual void SubdivideLeaf(vtkIdType index, unsigned int level) = 0;
470 
477  virtual bool IsTerminalNode(vtkIdType index) const = 0;
478 
486  virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const = 0;
487 
492  virtual const unsigned int* GetElderChildIndexArray(size_t& nbElements) const = 0;
493 
495 
501  void SetScales(std::shared_ptr<vtkHyperTreeGridScales> scales) const { this->Scales = scales; }
503 
505 
508  bool HasScales() const { return (this->Scales != nullptr); }
510 
512 
515  std::shared_ptr<vtkHyperTreeGridScales> GetScales() const
516  {
517  assert(this->Scales != nullptr);
518  return this->Scales;
519  }
521 
522 protected:
524 
525  ~vtkHyperTree() override = default;
526 
527  virtual void InitializePrivate() = 0;
528  virtual void PrintSelfPrivate(ostream& os, vtkIndent indent) = 0;
529  virtual void CopyStructurePrivate(vtkHyperTree* ht) = 0;
530 
531  //-- Global information
532 
533  // Branching factor of tree (2 or 3)
534  unsigned char BranchFactor;
535 
536  // Dimension of tree (1, 2, or 3)
537  unsigned char Dimension;
538 
539  // Number of children for coarse cell
540  unsigned char NumberOfChildren;
541 
542  //-- Local information
543  std::shared_ptr<vtkHyperTreeData> Datas;
544 
545  // Storage of pre-computed per-level cell scales
546  // In hypertree grid, one description by hypertree.
547  // In Uniform hypertree grid, one description by hypertree grid
548  // (all cells, differents hypertree, are identicals by level).
549  mutable std::shared_ptr<vtkHyperTreeGridScales> Scales;
550 
551 private:
552  void InitializeBase(
553  unsigned char branchFactor, unsigned char dimension, unsigned char numberOfChildren);
554  vtkHyperTree(const vtkHyperTree&) = delete;
555  void operator=(const vtkHyperTree&) = delete;
556 };
557 
558 #endif
vtkHyperTreeData::GlobalIndexStart
vtkIdType GlobalIndexStart
Definition: vtkHyperTree.h:172
vtkHyperTreeData::NumberOfNodes
vtkIdType NumberOfNodes
Definition: vtkHyperTree.h:162
vtkHyperTree::GetGlobalIndexFromLocal
virtual vtkIdType GetGlobalIndexFromLocal(vtkIdType index) const =0
Get the global id of a local node identified by index.
vtkHyperTree::vtkHyperTree
vtkHyperTree()
vtkHyperTree::CopyStructure
void CopyStructure(vtkHyperTree *ht)
Copy the structure by sharing the decomposition description of the tree.
vtkHyperTree::SetTreeIndex
void SetTreeIndex(vtkIdType treeIndex)
Set/Get tree index in hypertree grid.
Definition: vtkHyperTree.h:301
vtkHyperTree::IsGlobalIndexImplicit
virtual bool IsGlobalIndexImplicit()=0
Return if implicit global index maping has been used.
global
Definition: UnstructuredGhostZonesCommon.h:31
vtkHyperTree::GetNumberOfVertices
vtkIdType GetNumberOfVertices() const
Return the number of all vertices (coarse and fine) in the tree.
Definition: vtkHyperTree.h:317
vtkHyperTree::GetNumberOfLevels
unsigned int GetNumberOfLevels() const
Return the number of levels.
Definition: vtkHyperTree.h:308
vtkHyperTree::GetActualMemorySizeBytes
virtual unsigned long GetActualMemorySizeBytes()=0
Return memory used in bytes.
vtkHyperTree::Datas
std::shared_ptr< vtkHyperTreeData > Datas
Definition: vtkHyperTree.h:543
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkHyperTree::GetElderChildIndex
virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const =0
Return the elder child index, local index node of first child, of node, coarse cell,...
vtkHyperTree::InitializePrivate
virtual void InitializePrivate()=0
vtkHyperTree::GetDimension
int GetDimension() const
Return the spatial dimension of the tree.
Definition: vtkHyperTree.h:340
vtkHyperTree::GetScale
void GetScale(double s[3]) const
Set/Get scale of the tree in each direction for the ground level (0).
vtkHyperTree::GetElderChildIndexArray
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,...
vtkHyperTree::SetGlobalIndexFromLocal
virtual void SetGlobalIndexFromLocal(vtkIdType index, vtkIdType global)=0
Set the mapping between a node index in tree and a explicit global index mapping.
vtkHyperTree::~vtkHyperTree
~vtkHyperTree() override=default
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:82
vtkHyperTreeData::NumberOfVertices
vtkIdType NumberOfVertices
Definition: vtkHyperTree.h:159
vtkHyperTree::GetTreeIndex
vtkIdType GetTreeIndex() const
Set/Get tree index in hypertree grid.
Definition: vtkHyperTree.h:302
vtkHyperTree::GetNumberOfNodes
vtkIdType GetNumberOfNodes() const
Return the number of nodes (coarse) in the tree.
Definition: vtkHyperTree.h:322
vtkHyperTree::GetActualMemorySize
unsigned int GetActualMemorySize()
Return memory used in kibibytes (1024 bytes).
Definition: vtkHyperTree.h:387
vtkHyperTree::NumberOfChildren
unsigned char NumberOfChildren
Definition: vtkHyperTree.h:540
vtkHyperTree::ComputeBreadthFirstOrderDescriptor
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::IsLeaf
virtual bool IsLeaf(vtkIdType index) const =0
Return if a vertice identified by index in tree as being leaf.
vtkHyperTreeGridScales
A specifalized type of vtkHyperTreeGrid for the case when root cells have uniform sizes in each direc...
Definition: vtkHyperTreeGridScales.h:35
vtkX3D::level
@ level
Definition: vtkX3D.h:401
vtkHyperTree::CopyStructurePrivate
virtual void CopyStructurePrivate(vtkHyperTree *ht)=0
vtkHyperTreeData::TreeIndex
vtkIdType TreeIndex
Definition: vtkHyperTree.h:153
vtkHyperTree::PrintSelfPrivate
virtual void PrintSelfPrivate(ostream &os, vtkIndent indent)=0
vtkHyperTree::IsTerminalNode
virtual bool IsTerminalNode(vtkIdType index) const =0
Return if a vertice identified by index in tree as a terminal node.
vtkHyperTree::SetGlobalIndexStart
virtual void SetGlobalIndexStart(vtkIdType start)=0
Set the start implicit global index mapping for the first cell in the current tree.
vtkHyperTree::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkHyperTreeData::NumberOfLevels
unsigned int NumberOfLevels
Definition: vtkHyperTree.h:156
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:140
vtkHyperTree
A data object structured as a tree.
Definition: vtkHyperTree.h:177
vtkHyperTree::GetScales
std::shared_ptr< vtkHyperTreeGridScales > GetScales() const
Return all scales.
Definition: vtkHyperTree.h:515
vtkHyperTree::GetScale
double GetScale(unsigned int d) const
Set/Get scale of the tree in each direction for the ground level (0).
vtkHyperTree::Freeze
virtual vtkHyperTree * Freeze(const char *mode)=0
Return a freeze instance (a priori compact but potentially unmodifiable).
vtkHyperTree::SubdivideLeaf
virtual void SubdivideLeaf(vtkIdType index, unsigned int level)=0
Subdivide a vertice, only if its a leaf.
vtkObject.h
vtkHyperTree::GetBranchFactor
int GetBranchFactor() const
Return the branch factor of the tree.
Definition: vtkHyperTree.h:335
vtkHyperTree::InitializeScales
std::shared_ptr< vtkHyperTreeGridScales > InitializeScales(const double *scales, bool reinitialize=false) const
In an hypertree, all cells are the same size by level.
vtkHyperTree::Scales
std::shared_ptr< vtkHyperTreeGridScales > Scales
Definition: vtkHyperTree.h:549
vtkHyperTree::HasScales
bool HasScales() const
Return the existence scales.
Definition: vtkHyperTree.h:508
vtkHyperTree::Dimension
unsigned char Dimension
Definition: vtkHyperTree.h:537
vtkHyperTree::GetNumberOfLeaves
vtkIdType GetNumberOfLeaves() const
Return the number of leaf (fine) in the tree.
Definition: vtkHyperTree.h:327
vtkHyperTree::GetGlobalNodeIndexMax
virtual vtkIdType GetGlobalNodeIndexMax() const =0
Return the maximum value reached by global index mapping (implicit or explicit).
vtkHyperTree::GetGlobalIndexStart
vtkIdType GetGlobalIndexStart() const
Get the start global index for the current tree for implicit global index mapping.
Definition: vtkHyperTree.h:429
vtkHyperTree::Initialize
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.
vtkHyperTree::BranchFactor
unsigned char BranchFactor
Definition: vtkHyperTree.h:534
vtkBitArray
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:34
vtkX3D::mode
@ mode
Definition: vtkX3D.h:253
vtkHyperTree::GetNumberOfChildren
vtkIdType GetNumberOfChildren() const
Return the number of children per node of the tree.
Definition: vtkHyperTree.h:346
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:44
vtkHyperTree::BuildFromBreadthFirstOrderDescriptor
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.
vtkHyperTree::CreateInstance
static vtkHyperTree * CreateInstance(unsigned char branchFactor, unsigned char dimension)
Return an instance of an implementation of a hypertree for given branch factor and dimension.
vtkHyperTreeData
Definition: vtkHyperTree.h:151
vtkX3D::index
@ index
Definition: vtkX3D.h:252
vtkHyperTree::SetScales
void SetScales(std::shared_ptr< vtkHyperTreeGridScales > scales) const
In an hypertree, all cells are the same size by level.
Definition: vtkHyperTree.h:501
vtkHyperTree::InitializeForReader
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.