VTK  9.4.20250206
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 "vtkDeprecation.h" // Include the macros.
131#include "vtkObject.h"
132
133#include <cassert> // Used internally
134#include <limits> // Used infinity
135#include <memory> // std::shared_ptr
136
137VTK_ABI_NAMESPACE_BEGIN
138class vtkBitArray;
139class vtkIdList;
141class vtkTypeInt64Array;
142
143//=============================================================================
145{
146 // Index of this tree in the hypertree grid
148
149 // Number of levels in the tree
150 unsigned int NumberOfLevels;
151
152 // Number of vertices in this tree (coarse and leaves)
154
155 // Number of nodes (non-leaf vertices) in the tree
157
158 // Offset start for the implicit global index mapping fixed by
159 // SetGlobalIndexStart after create a tree.
160 // If you don't choose implicit global index mapping then this
161 // value is -1. Then, you must to descrieb explicit global index
162 // mapping by using then SetGlobalIndexFromLocal for each cell
163 // in tree.
164 // The extra cost is equivalent to the cost of a field of values
165 // of cells.
167};
168
169//=============================================================================
170class VTKCOMMONDATAMODEL_EXPORT vtkHyperTree : public vtkObject
171{
172public:
173 vtkTypeMacro(vtkHyperTree, vtkObject);
174 void PrintSelf(ostream& os, vtkIndent indent) override;
175
184 unsigned char branchFactor, unsigned char dimension, unsigned char numberOfChildren);
185
205 virtual void InitializeForReader(vtkIdType numberOfLevels, vtkIdType nbVertices,
206 vtkIdType nbVerticesOfLastLevel, vtkBitArray* isParent, vtkBitArray* isMasked,
207 vtkBitArray* outIsMasked) = 0;
208
230 vtkBitArray* descriptor, vtkIdType numberOfBits, vtkIdType startIndex = 0) = 0;
231
271 virtual void ComputeBreadthFirstOrderDescriptor(unsigned int depthLimiter, vtkBitArray* inputMask,
272 vtkTypeInt64Array* numberOfVerticesPerDepth, vtkBitArray* descriptor,
273 vtkIdList* breadthFirstIdMap) = 0;
274
276 "You must use depthLimiter parameter for transmit the eponymous member of vtkHyperTreeGrid")
277 void ComputeBreadthFirstOrderDescriptor(vtkBitArray* inputMask,
278 vtkTypeInt64Array* numberOfVerticesPerDepth, vtkBitArray* descriptor,
279 vtkIdList* breadthFirstIdMap)
280 {
281 ComputeBreadthFirstOrderDescriptor(std::numeric_limits<unsigned int>::infinity(), inputMask,
282 numberOfVerticesPerDepth, descriptor, breadthFirstIdMap);
283 }
284
291
299 virtual vtkHyperTree* Freeze(const char* mode) = 0;
300
302
306 void SetTreeIndex(vtkIdType treeIndex)
307 {
308 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
309 this->Datas->TreeIndex = treeIndex;
310 }
312 {
313 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
314 return this->Datas->TreeIndex;
315 }
317
321 unsigned int GetNumberOfLevels() const
322 {
323 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
324 assert("post: result_greater_or_equal_to_one" && this->Datas->NumberOfLevels >= 1);
325 return this->Datas->NumberOfLevels;
326 }
327
332 {
333 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
334 return this->Datas->NumberOfVertices;
335 }
336
341 {
342 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
343 return this->Datas->NumberOfNodes;
344 }
345
350 {
351 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
352 return this->Datas->NumberOfVertices - this->Datas->NumberOfNodes;
353 }
354
358 int GetBranchFactor() const { return this->BranchFactor; }
359
363 int GetDimension() const { return this->Dimension; }
364
369 vtkIdType GetNumberOfChildren() const { return this->NumberOfChildren; }
370
372
376 void GetScale(double s[3]) const;
377
378 double GetScale(unsigned int d) const;
380
386 std::shared_ptr<vtkHyperTreeGridScales> InitializeScales(
387 const double* scales, bool reinitialize = false) const;
388
399 static vtkHyperTree* CreateInstance(unsigned char branchFactor, unsigned char dimension);
404 virtual unsigned long GetActualMemorySizeBytes() = 0;
405
410 unsigned int GetActualMemorySize()
411 {
412 // in kilibytes
413 return static_cast<unsigned int>(this->GetActualMemorySizeBytes() / 1024);
414 }
415
425 virtual bool IsGlobalIndexImplicit() = 0;
426
446 virtual void SetGlobalIndexStart(vtkIdType start) = 0;
447
453 {
454 assert("pre: datas_non_nullptr" && this->Datas != nullptr);
455 return this->Datas->GlobalIndexStart;
456 }
457
468
478
483 virtual vtkIdType GetGlobalNodeIndexMax() const = 0;
484
489 virtual bool IsLeaf(vtkIdType index) const = 0;
490
496 virtual void SubdivideLeaf(vtkIdType index, unsigned int level) = 0;
497
504 virtual bool IsTerminalNode(vtkIdType index) const = 0;
505
513 virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const = 0;
514
519 virtual const unsigned int* GetElderChildIndexArray(size_t& nbElements) const = 0;
520
522
528 void SetScales(std::shared_ptr<vtkHyperTreeGridScales> scales) const { this->Scales = scales; }
530
532
535 bool HasScales() const { return (this->Scales != nullptr); }
537
539
542 std::shared_ptr<vtkHyperTreeGridScales> GetScales() const
543 {
544 assert(this->Scales != nullptr);
545 return this->Scales;
546 }
548
549protected:
551
552 ~vtkHyperTree() override = default;
553
554 virtual void InitializePrivate() = 0;
555 virtual void PrintSelfPrivate(ostream& os, vtkIndent indent) = 0;
556 virtual void CopyStructurePrivate(vtkHyperTree* ht) = 0;
557
558 //-- Global information
559
560 // Branching factor of tree (2 or 3)
561 unsigned char BranchFactor;
562
563 // Dimension of tree (1, 2, or 3)
564 unsigned char Dimension;
565
566 // Number of children for coarse cell
567 unsigned char NumberOfChildren;
568
569 //-- Local information
570 std::shared_ptr<vtkHyperTreeData> Datas;
571
572 // Storage of pre-computed per-level cell scales
573 // In hypertree grid, one description by hypertree.
574 // In Uniform hypertree grid, one description by hypertree grid
575 // (all cells, different hypertree, are identical by level).
576 mutable std::shared_ptr<vtkHyperTreeGridScales> Scales;
577
578private:
579 void InitializeBase(
580 unsigned char branchFactor, unsigned char dimension, unsigned char numberOfChildren);
581 vtkHyperTree(const vtkHyperTree&) = delete;
582 void operator=(const vtkHyperTree&) = delete;
583};
584
585VTK_ABI_NAMESPACE_END
586#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.
std::shared_ptr< vtkHyperTreeGridScales > Scales
virtual vtkIdType GetGlobalIndexFromLocal(vtkIdType index) const =0
Get the global id of a local node identified by index.
unsigned char BranchFactor
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.
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,...
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.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkHyperTree * CreateInstance(unsigned char branchFactor, unsigned char dimension)
Return an instance of an implementation of a hypertree for given branch factor and dimension.
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.
virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const =0
Return the elder child index, local index node of first child, of node, coarse cell,...
double GetScale(unsigned int d) const
Set/Get scale of the tree in each direction for the ground level (0).
std::shared_ptr< vtkHyperTreeGridScales > GetScales() const
Return all scales.
virtual void ComputeBreadthFirstOrderDescriptor(unsigned int depthLimiter, vtkBitArray *inputMask, vtkTypeInt64Array *numberOfVerticesPerDepth, vtkBitArray *descriptor, vtkIdList *breadthFirstIdMap)=0
This method computes the breadth first order descriptor of the current tree.
unsigned char Dimension
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.
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< vtkHyperTreeData > Datas
unsigned char NumberOfChildren
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 vtkHyperTree * Freeze(const char *mode)=0
Return a freeze instance (a priori compact but potentially unmodifiable).
virtual void CopyStructurePrivate(vtkHyperTree *ht)=0
vtkIdType GetTreeIndex() const
Set/Get tree index in hypertree grid.
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.
vtkIdType GetNumberOfLeaves() const
Return the number of leaf (fine) in the tree.
int GetDimension() const
Return the spatial dimension of the tree.
~vtkHyperTree() override=default
vtkIdType GetNumberOfChildren() const
Return the number of children per node of the tree.
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.
std::shared_ptr< vtkHyperTreeGridScales > InitializeScales(const double *scales, bool reinitialize=false) const
In an hypertree, all cells are the same size by level.
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
unsigned int NumberOfLevels
vtkIdType NumberOfVertices
vtkIdType TreeIndex
vtkIdType NumberOfNodes
vtkIdType GlobalIndexStart
#define VTK_DEPRECATED_IN_9_4_0(reason)
int vtkIdType
Definition vtkType.h:315
#define VTK_NEWINSTANCE