当前位置:   article > 正文

vtkConnectivityFilter提取连通区域中的问题_使用 vtkimageconnectivityfilter 有问题

使用 vtkimageconnectivityfilter 有问题
  1. 直接使用vtkConnectivityFilter提取连通区域,渲染上没问题,但是打印出polydata中的点数,发现跟原始数据是一致的。
	for (int i = 0; i < numRegions; ++i)
	{
		vtkSmartPointer<vtkConnectivityFilter> connectivityFilter = vtkSmartPointer<vtkConnectivityFilter>::New();
		connectivityFilter->SetInputData(polyData);
		connectivityFilter->SetExtractionModeToSpecifiedRegions();
		connectivityFilter->InitializeSpecifiedRegionList();
		connectivityFilter->AddSpecifiedRegion(i);
		connectivityFilter->Update();
		cout << connectivityFilter->GetOutput()->GetNumberOfPoints() << endl;
	}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

在这里插入图片描述
2. 正确的做法是后街一个vtkCleanPolyData过滤器

	for (int i = 0; i < numRegions; ++i)
   {
   	vtkSmartPointer<vtkConnectivityFilter> connectivityFilter = vtkSmartPointer<vtkConnectivityFilter>::New();
   	connectivityFilter->SetInputData(polyData);
   	connectivityFilter->SetExtractionModeToSpecifiedRegions();
   	connectivityFilter->InitializeSpecifiedRegionList();
   	connectivityFilter->AddSpecifiedRegion(i);
   	connectivityFilter->Update();
   	
   	// 使用vtkCleanPolyData删除孤立点
   	vtkSmartPointer<vtkCleanPolyData> cleanPolyData = vtkSmartPointer<vtkCleanPolyData>::New();
   	cleanPolyData->SetInputData(connectivityFilter->GetOutput());
   	cleanPolyData->Update();
   	
   	cout << cleanPolyData->GetOutput()->GetNumberOfPoints() << endl;
   }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/977584
推荐阅读
相关标签
  

闽ICP备14008679号