我想要的内容:指定一组点,使用vtkCellArray
指定连接,使其成为一个封闭的圆圈,从中创建vtkPolyData
并应用{ {1}}给它一些量。
我得到了什么:尽管明确定义了这个,但是没有正确连接第一个和最后一个元素的循环。另一个令人困惑的事情是,管子看起来越来越接近错误连接的开始/结束。
我做了什么:我从VTK wiki开始使用this example了解如何创建折线。这是代码(Python 3.4,VTK 7.0):
vtkTubeFilter
我希望有人对如何解决此问题有任何建议。我想到的是import vtk
def rendering(mapper):
"""Takes mapper and handles the rendering."""
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Create a renderer, render window, and interactor
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
# Add the actors to the scene
renderer.AddActor(actor)
# Render and interact
renderWindow.Render()
renderWindowInteractor.Start()
return
pts = vtk.vtkPoints()
pts.SetNumberOfPoints(4)
pts.SetPoint(0, 0.5, 0, 0)
pts.SetPoint(1, 1, 0.5, 0)
pts.SetPoint(2, 0.5, 1, 0)
pts.SetPoint(3, 0, 0.5, 0)
lines = vtk.vtkCellArray()
lines.InsertNextCell(5)
lines.InsertCellPoint(0)
lines.InsertCellPoint(1)
lines.InsertCellPoint(2)
lines.InsertCellPoint(3)
lines.InsertCellPoint(0)
poly = vtk.vtkPolyData()
poly.SetPoints(pts)
poly.SetLines(lines)
tubes = vtk.vtkTubeFilter()
tubes.SetInputData(poly)
tubes.CappingOn()
tubes.SidesShareVerticesOff()
tubes.SetNumberOfSides(4)
tubes.SetRadius(0.1)
tubes.Update()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(tubes.GetOutput())
rendering(mapper)
或polydata
中我缺少的参数。
答案 0 :(得分:1)
管式过滤器不支持生成周期性管。您应该能够通过使接缝(管子相遇)共线来近似效果。而不是
pts = vtk.vtkPoints()
pts.SetNumberOfPoints(4)
pts.SetPoint(0, 0.5, 0, 0)
pts.SetPoint(1, 1, 0.5, 0)
pts.SetPoint(2, 0.5, 1, 0)
pts.SetPoint(3, 0, 0.5, 0)
lines = vtk.vtkCellArray()
lines.InsertNextCell(5)
lines.InsertCellPoint(0)
lines.InsertCellPoint(1)
lines.InsertCellPoint(2)
lines.InsertCellPoint(3)
lines.InsertCellPoint(0)
你可以这样做:
pts = vtk.vtkPoints()
pts.SetNumberOfPoints(5)
pts.SetPoint(0, 0.25, 0.25, 0)
pts.SetPoint(1, 0.5, 0, 0)
pts.SetPoint(2, 1, 0.5, 0)
pts.SetPoint(3, 0.5, 1, 0)
pts.SetPoint(4, 0, 0.5, 0)
lines = vtk.vtkCellArray()
lines.InsertNextCell(6, range(5) + [0,])
你可能想要转动CappingOff(),因为接缝会出现在一个片段的中间。
“凹凸”也将移动到接缝处,似乎是VTK中的一个错误。如果尚未列出问题,您应该搜索VTK的错误跟踪器并提交报告。
答案 1 :(得分:1)
虽然这是几年前的事,但后来者可能想看看这个 PR:https://gitlab.kitware.com/vtk/vtk/-/merge_requests/2047
它没有制作成母版,但是使用更改,您可以这样做以从环形多段线获得一个封闭的管:
// Reset input polydata to a single cell, looped polyline
double lpt0[3] = { 0.0, 0.0, 0.0 };
double lpt1[3] = { 1.0, 0.0, 0.0 };
double lpt2[3] = { 1.0, 1.0, 0.0 };
double lpt3[3] = { 0.0, 1.0, 0.0 };
vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();
pts->InsertNextPoint(lpt0);
pts->InsertNextPoint(lpt1);
pts->InsertNextPoint(lpt2);
pts->InsertNextPoint(lpt3);
vtkSmartPointer<vtkPolyLine> line
= vtkSmartPointer<vtkPolyLine>::New();
line->GetPointIds()->InsertNextId(0);
line->GetPointIds()->InsertNextId(1);
line->GetPointIds()->InsertNextId(2);
line->GetPointIds()->InsertNextId(3);
line->GetPointIds()->InsertNextId(0);
vtkSmartPointer<vtkCellArray> cells
= vtkSmartPointer<vtkCellArray>::New();
cells->InsertNextCell(line);
inputPolyData = vtkSmartPointer<vtkPolyData>::New();
inputPolyData->SetPoints(pts);
inputPolyData->SetLines(cells);
tubeFilter->SetInputData(inputPolyData);
tubeFilter->LoopedOn();
tubeFilter->Update();