VTK  9.7.20260718
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
120
121#ifndef vtkHyperTree_h
122#define vtkHyperTree_h
123
124#include "vtkCommonDataModelModule.h" // For export macro
125#include "vtkObject.h"
126
127#include <cassert> // Used internally
128#include <memory> // std::shared_ptr
129
130VTK_ABI_NAMESPACE_BEGIN
131class vtkBitArray;
132class vtkIdList;
134class vtkTypeInt64Array;
135
136//=============================================================================
138{
139 // Index of this tree in the hypertree grid
141
142 // Number of levels in the tree
143 unsigned int NumberOfLevels;
144
145 // Number of vertices in this tree (coarse and leaves)
147
148 // Number of nodes (non-leaf vertices) in the tree
150
151 // Offset start for the implicit global index mapping fixed by
152 // SetGlobalIndexStart after create a tree.
153 // If you don't choose implicit global index mapping then this
154 // value is -1. Then, you must to descrieb explicit global index
155 // mapping by using then SetGlobalIndexFromLocal for each cell
156 // in tree.
157 // The extra cost is equivalent to the cost of a field of values
158 // of cells.
160
161 // Storage to record the parent of each tree vertex
162 std::vector<unsigned int> ParentToElderChild;
163
164 // Storage to record the local to global id mapping
165 std::vector<vtkIdType> GlobalIndexTable;
166};
167
168//=============================================================================
169class VTKCOMMONDATAMODEL_EXPORT vtkHyperTree : public vtkObject
170{
171public:
172 static vtkHyperTree* New();
173 vtkTypeMacro(vtkHyperTree, vtkObject);
174 void PrintSelf(ostream& os, vtkIndent indent) override;
175
184 bool Initialize(unsigned char branchFactor, unsigned char dimension);
185
205 virtual void InitializeForReader(vtkIdType numberOfLevels, vtkIdType nbVertices,
206 vtkIdType nbVerticesOfLastLevel, vtkBitArray* isParent, vtkBitArray* isMasked,
207 vtkBitArray* outIsMasked);
208
230 vtkBitArray* descriptor, vtkIdType numberOfBits, vtkIdType startIndex = 0);
231
271 virtual void ComputeBreadthFirstOrderDescriptor(unsigned int depthLimiter, vtkBitArray* inputMask,
272 vtkTypeInt64Array* numberOfVerticesPerDepth, vtkBitArray* descriptor,
273 vtkIdList* breadthFirstIdMap);
274
281
283
287 void SetTreeIndex(vtkIdType treeIndex)
288 {
289 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
290 this->Datas->TreeIndex = treeIndex;
291 }
293 {
294 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
295 return this->Datas->TreeIndex;
296 }
297
298
302 unsigned int GetNumberOfLevels() const
303 {
304 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
305 assert("post: result_greater_or_equal_to_one" && this->Datas->NumberOfLevels >= 1);
306 return this->Datas->NumberOfLevels;
307 }
308
313 {
314 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
315 return this->Datas->NumberOfVertices;
316 }
317
322 {
323 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
324 return this->Datas->NumberOfNodes;
325 }
326
331 {
332 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
333 return this->Datas->NumberOfVertices - this->Datas->NumberOfNodes;
334 }
335
339 int GetBranchFactor() const { return this->BranchFactor; }
340
344 int GetDimension() const { return this->Dimension; }
345
350 vtkIdType GetNumberOfChildren() const { return this->NumberOfChildren; }
351
353
357 void GetScale(double s[3]) const;
358 double GetScale(unsigned int d) const;
360
366 std::shared_ptr<vtkHyperTreeGridScales> InitializeScales(
367 const double* scales, bool reinitialize = false);
368
373 virtual unsigned long GetActualMemorySizeBytes();
374
379 unsigned int GetActualMemorySize()
380 {
381 // in kilibytes
382 return static_cast<unsigned int>(this->GetActualMemorySizeBytes() / 1024);
383 }
384
394 virtual bool IsGlobalIndexImplicit();
395
415 virtual void SetGlobalIndexStart(vtkIdType start);
416
422 {
423 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
424 return this->Datas->GlobalIndexStart;
425 }
426
437
447
453
458 virtual bool IsLeaf(vtkIdType index) const;
459
465 virtual void SubdivideLeaf(vtkIdType index, unsigned int level);
466
473 virtual bool IsTerminalNode(vtkIdType index) const;
474
482 virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const;
483
488 virtual const unsigned int* GetElderChildIndexArray(size_t& nbElements) const;
489
491
497 void SetScales(std::shared_ptr<vtkHyperTreeGridScales> scales) { this->Scales = scales; }
499
501
504 bool HasScales() const { return (this->Scales != nullptr); }
506
508
511 std::shared_ptr<vtkHyperTreeGridScales> GetScales() const
512 {
513 assert(this->Scales != nullptr);
514 return this->Scales;
515 }
516
517
518protected:
520 ~vtkHyperTree() override = default;
521
522private:
523 vtkHyperTree(const vtkHyperTree&) = delete;
524 void operator=(const vtkHyperTree&) = delete;
525
526 bool IsChildLeaf(vtkIdType index_parent, unsigned int ichild) const;
527
536 void ComputeBreadthFirstOrderDescriptorImpl(unsigned int depthLimiter, vtkBitArray* inputMask,
537 unsigned int depth, vtkIdType index, std::vector<std::vector<bool>>& descriptorPerDepth,
538 std::vector<std::vector<vtkIdType>>& breadthFirstOrderIdMapPerDepth);
539
540 //-- Global information
541
542 // Branching factor of tree (2 or 3)
543 unsigned char BranchFactor;
544
545 // Dimension of tree (1, 2, or 3)
546 unsigned char Dimension;
547
548 // Number of children for coarse cell
549 unsigned char NumberOfChildren;
550
551 //-- Local information
552 std::shared_ptr<vtkHyperTreeData> Datas;
553
554 // Storage of pre-computed per-level cell scales
555 // In hypertree grid, one description by hypertree.
556 // In Uniform hypertree grid, one description by hypertree grid
557 // (all cells, different hypertree, are identical by level).
558 std::shared_ptr<vtkHyperTreeGridScales> Scales;
559};
560
561VTK_ABI_NAMESPACE_END
562#endif
dynamic, self-adjusting array of bits
Definition vtkBitArray.h:33
Dynamic generation of scales for vtkHyperTree.
virtual vtkIdType GetGlobalNodeIndexMax() const
Return the maximum value reached by global index mapping (implicit or explicit).
void GetScale(double s[3]) const
Set/Get scale of the tree in each direction for the ground level (0).
virtual bool IsTerminalNode(vtkIdType index) const
Return if a vertice identified by index in tree as a terminal node.
vtkIdType GetNumberOfVertices() const
Return the number of all vertices (coarse and fine) in the tree.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkIdType GetGlobalIndexStart() const
Get the start global index for the current tree for implicit global index mapping.
unsigned int GetNumberOfLevels() const
Return the number of levels.
double GetScale(unsigned int d) const
Set/Get scale of the tree in each direction for the ground level (0).
virtual void SubdivideLeaf(vtkIdType index, unsigned int level)
Subdivide a vertice, only if its a leaf.
std::shared_ptr< vtkHyperTreeGridScales > InitializeScales(const double *scales, bool reinitialize=false)
In an hypertree, all cells are the same size by level.
std::shared_ptr< vtkHyperTreeGridScales > GetScales() const
Return all scales.
virtual bool IsLeaf(vtkIdType index) const
Return if a vertice identified by index in tree as being leaf.
virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const
Return the elder child index, local index node of first child, of node, coarse cell,...
unsigned int GetActualMemorySize()
Return memory used in kibibytes (1024 bytes).
bool HasScales() const
Return the existence scales.
vtkIdType GetNumberOfNodes() const
Return the number of nodes (coarse) in the tree.
int GetBranchFactor() const
Return the branch factor of the tree.
void SetScales(std::shared_ptr< vtkHyperTreeGridScales > scales)
In an hypertree, all cells are the same size by level.
virtual void BuildFromBreadthFirstOrderDescriptor(vtkBitArray *descriptor, vtkIdType numberOfBits, vtkIdType startIndex=0)
This method builds the indexing of this tree given a breadth first order descriptor.
virtual const unsigned int * GetElderChildIndexArray(size_t &nbElements) const
Return the elder child index array, internals of the tree structure Should be used with great care,...
void CopyStructure(vtkHyperTree *ht)
Copy the structure by sharing the decomposition description of the tree.
virtual vtkIdType GetGlobalIndexFromLocal(vtkIdType index) const
Get the global id of a local node identified by index.
vtkIdType GetTreeIndex() const
Set/Get tree index in hypertree grid.
virtual void ComputeBreadthFirstOrderDescriptor(unsigned int depthLimiter, vtkBitArray *inputMask, vtkTypeInt64Array *numberOfVerticesPerDepth, vtkBitArray *descriptor, vtkIdList *breadthFirstIdMap)
This method computes the breadth first order descriptor of the current tree.
virtual void SetGlobalIndexStart(vtkIdType start)
Set the start implicit global index mapping for the first cell in the current tree.
vtkIdType GetNumberOfLeaves() const
Return the number of leaf (fine) in the tree.
int GetDimension() const
Return the spatial dimension of the tree.
virtual void SetGlobalIndexFromLocal(vtkIdType index, vtkIdType global)
Set the mapping between a node index in tree and a explicit global index mapping.
~vtkHyperTree() override=default
static vtkHyperTree * New()
vtkIdType GetNumberOfChildren() const
Return the number of children per node of the tree.
virtual bool IsGlobalIndexImplicit()
Return if implicit global index mapping has been used.
virtual void InitializeForReader(vtkIdType numberOfLevels, vtkIdType nbVertices, vtkIdType nbVerticesOfLastLevel, vtkBitArray *isParent, vtkBitArray *isMasked, vtkBitArray *outIsMasked)
Restore a state from read data, without using a cursor Call after create hypertree with initialize.
void SetTreeIndex(vtkIdType treeIndex)
Set/Get tree index in hypertree grid.
bool Initialize(unsigned char branchFactor, unsigned char dimension)
Restore the initial state: only one vertice is then a leaf: the root cell for the hypertree.
virtual unsigned long GetActualMemorySizeBytes()
Return memory used in bytes.
list of point or cell ids
Definition vtkIdList.h:135
a simple class to control print indentation
Definition vtkIndent.h:108
unsigned int NumberOfLevels
vtkIdType NumberOfVertices
std::vector< vtkIdType > GlobalIndexTable
vtkIdType TreeIndex
std::vector< unsigned int > ParentToElderChild
vtkIdType NumberOfNodes
vtkIdType GlobalIndexStart
int vtkIdType
Definition vtkType.h:363