Skip to content
Snippets Groups Projects
Commit d6d313be authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: use simpler API for vtkPolyhedron

parent 32c03c7c
Branches
Tags
No related merge requests found
...@@ -164,17 +164,10 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -164,17 +164,10 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
// data types - max 'order' = hex = 8 points // data types - max 'order' = hex = 8 points
vtkIdType nodeIds[8]; vtkIdType nodeIds[8];
// hash to establish unique node ids for a polyhedral cell
HashSet<vtkIdType, Hash<label> > hashUniqId(2*256);
// unique node ids for a polyhedral cell
DynamicList<vtkIdType> uniqueNodeIds(256);
// face-stream for a polyhedral cell // face-stream for a polyhedral cell
// [numFace0Pts, id1, id2, id3, numFace1Pts, id1, id2, id3, ...] // [numFace0Pts, id1, id2, id3, numFace1Pts, id1, id2, id3, ...]
DynamicList<vtkIdType> faceStream(256); DynamicList<vtkIdType> faceStream(256);
forAll(cellShapes, cellI) forAll(cellShapes, cellI)
{ {
const cellShape& cellShape = cellShapes[cellI]; const cellShape& cellShape = cellShapes[cellI];
...@@ -282,6 +275,7 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -282,6 +275,7 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
// Polyhedral cell - use VTK_POLYHEDRON // Polyhedral cell - use VTK_POLYHEDRON
const labelList& cFaces = mesh.cells()[cellI]; const labelList& cFaces = mesh.cells()[cellI];
#ifdef HAS_VTK_POLYHEDRON
vtkIdType nFaces = cFaces.size(); vtkIdType nFaces = cFaces.size();
vtkIdType nLabels = nFaces; vtkIdType nLabels = nFaces;
...@@ -292,13 +286,6 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -292,13 +286,6 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
nLabels += f.size(); nLabels += f.size();
} }
// hash to establish unique node ids for a polyhedral cell
hashUniqId.clear();
// unique node ids - approximately equal to the number of point ids
uniqueNodeIds.clear();
uniqueNodeIds.reserve(nLabels-nFaces);
// build face-stream // build face-stream
// [numFace0Pts, id1, id2, id3, numFace1Pts, id1, id2, id3, ...] // [numFace0Pts, id1, id2, id3, numFace1Pts, id1, id2, id3, ...]
// point Ids are global // point Ids are global
...@@ -318,7 +305,6 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -318,7 +305,6 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
{ {
forAll(f, fp) forAll(f, fp)
{ {
hashUniqId.insert(f[fp]);
faceStream.append(f[fp]); faceStream.append(f[fp]);
} }
} }
...@@ -328,32 +314,37 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -328,32 +314,37 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
// or use face::reverseFace() // or use face::reverseFace()
forAllReverse(f, fp) forAllReverse(f, fp)
{ {
hashUniqId.insert(f[fp]);
faceStream.append(f[fp]); faceStream.append(f[fp]);
} }
} }
} }
uniqueNodeIds.append(hashUniqId.sortedToc()); vtkmesh->InsertNextCell(VTK_POLYHEDRON, nFaces, faceStream.data());
vtkIdType nodeCount = uniqueNodeIds.size();
#ifdef HAS_VTK_POLYHEDRON
vtkmesh->InsertNextCell
(
VTK_POLYHEDRON,
nodeCount,
uniqueNodeIds.data(),
nFaces,
faceStream.data()
);
#else #else
// this is a horrible substitute // this is a horrible substitute
// but avoids crashes when there is no vtkPolyhedron support // but avoids crashes when there is no vtkPolyhedron support
// establish unique node ids used
HashSet<vtkIdType, Hash<label> > hashUniqId(2*256);
forAll(cFaces, cFaceI)
{
const face& f = mesh.faces()[cFaces[cFaceI]];
forAll(f, fp)
{
hashUniqId.insert(f[fp]);
}
}
// use face stream to store unique node ids:
faceStream = hashUniqId.sortedToc();
vtkmesh->InsertNextCell vtkmesh->InsertNextCell
( (
VTK_CONVEX_POINT_SET, VTK_CONVEX_POINT_SET,
nodeCount, vtkIdType(faceStream.size()),
uniqueNodeIds.data() faceStream.data()
); );
#endif #endif
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment