Skip to content

Commit

Permalink
Fix issue with vtk warnings when segmentation data with gaps in the l…
Browse files Browse the repository at this point in the history
…abel range are loaded
  • Loading branch information
davidborland committed Dec 11, 2019
1 parent 46bcd28 commit 789f703
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Region.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Region::Region(unsigned short regionLabel, double regionColor[3], vtkImageData*
// XXX: USE GENERATE REGION EXTENTS FROM vktImageConnectivityFilter AND PASS THIS IN
// ALSO REGION SIZE FROM FILTER

int numVoxels = 0;
for (int i = 0; i < numPoints; i++) {
if (scalars[i] == label) {
double* point = data->GetPoint(i);
Expand All @@ -56,9 +57,18 @@ Region::Region(unsigned short regionLabel, double regionColor[3], vtkImageData*
if (point[1] > extent[3]) extent[3] = point[1];
if (point[2] < extent[4]) extent[4] = point[2];
if (point[2] > extent[5]) extent[5] = point[2];

numVoxels++;
}
}

// Fix extent if no voxels with this label
if (numVoxels == 0) {
extent[0] = extent[1] = dataExtent[0];
extent[2] = extent[3] = dataExtent[2];
extent[4] = extent[5] = dataExtent[4];
}

voi = vtkSmartPointer<vtkExtractVOI>::New();
voi->SetInputDataObject(data);

Expand Down
9 changes: 8 additions & 1 deletion VisualizationContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,14 @@ void VisualizationContainer::ExtractRegions() {
regions->RemoveAll();

for (int label = 1; label <= maxLabel; label++) {
regions->Add(new Region(label, labelColors->GetTableValue(label), labels));
Region* region = new Region(label, labelColors->GetTableValue(label), labels);

if (region->GetNumVoxels() > 0) {
regions->Add(new Region(label, labelColors->GetTableValue(label), labels));
}
else {
delete region;
}
}
}

Expand Down

0 comments on commit 789f703

Please sign in to comment.