1 /*=========================================================================
2 
3 Program:   Visualization Toolkit
4 Module:    vtkHyperTreeGridNonOrientedVonNeumannSuperCursor.cxx
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 Nonice for more information.
13 
14 =========================================================================*/
15 #include "vtkHyperTreeGridNonOrientedVonNeumannSuperCursor.h"
16 
17 #include "vtkHyperTree.h"
18 #include "vtkHyperTreeGrid.h"
19 #include "vtkHyperTreeGridGeometryLevelEntry.h"
20 #include "vtkHyperTreeGridNonOrientedGeometryCursor.h"
21 
22 #include "vtkObjectFactory.h"
23 
24 #include <cassert>
25 
26 vtkStandardNewMacro(vtkHyperTreeGridNonOrientedVonNeumannSuperCursor);
27 
28 // NOLINTNEXTLINE(bugprone-suspicious-include)
29 #include "vtkHyperTreeGridNonOrientedVonNeumannSuperCursorData.cxx"
30 
31 //------------------------------------------------------------------------------
Initialize(vtkHyperTreeGrid * grid,vtkIdType treeIndex,bool create)32 void vtkHyperTreeGridNonOrientedVonNeumannSuperCursor::Initialize(
33   vtkHyperTreeGrid* grid, vtkIdType treeIndex, bool create)
34 {
35   assert("pre: Non_valid_dimension" && grid->GetDimension() >= 1 && grid->GetDimension() <= 3);
36   assert(
37     "pre: Non_valid_branchfactor" && grid->GetBranchFactor() >= 2 && grid->GetBranchFactor() <= 3);
38 
39   if (this->Grid == nullptr)
40   {
41     this->Grid = grid;
42   }
43   assert("pre: Non_same_grid" && this->Grid == grid);
44 
45   // JB Initialize caracteristique
46   switch (grid->GetDimension())
47   {
48     case 1:
49     {
50       switch (grid->GetBranchFactor())
51       {
52         case 2:
53         {
54           // dimension = 1, branch factor = 2
55           this->IndiceCentralCursor = 1;
56           this->NumberOfCursors = 3;
57           this->ChildCursorToParentCursorTable = VonNeumannChildCursorToParentCursorTable[0][0];
58           this->ChildCursorToChildTable = VonNeumannChildCursorToChildTable[0][0];
59           break;
60         }
61         case 3:
62         {
63           // dimension = 1, branch factor = 3
64           this->IndiceCentralCursor = 1;
65           this->NumberOfCursors = 3;
66           this->ChildCursorToParentCursorTable = VonNeumannChildCursorToParentCursorTable[0][1];
67           this->ChildCursorToChildTable = VonNeumannChildCursorToChildTable[0][1];
68           break;
69         }
70       } // switch BranchFactor
71       break;
72     }
73     case 2:
74     {
75       switch (grid->GetBranchFactor())
76       {
77         case 2:
78         {
79           // dimension = 2, branch factor = 2
80           this->IndiceCentralCursor = 2;
81           this->NumberOfCursors = 5;
82           this->ChildCursorToParentCursorTable = VonNeumannChildCursorToParentCursorTable[1][0];
83           this->ChildCursorToChildTable = VonNeumannChildCursorToChildTable[1][0];
84           break;
85         }
86         case 3:
87         {
88           // dimension = 2, branch factor = 3
89           this->IndiceCentralCursor = 2;
90           this->NumberOfCursors = 5;
91           this->ChildCursorToParentCursorTable = VonNeumannChildCursorToParentCursorTable[1][1];
92           this->ChildCursorToChildTable = VonNeumannChildCursorToChildTable[1][1];
93           break;
94         }
95       } // switch BranchFactor
96       break;
97     }
98     case 3:
99     {
100       switch (grid->GetBranchFactor())
101       {
102         case 2:
103         {
104           // dimension = 3, branch factor = 2
105           this->IndiceCentralCursor = 3;
106           this->NumberOfCursors = 7;
107           this->ChildCursorToParentCursorTable = VonNeumannChildCursorToParentCursorTable[2][0];
108           this->ChildCursorToChildTable = VonNeumannChildCursorToChildTable[2][0];
109           break;
110         }
111         case 3:
112         {
113           // dimension = 3, branch factor = 3
114           this->IndiceCentralCursor = 3;
115           this->NumberOfCursors = 7;
116           this->ChildCursorToParentCursorTable = VonNeumannChildCursorToParentCursorTable[2][1];
117           this->ChildCursorToChildTable = VonNeumannChildCursorToChildTable[2][1];
118           break;
119         }
120       } // switch BranchFactor
121       break;
122     }
123   } // switch Dimension
124 
125   // JB Pour le niveau zero tout est defini
126   this->CentralCursor->Initialize(grid, treeIndex, create);
127   //
128   this->CurrentFirstNonValidEntryByLevel = 0;
129   if (this->FirstNonValidEntryByLevel.size() <= this->CurrentFirstNonValidEntryByLevel + 1)
130   {
131     this->FirstNonValidEntryByLevel.resize(this->CurrentFirstNonValidEntryByLevel + 1);
132   }
133   this->FirstNonValidEntryByLevel[this->CurrentFirstNonValidEntryByLevel] =
134     this->NumberOfCursors - 1;
135   bool isOld = true;
136   if (this->Entries.size() <= this->CurrentFirstNonValidEntryByLevel + 1)
137   {
138     isOld = false;
139     this->Entries.resize(this->FirstNonValidEntryByLevel[this->CurrentFirstNonValidEntryByLevel]);
140   }
141   // JB Pour le niveau zero tout est reference
142   this->FirstCurrentNeighboorReferenceEntry = 0;
143   if (this->ReferenceEntries.size() <=
144     this->FirstCurrentNeighboorReferenceEntry + this->NumberOfCursors - 1)
145   {
146     this->ReferenceEntries.resize(
147       this->FirstCurrentNeighboorReferenceEntry + this->NumberOfCursors - 1);
148   }
149   std::vector<unsigned int>::iterator it = this->ReferenceEntries.begin();
150   for (unsigned int icrt = this->FirstCurrentNeighboorReferenceEntry;
151        it != this->ReferenceEntries.end(); ++it, ++icrt)
152   {
153     (*it) = icrt;
154   }
155 
156   // If dimension=d: center cursor is d
157   //                 d-faces neighbor cursors are 0,...,2d except d
158   unsigned int i, j, k;
159   grid->GetLevelZeroCoordinatesFromIndex(treeIndex, i, j, k);
160   unsigned int n[3];
161   grid->GetCellDims(n);
162 
163   // JB Initialisation des cursors
164   switch (grid->GetDimension())
165   {
166     case 1:
167     {
168       // dimension == 1
169       if (i > 0)
170       {
171         // Cell has a neighbor to the left
172         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, (unsigned int)-1, 0, 0);
173         this->Entries[0].Initialize(grid, r);
174       }
175       else if (isOld)
176       {
177         this->Entries[0].Reset();
178       }
179       if (i + 1 < n[0])
180       {
181         // Cell has a neighbor to the right
182         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, 1, 0, 0);
183         this->Entries[1].Initialize(grid, r); // au lieu de 2
184       }
185       else if (isOld)
186       {
187         this->Entries[1].Reset();
188       }
189       break;
190     }
191     case 2:
192     {
193       // dimension == 2
194       if (i > 0)
195       {
196         // Cell has a neighbor to the left
197         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, (unsigned int)-1, 0, 0);
198         this->Entries[1].Initialize(grid, r);
199       }
200       else if (isOld)
201       {
202         this->Entries[1].Reset();
203       }
204       if (i + 1 < n[0])
205       {
206         // Cell has a neighbor to the right
207         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, 1, 0, 0);
208         this->Entries[2].Initialize(grid, r); // au lieu de 2
209       }
210       else if (isOld)
211       {
212         this->Entries[2].Reset();
213       }
214       if (j > 0)
215       {
216         // Cell has a neighbor before
217         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, 0, (unsigned int)-1, 0);
218         this->Entries[0].Initialize(grid, r);
219       }
220       else if (isOld)
221       {
222         this->Entries[0].Reset();
223       }
224       if (j + 1 < n[1])
225       {
226         // Cell has a neighbor after
227         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, 0, 1, 0);
228         this->Entries[3].Initialize(grid, r); // au lieu de 4
229       }
230       else if (isOld)
231       {
232         this->Entries[3].Reset();
233       }
234       break;
235     }
236     case 3:
237     {
238       // dimension == 3
239       if (i > 0)
240       {
241         // Cell has a neighbor to the left
242         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, (unsigned int)-1, 0, 0);
243         this->Entries[2].Initialize(grid, r);
244       }
245       else if (isOld)
246       {
247         this->Entries[2].Reset();
248       }
249       if (i + 1 < n[0])
250       {
251         // Cell has a neighbor to the right
252         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, 1, 0, 0);
253         this->Entries[3].Initialize(grid, r); // au lieu de 4
254       }
255       else if (isOld)
256       {
257         this->Entries[3].Reset();
258       }
259       if (j > 0)
260       {
261         // Cell has a neighbor before
262         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, 0, (unsigned int)-1, 0);
263         this->Entries[1].Initialize(grid, r);
264       }
265       else if (isOld)
266       {
267         this->Entries[1].Reset();
268       }
269       if (j + 1 < n[1])
270       {
271         // Cell has a neighbor after
272         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, 0, 1, 0);
273         this->Entries[4].Initialize(grid, r); // au lieu de 5
274       }
275       else if (isOld)
276       {
277         this->Entries[4].Reset();
278       }
279       if (k > 0)
280       {
281         // Cell has a neighbor below
282         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, 0, 0, (unsigned int)-1);
283         this->Entries[0].Initialize(grid, r);
284       }
285       else if (isOld)
286       {
287         this->Entries[0].Reset();
288       }
289       if (k + 1 < n[2])
290       {
291         // Cell has a neighbor above
292         unsigned int r = grid->GetShiftedLevelZeroIndex(treeIndex, 0, 0, 1);
293         this->Entries[5].Initialize(grid, r); // au lieu de 6
294       }
295       else if (isOld)
296       {
297         this->Entries[5].Reset();
298       }
299       break;
300     }
301   } // switch Dimension
302 }
303 
304 //------------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)305 void vtkHyperTreeGridNonOrientedVonNeumannSuperCursor::PrintSelf(ostream& os, vtkIndent indent)
306 {
307   os << indent << "--vtkHyperTreeGridNonOrientedVonNeumannSuperCursor--" << endl;
308   vtkHyperTreeGridNonOrientedSuperCursor::PrintSelf(os, indent);
309 }
310 
311 //------------------------------------------------------------------------------
312 vtkHyperTreeGridNonOrientedVonNeumannSuperCursor::
313   ~vtkHyperTreeGridNonOrientedVonNeumannSuperCursor() = default;
314 
315 //------------------------------------------------------------------------------
316