Skip to content

Commit

Permalink
Support loading of multi-page TIFF volume files
Browse files Browse the repository at this point in the history
  • Loading branch information
davidborland committed Jan 6, 2020
1 parent 4a28332 commit c23ceec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
4 changes: 2 additions & 2 deletions MainWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void MainWindow::on_actionOpen_Image_File_triggered() {
QString fileName = QFileDialog::getOpenFileName(this,
"Open Volume",
GetDefaultDirectory(defaultImageDirectoryKey),
"All files (*.*);;NIfTI (*.nii);;VTK XML ImageData (*.vti)");
"All files (*.*);;NIfTI (*.nii);;TIFF (*.tif *.tiff);;VTK XML ImageData (*.vti)");

// Check for file name
if (fileName == "") {
Expand Down Expand Up @@ -173,7 +173,7 @@ void MainWindow::on_actionOpen_Segmentation_File_triggered() {
QString fileName = QFileDialog::getOpenFileName(this,
"Open Segmentation Data",
GetDefaultDirectory(defaultSegmentationDirectoryKey),
"All files (*.*);;NIfTI (*.nii);;VTK XML ImageData (*.vti)");
"All files (*.*);;NIfTI (*.nii);;TIFF (*.tif *.tiff);;VTK XML ImageData (*.vti)");

// Check for file name
if (fileName == "") {
Expand Down
45 changes: 37 additions & 8 deletions VisualizationContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,26 @@ VisualizationContainer::FileErrorCode VisualizationContainer::OpenImageFile(cons
std::string extension = fileName.substr(fileName.find_last_of(".") + 1);

// Load the data
if (extension == "vti") {
vtkSmartPointer<vtkXMLImageDataReader> reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
if (extension == "nii") {
vtkSmartPointer<vtkNIFTIImageReader> reader = vtkSmartPointer<vtkNIFTIImageReader>::New();
reader->SetFileName(fileName.c_str());
reader->Update();

SetImageData(reader->GetOutput());

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

SetImageData(reader->GetOutput());

return Success;
}
else if (extension == "vti") {
vtkSmartPointer<vtkXMLImageDataReader> reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
reader->SetFileName(fileName.c_str());
reader->Update();

Expand Down Expand Up @@ -187,8 +196,8 @@ VisualizationContainer::FileErrorCode VisualizationContainer::OpenSegmentationFi
std::string extension = fileName.substr(fileName.find_last_of(".") + 1);

// Load the data
if (extension == "vti") {
vtkSmartPointer<vtkXMLImageDataReader> reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
if (extension == "nii") {
vtkSmartPointer<vtkNIFTIImageReader> reader = vtkSmartPointer<vtkNIFTIImageReader>::New();
reader->SetFileName(fileName.c_str());

vtkSmartPointer<vtkImageCast> cast = vtkSmartPointer<vtkImageCast>::New();
Expand All @@ -207,8 +216,28 @@ VisualizationContainer::FileErrorCode VisualizationContainer::OpenSegmentationFi
return VolumeMismatch;
}
}
else if (extension == "nii") {
vtkSmartPointer<vtkNIFTIImageReader> reader = vtkSmartPointer<vtkNIFTIImageReader>::New();
else if (extension == "tif" || extension == "tiff") {
vtkSmartPointer<vtkTIFFReader> reader = vtkSmartPointer<vtkTIFFReader>::New();
reader->SetFileName(fileName.c_str());

vtkSmartPointer<vtkImageCast> cast = vtkSmartPointer<vtkImageCast>::New();
cast->SetOutputScalarTypeToUnsignedShort();
cast->SetInputConnection(reader->GetOutputPort());
cast->Update();

if (SetLabelData(cast->GetOutput())) {
LoadRegionMetadata(fileName + ".json");

qtWindow->updateRegions(regions);

return Success;
}
else {
return VolumeMismatch;
}
}
else if (extension == "vti") {
vtkSmartPointer<vtkXMLImageDataReader> reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
reader->SetFileName(fileName.c_str());

vtkSmartPointer<vtkImageCast> cast = vtkSmartPointer<vtkImageCast>::New();
Expand Down

0 comments on commit c23ceec

Please sign in to comment.