Skip to content

Commit

Permalink
Check that segmentation data matches image data before loading
Browse files Browse the repository at this point in the history
  • Loading branch information
davidborland committed Dec 10, 2019
1 parent 96e2672 commit e3baf31
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 23 deletions.
76 changes: 53 additions & 23 deletions VisualizationContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -189,27 +189,29 @@ bool VisualizationContainer::OpenSegmentationFile(const std::string& fileName) {
reader->SetFileName(fileName.c_str());
reader->Update();

labels = reader->GetOutput();
if (SetLabelData(reader->GetOutput())) {
LoadRegionMetadata(fileName + ".json");

qtWindow->UpdateRegionTable(regions);

return true;
}
}
else if (extension == "nii") {
vtkSmartPointer<vtkNIFTIImageReader> reader = vtkSmartPointer<vtkNIFTIImageReader>::New();
reader->SetFileName(fileName.c_str());
reader->Update();

labels = reader->GetOutput();
}
else {
return false;
}
if (SetLabelData(reader->GetOutput())) {
LoadRegionMetadata(fileName + ".json");

UpdateLabels();
LoadRegionMetadata(fileName + ".json");
qtWindow->UpdateRegionTable(regions);

qtWindow->UpdateRegionTable(regions);

Render();
return true;
}
}

return true;
return false;
}

bool VisualizationContainer::OpenSegmentationStack(const std::vector<std::string>& fileNames) {
Expand All @@ -232,20 +234,16 @@ bool VisualizationContainer::OpenSegmentationStack(const std::vector<std::string
reader->SetFileNames(names);
reader->Update();

labels = reader->GetOutput();
}
else {
return false;
}
if (SetLabelData(reader->GetOutput())) {
LoadRegionMetadata(fileNames[0] + ".json");

UpdateLabels();
LoadRegionMetadata(fileNames[0] + ".json");

qtWindow->UpdateRegionTable(regions);
qtWindow->UpdateRegionTable(regions);

Render();
return true;
}
}

return true;
return false;
}

bool VisualizationContainer::SaveSegmentationData(const std::string& fileName) {
Expand Down Expand Up @@ -630,6 +628,38 @@ void VisualizationContainer::SetImageData(vtkImageData* imageData) {
sliceView->SetImageData(data);
}

bool VisualizationContainer::SetLabelData(vtkImageData* labelData) {
// Check that volumes match
int* dataDims = data->GetDimensions();
int* labelDims = data->GetDimensions();

for (int i = 0; i < 3; i++) {
if (dataDims[i] != labelDims[i]) {
std::cout << dataDims[i] << " != " << labelDims[i] << std::endl;
return false;
}
}

// Check that bounds match
double* dataBounds = data->GetBounds();
double* labelBounds = labelData->GetBounds();

double epsilon = 1e-6;

for (int i = 0; i < 6; i++) {
if (std::abs(dataBounds[i] - labelBounds[i]) > epsilon) {
std::cout << dataBounds[i] << " != " << labelBounds[i] << std::endl;
return false;
}
}

labels = labelData;

UpdateLabels();

return true;
}

void VisualizationContainer::UpdateLabels() {
UpdateColors();
ExtractRegions();
Expand Down
1 change: 1 addition & 0 deletions VisualizationContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class VisualizationContainer {
enum InteractionMode interactionMode;

void SetImageData(vtkImageData* imageData);
bool SetLabelData(vtkImageData* labelData);

void UpdateLabels();
void UpdateColors();
Expand Down

0 comments on commit e3baf31

Please sign in to comment.