Commit be24b724 authored by Cory Quammen's avatar Cory Quammen
Browse files

Add support for reordering RegionIds by RegionIdAssignmentMode

Also, fixed bug where ghost cells were being counted in cell count for
different regions.
parent 97ba574f
......@@ -482,11 +482,13 @@ int vtkPConnectivityFilter::RequestData(
int saveScalarConnectivity = this->ScalarConnectivity;
int saveExtractionMode = this->ExtractionMode;
int saveColorRegions = this->ColorRegions;
int saveRegionIdAssignmentMode = this->RegionIdAssignmentMode;
// Overwrite custom member variables temporarily.
this->ScalarConnectivity = 0;
this->ExtractionMode = VTK_EXTRACT_ALL_REGIONS;
this->ColorRegions = 1;
this->RegionIdAssignmentMode = UNSPECIFIED;
// Invoke the connectivity algorithm in the superclass.
success = this->Superclass::RequestData(request, inputVector, outputVector);
......@@ -494,6 +496,7 @@ int vtkPConnectivityFilter::RequestData(
this->ScalarConnectivity = saveScalarConnectivity;
this->ExtractionMode = saveExtractionMode;
this->ColorRegions = saveColorRegions;
this->RegionIdAssignmentMode = saveRegionIdAssignmentMode;
}
else
{
......@@ -794,9 +797,15 @@ int vtkPConnectivityFilter::RequestData(
std::vector< vtkIdType > localRegionSizes(numContiguousLabels, 0);
if (cellRegionIds)
{
// Iterate over cells and count how many are in different regions.
// Iterate over cells and count how many are in different regions. Count only non-ghost cells.
vtkUnsignedCharArray* cellGhostArray = output->GetCellGhostArray();
for (vtkIdType i = 0; i < cellRegionIds->GetNumberOfValues(); ++i)
{
if (cellGhostArray && cellGhostArray->GetTypedComponent(i, 0) &
vtkDataSetAttributes::DUPLICATECELL)
{
continue;
}
localRegionSizes[cellRegionIds->GetValue(i)]++;
}
}
......@@ -815,15 +824,26 @@ int vtkPConnectivityFilter::RequestData(
this->RegionSizes->SetTypedTuple(i, &globalRegionSizes[i]);
}
// Potentially reorder RegionIds in the output arrays.
this->OrderRegionIds(pointRegionIds, cellRegionIds);
if (this->ExtractionMode == VTK_EXTRACT_LARGEST_REGION ||
this->ExtractionMode == VTK_EXTRACT_CLOSEST_POINT_REGION)
{
double threshold = 0.0;
if (this->ExtractionMode == VTK_EXTRACT_LARGEST_REGION)
{
vtkIdType largestRegionId =
std::distance(globalRegionSizes.begin(),
std::max_element(globalRegionSizes.begin(), globalRegionSizes.end()));
vtkIdType largestRegionCount = 0;
vtkIdType largestRegionId = 0;
for (vtkIdType i = 0; i < this->RegionSizes->GetNumberOfTuples(); ++i)
{
vtkIdType candidateCount = this->RegionSizes->GetValue(i);
if (candidateCount > largestRegionCount)
{
largestRegionCount = candidateCount;
largestRegionId = i;
}
}
threshold = largestRegionId;
}
else if (this->ExtractionMode == VTK_EXTRACT_CLOSEST_POINT_REGION)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment