37 #ifndef vtk3DLinearGridInternal_h 38 #define vtk3DLinearGridInternal_h 60 #define MAX_CELL_VERTS 8 65 unsigned char CellType;
66 unsigned char NumVerts;
67 unsigned char NumEdges;
68 unsigned short* Cases;
71 BaseCell(
int cellType)
78 virtual ~BaseCell() {}
88 virtual void BuildCases() = 0;
89 void BuildCases(
int numCases,
const vtkIdType**
edges,
int** cases,
unsigned short* caseArray);
92 unsigned char BaseCell::Mask[
MAX_CELL_VERTS] = { 1, 2, 4, 8, 16, 32, 64, 128 };
94 void BaseCell::BuildCases(
95 int numCases,
const vtkIdType**
edges,
int** cases,
unsigned short* caseArray)
97 int caseOffset = numCases;
98 for (
int caseNum = 0; caseNum < numCases; ++caseNum)
100 caseArray[caseNum] = caseOffset;
101 int* triCases = cases[caseNum];
105 for (count = 0; triCases[count] != (-1); ++count)
108 caseArray[caseOffset++] = count;
112 for (count = 0; triCases[count] != (-1); ++count)
114 edge =
edges[triCases[count]];
115 caseArray[caseOffset++] = edge[0];
116 caseArray[caseOffset++] = edge[1];
123 struct TetraCell :
public BaseCell
125 static unsigned short TetraCases[152];
133 this->Cases = this->TetraCases;
135 ~TetraCell()
override {}
136 void BuildCases()
override;
140 unsigned short TetraCell::TetraCases[152] = { 0 };
143 void TetraCell::BuildCases()
146 int numCases = std::pow(2, this->NumVerts);
147 int** cases =
new int*[numCases];
148 for (
int i = 0; i < this->NumEdges; ++i)
152 for (
int i = 0; i < numCases; ++i)
157 BaseCell::BuildCases(numCases,
edges, cases, this->TetraCases);
164 struct HexahedronCell :
public BaseCell
166 static unsigned short HexahedronCases[5432];
174 this->Cases = this->HexahedronCases;
176 ~HexahedronCell()
override {}
177 void BuildCases()
override;
180 unsigned short HexahedronCell::HexahedronCases[5432] = { 0 };
183 void HexahedronCell::BuildCases()
186 int numCases = std::pow(2, this->NumVerts);
187 int** cases =
new int*[numCases];
188 for (
int i = 0; i < this->NumEdges; ++i)
192 for (
int i = 0; i < numCases; ++i)
197 BaseCell::BuildCases(numCases,
edges, cases, this->HexahedronCases);
204 struct WedgeCell :
public BaseCell
206 static unsigned short WedgeCases[968];
214 this->Cases = this->WedgeCases;
216 ~WedgeCell()
override {}
217 void BuildCases()
override;
220 unsigned short WedgeCell::WedgeCases[968] = { 0 };
223 void WedgeCell::BuildCases()
226 int numCases = std::pow(2, this->NumVerts);
227 int** cases =
new int*[numCases];
228 for (
int i = 0; i < this->NumEdges; ++i)
232 for (
int i = 0; i < numCases; ++i)
237 BaseCell::BuildCases(numCases,
edges, cases, this->WedgeCases);
244 struct PyramidCell :
public BaseCell
246 static unsigned short PyramidCases[448];
254 this->Cases = this->PyramidCases;
256 ~PyramidCell()
override {}
257 void BuildCases()
override;
260 unsigned short PyramidCell::PyramidCases[448] = { 0 };
263 void PyramidCell::BuildCases()
266 int numCases = std::pow(2, this->NumVerts);
267 int** cases =
new int*[numCases];
268 for (
int i = 0; i < this->NumEdges; ++i)
272 for (
int i = 0; i < numCases; ++i)
277 BaseCell::BuildCases(numCases,
edges, cases, this->PyramidCases);
284 struct VoxelCell :
public BaseCell
286 static unsigned short VoxCases[5432];
294 this->Cases = this->VoxCases;
296 ~VoxelCell()
override {}
297 void BuildCases()
override;
300 unsigned short VoxelCell::VoxCases[5432] = { 0 };
305 void VoxelCell::BuildCases()
310 constexpr
vtkIdType voxEdges[12][2] = { { 0, 1 }, { 1, 3 }, { 2, 3 }, { 0, 2 }, { 4, 5 },
311 { 5, 7 }, { 6, 7 }, { 4, 6 }, { 0, 4 }, { 1, 5 }, { 2, 6 }, { 3, 7 } };
313 for (
int i = 0; i < this->NumEdges; ++i)
315 edges[i] = voxEdges[i];
320 unsigned int numCases = std::pow(2, this->NumVerts);
321 int** cases =
new int*[numCases];
322 unsigned int hexCase, voxCase;
323 for (hexCase = 0; hexCase < numCases; ++hexCase)
325 voxCase = ((hexCase & BaseCell::Mask[0]) ? 1 : 0) << 0;
326 voxCase |= ((hexCase & BaseCell::Mask[1]) ? 1 : 0) << 1;
327 voxCase |= ((hexCase & BaseCell::Mask[2]) ? 1 : 0) << 3;
328 voxCase |= ((hexCase & BaseCell::Mask[3]) ? 1 : 0) << 2;
329 voxCase |= ((hexCase & BaseCell::Mask[4]) ? 1 : 0) << 4;
330 voxCase |= ((hexCase & BaseCell::Mask[5]) ? 1 : 0) << 5;
331 voxCase |= ((hexCase & BaseCell::Mask[6]) ? 1 : 0) << 7;
332 voxCase |= ((hexCase & BaseCell::Mask[7]) ? 1 : 0) << 6;
336 BaseCell::BuildCases(numCases,
edges, cases, this->VoxCases);
343 struct EmptyCell :
public BaseCell
345 static unsigned short EmptyCases[2];
352 this->Cases = this->EmptyCases;
354 ~EmptyCell()
override {}
355 void BuildCases()
override {}
358 unsigned short EmptyCell::EmptyCases[2] = { 0, 0 };
371 unsigned char NumVerts;
372 const unsigned short* Cases;
376 const unsigned char* Types;
383 HexahedronCell* Hexahedron;
384 PyramidCell* Pyramid;
397 , Hexahedron(nullptr)
412 , CellArray(cellArray)
415 this->Tetra =
new TetraCell;
416 this->Hexahedron =
new HexahedronCell;
417 this->Pyramid =
new PyramidCell;
418 this->Wedge =
new WedgeCell;
419 this->Voxel =
new VoxelCell;
420 this->Empty =
new EmptyCell;
428 delete this->Hexahedron;
429 delete this->Pyramid;
436 CellIter(
const CellIter&) =
default;
439 CellIter& operator=(
const CellIter& cellIter)
442 this->Cell =
nullptr;
444 this->NumVerts = cellIter.NumVerts;
445 this->Cases = cellIter.Cases;
447 this->NumCells = cellIter.NumCells;
448 this->Types = cellIter.Types;
449 this->CellArray = cellIter.CellArray;
454 if (cellIter.ConnIter)
457 this->ConnIter->
GoToCell(cellIter.ConnIter->GetCurrentCellId());
461 this->ConnIter =
nullptr;
464 this->Tetra = cellIter.Tetra;
465 this->Hexahedron = cellIter.Hexahedron;
466 this->Pyramid = cellIter.Pyramid;
467 this->Wedge = cellIter.Wedge;
468 this->Voxel = cellIter.Voxel;
469 this->Empty = cellIter.Empty;
477 const unsigned short* GetCase(
unsigned char caseNum)
479 return (this->Cases + this->Cases[caseNum]);
488 this->Cell = this->GetCell(this->Types[cellId]);
489 this->NumVerts = this->Cell->NumVerts;
490 this->Cases = this->Cell->Cases;
513 this->Cell->CellType != this->Types[currentCellId])
515 this->Cell = this->GetCell(this->Types[currentCellId]);
516 this->NumVerts = this->Cell->NumVerts;
517 this->Cases = this->Cell->Cases;
527 unsigned char GetCellType(
vtkIdType cellId) {
return this->Types[cellId]; }
532 this->Cell = this->GetCell(this->Types[cellId]);
533 this->NumVerts = this->Cell->NumVerts;
534 this->Cases = this->Cell->Cases;
544 BaseCell* GetCell(
int cellType)
551 return this->Hexahedron;
555 return this->Pyramid;
566 #endif // vtk3DLinearGridInternal_h
static int * GetTriangleCases(int caseId)
Return the case table for table-based isocontouring (aka marching cubes style implementations).
static const vtkIdType * GetEdgeArray(vtkIdType edgeId)
Return the ids of the vertices defining edge/face (edgeId/‘faceId’).
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
void GetCurrentCell(vtkIdType &cellSize, vtkIdType const *&cellPoints)
Returns the definition of the current cell during forward traversal.
bool IsDoneWithTraversal()
Returns true if the iterator has completed the traversal.
static int * GetTriangleCases(int caseId)
Return the case table for table-based isocontouring (aka marching cubes style implementations).
static const vtkIdType * GetEdgeArray(vtkIdType edgeId)
Return the ids of the vertices defining edge/face (edgeId/‘faceId’).
void GoToNextCell()
Advance the forward iterator to the next cell.
static int * GetTriangleCases(int caseId)
Return the case table for table-based isocontouring (aka marching cubes style implementations).
object to represent cell connectivity
vtkSmartPointer< T > TakeSmartPointer(T *obj)
Construct a vtkSmartPointer<T> containing obj.
static const vtkIdType * GetEdgeArray(vtkIdType edgeId)
Return the ids of the vertices defining edge/face (edgeId/‘faceId’).
static const vtkIdType * GetEdgeArray(vtkIdType edgeId)
Return the ids of the vertices defining edge/face (edgeId/‘faceId’).
vtkCellArrayIterator * NewIterator()
NewIterator returns a new instance of vtkCellArrayIterator that is initialized to point at the first ...
static int * GetTriangleCases(int caseId)
Return the case table for table-based isocontouring (aka marching cubes style implementations).
void GoToCell(vtkIdType cellId)
Intialize the iterator to a specific cell.
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
vtkIdType GetCurrentCellId() const
Returns the id of the current cell during forward iteration.