Part1: 简介
使用 vtkClipPolyData裁切后,切口是开放的,有时我们需要切口封闭,可以使用 vtkClipClosedSurface 切割完成的面会进行自动封闭;
vtkClipPolyData: vtk 鼠标截取数据 使用 vtkClipPolyData 裁剪删除选中的矩形区域_恋恋西风的博客-CSDN博客_vtkclippolydata
vtkClipClosedSurface 将使用一组剪裁平面剪裁闭合的多边形曲面。它将通过在剪切输入数据的地方创建新的多边形面来生成新的闭合曲面。
Part2:
如:vtkClipPolyData
vtkClipClosedSurface 裁切
下面使用三个面,裁切一个球的结果 ; 可以有多个面裁切
vtkNew<vtkPlaneCollection> planes;
planes->AddItem(clippingPlane);
vtkNew<vtkClipClosedSurface> clipper;
clipper->SetClippingPlanes(planes);
Part3: code
vtkSmartPointer<vtkPlane> clippingPlane = vtkSmartPointer<vtkPlane>::New();
/*Clipping Plane Widget*/
vtkSmartPointer<vtkPlaneWidget> m_pPlaneWidget = vtkSmartPointer<vtkPlaneWidget>::New();
m_pPlaneWidget->SetInteractor(renderWindowInteractor);//与交互器关联
m_pPlaneWidget->SetInputData(triangleFilter->GetOutput());//设置数据集,用于初始化平面,可以不设置
m_pPlaneWidget->SetResolution(50);//即:设置网格数
m_pPlaneWidget->GetPlaneProperty()->SetColor(.2, .8, 0.1);//设置颜色
m_pPlaneWidget->GetPlaneProperty()->SetOpacity(0.5);//设置透明度
m_pPlaneWidget->GetHandleProperty()->SetColor(0, .4, .7);//设置平面顶点颜色
m_pPlaneWidget->GetHandleProperty()->SetLineWidth(1.5);//设置平面线宽
m_pPlaneWidget->NormalToZAxisOn();//初始法线方向平行于Z轴
m_pPlaneWidget->SetRepresentationToWireframe();//平面显示为网格属性
m_pPlaneWidget->SetCenter(actor->GetCenter());//设置平面坐标
m_pPlaneWidget->SetPlaceFactor(1.0);
m_pPlaneWidget->PlaceWidget();//放置平面
m_pPlaneWidget->On();//显示平面
m_pPlaneWidget->GetPlane(clippingPlane);
vtkNew<vtkPlaneCollection> planes;
planes->AddItem(clippingPlane);
vtkNew<vtkClipClosedSurface> clipper;
clipper->SetInputData(this->Data);
clipper->SetClippingPlanes(planes);
//clipper->SetActivePlaneId(2);
clipper->SetScalarModeToColors();
clipper->SetClipColor(colors->GetColor3d("Banana").GetData());
clipper->SetBaseColor(colors->GetColor3d("Tomato").GetData());
clipper->SetActivePlaneColor(colors->GetColor3d("SandyBrown").GetData());
clipper->Update();
this->Data->DeepCopy(clipper->GetOutput());