Extracting regions as PolyData

Hi,

This is the piece of code I am using to obtain the extracted region’s polydata.

Code snippet:
vtkPolyDataConnectivityFilter* connectivityFilter = vtkPolyDataConnectivityFilter::New() ;
//The reader’s output will the input polydata attached
connectivityFilter->SetInputData(this->reader->GetOutput());
connectivityFilter->SetExtractionModeToAllRegions();
connectivityFilter->ScalarConnectivityOff();
connectivityFilter->Update();
int regCount = connectivityFilter->GetNumberOfExtractedRegions();
//Iterating all the extracted regions to get the region’s polydata
for (int i = 0; i < regCount; i++)
{
connectivityFilter->SetInputData(this->reader->GetOutput());
connectivityFilter->SetExtractionModeToSpecifiedRegions();
connectivityFilter->InitializeSpecifiedRegionList();
connectivityFilter->AddSpecifiedRegion(i);
connectivityFilter->ScalarConnectivityOff();
connectivityFilter->Update();
}

InputData:


PS: I am not able to attach .vtk format of InputData. So, just attached an image.

From the above image, I need to obtain the polydata of all the extracted regions differentiated by colors(29 regions).

Thanks,
Srihitha.