vtkHyperTreeGrid.h 25.3 KB
Newer Older
Philippe Pébay's avatar
Philippe Pébay committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkHyperTreeGrid.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
 * @class   vtkHyperTreeGrid
 * @brief   A dataset containing a grid of vtkHyperTree instances
 * arranged as a rectilinear grid.
 *
 *
 * An hypertree grid is a dataset containing a rectilinear grid of root nodes,
 * each of which can be refined as a vtkHyperTree grid. This organization of the
 * root nodes allows for the definition of tree-based AMR grids that do not have
 * uniform geometry.
 * Some filters can be applied on this dataset: contour, outline, geometry.
 *
 * @warning
 * It is not a spatial search object. If you are looking for this kind of
 * octree see vtkCellLocator instead.
 * Extent support is not finished yet.
 *
 * @sa
 * vtkHyperTree vtkRectilinearGrid
 *
 * @par Thanks:
36
37
38
39
 * This class was written by Philippe Pebay, Joachim Pouderoux, and Charles Law, Kitware 2013
 * This class was modified by Guenole Harel and Jacques-Bernard Lekien 2014
 * This class was rewritten by Philippe Pebay, 2016
 * This work was supported by Commissariat a l'Energie Atomique (CEA/DIF)
40
*/
41

42
43
#ifndef vtkHyperTreeGrid_h
#define vtkHyperTreeGrid_h
Philippe Pébay's avatar
Philippe Pébay committed
44

45
#include "vtkCommonDataModelModule.h" // For export macro
Philippe Pébay's avatar
Philippe Pébay committed
46
#include "vtkDataSet.h"
47

48
#include <map> // STL header for dual point coordinates ajustment
Philippe Pébay's avatar
Philippe Pébay committed
49

50
class vtkHyperTree;
51
52
class vtkHyperTreeCursor;
class vtkHyperTreeGridCursor;
Philippe Pébay's avatar
Philippe Pébay committed
53

54
class vtkBitArray;
55
class vtkBoundingBox;
56
57
class vtkCellLinks;
class vtkCollection;
58
class vtkDataArray;
Philippe Pébay's avatar
Philippe Pébay committed
59
class vtkDataSetAttributes;
60
class vtkIdTypeArray;
Philippe Pébay's avatar
Philippe Pébay committed
61
62
class vtkLine;
class vtkPixel;
63
class vtkPoints;
Philippe Pébay's avatar
Philippe Pébay committed
64
65
class vtkVoxel;

