From c23ceeca945c8493c4fbfaf4cca830a560b13fe6 Mon Sep 17 00:00:00 2001 From: David Borland Date: Mon, 6 Jan 2020 11:13:24 -0500 Subject: [PATCH] Support loading of multi-page TIFF volume files --- MainWindow.cxx | 4 ++-- VisualizationContainer.cxx | 45 +++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/MainWindow.cxx b/MainWindow.cxx index e808170..6c4e257 100644 --- a/MainWindow.cxx +++ b/MainWindow.cxx @@ -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 == "") { @@ -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 == "") { diff --git a/VisualizationContainer.cxx b/VisualizationContainer.cxx index 4bf5700..bf41f77 100644 --- a/VisualizationContainer.cxx +++ b/VisualizationContainer.cxx @@ -132,8 +132,8 @@ VisualizationContainer::FileErrorCode VisualizationContainer::OpenImageFile(cons std::string extension = fileName.substr(fileName.find_last_of(".") + 1); // Load the data - if (extension == "vti") { - vtkSmartPointer reader = vtkSmartPointer::New(); + if (extension == "nii") { + vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName(fileName.c_str()); reader->Update(); @@ -141,8 +141,17 @@ VisualizationContainer::FileErrorCode VisualizationContainer::OpenImageFile(cons return Success; } - else if (extension == "nii") { - vtkSmartPointer reader = vtkSmartPointer::New(); + else if (extension == "tif" || extension == "tiff") { + vtkSmartPointer reader = vtkSmartPointer::New(); + reader->SetFileName(fileName.c_str()); + reader->Update(); + + SetImageData(reader->GetOutput()); + + return Success; + } + else if (extension == "vti") { + vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName(fileName.c_str()); reader->Update(); @@ -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 reader = vtkSmartPointer::New(); + if (extension == "nii") { + vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName(fileName.c_str()); vtkSmartPointer cast = vtkSmartPointer::New(); @@ -207,8 +216,28 @@ VisualizationContainer::FileErrorCode VisualizationContainer::OpenSegmentationFi return VolumeMismatch; } } - else if (extension == "nii") { - vtkSmartPointer reader = vtkSmartPointer::New(); + else if (extension == "tif" || extension == "tiff") { + vtkSmartPointer reader = vtkSmartPointer::New(); + reader->SetFileName(fileName.c_str()); + + vtkSmartPointer cast = vtkSmartPointer::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 reader = vtkSmartPointer::New(); reader->SetFileName(fileName.c_str()); vtkSmartPointer cast = vtkSmartPointer::New();