VTK  9.0.3
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;
146 
147 class vtkIdList;
148 
150 
151 //=============================================================================
153 {
154  // Index of this tree in the hypertree grid
156 
157  // Number of levels in the tree
158  unsigned int NumberOfLevels;
159 
160  // Number of vertices in this tree (coarse and leaves)
162 
163  // Number of nodes (non-leaf vertices) in the tree
165 
166  // Offset start for the implicit global index mapping fixed by
167  // SetGlobalIndexStart after create a tree.
168  // If you don't choose implicit global index mapping then this
169  // value is -1. Then, you must to describ explicit global index
170  // mapping by using then SetGlobalIndexFromLocal for each cell
171  // in tree.
172  // The extra cost is equivalent to the cost of a field of values
173  // of cells.
175 };
176 
177 //=============================================================================
178 class VTKCOMMONDATAMODEL_EXPORT vtkHyperTree : public vtkObject
179 {
180 public:
181  vtkTypeMacro(vtkHyperTree, vtkObject);
182 
183  void PrintSelf(ostream&, vtkIndent) override;
184 
192  void Initialize(unsigned char, unsigned char, unsigned char);
193 
213  virtual void InitializeForReader(vtkIdType numberOfLevels, vtkIdType nbVertices,
214  vtkIdType nbVerticesOfLastLevel, vtkBitArray* isParent, vtkBitArray* isMasked,
215  vtkBitArray* outIsMasked) = 0;
216 
233  virtual void GetByLevelForWriter(vtkBitArray* inIsMasked, vtkUnsignedLongArray* nbVerticesbyLevel,
234  vtkBitArray* isParent, vtkBitArray* isMasked, vtkIdList* ids) = 0;
235 
242 
250  virtual vtkHyperTree* Freeze(const char* mode) = 0;
251 
253 
257  void SetTreeIndex(vtkIdType treeIndex) { this->Datas->TreeIndex = treeIndex; }
258  vtkIdType GetTreeIndex() const { return this->Datas->TreeIndex; }
260 
264  unsigned int GetNumberOfLevels() const
265  {
266  assert("post: result_greater_or_equal_to_one" && this->Datas->NumberOfLevels >= 1);
267  return this->Datas->NumberOfLevels;
268  }
269 
273  vtkIdType GetNumberOfVertices() const { return this->Datas->NumberOfVertices; }
274 
278  vtkIdType GetNumberOfNodes() const { return this->Datas->NumberOfNodes; }
279 
284  {
285  return this->Datas->NumberOfVertices - this->Datas->NumberOfNodes;
286  }
287 
291  int GetBranchFactor() const { return this->BranchFactor; }
292 
296  int GetDimension() const { return this->Dimension; }
297 
302  vtkIdType GetNumberOfChildren() const { return this->NumberOfChildren; }
303 
305 
309  void GetScale(double s[3]) const;
310 
311  double GetScale(unsigned int d) const;
313 
319  std::shared_ptr<vtkHyperTreeGridScales> InitializeScales(
320  const double* scales, bool reinitialize = false) const;
321 
332  static vtkHyperTree* CreateInstance(unsigned char branchFactor, unsigned char dimension);
337  virtual unsigned long GetActualMemorySizeBytes() = 0;
338 
343  unsigned int GetActualMemorySize()
344  {
345  // in kilibytes
346  return static_cast<unsigned int>(this->GetActualMemorySizeBytes() / 1024);
347  }
348 
358  virtual bool IsGlobalIndexImplicit() = 0;
359 
379  virtual void SetGlobalIndexStart(vtkIdType start) = 0;
380 
385  vtkIdType GetGlobalIndexStart() const { return this->Datas->GlobalIndexStart; }
386 
397 
407 
412  virtual vtkIdType GetGlobalNodeIndexMax() const = 0;
413 
418  virtual bool IsLeaf(vtkIdType index) const = 0;
419 
425  virtual void SubdivideLeaf(vtkIdType index, unsigned int level) = 0;
426 
433  virtual bool IsTerminalNode(vtkIdType index) const = 0;
434 
442  virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const = 0;
443 
445 
451  void SetScales(std::shared_ptr<vtkHyperTreeGridScales> scales) const { this->Scales = scales; }
453 
455 
458  bool HasScales() const { return (this->Scales != nullptr); }
460 
462 
465  std::shared_ptr<vtkHyperTreeGridScales> GetScales() const
466  {
467  assert(this->Scales != nullptr);
468  return this->Scales;
469  }
471 
472 protected:
474  : BranchFactor(2)
475  , Dimension(3)
476  , NumberOfChildren(8)
477  {
478  }
479 
480  virtual ~vtkHyperTree() override {}
481 
482  virtual void InitializePrivate() = 0;
483  virtual void PrintSelfPrivate(ostream& os, vtkIndent indent) = 0;
484  virtual void CopyStructurePrivate(vtkHyperTree* ht) = 0;
485 
486  //-- Global information
487 
488  // Branching factor of tree (2 or 3)
489  unsigned char BranchFactor;
490 
491  // Dimension of tree (1, 2, or 3)
492  unsigned char Dimension;
493 
494  // Number of children for coarse cell
495  unsigned char NumberOfChildren;
496 
497  //-- Local information
498  std::shared_ptr<vtkHyperTreeData> Datas;
499 
500  // Storage of pre-computed per-level cell scales
501  // In hypertree grid, one description by hypertree.
502  // In Uniform hypertree grid, one description by hypertree grid
503  // (all cells, differents hypertree, are identicals by level).
504  mutable std::shared_ptr<vtkHyperTreeGridScales> Scales;
505 
506 private:
507  vtkHyperTree(const vtkHyperTree&) = delete;
508  void operator=(const vtkHyperTree&) = delete;
509 };
510 
511 #endif
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:34
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:179
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:504
virtual vtkIdType GetGlobalIndexFromLocal(vtkIdType index) const =0
Get the global id of a local node identified by index.
unsigned char BranchFactor
Definition: vtkHyperTree.h:489
void PrintSelf(ostream &, vtkIndent) override
Methods invoked by print to print information about the object including superclasses.
void Initialize(unsigned char, unsigned char, unsigned char)
Restore the initial state: only one vertice is then a leaf: the root cell for the hypertree.
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:273
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.
Definition: vtkHyperTree.h:385
unsigned int GetNumberOfLevels() const
Return the number of levels.
Definition: vtkHyperTree.h:264
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
virtual ~vtkHyperTree() override
Definition: vtkHyperTree.h:480
unsigned char Dimension
Definition: vtkHyperTree.h:492
unsigned int GetActualMemorySize()
Return memory used in kibibytes (1024 bytes).
Definition: vtkHyperTree.h:343
bool HasScales() const
Return the existence scales.
Definition: vtkHyperTree.h:458
vtkIdType GetNumberOfNodes() const
Return the number of nodes (coarse) in the tree.
Definition: vtkHyperTree.h:278
int GetBranchFactor() const
Return the branch factor of the tree.
Definition: vtkHyperTree.h:291
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:465
std::shared_ptr< vtkHyperTreeData > Datas
Definition: vtkHyperTree.h:498
unsigned char NumberOfChildren
Definition: vtkHyperTree.h:495
void CopyStructure(vtkHyperTree *ht)
Copy the structure by sharing the decomposition description of the tree.
virtual bool IsGlobalIndexImplicit()=0
Return if implicit global index maping 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
Definition: vtkHyperTree.h:258
void SetScales(std::shared_ptr< vtkHyperTreeGridScales > scales) const
In an hypertree, all cells are the same size by level.
Definition: vtkHyperTree.h:451
vtkIdType GetNumberOfLeaves() const
Return the number of leaf (fine) in the tree.
Definition: vtkHyperTree.h:283
int GetDimension() const
Return the spatial dimension of the tree.
Definition: vtkHyperTree.h:296
virtual void GetByLevelForWriter(vtkBitArray *inIsMasked, vtkUnsignedLongArray *nbVerticesbyLevel, vtkBitArray *isParent, vtkBitArray *isMasked, vtkIdList *ids)=0
Initialize a state from write data.
vtkIdType GetNumberOfChildren() const
Return the number of children per node of the tree.
Definition: vtkHyperTree.h:302
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:257
list of point or cell ids
Definition: vtkIdList.h:31
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObject.h:63
dynamic, self-adjusting array of unsigned long
@ level
Definition: vtkX3D.h:401
@ mode
Definition: vtkX3D.h:253
@ index
Definition: vtkX3D.h:252
unsigned int NumberOfLevels
Definition: vtkHyperTree.h:158
vtkIdType NumberOfVertices
Definition: vtkHyperTree.h:161
vtkIdType TreeIndex
Definition: vtkHyperTree.h:155
vtkIdType NumberOfNodes
Definition: vtkHyperTree.h:164
vtkIdType GlobalIndexStart
Definition: vtkHyperTree.h:174
int vtkIdType
Definition: vtkType.h:338
#define VTK_NEWINSTANCE