I want to turn an irregular polygon into a plane through VTK, and then stretch this plane vertically into an irregular cylinder,there are any good ways?I hope that the seniors will give good advice,Sincere thanks!
Try Filters/Modeling/vtkLinearExtrusionFilter
thank you very much sir,it’s very useful for me
---- Replied Message ----
From | Will Schroeder via VTKnoreply@discourse.vtk.org |
- | - |
Date | 01/03/2023 20:29 |
To | wlsc1998@163.comwlsc1998@163.com |
Cc | |
Subject | [VTK] [Support] How to generate a cylinder from an irregular polygon |
| Will Schroeder will.schroeder
January 3 |
- | - |
Try Filters/Modeling/vtkLinearExtrusionFilter
Dear seniors,Take the liberty to bother you again,Based on your previous description, I can use vtkLinearExtrusionFilter to generate the model I want,but,A problem arose with this process,I used two objects, vtkPoints and vtkCellArray, to generate the required polygons, but the parameter value I gave vtkpoints was established by the latitude and longitude in the WGS84 coordinate system,so I can’t export the correct obj model,How should I do。Not sure if my expression is cleared,But below is my code, I hope you can give me a little advice, thank you very much
import vtk
def main():
points = vtk.vtkPoints()
points.InsertPoint(0, 2.0, 1.0, 0.0)
points.InsertPoint(1, 1.0, 1.0, 0.0)
points.InsertPoint(2, 1.0, 2.0, 0.0)
points.InsertPoint(3, -1.0, 2.0, 0.0)
points.InsertPoint(4, -1.0, -1.0, 0.0)
points.InsertPoint(5, 2.0, -1.0, 0.0)
print(points)
print(points.GetNumberOfPoints())
poly = vtk.vtkCellArray()
poly.InsertNextCell(6)
poly.InsertCellPoint(0)
poly.InsertCellPoint(1)
poly.InsertCellPoint(2)
poly.InsertCellPoint(3)
poly.InsertCellPoint(4)
poly.InsertCellPoint(5)
profile = vtk.vtkPolyData()
profile.SetPoints(points)
profile.SetPolys(poly)
normals = vtk.vtkPolyDataNormals()
normals.SetInputData(profile)
normals.SetComputeCellNormals(1)
normals.SetComputePointNormals(0)
normals.SetFeatureAngle(60)
normals.Update()
cellNormals = normals.GetOutput().GetCellData().GetNormals()
for item in range(cellNormals.GetNumberOfTuples()):
value = [0,0,0]
cellNormals.GetTuple(item,value)
print(value[0],value[1],value[2])
# print(normals.GetOutput().GetCellData().GetNormals().GetTuple(0,[0,0,0]))
extrude = vtk.vtkLinearExtrusionFilter()
extrude.SetInputData(profile)
extrude.SetVector(value[0],value[1],value[2])
extrude.SetScaleFactor(10)
extrude.Update()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(extrude.GetOutputPort())
spring = vtk.vtkActor()
spring.SetMapper(mapper)
spring.GetProperty().SetColor(0.0, 0.79, 0.34)
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
ren.AddActor(spring)
renWin.Render()
iren.Start()
if name == ‘main’:
main()
What needs to be added to you:The code I posted above is an example,The parameter I actually inserted is some latitude and longitude values,I’m sorry I didn’t notice until after I uploaded my response