PolyData connectivity filter with mode to specified regions only shows the first region selected

Hello,

I have a question about vtkPolyDataConnectivityFilter with SetExtractionModeToSpecifiedRegions . It does it well if I only get one region with label 0 or 1. But if I already specified one, the other returns both labels.

           vtkSmartPointer<vtkPolyDataConnectivityFilter>
          GetConnectedComponents(vtkSmartPointer<vtkPolyData> pol) {
                vtkNew<vtkPolyDataConnectivityFilter> result;
                result->SetInputData(pol);
                result->SetExtractionModeToAllRegions();
               result->Modified();
               result->Update();
               return result;
            }

 
         vtkSmartPointer<vtkPolyDataConnectivityFilter> components_alongX =
          GetConnectedComponents(polydata);


      if (components_alongX->GetNumberOfExtractedRegions() == 2) {
        components_alongX->SetExtractionModeToSpecifiedRegions();
        components_alongX->AddSpecifiedRegion(0); 
        components_alongX->Update();

	cout << "Number of cells : " << components_alongX->GetOutput()-
                    >GetNumberOfCells() << "\n";

            components_alongX->SetExtractionModeToSpecifiedRegions();
            components_alongX->AddSpecifiedRegion(1); 
            components_alongX->Update();

           	cout << "Number of cells : " << components_alongX->GetOutput()-
                    >GetNumberOfCells() << "\n";
              }

I have also tried like this. But it was still worse I got both components in both labels

          components_alongX->InitializeSpecifiedRegionList();
          components_alongX->AddSpecifiedRegion(1); //select the region to extract here
          components_alongX->Update();

Someone had the same problem?. I am using vtk 8. Thanks !!

If i do this between region selections:
components_alongX =
GetConnectedComponents(polydata);

and i get the other label It works. But this is not efficient at all. Is it a bug in vtk 8.x?

Thanks

Have you tried calling components_alongX->DeleteSpecifiedRegion() to delete one or the other regions you no longer wish to extract?

hello, thank you for answering. Yes i also tried this but the same result. the only way to make it work is to apply the connected components again to the same polydata and choose the second label.

Hmm, I don’t see a problem in either your code or in the code of the vtkPolyDataConnectvityFilter itself.

When i have time i will debug this vtk filter. There must be something wrong in it. I let you know. by now, I will make this trick that it works.