66
class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeGrid : public vtkDataSet
Philippe Pébay's avatar
Philippe Pébay committed
67
68
{
public:
69
  class vtkHyperTreeSimpleCursor;
70
71
  class vtkHyperTreePositionCursor;
  class vtkHyperTreeGridIterator;
72
73
  struct vtkHyperTreeGridSuperCursor;

Philippe Pébay's avatar
Philippe Pébay committed
74
75
  static vtkInformationIntegerKey* LEVELS();
  static vtkInformationIntegerKey* DIMENSION();
76
  static vtkInformationIntegerKey* ORIENTATION();
Philippe Pébay's avatar
Philippe Pébay committed
77
  static vtkInformationDoubleVectorKey* SIZES();
Philippe Pébay's avatar
Philippe Pébay committed
78
  static vtkHyperTreeGrid* New();
Charles Law's avatar
Charles Law committed
79

80
  vtkTypeMacro(vtkHyperTreeGrid, vtkDataSet);
81
  void PrintSelf( ostream&, vtkIndent ) override;
Charles Law's avatar
Charles Law committed
82

83
84
85
  /**
   * Return what type of dataset this is.
   */
86
  int GetDataObjectType() override;
Charles Law's avatar
Charles Law committed
87

88
89
90
91
  /**
   * Copy the internal geometric and topological structure of a
   * vtkHyperTreeGrid object.
   */
92
  void CopyStructure( vtkDataSet* ) override;
Philippe Pébay's avatar
Philippe Pébay committed
93

94
95
96
97
  //@{
  /**
   * Set/Get sizes of this rectilinear grid dataset
   */
98
  void SetGridSize( unsigned int[3] );
99
  void SetGridSize( unsigned int, unsigned int, unsigned int );
100
  vtkGetVector3Macro(GridSize, unsigned int);
101
  //@}
Philippe Pébay's avatar
Philippe Pébay committed
102

103
104
  //@{
  /**
105
   * Set/Get extent of this rectilinear grid dataset.
106
   */
107
  void SetGridExtent(int extent[6]);
108
  void SetGridExtent(int, int, int, int, int, int );
109
  //@}
110

111
112
113
114
115
  //@{
  /**
   * Specify whether indexing mode of grid root cells must be transposed to
   * x-axis first, z-axis last, instead of the default z-axis first, k-axis last
   */
116
117
  vtkSetMacro(TransposedRootIndexing, bool);
  vtkGetMacro(TransposedRootIndexing, bool);
118
  void SetIndexingModeToKJI()
119
    { this->SetTransposedRootIndexing( false ); }
120
  void SetIndexingModeToIJK()
121
    { this->SetTransposedRootIndexing( true ); }
122
  //@}
123

124
  //@{
125
  /**
126
   * Set/Get the dimensionality of the grid.
127
   */
128
129
  void SetDimension( unsigned int );
  vtkGetMacro(Dimension, unsigned int);
130
  //@}
Charles Law's avatar
Charles Law committed
131

132
  //@{
133
  /**
134
135
136
137
   * Set/Get the orientation of 1D or 2D grids:
   * . in 1D: 0, 1, 2 = aligned along X, Y, Z axis
   * . in 2D: 0, 1, 2 = normal to X, Y, Z axis
   * NB: Not used in 3D
138
   */
139
  virtual void SetOrientation(unsigned int);
140
  vtkGetMacro(Orientation, unsigned int);
141
  //@}
Philippe Pébay's avatar
Philippe Pébay committed
142

143
  //@{
144
  /**
145
   * Set/Get the subdivision factor in the grid refinement scheme
146
   */
147
148
149
  void SetBranchFactor( unsigned int );
  vtkGetMacro(BranchFactor, unsigned int);
  //@}
150
151

  /**
152
   * Return the number of trees in the level 0 grid.
153
   */
154
155
156
157
158
159
  vtkIdType GetNumberOfTrees();

  /**
   * Get the number of vertices in the primal tree grid.
   */
  vtkIdType GetNumberOfVertices();
160
161

  /**
162
163
164
165
166
   * Get the number of leaves in the primal tree grid.
   */
  vtkIdType GetNumberOfLeaves();

  /**
167
168
   * Return the number of cells in the dual grid.
   */
169
  vtkIdType GetNumberOfCells() override;
170
171
172
173

  /**
   * Return the number of points in the dual grid.
   */
174
  vtkIdType GetNumberOfPoints() override;
175
176
177

  /**
   * Return the number of levels in an individual (primal) tree.
178
   */
179
  vtkIdType GetNumberOfLevels( vtkIdType );
Philippe Pébay's avatar
Philippe Pébay committed
180

181
  /**
182
   * Return the number of levels in the hyper tree grid.
183
   */
184
  vtkIdType GetNumberOfLevels();
185

186
187
  //@{
  /**
188
   * Set/Get the grid coordinates in the x-direction.
189
   */
190
  void SetXCoordinates( vtkDataArray* );
191
  vtkGetObjectMacro(XCoordinates, vtkDataArray);
192
  //@}
193

194
195
  //@{
  /**
196
   * Set/Get the grid coordinates in the y-direction.
197
   */
198
  void SetYCoordinates( vtkDataArray* );
199
  vtkGetObjectMacro(YCoordinates, vtkDataArray);
200
  //@}
201

202
203
  //@{
  /**
204
   * Set/Get the grid coordinates in the z-direction.
205
   */
206
  void SetZCoordinates( vtkDataArray* );
207
  vtkGetObjectMacro(ZCoordinates, vtkDataArray);
208
  //@}
209

210
211
  //@{
  /**
212
   * Set/Get the blanking mask of primal leaf cells
213
   */
214
215
  void SetMaterialMask( vtkBitArray* );
  vtkGetObjectMacro(MaterialMask, vtkBitArray);
216
  //@}
217

218
219
220
221
222
  /**
   * Determine whether blanking mask is empty or not
   */
  bool HasMaterialMask();

223
224
  //@{
  /**
225
   * Set/Get the visibility mask of primal leaf cells
226
   */
227
228
  virtual void SetMaterialMaskIndex( vtkIdTypeArray* );
  vtkGetObjectMacro(MaterialMaskIndex, vtkIdTypeArray);
229
  //@}
230

231
232
233
234
  //@{
  /**
   * Set/Get presence or absence of interface
   */
235
236
237
  vtkSetMacro( HasInterface, bool );
  vtkGetMacro( HasInterface, bool );
  vtkBooleanMacro( HasInterface, bool );
238
239
240
  //@}

  //@{
241
  /**
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
   * Set/Get names of interface normal vectors arrays
   */
  vtkSetStringMacro(InterfaceNormalsName);
  vtkGetStringMacro(InterfaceNormalsName);
  //@}

  //@{
  /**
   * Set/Get names of interface intercepts arrays
   */
  vtkSetStringMacro(InterfaceInterceptsName);
  vtkGetStringMacro(InterfaceInterceptsName);
  //@}

  /**
   * This method must be called once the tree settings change.
258
   */
259
260
  virtual void GenerateTrees();

261
  /**
262
263
264
265
266
267
268
269
270
271
272
273
274
   * Create a new hyper tree cursor: an object that can traverse
   * the cells of an individual hyper tree at given index.
   * If no hyper tree is present at given location, then one
   * will be created only if 'create' flag is true.
   */
  vtkHyperTreeCursor* NewCursor( vtkIdType, bool create=false );

  /**
   * Create a new hyper tree grid cursor: an object that
   * can traverse the cells of an hyper tree grid, starting at given
   * tree root index.
   * If no hyper tree is present at given location, then one
   * will be created only if 'create' flag is true.
275
   */
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
  vtkHyperTreeGridCursor* NewGridCursor( vtkIdType,
                                         bool create=false );

  /**
   * Create a new hyper tree grid geometric cursor: an object that
   * can traverse the cells of an hyper tree grid, starting at given
   * tree root index, managing the geometric properties.
   * If no hyper tree is present at given location, then one
   * will be created only if 'create' flag is true.
   */
  vtkHyperTreeGridCursor* NewGeometricCursor( vtkIdType,
                                              bool create=false );

  /**
   * Create a new hyper tree grid Von Neumann super cursor: an object that
   * can traverse the cells of an hyper tree grid, starting at given
   * tree root index, managing geometric properties and von Neumann
   * neighborhood with basic hyper tree grid cursors.
   * If no hyper tree is present at given location, then one
   * will be created only if 'create' flag is true.
   */
  vtkHyperTreeGridCursor* NewVonNeumannSuperCursor( vtkIdType,
                                                    bool create=false );

  /**
   * Create a new hyper tree grid Moore super cursor: an object that
   * can traverse the cells of an hyper tree grid, starting at given
   * tree root index, managing geometric properties and Moore
   * neighborhood with basic hyper tree grid cursors.
   * If no hyper tree is present at given location, then one
   * will be created only if 'create' flag is true.
   */
  vtkHyperTreeGridCursor* NewMooreSuperCursor( vtkIdType,
                                               bool create=false );
Philippe Pébay's avatar
Philippe Pébay committed
310

311
312
313
314
315
316
  /**
   * Subdivide node pointed by cursor, only if its a leaf.
   * At the end, cursor points on the node that used to be leaf.
   * \pre leaf_exists: leaf!=0
   * \pre is_a_leaf: leaf->CurrentIsLeaf()
   */
317
318
  void SubdivideLeaf( vtkHyperTreeCursor*, vtkIdType );

319
320
321
322
323
324
  /**
   * This method should be avoided in favor of cell/point iterators.
   * Random access to points requires that arrays are created explicitly.
   * Get point coordinates with ptId such that: 0 <= ptId < NumberOfPoints.
   * THIS METHOD IS NOT THREAD SAFE.
   */
325
  double* GetPoint( vtkIdType ) override;
Philippe Pébay's avatar
Philippe Pébay committed
326

327
328
329
330
331
332
333
334
  /**
   * This method should be avoided in favor of cell/point iterators.
   * Random access to points requires that arrays are created explicitly.
   * Copy point coordinates into user provided array x[3] for specified
   * point id.
   * THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
   * THE DATASET IS NOT MODIFIED
   */
335
  void GetPoint( vtkIdType, double[3] ) override;
Charles Law's avatar
Charles Law committed
336

337
338
339
340
341
342
  /**
   * This method should be avoided in favor of cell/point iterators.
   * Random access to cells requires that connectivity arrays are created explicitly.
   * Get cell with cellId such that: 0 <= cellId < NumberOfCells.
   * THIS METHOD IS NOT THREAD SAFE.
   */
343
  vtkCell* GetCell( vtkIdType ) override;
Philippe Pébay's avatar
Philippe Pébay committed
344

345
346
347
348
  /**
   * Overridden so as no not unintentionally hide parent class.
   * See -Woverloaded-virtual
   */
349
  vtkCell* GetCell( int i, int j, int k) override {
350
351
352
    return this->Superclass::GetCell(i,j,k);
  };

353
354
355
356
357
358
359
360
361
  /**
   * This method should be avoided in favor of cell/point iterators.
   * Random access to cells requires that connectivity arrays are created explicitly.
   * Get cell with cellId such that: 0 <= cellId < NumberOfCells.
   * This is a thread-safe alternative to the previous GetCell()
   * method.
   * THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
   * THE DATASET IS NOT MODIFIED
   */
362
  void GetCell( vtkIdType, vtkGenericCell* ) override;
Philippe Pébay's avatar
Philippe Pébay committed
363

364
365
366
367
368
369
  /**
   * All cell types are 2: quadrilaters,3d: hexahedrons.  They may be degenerate though.
   * Get type of cell with cellId such that: 0 <= cellId < NumberOfCells.
   * THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
   * THE DATASET IS NOT MODIFIED
   */
370
  int GetCellType( vtkIdType ) override;
Philippe Pébay's avatar
Philippe Pébay committed
371

372
373
374
375
376
377
378
  /**
   * This method should be avoided in favor of cell/point iterators.
   * Random access to cells requires that connectivity arrays are created explicitly.
   * Topological inquiry to get points defining cell.
   * THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
   * THE DATASET IS NOT MODIFIED
   */
379
  void GetCellPoints( vtkIdType, vtkIdList* ) override;
380

381
382
383
384
  /**
   * Return a pointer to a list of point ids defining cell.
   * NB: More efficient than alternative method.
   */
385
  void GetCellPoints( vtkIdType, vtkIdType&, vtkIdType*& );
Philippe Pébay's avatar
Philippe Pébay committed
386

387
388
389
390
391
392
393
  /**
   * This method should be avoided in favor of cell/point iterators.
   * Random access to cells requires that connectivity arrays are created explicitly.
   * Topological inquiry to get cells using point.
   * THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
   * THE DATASET IS NOT MODIFIED
   */
394
  void GetPointCells( vtkIdType, vtkIdList* ) override;
Philippe Pébay's avatar
Philippe Pébay committed
395

396
397
398
399
400
401
402
403
404
405
  /**
   * This method should be avoided in favor of cell/point iterators.
   * Random access to cells requires that connectivity arrays are created explicitly.
   * Topological inquiry to get all cells using list of points exclusive of
   * cell specified (e.g., cellId). Note that the list consists of only
   * cells that use ALL the points provided.
   * This is exactly the same as GetCellNeighbors in unstructured grid.
   * THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
   * THE DATASET IS NOT MODIFIED
   */
406
  void GetCellNeighbors( vtkIdType, vtkIdList*, vtkIdList* ) override;
Philippe Pébay's avatar
Philippe Pébay committed
407

408
409
410
411
412
413
  /**
   * Find cell to which this point belongs, or at least closest one,
   * even if the point is outside the grid.
   * Since dual points are leaves, use the structure of the Tree instead
   * of a point locator.
   */
414
  vtkIdType FindPoint( double x[3] ) override;
Philippe Pébay's avatar
Philippe Pébay committed
415

416
417
  /**
   * Locate cell based on global coordinate x and tolerance
418
   * squared. If cell and cellId is non-nullptr, then search starts from
419
420
421
422
423
424
425
426
427
428
   * this cell and looks at immediate neighbors.  Returns cellId >= 0
   * if inside, < 0 otherwise.  The parametric coordinates are
   * provided in pcoords[3]. The interpolation weights are returned in
   * weights[]. (The number of weights is equal to the number of
   * points in the found cell). Tolerance is used to control how close
   * the point is to be considered "in" the cell.
   * NB: There is actually no need for a starting cell, just use the
   * point, as the tree structure is efficient enough.
   * THIS METHOD IS NOT THREAD SAFE.
   */
429
430
  vtkIdType FindCell( double x[3], vtkCell *cell, vtkIdType cellId,
                      double tol2, int& subId, double pcoords[3],
431
                      double *weights ) override;
Philippe Pébay's avatar
Philippe Pébay committed
432

433
434
435
436
437
438
439
  /**
   * This is a version of the above method that can be used with
   * multithreaded applications. A vtkGenericCell must be passed in
   * to be used in internal calls that might be made to GetCell()
   * THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
   * THE DATASET IS NOT MODIFIED
   */
440
441
442
  vtkIdType FindCell( double x[3], vtkCell *cell,
                      vtkGenericCell *gencell, vtkIdType cellId,
                      double tol2, int& subId, double pcoords[3],
443
                      double *weights ) override;
Charles Law's avatar
Charles Law committed
444

445
  /**
446
   * Restore data object to initial state.
447
   */
448
  void Initialize() override;
Charles Law's avatar
Charles Law committed
449

450
451
  /**
   * Return tree located at given index of hyper tree grid
452
   * NB: This will return nullptr if grid slot is empty.
453
454
455
456
457
458
459
460
461
   */
  vtkHyperTree* GetTree( vtkIdType );

  /**
   * Assign given tree to given index of hyper tree grid
   * NB: This will create a new slot in the grid if needed.
   */
  void SetTree( vtkIdType, vtkHyperTree* );

462
463
  /**
   * Initialize an iterator to browse level 0 trees.
464
   * FIXME: this method is completely unnecessary.
465
   */
466
  void InitializeTreeIterator( vtkHyperTreeGridIterator& );
467

468
  /**
469
470
   * Convenience method to return largest cell size in dataset.
   * Generally used to allocate memory for supporting data structures.
471
472
473
   * This is the number of points of a cell.
   * THIS METHOD IS THREAD SAFE
   */
474
  int GetMaxCellSize() override;
Charles Law's avatar
Charles Law committed
475

476
  /**
477
   * Create shallow copy of hyper tree grid.
478
   */
479
  void ShallowCopy( vtkDataObject* ) override;
480
481
482
483

  /**
   * Create deep copy of hyper tree grid.
   */
484
  void DeepCopy( vtkDataObject* ) override;
Philippe Pébay's avatar
Philippe Pébay committed
485

486
  /**
487
   * Structured extent. The extent type is a 3D extent.
488
   */
489
  int GetExtentType() override { return VTK_3D_EXTENT; }
490

491
492
493
494
495
496
497
498
  /**
   * Return the actual size of the data in kibibytes (1024 bytes). This number
   * is valid only after the pipeline has updated. The memory size
   * returned is guaranteed to be greater than or equal to the
   * memory required to represent the data (e.g., extra space in
   * arrays, etc. are not included in the return value). THIS METHOD
   * IS THREAD SAFE.
   */
499
  unsigned long GetActualMemorySize() override;
500

501
  //@{
502
  /**
503
   * The number of children each node can have.
504
   */
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
  vtkGetMacro(NumberOfChildren, unsigned int);
  //@}

  /**
   * Recursively initialize pure material mask
   */
  bool RecursivelyInitializePureMaterialMask( vtkHyperTreeGridCursor* cursor );

  /**
   * Get or create pure material mask
   */
  vtkBitArray* GetPureMaterialMask();

  /**
   * Return hard-coded bitcode correspondng to child mask
   * Dimension 1:
   * Factor 2:
   * 0: 100, 1: 001
   * Factor 3:
   * 0: 100, 1: 010, 2: 001
   * Dimension 2:
   * Factor 2:
   * 0: 1101 0000 0, 1: 0110 0100 0
   * 2: 0001 0011 0, 3: 0000 0101 1
   * Factor 3:
   * 0: 1101 0000 0, 1: 0100 0000 0, 2: 0110 0100 0
   * 3: 0001 0000 0, 4: 0000 1000 0, 5: 0000 0100 0
   * 6: 0001 0011 0, 7: 0000 0001 0, 8: 0000 0101 1
   * Dimension 3:
   * Factor 2:
   * 0: 1101 1000 0110 1000 0000 0000 000, 1: 0110 1100 0011 0010 0000 0000 000
   * 2: 0001 1011 0000 1001 1000 0000 000, 3: 0000 1101 1000 0010 1100 0000 000
   * 4: 0000 0000 0110 1000 0011 0110 000, 5: 0000 0000 0011 0010 0001 1011 000
   * 6: 0000 0000 0000 1001 1000 0110 110, 7: 0000 0000 0000 0010 1100 0011 011
   * Factor 3:
   * 0: 1101 1000 0110 1000 0000 0000 000
   * 1: 0100 1000 0010 0000 0000 0000 000
   * 2: 0110 1100 0011 0010 0000 0000 000
   * 3: 0001 1000 0000 1000 0000 0000 000
   * 4: 0000 1000 0000 0000 0000 0000 000
   * 5: 0000 1100 0000 0010 0000 0000 000
   * 6: 0001 1011 0000 1001 1000 0000 000
   * 7: 0000 1001 0000 0000 1000 0000 000
   * 8: 0000 1101 1000 0010 1100 0000 000
   * 9: 0000 0000 0110 1000 0000 0000 000
   * 10: 0000 0000 0010 0000 0000 0000 000
   * 11: 0000 0000 0011 0010 0000 0000 000
   * 12: 0000 0000 0000 1000 0000 0000 000
   * 13: 0000 0000 0000 0100 0000 0000 000
   * 14: 0000 0000 0000 0010 0000 0000 000
   * 15: 0000 0000 0000 1001 1000 0000 000
   * 16: 0000 0000 0000 0000 1000 0000 000
   * 17: 0000 0000 0000 0010 1100 0000 000
   * 18: 0000 0000 0110 1000 0011 0110 000
   * 19: 0000 0000 0010 0000 0001 0010 000
   * 20: 0000 0000 0011 0010 0001 1011 000
   * 21: 0000 0000 0000 1000 0000 0110 000
   * 22: 0000 0000 0000 0000 0000 0010 000
   * 23: 0000 0000 0000 0010 0000 0011 000
   * 24: 0000 0000 0000 1001 1000 0110 110
   * 25: 0000 0000 0000 0000 1000 0010 010
   * 26: 0000 0000 0000 0010 1100 0011 011
   */
  unsigned int GetChildMask( unsigned int );

  /**
   * Convert the global index of a root to its Cartesian coordinates in the grid.
   */
  void GetLevelZeroCoordinatesFromIndex( vtkIdType,
                                         unsigned int&,
                                         unsigned int&,
                                         unsigned int& );

  /**
   * Convert the Cartesian coordinates of a root in the grid  to its global index.
   */
  void GetIndexFromLevelZeroCoordinates( vtkIdType&,
                                         unsigned int,
                                         unsigned int,
                                         unsigned int );

  /**
   * Return the root index of a root cell with given index displaced.
   * by a Cartesian vector in the grid.
   * NB: No boundary checks are performed.
   */
591
592
593
594
  unsigned int GetShiftedLevelZeroIndex( vtkIdType,
                                         int,
                                         int,
                                         int );
595

596
  //@{
597
  /**
598
599
600
601
602
603
604
605
   * A simplified hyper tree cursor, to be used by the hyper tree.
   * grid supercursor.
   */
  class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeSimpleCursor
  {
  public:
    vtkHyperTreeSimpleCursor();
    ~vtkHyperTreeSimpleCursor();
606
  //@}
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630

    //@{
    /**
     * Methods that belong to the vtkHyperTreeCursor API.
     */
    vtkHyperTree* GetTree() { return this->Tree; }
    //@}

    /**
     * Only valid for leaves.
     */
    vtkIdType GetLeafIndex() { return this->Index; }

    /**
     * Return level at which cursor is positioned.
     */
    unsigned short GetLevel() { return this->Level; }

  private:
    vtkHyperTree* Tree;
    vtkIdType Index;
    unsigned short Level;
  };

631
  /**
632
633
634
635
   * Public structure used by filters to move around the hyper
   * tree grid and easily access neighbors to leaves.
   * The super cursor is 'const'. Methods in vtkHyperTreeGrid
   * initialize and compute children for moving toward leaves.
636
   */
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
  struct vtkHyperTreeGridSuperCursor
  {
    double Origin[3];
    double Size[3];
    int NumberOfCursors;
    int MiddleCursorId;
    vtkHyperTreeSimpleCursor Cursors[3*3*3];
    vtkHyperTreeSimpleCursor* GetCursor( int );
  };

  /**
   * An iterator object to iteratively access trees in the grid.
   */
  class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeGridIterator
  {
  public:
    vtkHyperTreeGridIterator() {}

    /**
     * Initialize the iterator on the tree set of the given grid.
     */
    void Initialize( vtkHyperTreeGrid* );

    /**
     * Get the next tree and set its index then increment the iterator.
     * Returns 0 at the end.
     */
    vtkHyperTree* GetNextTree( vtkIdType& index );

    /**
     * Get the next tree and set its index then increment the iterator.
     * Returns 0 at the end.
     */
    vtkHyperTree* GetNextTree();

  protected:
    std::map<vtkIdType, vtkHyperTree*>::iterator Iterator;
    vtkHyperTreeGrid* Tree;
  };
676

677
678
  //@{
  /**
679
   * Retrieve an instance of this class from an information object
680
   */
681
682
  static vtkHyperTreeGrid* GetData( vtkInformation* info );
  static vtkHyperTreeGrid* GetData( vtkInformationVector* v, int i=0);
683
  //@}
Charles Law's avatar
Charles Law committed
684

685
protected:
686
  /**
687
   * Constructor with default bounds (0,1, 0,1, 0,1).
688
   */
689
  vtkHyperTreeGrid();
690
691
692
693

  /**
   * Destructor
   */
694
  ~vtkHyperTreeGrid() override;
Philippe Pébay's avatar
Philippe Pébay committed
695

696
  void ComputeBounds() override;
Philippe Pébay's avatar
Philippe Pébay committed
697

698
699
700
701
702
703
  /**
   * Traverse tree with 3x3x3 super cursor. Center cursor generates dual point.
   * Smallest leaf (highest level) owns corners/dual cell.  Ties are given to
   * smallest index (z,y,x order)
   * post: Generate Points and Connectivity.
   */
704
  void ComputeDualGrid();
705

706
707
  vtkPoints* GetPoints();
  vtkIdTypeArray* GetConnectivity();
708

709
710
711
  unsigned int BranchFactor; // 2 or 3
  unsigned int Dimension;    // 1, 2, or 3
  unsigned int Orientation;  // 0, 1, or 2
712
  unsigned int GridSize[3];
713
  int Extent[6];
714
  unsigned int NumberOfChildren;
715
  bool TransposedRootIndexing;
Philippe Pébay's avatar
Philippe Pébay committed
716

Philippe Pébay's avatar
Philippe Pébay committed
717
  vtkBitArray* MaterialMask;
718
  vtkBitArray* PureMaterialMask;
719
  vtkIdTypeArray* MaterialMaskIndex;
720
721
722
  bool InitPureMaterialMask;

  bool HasInterface;
723
724
  char* InterfaceNormalsName;
  char* InterfaceInterceptsName;
725

726
727
728
  vtkDataArray* XCoordinates;
  vtkDataArray* YCoordinates;
  vtkDataArray* ZCoordinates;
729

730
  std::map<vtkIdType, vtkHyperTree*> HyperTrees;
Philippe Pébay's avatar
Philippe Pébay committed
731

732
733
  vtkPoints* Points;
  vtkIdTypeArray* Connectivity;
734
  std::map<vtkIdType, bool> PointShifted;
735
  std::map<vtkIdType, double> PointShifts[3];
736
  std::map<vtkIdType, double> ReductionFactors;
Philippe Pébay's avatar
Philippe Pébay committed
737

738
739
740
741
  /**
   * Perform left to right deep copy of hyper tree cursors.
   */
  void DeepCopyCursors( vtkHyperTreeCursor*, vtkHyperTreeCursor* );
Philippe Pébay's avatar
Philippe Pébay committed
742

743
744
745
746
  /**
   * Remove existing trees.
   */
  void DeleteTrees();
Philippe Pébay's avatar
Philippe Pébay committed
747

748
749
750
751
  /**
   * Reset dual mesh
   */
  void ResetDual();
Philippe Pébay's avatar
Philippe Pébay committed
752

753
754
755
756
757
758
759
760
  /**
   * A convenience method to reset all cursors in a super cursor,
   * either Von Neumann or Moore.
   * This is to be used by Initialize() and ToRoot(), factoring
   * out the commonalities shared by these methods, while allowing for
   * different inheritances.
   */
  void ResetSuperCursor();
Charles Law's avatar
Charles Law committed
761

762
763
764
765
  /**
   * Recursively descend into tree down to leaves to generate dual.
   */
  void TraverseDualRecursively( vtkHyperTreeGridCursor* );
766

767
768
769
770
771
  /**
   * Recursively descend into tree down to leaves to generate dual,
   * when a mask array is present.
   */
  void TraverseDualRecursively( vtkHyperTreeGridCursor*, vtkBitArray* );
772

773
774
775
776
  /**
   * Process leaf cell and issue corresponding dual corner point in 1D.
   */
  void GenerateDualCornerFromLeaf1D( vtkHyperTreeGridCursor* );
777

778
779
780
781
782
  /**
   * Process leaf cell and issue corresponding dual corner point in 1D,
   * when a mask array is present.
   */
  void GenerateDualCornerFromLeaf1D( vtkHyperTreeGridCursor*, vtkBitArray* );
783

784
785
786
787
  /**
   * Process leaf cell and issue corresponding dual corner point in 2D.
   */
  void GenerateDualCornerFromLeaf2D( vtkHyperTreeGridCursor* );
788

789
790
791
792
793
  /**
   * Process leaf cell and issue corresponding dual corner point in 2D,
   * when a mask array is present.
   */
  void GenerateDualCornerFromLeaf2D( vtkHyperTreeGridCursor*, vtkBitArray* );
794

795
796
797
798
  /**
   * Process leaf cell and issue corresponding dual corner point in 3D.
   */
  void GenerateDualCornerFromLeaf3D( vtkHyperTreeGridCursor* );
799

800
801
802
803
804
  /**
   * Process leaf cell and issue corresponding dual corner point in 3D,
   * when a mask array is present.
   */
  void GenerateDualCornerFromLeaf3D( vtkHyperTreeGridCursor*, vtkBitArray* );
805

806
807
808
809
  /**
   * Compute appropriate shifts for dual corners of masked cells in 2D.
   */
  void ShiftDualCornerFromMaskedLeaf2D( vtkHyperTreeGridCursor*, vtkBitArray* );
810

811
812
813
814
  /**
   * Compute appropriate shifts for dual corners of masked cells in 3D.
   */
  void ShiftDualCornerFromMaskedLeaf3D( vtkHyperTreeGridCursor*, vtkBitArray* );
815

816
817
818
819
820
821
822
  /**
   * Recursive method called under the hood by FindPoint().
   */
  vtkIdType RecursivelyFindPoint( double x[3],
                                  vtkHyperTreeGridCursor*,
                                  double*,
                                  double* );
823

824
#if !defined(__VTK_WRAP__) && !defined(__WRAP_GCCXML__)
825
826
  void EvaluateDualCorner( vtkHyperTreeSimpleCursor* );
#endif
827

828
829
830
831
832
833
834
835
  //@{
  /**
   * These are needed by the GetCell() method.
   */
  vtkLine* Line;
  vtkPixel* Pixel;
  vtkVoxel* Voxel;
  //@}
836

837
838
839
840
841
842
843
  //@{
  /**
   * Not really needed. Might be removed (is it a part of the vtkDataSet API?).
   */
  vtkCellLinks* Links;
  void BuildLinks();
  //@}
844

845
private:
846
847
  vtkHyperTreeGrid(const vtkHyperTreeGrid&) = delete;
  void operator=(const vtkHyperTreeGrid&) = delete;
848
849

  void GetCellImplementation( vtkIdType, vtkCell* );
Charles Law's avatar
Charles Law committed
850
851
};

Philippe Pébay's avatar
Philippe Pébay committed
852
#endif