Hello,
For a non-spherical shape, it is needed to use the Programmable filter so that the surface of the shape is extruded in each surface normal direction. As the simplest example, the state file is attached:
extrusion.zip (356.1 KB)
And, the figure below shows the result.
Here is programmable filter:
- Output Data set Type: vtkUnstructuredGrid
- Script:
import numpy as np
pdi = self.GetInput()
ugo = self.GetOutput()
ugo.Allocate()
scale = 0.2
num_pts = pdi.GetNumberOfPoints()
num_cells = pdi.GetNumberOfCells()
new_pts = pdi.GetPoints()
in_pd = pdi.GetPointData()
out_pd = ugo.GetPointData()
out_pd.CopyAllocate(in_pd);
normals =in_pd.GetArray('Normals')
id_map = {}
for i in range(num_pts):
point = np.array(pdi.GetPoint(i))
normal = np.array(normals.GetTuple3(i))
j = new_pts.InsertNextPoint(point+normal*scale)
out_pd.CopyData(in_pd, i, i)
out_pd.CopyData(in_pd, i, j)
id_map[i] = j
ids = vtk.vtkIdList()
for c_id in range(num_cells):
pdi.GetCellPoints(c_id, ids)
new_ids = ids
for id in range(ids.GetNumberOfIds()):
extruded_pt_id = id_map[ids.GetId(id)]
new_ids.InsertNextId(extruded_pt_id)
ugo.InsertNextCell(vtk.VTK_WEDGE, new_ids)
ugo.SetPoints(new_pts)