<div dir="ltr"><div dir="ltr">Dear list,<div><br></div><div>   I have a very simple script that generates a 2D polydata (similar to a 2D unstructured grid). In this simple script, the polydata has 6 cells. I then apply a vtkLinearExtrusionFilter to make this polydata "3D", by extruding the polydata across the Z direction. The resulting unstructured grid, though, has 41 cells (!). I was expecting it to have the same number of cells as the polydata itself, since the polydata should be implicitly converted into a polyhedron while extruding it...</div><div><br></div><div> I am surely missing something, as maybe "cells" has a different meaning in 2D and 3D. I paste below a small Python example showing what I mean.</div><div><br></div><div>Any suggestion/clarification would be more than welcome - especially on how to convert a polydata into a polyhedron while keeping the same number of cells.</div><div><br></div><div>Thank you in advance.</div><div><br></div><div>Andrea.</div><div><br></div><div><br></div><div># Begin code</div><div><br></div><div><div>import vtk as vtk</div><div>import numpy</div><div><br></div><div>import vtk.util.numpy_support as numpy_support</div><div><br></div><div># X, Y coordinates of a simple grid - Z is zero</div><div><br></div><div>X = [600.4957421, 600.5, 600.5, 600.4957421, 600.4913048, 600.5,</div><div>     600.5, 600.4957421, 600.4913048, 600.4868674, 600.5, 600.5,</div><div>     600.4913048, 600.4868674, 600.4824301, 600.5, 600.5, 600.4868674,</div><div>     600.4824301, 600.4779928, 600.5, 600.5, 600.4824301, 600.4779928,</div><div>     600.4735554, 600.5, 600.5, 600.4779928, 600.4735554]</div><div><br></div><div>Y = [2940.5, 2940.5, 2940.404044, 2940.5, 2940.6, 2940.6, 2940.5,</div><div>     2940.5, 2940.6, 2940.7, 2940.7, 2940.6, 2940.6, 2940.7, 2940.8,</div><div>     2940.8, 2940.7, 2940.7, 2940.8, 2940.9, 2940.9, 2940.8, 2940.8,</div><div>     2940.9, 2941, 2941, 2940.9, 2940.9, 2941]</div><div><br></div><div># First face is triangular, everything else is a 4-sided polygon</div><div>IDS = [range(4)]</div><div>IDS += numpy.split(numpy.arange(4, len(X)), 5)</div><div><br></div><div>npoints = len(X)</div><div>matrix = numpy.zeros((npoints, 3), numpy.float32)</div><div><br></div><div>matrix[:, 0] = X</div><div>matrix[:, 1] = Y</div><div><br></div><div># Create the grid points</div><div>vtk_pts = vtk.vtkPoints()</div><div>vtk_pts.SetData(numpy_support.numpy_to_vtk(matrix, deep=1))</div><div><br></div><div># Create the polydata</div><div>grid = vtk.vtkPolyData()</div><div>grid.SetPoints(vtk_pts)</div><div><br></div><div># Allocate space for the cells in the grid</div><div>nc = len(IDS)</div><div>grid.Allocate(nc)</div><div><br></div><div># Loop through all cells</div><div>for i in xrange(nc):</div><div>    cell_ids = IDS[i]</div><div>    ncoords = len(cell_ids)</div><div>    grid.InsertNextCell(vtk.VTK_POLYGON, ncoords, cell_ids)</div><div><br></div><div>print 'Polydata Cells:', grid.GetNumberOfCells()</div><div><br></div><div>extrude = vtk.vtkLinearExtrusionFilter()</div><div>extrude.SetInputData(grid)</div><div><br></div><div>extrude.SetExtrusionType(1)</div><div>extrude.SetVector(0, 0, 1)</div><div>extrude.CappingOn()</div><div>extrude.SetScaleFactor(1)</div><div>extrude.Update()</div><div><br></div><div>ugrid = extrude.GetOutput()</div><div><br></div><div>print 'Extruded Cells:', ugrid.GetNumberOfCells()</div></div><div><br></div></div></div>