VTK: Common/DataModel/vtkHyperTree.h Source File

| VTK 9.3.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
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;
138 class vtkHyperTreeGridScales;
139 class vtkTypeInt64Array;
140
141 //=============================================================================
142 struct vtkHyperTreeData
143 {
144 // Index of this tree in the hypertree grid
145 vtkIdType TreeIndex;
146
147 // Number of levels in the tree
148 unsigned int NumberOfLevels;
149
150 // Number of vertices in this tree (coarse and leaves)
151 vtkIdType NumberOfVertices;
152
153 // Number of nodes (non-leaf vertices) in the tree
154 vtkIdType NumberOfNodes;
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.
164 vtkIdType GlobalIndexStart;
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
181 void Initialize(
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
227 virtual void BuildFromBreadthFirstOrderDescriptor(
228 vtkBitArray* descriptor, vtkIdType numberOfBits, vtkIdType startIndex = 0) = 0;
229
267 virtual void ComputeBreadthFirstOrderDescriptor(vtkBitArray* inputMask,
268 vtkTypeInt64Array* numberOfVerticesPerDepth, vtkBitArray* descriptor,
269 vtkIdList* breadthFirstIdMap) = 0;
270
276 void CopyStructure(vtkHyperTree* ht);
277
285 virtual vtkHyperTree* Freeze(const char* mode) = 0;
286
288
292 void SetTreeIndex(vtkIdType treeIndex) { this->Datas->TreeIndex = treeIndex; }
293 vtkIdType GetTreeIndex() const { return this->Datas->TreeIndex; }
295
299 unsigned int GetNumberOfLevels() const
300 {
301 assert("post: result_greater_or_equal_to_one" && this->Datas->NumberOfLevels >= 1);
302 return this->Datas->NumberOfLevels;
303 }
304
308 vtkIdType GetNumberOfVertices() const { return this->Datas->NumberOfVertices; }
309
313 vtkIdType GetNumberOfNodes() const { return this->Datas->NumberOfNodes; }
314
318 vtkIdType GetNumberOfLeaves() const
319 {
320 return this->Datas->NumberOfVertices - this->Datas->NumberOfNodes;
321 }
322
326 int GetBranchFactor() const { return this->BranchFactor; }
327
331 int GetDimension() const { return this->Dimension; }
332
337 vtkIdType GetNumberOfChildren() const { return this->NumberOfChildren; }
338
340
344 void GetScale(double s[3]) const;
345
346 double GetScale(unsigned int d) const;
348
354 std::shared_ptr<vtkHyperTreeGridScales> InitializeScales(
355 const double* scales, bool reinitialize = false) const;
356
366 VTK_NEWINSTANCE
367 static vtkHyperTree* CreateInstance(unsigned char branchFactor, unsigned char dimension);
372 virtual unsigned long GetActualMemorySizeBytes() = 0;
373
378 unsigned int GetActualMemorySize()
379 {
380 // in kilibytes
381 return static_cast<unsigned int>(this->GetActualMemorySizeBytes() / 1024);
382 }
383
393 virtual bool IsGlobalIndexImplicit() = 0;
394
414 virtual void SetGlobalIndexStart(vtkIdType start) = 0;
415
420 vtkIdType GetGlobalIndexStart() const { return this->Datas->GlobalIndexStart; }
421
431 virtual void SetGlobalIndexFromLocal(vtkIdType index, vtkIdType global) = 0;
432
441 virtual vtkIdType GetGlobalIndexFromLocal(vtkIdType index) const = 0;
442
447 virtual vtkIdType GetGlobalNodeIndexMax() const = 0;
448
453 virtual bool IsLeaf(vtkIdType index) const = 0;
454
460 virtual void SubdivideLeaf(vtkIdType index, unsigned int level) = 0;
461
468 virtual bool IsTerminalNode(vtkIdType index) const = 0;
469
477 virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const = 0;
478
483 virtual const unsigned int* GetElderChildIndexArray(size_t& nbElements) const = 0;
484
486
492 void SetScales(std::shared_ptr<vtkHyperTreeGridScales> scales) const { this->Scales = scales; }
494
496
499 bool HasScales() const { return (this->Scales != nullptr); }
501
503
506 std::shared_ptr<vtkHyperTreeGridScales> GetScales() const
507 {
508 assert(this->Scales != nullptr);
509 return this->Scales;
510 }
512
513 protected:
514 vtkHyperTree();
515
516 ~vtkHyperTree() override = default;
517
518 virtual void InitializePrivate() = 0;
519 virtual void PrintSelfPrivate(ostream& os, vtkIndent indent) = 0;
520 virtual void CopyStructurePrivate(vtkHyperTree* ht) = 0;
521
522 //-- Global information
523
524 // Branching factor of tree (2 or 3)
525 unsigned char BranchFactor;
526
527 // Dimension of tree (1, 2, or 3)
528 unsigned char Dimension;
529
530 // Number of children for coarse cell
531 unsigned char NumberOfChildren;
532
533 //-- Local information
534 std::shared_ptr<vtkHyperTreeData> Datas;
535
536 // Storage of pre-computed per-level cell scales
537 // In hypertree grid, one description by hypertree.
538 // In Uniform hypertree grid, one description by hypertree grid
539 // (all cells, differents hypertree, are identicals by level).
540 mutable std::shared_ptr<vtkHyperTreeGridScales> Scales;
541
542 private:
543 void InitializeBase(
544 unsigned char branchFactor, unsigned char dimension, unsigned char numberOfChildren);
545 vtkHyperTree(const vtkHyperTree&) = delete;
546 void operator=(const vtkHyperTree&) = delete;
547 };
548
549 VTK_ABI_NAMESPACE_END
550 #endif
vtkBitArray
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:29
vtkHyperTreeGridScales
A specifalized type of vtkHyperTreeGrid for the case when root cells have uniform sizes in each direc...
Definition: vtkHyperTreeGridScales.h:27
vtkHyperTree
A data object structured as a tree.
Definition: vtkHyperTree.h:169
vtkHyperTree::Freeze
virtual vtkHyperTree * Freeze(const char *mode)=0
Return a freeze instance (a priori compact but potentially unmodifiable).
vtkHyperTree::Scales
std::shared_ptr< vtkHyperTreeGridScales > Scales
Definition: vtkHyperTree.h:540
vtkHyperTree::GetGlobalIndexFromLocal
virtual vtkIdType GetGlobalIndexFromLocal(vtkIdType index) const =0
Get the global id of a local node identified by index.
vtkHyperTree::BranchFactor
unsigned char BranchFactor
Definition: vtkHyperTree.h:525
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::GetScale
void GetScale(double s[3]) const
Set/Get scale of the tree in each direction for the ground level (0).
vtkHyperTree::PrintSelfPrivate
virtual void PrintSelfPrivate(ostream &os, vtkIndent indent)=0
vtkHyperTree::SubdivideLeaf
virtual void SubdivideLeaf(vtkIdType index, unsigned int level)=0
Subdivide a vertice, only if its a leaf.
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::GetNumberOfVertices
vtkIdType GetNumberOfVertices() const
Return the number of all vertices (coarse and fine) in the tree.
Definition: vtkHyperTree.h:308
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.
vtkHyperTree::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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::GetGlobalIndexStart
vtkIdType GetGlobalIndexStart() const
Get the start global index for the current tree for implicit global index mapping.
Definition: vtkHyperTree.h:420
vtkHyperTree::GetNumberOfLevels
unsigned int GetNumberOfLevels() const
Return the number of levels.
Definition: vtkHyperTree.h:299
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::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::GetScale
double GetScale(unsigned int d) const
Set/Get scale of the tree in each direction for the ground level (0).
vtkHyperTree::Dimension
unsigned char Dimension
Definition: vtkHyperTree.h:528
vtkHyperTree::GetActualMemorySize
unsigned int GetActualMemorySize()
Return memory used in kibibytes (1024 bytes).
Definition: vtkHyperTree.h:378
vtkHyperTree::HasScales
bool HasScales() const
Return the existence scales.
Definition: vtkHyperTree.h:499
vtkHyperTree::GetNumberOfNodes
vtkIdType GetNumberOfNodes() const
Return the number of nodes (coarse) in the tree.
Definition: vtkHyperTree.h:313
vtkHyperTree::GetBranchFactor
int GetBranchFactor() const
Return the branch factor of the tree.
Definition: vtkHyperTree.h:326
vtkHyperTree::SetGlobalIndexStart
virtual void SetGlobalIndexStart(vtkIdType start)=0
Set the start implicit global index mapping for the first cell in the current tree.
vtkHyperTree::InitializePrivate
virtual void InitializePrivate()=0
vtkHyperTree::GetScales
std::shared_ptr< vtkHyperTreeGridScales > GetScales() const
Return all scales.
Definition: vtkHyperTree.h:506
vtkHyperTree::Datas
std::shared_ptr< vtkHyperTreeData > Datas
Definition: vtkHyperTree.h:534
vtkHyperTree::NumberOfChildren
unsigned char NumberOfChildren
Definition: vtkHyperTree.h:531
vtkHyperTree::CopyStructure
void CopyStructure(vtkHyperTree *ht)
Copy the structure by sharing the decomposition description of the tree.
vtkHyperTree::IsGlobalIndexImplicit
virtual bool IsGlobalIndexImplicit()=0
Return if implicit global index mapping has been used.
vtkHyperTree::IsTerminalNode
virtual bool IsTerminalNode(vtkIdType index) const =0
Return if a vertice identified by index in tree as a terminal node.
vtkHyperTree::CopyStructurePrivate
virtual void CopyStructurePrivate(vtkHyperTree *ht)=0
vtkHyperTree::GetTreeIndex
vtkIdType GetTreeIndex() const
Set/Get tree index in hypertree grid.
Definition: vtkHyperTree.h:293
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::SetScales
void SetScales(std::shared_ptr< vtkHyperTreeGridScales > scales) const
In an hypertree, all cells are the same size by level.
Definition: vtkHyperTree.h:492
vtkHyperTree::GetNumberOfLeaves
vtkIdType GetNumberOfLeaves() const
Return the number of leaf (fine) in the tree.
Definition: vtkHyperTree.h:318
vtkHyperTree::vtkHyperTree
vtkHyperTree()
vtkHyperTree::GetDimension
int GetDimension() const
Return the spatial dimension of the tree.
Definition: vtkHyperTree.h:331
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::~vtkHyperTree
~vtkHyperTree() override=default
vtkHyperTree::GetNumberOfChildren
vtkIdType GetNumberOfChildren() const
Return the number of children per node of the tree.
Definition: vtkHyperTree.h:337
vtkHyperTree::GetGlobalNodeIndexMax
virtual vtkIdType GetGlobalNodeIndexMax() const =0
Return the maximum value reached by global index mapping (implicit or explicit).
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.
vtkHyperTree::GetActualMemorySizeBytes
virtual unsigned long GetActualMemorySizeBytes()=0
Return memory used in bytes.
vtkHyperTree::IsLeaf
virtual bool IsLeaf(vtkIdType index) const =0
Return if a vertice identified by index in tree as being leaf.
vtkHyperTree::SetTreeIndex
void SetTreeIndex(vtkIdType treeIndex)
Set/Get tree index in hypertree grid.
Definition: vtkHyperTree.h:292
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:32
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkX3D::level
@ level
Definition: vtkX3D.h:395
vtkX3D::mode
@ mode
Definition: vtkX3D.h:247
vtkX3D::index
@ index
Definition: vtkX3D.h:246
global
Definition: UnstructuredGhostZonesCommon.h:19
vtkHyperTreeData
Definition: vtkHyperTree.h:143
vtkHyperTreeData::NumberOfLevels
unsigned int NumberOfLevels
Definition: vtkHyperTree.h:148
vtkHyperTreeData::NumberOfVertices
vtkIdType NumberOfVertices
Definition: vtkHyperTree.h:151
vtkHyperTreeData::TreeIndex
vtkIdType TreeIndex
Definition: vtkHyperTree.h:145
vtkHyperTreeData::NumberOfNodes
vtkIdType NumberOfNodes
Definition: vtkHyperTree.h:154
vtkHyperTreeData::GlobalIndexStart
vtkIdType GlobalIndexStart
Definition: vtkHyperTree.h:164
vtkObject.h
vtkIdType
int vtkIdType
Definition: vtkType.h:315
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:32