在VTK9.1.0在Windows10+VS2019+Qt 5.15.2环境下编译安装的Qt例子中,想显示球体表面的网格线。
通过vtkExtractEdges来实现显示全部网格线
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat()); vtkNew<vtkRenderer> renderer; vtkNew<vtkNamedColors> colors; vtkNew<vtkSphereSource> sphereSource; { //球体 vtkNew<vtkPolyDataMapper> sphereMapper; sphereMapper->SetInputConnection(sphereSource->GetOutputPort()); vtkNew<vtkActor> sphereActor; sphereActor->SetMapper(sphereMapper); sphereActor->GetProperty()->SetColor(colors->GetColor4d("Tomato").GetData()); renderer->AddActor(sphereActor); } { //网格线 vtkNew<vtkExtractEdges> extractEdges; extractEdges->SetInputConnection(sphereSource->GetOutputPort()); vtkNew<vtkPolyDataMapper> sphereMapper; sphereMapper->SetInputConnection(extractEdges->GetOutputPort()); vtkNew<vtkActor> sphereActor; sphereActor->SetMapper(sphereMapper); sphereActor->GetProperty()->SetColor(colors->GetColor4d("Black").GetData()); renderer->AddActor(sphereActor); } renderer->SetBackground(colors->GetColor3d("SteelBlue").GetData()); vtkNew<vtkGenericOpenGLRenderWindow> renderWindow; renderWindow->AddRenderer(renderer); renderWindow->SetWindowName("RenderWindowNoUIFile"); ui.vtk_main->setRenderWindow(renderWindow);
如下图所示:
还可以通过vtkFeatureEdges来显示特定的网格线:
1.边界(boundary):只被一个多边形使用的边,或者直线单元;
2.非流行(non-manifold):被三个以上的多边形共用的边;
3.特征边(feature edges):被两个三角形使用,并且两个三角形之间的夹角大于特征角度(可自行设置此角度);
4.流行边(manifold edges):只被两个多边形使用的边。
标签:VTK,sphereMapper,网格线,colors,renderer,sphereActor,3D,vtkNew From: https://www.cnblogs.com/SamFang/p/17415915.html