Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

python - VTK: render concave polygon with vtkDelaunay2D

I want to render a concave polygon with the use of a vtkDelaunay2D. I've read that it should work with a vtkDelaunay2D, but it doesn't. Why? Here is the my code:

import vtk

points = vtk.vtkPoints()

ls = [
    [5, 5], [-5, 5], [-8, 0], [-5, -5], [5, -5], [2, 0]
]
for x, y in ls:
    points.InsertNextPoint(x, y, 0)

aPolyData = vtk.vtkPolyData()
aPolyData.SetPoints(points)

delaunay = vtk.vtkDelaunay2D()
delaunay.SetInputData(aPolyData)

meshMapper = vtk.vtkPolyDataMapper()
meshMapper.SetInputConnection(delaunay.GetOutputPort())

colors = vtk.vtkNamedColors()

meshActor = vtk.vtkActor()
meshActor.SetMapper(meshMapper)
meshActor.GetProperty().EdgeVisibilityOn()
meshActor.GetProperty().SetEdgeColor(colors.GetColor3d("Peacock"))
meshActor.GetProperty().SetInterpolationToFlat()

renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)

renderer.AddActor(meshActor)
renderer.SetBackground(colors.GetColor3d("Mint"))

renderWindow.SetSize(640, 480)
renderWindow.Render()
renderWindowInteractor.Start()

The result looks like this:

result

The triangle on the right side shouldn't be there.

So why does this happen? And what do I have to do so this doesn't happen?

question from:https://stackoverflow.com/questions/65891622/vtk-render-concave-polygon-with-vtkdelaunay2d

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From the documentation (specially the Warning part), output is expected to be convex.

As workaround for your example, decreasing the Offset value of the filter leads to the result you want (for instance delaunay.SetOffset(0.1)). But as it is not intended by the filter, it may have unexpected results.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...