Skip to content
Snippets Groups Projects
Commit 94b78e30 authored by Mathieu Westphal (Kitware)'s avatar Mathieu Westphal (Kitware) :zap: Committed by Kitware Robot
Browse files

Merge topic 'extractcellbytyp_polyhedron'


40379369 Fix correction omissions
a45d5208 Add Polyhedron type test for ExtractCellsByType test
d4a70d42 Support VTK_POLYHEDRON in vtkExtractCellsByType

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Tested-by: default avatarbuildbot <buildbot@kitware.com>
Reviewed-by: default avatarTiffany Chhim <tiffany.chhim@kitware.com>
Merge-request: !10421
parents c938561f 40379369
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
from vtkmodules.vtkCommonDataModel import (
VTK_HEXAHEDRON,
VTK_LINE,
VTK_POLYHEDRON,
VTK_QUAD,
VTK_TETRA,
VTK_TRIANGLE_STRIP,
......@@ -10,6 +11,7 @@ from vtkmodules.vtkCommonDataModel import (
VTK_WEDGE,
vtkQuadric,
)
from vtkmodules.vtkCommonCore import vtkIdList
from vtkmodules.vtkFiltersCore import (
vtkAppendFilter,
vtkAppendPolyData,
......@@ -108,17 +110,32 @@ print("Number of wedges: {0}".format(extr.GetOutput().GetNumberOfCells()))
if extr.GetOutput().GetNumberOfCells() != 0:
error = 1
# Now construct unstructured grid as conglomerate of tets and voxels. Should
# produce res*res*res + 5*res*res*res cells
# Now construct unstructured grid as conglomerate of tets and voxels.
appendU = vtkAppendFilter()
appendU.AddInputConnection(sample.GetOutputPort())
appendU.AddInputConnection(clip.GetOutputPort())
appendU.Update()
# Add one Polyhedron to the conglomerate. Should
# produce res*res*res + 5*res*res*res + 1 cells
d1 = res+1
d2 = (res+1)*(res+1)
faces = [6,
4, 0+0*d1+0*d2, 0+0*d1+1*d2, 0+1*d1+1*d2, 0+1*d1+0*d2,
4, 1+0*d1+0*d2, 1+1*d1+0*d2, 1+1*d1+1*d2, 1+0*d1+1*d2,
4, 0+0*d1+0*d2, 1+0*d1+0*d2, 1+0*d1+1*d2, 0+0*d1+1*d2,
4, 0+1*d1+0*d2, 0+1*d1+1*d2, 1+1*d1+1*d2, 1+1*d1+0*d2,
4, 0+0*d1+0*d2, 0+1*d1+0*d2, 1+1*d1+0*d2, 1+0*d1+0*d2,
4, 0+0*d1+1*d2, 1+0*d2+1*d2, 1+1*d1+1*d2, 0+1*d1+1*d2]
faceIds = vtkIdList()
[faceIds.InsertNextId(i) for i in faces]
appendU.GetOutput().InsertNextCell(VTK_POLYHEDRON, faceIds)
extr.SetInputConnection(appendU.GetOutputPort())
extr.AddAllCellTypes()
extr.Update()
print("Number of unstructured cells: {0}".format(extr.GetOutput().GetNumberOfCells()))
if extr.GetOutput().GetNumberOfCells() != 6*res*res*res:
if extr.GetOutput().GetNumberOfCells() != 6*res*res*res + 1:
error = 1
extr.RemoveAllCellTypes()
......@@ -135,6 +152,13 @@ print("\tNumber of voxels: {0}".format(extr.GetOutput().GetNumberOfCells()))
if extr.GetOutput().GetNumberOfCells() != res*res*res:
error = 1
extr.RemoveAllCellTypes()
extr.AddCellType(VTK_POLYHEDRON)
extr.Update()
print("\tNumber of polyhedrons: {0}".format(extr.GetOutput().GetNumberOfCells()))
if extr.GetOutput().GetNumberOfCells() != 1:
error = 1
# Now construct polydata as a conglomerate of verts, lines, polys
centers = vtkCellCenters()
centers.SetInputConnection(sample.GetOutputPort())
......
......@@ -365,19 +365,45 @@ void vtkExtractCellsByType::ExtractUnstructuredGridCells(
cellType = input->GetCellType(cellId);
if (this->ExtractCellType(cellType))
{
input->GetCellPoints(cellId, ptIds);
npts = ptIds->GetNumberOfIds();
for (i = 0; i < npts; ++i)
if (cellType == VTK_POLYHEDRON)
{
ptId = ptIds->GetId(i);
if (ptMap[ptId] < 0)
vtkIdType nfaces;
const vtkIdType* facePtIds;
input->GetFaceStream(cellId, nfaces, facePtIds);
for (vtkIdType id = 0; id < nfaces; ++id)
{
ptMap[ptId] = numNewPts++;
vtkIdType nPoints = facePtIds[0];
ptIds->InsertNextId(nPoints);
for (vtkIdType j = 1; j <= nPoints; ++j)
{
ptId = facePtIds[j];
if (ptMap[ptId] < 0)
{
ptMap[ptId] = numNewPts++;
}
ptIds->InsertNextId(ptMap[ptId]);
}
facePtIds += nPoints + 1;
}
ptIds->InsertId(i, ptMap[ptId]);
newCellId = output->InsertNextCell(VTK_POLYHEDRON, nfaces, ptIds->GetPointer(0));
}
else
{
input->GetCellPoints(cellId, ptIds);
npts = ptIds->GetNumberOfIds();
for (i = 0; i < npts; ++i)
{
ptId = ptIds->GetId(i);
if (ptMap[ptId] < 0)
{
ptMap[ptId] = numNewPts++;
}
ptIds->InsertId(i, ptMap[ptId]);
}
newCellId = output->InsertNextCell(cellType, ptIds);
}
newCellId = output->InsertNextCell(cellType, ptIds);
outCD->CopyData(inCD, cellId, newCellId);
ptIds->Reset();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment