[vtkusers] Extract surface shell polygons

Alexey Shildyakov shildyakov at saldlab.com
Wed Mar 1 11:02:10 EST 2017


Hello everyone,
I'm sorry if that question has already been answered but I didn't find
anything.

I want to extract only polygons from surface shell of PolyData. So - the
only outside polygons, not inside the volume. What I mean:

from vtk import vtkCellArray, vtkIdList, vtkPoints, vtkPolyData

# coords
raw_points = (
    (-1, -1, 1),
    (-1, 1, 1),
    (1, 1, 1),
    (1, -1, 1),
    (-1, -1, -1),
    (-1, 1, -1),
    (1, 1, -1),
    (1, -1, -1),
    (0, 0, 0)
)

# cell = indexes of triangle
raw_cells = [
    (0, 1, 3),
    (2, 3, 1),
    (4, 5, 0),
    (1, 0, 5),
    (7, 6, 4),
    (5, 4, 6),
    (3, 2, 7),
    (6, 7, 2),
    (1, 5, 2),
    (6, 2, 5),
    (4, 7, 0),
    (3, 0, 7),
]
must_kept = len(raw_cells)
raw_cells.extend((
    (0, 8, 3),
    (1, 8, 2),
    (1, 8, 0),
    (2, 8, 3),
    (5, 8, 4),
    (6, 8, 7),
    (5, 8, 6),
    (4, 8, 7),
))

def init_data():
    points = vtkPoints()
    for i, point in enumerate(raw_points):
        points.InsertPoint(i, point)

    cells = vtkCellArray()
    for raw_cell in raw_cells:
        cell = vtkIdList()
        for id_ in raw_cell:
            cell.InsertNextId(id_)
        cells.InsertNextCell(cell)

    data = vtkPolyData()
    data.SetPoints(points)
    data.SetPolys(cells)
    return data

I use the cube with one point inside and triangle cells for that, I want to
use filter to remove inner cells - it used to extend raw_cells array.
I tried vtkPolyDataConnectivityFilter() and vtkPolyDataConnectivityFilter()
with no success in the way:

data = init_data()

filter_ = vtkPolyDataConnectivityFilter()
filter_.SetInput(data)
filter_.Update()
surface_data = filter_.GetOutput()

print('{} kept after filter {} of
all'.format(surface_data.GetNumberOfCells(), data.GetNumberOfCells()))
print('{} points kept after filter {} of
all'.format(surface_data.GetNumberOfPoints(), data.GetNumberOfPoints()))

And got:
20 kept after filter 20 of all
9 points kept after filter 9 of all

while expected:
12 kept after filter 20 of all
8 points kept after filter 9 of all

Which filter should I use to get the result?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170301/7b6c7083/attachment.html>


More information about the vtkusers mailing list