#The visualization code in ParaView is as follows: import vtk import numpy as np input = self.GetInput() output = self.GetPolyDataOutput() # ===================== Adjust these two parameters by yourself ===================== height = 20 # Vertical height (up-down direction) thickness = 5 # Lateral thickness (perpendicular to the trajectory direction) # ==================================================================================== pts = input.GetPoints() lines = input.GetLines() new_pts = vtk.vtkPoints() new_polys = vtk.vtkCellArray() idList = vtk.vtkIdList() lines.InitTraversal() while lines.GetNextCell(idList): n = idList.GetNumberOfIds() for i in range(n - 1): # Two adjacent points p0 = np.array(pts.GetPoint(idList.GetId(i))) p1 = np.array(pts.GetPoint(idList.GetId(i+1))) # Trajectory direction dir = p1 - p0 dir = dir / np.linalg.norm(dir) if np.linalg.norm(dir) > 1e-12 else dir # Construct cross-section coordinate system: lateral + vertical up = np.array([0, 0, 1.0]) if abs(np.dot(dir, up)) > 0.99: up = np.array([1, 0, 0]) # Lateral: thickness direction side = np.cross(dir, up) side = side / np.linalg.norm(side) # Vertical: height direction vert = np.cross(side, dir) # 8 corner points hh = height / 2 ht = thickness / 2 c1 = p0 - ht*side - hh*vert c2 = p0 + ht*side - hh*vert c3 = p0 + ht*side + hh*vert c4 = p0 - ht*side + hh*vert c5 = p1 - ht*side - hh*vert c6 = p1 + ht*side - hh*vert c7 = p1 + ht*side + hh*vert c8 = p1 - ht*side + hh*vert # Insert points base = new_pts.GetNumberOfPoints() new_pts.InsertNextPoint(c1) new_pts.InsertNextPoint(c2) new_pts.InsertNextPoint(c3) new_pts.InsertNextPoint(c4) new_pts.InsertNextPoint(c5) new_pts.InsertNextPoint(c6) new_pts.InsertNextPoint(c7) new_pts.InsertNextPoint(c8) # 6 faces quads = [ (0,1,5,4), (1,2,6,5), (2,3,7,6), (3,0,4,7), (0,3,2,1), (4,5,6,7) ] for q in quads: quad = vtk.vtkQuad() pids = quad.GetPointIds() pids.SetId(0, base+q[0]) pids.SetId(1, base+q[1]) pids.SetId(2, base+q[2]) pids.SetId(3, base+q[3]) new_polys.InsertNextCell(quad) output.SetPoints(new_pts) output.SetPolys(new_polys)