如何在vtk中仅显示纹理表面上的三角形边界?

发布于 2024-12-06 13:48:17 字数 1334 浏览 2 评论 0原文

我想显示一个有纹理的表面。我希望三角形边界在表面上以不同的颜色可见(比如说红色)。我从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兮颜 2024-12-13 13:48:17

您需要从 vtkPolyData 对象中提取边缘:

edges = vtk.vtkExtractEdges()
edges.SetInput(trianglePolyData)
edge_mapper = vtk.vtkPolyDataMapper()
edge_mapper.SetInput(edges.GetOutput())

edge_actor = vtk.vtkActor()
edge_actor.SetMapper(edge_mapper)
edge_actor.GetProperty().SetColor(1,0,0)

ren.AddActor(edge_actor)

vtk.vtkPolyDataMapper().SetResolveCoincidentTopologyToPolygonOffset()

首先,您必须通过 vtkExtractEdges 过滤器提取边缘。您将该过滤器的结果映射到 vtkPolyData 对象并为该数据构造一个 actor。然后我们通过直接修改 actor 将网格的颜色设置为红色。

调用 vtk.vtkPolyDataMapper().SetResolveCoincidentTopologyToPolygonOffset() 可防止边缘与曲面发生冲突(两个几何对象重合,并且由于 z- 作用而相互撕裂缓冲区精度问题)。

为了完整起见,以下是整个代码:

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)

#++++++++++++++++++++++++++++++++++++++++++++++++
# Get the edges from the mesh
edges = vtk.vtkExtractEdges()
edges.SetInput(trianglePolyData)
edge_mapper = vtk.vtkPolyDataMapper()
edge_mapper.SetInput(edges.GetOutput())

# Make an actor for those edges    
edge_actor = vtk.vtkActor()
edge_actor.SetMapper(edge_mapper)

# Make the actor red (there are other ways of doing this also)
edge_actor.GetProperty().SetColor(1,0,0)

ren.AddActor(edge_actor)

# Avoid z-buffer fighting
vtk.vtkPolyDataMapper().SetResolveCoincidentTopologyToPolygonOffset()
#------------------------------------------------

# enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()

You need to extract the edges from your vtkPolyData object:

edges = vtk.vtkExtractEdges()
edges.SetInput(trianglePolyData)
edge_mapper = vtk.vtkPolyDataMapper()
edge_mapper.SetInput(edges.GetOutput())

edge_actor = vtk.vtkActor()
edge_actor.SetMapper(edge_mapper)
edge_actor.GetProperty().SetColor(1,0,0)

ren.AddActor(edge_actor)

vtk.vtkPolyDataMapper().SetResolveCoincidentTopologyToPolygonOffset()

First you must extract the edges via a vtkExtractEdges filter. You map the results of that filter to a vtkPolyData 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:

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)

#++++++++++++++++++++++++++++++++++++++++++++++++
# Get the edges from the mesh
edges = vtk.vtkExtractEdges()
edges.SetInput(trianglePolyData)
edge_mapper = vtk.vtkPolyDataMapper()
edge_mapper.SetInput(edges.GetOutput())

# Make an actor for those edges    
edge_actor = vtk.vtkActor()
edge_actor.SetMapper(edge_mapper)

# Make the actor red (there are other ways of doing this also)
edge_actor.GetProperty().SetColor(1,0,0)

ren.AddActor(edge_actor)

# Avoid z-buffer fighting
vtk.vtkPolyDataMapper().SetResolveCoincidentTopologyToPolygonOffset()
#------------------------------------------------

# enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文