VTK 设置面片背面颜色

在上一篇文章切开了零件,发现零件内部和外部颜色一样,当需要不一样时,可以通过actor的SetBackfaceProperty方法设置背面属性。

代码跟上一篇几乎一样,只是给actor设置了SetBackfaceProperty。

//定义背面材质属性
vtkNew<vtkProperty> backfaceProp;
backfaceProp->SetDiffuseColor(0, 1, 0);
//设置背面属性
clipActor->SetBackfaceProperty(backfaceProp);

显示如下:

 

全部代码如下:

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(); //显示线框
        
//定义背面材质属性
vtkNew<vtkProperty> backfaceProp;
backfaceProp->SetDiffuseColor(0, 1, 0);
//设置背面属性
clipActor->SetBackfaceProperty(backfaceProp);

renderer->AddActor(clipActor);

renderer->SetBackground(colors->GetColor3d("SteelBlue").GetData());

vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
renderWindow->SetWindowName("RenderWindowNoUIFile");
ui.vtk_main->setRenderWindow(renderWindow);

 

posted @ 2023-05-20 11:55  上位机  阅读(412)  评论(0编辑  收藏  举报