如何在vtk中仅显示纹理表面上的三角形边界?
我想显示一个有纹理的表面。我希望三角形边界在表面上以不同的颜色可见(比如说红色)。我从 vtk 代码示例中找到了以下代码,但它不显示三角形边界,而是显示填充的三角形。
import vtk
# create a rendering window and renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# create points
points = vtk.vtkPoints()
points.InsertNextPoint(1.0,0.0,0.0)
points.InsertNextPoint(0.0,0.0,0.0)
points.InsertNextPoint(0.0,1.0,0.0)
triangle = vtk.vtkTriangle()
triangle.GetPointIds().SetId(0,0)
triangle.GetPointIds().SetId(1,1)
triangle.GetPointIds().SetId(2,2)
triangles = vtk.vtkCellArray()
triangles.InsertNextCell(triangle)
# polydata object
trianglePolyData = vtk.vtkPolyData()
trianglePolyData.SetPoints( points )
trianglePolyData.SetPolys( triangles )
# mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(trianglePolyData)
# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# assign actor to the renderer
ren.AddActor(actor)
# enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()
谁能告诉我如何仅显示具有特定颜色边界的三角形。
理想情况下,我想在纹理表面上显示三角形。我的数据由三角形组成。赋予 vtk 的三角形的顶点也可能是可见的。
我正在用 python 编码。
多谢
I want to display a surface which is textured. I want the triangles boundaries to be visible over the surface in a different color (lets say red). I have found the following code from the vtk code samples but it does not display the triangle boundaries but the filled triangles.
import vtk
# create a rendering window and renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# create points
points = vtk.vtkPoints()
points.InsertNextPoint(1.0,0.0,0.0)
points.InsertNextPoint(0.0,0.0,0.0)
points.InsertNextPoint(0.0,1.0,0.0)
triangle = vtk.vtkTriangle()
triangle.GetPointIds().SetId(0,0)
triangle.GetPointIds().SetId(1,1)
triangle.GetPointIds().SetId(2,2)
triangles = vtk.vtkCellArray()
triangles.InsertNextCell(triangle)
# polydata object
trianglePolyData = vtk.vtkPolyData()
trianglePolyData.SetPoints( points )
trianglePolyData.SetPolys( triangles )
# mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(trianglePolyData)
# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# assign actor to the renderer
ren.AddActor(actor)
# enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()
Can anybody please let me know that how to display triangle only with the boundaries with a specific color.
I ideally i want to display triangles on a textured surface. My data consist of triangles. It might also be possible that the vertices of the triangles which are given to vtk can be made visible.
I am coding in python.
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要从
vtkPolyData
对象中提取边缘:首先,您必须通过
vtkExtractEdges
过滤器提取边缘。您将该过滤器的结果映射到 vtkPolyData 对象并为该数据构造一个 actor。然后我们通过直接修改 actor 将网格的颜色设置为红色。调用
vtk.vtkPolyDataMapper().SetResolveCoincidentTopologyToPolygonOffset()
可防止边缘与曲面发生冲突(两个几何对象重合,并且由于 z- 作用而相互撕裂缓冲区精度问题)。为了完整起见,以下是整个代码:
You need to extract the edges from your
vtkPolyData
object:First you must extract the edges via a
vtkExtractEdges
filter. You map the results of that filter to avtkPolyData
object and construct an actor for that data. We then set the color of the mesh to red by modifying the actor directly.The call to
vtk.vtkPolyDataMapper().SetResolveCoincidentTopologyToPolygonOffset()
prevents the edges from fighting with the surfaces (the two geometric objects are coincident and tear through each other due to z-buffer precision issues).For completeness sake, here's the whole code: