[vtkusers] vtkLinearExtrusionFilter and number of cells

Andrea Gavana andrea.gavana at gmail.com
Thu Sep 27 08:16:10 EDT 2018


Dear list,

   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...

 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.

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.

Thank you in advance.

Andrea.


# Begin code

import vtk as vtk
import numpy

import vtk.util.numpy_support as numpy_support

# X, Y coordinates of a simple grid - Z is zero

X = [600.4957421, 600.5, 600.5, 600.4957421, 600.4913048, 600.5,
     600.5, 600.4957421, 600.4913048, 600.4868674, 600.5, 600.5,
     600.4913048, 600.4868674, 600.4824301, 600.5, 600.5, 600.4868674,
     600.4824301, 600.4779928, 600.5, 600.5, 600.4824301, 600.4779928,
     600.4735554, 600.5, 600.5, 600.4779928, 600.4735554]

Y = [2940.5, 2940.5, 2940.404044, 2940.5, 2940.6, 2940.6, 2940.5,
     2940.5, 2940.6, 2940.7, 2940.7, 2940.6, 2940.6, 2940.7, 2940.8,
     2940.8, 2940.7, 2940.7, 2940.8, 2940.9, 2940.9, 2940.8, 2940.8,
     2940.9, 2941, 2941, 2940.9, 2940.9, 2941]

# First face is triangular, everything else is a 4-sided polygon
IDS = [range(4)]
IDS += numpy.split(numpy.arange(4, len(X)), 5)

npoints = len(X)
matrix = numpy.zeros((npoints, 3), numpy.float32)

matrix[:, 0] = X
matrix[:, 1] = Y

# Create the grid points
vtk_pts = vtk.vtkPoints()
vtk_pts.SetData(numpy_support.numpy_to_vtk(matrix, deep=1))

# Create the polydata
grid = vtk.vtkPolyData()
grid.SetPoints(vtk_pts)

# Allocate space for the cells in the grid
nc = len(IDS)
grid.Allocate(nc)

# Loop through all cells
for i in xrange(nc):
    cell_ids = IDS[i]
    ncoords = len(cell_ids)
    grid.InsertNextCell(vtk.VTK_POLYGON, ncoords, cell_ids)

print 'Polydata Cells:', grid.GetNumberOfCells()

extrude = vtk.vtkLinearExtrusionFilter()
extrude.SetInputData(grid)

extrude.SetExtrusionType(1)
extrude.SetVector(0, 0, 1)
extrude.CappingOn()
extrude.SetScaleFactor(1)
extrude.Update()

ugrid = extrude.GetOutput()

print 'Extruded Cells:', ugrid.GetNumberOfCells()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180927/84c10c51/attachment.html>


More information about the vtkusers mailing list