有些时候需要显示零件内部情况,所有会对零件显示进行平面裁剪,这里用到了vtkPlane和vtkClipPolyData。
vtkPlane是定义一个平面,vtkClipPolyData使用vtkPlane定义的平面进行裁剪。
下面列出主要的代码,其他Qt框架代码参考前面文章。
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat()); vtkNew<vtkRenderer> renderer; vtkNew<vtkNamedColors> colors; //定义球 vtkNew<vtkSphereSource> sphereSource; sphereSource->SetRadius(10); sphereSource->SetCenter(0, 0, 0); //定义平面 vtkNew<vtkPlane> plane; plane->SetOrigin(3,0,0); plane->SetNormal(-1, 0, 0); //定义裁剪 vtkNew<vtkClipPolyData> clipper; clipper->SetInputConnection(sphereSource->GetOutputPort()); clipper->SetClipFunction(plane); vtkNew<vtkDataSetMapper> clipMapper; clipMapper->SetInputConnection(clipper->GetOutputPort()); vtkNew<vtkActor> clipActor; clipActor->SetMapper(clipMapper); clipActor->GetProperty()->SetDiffuseColor(colors->GetColor4d("Tomato").GetData()); clipActor->GetProperty()->EdgeVisibilityOn(); //显示线框 renderer->AddActor(clipActor); renderer->SetBackground(colors->GetColor3d("SteelBlue").GetData()); vtkNew<vtkGenericOpenGLRenderWindow> renderWindow; renderWindow->AddRenderer(renderer); renderWindow->SetWindowName("RenderWindowNoUIFile"); ui.vtk_main->setRenderWindow(renderWindow);
显示如下:
标签:sphereSource,VTK,裁剪,renderer,renderWindow,平面,clipActor,vtkNew From: https://www.cnblogs.com/SamFang/p/17417000.html