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

**URL:** https://discourse.vtk.org/t/polydata-connectivity-filter-with-mode-to-specified-regions-only-shows-the-first-region-selected/4458
**Category:** Support
**Created:** [October 21, 2020, 8:49am UTC](https://discourse.vtk.org/t/polydata-connectivity-filter-with-mode-to-specified-regions-only-shows-the-first-region-selected/4458 "2020-10-21T08:49:40Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [October 21, 2020, 8:49am UTC](https://discourse.vtk.org/t/polydata-connectivity-filter-with-mode-to-specified-regions-only-shows-the-first-region-selected/4458/1 "2020-10-21T08:49:40Z")

</div>

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 !!

---

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [October 21, 2020, 9:42am UTC](https://discourse.vtk.org/t/polydata-connectivity-filter-with-mode-to-specified-regions-only-shows-the-first-region-selected/4458/2 "2020-10-21T09:42:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [October 21, 2020, 12:42pm UTC](https://discourse.vtk.org/t/polydata-connectivity-filter-with-mode-to-specified-regions-only-shows-the-first-region-selected/4458/3 "2020-10-21T12:42:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [October 21, 2020, 12:50pm UTC](https://discourse.vtk.org/t/polydata-connectivity-filter-with-mode-to-specified-regions-only-shows-the-first-region-selected/4458/4 "2020-10-21T12:50:36Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [October 21, 2020, 1:00pm UTC](https://discourse.vtk.org/t/polydata-connectivity-filter-with-mode-to-specified-regions-only-shows-the-first-region-selected/4458/5 "2020-10-21T13:00:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [November 3, 2020, 4:42pm UTC](https://discourse.vtk.org/t/polydata-connectivity-filter-with-mode-to-specified-regions-only-shows-the-first-region-selected/4458/6 "2020-11-03T16:42:49Z")

</div>

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.
