前言:
vtkPolyDataConnectivityFilter 使用过,但网上没有看到完事的教程;这里整理一下;
提取数据集中连通的多边形数据。
该类是一个滤波器,提取cell(区域) - 拥有公共点或者满足某个阈值
该类在提取连通区域时候有如下6种模式:
1 )提取数据集中的最大(最多点)连接区域:SetExtractionModeTo LargestRegion();
2)提取指定区域号:SetExtractionModeTo SpecifiedRegions();
3)提取共享指定点ids的所有区域:SetExtractionModeTo PointSeededRegions();
4)提取共享指定单元ID的所有区域:SetExtractionModeTo CellSeededRegions();
5)提取最靠近指定点的区域:SetExtractionModeTo ClosestPointRegion();
6)提取所有区域(用于着色区域):SetExtractionModeTo AllRegions()
这个滤波器是针对多边形数据的。
通过修改 ScalarConnectivity 该布尔值,可以修改该类的行为。如果该值为true,算法中① 共享一个点的cell 会被认为是几何连通的;②cell中点的标量在指定的标量范围内;这两种情况下,cell会被认为是连通的。
如果 ScalarConnectivity 和 FullScalarConnectivity 都为 true,只有当cell中所有的点的标量值满足指定范围,该cell才会被认为是连通的。如果 FullScalarConnectivity 为false,cell中任何一个点满足标量的指定范围都会被认为是连通的。
ColorRegionsOn() 用于对不同的连通区域着色。
1. LargestRegion 这种通常取最大的哪个;
vtkNew<vtkPolyDataConnectivityFilter> ConnectivityFilter ;
ConnectivityFilter->SetInputConnection(polyData);
ConnectivityFilter->SetExtractionModeToLargestRegion();
ConnectivityFilter->Updata()
// get largest region
mPolydata->DeepCopy(ConnectivityFilter->GetOutput());
2. SpecifiedRegions 可能会有多个连通区域,每个有相应Id;
需要在第6个的基础上,取其中一个 ;
vtkNew<vtkConnectivityFilter> connectivityFilter;
connectivityFilter->SetInputData(mVtkPolyDataAll);
connectivityFilter->SetExtractionModeToAllRegions();
connectivityFilter->ColorRegionsOn();
connectivityFilter->Update();
int regionNum = connectivityFilter->GetNumberOfExtractedRegions() # 获取连通区域的数目
for (int i =0;i<regionNum;i++)
{
connectivityFilter2 = vtk.vtkPolyDataConnectivityFilter()
connectivityFilter2.SetInputData(mVtkPolyDataAll)
connectivityFilter2.InitializeSpecifiedRegionList() # 清空要提取的连通区域号的列表
connectivityFilter2.SetExtractionModeToSpecifiedRegions() # 用于提取一个或多个连通区域
connectivityFilter2.AddSpecifiedRegion(i) # 设置提取的连通区域号
connectivityFilter2.Update()
// get one region
vtkPolyData * polydata = connectivityFilter2->GetOutput();
}
3. SetExtractionModeToPointSeededRegions 获取包含一个 点 id 的区域;
需要先找到一个点Id,这个 id 通常需要使用交互,鼠标选择得到 ;
vtkSmartPointer<vtkPolyDataConnectivityFilter> connectivityFilter =
vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
connectivityFilter->SetInputData(appendFilter->GetOutput());
connectivityFilter->SetExtractionModeToPointSeededRegions();
connectivityFilter->AddSeed(100);
connectivityFilter->Update();
// get plydata
connectivityFilter->GetOutput();
4. SetExtractionModeToCellSeededRegions 需要指定一个 cell id;
vtkSmartPointer<vtkPolyDataConnectivityFilter> connectivityFilter =
vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
connectivityFilter->SetInputData(polyData);
connectivityFilter->SetExtractionModeToCellSeededRegions();
connectivityFilter->InitializeSeedList();
connectivityFilter->AddSeed(cellId);
connectivityFilter-Update();
6. SetExtractionModeToClosestPointRegion 提取最靠近指定点的区域文章来源:https://www.toymoban.com/news/detail-430952.html
vtkSmartPointer<vtkPolyDataConnectivityFilter> connectivityFilter =
vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
connectivityFilter->SetInputData(polyData);
connectivityFilter->SetExtractionModeToClosestPointRegion();
connectivityFilter->InitializeSeedList();
connectivityFilter->AddSeed(PointId);
connectivityFilter-Update();
6. SetExtractionModeToAllRegions 获取所有连通区域文章来源地址https://www.toymoban.com/news/detail-430952.html
vtkSmartPointer<vtkPolyDataConnectivityFilter> connectFilter1=
vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
connectFilter1->SetInputConnection(contourFilter->GetOutputPort());
connectFilter1->SetExtractionModeToAllRegions();
connectFilter1->ColorRegionsOn();
connectFilter1->MarkVisitedPointIdsOn();
connectFilter1->Update();
int regionNum=connectFilter1->GetNumberOfExtractedRegions();
qDebug()<<"regionNum:"<<regionNum;
到了这里,关于VTK 几何体连通区域分析 vtkPolyDataConnectivityFilter的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!