VTK  9.2.6
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 =========================================================================*/
138 #ifndef vtkHyperTree_h
139 #define vtkHyperTree_h
140 
141 #include "vtkCommonDataModelModule.h" // For export macro
142 #include "vtkObject.h"
143 
144 #include <cassert> // Used internally
145 #include <memory> // std::shared_ptr
146 
147 class vtkBitArray;
148 class vtkIdList;
150 class vtkTypeInt64Array;
151 
152 //=============================================================================
154 {
155  // Index of this tree in the hypertree grid
157 
158  // Number of levels in the tree
159  unsigned int NumberOfLevels;
160 
161  // Number of vertices in this tree (coarse and leaves)
163 
164  // Number of nodes (non-leaf vertices) in the tree
166 
167  // Offset start for the implicit global index mapping fixed by
168  // SetGlobalIndexStart after create a tree.
169  // If you don't choose implicit global index mapping then this
170  // value is -1. Then, you must to descrieb explicit global index
171  // mapping by using then SetGlobalIndexFromLocal for each cell
172  // in tree.
173  // The extra cost is equivalent to the cost of a field of values
174  // of cells.
176 };
177 
178 //=============================================================================
179 class VTKCOMMONDATAMODEL_EXPORT vtkHyperTree : public vtkObject
180 {
181 public:
182  vtkTypeMacro(vtkHyperTree, vtkObject);
183 
184  void PrintSelf(ostream& os, vtkIndent indent) override;
185 
193  void Initialize(
194  unsigned char branchFactor, unsigned char dimension, unsigned char numberOfChildren);
195 
215  virtual void InitializeForReader(vtkIdType numberOfLevels, vtkIdType nbVertices,
216  vtkIdType nbVerticesOfLastLevel, vtkBitArray* isParent, vtkBitArray* isMasked,
217  vtkBitArray* outIsMasked) = 0;
218 
239  virtual void BuildFromBreadthFirstOrderDescriptor(
240  vtkBitArray* descriptor, vtkIdType numberOfBits, vtkIdType startIndex = 0) = 0;
241 
279  virtual void ComputeBreadthFirstOrderDescriptor(vtkBitArray* inputMask,
280  vtkTypeInt64Array* numberOfVerticesPerDepth, vtkBitArray* descriptor,
281  vtkIdList* breadthFirstIdMap) = 0;
282 
288  void CopyStructure(vtkHyperTree* ht);
289 
297  virtual vtkHyperTree* Freeze(const char* mode) = 0;
298 
300 
304  void SetTreeIndex(vtkIdType treeIndex) { this->Datas->TreeIndex = treeIndex; }
305  vtkIdType GetTreeIndex() const { return this->Datas->TreeIndex; }
307 
311  unsigned int GetNumberOfLevels() const
312  {
313  assert("post: result_greater_or_equal_to_one" && this->Datas->NumberOfLevels >= 1);
314  return this->Datas->NumberOfLevels;
315  }
316 
320  vtkIdType GetNumberOfVertices() const { return this->Datas->NumberOfVertices; }
321 
325  vtkIdType GetNumberOfNodes() const { return this->Datas->NumberOfNodes; }
326 
331  {
332  return this->Datas->NumberOfVertices - this->Datas->NumberOfNodes;
333  }
334 
338  int GetBranchFactor() const { return this->BranchFactor; }
339 
343  int GetDimension() const { return this->Dimension; }
344 
349  vtkIdType GetNumberOfChildren() const { return this->NumberOfChildren; }
350 
352 
356  void GetScale(double s[3]) const;
357 
358  double GetScale(unsigned int d) const;
360 
366  std::shared_ptr<vtkHyperTreeGridScales> InitializeScales(
367  const double* scales, bool reinitialize = false) const;
368 
379  static vtkHyperTree* CreateInstance(unsigned char branchFactor, unsigned char dimension);
384  virtual unsigned long GetActualMemorySizeBytes() = 0;
385 
390  unsigned int GetActualMemorySize()
391  {
392  // in kilibytes
393  return static_cast<unsigned int>(this->GetActualMemorySizeBytes() / 1024);
394  }
395 
405  virtual bool IsGlobalIndexImplicit() = 0;
406 
426  virtual void SetGlobalIndexStart(vtkIdType start) = 0;
427 
432  vtkIdType GetGlobalIndexStart() const { return this->Datas->GlobalIndexStart; }
433 
443  virtual void SetGlobalIndexFromLocal(vtkIdType index, vtkIdType global) = 0;
444 
453  virtual vtkIdType GetGlobalIndexFromLocal(vtkIdType index) const = 0;
454 
459  virtual vtkIdType GetGlobalNodeIndexMax() const = 0;
460 
465  virtual bool IsLeaf(vtkIdType index) const = 0;
466 
472  virtual void SubdivideLeaf(vtkIdType index, unsigned int level) = 0;
473 
480  virtual bool IsTerminalNode(vtkIdType index) const = 0;
481 
489  virtual vtkIdType GetElderChildIndex(unsigned int index_parent) const = 0;
490 
495  virtual const unsigned int* GetElderChildIndexArray(size_t& nbElements) const = 0;
496 
498 
504  void SetScales(std::shared_ptr<vtkHyperTreeGridScales> scales) const { this->Scales = scales; }
506 
508 
511  bool HasScales() const { return (this->Scales != nullptr); }
513 
515 
518  std::shared_ptr<vtkHyperTreeGridScales> GetScales() const
519  {
520  assert(this->Scales != nullptr);
521  return this->Scales;
522  }
524 
525 protected:
526  vtkHyperTree();
527 
528  ~vtkHyperTree() override = default;
529 
530  virtual void InitializePrivate() = 0;
531  virtual void PrintSelfPrivate(ostream& os, vtkIndent indent) = 0;
532  virtual void CopyStructurePrivate(vtkHyperTree* ht) = 0;
533 
534  //-- Global information
535 
536  // Branching factor of tree (2 or 3)
537  unsigned char BranchFactor;
538 
539  // Dimension of tree (1, 2, or 3)
540  unsigned char Dimension;
541 
542  // Number of children for coarse cell
543  unsigned char NumberOfChildren;
544 
545  //-- Local information
546  std::shared_ptr<vtkHyperTreeData> Datas;
547 
548  // Storage of pre-computed per-level cell scales
549  // In hypertree grid, one description by hypertree.
550  // In Uniform hypertree grid, one description by hypertree grid
551  // (all cells, differents hypertree, are identicals by level).
552  mutable std::shared_ptr<vtkHyperTreeGridScales> Scales;
553 
554 private:
555  void InitializeBase(
556  unsigned char branchFactor, unsigned char dimension, unsigned char numberOfChildren);
557  vtkHyperTree(const vtkHyperTree&) = delete;
558  void operator=(const vtkHyperTree&) = delete;
559 };
560 
561 #endif
vtkIdType GetGlobalIndexStart() const
Get the start global index for the current tree for implicit global index mapping.
Definition: vtkHyperTree.h:432
bool HasScales() const
Return the existence scales.
Definition: vtkHyperTree.h:511
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkIdType NumberOfVertices
Definition: vtkHyperTree.h:162
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int GetDimension() const
Return the spatial dimension of the tree.
Definition: vtkHyperTree.h:343
unsigned char Dimension
Definition: vtkHyperTree.h:540
void SetTreeIndex(vtkIdType treeIndex)
Set/Get tree index in hypertree grid.
Definition: vtkHyperTree.h:304
int vtkIdType
Definition: vtkType.h:332
void SetScales(std::shared_ptr< vtkHyperTreeGridScales > scales) const
In an hypertree, all cells are the same size by level.
Definition: vtkHyperTree.h:504
unsigned char BranchFactor
Definition: vtkHyperTree.h:537
vtkIdType TreeIndex
Definition: vtkHyperTree.h:156
unsigned int NumberOfLevels
Definition: vtkHyperTree.h:159
a simple class to control print indentation
Definition: vtkIndent.h:39
std::shared_ptr< vtkHyperTreeGridScales > GetScales() const
Return all scales.
Definition: vtkHyperTree.h:518
unsigned int GetActualMemorySize()
Return memory used in kibibytes (1024 bytes).
Definition: vtkHyperTree.h:390
list of point or cell ids
Definition: vtkIdList.h:33
std::shared_ptr< vtkHyperTreeGridScales > Scales
Definition: vtkHyperTree.h:552
vtkIdType GetNumberOfChildren() const
Return the number of children per node of the tree.
Definition: vtkHyperTree.h:349
vtkIdType GetNumberOfLeaves() const
Return the number of leaf (fine) in the tree.
Definition: vtkHyperTree.h:330
int GetBranchFactor() const
Return the branch factor of the tree.
Definition: vtkHyperTree.h:338
#define VTK_NEWINSTANCE
unsigned int GetNumberOfLevels() const
Return the number of levels.
Definition: vtkHyperTree.h:311
vtkIdType GetTreeIndex() const
Set/Get tree index in hypertree grid.
Definition: vtkHyperTree.h:305
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:36
A data object structured as a tree.
Definition: vtkHyperTree.h:179
vtkIdType GetNumberOfVertices() const
Return the number of all vertices (coarse and fine) in the tree.
Definition: vtkHyperTree.h:320
unsigned char NumberOfChildren
Definition: vtkHyperTree.h:543
vtkIdType GetNumberOfNodes() const
Return the number of nodes (coarse) in the tree.
Definition: vtkHyperTree.h:325
A specifalized type of vtkHyperTreeGrid for the case when root cells have uniform sizes in each direc...
vtkIdType GlobalIndexStart
Definition: vtkHyperTree.h:175
std::shared_ptr< vtkHyperTreeData > Datas
Definition: vtkHyperTree.h:546
vtkIdType NumberOfNodes
Definition: vtkHyperTree.h:165