diff --git a/Examples/Plugins/org.mitk.example.gui.customviewer.views/src/internal/DicomView.cpp b/Examples/Plugins/org.mitk.example.gui.customviewer.views/src/internal/DicomView.cpp index d0255aaf8f..019f22cb57 100644 --- a/Examples/Plugins/org.mitk.example.gui.customviewer.views/src/internal/DicomView.cpp +++ b/Examples/Plugins/org.mitk.example.gui.customviewer.views/src/internal/DicomView.cpp @@ -1,107 +1,107 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "DicomView.h" #include "org_mitk_example_gui_customviewer_views_Activator.h" -#include "mitkDicomSeriesReader.h" +#include "mitkIOUtil.h" #include "mitkIDataStorageService.h" #include "mitkImage.h" #include #include #include #include "QDockWidget" const std::string DicomView::VIEW_ID = "org.mitk.customviewer.views.dicomview"; DicomView::DicomView() : m_Parent(nullptr) { } DicomView::~DicomView() { } // //! [DicomViewCreatePartControl] void DicomView::CreateQtPartControl(QWidget *parent) { // create GUI widgets m_Parent = parent; m_Controls.setupUi(parent); // remove unused widgets QPushButton *downloadButton = parent->findChild("downloadButton"); downloadButton->setVisible(false); connect(m_Controls.importButton, SIGNAL(clicked()), m_Controls.widget, SLOT(OnFolderCDImport())); connect(m_Controls.widget, SIGNAL(SignalDicomToDataManager(const QHash &)), this, SLOT(AddDataNodeFromDICOM(const QHash &))); m_Parent->setEnabled(true); } // //! [DicomViewCreatePartControl] // //! [DicomViewCreateAddDataNodeInformation] void DicomView::AddDataNodeFromDICOM(QHash eventProperties) { QStringList listOfFilesForSeries; - mitk::DicomSeriesReader::StringContainer seriesToLoad; + std::vector seriesToLoad; listOfFilesForSeries = eventProperties["FilesForSeries"].toStringList(); if (!listOfFilesForSeries.isEmpty()) { QStringListIterator it(listOfFilesForSeries); while (it.hasNext()) { seriesToLoad.push_back(it.next().toStdString()); } - mitk::DataNode::Pointer node = mitk::DicomSeriesReader::LoadDicomSeries(seriesToLoad); - if (node.IsNull()) + auto results = mitk::IOUtil::Load(seriesToLoad, *(this->GetDataStorage().GetPointer())); + + if (results->empty()) { MITK_ERROR << "Error loading Dicom series"; } // //! [DicomViewCreateAddDataNodeLoadSeries] else { // //! [DicomViewCreateAddDataNode] mitk::DataStorage::Pointer ds = this->GetDataStorage(); - ds->Add(node); // //! [DicomViewCreateAddDataNode] mitk::RenderingManager::GetInstance()->SetDataStorage(ds); mitk::TimeGeometry::Pointer geometry = ds->ComputeBoundingGeometry3D(ds->GetAll()); mitk::RenderingManager::GetInstance()->InitializeViews(geometry); // //! [DicomViewCreateAddDataNodeActivatePersp] berry::IWorkbenchWindow::Pointer window = this->GetSite()->GetWorkbenchWindow(); QString perspectiveId = "org.mitk.example.viewerperspective"; window->GetWorkbench()->ShowPerspective(perspectiveId, berry::IWorkbenchWindow::Pointer(window)); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); // //! [DicomViewCreateAddDataNodeActivatePersp] } } } void DicomView::SetFocus() { } diff --git a/Modules/CEST/autoload/IO/mitkCESTDICOMReaderService.h b/Modules/CEST/autoload/IO/mitkCESTDICOMReaderService.h index e5bc97baf4..76363b8bfb 100644 --- a/Modules/CEST/autoload/IO/mitkCESTDICOMReaderService.h +++ b/Modules/CEST/autoload/IO/mitkCESTDICOMReaderService.h @@ -1,50 +1,50 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKCESTDICOMReaderService_H #define MITKCESTDICOMReaderService_H #include namespace mitk { /** Service wrapper that auto selects (using the mitk::DICOMFileReaderSelector) the best DICOMFileReader from the DICOMReader module and loads additional meta data for CEST data. */ class CESTDICOMReaderService : public BaseDICOMReaderService { public: CESTDICOMReaderService(); CESTDICOMReaderService(const std::string& description); /** Uses the BaseDICOMReaderService Read function and add extra steps for CEST meta data */ using AbstractFileReader::Read; std::vector > Read() override; protected: /** Returns the reader instance that should be used. The decision may be based * one the passed relevant file list.*/ mitk::DICOMFileReader::Pointer GetReader(const mitk::StringList& relevantFiles) const override; private: CESTDICOMReaderService* Clone() const override; }; } -#endif // MITKDICOMSERIESREADERSERVICE_H +#endif // MITKCESTDICOMREADERSERVICE_H diff --git a/Modules/Classification/CLMiniApps/CLDicom2Nrrd.cpp b/Modules/Classification/CLMiniApps/CLDicom2Nrrd.cpp index 490fc4df87..b97da7450c 100644 --- a/Modules/Classification/CLMiniApps/CLDicom2Nrrd.cpp +++ b/Modules/Classification/CLMiniApps/CLDicom2Nrrd.cpp @@ -1,88 +1,87 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include "mitkDicomSeriesReader.h" #include "mitkProperties.h" #include "mitkCommandLineParser.h" #include "mitkIOUtil.h" #include "mitkPreferenceListReaderOptionsFunctor.h" int main(int argc, char* argv[]) { mitkCommandLineParser parser; parser.setTitle("Dicom Loader"); parser.setCategory("Preprocessing Tools"); parser.setDescription(""); parser.setContributor("MBI"); parser.setArgumentPrefix("--","-"); // Add command line argument names parser.addArgument("help", "h",mitkCommandLineParser::Bool, "Help:", "Show this help text"); parser.addArgument("input", "i", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder",us::Any(),false); parser.addArgument("output", "o", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any(), false); parser.addArgument("reader", "r", mitkCommandLineParser::String, "Reader Name", "Reader Name", us::Any()); std::map parsedArgs = parser.parseArguments(argc, argv); if (parsedArgs.size()==0) return EXIT_FAILURE; // Show a help message if ( parsedArgs.count("help") || parsedArgs.count("h")) { std::cout << parser.helpText(); return EXIT_SUCCESS; } std::string inputFolder = us::any_cast(parsedArgs["input"]); std::string outFileName = us::any_cast(parsedArgs["output"]); //mitk::PreferenceListReaderOptionsFunctor::ListType preference = { "MITK DICOM Reader v2 (classic config)" }; mitk::PreferenceListReaderOptionsFunctor::ListType preference = {}; if (parsedArgs.count("reader")) { preference.push_back(us::any_cast(parsedArgs["reader"])); } mitk::PreferenceListReaderOptionsFunctor::ListType emptyList = {}; mitk::IOUtil::LoadInfo info(inputFolder); mitk::PreferenceListReaderOptionsFunctor functor = mitk::PreferenceListReaderOptionsFunctor(preference, emptyList); functor(info); std::string extension = itksys::SystemTools::GetFilenameExtension(outFileName); std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(outFileName); std::string path = itksys::SystemTools::GetFilenamePath(outFileName); auto nodes = mitk::IOUtil::Load(inputFolder, &functor); unsigned count = 0; for (auto node : nodes) { std::string writeName = path + "/" + filename + extension; if (count > 0) { writeName = path + "/" + filename + "_" + std::to_string(count) + extension; } mitk::IOUtil::Save(node, writeName); ++count; } return EXIT_SUCCESS; } diff --git a/Modules/Classification/CLMiniApps/CLLungSegmentation.cpp b/Modules/Classification/CLMiniApps/CLLungSegmentation.cpp index 3350c8bd4d..46b4e58737 100644 --- a/Modules/Classification/CLMiniApps/CLLungSegmentation.cpp +++ b/Modules/Classification/CLMiniApps/CLLungSegmentation.cpp @@ -1,177 +1,176 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include "mitkDicomSeriesReader.h" #include "mitkProperties.h" #include "mitkCommandLineParser.h" #include "mitkIOUtil.h" #include #include "mitkLabelSetImage.h" #include "mitkImageCast.h" #include "mitkImageTimeSelector.h" #include "mitkITKImageImport.h" #include "mitkImageAccessByItk.h" #include #include template void StartRegionGrowing(itk::Image* itkImage, mitk::Image::Pointer &result) { typedef itk::Image InputImageType; typedef typename InputImageType::IndexType IndexType; typedef itk::ConnectedThresholdImageFilter RegionGrowingFilterType; typename RegionGrowingFilterType::Pointer regionGrower = RegionGrowingFilterType::New(); // convert world coordinates to image indices IndexType startIndex; IndexType seedIndex; IndexType bestSeedIndex; startIndex[0] = itkImage->GetLargestPossibleRegion().GetSize()[0]/2; startIndex[1] = itkImage->GetLargestPossibleRegion().GetSize()[1]/2; startIndex[2] = itkImage->GetLargestPossibleRegion().GetSize()[2]/2; auto region = itkImage->GetLargestPossibleRegion(); auto spacing = itkImage->GetSpacing(); spacing[0] = itkImage->GetSpacing()[0]; spacing[1] = itkImage->GetSpacing()[1]; spacing[2] = itkImage->GetSpacing()[2]; int minimumDistance = 50 * 50 * (spacing[0] + spacing[1] + spacing[2]); for (int x = -50; x < 50; ++x) { for (int y = -50; y < 50; ++y) { for (int z = -20; z < 20; ++z) { seedIndex[0] = startIndex[0] + x; seedIndex[1] = startIndex[1] + y; seedIndex[2] = startIndex[2] + z; if (region.IsInside(seedIndex)) { if (itkImage->GetPixel(seedIndex) > 0) { int newDistance = x*x*spacing[0] + y*y*spacing[1] + z*z*spacing[2]; if (newDistance < minimumDistance) { bestSeedIndex = seedIndex; minimumDistance = newDistance; } } } } } } seedIndex = bestSeedIndex; MITK_INFO << "Seedpoint: " << seedIndex; //perform region growing in desired segmented region regionGrower->SetInput(itkImage); regionGrower->AddSeed(seedIndex); regionGrower->SetLower(1); regionGrower->SetUpper(255); try { regionGrower->Update(); } catch (const itk::ExceptionObject&) { return; // can't work } catch (...) { return; } //Store result and preview mitk::CastToMitkImage(regionGrower->GetOutput(), result); } int main(int argc, char* argv[]) { mitkCommandLineParser parser; parser.setTitle("Dicom Loader"); parser.setCategory("Preprocessing Tools"); parser.setDescription(""); parser.setContributor("MBI"); parser.setArgumentPrefix("--","-"); // Add command line argument names parser.addArgument("help", "h",mitkCommandLineParser::Bool, "Help:", "Show this help text"); parser.addArgument("input", "i", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any(), false); parser.addArgument("output", "o", mitkCommandLineParser::OutputFile, "Output file:", "Output file",us::Any(),false); std::map parsedArgs = parser.parseArguments(argc, argv); if (parsedArgs.size()==0) return EXIT_FAILURE; // Show a help message if ( parsedArgs.count("help") || parsedArgs.count("h")) { std::cout << parser.helpText(); return EXIT_SUCCESS; } std::string inputFile = us::any_cast(parsedArgs["input"]); std::string outFileName = us::any_cast(parsedArgs["output"]); MITK_INFO << "Start Image Loading"; mitk::Image::Pointer image = mitk::IOUtil::LoadImage(inputFile); MITK_INFO << "Loaded Image"; mitk::OtsuSegmentationFilter::Pointer otsuFilter = mitk::OtsuSegmentationFilter::New(); otsuFilter->SetNumberOfThresholds(2); otsuFilter->SetValleyEmphasis(false); otsuFilter->SetNumberOfBins(128); otsuFilter->SetInput(image); try { otsuFilter->Update(); } catch (...) { mitkThrow() << "itkOtsuFilter error (image dimension must be in {2, 3} and image must not be RGB)"; } MITK_INFO << "Calculated Otsu"; mitk::LabelSetImage::Pointer resultImage = mitk::LabelSetImage::New(); resultImage->InitializeByLabeledImage(otsuFilter->GetOutput()); mitk::Image::Pointer rawMask = resultImage->CreateLabelMask(1); mitk::Image::Pointer pickedMask; AccessByItk_1(rawMask, StartRegionGrowing, pickedMask); mitk::MorphologicalOperations::FillHoles(pickedMask); mitk::MorphologicalOperations::Closing(pickedMask, 5, mitk::MorphologicalOperations::StructuralElementType::Ball); mitk::MorphologicalOperations::FillHoles(pickedMask); mitk::IOUtil::Save(pickedMask, outFileName); return EXIT_SUCCESS; } diff --git a/Modules/Classification/CLMiniApps/CLMatchPointReg.cpp b/Modules/Classification/CLMiniApps/CLMatchPointReg.cpp index 8db9bae5fb..58ff53861c 100644 --- a/Modules/Classification/CLMiniApps/CLMatchPointReg.cpp +++ b/Modules/Classification/CLMiniApps/CLMatchPointReg.cpp @@ -1,169 +1,168 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include "mitkDicomSeriesReader.h" #include "mitkProperties.h" #include "mitkCommandLineParser.h" #include "mitkIOUtil.h" #include "mitkPreferenceListReaderOptionsFunctor.h" // MatchPoint #include #include #include #include #include #include #include #include #include #include #include #include // Qt #include #include #include //#include #include #include #include #include int main(int argc, char* argv[]) { mitkCommandLineParser parser; parser.setTitle("Dicom Loader"); parser.setCategory("Preprocessing Tools"); parser.setDescription(""); parser.setContributor("MBI"); parser.setArgumentPrefix("--","-"); // Add command line argument names parser.addArgument("help", "h",mitkCommandLineParser::Bool, "Help:", "Show this help text"); parser.addArgument("moving", "m", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any(), false); parser.addArgument("fixed", "f", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any(), false); parser.addArgument("output", "o", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any(), false); parser.addArgument("reader", "r", mitkCommandLineParser::Int, "Reader ID", "Reader Name", us::Any(), false); parser.addArgument("interpolation", "interp", mitkCommandLineParser::Int, "Reader ID", "Reader Name", us::Any(), false); std::map parsedArgs = parser.parseArguments(argc, argv); QFileInfo fi(argv[0]); map::deployment::DLLDirectoryBrowser::Pointer browser = map::deployment::DLLDirectoryBrowser::New(); browser->addDLLSearchLocation(QDir::homePath().toStdString()); browser->addDLLSearchLocation(QDir::currentPath().toStdString()); browser->addDLLSearchLocation(fi.canonicalPath().toStdString()); browser->update(); auto dllList = browser->getLibraryInfos(); int id = 0; std::cout << std::endl << " --- Algorithm List --- " << std::endl; for (auto info : dllList) { std::cout << "Algorithm ID " << id << ": " << info->getAlgorithmUID().getName() << std::endl; ++id; } std::cout << std::endl << " --- Interpolation List --- " << std::endl; std::cout << "Interpolation ID 0: Linear Interpolation " << std::endl; std::cout << "Interpolation ID 1: Nearest Neighbour" << std::endl; std::cout << "Interpolation ID 2: BSpline 3D" << std::endl << std::endl; mitk::ImageMappingInterpolator::Type interpolationMode = mitk::ImageMappingInterpolator::Linear; if (parsedArgs.size()==0) return EXIT_FAILURE; // Show a help message if ( parsedArgs.count("help") || parsedArgs.count("h")) { std::cout << parser.helpText(); return EXIT_SUCCESS; } std::string movingFile = us::any_cast(parsedArgs["moving"]); std::string fixedFile = us::any_cast(parsedArgs["fixed"]); int selectedAlgorithm = us::any_cast(parsedArgs["reader"]); std::string outputPath = us::any_cast(parsedArgs["output"]); if (parsedArgs.count("interpolation")) { switch (us::any_cast(parsedArgs["interpolation"])) { case 0: interpolationMode = mitk::ImageMappingInterpolator::Linear; break; case 1: interpolationMode = mitk::ImageMappingInterpolator::NearestNeighbor; break; case 2: interpolationMode = mitk::ImageMappingInterpolator::BSpline_3; break; default: interpolationMode = mitk::ImageMappingInterpolator::Linear; } } mitk::Image::Pointer movingImage = dynamic_cast(mitk::IOUtil::Load(movingFile)[0].GetPointer()); mitk::Image::Pointer fixedImage = dynamic_cast(mitk::IOUtil::Load(fixedFile)[0].GetPointer()); auto dllInfo = dllList[selectedAlgorithm]; if (!dllInfo) { MITK_ERROR << "No valid algorithm is selected. Cannot load algorithm. ABORTING."; return -1; } ::map::deployment::DLLHandle::Pointer tempDLLHandle = ::map::deployment::openDeploymentDLL( dllInfo->getLibraryFilePath()); ::map::algorithm::RegistrationAlgorithmBase::Pointer tempAlgorithm = ::map::deployment::getRegistrationAlgorithm(tempDLLHandle); MITK_INFO << "Well...."; if (tempAlgorithm.IsNull()) { MITK_ERROR << "Error. Cannot load selected algorithm."; return -2; } mitk::MITKAlgorithmHelper helper(tempAlgorithm); helper.SetData(movingImage, fixedImage); auto registration = helper.GetRegistration(); MITK_INFO << "Well...."; mitk::Image::Pointer spResultData= mitk::ImageMappingHelper::map(movingImage, registration, false, // Use all Pixels 0.0, // Padding Value fixedImage->GetGeometry()->Clone().GetPointer(), // Ref. Geometry false, //!(this->m_allowUnregPixels), 0, // Error Value interpolationMode // Interpolator Type ); MITK_INFO << "Well...."; mitk::IOUtil::Save(spResultData, outputPath); return EXIT_SUCCESS; } diff --git a/Modules/Classification/CLMiniApps/XRaxSimulationFromCT.cpp b/Modules/Classification/CLMiniApps/XRaxSimulationFromCT.cpp index 25e7386938..7286cb1881 100644 --- a/Modules/Classification/CLMiniApps/XRaxSimulationFromCT.cpp +++ b/Modules/Classification/CLMiniApps/XRaxSimulationFromCT.cpp @@ -1,227 +1,226 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include "mitkDicomSeriesReader.h" #include "mitkProperties.h" #include "mitkCommandLineParser.h" #include "mitkIOUtil.h" #include "itkImageRegionIterator.h" // MITK #include #include #include struct Params { bool invert; float zeroValue; }; template void CreateXRay(itk::Image* itkImage, mitk::Image::Pointer mask1, std::string output, Params param) { typedef itk::Image ImageType; typedef itk::Image MaskType; typedef itk::Image NewImageType; typename MaskType::Pointer itkMask = MaskType::New(); mitk::CastToItkImage(mask1, itkMask); NewImageType::SpacingType newSpacing; auto spacing = itkImage->GetSpacing(); spacing[0] = itkImage->GetSpacing()[0]; spacing[1] = itkImage->GetSpacing()[1]; spacing[2] = itkImage->GetSpacing()[2]; spacing = itkImage->GetSpacing(); NewImageType::RegionType region1,region2,region3,region1m,region2m,region3m; NewImageType::IndexType start; start[0] = 0; start[1] = 0; NewImageType::SizeType size1, size2, size3; size1[0] = mask1->GetDimensions()[0]; size2[0] = mask1->GetDimensions()[0]; size3[0] = mask1->GetDimensions()[1]; size1[1] = mask1->GetDimensions()[1]; size2[1] = mask1->GetDimensions()[2]; size3[1] = mask1->GetDimensions()[2]; region1.SetSize(size1); region1m.SetSize(size1); region2.SetSize(size2); region2m.SetSize(size2); region3.SetSize(size3); region3m.SetSize(size3); region1.SetIndex(start); region1m.SetIndex(start); region2.SetIndex(start); region2m.SetIndex(start); region3.SetIndex(start); region3m.SetIndex(start); NewImageType::Pointer image1 = NewImageType::New(); image1->SetRegions(region1); image1->Allocate(); image1->FillBuffer(0); newSpacing[0] = spacing[0]; newSpacing[1] = spacing[1]; image1->SetSpacing(newSpacing); NewImageType::Pointer image2 = NewImageType::New(); image2->SetRegions(region2); image2->Allocate(); image2->FillBuffer(0); newSpacing[0] = spacing[0]; newSpacing[1] = spacing[2]; image2->SetSpacing(newSpacing); NewImageType::Pointer image3 = NewImageType::New(); image3->SetRegions(region3); image3->Allocate(); image3->FillBuffer(0); newSpacing[0] = spacing[1]; newSpacing[1] = spacing[2]; image3->SetSpacing(newSpacing); NewImageType::Pointer image1m = NewImageType::New(); image1m->SetRegions(region1m); image1m->Allocate(); image1m->FillBuffer(0); newSpacing[0] = spacing[0]; newSpacing[1] = spacing[1]; image1m->SetSpacing(newSpacing); NewImageType::Pointer image2m = NewImageType::New(); image2m->SetRegions(region2m); image2m->Allocate(); image2m->FillBuffer(0); newSpacing[0] = spacing[0]; newSpacing[1] = spacing[2]; image2m->SetSpacing(newSpacing); NewImageType::Pointer image3m = NewImageType::New(); image3m->SetRegions(region3m); image3m->Allocate(); image3m->FillBuffer(0); newSpacing[0] = spacing[1]; newSpacing[1] = spacing[2]; image3m->SetSpacing(newSpacing); for (unsigned int x = 0; x < mask1->GetDimensions()[0]; ++x) { for (unsigned int y = 0; y < mask1->GetDimensions()[1]; ++y) { for (unsigned int z = 0; z < mask1->GetDimensions()[2]; ++z) { NewImageType::IndexType newIndex; typename ImageType::IndexType index; index[0] = x; index[1] = y; index[2] = z; double pixel = itkImage->GetPixel(index)+1024; pixel = pixel / 1000.0; pixel = (pixel < 0)? 0 : pixel; newIndex[0] = x; newIndex[1] = y; image1->SetPixel(newIndex, image1->GetPixel(newIndex) + pixel); newIndex[0] = x; newIndex[1] = z; image2->SetPixel(newIndex, image2->GetPixel(newIndex) + pixel); newIndex[0] = y; newIndex[1] = z; image3->SetPixel(newIndex, image3->GetPixel(newIndex) + pixel); if (itkMask->GetPixel(index) > 0 && !param.invert) { pixel = param.zeroValue + 1024; pixel = pixel / 1000.0; } if (itkMask->GetPixel(index) < 1 && param.invert) { pixel = param.zeroValue + 1024; pixel = pixel / 1000.0; } pixel = (pixel < 0)? 0 : pixel; newIndex[0] = x; newIndex[1] = y; image1m->SetPixel(newIndex, image1m->GetPixel(newIndex) + pixel); newIndex[0] = x; newIndex[1] = z; image2m->SetPixel(newIndex, image2m->GetPixel(newIndex) + pixel); newIndex[0] = y; newIndex[1] = z; image3m->SetPixel(newIndex, image3m->GetPixel(newIndex) + pixel); } } } mitk::Image::Pointer img = mitk::ImportItkImage(image1); mitk::IOUtil::Save(img, output + "1.nrrd"); img = mitk::ImportItkImage(image2); mitk::IOUtil::Save(img, output + "2.nrrd"); img = mitk::ImportItkImage(image3); mitk::IOUtil::Save(img, output + "3.nrrd"); img = mitk::ImportItkImage(image1m); mitk::IOUtil::Save(img, output + "1m.nrrd"); img = mitk::ImportItkImage(image2m); mitk::IOUtil::Save(img, output + "2m.nrrd"); img = mitk::ImportItkImage(image3m); mitk::IOUtil::Save(img, output + "3m.nrrd"); } int main(int argc, char* argv[]) { mitkCommandLineParser parser; parser.setTitle("Dicom Loader"); parser.setCategory("Preprocessing Tools"); parser.setDescription(""); parser.setContributor("MBI"); parser.setArgumentPrefix("-","-"); // Add command line argument names parser.addArgument("help", "h",mitkCommandLineParser::Bool, "Help:", "Show this help text"); parser.addArgument("input", "i", mitkCommandLineParser::InputDirectory, "Input image:", "Input folder", us::Any(), false); parser.addArgument("mask", "m", mitkCommandLineParser::InputDirectory, "Input mask:", "Input folder", us::Any(), false); parser.addArgument("output", "o", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any(), false); parser.addArgument("invert", "invert", mitkCommandLineParser::Bool, "Input mask:", "Input folder", us::Any()); parser.addArgument("zero_value", "zero", mitkCommandLineParser::Float, "Output file:", "Output file", us::Any()); std::map parsedArgs = parser.parseArguments(argc, argv); if (parsedArgs.size()==0) return EXIT_FAILURE; // Show a help message if ( parsedArgs.count("help") || parsedArgs.count("h")) { std::cout << parser.helpText(); return EXIT_SUCCESS; } std::string inputImage = us::any_cast(parsedArgs["input"]); MITK_INFO << inputImage; std::string inputMask = us::any_cast(parsedArgs["mask"]); MITK_INFO << inputMask; Params param; param.invert = false; param.zeroValue = 0; if (parsedArgs.count("invert")) { param.invert = true; } if (parsedArgs.count("zero_value")) { param.zeroValue = us::any_cast(parsedArgs["zero_value"]); } mitk::Image::Pointer image = mitk::IOUtil::LoadImage(inputImage); mitk::Image::Pointer mask = mitk::IOUtil::LoadImage(inputMask); AccessByItk_3(image, CreateXRay, mask, parsedArgs["output"].ToString(),param); //const mitk::Image::Pointer image = *imageIter; //mitk::IOUtil::SaveImage(image,outFileName); return EXIT_SUCCESS; } diff --git a/Modules/Classification/DataCollection/Testing/mitKnnClassificationTest.cpp b/Modules/Classification/DataCollection/Testing/mitKnnClassificationTest.cpp index c3eaf5b099..a95a6ce70e 100644 --- a/Modules/Classification/DataCollection/Testing/mitKnnClassificationTest.cpp +++ b/Modules/Classification/DataCollection/Testing/mitKnnClassificationTest.cpp @@ -1,269 +1,268 @@ -#include #include #include #include #include #include #include #include "itkImageDuplicator.h" #include #include #include "ml.h" #include #include #include #define VDimension 3 // 2 D:\\output\\ D:\\TestImages\\train1.nrrd D:\\TestImages\\train2.nrrd D:\\TestImages\\train3.nrrd D:\\TestImages\\target1.nrrd D:\\TestImages\\target2.nrrd D:\\TestImages\\target3.nrrd D:\\TestImages\\test1.nrrd D:\\TestImages\\test2.nrrd D:\\TestImages\\test3.nrrd typedef unsigned char PixelType; typedef itk::Image< PixelType,VDimension > ImageType; typedef ImageType::Pointer ImageTypePtr; typedef itk::ImageFileReader< ImageType> ReaderType; typedef itk::ImageFileWriter< ImageType> WriterType; typedef mitk::mitkClassResultToImageFilter ResultToImageType; typedef itk::ImageDuplicator< ImageType > DuplicatorType; //cv::Mat create2DImageFromVect(cv::Size size, cv::Mat& image ) //{ // unsigned long index; // unsigned long x = 0; // unsigned long y = 0; // // cv::Mat outputImage(size.height,size.width,CV_32FC1); // // if(image.cols < 0) // { // std::cout << "Can't create 2D Image" << std::endl; // return outputImage; // // } // // for( index = 0; index < size.width*size.height ; index++) // { // x = (int) index % (size.width); // float d = index / (size.width); // y = (int) floor( d); // // unsigned char value; // float val = image.at(index,0); // value = (unsigned char) val; // outputImage.at(y,x)= value; // } // // return outputImage; //} int mitKnnClassificationTest(int argc, char* argv[] ) { if(argc < 5 ) { MITK_INFO << "Please specify number of NN as first parameter, as second parameter output path and train, target and test images in abitrary order" << std::endl << " train data must start with 'train*', target with 'target*' and test with 'test.'" << std::endl<< "Usage: 3 D:\\output\\ D:\\TestImages\\train1.nrrd D:\\TestImages\\train2.nrrd D:\\TestImages\\train3.nrrd D:\\TestImages\\target1.nrrd D:\\TestImages\\target2.nrrd D:\\TestImages\\target3.nrrd D:\\TestImages\\test1.nrrd D:\\TestImages\\test2.nrrd D:\\TestImages\\test3.nrrd" << std::endl; exit(-1); } std::vector inputFilesTrain; std::vector inputFilesTarget; std::vector inputFilesTest; std::string outputFolder; int k = atoi(argv[1]); outputFolder = argv[2]; for(int i = 3; i < argc; i++) { std::string str; str = argv[i]; if(str.find("train") != std::string::npos) { inputFilesTrain.push_back(str); } else if (str.find("target") != std::string::npos) { inputFilesTarget.push_back(str); } else if(str.find("test") != std::string::npos) { inputFilesTest.push_back(str); } } if( ( inputFilesTrain.size() || inputFilesTarget.size() ) <= 0) { MITK_INFO << "No test or training image set! " << std::endl; return -1; } if(inputFilesTrain.size() != inputFilesTarget.size()) { MITK_INFO << "Number of training and target images are not equal - please specify same number for training " << std::endl; return -1; } std::vector trainImages; std::vector targetImages; std::vector testImages; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); DuplicatorType::Pointer duplicator = DuplicatorType::New(); for(int i = 0; i< inputFilesTrain.size(); i++) { reader->SetFileName(inputFilesTrain.at(i)); reader->Update(); duplicator->SetInputImage(reader->GetOutput()); duplicator->Update(); trainImages.push_back(duplicator->GetOutput()); } for(int i = 0; i< inputFilesTarget.size(); i++) { reader->SetFileName(inputFilesTarget.at(i)); reader->Update(); duplicator->SetInputImage(reader->GetOutput()); duplicator->Update(); targetImages.push_back(duplicator->GetOutput()); } for(int i = 0; i< inputFilesTest.size(); i++) { reader->SetFileName(inputFilesTest.at(i)); reader->Update(); duplicator->SetInputImage(reader->GetOutput()); duplicator->Update(); testImages.push_back(duplicator->GetOutput()); } ResultToImageType::Pointer resultToImage = ResultToImageType::New(); mitk::mitkClassificationFeatureVectCreator::Pointer featureVectCreator = mitk::mitkClassificationFeatureVectCreator::New(); // SET NUMBER OF FeaturesProperly featureVectCreator->SetNumberOfFeaturesPerVoxel(1); featureVectCreator->SetGenerateResponsEnabled(false); cv::Mat output; // Image size ImageType::SizeType size; size = trainImages.at(0)->GetLargestPossibleRegion().GetSize(); int dim = 1; for(int i = 0; i < VDimension; i++) { dim *= size[i]; } // generate feature matrix from input images // generate train data for(int i = 0; i < trainImages.size(); i++) { featureVectCreator->SetPrimaryInput(trainImages.at(i)); featureVectCreator->Update(); } cv::Mat trainData = featureVectCreator->GetOuputCv(); //for(int i = 0; i< (trainData.rows /dim) ; i++ ) //{ // cv::Rect roi(0, i * dim,1,dim); // cv::Mat image(trainData,roi); // std::cout << image << std::endl; //} featureVectCreator->ClearData(); //generate target data for train data for(int i = 0; i < targetImages.size(); i++) { featureVectCreator->SetPrimaryInput(targetImages.at(i)); featureVectCreator->Update(); } cv::Mat targetData = featureVectCreator->GetOuputCv(); //for(int i = 0; i< (targetData.rows /dim) ; i++ ) //{ // cv::Rect roi(0, i * dim,1,dim); // cv::Mat image(targetData,roi); // std::cout << image << std::endl; //} // generate test data featureVectCreator->ClearData(); for(int i = 0; i < testImages.size(); i++) { featureVectCreator->SetPrimaryInput(testImages.at(i)); featureVectCreator->Update(); } cv::Mat testData = featureVectCreator->GetOuputCv(); //for(int i = 0; i< (testData.rows /dim) ; i++ ) //{ // cv::Rect roi(0, i * dim,1,dim); // cv::Mat image(testData,roi); // std::cout << image << std::endl; //} // Classification!! // KNN // number of NearestNeighbors CvKNearest knn( trainData, targetData, cv::Mat() ,false, k); cv::Mat neighbors(1,k, CV_32FC1); cv::Mat result(1,k,CV_32FC1); knn.find_nearest(testData,k,result,neighbors, cv::Mat()); itk::ProcessObject::DataObjectPointerArray array = resultToImage->GetOutputs(); if( itksys::SystemTools::FileIsDirectory(outputFolder.c_str() ) || !itksys::SystemTools::FileExists(outputFolder.c_str(),false) ) { itksys::SystemTools::MakeDirectory(outputFolder.c_str()); } // Write result images for(int i = 0; i< (result.rows /dim) ; i++ ) { cv::Rect roi(0, i * dim,1,dim); cv::Mat image(result,roi); resultToImage->setOpenCVInput(image,size); std::cout << image << std::endl; resultToImage->Update(); ImageTypePtr img = resultToImage->GetOutput(0); std::stringstream filename; filename << outputFolder << "result" << i << ".nrrd"; writer->SetFileName(filename.str()); writer->SetInput(img); writer->Update(); } return 0; } \ No newline at end of file diff --git a/Modules/Classification/DataCollection/Testing/mitkGenerateFeatureVectFromImageTest.cpp b/Modules/Classification/DataCollection/Testing/mitkGenerateFeatureVectFromImageTest.cpp index da76b6ed82..44077d826c 100644 --- a/Modules/Classification/DataCollection/Testing/mitkGenerateFeatureVectFromImageTest.cpp +++ b/Modules/Classification/DataCollection/Testing/mitkGenerateFeatureVectFromImageTest.cpp @@ -1,140 +1,139 @@ -#include #include #include #include //#include #include #include #include #include "itkImageDuplicator.h" #include #include #include // 2D Image //#define filename "D:\\gray.jpg" //#define VDimension 2 // 3D Image //#define filename "D:\\pic3d.nrrd" #define VDimension 3 int mitkGenerateFeatureVectFromImageTest(int argc, char* argv[]) { typedef unsigned char PixelType; typedef itk::Image< PixelType,VDimension > ImageType; typedef ImageType::Pointer ImageTypePtr; typedef itk::ImageDuplicator< ImageType > DuplicatorType; typedef itk::ImageFileReader< ImageType> ReaderType; typedef itk::ImageFileWriter< ImageType> WriterType; if(argc < 3) { MITK_INFO << "Please specify number of features per Voxel per Input (MUST BE IMPLEMENTED) and at least one input image" << std::endl; MITK_INFO << " Usage: 1 d:\\pic3d.nrrd [d:\\pic3d.nrrd] .." << std::endl; return -1; } int k = atoi(argv[1]); std::vector inputFile; for(int i = 2; i < argc; i++) { inputFile.push_back(argv[i]); } ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); std::vector inputImages; DuplicatorType::Pointer duplicator = DuplicatorType::New(); for(int i = 0; i< inputFile.size(); i++) { reader->SetFileName(inputFile.at(i)); reader->Update(); duplicator->SetInputImage(reader->GetOutput()); duplicator->Update(); inputImages.push_back(duplicator->GetOutput()); } mitk::mitkClassificationFeatureVectCreator::Pointer featureVectCreator = mitk::mitkClassificationFeatureVectCreator::New(); // SET NUMBER OF FeaturesProperly featureVectCreator->SetNumberOfFeaturesPerVoxel(k); for(int i = 0; i < inputImages.size(); i++) { featureVectCreator->SetNthInput(i,inputImages.at(i)); } featureVectCreator->Update(); std::cout << "Number of Inputs: " << featureVectCreator->GetNumberOfInputs() << std::endl; cv::Mat output = featureVectCreator->GetOuputCv(); float f1 = output.at(0,0); float f2 = output.at(0,1); MITK_INFO << "OutputVector :" << std::endl << output << std::endl; cv::waitKey(); //// Test with 2D Image for "visual" verification //if(VDimension == 2) //{ // ImageTypePtr image = inputImages.at(0); // unsigned int width; // unsigned int height; // unsigned int x,y; // width = image->GetLargestPossibleRegion().GetSize(0); // height = 2* image->GetLargestPossibleRegion().GetSize(1); // cv::Mat testImage(height,width, CV_8UC1); // cv::Mat testImage2(height,width, CV_8UC1); // cv::Mat testImage3(height,width, CV_8UC1); // unsigned int index = 0; // for( index = 0; index < width*height ; index++) // { // x = (int) index % (width); // float d = index / (width); // y = (int) floor( d); // unsigned char value; // float val = output.at(index,0); // value = (unsigned char) val; // testImage.at(y,x)= value; // if(featureVectCreator->GetIsGenerateResponseEnabled() == false) // { // value = (unsigned char) output.at(index,1); // testImage2.at(y,x)= value; // value = (unsigned char) output.at(index,2); // testImage3.at(y,x)= value; // } // } // cv::imshow("testImage1", testImage); // cv::imshow("testImage2", testImage2); // cv::imshow("testImage3", testImage3); // cv::waitKey(); //} //if(VDimension == 3) //{ // } return 0; } \ No newline at end of file diff --git a/Modules/Core/CMakeLists.txt b/Modules/Core/CMakeLists.txt index cf7b771577..b15690cf0f 100644 --- a/Modules/Core/CMakeLists.txt +++ b/Modules/Core/CMakeLists.txt @@ -1,77 +1,75 @@ set(TOOL_CPPS "") # temporary suppress warnings in the following files until image accessors are fully integrated. set_source_files_properties( src/DataManagement/mitkImage.cpp COMPILE_FLAGS -DMITK_NO_DEPRECATED_WARNINGS ) set_source_files_properties( src/Controllers/mitkSliceNavigationController.cpp COMPILE_FLAGS -DMITK_NO_DEPRECATED_WARNINGS ) MITK_CREATE_MODULE( INCLUDE_DIRS PUBLIC ${MITK_BINARY_DIR} PRIVATE src/Algorithms src/Controllers src/DataManagement src/Interactions src/IO src/Rendering ${OPENGL_INCLUDE_DIR} DEPENDS PUBLIC mbilog CppMicroServices PACKAGE_DEPENDS PRIVATE tinyxml OpenGL - # Remove public GDCM and ITKIOGDCM+... dependencies after mitkDicomSeriesReader was removed - PUBLIC GDCM - PUBLIC ITK|ITKTransform+ITKImageGrid+ITKImageFeature+ITKIOImageBase+ITKIOGDCM+ITKIOHDF5+ITKIOLSM+ITKIOMRC+ITKIOBioRad+ITKIOGE+ITKIOStimulate + PUBLIC ITK|ITKTransform+ITKImageGrid+ITKImageFeature+ITKIOImageBase+ITKIOHDF5+ITKIOLSM+ITKIOMRC+ITKIOBioRad+ITKIOGE+ITKIOStimulate # We privately use/link all ITK modules in order to support all IO, Transform, etc. # factories from ITK which are registered "automatically" via a factory manager. PRIVATE ITK PUBLIC VTK|vtkFiltersTexture+vtkFiltersParallel+vtkImagingStencil+vtkImagingMath+vtkInteractionStyle+vtkRenderingOpenGL2+vtkRenderingContextOpenGL2+vtkRenderingVolumeOpenGL2+vtkRenderingFreeType+vtkRenderingLabel+vtkInteractionWidgets+vtkIOGeometry+vtkIOXML PUBLIC Boost SUBPROJECTS MITK-Core # Do not automatically create CppMicroServices initialization code. # Because the VTK 6 "auto-init" functionality injects file-local static # initialization code in every cpp file which includes a VTK header, # static initialization order becomes an issue again. For the Mitk # core library, we need to ensure that the VTK static initialization stuff # happens before the CppMicroServices initialization, since the latter # might already use VTK code which needs to access VTK object factories. # Hence, CppMicroServices initialization code is placed manually within # the mitkCoreActivator.cpp file. NO_INIT ) if(NOT TARGET ${MODULE_TARGET}) message(SEND_ERROR "Core target ${MODULE_TARGET} does not exist") endif() function(_itk_create_factory_register_manager) # In MITK_ITK_Config.cmake, we do *not* include ITK_USE_FILE, which # prevents multiple registrations/unregistrations of ITK IO factories # during library loading/unloading (of MITK libraries). However, we need # "one" place where the IO factories are registered at # least once. This could be the application executable, but every executable would # need to take care of that itself. Instead, we allow the auto registration in the # Mitk Core library. set(NO_DIRECTORY_SCOPED_ITK_COMPILE_DEFINITION 1) find_package(ITK) include(${ITK_USE_FILE}) if(NOT ITK_NO_IO_FACTORY_REGISTER_MANAGER) # We manually add the define which will be of target scope. MITK # patches ITK_USE_FILE to remove the directory scoped compile # definition since it would be propagated to other targets in the # same directory scope but these targets might want to *not* # use the ITK factory manager stuff. target_compile_definitions(${MODULE_TARGET} PRIVATE ITK_IO_FACTORY_REGISTER_MANAGER) endif() endfunction() _itk_create_factory_register_manager() # this is needed for libraries which link to Mitk and need # symbols from explicitly instantiated templates if(MINGW) get_target_property(_mitkCore_MINGW_linkflags ${MODULE_TARGET} LINK_FLAGS) if(NOT _mitkCore_MINGW_linkflags) set(_mitkCore_MINGW_linkflags "") endif(NOT _mitkCore_MINGW_linkflags) set_target_properties(${MODULE_TARGET} PROPERTIES LINK_FLAGS "${_mitkCore_MINGW_linkflags} -Wl,--export-all-symbols") endif(MINGW) if(MSVC_IDE OR MSVC_VERSION OR MINGW) target_link_libraries(${MODULE_TARGET} PRIVATE psapi.lib) endif(MSVC_IDE OR MSVC_VERSION OR MINGW) add_subdirectory(TestingHelper) add_subdirectory(test) diff --git a/Modules/Core/files.cmake b/Modules/Core/files.cmake index a6dcf344b4..2950c63e78 100644 --- a/Modules/Core/files.cmake +++ b/Modules/Core/files.cmake @@ -1,325 +1,316 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES mitkCoreActivator.cpp mitkCoreObjectFactoryBase.cpp mitkCoreObjectFactory.cpp mitkCoreServices.cpp mitkException.cpp Algorithms/mitkBaseDataSource.cpp Algorithms/mitkClippedSurfaceBoundsCalculator.cpp Algorithms/mitkCompareImageDataFilter.cpp Algorithms/mitkCompositePixelValueToString.cpp Algorithms/mitkConvert2Dto3DImageFilter.cpp Algorithms/mitkDataNodeSource.cpp Algorithms/mitkExtractSliceFilter.cpp Algorithms/mitkExtractSliceFilter2.cpp Algorithms/mitkHistogramGenerator.cpp Algorithms/mitkImageChannelSelector.cpp Algorithms/mitkImageSliceSelector.cpp Algorithms/mitkImageSource.cpp Algorithms/mitkImageTimeSelector.cpp Algorithms/mitkImageToImageFilter.cpp Algorithms/mitkImageToSurfaceFilter.cpp Algorithms/mitkMultiComponentImageDataComparisonFilter.cpp Algorithms/mitkPlaneGeometryDataToSurfaceFilter.cpp Algorithms/mitkPointSetSource.cpp Algorithms/mitkPointSetToPointSetFilter.cpp Algorithms/mitkRGBToRGBACastImageFilter.cpp Algorithms/mitkSubImageSelector.cpp Algorithms/mitkSurfaceSource.cpp Algorithms/mitkSurfaceToImageFilter.cpp Algorithms/mitkSurfaceToSurfaceFilter.cpp Algorithms/mitkUIDGenerator.cpp Algorithms/mitkVolumeCalculator.cpp Controllers/mitkBaseController.cpp Controllers/mitkCallbackFromGUIThread.cpp Controllers/mitkCameraController.cpp Controllers/mitkCameraRotationController.cpp Controllers/mitkLimitedLinearUndo.cpp Controllers/mitkOperationEvent.cpp Controllers/mitkPlanePositionManager.cpp Controllers/mitkProgressBar.cpp Controllers/mitkRenderingManager.cpp Controllers/mitkSliceNavigationController.cpp Controllers/mitkSlicesCoordinator.cpp Controllers/mitkStatusBar.cpp Controllers/mitkStepper.cpp Controllers/mitkTestManager.cpp Controllers/mitkUndoController.cpp Controllers/mitkVerboseLimitedLinearUndo.cpp Controllers/mitkVtkLayerController.cpp DataManagement/mitkAnatomicalStructureColorPresets.cpp DataManagement/mitkArbitraryTimeGeometry.cpp DataManagement/mitkAbstractTransformGeometry.cpp DataManagement/mitkAnnotationProperty.cpp DataManagement/mitkApplicationCursor.cpp DataManagement/mitkApplyTransformMatrixOperation.cpp DataManagement/mitkBaseData.cpp DataManagement/mitkBaseGeometry.cpp DataManagement/mitkBaseProperty.cpp DataManagement/mitkChannelDescriptor.cpp DataManagement/mitkClippingProperty.cpp DataManagement/mitkColorProperty.cpp DataManagement/mitkDataNode.cpp DataManagement/mitkDataStorage.cpp DataManagement/mitkEnumerationProperty.cpp DataManagement/mitkFloatPropertyExtension.cpp DataManagement/mitkGeometry3D.cpp DataManagement/mitkGeometryData.cpp DataManagement/mitkGeometryTransformHolder.cpp DataManagement/mitkGroupTagProperty.cpp DataManagement/mitkGenericIDRelationRule.cpp DataManagement/mitkIdentifiable.cpp DataManagement/mitkImageAccessorBase.cpp DataManagement/mitkImageCaster.cpp DataManagement/mitkImageCastPart1.cpp DataManagement/mitkImageCastPart2.cpp DataManagement/mitkImageCastPart3.cpp DataManagement/mitkImageCastPart4.cpp DataManagement/mitkImage.cpp DataManagement/mitkImageDataItem.cpp DataManagement/mitkImageDescriptor.cpp DataManagement/mitkImageReadAccessor.cpp DataManagement/mitkImageStatisticsHolder.cpp DataManagement/mitkImageVtkAccessor.cpp DataManagement/mitkImageVtkReadAccessor.cpp DataManagement/mitkImageVtkWriteAccessor.cpp DataManagement/mitkImageWriteAccessor.cpp DataManagement/mitkIntPropertyExtension.cpp DataManagement/mitkIPersistenceService.cpp DataManagement/mitkIPropertyAliases.cpp DataManagement/mitkIPropertyDescriptions.cpp DataManagement/mitkIPropertyExtensions.cpp DataManagement/mitkIPropertyFilters.cpp DataManagement/mitkIPropertyOwner.cpp DataManagement/mitkIPropertyPersistence.cpp DataManagement/mitkIPropertyProvider.cpp DataManagement/mitkLandmarkProjectorBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjector.cpp DataManagement/mitkLevelWindow.cpp DataManagement/mitkLevelWindowManager.cpp DataManagement/mitkLevelWindowPreset.cpp DataManagement/mitkLevelWindowProperty.cpp DataManagement/mitkLine.cpp DataManagement/mitkLookupTable.cpp DataManagement/mitkLookupTableProperty.cpp DataManagement/mitkLookupTables.cpp # specializations of GenericLookupTable DataManagement/mitkMaterial.cpp DataManagement/mitkMemoryUtilities.cpp DataManagement/mitkModalityProperty.cpp DataManagement/mitkModifiedLock.cpp DataManagement/mitkNodePredicateAnd.cpp DataManagement/mitkNodePredicateBase.cpp DataManagement/mitkNodePredicateCompositeBase.cpp DataManagement/mitkNodePredicateData.cpp DataManagement/mitkNodePredicateDataType.cpp DataManagement/mitkNodePredicateDataUID.cpp DataManagement/mitkNodePredicateDimension.cpp DataManagement/mitkNodePredicateFirstLevel.cpp DataManagement/mitkNodePredicateFunction.cpp DataManagement/mitkNodePredicateGeometry.cpp DataManagement/mitkNodePredicateNot.cpp DataManagement/mitkNodePredicateOr.cpp DataManagement/mitkNodePredicateProperty.cpp DataManagement/mitkNodePredicateDataProperty.cpp DataManagement/mitkNodePredicateSource.cpp DataManagement/mitkNodePredicateUID.cpp DataManagement/mitkNumericConstants.cpp DataManagement/mitkPlaneGeometry.cpp DataManagement/mitkPlaneGeometryData.cpp DataManagement/mitkPlaneOperation.cpp DataManagement/mitkPlaneOrientationProperty.cpp DataManagement/mitkPointOperation.cpp DataManagement/mitkPointSet.cpp DataManagement/mitkPointSetShapeProperty.cpp DataManagement/mitkProperties.cpp DataManagement/mitkPropertyAliases.cpp DataManagement/mitkPropertyDescriptions.cpp DataManagement/mitkPropertyExtension.cpp DataManagement/mitkPropertyExtensions.cpp DataManagement/mitkPropertyFilter.cpp DataManagement/mitkPropertyFilters.cpp DataManagement/mitkPropertyKeyPath.cpp DataManagement/mitkPropertyList.cpp DataManagement/mitkPropertyListReplacedObserver.cpp DataManagement/mitkPropertyNameHelper.cpp DataManagement/mitkPropertyObserver.cpp DataManagement/mitkPropertyPersistence.cpp DataManagement/mitkPropertyPersistenceInfo.cpp DataManagement/mitkPropertyRelationRuleBase.cpp DataManagement/mitkProportionalTimeGeometry.cpp DataManagement/mitkRenderingModeProperty.cpp DataManagement/mitkResliceMethodProperty.cpp DataManagement/mitkRestorePlanePositionOperation.cpp DataManagement/mitkRotationOperation.cpp DataManagement/mitkScaleOperation.cpp DataManagement/mitkSlicedData.cpp DataManagement/mitkSlicedGeometry3D.cpp DataManagement/mitkSmartPointerProperty.cpp DataManagement/mitkStandaloneDataStorage.cpp DataManagement/mitkStringProperty.cpp DataManagement/mitkSurface.cpp DataManagement/mitkSurfaceOperation.cpp DataManagement/mitkThinPlateSplineCurvedGeometry.cpp DataManagement/mitkTimeGeometry.cpp DataManagement/mitkTransferFunction.cpp DataManagement/mitkTransferFunctionInitializer.cpp DataManagement/mitkTransferFunctionProperty.cpp DataManagement/mitkTemporoSpatialStringProperty.cpp DataManagement/mitkUIDManipulator.cpp DataManagement/mitkVector.cpp DataManagement/mitkVectorProperty.cpp DataManagement/mitkVtkInterpolationProperty.cpp DataManagement/mitkVtkRepresentationProperty.cpp DataManagement/mitkVtkResliceInterpolationProperty.cpp DataManagement/mitkVtkScalarModeProperty.cpp DataManagement/mitkVtkVolumeRenderingProperty.cpp DataManagement/mitkWeakPointerProperty.cpp DataManagement/mitkIPropertyRelations.cpp DataManagement/mitkPropertyRelations.cpp Interactions/mitkAction.cpp Interactions/mitkBindDispatcherInteractor.cpp Interactions/mitkCrosshairPositionEvent.cpp Interactions/mitkDataInteractor.cpp Interactions/mitkDispatcher.cpp Interactions/mitkDisplayCoordinateOperation.cpp Interactions/mitkDisplayInteractor.cpp Interactions/mitkEventConfig.cpp Interactions/mitkEventFactory.cpp Interactions/mitkEventRecorder.cpp Interactions/mitkEventStateMachine.cpp Interactions/mitkInteractionEventConst.cpp Interactions/mitkInteractionEvent.cpp Interactions/mitkInteractionEventHandler.cpp Interactions/mitkInteractionEventObserver.cpp Interactions/mitkInteractionKeyEvent.cpp Interactions/mitkInteractionPositionEvent.cpp Interactions/mitkInternalEvent.cpp Interactions/mitkMouseDoubleClickEvent.cpp Interactions/mitkMouseModeSwitcher.cpp Interactions/mitkMouseMoveEvent.cpp Interactions/mitkMousePressEvent.cpp Interactions/mitkMouseReleaseEvent.cpp Interactions/mitkMouseWheelEvent.cpp Interactions/mitkPointSetDataInteractor.cpp Interactions/mitkSinglePointDataInteractor.cpp Interactions/mitkStateMachineAction.cpp Interactions/mitkStateMachineCondition.cpp Interactions/mitkStateMachineContainer.cpp Interactions/mitkStateMachineState.cpp Interactions/mitkStateMachineTransition.cpp Interactions/mitkVtkEventAdapter.cpp Interactions/mitkVtkInteractorStyle.cxx Interactions/mitkXML2EventParser.cpp IO/mitkAbstractFileIO.cpp IO/mitkAbstractFileReader.cpp IO/mitkAbstractFileWriter.cpp IO/mitkCustomMimeType.cpp - IO/mitkDicomSeriesReader.cpp - IO/mitkDicomSeriesReaderService.cpp - IO/mitkDicomSR_GantryTiltInformation.cpp - IO/mitkDicomSR_ImageBlockDescriptor.cpp - IO/mitkDicomSR_LoadDICOMRGBPixel4D.cpp - IO/mitkDicomSR_LoadDICOMRGBPixel.cpp - IO/mitkDicomSR_LoadDICOMScalar4D.cpp - IO/mitkDicomSR_LoadDICOMScalar.cpp - IO/mitkDicomSR_SliceGroupingResult.cpp IO/mitkFileReader.cpp IO/mitkFileReaderRegistry.cpp IO/mitkFileReaderSelector.cpp IO/mitkFileReaderWriterBase.cpp IO/mitkFileWriter.cpp IO/mitkFileWriterRegistry.cpp IO/mitkFileWriterSelector.cpp IO/mitkGeometry3DToXML.cpp IO/mitkIFileIO.cpp IO/mitkIFileReader.cpp IO/mitkIFileWriter.cpp IO/mitkGeometryDataReaderService.cpp IO/mitkGeometryDataWriterService.cpp IO/mitkImageGenerator.cpp IO/mitkImageVtkLegacyIO.cpp IO/mitkImageVtkXmlIO.cpp IO/mitkIMimeTypeProvider.cpp IO/mitkIOConstants.cpp IO/mitkIOMimeTypes.cpp IO/mitkIOUtil.cpp IO/mitkItkImageIO.cpp IO/mitkItkLoggingAdapter.cpp IO/mitkLegacyFileReaderService.cpp IO/mitkLegacyFileWriterService.cpp IO/mitkLocaleSwitch.cpp IO/mitkLog.cpp IO/mitkMimeType.cpp IO/mitkMimeTypeProvider.cpp IO/mitkOperation.cpp IO/mitkPixelType.cpp IO/mitkPointSetReaderService.cpp IO/mitkPointSetWriterService.cpp IO/mitkProportionalTimeGeometryToXML.cpp IO/mitkRawImageFileReader.cpp IO/mitkStandardFileLocations.cpp IO/mitkSurfaceStlIO.cpp IO/mitkSurfaceVtkIO.cpp IO/mitkSurfaceVtkLegacyIO.cpp IO/mitkSurfaceVtkXmlIO.cpp IO/mitkVtkLoggingAdapter.cpp IO/mitkPreferenceListReaderOptionsFunctor.cpp Rendering/mitkAbstractAnnotationRenderer.cpp Rendering/mitkAnnotationUtils.cpp Rendering/mitkBaseRenderer.cpp #Rendering/mitkGLMapper.cpp Moved to deprecated LegacyGL Module Rendering/mitkGradientBackground.cpp Rendering/mitkImageVtkMapper2D.cpp Rendering/mitkMapper.cpp Rendering/mitkAnnotation.cpp Rendering/mitkPlaneGeometryDataMapper2D.cpp Rendering/mitkPlaneGeometryDataVtkMapper3D.cpp Rendering/mitkPointSetVtkMapper2D.cpp Rendering/mitkPointSetVtkMapper3D.cpp Rendering/mitkRenderWindowBase.cpp Rendering/mitkRenderWindow.cpp Rendering/mitkRenderWindowFrame.cpp #Rendering/mitkSurfaceGLMapper2D.cpp Moved to deprecated LegacyGL Module Rendering/mitkSurfaceVtkMapper2D.cpp Rendering/mitkSurfaceVtkMapper3D.cpp Rendering/mitkVtkEventProvider.cpp Rendering/mitkVtkMapper.cpp Rendering/mitkVtkPropRenderer.cpp Rendering/mitkVtkWidgetRendering.cpp Rendering/vtkMitkLevelWindowFilter.cpp Rendering/vtkMitkRectangleProp.cpp Rendering/vtkMitkRenderProp.cpp Rendering/vtkMitkThickSlicesFilter.cpp Rendering/vtkNeverTranslucentTexture.cpp ) set(RESOURCE_FILES Interactions/globalConfig.xml Interactions/DisplayInteraction.xml Interactions/DisplayConfig.xml Interactions/DisplayConfigPACS.xml Interactions/DisplayConfigPACSPan.xml Interactions/DisplayConfigPACSScroll.xml Interactions/DisplayConfigPACSZoom.xml Interactions/DisplayConfigPACSLevelWindow.xml Interactions/DisplayConfigMITK.xml Interactions/DisplayConfigMITKNoCrosshair.xml Interactions/DisplayConfigMITKRotation.xml Interactions/DisplayConfigMITKRotationUnCoupled.xml Interactions/DisplayConfigMITKSwivel.xml Interactions/DisplayConfigMITKLimited.xml Interactions/PointSet.xml Interactions/Legacy/StateMachine.xml Interactions/Legacy/DisplayConfigMITKTools.xml Interactions/PointSetConfig.xml mitkLevelWindowPresets.xml mitkAnatomicalStructureColorPresets.xml ) diff --git a/Modules/Core/include/mitkIDataNodeReader.h b/Modules/Core/include/mitkIDataNodeReader.h deleted file mode 100644 index b7ef923b7e..0000000000 --- a/Modules/Core/include/mitkIDataNodeReader.h +++ /dev/null @@ -1,57 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#ifndef MITKIDATANODEREADER_H -#define MITKIDATANODEREADER_H - -#include -#include - -namespace mitk -{ - class DataStorage; - - /** - * \ingroup MicroServices_Interfaces - * - * This interface provides methods to load data from the local filesystem - * into a given mitk::DataStorage. - * - * \deprecatedSince{2014_10} Use mitk::IFileReader instead - */ - struct IDataNodeReader - { - virtual ~IDataNodeReader() {} - /** - * Reads the local file given by fileName and constructs one or more - * mitk::DataNode instances which are added to the given mitk::DataStorage storage. - * - * \param fileName The absolute path to a local file. - * \param storage The mitk::DataStorage which will contain the constructed data nodes. - * \return The number of constructed mitk::DataNode instances. - * - * \note Errors during reading the file or constructing the data node should be expressed by - * throwing appropriate exceptions. - * - * \see mitk::DataNodeFactory - */ - virtual int Read(const std::string &fileName, mitk::DataStorage &storage) = 0; - }; -} - -MITK_DECLARE_SERVICE_INTERFACE(mitk::IDataNodeReader, "org.mitk.IDataNodeReader") - -#endif // MITKIDATANODEREADER_H diff --git a/Modules/Core/include/mitkImageVtkMapper2D.h b/Modules/Core/include/mitkImageVtkMapper2D.h index a8a33923eb..3e7a9e48c3 100644 --- a/Modules/Core/include/mitkImageVtkMapper2D.h +++ b/Modules/Core/include/mitkImageVtkMapper2D.h @@ -1,310 +1,310 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKIMAGEVTKMAPPER2D_H_HEADER_INCLUDED_C10E906E #define MITKIMAGEVTKMAPPER2D_H_HEADER_INCLUDED_C10E906E // MITK #include // MITK Rendering #include "mitkBaseRenderer.h" #include "mitkExtractSliceFilter.h" #include "mitkVtkMapper.h" // VTK #include #include class vtkActor; class vtkPolyDataMapper; class vtkPlaneSource; class vtkImageData; class vtkLookupTable; class vtkImageExtractComponents; class vtkImageReslice; class vtkImageChangeInformation; class vtkPoints; class vtkMitkThickSlicesFilter; class vtkPolyData; class vtkMitkApplyLevelWindowToRGBFilter; class vtkMitkLevelWindowFilter; namespace mitk { /** \brief Mapper to resample and display 2D slices of a 3D image. * * The following image gives a brief overview of the mapping and the involved parts. * * \image html imageVtkMapper2Darchitecture.png * * First, the image is resliced by means of vtkImageReslice. The volume image * serves as input to the mapper in addition to spatial placement of the slice and a few other * properties such as thick slices. This code was already present in the old version * (mitkImageMapperGL2D). * * Next, the obtained slice (m_ReslicedImage) is put into a vtkMitkLevelWindowFilter * and the scalar levelwindow, opacity levelwindow and optional clipping to * local image bounds are applied * * Next, the output of the vtkMitkLevelWindowFilter is used to create a texture * (m_Texture) and a plane onto which the texture is rendered (m_Plane). For * mapping purposes, a vtkPolyDataMapper (m_Mapper) is utilized. Orthographic * projection is applied to create the effect of a 2D image. The mapper and the * texture are assigned to the actor (m_Actor) which is passed to the VTK rendering * pipeline via the method GetVtkProp(). * * In order to transform the textured plane to the correct position in space, the * same transformation as used for reslicing is applied to both the camera and the * vtkActor. All important steps are explained in more detail below. The resulting * 2D image (by reslicing the underlying 3D input image appropriately) can either * be directly rendered in a 2D view or just be calculated to be used later by another * rendering entity, e.g. in texture mapping in a 3D view. * * Properties that can be set for images and influence the imageMapper2D are: * * - \b "opacity": (FloatProperty) Opacity of the image * - \b "color": (ColorProperty) Color of the image * - \b "LookupTable": (mitkLookupTableProperty) If this property is set, * the default lookuptable will be ignored and the "LookupTable" value * will be used instead. * - \b "Image Rendering.Mode": This property decides which mode is used to render images. (E.g. if a lookup table or a transferfunction is applied). Detailed documentation about the modes can be found here: \link mitk::RenderingerModeProperty \endlink * - \b "Image Rendering.Transfer Function": (mitkTransferFunctionProperty) If this * property is set, a color transferfunction will be used to color the image. * - \b "binary": (BoolProperty) is the image a binary image or not * - \b "outline binary": (BoolProperty) show outline of the image or not * - \b "texture interpolation": (BoolProperty) texture interpolation of the image * - \b "reslice interpolation": (VtkResliceInterpolationProperty) reslice interpolation of the image * - \b "in plane resample extent by geometry": (BoolProperty) Do it or not * - \b "bounding box": (BoolProperty) Is the Bounding Box of the image shown or not * - \b "layer": (IntProperty) Layer of the image * - \b "volume annotation color": (ColorProperty) color of the volume annotation, TODO has to be reimplemented * - \b "volume annotation unit": (StringProperty) annotation unit as string (does not implicit convert the unit!) unit is ml or cm3, TODO has to be reimplemented * The default properties are: * - \b "opacity", mitk::FloatProperty::New(0.3f), renderer, overwrite ) * - \b "color", ColorProperty::New(1.0,0.0,0.0), renderer, overwrite ) * - \b "binary", mitk::BoolProperty::New( true ), renderer, overwrite ) * - \b "outline binary", mitk::BoolProperty::New( false ), renderer, overwrite ) - * - \b "texture interpolation", mitk::BoolProperty::New( mitk::DataNodeFactory::m_TextureInterpolationActive ) ) + * - \b "texture interpolation", mitk::BoolProperty::New( false ) ) * - \b "reslice interpolation", mitk::VtkResliceInterpolationProperty::New() ) * - \b "in plane resample extent by geometry", mitk::BoolProperty::New( false ) ) * - \b "bounding box", mitk::BoolProperty::New( false ) ) * - \b "layer", mitk::IntProperty::New(10), renderer, overwrite) * - \b "Image Rendering.Transfer Function": Default color transfer function for CTs * - \b "LookupTable": Rainbow color. * If the modality-property is set for an image, the mapper uses modality-specific default properties, * e.g. color maps, if they are defined. * \ingroup Mapper */ class MITKCORE_EXPORT ImageVtkMapper2D : public VtkMapper { public: /** Standard class typedefs. */ mitkClassMacro(ImageVtkMapper2D, VtkMapper); /** Method for creation through the object factory. */ itkFactorylessNewMacro(Self) itkCloneMacro(Self) /** \brief Get the Image to map */ const mitk::Image *GetInput(void); /** \brief Checks whether this mapper needs to update itself and generate * data. */ void Update(mitk::BaseRenderer *renderer) override; //### methods of MITK-VTK rendering pipeline vtkProp *GetVtkProp(mitk::BaseRenderer *renderer) override; //### end of methods of MITK-VTK rendering pipeline /** \brief Internal class holding the mapper, actor, etc. for each of the 3 2D render windows */ /** * To render transveral, coronal, and sagittal, the mapper is called three times. * For performance reasons, the corresponding data for each view is saved in the * internal helper class LocalStorage. This allows rendering n views with just * 1 mitkMapper using n vtkMapper. * */ class MITKCORE_EXPORT LocalStorage : public mitk::Mapper::BaseLocalStorage { public: /** \brief Actor of a 2D render window. */ vtkSmartPointer m_Actor; vtkSmartPointer m_Actors; /** \brief Mapper of a 2D render window. */ vtkSmartPointer m_Mapper; vtkSmartPointer m_VectorComponentExtractor; /** \brief Current slice of a 2D render window.*/ vtkSmartPointer m_ReslicedImage; /** \brief Empty vtkPolyData that is set when rendering geometry does not * intersect the image geometry. * \warning This member variable is set to nullptr, * if no image geometry is inside the plane geometry * of the respective render window. Any user of this * slice has to check whether it is set to nullptr! */ vtkSmartPointer m_EmptyPolyData; /** \brief Plane on which the slice is rendered as texture. */ vtkSmartPointer m_Plane; /** \brief The texture which is used to render the current slice. */ vtkSmartPointer m_Texture; /** \brief The lookuptables for colors and level window */ vtkSmartPointer m_DefaultLookupTable; vtkSmartPointer m_BinaryLookupTable; vtkSmartPointer m_ColorLookupTable; /** \brief The actual reslicer (one per renderer) */ mitk::ExtractSliceFilter::Pointer m_Reslicer; /** \brief Filter for thick slices */ vtkSmartPointer m_TSFilter; /** \brief PolyData object containg all lines/points needed for outlining the contour. This container is used to save a computed contour for the next rendering execution. For instance, if you zoom or pann, there is no need to recompute the contour. */ vtkSmartPointer m_OutlinePolyData; /** \brief Timestamp of last update of stored data. */ itk::TimeStamp m_LastUpdateTime; /** \brief mmPerPixel relation between pixel and mm. (World spacing).*/ mitk::ScalarType *m_mmPerPixel; /** \brief This filter is used to apply the level window to Grayvalue and RBG(A) images. */ vtkSmartPointer m_LevelWindowFilter; /** \brief Default constructor of the local storage. */ LocalStorage(); /** \brief Default deconstructor of the local storage. */ ~LocalStorage() override; }; /** \brief The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows. */ mitk::LocalStorageHandler m_LSH; /** \brief Get the LocalStorage corresponding to the current renderer. */ LocalStorage *GetLocalStorage(mitk::BaseRenderer *renderer); /** \brief Set the default properties for general image rendering. */ static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer = nullptr, bool overwrite = false); /** \brief This method switches between different rendering modes (e.g. use a lookup table or a transfer function). * Detailed documentation about the modes can be found here: \link mitk::RenderingerModeProperty \endlink */ void ApplyRenderingMode(mitk::BaseRenderer *renderer); protected: /** \brief Transforms the actor to the actual position in 3D. * \param renderer The current renderer corresponding to the render window. */ void TransformActor(mitk::BaseRenderer *renderer); /** \brief Generates a plane according to the size of the resliced image in milimeters. * * \image html texturedPlane.png * * In VTK a vtkPlaneSource is defined through three points. The origin and two * points defining the axes of the plane (see VTK documentation). The origin is * set to (xMin; yMin; Z), where xMin and yMin are the minimal bounds of the * resliced image in space. Z is relevant for blending and the layer property. * The center of the plane (C) is also the center of the view plane (cf. the image above). * * \note For the standard MITK view with three 2D render windows showing three * different slices, three such planes are generated. All these planes are generated * in the XY-plane (even if they depict a YZ-slice of the volume). * */ void GeneratePlane(mitk::BaseRenderer *renderer, double planeBounds[6]); /** \brief Generates a vtkPolyData object containing the outline of a given binary slice. \param renderer: Pointer to the renderer containing the needed information \note This code is based on code from the iil library. */ template vtkSmartPointer CreateOutlinePolyData(mitk::BaseRenderer *renderer); /** Default constructor */ ImageVtkMapper2D(); /** Default deconstructor */ ~ImageVtkMapper2D() override; /** \brief Does the actual resampling, without rendering the image yet. * All the data is generated inside this method. The vtkProp (or Actor) * is filled with content (i.e. the resliced image). * * After generation, a 4x4 transformation matrix(t) of the current slice is obtained * from the vtkResliceImage object via GetReslicesAxis(). This matrix is * applied to each textured plane (actor->SetUserTransform(t)) to transform everything * to the actual 3D position (cf. the following image). * * \image html cameraPositioning3D.png * */ void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override; /** \brief This method uses the vtkCamera clipping range and the layer property * to calcualte the depth of the object (e.g. image or contour). The depth is used * to keep the correct order for the final VTK rendering.*/ float CalculateLayerDepth(mitk::BaseRenderer *renderer); /** \brief This method applies (or modifies) the lookuptable for all types of images. * \warning To use the lookup table, the property 'Lookup Table' must be set and a 'Image Rendering.Mode' * which uses the lookup table must be set. */ void ApplyLookuptable(mitk::BaseRenderer *renderer); /** \brief This method applies a color transfer function. * Internally, a vtkColorTransferFunction is used. This is usefull for coloring continous * images (e.g. float) * \warning To use the color transfer function, the property 'Image Rendering.Transfer Function' must be set and a * 'Image Rendering.Mode' which uses the color transfer function must be set. */ void ApplyColorTransferFunction(mitk::BaseRenderer *renderer); /** * @brief ApplyLevelWindow Apply the level window for the given renderer. * \warning To use the level window, the property 'LevelWindow' must be set and a 'Image Rendering.Mode' which uses * the level window must be set. * @param renderer Level window for which renderer? */ void ApplyLevelWindow(mitk::BaseRenderer *renderer); /** \brief Set the color of the image/polydata */ void ApplyColor(mitk::BaseRenderer *renderer); /** \brief Set the opacity of the actor. */ void ApplyOpacity(mitk::BaseRenderer *renderer); /** * \brief Calculates whether the given rendering geometry intersects the * given SlicedGeometry3D. * * This method checks if the given PlaneGeometry intersects the given * SlicedGeometry3D. It calculates the distance of the PlaneGeometry to all * 8 cornerpoints of the SlicedGeometry3D. If all distances have the same * sign (all positive or all negative) there is no intersection. * If the distances have different sign, there is an intersection. **/ bool RenderingGeometryIntersectsImage(const PlaneGeometry *renderingGeometry, SlicedGeometry3D *imageGeometry); }; } // namespace mitk #endif /* MITKIMAGEVTKMAPPER2D_H_HEADER_INCLUDED_C10E906E */ diff --git a/Modules/Core/src/IO/mitkDicomSeriesReaderService.cpp b/Modules/Core/src/IO/mitkDicomSeriesReaderService.cpp deleted file mode 100644 index f58fc8d0f0..0000000000 --- a/Modules/Core/src/IO/mitkDicomSeriesReaderService.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#include "mitkDicomSeriesReaderService.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace mitk -{ - DicomSeriesReaderService::DicomSeriesReaderService() - : AbstractFileReader(CustomMimeType(IOMimeTypes::DICOM_MIMETYPE()), "MITK DICOM Reader") - { - this->RegisterService(); - } - - std::vector> DicomSeriesReaderService::Read() - { - std::vector result; - - mitk::LocaleSwitch localeSwitch("C"); - std::locale previousCppLocale(std::cin.getloc()); - std::locale l("C"); - std::cin.imbue(l); - - std::string fileName = this->GetLocalFileName(); - if (DicomSeriesReader::IsPhilips3DDicom(fileName)) - { - MITK_INFO << "it is a Philips3D US Dicom file" << std::endl; - DataNode::Pointer node = DataNode::New(); - mitk::DicomSeriesReader::StringContainer stringvec; - stringvec.push_back(fileName); - if (DicomSeriesReader::LoadDicomSeries(stringvec, *node)) - { - BaseData::Pointer data = node->GetData(); - StringProperty::Pointer nameProp = StringProperty::New(itksys::SystemTools::GetFilenameName(fileName)); - data->GetPropertyList()->SetProperty("name", nameProp); - result.push_back(data); - } - std::cin.imbue(previousCppLocale); - return result; - } - - DicomSeriesReader::FileNamesGrouping imageBlocks = - DicomSeriesReader::GetSeries(itksys::SystemTools::GetFilenamePath(fileName), - true); // true = group gantry tilt images - const unsigned int size = imageBlocks.size(); - - ProgressBar::GetInstance()->AddStepsToDo(size); - ProgressBar::GetInstance()->Progress(); - - unsigned int outputIndex = 0u; - const DicomSeriesReader::FileNamesGrouping::const_iterator n_end = imageBlocks.end(); - - for (DicomSeriesReader::FileNamesGrouping::const_iterator n_it = imageBlocks.begin(); n_it != n_end; ++n_it) - { - const std::string &uid = n_it->first; - DataNode::Pointer node = DataNode::New(); - - const DicomSeriesReader::ImageBlockDescriptor &imageBlockDescriptor(n_it->second); - - MITK_INFO << "--------------------------------------------------------------------------------"; - MITK_INFO << "DicomSeriesReader: Loading DICOM series " << outputIndex << ": Series UID " - << imageBlockDescriptor.GetSeriesInstanceUID() << std::endl; - MITK_INFO << " " << imageBlockDescriptor.GetFilenames().size() << " '" << imageBlockDescriptor.GetModality() - << "' files (" << imageBlockDescriptor.GetSOPClassUIDAsString() << ") loaded into 1 mitk::Image"; - MITK_INFO << " multi-frame: " << (imageBlockDescriptor.IsMultiFrameImage() ? "Yes" : "No"); - MITK_INFO << " reader support: " << DicomSeriesReader::ReaderImplementationLevelToString( - imageBlockDescriptor.GetReaderImplementationLevel()); - MITK_INFO << " pixel spacing type: " - << DicomSeriesReader::PixelSpacingInterpretationToString(imageBlockDescriptor.GetPixelSpacingType()); - MITK_INFO << " gantry tilt corrected: " << (imageBlockDescriptor.HasGantryTiltCorrected() ? "Yes" : "No"); - MITK_INFO << " 3D+t: " << (imageBlockDescriptor.HasMultipleTimePoints() ? "Yes" : "No"); - MITK_INFO << "--------------------------------------------------------------------------------"; - - if (DicomSeriesReader::LoadDicomSeries(n_it->second.GetFilenames(), *node, true, true, true)) - { - BaseData::Pointer data = node->GetData(); - PropertyList::ConstPointer dataProps = data->GetPropertyList().GetPointer(); - - std::string nodeName(uid); - std::string studyDescription; - - if (GetBackwardsCompatibleDICOMProperty( - 0x0008, 0x1030, "dicom.study.StudyDescription", dataProps, studyDescription)) - { - nodeName = studyDescription; - std::string seriesDescription; - - if (GetBackwardsCompatibleDICOMProperty( - 0x0008, 0x103e, "dicom.study.SeriesDescription", dataProps, seriesDescription)) - { // may not be a string property so use the generic access. - nodeName += "/" + seriesDescription; - } - } - - StringProperty::Pointer nameProp = StringProperty::New(nodeName); - data->SetProperty("name", nameProp); - - result.push_back(data); - ++outputIndex; - } - else - { - MITK_ERROR << "DicomSeriesReader: Skipping series " << outputIndex << " due to some unspecified error..." - << std::endl; - } - - ProgressBar::GetInstance()->Progress(); - } - - std::cin.imbue(previousCppLocale); - - return result; - } - - DicomSeriesReaderService *DicomSeriesReaderService::Clone() const { return new DicomSeriesReaderService(*this); } -} diff --git a/Modules/Core/src/IO/mitkDicomSeriesReaderService.h b/Modules/Core/src/IO/mitkDicomSeriesReaderService.h deleted file mode 100644 index 04d3f482cb..0000000000 --- a/Modules/Core/src/IO/mitkDicomSeriesReaderService.h +++ /dev/null @@ -1,37 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#ifndef MITKDICOMSERIESREADERSERVICE_H -#define MITKDICOMSERIESREADERSERVICE_H - -#include - -namespace mitk -{ - class DicomSeriesReaderService : public AbstractFileReader - { - public: - DicomSeriesReaderService(); - - using AbstractFileReader::Read; - std::vector> Read() override; - - private: - DicomSeriesReaderService *Clone() const override; - }; -} - -#endif // MITKDICOMSERIESREADERSERVICE_H diff --git a/Modules/Core/src/IO/mitkIOUtil.cpp b/Modules/Core/src/IO/mitkIOUtil.cpp index 635905f554..de2ceb9c6d 100644 --- a/Modules/Core/src/IO/mitkIOUtil.cpp +++ b/Modules/Core/src/IO/mitkIOUtil.cpp @@ -1,1062 +1,1061 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkIOUtil.h" #include #include #include #include #include -#include #include #include #include #include #include #include #include #include #include // ITK #include // VTK #include #include #include #include #include static std::string GetLastErrorStr() { #ifdef US_PLATFORM_POSIX return std::string(strerror(errno)); #else // Retrieve the system error message for the last-error code LPVOID lpMsgBuf; DWORD dw = GetLastError(); FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, nullptr); std::string errMsg((LPCTSTR)lpMsgBuf); LocalFree(lpMsgBuf); return errMsg; #endif } #ifdef US_PLATFORM_WINDOWS #include #include // make the posix flags point to the obsolte bsd types on windows #define S_IRUSR S_IREAD #define S_IWUSR S_IWRITE #else #include #include #include #endif #include #include static const char validLetters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // A cross-platform version of the mkstemps function static int mkstemps_compat(char *tmpl, int suffixlen) { static unsigned long long value = 0; int savedErrno = errno; // Lower bound on the number of temporary files to attempt to generate. #define ATTEMPTS_MIN (62 * 62 * 62) /* The number of times to attempt to generate a temporary file. To conform to POSIX, this must be no smaller than TMP_MAX. */ #if ATTEMPTS_MIN < TMP_MAX const unsigned int attempts = TMP_MAX; #else const unsigned int attempts = ATTEMPTS_MIN; #endif const int len = strlen(tmpl); if ((len - suffixlen) < 6 || strncmp(&tmpl[len - 6 - suffixlen], "XXXXXX", 6)) { errno = EINVAL; return -1; } /* This is where the Xs start. */ char *XXXXXX = &tmpl[len - 6 - suffixlen]; /* Get some more or less random data. */ #ifdef US_PLATFORM_WINDOWS { SYSTEMTIME stNow; FILETIME ftNow; // get system time GetSystemTime(&stNow); stNow.wMilliseconds = 500; if (!SystemTimeToFileTime(&stNow, &ftNow)) { errno = -1; return -1; } unsigned long long randomTimeBits = ((static_cast(ftNow.dwHighDateTime) << 32) | static_cast(ftNow.dwLowDateTime)); value = randomTimeBits ^ static_cast(GetCurrentThreadId()); } #else { struct timeval tv; gettimeofday(&tv, nullptr); unsigned long long randomTimeBits = ((static_cast(tv.tv_usec) << 32) | static_cast(tv.tv_sec)); value = randomTimeBits ^ static_cast(getpid()); } #endif for (unsigned int count = 0; count < attempts; value += 7777, ++count) { unsigned long long v = value; /* Fill in the random bits. */ XXXXXX[0] = validLetters[v % 62]; v /= 62; XXXXXX[1] = validLetters[v % 62]; v /= 62; XXXXXX[2] = validLetters[v % 62]; v /= 62; XXXXXX[3] = validLetters[v % 62]; v /= 62; XXXXXX[4] = validLetters[v % 62]; v /= 62; XXXXXX[5] = validLetters[v % 62]; int fd = open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); if (fd >= 0) { errno = savedErrno; return fd; } else if (errno != EEXIST) { return -1; } } /* We got out of the loop because we ran out of combinations to try. */ errno = EEXIST; return -1; } // A cross-platform version of the POSIX mkdtemp function static char *mkdtemps_compat(char *tmpl, int suffixlen) { static unsigned long long value = 0; int savedErrno = errno; // Lower bound on the number of temporary dirs to attempt to generate. #define ATTEMPTS_MIN (62 * 62 * 62) /* The number of times to attempt to generate a temporary dir. To conform to POSIX, this must be no smaller than TMP_MAX. */ #if ATTEMPTS_MIN < TMP_MAX const unsigned int attempts = TMP_MAX; #else const unsigned int attempts = ATTEMPTS_MIN; #endif const int len = strlen(tmpl); if ((len - suffixlen) < 6 || strncmp(&tmpl[len - 6 - suffixlen], "XXXXXX", 6)) { errno = EINVAL; return nullptr; } /* This is where the Xs start. */ char *XXXXXX = &tmpl[len - 6 - suffixlen]; /* Get some more or less random data. */ #ifdef US_PLATFORM_WINDOWS { SYSTEMTIME stNow; FILETIME ftNow; // get system time GetSystemTime(&stNow); stNow.wMilliseconds = 500; if (!SystemTimeToFileTime(&stNow, &ftNow)) { errno = -1; return nullptr; } unsigned long long randomTimeBits = ((static_cast(ftNow.dwHighDateTime) << 32) | static_cast(ftNow.dwLowDateTime)); value = randomTimeBits ^ static_cast(GetCurrentThreadId()); } #else { struct timeval tv; gettimeofday(&tv, nullptr); unsigned long long randomTimeBits = ((static_cast(tv.tv_usec) << 32) | static_cast(tv.tv_sec)); value = randomTimeBits ^ static_cast(getpid()); } #endif unsigned int count = 0; for (; count < attempts; value += 7777, ++count) { unsigned long long v = value; /* Fill in the random bits. */ XXXXXX[0] = validLetters[v % 62]; v /= 62; XXXXXX[1] = validLetters[v % 62]; v /= 62; XXXXXX[2] = validLetters[v % 62]; v /= 62; XXXXXX[3] = validLetters[v % 62]; v /= 62; XXXXXX[4] = validLetters[v % 62]; v /= 62; XXXXXX[5] = validLetters[v % 62]; #ifdef US_PLATFORM_WINDOWS int fd = _mkdir(tmpl); //, _S_IREAD | _S_IWRITE | _S_IEXEC); #else int fd = mkdir(tmpl, S_IRUSR | S_IWUSR | S_IXUSR); #endif if (fd >= 0) { errno = savedErrno; return tmpl; } else if (errno != EEXIST) { return nullptr; } } /* We got out of the loop because we ran out of combinations to try. */ errno = EEXIST; return nullptr; } //#endif //************************************************************** // mitk::IOUtil method definitions namespace mitk { struct IOUtil::Impl { struct FixedReaderOptionsFunctor : public ReaderOptionsFunctorBase { FixedReaderOptionsFunctor(const IFileReader::Options &options) : m_Options(options) {} bool operator()(LoadInfo &loadInfo) const override { IFileReader *reader = loadInfo.m_ReaderSelector.GetSelected().GetReader(); if (reader) { reader->SetOptions(m_Options); } return false; } private: const IFileReader::Options &m_Options; }; struct FixedWriterOptionsFunctor : public WriterOptionsFunctorBase { FixedWriterOptionsFunctor(const IFileReader::Options &options) : m_Options(options) {} bool operator()(SaveInfo &saveInfo) const override { IFileWriter *writer = saveInfo.m_WriterSelector.GetSelected().GetWriter(); if (writer) { writer->SetOptions(m_Options); } return false; } private: const IFileWriter::Options &m_Options; }; static BaseData::Pointer LoadBaseDataFromFile(const std::string &path, const ReaderOptionsFunctorBase* optionsCallback = nullptr); static void SetDefaultDataNodeProperties(mitk::DataNode *node, const std::string &filePath = std::string()); }; BaseData::Pointer IOUtil::Impl::LoadBaseDataFromFile(const std::string &path, const ReaderOptionsFunctorBase *optionsCallback) { std::vector baseDataList = Load(path, optionsCallback); // The Load(path) call above should throw an exception if nothing could be loaded assert(!baseDataList.empty()); return baseDataList.front(); } #ifdef US_PLATFORM_WINDOWS std::string IOUtil::GetProgramPath() { char path[512]; std::size_t index = std::string(path, GetModuleFileName(nullptr, path, 512)).find_last_of('\\'); return std::string(path, index); } #elif defined(US_PLATFORM_APPLE) #include std::string IOUtil::GetProgramPath() { char path[512]; uint32_t size = sizeof(path); if (_NSGetExecutablePath(path, &size) == 0) { std::size_t index = std::string(path).find_last_of('/'); std::string strPath = std::string(path, index); // const char* execPath = strPath.c_str(); // mitk::StandardFileLocations::GetInstance()->AddDirectoryForSearch(execPath,false); return strPath; } return std::string(); } #else #include #include #include std::string IOUtil::GetProgramPath() { std::stringstream ss; ss << "/proc/" << getpid() << "/exe"; char proc[512] = {0}; ssize_t ch = readlink(ss.str().c_str(), proc, 512); if (ch == -1) return std::string(); std::size_t index = std::string(proc).find_last_of('/'); return std::string(proc, index); } #endif char IOUtil::GetDirectorySeparator() { #ifdef US_PLATFORM_WINDOWS return '\\'; #else return '/'; #endif } std::string IOUtil::GetTempPath() { static std::string result; if (result.empty()) { #ifdef US_PLATFORM_WINDOWS char tempPathTestBuffer[1]; DWORD bufferLength = ::GetTempPath(1, tempPathTestBuffer); if (bufferLength == 0) { mitkThrow() << GetLastErrorStr(); } std::vector tempPath(bufferLength); bufferLength = ::GetTempPath(bufferLength, &tempPath[0]); if (bufferLength == 0) { mitkThrow() << GetLastErrorStr(); } result.assign(tempPath.begin(), tempPath.begin() + static_cast(bufferLength)); #else result = "/tmp/"; #endif } return result; } std::string IOUtil::CreateTemporaryFile(const std::string &templateName, std::string path) { ofstream tmpOutputStream; std::string returnValue = CreateTemporaryFile(tmpOutputStream, templateName, path); tmpOutputStream.close(); return returnValue; } std::string IOUtil::CreateTemporaryFile(std::ofstream &f, const std::string &templateName, std::string path) { return CreateTemporaryFile(f, std::ios_base::out | std::ios_base::trunc, templateName, path); } std::string IOUtil::CreateTemporaryFile(std::ofstream &f, std::ios_base::openmode mode, const std::string &templateName, std::string path) { if (path.empty()) { path = GetTempPath(); } path += templateName; std::vector dst_path(path.begin(), path.end()); dst_path.push_back('\0'); std::size_t lastX = path.find_last_of('X'); std::size_t firstX = path.find_last_not_of('X', lastX); int firstNonX = firstX == std::string::npos ? -1 : firstX - 1; while (lastX != std::string::npos && (lastX - firstNonX) < 6) { lastX = path.find_last_of('X', firstX); firstX = path.find_last_not_of('X', lastX); firstNonX = firstX == std::string::npos ? -1 : firstX - 1; } std::size_t suffixlen = lastX == std::string::npos ? path.size() : path.size() - lastX - 1; int fd = mkstemps_compat(&dst_path[0], suffixlen); if (fd != -1) { path.assign(dst_path.begin(), dst_path.end() - 1); f.open(path.c_str(), mode | std::ios_base::out | std::ios_base::trunc); close(fd); } else { mitkThrow() << "Creating temporary file " << &dst_path[0] << " failed: " << GetLastErrorStr(); } return path; } std::string IOUtil::CreateTemporaryDirectory(const std::string &templateName, std::string path) { if (path.empty()) { path = GetTempPath(); } path += GetDirectorySeparator() + templateName; std::vector dst_path(path.begin(), path.end()); dst_path.push_back('\0'); std::size_t lastX = path.find_last_of('X'); std::size_t firstX = path.find_last_not_of('X', lastX); int firstNonX = firstX == std::string::npos ? -1 : firstX - 1; while (lastX != std::string::npos && (lastX - firstNonX) < 6) { lastX = path.find_last_of('X', firstX); firstX = path.find_last_not_of('X', lastX); firstNonX = firstX == std::string::npos ? -1 : firstX - 1; } std::size_t suffixlen = lastX == std::string::npos ? path.size() : path.size() - lastX - 1; if (mkdtemps_compat(&dst_path[0], suffixlen) == nullptr) { mitkThrow() << "Creating temporary directory " << &dst_path[0] << " failed: " << GetLastErrorStr(); } path.assign(dst_path.begin(), dst_path.end() - 1); return path; } DataStorage::SetOfObjects::Pointer IOUtil::Load(const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback) { std::vector paths; paths.push_back(path); return Load(paths, storage, optionsCallback); } DataStorage::SetOfObjects::Pointer IOUtil::Load(const std::string &path, const IFileReader::Options &options, DataStorage &storage) { std::vector loadInfos; loadInfos.push_back(LoadInfo(path)); DataStorage::SetOfObjects::Pointer nodeResult = DataStorage::SetOfObjects::New(); Impl::FixedReaderOptionsFunctor optionsCallback(options); std::string errMsg = Load(loadInfos, nodeResult, &storage, &optionsCallback); if (!errMsg.empty()) { mitkThrow() << errMsg; } return nodeResult; } std::vector IOUtil::Load(const std::string &path, const ReaderOptionsFunctorBase *optionsCallback) { std::vector paths; paths.push_back(path); return Load(paths, optionsCallback); } std::vector IOUtil::Load(const std::string &path, const IFileReader::Options &options) { std::vector loadInfos; loadInfos.push_back(LoadInfo(path)); Impl::FixedReaderOptionsFunctor optionsCallback(options); std::string errMsg = Load(loadInfos, nullptr, nullptr, &optionsCallback); if (!errMsg.empty()) { mitkThrow() << errMsg; } return loadInfos.front().m_Output; } DataStorage::SetOfObjects::Pointer IOUtil::Load(const std::vector &paths, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback) { DataStorage::SetOfObjects::Pointer nodeResult = DataStorage::SetOfObjects::New(); std::vector loadInfos; for (auto loadInfo : paths) { loadInfos.push_back(loadInfo); } std::string errMsg = Load(loadInfos, nodeResult, &storage, optionsCallback); if (!errMsg.empty()) { mitkThrow() << errMsg; } return nodeResult; } std::vector IOUtil::Load(const std::vector &paths, const ReaderOptionsFunctorBase *optionsCallback) { std::vector result; std::vector loadInfos; for (auto loadInfo : paths) { loadInfos.push_back(loadInfo); } std::string errMsg = Load(loadInfos, nullptr, nullptr, optionsCallback); if (!errMsg.empty()) { mitkThrow() << errMsg; } for (std::vector::const_iterator iter = loadInfos.begin(), iterEnd = loadInfos.end(); iter != iterEnd; ++iter) { result.insert(result.end(), iter->m_Output.begin(), iter->m_Output.end()); } return result; } Image::Pointer IOUtil::LoadImage(const std::string &path, const ReaderOptionsFunctorBase *optionsCallback) { BaseData::Pointer baseData = Impl::LoadBaseDataFromFile(path, optionsCallback); mitk::Image::Pointer image = dynamic_cast(baseData.GetPointer()); if (image.IsNull()) { mitkThrow() << path << " is not a mitk::Image but a " << baseData->GetNameOfClass(); } return image; } Surface::Pointer IOUtil::LoadSurface(const std::string &path, const ReaderOptionsFunctorBase *optionsCallback) { BaseData::Pointer baseData = Impl::LoadBaseDataFromFile(path, optionsCallback); mitk::Surface::Pointer surface = dynamic_cast(baseData.GetPointer()); if (surface.IsNull()) { mitkThrow() << path << " is not a mitk::Surface but a " << baseData->GetNameOfClass(); } return surface; } PointSet::Pointer IOUtil::LoadPointSet(const std::string &path, const ReaderOptionsFunctorBase *optionsCallback) { BaseData::Pointer baseData = Impl::LoadBaseDataFromFile(path, optionsCallback); mitk::PointSet::Pointer pointset = dynamic_cast(baseData.GetPointer()); if (pointset.IsNull()) { mitkThrow() << path << " is not a mitk::PointSet but a " << baseData->GetNameOfClass(); } return pointset; } std::string IOUtil::Load(std::vector &loadInfos, DataStorage::SetOfObjects *nodeResult, DataStorage *ds, const ReaderOptionsFunctorBase *optionsCallback) { if (loadInfos.empty()) { return "No input files given"; } int filesToRead = loadInfos.size(); mitk::ProgressBar::GetInstance()->AddStepsToDo(2 * filesToRead); std::string errMsg; std::map usedReaderItems; std::vector< std::string > read_files; for (auto &loadInfo : loadInfos) { if(std::find(read_files.begin(), read_files.end(), loadInfo.m_Path) != read_files.end()) continue; std::vector readers = loadInfo.m_ReaderSelector.Get(); if (readers.empty()) { if (!itksys::SystemTools::FileExists(loadInfo.m_Path.c_str())) { errMsg += "File '" + loadInfo.m_Path + "' does not exist\n"; } else { errMsg += "No reader available for '" + loadInfo.m_Path + "'\n"; } continue; } bool callOptionsCallback = readers.size() > 1 || !readers.front().GetReader()->GetOptions().empty(); // check if we already used a reader which should be re-used std::vector currMimeTypes = loadInfo.m_ReaderSelector.GetMimeTypes(); std::string selectedMimeType; for (std::vector::const_iterator mimeTypeIter = currMimeTypes.begin(), mimeTypeIterEnd = currMimeTypes.end(); mimeTypeIter != mimeTypeIterEnd; ++mimeTypeIter) { std::map::const_iterator oldSelectedItemIter = usedReaderItems.find(mimeTypeIter->GetName()); if (oldSelectedItemIter != usedReaderItems.end()) { // we found an already used item for a mime-type which is contained // in the current reader set, check all current readers if there service // id equals the old reader for (std::vector::const_iterator currReaderItem = readers.begin(), currReaderItemEnd = readers.end(); currReaderItem != currReaderItemEnd; ++currReaderItem) { if (currReaderItem->GetMimeType().GetName() == mimeTypeIter->GetName() && currReaderItem->GetServiceId() == oldSelectedItemIter->second.GetServiceId() && currReaderItem->GetConfidenceLevel() >= oldSelectedItemIter->second.GetConfidenceLevel()) { // okay, we used the same reader already, re-use its options selectedMimeType = mimeTypeIter->GetName(); callOptionsCallback = false; loadInfo.m_ReaderSelector.Select(oldSelectedItemIter->second.GetServiceId()); loadInfo.m_ReaderSelector.GetSelected().GetReader()->SetOptions( oldSelectedItemIter->second.GetReader()->GetOptions()); break; } } if (!selectedMimeType.empty()) break; } } if (callOptionsCallback && optionsCallback) { callOptionsCallback = (*optionsCallback)(loadInfo); if (!callOptionsCallback && !loadInfo.m_Cancel) { usedReaderItems.erase(selectedMimeType); FileReaderSelector::Item selectedItem = loadInfo.m_ReaderSelector.GetSelected(); usedReaderItems.insert(std::make_pair(selectedItem.GetMimeType().GetName(), selectedItem)); } } if (loadInfo.m_Cancel) { errMsg += "Reading operation(s) cancelled."; break; } IFileReader *reader = loadInfo.m_ReaderSelector.GetSelected().GetReader(); if (reader == nullptr) { errMsg += "Unexpected nullptr reader."; break; } // Do the actual reading try { DataStorage::SetOfObjects::Pointer nodes; if (ds != nullptr) { nodes = reader->Read(*ds); std::vector< std::string > new_files = reader->GetReadFiles(); read_files.insert( read_files.end(), new_files.begin(), new_files.end() ); } else { nodes = DataStorage::SetOfObjects::New(); std::vector baseData = reader->Read(); for (auto iter = baseData.begin(); iter != baseData.end(); ++iter) { if (iter->IsNotNull()) { mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(*iter); nodes->InsertElement(nodes->Size(), node); } } std::vector< std::string > new_files = reader->GetReadFiles(); read_files.insert( read_files.end(), new_files.begin(), new_files.end() ); } for (DataStorage::SetOfObjects::ConstIterator nodeIter = nodes->Begin(), nodeIterEnd = nodes->End(); nodeIter != nodeIterEnd; ++nodeIter) { const mitk::DataNode::Pointer &node = nodeIter->Value(); mitk::BaseData::Pointer data = node->GetData(); if (data.IsNull()) { continue; } mitk::StringProperty::Pointer pathProp = mitk::StringProperty::New(loadInfo.m_Path); data->SetProperty("path", pathProp); loadInfo.m_Output.push_back(data); if (nodeResult) { nodeResult->push_back(nodeIter->Value()); } } if (loadInfo.m_Output.empty() || (nodeResult && nodeResult->Size() == 0)) { errMsg += "Unknown read error occurred reading " + loadInfo.m_Path; } } catch (const std::exception &e) { errMsg += "Exception occured when reading file " + loadInfo.m_Path + ":\n" + e.what() + "\n\n"; } mitk::ProgressBar::GetInstance()->Progress(2); --filesToRead; } if (!errMsg.empty()) { MITK_ERROR << errMsg; } mitk::ProgressBar::GetInstance()->Progress(2 * filesToRead); return errMsg; } std::vector IOUtil::Load(const us::ModuleResource &usResource, std::ios_base::openmode mode) { us::ModuleResourceStream resStream(usResource, mode); mitk::CoreServicePointer mimeTypeProvider(mitk::CoreServices::GetMimeTypeProvider()); std::vector mimetypes = mimeTypeProvider->GetMimeTypesForFile(usResource.GetResourcePath()); std::vector data; if (mimetypes.empty()) { mitkThrow() << "No mimetype for resource stream: " << usResource.GetResourcePath(); return data; } mitk::FileReaderRegistry fileReaderRegistry; std::vector> refs = fileReaderRegistry.GetReferences(mimetypes[0]); if (refs.empty()) { mitkThrow() << "No reader available for resource stream: " << usResource.GetResourcePath(); return data; } mitk::IFileReader *reader = fileReaderRegistry.GetReader(refs[0]); reader->SetInput(usResource.GetResourcePath(), &resStream); data = reader->Read(); return data; } void IOUtil::Save(const BaseData *data, const std::string &path) { Save(data, path, IFileWriter::Options()); } void IOUtil::Save(const BaseData *data, const std::string &path, const IFileWriter::Options &options) { Save(data, std::string(), path, options); } void IOUtil::Save(const BaseData *data, const std::string &mimeType, const std::string &path, bool addExtension) { Save(data, mimeType, path, IFileWriter::Options(), addExtension); } void IOUtil::Save(const BaseData *data, const std::string &mimeType, const std::string &path, const IFileWriter::Options &options, bool addExtension) { if ((data == nullptr) || (data->IsEmpty())) mitkThrow() << "BaseData cannotbe null or empty for save methods in IOUtil.h."; std::string errMsg; if (options.empty()) { errMsg = Save(data, mimeType, path, nullptr, addExtension); } else { Impl::FixedWriterOptionsFunctor optionsCallback(options); errMsg = Save(data, mimeType, path, &optionsCallback, addExtension); } if (!errMsg.empty()) { mitkThrow() << errMsg; } } void IOUtil::Save(std::vector &saveInfos) { std::string errMsg = Save(saveInfos, nullptr); if (!errMsg.empty()) { mitkThrow() << errMsg; } } std::string IOUtil::Save(const BaseData *data, const std::string &mimeTypeName, const std::string &path, WriterOptionsFunctorBase *optionsCallback, bool addExtension) { if (path.empty()) { return "No output filename given"; } mitk::CoreServicePointer mimeTypeProvider(mitk::CoreServices::GetMimeTypeProvider()); MimeType mimeType = mimeTypeProvider->GetMimeTypeForName(mimeTypeName); SaveInfo saveInfo(data, mimeType, path); std::string ext = itksys::SystemTools::GetFilenameExtension(path); if (saveInfo.m_WriterSelector.IsEmpty()) { return std::string("No suitable writer found for the current data of type ") + data->GetNameOfClass() + (mimeType.IsValid() ? (std::string(" and mime-type ") + mimeType.GetName()) : std::string()) + (ext.empty() ? std::string() : (std::string(" with extension ") + ext)); } // Add an extension if not already specified if (ext.empty() && addExtension) { saveInfo.m_MimeType.GetExtensions().empty() ? std::string() : "." + saveInfo.m_MimeType.GetExtensions().front(); } std::vector infos; infos.push_back(saveInfo); return Save(infos, optionsCallback); } std::string IOUtil::Save(std::vector &saveInfos, WriterOptionsFunctorBase *optionsCallback) { if (saveInfos.empty()) { return "No data for saving available"; } int filesToWrite = saveInfos.size(); mitk::ProgressBar::GetInstance()->AddStepsToDo(2 * filesToWrite); std::string errMsg; std::set usedSaveInfos; for (auto &saveInfo : saveInfos) { const std::string baseDataType = saveInfo.m_BaseData->GetNameOfClass(); std::vector writers = saveInfo.m_WriterSelector.Get(); // Error out if no compatible Writer was found if (writers.empty()) { errMsg += std::string("No writer available for ") + baseDataType + " data.\n"; continue; } bool callOptionsCallback = writers.size() > 1 || !writers[0].GetWriter()->GetOptions().empty(); // check if we already used a writer for this base data type // which should be re-used auto oldSaveInfoIter = usedSaveInfos.find(saveInfo); if (oldSaveInfoIter != usedSaveInfos.end()) { // we previously saved a base data object of the same data with the same mime-type, // check if the same writer is contained in the current writer set and if the // confidence level matches FileWriterSelector::Item oldSelectedItem = oldSaveInfoIter->m_WriterSelector.Get(oldSaveInfoIter->m_WriterSelector.GetSelectedId()); for (std::vector::const_iterator currWriterItem = writers.begin(), currWriterItemEnd = writers.end(); currWriterItem != currWriterItemEnd; ++currWriterItem) { if (currWriterItem->GetServiceId() == oldSelectedItem.GetServiceId() && currWriterItem->GetConfidenceLevel() >= oldSelectedItem.GetConfidenceLevel()) { // okay, we used the same writer already, re-use its options callOptionsCallback = false; saveInfo.m_WriterSelector.Select(oldSaveInfoIter->m_WriterSelector.GetSelectedId()); saveInfo.m_WriterSelector.GetSelected().GetWriter()->SetOptions(oldSelectedItem.GetWriter()->GetOptions()); break; } } } if (callOptionsCallback && optionsCallback) { callOptionsCallback = (*optionsCallback)(saveInfo); if (!callOptionsCallback && !saveInfo.m_Cancel) { usedSaveInfos.erase(saveInfo); usedSaveInfos.insert(saveInfo); } } if (saveInfo.m_Cancel) { errMsg += "Writing operation(s) cancelled."; break; } IFileWriter *writer = saveInfo.m_WriterSelector.GetSelected().GetWriter(); if (writer == nullptr) { errMsg += "Unexpected nullptr writer."; break; } // Do the actual writing try { writer->SetOutputLocation(saveInfo.m_Path); writer->Write(); } catch (const std::exception &e) { errMsg += std::string("Exception occurred when writing to ") + saveInfo.m_Path + ":\n" + e.what() + "\n"; } mitk::ProgressBar::GetInstance()->Progress(2); --filesToWrite; } if (!errMsg.empty()) { MITK_ERROR << errMsg; } mitk::ProgressBar::GetInstance()->Progress(2 * filesToWrite); return errMsg; } // This method can be removed after the deprecated LoadDataNode() method was removed void IOUtil::Impl::SetDefaultDataNodeProperties(DataNode *node, const std::string &filePath) { // path mitk::StringProperty::Pointer pathProp = mitk::StringProperty::New(itksys::SystemTools::GetFilenamePath(filePath)); node->SetProperty(StringProperty::PATH, pathProp); // name already defined? mitk::StringProperty::Pointer nameProp = dynamic_cast(node->GetProperty("name")); if (nameProp.IsNull() || (strcmp(nameProp->GetValue(), "No Name!") == 0)) { // name already defined in BaseData mitk::StringProperty::Pointer baseDataNameProp = dynamic_cast(node->GetData()->GetProperty("name").GetPointer()); if (baseDataNameProp.IsNull() || (strcmp(baseDataNameProp->GetValue(), "No Name!") == 0)) { // name neither defined in node, nor in BaseData -> name = filename nameProp = mitk::StringProperty::New(itksys::SystemTools::GetFilenameWithoutExtension(filePath)); node->SetProperty("name", nameProp); } else { // name defined in BaseData! nameProp = mitk::StringProperty::New(baseDataNameProp->GetValue()); node->SetProperty("name", nameProp); } } // visibility if (!node->GetProperty("visible")) { node->SetVisibility(true); } } IOUtil::SaveInfo::SaveInfo(const BaseData *baseData, const MimeType &mimeType, const std::string &path) : m_BaseData(baseData), m_WriterSelector(baseData, mimeType.GetName(), path), m_MimeType(mimeType.IsValid() ? mimeType // use the original mime-type : (m_WriterSelector.IsEmpty() ? mimeType // no writer found, use the original invalid mime-type : m_WriterSelector.GetDefault().GetMimeType() // use the found default mime-type )), m_Path(path), m_Cancel(false) { } bool IOUtil::SaveInfo::operator<(const IOUtil::SaveInfo &other) const { int r = strcmp(m_BaseData->GetNameOfClass(), other.m_BaseData->GetNameOfClass()); if (r == 0) { return m_WriterSelector.GetSelected().GetMimeType() < other.m_WriterSelector.GetSelected().GetMimeType(); } return r < 0; } IOUtil::LoadInfo::LoadInfo(const std::string &path) : m_Path(path), m_ReaderSelector(path), m_Cancel(false) {} } diff --git a/Modules/Core/src/IO/mitkLegacyFileReaderService.cpp b/Modules/Core/src/IO/mitkLegacyFileReaderService.cpp index dde4675791..edcaa2cea8 100644 --- a/Modules/Core/src/IO/mitkLegacyFileReaderService.cpp +++ b/Modules/Core/src/IO/mitkLegacyFileReaderService.cpp @@ -1,118 +1,117 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkLegacyFileReaderService.h" #include -#include #include #include #include mitk::LegacyFileReaderService::LegacyFileReaderService(const mitk::LegacyFileReaderService &other) : mitk::AbstractFileReader(other) { } mitk::LegacyFileReaderService::LegacyFileReaderService(const std::vector &extensions, const std::string &category) : AbstractFileReader() { this->SetMimeTypePrefix(IOMimeTypes::DEFAULT_BASE_NAME() + ".legacy."); CustomMimeType customMimeType; customMimeType.SetCategory(category); for (auto extension : extensions) { if (!extension.empty() && extension[0] == '.') { extension.assign(extension.begin() + 1, extension.end()); } customMimeType.AddExtension(extension); } this->SetDescription(category); this->SetMimeType(customMimeType); m_ServiceReg = this->RegisterService(); } mitk::LegacyFileReaderService::~LegacyFileReaderService() { } ////////////////////// Reading ///////////////////////// std::vector> mitk::LegacyFileReaderService::Read() { std::vector result; std::list possibleIOAdapter; std::list allobjects = itk::ObjectFactoryBase::CreateAllInstance("mitkIOAdapter"); for (auto i = allobjects.begin(); i != allobjects.end(); ++i) { auto *io = dynamic_cast(i->GetPointer()); if (io) { possibleIOAdapter.push_back(io); } else { MITK_ERROR << "Error BaseDataIO factory did not return an IOAdapterBase: " << (*i)->GetNameOfClass() << std::endl; } } const std::string path = this->GetLocalFileName(); for (auto k = possibleIOAdapter.begin(); k != possibleIOAdapter.end(); ++k) { bool canReadFile = (*k)->CanReadFile(path, "", ""); // they could read the file if (canReadFile) { BaseDataSource::Pointer ioObject = (*k)->CreateIOProcessObject(path, "", ""); ioObject->Update(); auto numberOfContents = static_cast(ioObject->GetNumberOfOutputs()); if (numberOfContents > 0) { BaseData::Pointer baseData; for (int i = 0; i < numberOfContents; ++i) { baseData = dynamic_cast(ioObject->GetOutputs()[i].GetPointer()); if (baseData) // this is what's wanted, right? { result.push_back(baseData); } } } break; } } if (result.empty()) { mitkThrow() << "Could not read file '" << path << "'"; } return result; } mitk::LegacyFileReaderService *mitk::LegacyFileReaderService::Clone() const { return new LegacyFileReaderService(*this); } diff --git a/Modules/Core/src/mitkCoreActivator.cpp b/Modules/Core/src/mitkCoreActivator.cpp index 96f92328ff..12f59e65fd 100644 --- a/Modules/Core/src/mitkCoreActivator.cpp +++ b/Modules/Core/src/mitkCoreActivator.cpp @@ -1,327 +1,325 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkCoreActivator.h" // File IO #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#include "mitkDicomSeriesReaderService.h" #include "mitkLegacyFileWriterService.h" #include #include #include // Micro Services #include #include #include #include #include #include #include #include #include #include // ITK "injects" static initialization code for IO factories // via the itkImageIOFactoryRegisterManager.h header (which // is generated in the application library build directory). // To ensure that the code is called *before* the CppMicroServices // static initialization code (which triggers the Activator::Start // method), we include the ITK header here. #include void HandleMicroServicesMessages(us::MsgType type, const char *msg) { switch (type) { case us::DebugMsg: MITK_DEBUG << msg; break; case us::InfoMsg: MITK_INFO << msg; break; case us::WarningMsg: MITK_WARN << msg; break; case us::ErrorMsg: MITK_ERROR << msg; break; } } void AddMitkAutoLoadPaths(const std::string &programPath) { us::ModuleSettings::AddAutoLoadPath(programPath); #ifdef __APPLE__ // Walk up three directories since that is where the .dylib files are located // for build trees. std::string additionalPath = programPath; bool addPath = true; for (int i = 0; i < 3; ++i) { std::size_t index = additionalPath.find_last_of('/'); if (index != std::string::npos) { additionalPath = additionalPath.substr(0, index); } else { addPath = false; break; } } if (addPath) { us::ModuleSettings::AddAutoLoadPath(additionalPath); } #endif } class FixedNiftiImageIO : public itk::NiftiImageIO { public: /** Standard class typedefs. */ typedef FixedNiftiImageIO Self; typedef itk::NiftiImageIO Superclass; typedef itk::SmartPointer Pointer; /** Method for creation through the object factory. */ itkNewMacro(Self) /** Run-time type information (and related methods). */ itkTypeMacro(FixedNiftiImageIO, Superclass) bool SupportsDimension(unsigned long dim) override { return dim > 1 && dim < 5; } }; void MitkCoreActivator::Load(us::ModuleContext *context) { // Handle messages from CppMicroServices us::installMsgHandler(HandleMicroServicesMessages); this->m_Context = context; // Add the current application directory to the auto-load paths. // This is useful for third-party executables. std::string programPath = mitk::IOUtil::GetProgramPath(); if (programPath.empty()) { MITK_WARN << "Could not get the program path."; } else { AddMitkAutoLoadPaths(programPath); } // m_RenderingManager = mitk::RenderingManager::New(); // context->RegisterService(renderingManager.GetPointer()); m_PlanePositionManager.reset(new mitk::PlanePositionManagerService); context->RegisterService(m_PlanePositionManager.get()); m_PropertyAliases.reset(new mitk::PropertyAliases); context->RegisterService(m_PropertyAliases.get()); m_PropertyDescriptions.reset(new mitk::PropertyDescriptions); context->RegisterService(m_PropertyDescriptions.get()); m_PropertyExtensions.reset(new mitk::PropertyExtensions); context->RegisterService(m_PropertyExtensions.get()); m_PropertyFilters.reset(new mitk::PropertyFilters); context->RegisterService(m_PropertyFilters.get()); m_PropertyPersistence.reset(new mitk::PropertyPersistence); context->RegisterService(m_PropertyPersistence.get()); m_PropertyRelations.reset(new mitk::PropertyRelations); context->RegisterService(m_PropertyRelations.get()); m_MimeTypeProvider.reset(new mitk::MimeTypeProvider); m_MimeTypeProvider->Start(); m_MimeTypeProviderReg = context->RegisterService(m_MimeTypeProvider.get()); this->RegisterDefaultMimeTypes(); this->RegisterItkReaderWriter(); this->RegisterVtkReaderWriter(); // Add custom Reader / Writer Services m_FileReaders.push_back(new mitk::PointSetReaderService()); m_FileWriters.push_back(new mitk::PointSetWriterService()); m_FileReaders.push_back(new mitk::GeometryDataReaderService()); m_FileWriters.push_back(new mitk::GeometryDataWriterService()); - m_FileReaders.push_back(new mitk::DicomSeriesReaderService()); m_FileReaders.push_back(new mitk::RawImageFileReaderService()); /* There IS an option to exchange ALL vtkTexture instances against vtkNeverTranslucentTextureFactory. This code is left here as a reminder, just in case we might need to do that some time. vtkNeverTranslucentTextureFactory* textureFactory = vtkNeverTranslucentTextureFactory::New(); vtkObjectFactory::RegisterFactory( textureFactory ); textureFactory->Delete(); */ this->RegisterLegacyWriter(); } void MitkCoreActivator::Unload(us::ModuleContext *) { for (auto &elem : m_FileReaders) { delete elem; } for (auto &elem : m_FileWriters) { delete elem; } for (auto &elem : m_FileIOs) { delete elem; } for (auto &elem : m_LegacyWriters) { delete elem; } // The mitk::ModuleContext* argument of the Unload() method // will always be 0 for the Mitk library. It makes no sense // to use it at this stage anyway, since all libraries which // know about the module system have already been unloaded. // we need to close the internal service tracker of the // MimeTypeProvider class here. Otherwise it // would hold on to the ModuleContext longer than it is // actually valid. m_MimeTypeProviderReg.Unregister(); m_MimeTypeProvider->Stop(); for (std::vector::const_iterator mimeTypeIter = m_DefaultMimeTypes.begin(), iterEnd = m_DefaultMimeTypes.end(); mimeTypeIter != iterEnd; ++mimeTypeIter) { delete *mimeTypeIter; } } void MitkCoreActivator::RegisterDefaultMimeTypes() { // Register some default mime-types std::vector mimeTypes = mitk::IOMimeTypes::Get(); for (std::vector::const_iterator mimeTypeIter = mimeTypes.begin(), iterEnd = mimeTypes.end(); mimeTypeIter != iterEnd; ++mimeTypeIter) { m_DefaultMimeTypes.push_back(*mimeTypeIter); m_Context->RegisterService(m_DefaultMimeTypes.back()); } } void MitkCoreActivator::RegisterItkReaderWriter() { std::list allobjects = itk::ObjectFactoryBase::CreateAllInstance("itkImageIOBase"); for (auto &allobject : allobjects) { auto *io = dynamic_cast(allobject.GetPointer()); // NiftiImageIO does not provide a correct "SupportsDimension()" methods // and the supported read/write extensions are not ordered correctly if (dynamic_cast(io)) continue; // Use a custom mime-type for GDCMImageIO below if (dynamic_cast(allobject.GetPointer())) { // MITK provides its own DICOM reader (which internally uses GDCMImageIO). continue; } if (io) { m_FileIOs.push_back(new mitk::ItkImageIO(io)); } else { MITK_WARN << "Error ImageIO factory did not return an ImageIOBase: " << (allobject)->GetNameOfClass(); } } FixedNiftiImageIO::Pointer itkNiftiIO = FixedNiftiImageIO::New(); mitk::ItkImageIO *niftiIO = new mitk::ItkImageIO(mitk::IOMimeTypes::NIFTI_MIMETYPE(), itkNiftiIO.GetPointer(), 0); m_FileIOs.push_back(niftiIO); } void MitkCoreActivator::RegisterVtkReaderWriter() { m_FileIOs.push_back(new mitk::SurfaceVtkXmlIO()); m_FileIOs.push_back(new mitk::SurfaceStlIO()); m_FileIOs.push_back(new mitk::SurfaceVtkLegacyIO()); m_FileIOs.push_back(new mitk::ImageVtkXmlIO()); m_FileIOs.push_back(new mitk::ImageVtkLegacyIO()); } void MitkCoreActivator::RegisterLegacyWriter() { std::list allobjects = itk::ObjectFactoryBase::CreateAllInstance("IOWriter"); for (auto i = allobjects.begin(); i != allobjects.end(); ++i) { mitk::FileWriter::Pointer io = dynamic_cast(i->GetPointer()); if (io) { std::string description = std::string("Legacy ") + io->GetNameOfClass() + " Writer"; mitk::IFileWriter *writer = new mitk::LegacyFileWriterService(io, description); m_LegacyWriters.push_back(writer); } else { MITK_ERROR << "Error IOWriter override is not of type mitk::FileWriter: " << (*i)->GetNameOfClass() << std::endl; } } } US_EXPORT_MODULE_ACTIVATOR(MitkCoreActivator) // Call CppMicroservices initialization code at the end of the file. // This especially ensures that VTK object factories have already // been registered (VTK initialization code is injected by implicitly // include VTK header files at the top of this file). US_INITIALIZE_MODULE diff --git a/Modules/Core/test/CMakeLists.txt b/Modules/Core/test/CMakeLists.txt index 61a4fd1b4a..52f41548f3 100644 --- a/Modules/Core/test/CMakeLists.txt +++ b/Modules/Core/test/CMakeLists.txt @@ -1,219 +1,215 @@ # The core tests need relaxed compiler flags... # TODO fix core tests to compile without these additional no-error flags if(MSVC_VERSION) # disable deprecated warnings (they would lead to errors) mitkFunctionCheckCAndCXXCompilerFlags("/wd4996" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) else() mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=deprecated" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=deprecated-declarations" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif() MITK_CREATE_MODULE_TESTS() if(TARGET ${TESTDRIVER}) mitk_use_modules(TARGET ${TESTDRIVER} PACKAGES ITK|ITKThresholding+ITKTestKernel VTK|vtkTestingRendering tinyxml) mitkAddCustomModuleTest(mitkVolumeCalculatorTest_Png2D-bw mitkVolumeCalculatorTest ${MITK_DATA_DIR}/Png2D-bw.png ${MITK_DATA_DIR}/Pic2DplusT.nrrd ) mitkAddCustomModuleTest(mitkEventConfigTest_CreateObjectInDifferentWays mitkEventConfigTest ${MITK_SOURCE_DIR}/Modules/Core/test/resource/Interactions/StatemachineConfigTest.xml ) mitkAddCustomModuleTest(mitkDataStorageTest_US4DCyl mitkDataStorageTest ${MITK_DATA_DIR}/US4DCyl.nrrd ) - mitkAddCustomModuleTest(mitkDicomSeriesReaderTest_CTImage mitkDicomSeriesReaderTest - ${MITK_DATA_DIR}/TinyCTAbdomen - ${MITK_DATA_DIR}/DICOMReader/Broken-Series - ) mitkAddCustomModuleTest(mitkPointSetReaderTest mitkPointSetReaderTest ${MITK_DATA_DIR}/PointSetReaderTestData.mps ) mitkAddCustomModuleTest(mitkImageTest_4DImageData mitkImageTest ${MITK_DATA_DIR}/US4DCyl.nrrd ) mitkAddCustomModuleTest(mitkImageTest_2D+tImageData mitkImageTest ${MITK_DATA_DIR}/Pic2DplusT.nrrd ) mitkAddCustomModuleTest(mitkImageTest_3DImageData mitkImageTest ${MITK_DATA_DIR}/Pic3D.nrrd ) mitkAddCustomModuleTest(mitkImageEqualTest mitkImageEqualTest) mitkAddCustomModuleTest(mitkImageTest_brainImage mitkImageTest ${MITK_DATA_DIR}/brain.mhd ) mitkAddCustomModuleTest(mitkImageTest_3DImageData mitkImageGeneratorTest ${MITK_DATA_DIR}/Pic3D.nrrd ) mitkAddCustomModuleTest(mitkLevelWindowManagerTest mitkLevelWindowManagerTest ${MITK_DATA_DIR}/Pic3D.nrrd ) mitkAddCustomModuleTest(mitkMultiComponentImageDataComparisonFilterTest mitkMultiComponentImageDataComparisonFilterTest ${MITK_DATA_DIR}/NrrdWritingTestImage.jpg ) mitkAddCustomModuleTest(mitkImageToItkTest mitkImageToItkTest ${MITK_DATA_DIR}/Pic3D.nrrd ) mitkAddCustomModuleTest(mitkImageSliceSelectorTest mitkImageSliceSelectorTest ${MITK_DATA_DIR}/Pic2DplusT.nrrd ) mitkAddCustomModuleTest(mitkRotatedSlice4DTest mitkRotatedSlice4DTest ${MITK_DATA_DIR}/UltrasoundImages/4D_TEE_Data_MV.dcm ) if(MITK_ENABLE_RENDERING_TESTING) ### since the rendering test's do not run in ubuntu, yet, we build them only for other systems or if the user explicitly sets the variable MITK_ENABLE_RENDERING_TESTING mitkAddCustomModuleTest(mitkImageVtkMapper2D_rgbaImage640x480 mitkImageVtkMapper2DTest ${MITK_DATA_DIR}/RenderingTestData/rgbaImage.png #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/rgbaImage640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3d640x480 mitkImageVtkMapper2DTest #test for standard Pic3D axial slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3d640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dColorBlue640x480 mitkImageVtkMapper2DColorTest #test for color property (=blue) Pic3D sagittal slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dColorBlue640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dLevelWindow640x480 mitkImageVtkMapper2DLevelWindowTest #test for levelwindow property (=blood) #Pic3D sagittal slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dLevelWindowBlood640x480REF.png #corresponding reference #screenshot ) #mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dOpacity640x480 mitkImageVtkMapper2DOpacityTest #test for opacity (=0.5) Pic3D coronal slice # ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage # -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dOpacity640x480REF.png corresponding reference screenshot #) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dSwivel640x480 mitkImageVtkMapper2DSwivelTest #test for a randomly chosen Pic3D swivelled slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dSwivel640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkPointSetVtkMapper2D_openMeAlone640x480 mitkPointSetVtkMapper2DTest ${MITK_DATA_DIR}/RenderingTestData/openMeAlone.mps #input point set to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/openMeAlone640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkPointSetVtkMapper2D_Pic3DPointSetForPic3D640x480 mitkPointSetVtkMapper2DImageTest ${MITK_DATA_DIR}/Pic3D.nrrd ${MITK_DATA_DIR}/RenderingTestData/PointSetForPic3D.mps #input point set and image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/Pic3DPointSetForPic3D640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkPointSetVtkMapper2D_openMeAloneGlyphType640x480 mitkPointSetVtkMapper2DGlyphTypeTest ${MITK_DATA_DIR}/RenderingTestData/openMeAlone.mps #input point set to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/openMeAloneGlyphType640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkPointSetVtkMapper2D_openMeAloneTransformed640x480 mitkPointSetVtkMapper2DTransformedPointsTest ${MITK_DATA_DIR}/RenderingTestData/openMeAlone.mps #input point set to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/openMeAloneTransformedPoints640x480REF.png #corresponding reference screenshot ) # Currently not working on windows because of a rendering timing issue # see bug 18083 for details if(NOT WIN32) mitkAddCustomModuleTest(mitkSurfaceDepthSortingTransparency_StanfordBunnySTL640x480 mitkSurfaceDepthSortingTest ${MITK_DATA_DIR}/RenderingTestData/Stanford_bunny.stl -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/Stanford_bunnySTLDepthSorting640x480REF.png ) endif() if(NOT APPLE) mitkAddCustomModuleTest(mitkSurfaceDepthPeelingTransparency_StanfordBunnySTL640x480 mitkSurfaceDepthPeelingTest ${MITK_DATA_DIR}/RenderingTestData/Stanford_bunny.stl -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/Stanford_bunnySTLDepthPeeling640x480REF.png #corresponding reference screenshot ) endif() # BUG 18695 - tests deactivated, because win 32 bit continuous renders images slightly different. TODO! #Test reslice interpolation #note: nearest mode is already tested by swivel test #mitkAddCustomModuleTest(ResliceInterpolationIsLinear mitkImageVtkMapper2DResliceInterpolationPropertyTest # 1 #linear # ${MITK_DATA_DIR}/Pic3D.nrrd # -V # ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dRefLinear.png #corresponding reference screenshot LINEAR #) #mitkAddCustomModuleTest(ResliceInterpolationIsCubic mitkImageVtkMapper2DResliceInterpolationPropertyTest # 3 #cubic # ${MITK_DATA_DIR}/Pic3D.nrrd # -V # ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dRefCubic.png #corresponding reference screenshot CUBIC #) #End test reslice interpolation # Testing of the rendering of binary images #mitkAddCustomModuleTest(mitkImageVtkMapper2D_binaryTestImage640x480 mitkImageVtkMapper2DTest #test for standard Pic3D axial slice # ${MITK_DATA_DIR}/RenderingTestData/binaryImage.nrrd #input image to load in data storage # -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/binaryImage640x480REF.png #corresponding reference screenshot #) #mitkAddCustomModuleTest(mitkImageVtkMapper2D_binaryTestImageWithRef640x480 mitkImageVtkMapper2DTest #test for standard Pic3D axial slice # ${MITK_DATA_DIR}/Pic3D.nrrd ${MITK_DATA_DIR}/RenderingTestData/binaryImage.nrrd #input image to load in data storage # -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/binaryImageWithRef640x480REF.png #corresponding reference screenshot #) # End of binary image tests mitkAddCustomModuleTest(mitkSurfaceVtkMapper3DTest_TextureProperty mitkSurfaceVtkMapper3DTest ${MITK_DATA_DIR}/ToF-Data/Kinect_LiverPhantom.vtp ${MITK_DATA_DIR}/ToF-Data/Kinect_LiverPhantom_RGBImage.nrrd -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/texturedLiver640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2DTransferFunctionTest_Png2D-bw mitkImageVtkMapper2DTransferFunctionTest ${MITK_DATA_DIR}/Png2D-bw.png -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/Png2D-bw-TransferFunctionRGBImage640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2DOpacityTransferFunctionTest_Png2D-bw mitkImageVtkMapper2DOpacityTransferFunctionTest ${MITK_DATA_DIR}/Png2D-bw.png -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/Png2D-bw-OpacityTransferFunctionRGBImage640x480REF.png #corresponding reference screenshot ) ############################## DISABLED TESTS #Removed due to high rendering error. #mitkAddCustomModuleTest(mitkSurfaceVtkMapper3DTexturedSphereTest_Football mitkSurfaceVtkMapper3DTexturedSphereTest # ${MITK_DATA_DIR}/RenderingTestData/texture.jpg #input texture # -V # ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/texturedSphere640x480REF.png corresponding reference screenshot #) mitkAddCustomModuleTest(mitkImageVtkMapper2DLookupTableTest_Png2D-bw mitkImageVtkMapper2DLookupTableTest ${MITK_DATA_DIR}/Png2D-bw.png -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/Png2D-bw-LookupTableRGBImage640x480REF.png #corresponding reference screenshot ) #mitkAddCustomModuleTest(mitkImageTest_color2DImage mitkImageTest # ${MITK_DATA_DIR}/NrrdWritingTestImage.jpg #) #mitkAddCustomModuleTest(mitkNodeDependentPointSetInteractorTest mitkNodeDependentPointSetInteractorTest # ${MITK_DATA_DIR}/Pic3D.pic.gz ${MITK_DATA_DIR}/BallBinary30x30x30.pic.gz #) mitkAddCustomModuleTest(mitkPlaneGeometryDataMapper2DTest mitkPlaneGeometryDataMapper2DTest ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/PlaneGeometryMapper640x480REF.png #corresponding reference screenshot ) SET_PROPERTY(TEST mitkRotatedSlice4DTest mitkImageVtkMapper2D_rgbaImage640x480 mitkImageVtkMapper2D_pic3d640x480 mitkImageVtkMapper2D_pic3dColorBlue640x480 mitkImageVtkMapper2D_pic3dLevelWindow640x480 mitkImageVtkMapper2D_pic3dSwivel640x480 mitkImageVtkMapper2DTransferFunctionTest_Png2D-bw # mitkImageVtkMapper2D_pic3dOpacity640x480 mitkSurfaceVtkMapper2DTest mitkSurfaceVtkMapper3DTest_TextureProperty mitkPointSetVtkMapper2D_Pic3DPointSetForPic3D640x480 mitkPointSetVtkMapper2D_openMeAlone640x480 mitkPointSetVtkMapper2D_openMeAloneGlyphType640x480 mitkPointSetVtkMapper2D_openMeAloneTransformed640x480 #mitkSurfaceVtkMapper3DTexturedSphereTest_Football mitkPlaneGeometryDataMapper2DTest PROPERTY RUN_SERIAL TRUE) endif() endif() # TARGET ${TESTDRIVER} diff --git a/Modules/Core/test/files.cmake b/Modules/Core/test/files.cmake index 6021517f59..5ba1088eeb 100644 --- a/Modules/Core/test/files.cmake +++ b/Modules/Core/test/files.cmake @@ -1,204 +1,202 @@ # tests with no extra command line parameter set(MODULE_TESTS # IMPORTANT: If you plan to deactivate / comment out a test please write a bug number to the commented out line of code. # # Example: #mitkMyTest #this test is commented out because of bug 12345 # # It is important that the bug is open and that the test will be activated again before the bug is closed. This assures that # no test is forgotten after it was commented out. If there is no bug for your current problem, please add a new one and # mark it as critical. ################## DISABLED TESTS ################################################# #mitkAbstractTransformGeometryTest.cpp #seems as tested class mitkExternAbstractTransformGeometry doesnt exist any more #mitkStateMachineContainerTest.cpp #rewrite test, indirect since no longer exported Bug 14529 #mitkRegistrationBaseTest.cpp #tested class mitkRegistrationBase doesn't exist any more #mitkSegmentationInterpolationTest.cpp #file doesn't exist! #mitkPipelineSmartPointerCorrectnessTest.cpp #file doesn't exist! #mitkITKThreadingTest.cpp #test outdated because itk::Semaphore was removed from ITK #mitkAbstractTransformPlaneGeometryTest.cpp #mitkVtkAbstractTransformPlaneGeometry doesn't exist any more #mitkTestUtilSharedLibrary.cpp #Linker problem with this test... #mitkTextOverlay2DSymbolsRenderingTest.cpp #Implementation of the tested feature is not finished yet. Ask Christoph or see bug 15104 for details. ################# RUNNING TESTS ################################################### mitkAccessByItkTest.cpp mitkCoreObjectFactoryTest.cpp mitkDataNodeTest.cpp mitkMaterialTest.cpp mitkActionTest.cpp mitkDispatcherTest.cpp mitkEnumerationPropertyTest.cpp mitkFileReaderRegistryTest.cpp #mitkFileWriterRegistryTest.cpp mitkFloatToStringTest.cpp mitkGenericPropertyTest.cpp mitkGeometry3DTest.cpp mitkGeometry3DEqualTest.cpp mitkGeometryDataIOTest.cpp mitkGeometryDataToSurfaceFilterTest.cpp mitkImageCastTest.cpp mitkImageEqualTest.cpp mitkImageDataItemTest.cpp mitkImageGeneratorTest.cpp mitkIOUtilTest.cpp mitkBaseDataTest.cpp mitkImportItkImageTest.cpp mitkGrabItkImageMemoryTest.cpp mitkInstantiateAccessFunctionTest.cpp mitkLevelWindowTest.cpp mitkMessageTest.cpp mitkPixelTypeTest.cpp mitkPlaneGeometryTest.cpp mitkPointSetTest.cpp mitkPointSetEqualTest.cpp mitkPointSetFileIOTest.cpp mitkPointSetOnEmptyTest.cpp mitkPointSetLocaleTest.cpp mitkPointSetWriterTest.cpp mitkPointSetReaderTest.cpp mitkPointSetPointOperationsTest.cpp mitkProgressBarTest.cpp mitkPropertyTest.cpp mitkPropertyListTest.cpp mitkPropertyPersistenceTest.cpp mitkPropertyPersistenceInfoTest.cpp mitkPropertyRelationRuleBaseTest.cpp mitkPropertyRelationsTest.cpp mitkSlicedGeometry3DTest.cpp mitkSliceNavigationControllerTest.cpp mitkSurfaceTest.cpp mitkSurfaceEqualTest.cpp mitkSurfaceToSurfaceFilterTest.cpp mitkTimeGeometryTest.cpp mitkProportionalTimeGeometryTest.cpp mitkUndoControllerTest.cpp mitkVtkWidgetRenderingTest.cpp mitkVerboseLimitedLinearUndoTest.cpp mitkWeakPointerTest.cpp mitkTransferFunctionTest.cpp mitkStepperTest.cpp mitkRenderingManagerTest.cpp mitkCompositePixelValueToStringTest.cpp vtkMitkThickSlicesFilterTest.cpp mitkNodePredicateSourceTest.cpp mitkNodePredicateDataPropertyTest.cpp mitkNodePredicateFunctionTest.cpp mitkVectorTest.cpp mitkClippedSurfaceBoundsCalculatorTest.cpp mitkExceptionTest.cpp mitkExtractSliceFilterTest.cpp mitkLogTest.cpp mitkImageDimensionConverterTest.cpp mitkLoggingAdapterTest.cpp mitkUIDGeneratorTest.cpp mitkPlanePositionManagerTest.cpp mitkAffineTransformBaseTest.cpp mitkPropertyAliasesTest.cpp mitkPropertyDescriptionsTest.cpp mitkPropertyExtensionsTest.cpp mitkPropertyFiltersTest.cpp mitkPropertyKeyPathTest.cpp mitkTinyXMLTest.cpp mitkRawImageFileReaderTest.cpp mitkInteractionEventTest.cpp mitkLookupTableTest.cpp mitkSTLFileReaderTest.cpp mitkPointTypeConversionTest.cpp mitkVectorTypeConversionTest.cpp mitkMatrixTypeConversionTest.cpp mitkArrayTypeConversionTest.cpp mitkSurfaceToImageFilterTest.cpp mitkBaseGeometryTest.cpp mitkImageToSurfaceFilterTest.cpp mitkEqualTest.cpp mitkLineTest.cpp mitkArbitraryTimeGeometryTest mitkItkImageIOTest.cpp mitkRotatedSlice4DTest.cpp mitkLevelWindowManagerCppUnitTest.cpp mitkVectorPropertyTest.cpp mitkTemporoSpatialStringPropertyTest.cpp mitkPropertyNameHelperTest.cpp mitkNodePredicateGeometryTest.cpp mitkPreferenceListReaderOptionsFunctorTest.cpp mitkGenericIDRelationRuleTest.cpp ) if(MITK_ENABLE_RENDERING_TESTING) set(MODULE_TESTS ${MODULE_TESTS} mitkPlaneGeometryDataMapper2DTest.cpp mitkPointSetDataInteractorTest.cpp #since mitkInteractionTestHelper is currently creating a vtkRenderWindow mitkSurfaceVtkMapper2DTest.cpp #new rendering test in CppUnit style mitkSurfaceVtkMapper2D3DTest.cpp # comparisons/consistency 2D/3D ) endif() # test with image filename as an extra command line parameter set(MODULE_IMAGE_TESTS mitkImageTimeSelectorTest.cpp #only runs on images mitkImageAccessorTest.cpp #only runs on images ) set(MODULE_SURFACE_TESTS mitkSurfaceVtkWriterTest.cpp #only runs on surfaces ) # list of images for which the tests are run set(MODULE_TESTIMAGE US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd Png2D-bw.png ) set(MODULE_TESTSURFACE binary.stl ball.stl ) set(MODULE_CUSTOM_TESTS mitkDataStorageTest.cpp - mitkDicomSeriesReaderTest.cpp - mitkDICOMLocaleTest.cpp mitkDataNodeTest.cpp mitkEventConfigTest.cpp mitkPointSetLocaleTest.cpp mitkImageTest.cpp mitkImageVtkMapper2DTest.cpp mitkImageVtkMapper2DLevelWindowTest.cpp mitkImageVtkMapper2DOpacityTest.cpp mitkImageVtkMapper2DResliceInterpolationPropertyTest.cpp mitkImageVtkMapper2DColorTest.cpp mitkImageVtkMapper2DSwivelTest.cpp mitkImageVtkMapper2DTransferFunctionTest.cpp mitkImageVtkMapper2DOpacityTransferFunctionTest.cpp mitkImageVtkMapper2DLookupTableTest.cpp mitkSurfaceVtkMapper3DTest mitkSurfaceVtkMapper3DTexturedSphereTest.cpp mitkVolumeCalculatorTest.cpp mitkLevelWindowManagerTest.cpp mitkPointSetVtkMapper2DTest.cpp mitkPointSetVtkMapper2DImageTest.cpp mitkPointSetVtkMapper2DGlyphTypeTest.cpp mitkPointSetVtkMapper2DTransformedPointsTest.cpp mitkVTKRenderWindowSizeTest.cpp mitkMultiComponentImageDataComparisonFilterTest.cpp mitkImageToItkTest.cpp mitkImageSliceSelectorTest.cpp mitkSurfaceDepthPeelingTest.cpp ) # Currently not working on windows because of a rendering timing issue # see bug 18083 for details if(NOT WIN32) set(MODULE_CUSTOM_TESTS ${MODULE_CUSTOM_TESTS} mitkSurfaceDepthSortingTest.cpp) endif() set(RESOURCE_FILES Interactions/AddAndRemovePoints.xml Interactions/globalConfig.xml Interactions/StatemachineTest.xml Interactions/StatemachineConfigTest.xml ) diff --git a/Modules/Core/test/mitkDICOMLocaleTest.cpp b/Modules/Core/test/mitkDICOMLocaleTest.cpp deleted file mode 100644 index 3d4a1fc4e4..0000000000 --- a/Modules/Core/test/mitkDICOMLocaleTest.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -/* - This test is meant to reproduce the following error: - - - The machine or current user has a German locale. - - This esp. means that stream IO expects the decimal separator as a comma: "," - - DICOM files use a point "." as the decimal separator to be locale independent - - The parser used by MITK (ITK's GDCM) seems to use the current locale instead of the "C" or "POSIX" locale - - This leads to spacings (and probably other numbers) being trimmed/rounded, - e.g. the correct spacing of 0.314 is read as 1.0 etc. - -*/ - -#include "mitkDicomSeriesReader.h" -#include "mitkIOUtil.h" -#include "mitkImage.h" -#include "mitkStandardFileLocations.h" - -#include "mitkTestFixture.h" -#include "mitkTestingMacros.h" - -#include -#include -#include - -class mitkDICOMLocaleTestSuite : public mitk::TestFixture -{ - CPPUNIT_TEST_SUITE(mitkDICOMLocaleTestSuite); - CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS(addDICOMLocaleWithReferenceImageTests); - CPPUNIT_TEST_SUITE_END(); - -private: - // A custom method for adding a combination of filename and locale tests - static void addDICOMLocaleWithReferenceImageTests(TestSuiteBuilderContextType &context) - { - std::vector fileArgs; - fileArgs.push_back("spacing-ok-ct.dcm"); - fileArgs.push_back("spacing-ok-mr.dcm"); - fileArgs.push_back("spacing-ok-sc.dcm"); - - // load a reference DICOM file with German locales being set - std::vector localeArgs; - localeArgs.push_back("C"); - localeArgs.push_back("de_DE"); - localeArgs.push_back("de_DE.utf8"); - localeArgs.push_back("de_DE.UTF8"); - localeArgs.push_back("de_DE@euro"); - localeArgs.push_back("German_Germany"); - - for (std::size_t fileIndex = 0; fileIndex < fileArgs.size(); ++fileIndex) - { - for (std::size_t localeIndex = 0; localeIndex < localeArgs.size(); ++localeIndex) - { - MITK_PARAMETERIZED_TEST_2(testLocaleWithReferenceImage, fileArgs[fileIndex], localeArgs[localeIndex]); - } - } - } - -private: - std::string m_FileName; - std::string m_Locale; - char *m_OldLocale; - bool m_SkipImageTest; - - void SetTestParameter() - { - std::vector parameter = GetTestParameter(); - CPPUNIT_ASSERT(parameter.size() == 2); - m_FileName = GetTestDataFilePath(parameter[0]); - m_Locale = parameter[1]; - } - -public: - mitkDICOMLocaleTestSuite() : m_OldLocale(nullptr), m_SkipImageTest(false) {} - // Change the current locale to m_Locale - void setUp() override - { - m_SkipImageTest = false; - m_OldLocale = nullptr; - SetTestParameter(); - - try - { - m_OldLocale = setlocale(LC_ALL, nullptr); - MITK_TEST_OUTPUT(<< " ** Changing locale from " << m_OldLocale << " to '" << m_Locale << "'") - setlocale(LC_ALL, m_Locale.c_str()); - std::cin.imbue(std::locale(m_Locale.c_str())); - } - catch (...) - { - MITK_TEST_OUTPUT(<< "Could not activate locale " << m_Locale) - m_SkipImageTest = true; - } - } - - void tearDown() override - { - if (m_OldLocale) - { - setlocale(LC_ALL, m_OldLocale); - std::cin.imbue(std::locale(m_OldLocale)); - } - } - - void testLocaleWithReferenceImage() - { - if (m_SkipImageTest) - return; - - mitk::Image::Pointer image = dynamic_cast(mitk::IOUtil::Load(m_FileName)[0].GetPointer()); - CPPUNIT_ASSERT(image.IsNotNull()); - - // note importance of minor differences in spacings: - // DICOM has order y-spacing, x-spacing, while in MITK we assume x-spacing, y-spacing (both meant for 0 and 1 index - // in array) - CPPUNIT_ASSERT_MESSAGE("incorrect x spacing", mitk::Equal(image->GetGeometry()->GetSpacing()[0], 0.3141592)); - CPPUNIT_ASSERT_MESSAGE("incorrect y spacing ", mitk::Equal(image->GetGeometry()->GetSpacing()[1], 0.3411592)); - } -}; - -MITK_TEST_SUITE_REGISTRATION(mitkDICOMLocale) diff --git a/Modules/Core/test/mitkDicomSeriesReaderTest.cpp b/Modules/Core/test/mitkDicomSeriesReaderTest.cpp deleted file mode 100644 index 1e33d95313..0000000000 --- a/Modules/Core/test/mitkDicomSeriesReaderTest.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#include "mitkTestingMacros.h" - -#include - -#include "mitkDicomSeriesReader.h" -#include "mitkImage.h" -#include "mitkProperties.h" - -static std::map> GetTagInformationFromFile( - mitk::DicomSeriesReader::StringContainer files) -{ - gdcm::Scanner scanner; - std::map> tagInformations; - - const gdcm::Tag tagSliceLocation(0x0020, 0x1041); // slice location - scanner.AddTag(tagSliceLocation); - - const gdcm::Tag tagInstanceNumber(0x0020, 0x0013); // (image) instance number - scanner.AddTag(tagInstanceNumber); - - const gdcm::Tag tagSOPInstanceNumber(0x0008, 0x0018); // SOP instance number - scanner.AddTag(tagSOPInstanceNumber); - - // unsigned int slice(0); - scanner.Scan(files); - - // return const_cast(scanner.GetMappings()); - auto &tagValueMappings = const_cast(scanner.GetMappings()); - - for (std::vector::const_iterator fIter = files.begin(); fIter != files.end(); ++fIter) - { - std::map tags; - tags.insert( - std::pair(tagSliceLocation, tagValueMappings[fIter->c_str()][tagSliceLocation])); - tags.insert( - std::pair(tagInstanceNumber, tagValueMappings[fIter->c_str()][tagInstanceNumber])); - tags.insert( - std::pair(tagSOPInstanceNumber, tagValueMappings[fIter->c_str()][tagSOPInstanceNumber])); - - tagInformations.insert(std::pair>(fIter->c_str(), tags)); - } - - return tagInformations; -} - -int mitkDicomSeriesReaderTest(int argc, char *argv[]) -{ - // always start with this! - MITK_TEST_BEGIN("DicomSeriesReader") - if (argc < 1) - { - MITK_ERROR << "No directory given!"; - return -1; - } - - char *dir; - dir = argv[1]; - - // check if DICOMTags have been set as property for mitk::Image - mitk::DicomSeriesReader::FileNamesGrouping seriesInFiles = mitk::DicomSeriesReader::GetSeries(dir, true); - std::list images; - std::map fileMap; - - // TODO sort series UIDs, implementation of map iterator might differ on different platforms (or verify this is a - // standard topic??) - for (mitk::DicomSeriesReader::FileNamesGrouping::const_iterator seriesIter = seriesInFiles.begin(); - seriesIter != seriesInFiles.end(); - ++seriesIter) - { - mitk::DicomSeriesReader::StringContainer files = seriesIter->second.GetFilenames(); - - mitk::DataNode::Pointer node = mitk::DicomSeriesReader::LoadDicomSeries(files); - MITK_TEST_CONDITION_REQUIRED(node.IsNotNull(), "Testing node") - - if (node.IsNotNull()) - { - mitk::Image::Pointer image = dynamic_cast(node->GetData()); - - images.push_back(image); - fileMap.insert(std::pair(image, files)); - } - } - - // Test if DICOM tags have been added correctly to the mitk::image properties - - const gdcm::Tag tagSliceLocation(0x0020, 0x1041); // slice location - const gdcm::Tag tagInstanceNumber(0x0020, 0x0013); // (image) instance number - const gdcm::Tag tagSOPInstanceNumber(0x0008, 0x0018); // SOP instance number - - for (std::list::const_iterator imageIter = images.begin(); imageIter != images.end(); - ++imageIter) - { - const mitk::Image::Pointer image = *imageIter; - - // Get tag information for all dicom files of this image - std::map> tagInformations = - GetTagInformationFromFile((*fileMap.find(image)).second); - - mitk::StringLookupTableProperty *sliceLocation = - dynamic_cast(image->GetProperty("dicom.image.0020.1041").GetPointer()); - mitk::StringLookupTableProperty *instanceNumber = - dynamic_cast(image->GetProperty("dicom.image.0020.0013").GetPointer()); - mitk::StringLookupTableProperty *SOPInstnaceNumber = - dynamic_cast(image->GetProperty("dicom.image.0008.0018").GetPointer()); - - mitk::StringLookupTableProperty *files = - dynamic_cast(image->GetProperty("files").GetPointer()); - - MITK_TEST_CONDITION(sliceLocation != nullptr, "Test if tag for slice location has been set to mitk image"); - if (sliceLocation != nullptr) - { - for (int i = 0; i < (int)sliceLocation->GetValue().GetLookupTable().size(); i++) - { - if (i < (int)files->GetValue().GetLookupTable().size()) - { - MITK_INFO << "Table value: " << sliceLocation->GetValue().GetTableValue(i) << " and File value: " - << tagInformations[files->GetValue().GetTableValue(i).c_str()][tagSliceLocation] << std::endl; - MITK_INFO << "Filename: " << files->GetValue().GetTableValue(i).c_str() << std::endl; - MITK_TEST_CONDITION(sliceLocation->GetValue().GetTableValue(i) == - tagInformations[files->GetValue().GetTableValue(i).c_str()][tagSliceLocation], - "Test if value for slice location is correct"); - } - } - } - - MITK_TEST_CONDITION(instanceNumber != nullptr, "Test if tag for image instance number has been set to mitk image"); - if (instanceNumber != nullptr) - { - for (int i = 0; i < (int)instanceNumber->GetValue().GetLookupTable().size(); i++) - { - if (i < (int)files->GetValue().GetLookupTable().size()) - { - MITK_INFO << "Table value: " << instanceNumber->GetValue().GetTableValue(i) << " and File value: " - << tagInformations[files->GetValue().GetTableValue(i).c_str()][tagInstanceNumber] << std::endl; - MITK_INFO << "Filename: " << files->GetValue().GetTableValue(i).c_str() << std::endl; - MITK_TEST_CONDITION(instanceNumber->GetValue().GetTableValue(i) == - tagInformations[files->GetValue().GetTableValue(i).c_str()][tagInstanceNumber], - "Test if value for instance number is correct"); - } - } - } - - MITK_TEST_CONDITION(SOPInstnaceNumber != nullptr, "Test if tag for SOP instance number has been set to mitk image"); - if (SOPInstnaceNumber != nullptr) - { - for (int i = 0; i < (int)SOPInstnaceNumber->GetValue().GetLookupTable().size(); i++) - { - if (i < (int)files->GetValue().GetLookupTable().size()) - { - MITK_INFO << "Table value: " << instanceNumber->GetValue().GetTableValue(i) << " and File value: " - << tagInformations[files->GetValue().GetTableValue(i).c_str()][tagSOPInstanceNumber] << std::endl; - MITK_INFO << "Filename: " << files->GetValue().GetTableValue(i).c_str() << std::endl; - MITK_TEST_CONDITION(SOPInstnaceNumber->GetValue().GetTableValue(i) == - tagInformations[files->GetValue().GetTableValue(i).c_str()][tagSOPInstanceNumber], - "Test if value for SOP instance number is correct"); - } - } - } - } - - MITK_TEST_END() -} diff --git a/Modules/DICOMReader/CMakeLists.txt b/Modules/DICOMReader/CMakeLists.txt index 33be4a169f..4a1cff1322 100644 --- a/Modules/DICOMReader/CMakeLists.txt +++ b/Modules/DICOMReader/CMakeLists.txt @@ -1,8 +1,8 @@ MITK_CREATE_MODULE( DEPENDS MitkCore PACKAGE_DEPENDS - PUBLIC tinyxml + PUBLIC tinyxml GDCM PRIVATE ITK|ITKIOImageBase+ITKIOGDCM DCMTK ) add_subdirectory(test) diff --git a/Modules/DICOMReader/files.cmake b/Modules/DICOMReader/files.cmake index c64c804da2..e72f2b58c1 100644 --- a/Modules/DICOMReader/files.cmake +++ b/Modules/DICOMReader/files.cmake @@ -1,54 +1,62 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES mitkBaseDICOMReaderService.cpp mitkDICOMFileReader.cpp mitkDICOMTagScanner.cpp mitkDICOMGDCMTagScanner.cpp mitkDICOMDCMTKTagScanner.cpp mitkDICOMImageBlockDescriptor.cpp mitkDICOMITKSeriesGDCMReader.cpp mitkDICOMDatasetSorter.cpp mitkDICOMTagBasedSorter.cpp mitkDICOMGDCMImageFrameInfo.cpp mitkDICOMImageFrameInfo.cpp mitkDICOMIOHelper.cpp mitkDICOMGenericImageFrameInfo.cpp mitkDICOMDatasetAccessingImageFrameInfo.cpp mitkDICOMSortCriterion.cpp mitkDICOMSortByTag.cpp mitkITKDICOMSeriesReaderHelper.cpp mitkEquiDistantBlocksSorter.cpp mitkNormalDirectionConsistencySorter.cpp mitkSortByImagePositionPatient.cpp mitkGantryTiltInformation.cpp mitkClassicDICOMSeriesReader.cpp mitkThreeDnTDICOMSeriesReader.cpp mitkDICOMTag.cpp mitkDICOMTagsOfInterestHelper.cpp mitkDICOMTagCache.cpp mitkDICOMGDCMTagCache.cpp mitkDICOMGenericTagCache.cpp mitkDICOMEnums.cpp mitkDICOMReaderConfigurator.cpp mitkDICOMFileReaderSelector.cpp mitkIDICOMTagsOfInterest.cpp mitkDICOMTagPath.cpp mitkDICOMProperty.cpp mitkDICOMFilesHelper.cpp + legacy/mitkDicomSeriesReader.cpp + legacy/mitkDicomSR_GantryTiltInformation.cpp + legacy/mitkDicomSR_ImageBlockDescriptor.cpp + legacy/mitkDicomSR_LoadDICOMRGBPixel.cpp + legacy/mitkDicomSR_LoadDICOMRGBPixel4D.cpp + legacy/mitkDicomSR_LoadDICOMScalar.cpp + legacy/mitkDicomSR_LoadDICOMScalar4D.cpp + legacy/mitkDicomSR_SliceGroupingResult.cpp ) set(RESOURCE_FILES configurations/3D/classicreader.xml configurations/3D/imageposition.xml configurations/3D/imageposition_byacquisition.xml configurations/3D/instancenumber.xml configurations/3D/instancenumber_soft.xml configurations/3D/slicelocation.xml configurations/3D/simpleinstancenumber_soft.xml configurations/3DnT/classicreader.xml configurations/3DnT/imageposition.xml configurations/3DnT/imageposition_byacquisition.xml configurations/3DnT/imageposition_bytriggertime.xml ) diff --git a/Modules/Core/src/IO/mitkDicomSR_GantryTiltInformation.cpp b/Modules/DICOMReader/src/legacy/mitkDicomSR_GantryTiltInformation.cpp similarity index 99% rename from Modules/Core/src/IO/mitkDicomSR_GantryTiltInformation.cpp rename to Modules/DICOMReader/src/legacy/mitkDicomSR_GantryTiltInformation.cpp index c8cd3ee4ac..29d6c1fd75 100644 --- a/Modules/Core/src/IO/mitkDicomSR_GantryTiltInformation.cpp +++ b/Modules/DICOMReader/src/legacy/mitkDicomSR_GantryTiltInformation.cpp @@ -1,170 +1,170 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include +#include namespace mitk { DicomSeriesReader::GantryTiltInformation::GantryTiltInformation() : m_ShiftUp(0.0), m_ShiftRight(0.0), m_ShiftNormal(0.0), m_ITKAssumedSliceSpacing(0.0), m_NumberOfSlicesApart(1) { } #define doublepoint(x) \ Point3Dd x; \ x[0] = x##f[0]; \ x[1] = x##f[1]; \ x[2] = x##f[2]; #define doublevector(x) \ Vector3Dd x; \ x[0] = x##f[0]; \ x[1] = x##f[1]; \ x[2] = x##f[2]; DicomSeriesReader::GantryTiltInformation::GantryTiltInformation(const Point3D &origin1f, const Point3D &origin2f, const Vector3D &rightf, const Vector3D &upf, unsigned int numberOfSlicesApart) : m_ShiftUp(0.0), m_ShiftRight(0.0), m_ShiftNormal(0.0), m_NumberOfSlicesApart(numberOfSlicesApart) { assert(numberOfSlicesApart); doublepoint(origin1); doublepoint(origin2); doublevector(right); doublevector(up); // determine if slice 1 (imagePosition1 and imageOrientation1) and slice 2 can be in one orthogonal slice stack: // calculate a line from origin 1, directed along the normal of slice (calculated as the cross product of // orientation // 1) // check if this line passes through origin 2 /* Determine if line (imagePosition2 + l * normal) contains imagePosition1. Done by calculating the distance of imagePosition1 from line (imagePosition2 + l *normal) E.g. http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html squared distance = | (pointAlongNormal - origin2) x (origin2 - origin1) | ^ 2 / |pointAlongNormal - origin2| ^ 2 ( x meaning the cross product ) */ Vector3Dd normal = itk::CrossProduct(right, up); Point3Dd pointAlongNormal = origin2 + normal; double numerator = itk::CrossProduct(pointAlongNormal - origin2, origin2 - origin1).GetSquaredNorm(); double denominator = (pointAlongNormal - origin2).GetSquaredNorm(); double distance = sqrt(numerator / denominator); if (distance > 0.001) // mitk::eps is too small; 1/1000 of a mm should be enough to detect tilt { MITK_DEBUG << " Series seems to contain a tilted (or sheared) geometry"; MITK_DEBUG << " Distance of expected slice origin from actual slice origin: " << distance; MITK_DEBUG << " ==> storing this shift for later analysis:"; MITK_DEBUG << " v right: " << right; MITK_DEBUG << " v up: " << up; MITK_DEBUG << " v normal: " << normal; Point3Dd projectionRight = projectPointOnLine(origin1, origin2, right); Point3Dd projectionNormal = projectPointOnLine(origin1, origin2, normal); m_ShiftRight = (projectionRight - origin2).GetNorm(); m_ShiftNormal = (projectionNormal - origin2).GetNorm(); /* now also check to which side the image is shifted. Calculation e.g. from http://mathworld.wolfram.com/Point-PlaneDistance.html */ Point3Dd testPoint = origin1; Vector3Dd planeNormal = up; double signedDistance = (planeNormal[0] * testPoint[0] + planeNormal[1] * testPoint[1] + planeNormal[2] * testPoint[2] - (planeNormal[0] * origin2[0] + planeNormal[1] * origin2[1] + planeNormal[2] * origin2[2])) / sqrt(planeNormal[0] * planeNormal[0] + planeNormal[1] * planeNormal[1] + planeNormal[2] * planeNormal[2]); m_ShiftUp = signedDistance; m_ITKAssumedSliceSpacing = (origin2 - origin1).GetNorm(); // How do we now this is assumed? See header documentation for ITK code references // double itkAssumedSliceSpacing = sqrt( m_ShiftUp * m_ShiftUp + m_ShiftNormal * m_ShiftNormal ); MITK_DEBUG << " shift normal: " << m_ShiftNormal; MITK_DEBUG << " shift normal assumed by ITK: " << m_ITKAssumedSliceSpacing; MITK_DEBUG << " shift up: " << m_ShiftUp; MITK_DEBUG << " shift right: " << m_ShiftRight; MITK_DEBUG << " tilt angle (deg): " << atan(m_ShiftUp / m_ShiftNormal) * 180.0 / 3.1415926535; } } Point3D DicomSeriesReader::GantryTiltInformation::projectPointOnLine(Point3Dd p, Point3Dd lineOrigin, Vector3Dd lineDirection) { /** See illustration at http://mo.mathematik.uni-stuttgart.de/inhalt/aussage/aussage472/ vector(lineOrigin,p) = normal * ( innerproduct((p - lineOrigin),normal) / squared-length(normal) ) */ Vector3Dd lineOriginToP = p - lineOrigin; double innerProduct = lineOriginToP * lineDirection; double factor = innerProduct / lineDirection.GetSquaredNorm(); Point3Dd projection = lineOrigin + factor * lineDirection; return projection; } double DicomSeriesReader::GantryTiltInformation::GetTiltCorrectedAdditionalSize() const { return fabs(m_ShiftUp); } double DicomSeriesReader::GantryTiltInformation::GetTiltAngleInDegrees() const { return atan(fabs(m_ShiftUp) / m_ShiftNormal) * 180.0 / 3.1415926535; } double DicomSeriesReader::GantryTiltInformation::GetMatrixCoefficientForCorrectionInWorldCoordinates() const { // so many mm need to be shifted per slice! return m_ShiftUp / static_cast(m_NumberOfSlicesApart); } double DicomSeriesReader::GantryTiltInformation::GetRealZSpacing() const { return m_ShiftNormal / static_cast(m_NumberOfSlicesApart); } bool DicomSeriesReader::GantryTiltInformation::IsSheared() const { return (fabs(m_ShiftRight) > 0.001 || fabs(m_ShiftUp) > 0.001); } bool DicomSeriesReader::GantryTiltInformation::IsRegularGantryTilt() const { return (fabs(m_ShiftRight) < 0.001 && fabs(m_ShiftUp) > 0.001); } } // end namespace mitk diff --git a/Modules/Core/src/IO/mitkDicomSR_ImageBlockDescriptor.cpp b/Modules/DICOMReader/src/legacy/mitkDicomSR_ImageBlockDescriptor.cpp similarity index 99% rename from Modules/Core/src/IO/mitkDicomSR_ImageBlockDescriptor.cpp rename to Modules/DICOMReader/src/legacy/mitkDicomSR_ImageBlockDescriptor.cpp index 0f0abc5a47..6ef0bf1d74 100644 --- a/Modules/Core/src/IO/mitkDicomSR_ImageBlockDescriptor.cpp +++ b/Modules/DICOMReader/src/legacy/mitkDicomSR_ImageBlockDescriptor.cpp @@ -1,197 +1,197 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include +#include #include namespace mitk { DicomSeriesReader::ImageBlockDescriptor::ImageBlockDescriptor() : m_HasGantryTiltCorrected(false), m_HasMultipleTimePoints(false), m_IsMultiFrameImage(false) { } DicomSeriesReader::ImageBlockDescriptor::~ImageBlockDescriptor() { // nothing } DicomSeriesReader::ImageBlockDescriptor::ImageBlockDescriptor(const StringContainer &files) : m_HasGantryTiltCorrected(false), m_HasMultipleTimePoints(false), m_IsMultiFrameImage(false) { m_Filenames = files; } void DicomSeriesReader::ImageBlockDescriptor::AddFile(const std::string &filename) { m_Filenames.push_back(filename); } void DicomSeriesReader::ImageBlockDescriptor::AddFiles(const StringContainer &files) { m_Filenames.insert(m_Filenames.end(), files.begin(), files.end()); } DicomSeriesReader::StringContainer DicomSeriesReader::ImageBlockDescriptor::GetFilenames() const { return m_Filenames; } std::string DicomSeriesReader::ImageBlockDescriptor::GetImageBlockUID() const { return m_ImageBlockUID; } std::string DicomSeriesReader::ImageBlockDescriptor::GetSeriesInstanceUID() const { return m_SeriesInstanceUID; } std::string DicomSeriesReader::ImageBlockDescriptor::GetModality() const { return m_Modality; } std::string DicomSeriesReader::ImageBlockDescriptor::GetSOPClassUIDAsString() const { gdcm::UIDs uidKnowledge; uidKnowledge.SetFromUID(m_SOPClassUID.c_str()); return uidKnowledge.GetName(); } std::string DicomSeriesReader::ImageBlockDescriptor::GetSOPClassUID() const { return m_SOPClassUID; } bool DicomSeriesReader::ImageBlockDescriptor::IsMultiFrameImage() const { return m_IsMultiFrameImage; } DicomSeriesReader::ReaderImplementationLevel DicomSeriesReader::ImageBlockDescriptor::GetReaderImplementationLevel() const { if (this->IsMultiFrameImage()) return ReaderImplementationLevel_Unsupported; gdcm::UIDs uidKnowledge; uidKnowledge.SetFromUID(m_SOPClassUID.c_str()); gdcm::UIDs::TSType uid = uidKnowledge; switch (uid) { case gdcm::UIDs::CTImageStorage: case gdcm::UIDs::MRImageStorage: case gdcm::UIDs::PositronEmissionTomographyImageStorage: case gdcm::UIDs::ComputedRadiographyImageStorage: case gdcm::UIDs::DigitalXRayImageStorageForPresentation: case gdcm::UIDs::DigitalXRayImageStorageForProcessing: return ReaderImplementationLevel_Supported; case gdcm::UIDs::NuclearMedicineImageStorage: return ReaderImplementationLevel_PartlySupported; case gdcm::UIDs::SecondaryCaptureImageStorage: return ReaderImplementationLevel_Implemented; default: return ReaderImplementationLevel_Unsupported; } } bool DicomSeriesReader::ImageBlockDescriptor::HasGantryTiltCorrected() const { return m_HasGantryTiltCorrected; } /* PS defined IPS defined PS==IPS 0 0 --> UNKNOWN spacing, loader will invent 0 1 --> spacing as at detector surface 1 0 --> spacing as in patient 1 1 0 --> detector surface spacing CORRECTED for geometrical magnifications: spacing as in patient 1 1 1 --> detector surface spacing NOT corrected for geometrical magnifications: spacing as at detector */ DicomSeriesReader::PixelSpacingInterpretation DicomSeriesReader::ImageBlockDescriptor::GetPixelSpacingType() const { if (m_PixelSpacing.empty()) { if (m_ImagerPixelSpacing.empty()) { return PixelSpacingInterpretation_SpacingUnknown; } else { return PixelSpacingInterpretation_SpacingAtDetector; } } else // Pixel Spacing defined { if (m_ImagerPixelSpacing.empty()) { return PixelSpacingInterpretation_SpacingInPatient; } else if (m_PixelSpacing != m_ImagerPixelSpacing) { return PixelSpacingInterpretation_SpacingInPatient; } else { return PixelSpacingInterpretation_SpacingAtDetector; } } } bool DicomSeriesReader::ImageBlockDescriptor::PixelSpacingRelatesToPatient() const { return GetPixelSpacingType() == PixelSpacingInterpretation_SpacingInPatient; } bool DicomSeriesReader::ImageBlockDescriptor::PixelSpacingRelatesToDetector() const { return GetPixelSpacingType() == PixelSpacingInterpretation_SpacingAtDetector; } bool DicomSeriesReader::ImageBlockDescriptor::PixelSpacingIsUnknown() const { return GetPixelSpacingType() == PixelSpacingInterpretation_SpacingUnknown; } void DicomSeriesReader::ImageBlockDescriptor::SetPixelSpacingInformation(const std::string &pixelSpacing, const std::string &imagerPixelSpacing) { m_PixelSpacing = pixelSpacing; m_ImagerPixelSpacing = imagerPixelSpacing; } void DicomSeriesReader::ImageBlockDescriptor::GetDesiredMITKImagePixelSpacing(ScalarType &spacingX, ScalarType &spacingY) const { // preference for "in patient" pixel spacing if (!DICOMStringToSpacing(m_PixelSpacing, spacingX, spacingY)) { // fallback to "on detector" spacing if (!DICOMStringToSpacing(m_ImagerPixelSpacing, spacingX, spacingY)) { // last resort: invent something spacingX = spacingY = 1.0; } } } bool DicomSeriesReader::ImageBlockDescriptor::HasMultipleTimePoints() const { return m_HasMultipleTimePoints; } void DicomSeriesReader::ImageBlockDescriptor::SetImageBlockUID(const std::string &uid) { m_ImageBlockUID = uid; } void DicomSeriesReader::ImageBlockDescriptor::SetSeriesInstanceUID(const std::string &uid) { m_SeriesInstanceUID = uid; } void DicomSeriesReader::ImageBlockDescriptor::SetModality(const std::string &modality) { m_Modality = modality; } void DicomSeriesReader::ImageBlockDescriptor::SetNumberOfFrames(const std::string &numberOfFrames) { m_IsMultiFrameImage = !numberOfFrames.empty(); } void DicomSeriesReader::ImageBlockDescriptor::SetSOPClassUID(const std::string &sopClassUID) { m_SOPClassUID = sopClassUID; } void DicomSeriesReader::ImageBlockDescriptor::SetHasGantryTiltCorrected(bool on) { m_HasGantryTiltCorrected = on; } void DicomSeriesReader::ImageBlockDescriptor::SetHasMultipleTimePoints(bool on) { m_HasMultipleTimePoints = on; } } // end namespace mitk diff --git a/Modules/Core/src/IO/mitkDicomSR_LoadDICOMRGBPixel.cpp b/Modules/DICOMReader/src/legacy/mitkDicomSR_LoadDICOMRGBPixel.cpp similarity index 100% rename from Modules/Core/src/IO/mitkDicomSR_LoadDICOMRGBPixel.cpp rename to Modules/DICOMReader/src/legacy/mitkDicomSR_LoadDICOMRGBPixel.cpp diff --git a/Modules/Core/src/IO/mitkDicomSR_LoadDICOMRGBPixel4D.cpp b/Modules/DICOMReader/src/legacy/mitkDicomSR_LoadDICOMRGBPixel4D.cpp similarity index 100% rename from Modules/Core/src/IO/mitkDicomSR_LoadDICOMRGBPixel4D.cpp rename to Modules/DICOMReader/src/legacy/mitkDicomSR_LoadDICOMRGBPixel4D.cpp diff --git a/Modules/Core/src/IO/mitkDicomSR_LoadDICOMScalar.cpp b/Modules/DICOMReader/src/legacy/mitkDicomSR_LoadDICOMScalar.cpp similarity index 98% rename from Modules/Core/src/IO/mitkDicomSR_LoadDICOMScalar.cpp rename to Modules/DICOMReader/src/legacy/mitkDicomSR_LoadDICOMScalar.cpp index b9ea940e52..1b3b77bf63 100644 --- a/Modules/Core/src/IO/mitkDicomSR_LoadDICOMScalar.cpp +++ b/Modules/DICOMReader/src/legacy/mitkDicomSR_LoadDICOMScalar.cpp @@ -1,58 +1,58 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkDicomSeriesReader.txx" namespace mitk { Image::Pointer DicomSeriesReader::MultiplexLoadDICOMByITKScalar(const StringContainer &filenames, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, Image::Pointer preLoadedImageBlock) { switch (io->GetComponentType()) { case DcmIoType::UCHAR: return LoadDICOMByITK(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::CHAR: return LoadDICOMByITK(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::USHORT: return LoadDICOMByITK(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::SHORT: return LoadDICOMByITK(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::UINT: return LoadDICOMByITK(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::INT: return LoadDICOMByITK(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::ULONG: return LoadDICOMByITK(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::LONG: return LoadDICOMByITK(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::FLOAT: return LoadDICOMByITK(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::DOUBLE: return LoadDICOMByITK(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); default: MITK_ERROR << "Found unsupported DICOM scalar pixel type: (enum value) " << io->GetComponentType(); return nullptr; } } } // end namespace mitk -#include +#include diff --git a/Modules/Core/src/IO/mitkDicomSR_LoadDICOMScalar4D.cpp b/Modules/DICOMReader/src/legacy/mitkDicomSR_LoadDICOMScalar4D.cpp similarity index 98% rename from Modules/Core/src/IO/mitkDicomSR_LoadDICOMScalar4D.cpp rename to Modules/DICOMReader/src/legacy/mitkDicomSR_LoadDICOMScalar4D.cpp index 4c7afdf1b8..9ddde9bd8c 100644 --- a/Modules/Core/src/IO/mitkDicomSR_LoadDICOMScalar4D.cpp +++ b/Modules/DICOMReader/src/legacy/mitkDicomSR_LoadDICOMScalar4D.cpp @@ -1,69 +1,69 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkDicomSeriesReader.txx" namespace mitk { Image::Pointer DicomSeriesReader::MultiplexLoadDICOMByITK4DScalar(std::list &imageBlocks, ImageBlockDescriptor imageBlockDescriptor, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, Image::Pointer preLoadedImageBlock) { switch (io->GetComponentType()) { case DcmIoType::UCHAR: return LoadDICOMByITK4D( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::CHAR: return LoadDICOMByITK4D( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::USHORT: return LoadDICOMByITK4D( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::SHORT: return LoadDICOMByITK4D( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::UINT: return LoadDICOMByITK4D( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::INT: return LoadDICOMByITK4D( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::ULONG: return LoadDICOMByITK4D( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::LONG: return LoadDICOMByITK4D( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::FLOAT: return LoadDICOMByITK4D( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); case DcmIoType::DOUBLE: return LoadDICOMByITK4D( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); default: MITK_ERROR << "Found unsupported DICOM scalar pixel type: (enum value) " << io->GetComponentType(); return nullptr; } } } // end namespace mitk -#include +#include diff --git a/Modules/Core/src/IO/mitkDicomSR_SliceGroupingResult.cpp b/Modules/DICOMReader/src/legacy/mitkDicomSR_SliceGroupingResult.cpp similarity index 97% rename from Modules/Core/src/IO/mitkDicomSR_SliceGroupingResult.cpp rename to Modules/DICOMReader/src/legacy/mitkDicomSR_SliceGroupingResult.cpp index 027c1598e9..72a29863e9 100644 --- a/Modules/Core/src/IO/mitkDicomSR_SliceGroupingResult.cpp +++ b/Modules/DICOMReader/src/legacy/mitkDicomSR_SliceGroupingResult.cpp @@ -1,56 +1,56 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include +#include namespace mitk { DicomSeriesReader::SliceGroupingAnalysisResult::SliceGroupingAnalysisResult() : m_GantryTilt(false) {} DicomSeriesReader::StringContainer DicomSeriesReader::SliceGroupingAnalysisResult::GetBlockFilenames() { return m_GroupedFiles; } DicomSeriesReader::StringContainer DicomSeriesReader::SliceGroupingAnalysisResult::GetUnsortedFilenames() { return m_UnsortedFiles; } bool DicomSeriesReader::SliceGroupingAnalysisResult::ContainsGantryTilt() { return m_GantryTilt; } void DicomSeriesReader::SliceGroupingAnalysisResult::AddFileToSortedBlock(const std::string &filename) { m_GroupedFiles.push_back(filename); } void DicomSeriesReader::SliceGroupingAnalysisResult::AddFileToUnsortedBlock(const std::string &filename) { m_UnsortedFiles.push_back(filename); } void DicomSeriesReader::SliceGroupingAnalysisResult::AddFilesToUnsortedBlock(const StringContainer &filenames) { m_UnsortedFiles.insert(m_UnsortedFiles.end(), filenames.begin(), filenames.end()); } void DicomSeriesReader::SliceGroupingAnalysisResult::FlagGantryTilt() { m_GantryTilt = true; } void DicomSeriesReader::SliceGroupingAnalysisResult::UndoPrematureGrouping() { assert(!m_GroupedFiles.empty()); m_UnsortedFiles.insert(m_UnsortedFiles.begin(), m_GroupedFiles.back()); m_GroupedFiles.pop_back(); } } // end namespace mitk diff --git a/Modules/Core/src/IO/mitkDicomSeriesReader.cpp b/Modules/DICOMReader/src/legacy/mitkDicomSeriesReader.cpp similarity index 99% rename from Modules/Core/src/IO/mitkDicomSeriesReader.cpp rename to Modules/DICOMReader/src/legacy/mitkDicomSeriesReader.cpp index 90f83ec0e0..7d7d94a7f8 100644 --- a/Modules/Core/src/IO/mitkDicomSeriesReader.cpp +++ b/Modules/DICOMReader/src/legacy/mitkDicomSeriesReader.cpp @@ -1,1864 +1,1864 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // uncomment for learning more about the internal sorting mechanisms //#define MBILOG_ENABLE_DEBUG -#include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include "mitkProperties.h" namespace mitk { std::string DicomSeriesReader::ReaderImplementationLevelToString(const ReaderImplementationLevel &enumValue) { switch (enumValue) { case ReaderImplementationLevel_Supported: return "Supported"; case ReaderImplementationLevel_PartlySupported: return "PartlySupported"; case ReaderImplementationLevel_Implemented: return "Implemented"; case ReaderImplementationLevel_Unsupported: return "Unsupported"; default: return ""; }; } std::string DicomSeriesReader::PixelSpacingInterpretationToString(const PixelSpacingInterpretation &enumValue) { switch (enumValue) { case PixelSpacingInterpretation_SpacingInPatient: return "In Patient"; case PixelSpacingInterpretation_SpacingAtDetector: return "At Detector"; case PixelSpacingInterpretation_SpacingUnknown: return "Unknown spacing"; default: return ""; }; } const DicomSeriesReader::TagToPropertyMapType &DicomSeriesReader::GetDICOMTagsToMITKPropertyMap() { static bool initialized = false; static TagToPropertyMapType dictionary; if (!initialized) { /* Selection criteria: - no sequences because we cannot represent that - nothing animal related (specied, breed registration number), MITK focusses on human medical image processing. - only general attributes so far When extending this, we should make use of a real dictionary (GDCM/DCMTK and lookup the tag names there) */ // Patient module dictionary["0010|0010"] = "dicom.patient.PatientsName"; dictionary["0010|0020"] = "dicom.patient.PatientID"; dictionary["0010|0030"] = "dicom.patient.PatientsBirthDate"; dictionary["0010|0040"] = "dicom.patient.PatientsSex"; dictionary["0010|0032"] = "dicom.patient.PatientsBirthTime"; dictionary["0010|1000"] = "dicom.patient.OtherPatientIDs"; dictionary["0010|1001"] = "dicom.patient.OtherPatientNames"; dictionary["0010|2160"] = "dicom.patient.EthnicGroup"; dictionary["0010|4000"] = "dicom.patient.PatientComments"; dictionary["0012|0062"] = "dicom.patient.PatientIdentityRemoved"; dictionary["0012|0063"] = "dicom.patient.DeIdentificationMethod"; // General Study module dictionary["0020|000d"] = "dicom.study.StudyInstanceUID"; dictionary["0008|0020"] = "dicom.study.StudyDate"; dictionary["0008|0030"] = "dicom.study.StudyTime"; dictionary["0008|0090"] = "dicom.study.ReferringPhysiciansName"; dictionary["0020|0010"] = "dicom.study.StudyID"; dictionary["0008|0050"] = "dicom.study.AccessionNumber"; dictionary["0008|1030"] = "dicom.study.StudyDescription"; dictionary["0008|1048"] = "dicom.study.PhysiciansOfRecord"; dictionary["0008|1060"] = "dicom.study.NameOfPhysicianReadingStudy"; // General Series module dictionary["0008|0060"] = "dicom.series.Modality"; dictionary["0020|000e"] = "dicom.series.SeriesInstanceUID"; dictionary["0020|0011"] = "dicom.series.SeriesNumber"; dictionary["0020|0060"] = "dicom.series.Laterality"; dictionary["0008|0021"] = "dicom.series.SeriesDate"; dictionary["0008|0031"] = "dicom.series.SeriesTime"; dictionary["0008|1050"] = "dicom.series.PerformingPhysiciansName"; dictionary["0018|1030"] = "dicom.series.ProtocolName"; dictionary["0008|103e"] = "dicom.series.SeriesDescription"; dictionary["0008|1070"] = "dicom.series.OperatorsName"; dictionary["0018|0015"] = "dicom.series.BodyPartExamined"; dictionary["0018|5100"] = "dicom.series.PatientPosition"; dictionary["0028|0108"] = "dicom.series.SmallestPixelValueInSeries"; dictionary["0028|0109"] = "dicom.series.LargestPixelValueInSeries"; // VOI LUT module dictionary["0028|1050"] = "dicom.voilut.WindowCenter"; dictionary["0028|1051"] = "dicom.voilut.WindowWidth"; dictionary["0028|1055"] = "dicom.voilut.WindowCenterAndWidthExplanation"; // Image Pixel module dictionary["0028|0004"] = "dicom.pixel.PhotometricInterpretation"; dictionary["0028|0010"] = "dicom.pixel.Rows"; dictionary["0028|0011"] = "dicom.pixel.Columns"; // Image Plane module dictionary["0028|0030"] = "dicom.PixelSpacing"; dictionary["0018|1164"] = "dicom.ImagerPixelSpacing"; // Misc dictionary["0008|0005"] = "dicom.SpecificCharacterSet"; initialized = true; } return dictionary; } DataNode::Pointer DicomSeriesReader::LoadDicomSeries(const StringContainer &filenames, bool sort, bool check_4d, bool correctTilt, UpdateCallBackMethod callback, Image::Pointer preLoadedImageBlock) { DataNode::Pointer node = DataNode::New(); if (DicomSeriesReader::LoadDicomSeries( filenames, *node, sort, check_4d, correctTilt, callback, preLoadedImageBlock)) { if (filenames.empty()) { return nullptr; } return node; } else { return nullptr; } } bool DicomSeriesReader::LoadDicomSeries(const StringContainer &filenames, DataNode &node, bool sort, bool check_4d, bool correctTilt, UpdateCallBackMethod callback, itk::SmartPointer preLoadedImageBlock) { if (filenames.empty()) { MITK_DEBUG << "Calling LoadDicomSeries with empty filename string container. Probably invalid application logic."; node.SetData(nullptr); return true; // this is not actually an error but the result is very simple } DcmIoType::Pointer io = DcmIoType::New(); try { if (io->CanReadFile(filenames.front().c_str())) { io->SetFileName(filenames.front().c_str()); io->ReadImageInformation(); if (io->GetPixelType() == itk::ImageIOBase::SCALAR || io->GetPixelType() == itk::ImageIOBase::RGB) { LoadDicom(filenames, node, sort, check_4d, correctTilt, callback, preLoadedImageBlock); } if (node.GetData()) { return true; } } } catch (itk::MemoryAllocationError &e) { MITK_ERROR << "Out of memory. Cannot load DICOM series: " << e.what(); } catch (std::exception &e) { MITK_ERROR << "Error encountered when loading DICOM series:" << e.what(); } catch (...) { MITK_ERROR << "Unspecified error encountered when loading DICOM series."; } return false; } bool DicomSeriesReader::IsDicom(const std::string &filename) { DcmIoType::Pointer io = DcmIoType::New(); return io->CanReadFile(filename.c_str()); } bool DicomSeriesReader::IsPhilips3DDicom(const std::string &filename) { DcmIoType::Pointer io = DcmIoType::New(); if (io->CanReadFile(filename.c_str())) { // Look at header Tag 3001,0010 if it is "Philips3D" gdcm::Reader reader; reader.SetFileName(filename.c_str()); reader.Read(); gdcm::DataSet &data_set = reader.GetFile().GetDataSet(); gdcm::StringFilter sf; sf.SetFile(reader.GetFile()); if (data_set.FindDataElement(gdcm::Tag(0x3001, 0x0010)) && (sf.ToString(gdcm::Tag(0x3001, 0x0010)) == "Philips3D ")) { return true; } } return false; } bool DicomSeriesReader::ReadPhilips3DDicom(const std::string &filename, itk::SmartPointer output_image) { // Now get PhilipsSpecific Tags gdcm::PixmapReader reader; reader.SetFileName(filename.c_str()); reader.Read(); gdcm::DataSet &data_set = reader.GetFile().GetDataSet(); gdcm::StringFilter sf; sf.SetFile(reader.GetFile()); gdcm::Attribute<0x0028, 0x0011> dimTagX; // coloumns || sagittal gdcm::Attribute<0x3001, 0x1001, gdcm::VR::UL, gdcm::VM::VM1> dimTagZ; // I have no idea what is VM1. // (Philips specific) // axial gdcm::Attribute<0x0028, 0x0010> dimTagY; // rows || coronal gdcm::Attribute<0x0028, 0x0008> dimTagT; // how many frames gdcm::Attribute<0x0018, 0x602c> spaceTagX; // Spacing in X , unit is "physicalTagx" (usually centimeter) gdcm::Attribute<0x0018, 0x602e> spaceTagY; gdcm::Attribute<0x3001, 0x1003, gdcm::VR::FD, gdcm::VM::VM1> spaceTagZ; // (Philips specific) gdcm::Attribute<0x0018, 0x6024> physicalTagX; // if 3, then spacing params are centimeter gdcm::Attribute<0x0018, 0x6026> physicalTagY; gdcm::Attribute<0x3001, 0x1002, gdcm::VR::US, gdcm::VM::VM1> physicalTagZ; // (Philips specific) dimTagX.Set(data_set); dimTagY.Set(data_set); dimTagZ.Set(data_set); dimTagT.Set(data_set); spaceTagX.Set(data_set); spaceTagY.Set(data_set); spaceTagZ.Set(data_set); physicalTagX.Set(data_set); physicalTagY.Set(data_set); physicalTagZ.Set(data_set); unsigned int dimX = dimTagX.GetValue(), dimY = dimTagY.GetValue(), dimZ = dimTagZ.GetValue(), dimT = dimTagT.GetValue(), physicalX = physicalTagX.GetValue(), physicalY = physicalTagY.GetValue(), physicalZ = physicalTagZ.GetValue(); float spaceX = spaceTagX.GetValue(), spaceY = spaceTagY.GetValue(), spaceZ = spaceTagZ.GetValue(); if (physicalX == 3) // spacing parameter in cm, have to convert it to mm. spaceX = spaceX * 10; if (physicalY == 3) // spacing parameter in cm, have to convert it to mm. spaceY = spaceY * 10; if (physicalZ == 3) // spacing parameter in cm, have to convert it to mm. spaceZ = spaceZ * 10; // Ok, got all necessary Tags! // Now read Pixeldata (7fe0,0010) X x Y x Z x T Elements const gdcm::Pixmap &pixels = reader.GetPixmap(); gdcm::RAWCodec codec; codec.SetPhotometricInterpretation(gdcm::PhotometricInterpretation::MONOCHROME2); codec.SetPixelFormat(pixels.GetPixelFormat()); codec.SetPlanarConfiguration(0); gdcm::DataElement out; codec.Decode(data_set.GetDataElement(gdcm::Tag(0x7fe0, 0x0010)), out); const gdcm::ByteValue *bv = out.GetByteValue(); const char *new_pixels = bv->GetPointer(); // Create MITK Image + Geometry typedef itk::Image ImageType; // Pixeltype might be different sometimes? Maybe read it out from header ImageType::RegionType myRegion; ImageType::SizeType mySize; ImageType::IndexType myIndex; ImageType::SpacingType mySpacing; ImageType::Pointer imageItk = ImageType::New(); mySpacing[0] = spaceX; mySpacing[1] = spaceY; mySpacing[2] = spaceZ; mySpacing[3] = 1; myIndex[0] = 0; myIndex[1] = 0; myIndex[2] = 0; myIndex[3] = 0; mySize[0] = dimX; mySize[1] = dimY; mySize[2] = dimZ; mySize[3] = dimT; myRegion.SetSize(mySize); myRegion.SetIndex(myIndex); imageItk->SetSpacing(mySpacing); imageItk->SetRegions(myRegion); imageItk->Allocate(); imageItk->FillBuffer(0); itk::ImageRegionIterator iterator(imageItk, imageItk->GetLargestPossibleRegion()); iterator.GoToBegin(); unsigned long pixCount = 0; unsigned long planeSize = dimX * dimY; unsigned long planeCount = 0; unsigned long timeCount = 0; unsigned long numberOfSlices = dimZ; while (!iterator.IsAtEnd()) { unsigned long adressedPixel = pixCount + (numberOfSlices - 1 - planeCount) * planeSize // add offset to adress the first pixel of current plane + timeCount * numberOfSlices * planeSize; // add time offset iterator.Set(new_pixels[adressedPixel]); pixCount++; ++iterator; if (pixCount == planeSize) { pixCount = 0; planeCount++; } if (planeCount == numberOfSlices) { planeCount = 0; timeCount++; } if (timeCount == dimT) { break; } } mitk::CastToMitkImage(imageItk, output_image); return true; // actually never returns false yet.. but exception possible } std::string DicomSeriesReader::ConstCharStarToString(const char *s) { return s ? std::string(s) : std::string(); } bool DicomSeriesReader::DICOMStringToSpacing(const std::string &s, ScalarType &spacingX, ScalarType &spacingY) { bool successful = false; std::istringstream spacingReader(s); std::string spacing; if (std::getline(spacingReader, spacing, '\\')) { spacingY = atof(spacing.c_str()); if (std::getline(spacingReader, spacing, '\\')) { spacingX = atof(spacing.c_str()); successful = true; } } return successful; } Point3D DicomSeriesReader::DICOMStringToPoint3D(const std::string &s, bool &successful) { Point3D p; successful = true; std::istringstream originReader(s); std::string coordinate; unsigned int dim(0); while (std::getline(originReader, coordinate, '\\') && dim < 3) { p[dim++] = atof(coordinate.c_str()); } if (dim && dim != 3) { successful = false; MITK_ERROR << "Reader implementation made wrong assumption on tag (0020,0032). Found " << dim << " instead of 3 values."; } else if (dim == 0) { successful = false; p.Fill(0.0); // assume default (0,0,0) } return p; } void DicomSeriesReader::DICOMStringToOrientationVectors(const std::string &s, Vector3D &right, Vector3D &up, bool &successful) { successful = true; std::istringstream orientationReader(s); std::string coordinate; unsigned int dim(0); while (std::getline(orientationReader, coordinate, '\\') && dim < 6) { if (dim < 3) { right[dim++] = atof(coordinate.c_str()); } else { up[dim++ - 3] = atof(coordinate.c_str()); } } if (dim && dim != 6) { successful = false; MITK_ERROR << "Reader implementation made wrong assumption on tag (0020,0037). Found " << dim << " instead of 6 values."; } else if (dim == 0) { // fill with defaults right.Fill(0.0); right[0] = 1.0; up.Fill(0.0); up[1] = 1.0; successful = false; } } DicomSeriesReader::SliceGroupingAnalysisResult DicomSeriesReader::AnalyzeFileForITKImageSeriesReaderSpacingAssumption( const StringContainer &files, bool groupImagesWithGantryTilt, const gdcm::Scanner::MappingType &tagValueMappings_) { // result.first = files that fit ITK's assumption // result.second = files that do not fit, should be run through // AnalyzeFileForITKImageSeriesReaderSpacingAssumption() // again SliceGroupingAnalysisResult result; // we const_cast here, because I could not use a map.at(), which would make the code much more readable auto &tagValueMappings = const_cast(tagValueMappings_); const gdcm::Tag tagImagePositionPatient(0x0020, 0x0032); // Image Position (Patient) const gdcm::Tag tagImageOrientation(0x0020, 0x0037); // Image Orientation const gdcm::Tag tagGantryTilt(0x0018, 0x1120); // gantry tilt Vector3D fromFirstToSecondOrigin; fromFirstToSecondOrigin.Fill(0.0); bool fromFirstToSecondOriginInitialized(false); Point3D thisOrigin; thisOrigin.Fill(0.0f); Point3D lastOrigin; lastOrigin.Fill(0.0f); Point3D lastDifferentOrigin; lastDifferentOrigin.Fill(0.0f); bool lastOriginInitialized(false); MITK_DEBUG << "--------------------------------------------------------------------------------"; MITK_DEBUG << "Analyzing files for z-spacing assumption of ITK's ImageSeriesReader (group tilted: " << groupImagesWithGantryTilt << ")"; unsigned int fileIndex(0); for (auto fileIter = files.begin(); fileIter != files.end(); ++fileIter, ++fileIndex) { bool fileFitsIntoPattern(false); std::string thisOriginString; // Read tag value into point3D. PLEASE replace this by appropriate GDCM code if you figure out how to do that thisOriginString = ConstCharStarToString(tagValueMappings[fileIter->c_str()][tagImagePositionPatient]); if (thisOriginString.empty()) { // don't let such files be in a common group. Everything without position information will be loaded as a single // slice: // with standard DICOM files this can happen to: CR, DX, SC MITK_DEBUG << " ==> Sort away " << *fileIter << " for later analysis (no position information)"; // we already have one occupying this position if (result.GetBlockFilenames().empty()) // nothing WITH position information yet { // ==> this is a group of its own, stop processing, come back later result.AddFileToSortedBlock(*fileIter); StringContainer remainingFiles; remainingFiles.insert(remainingFiles.end(), fileIter + 1, files.end()); result.AddFilesToUnsortedBlock(remainingFiles); fileFitsIntoPattern = false; break; // no files anymore } else { // ==> this does not match, consider later result.AddFileToUnsortedBlock(*fileIter); fileFitsIntoPattern = false; continue; // next file } } bool ignoredConversionError(-42); // hard to get here, no graceful way to react thisOrigin = DICOMStringToPoint3D(thisOriginString, ignoredConversionError); MITK_DEBUG << " " << fileIndex << " " << *fileIter << " at " /* << thisOriginString */ << "(" << thisOrigin[0] << "," << thisOrigin[1] << "," << thisOrigin[2] << ")"; if (lastOriginInitialized && (thisOrigin == lastOrigin)) { MITK_DEBUG << " ==> Sort away " << *fileIter << " for separate time step"; // we already have one occupying this position result.AddFileToUnsortedBlock(*fileIter); fileFitsIntoPattern = false; } else { if (!fromFirstToSecondOriginInitialized && lastOriginInitialized) // calculate vector as soon as possible when we get a new position { fromFirstToSecondOrigin = thisOrigin - lastDifferentOrigin; fromFirstToSecondOriginInitialized = true; // Here we calculate if this slice and the previous one are well aligned, // i.e. we test if the previous origin is on a line through the current // origin, directed into the normal direction of the current slice. // If this is NOT the case, then we have a data set with a TILTED GANTRY geometry, // which cannot be simply loaded into a single mitk::Image at the moment. // For this case, we flag this finding in the result and DicomSeriesReader // can correct for that later. Vector3D right; right.Fill(0.0); Vector3D up; right.Fill(0.0); // might be down as well, but it is just a name at this point DICOMStringToOrientationVectors( tagValueMappings[fileIter->c_str()][tagImageOrientation], right, up, ignoredConversionError); GantryTiltInformation tiltInfo(lastDifferentOrigin, thisOrigin, right, up, 1); if (tiltInfo.IsSheared()) // mitk::eps is too small; 1/1000 of a mm should be enough to detect tilt { /* optimistic approach, accepting gantry tilt: save file for later, check all further files */ // at this point we have TWO slices analyzed! if they are the only two files, we still split, because there // is // no third to verify our tilting assumption. // later with a third being available, we must check if the initial tilting vector is still valid. if yes, // continue. // if NO, we need to split the already sorted part (result.first) and the currently analyzed file // (*fileIter) // tell apart gantry tilt from overall skewedness // sort out irregularly sheared slices, that IS NOT tilting if (groupImagesWithGantryTilt && tiltInfo.IsRegularGantryTilt()) { // check if this is at least roughly the same angle as recorded in DICOM tags if (tagValueMappings[fileIter->c_str()].find(tagGantryTilt) != tagValueMappings[fileIter->c_str()].end()) { // read value, compare to calculated angle std::string tiltStr = ConstCharStarToString(tagValueMappings[fileIter->c_str()][tagGantryTilt]); double angle = atof(tiltStr.c_str()); MITK_DEBUG << "Comparing recorded tilt angle " << angle << " against calculated value " << tiltInfo.GetTiltAngleInDegrees(); // TODO we probably want the signs correct, too (that depends: this is just a rough check, nothing // serious) // TODO TODO TODO when angle -27 and tiltangle 63, this will never trigger the if-clause... useless // check // in this case! old bug..?! if (fabs(angle) - tiltInfo.GetTiltAngleInDegrees() > 0.25) { result.AddFileToUnsortedBlock(*fileIter); // sort away for further analysis fileFitsIntoPattern = false; } else // tilt angle from header is less than 0.25 degrees different from what we calculated, assume this // is // fine { result.FlagGantryTilt(); result.AddFileToSortedBlock(*fileIter); // this file is good for current block fileFitsIntoPattern = true; } } else // we cannot check the calculated tilt angle against the one from the dicom header (so we assume we // are // right) { result.FlagGantryTilt(); result.AddFileToSortedBlock(*fileIter); // this file is good for current block fileFitsIntoPattern = true; } } else // caller does not want tilt compensation OR shearing is more complicated than tilt { result.AddFileToUnsortedBlock(*fileIter); // sort away for further analysis fileFitsIntoPattern = false; } } else // not sheared { result.AddFileToSortedBlock(*fileIter); // this file is good for current block fileFitsIntoPattern = true; } } else if (fromFirstToSecondOriginInitialized) // we already know the offset between slices { Point3D assumedOrigin = lastDifferentOrigin + fromFirstToSecondOrigin; Vector3D originError = assumedOrigin - thisOrigin; double norm = originError.GetNorm(); double toleratedError(0.005); // max. 1/10mm error when measurement crosses 20 slices in z direction if (norm > toleratedError) { MITK_DEBUG << " File does not fit into the inter-slice distance pattern (diff = " << norm << ", allowed " << toleratedError << ")."; MITK_DEBUG << " Expected position (" << assumedOrigin[0] << "," << assumedOrigin[1] << "," << assumedOrigin[2] << "), got position (" << thisOrigin[0] << "," << thisOrigin[1] << "," << thisOrigin[2] << ")"; MITK_DEBUG << " ==> Sort away " << *fileIter << " for later analysis"; // At this point we know we deviated from the expectation of ITK's ImageSeriesReader // We split the input file list at this point, i.e. all files up to this one (excluding it) // are returned as group 1, the remaining files (including the faulty one) are group 2 /* Optimistic approach: check if any of the remaining slices fits in */ result.AddFileToUnsortedBlock(*fileIter); // sort away for further analysis fileFitsIntoPattern = false; } else { result.AddFileToSortedBlock(*fileIter); // this file is good for current block fileFitsIntoPattern = true; } } else // this should be the very first slice { result.AddFileToSortedBlock(*fileIter); // this file is good for current block fileFitsIntoPattern = true; } } // record current origin for reference in later iterations if (!lastOriginInitialized || (fileFitsIntoPattern && (thisOrigin != lastOrigin))) { lastDifferentOrigin = thisOrigin; } lastOrigin = thisOrigin; lastOriginInitialized = true; } if (result.ContainsGantryTilt()) { // check here how many files were grouped. // IF it was only two files AND we assume tiltedness (e.g. save "distance") // THEN we would want to also split the two previous files (simple) because // we don't have any reason to assume they belong together if (result.GetBlockFilenames().size() == 2) { result.UndoPrematureGrouping(); } } return result; } DicomSeriesReader::FileNamesGrouping DicomSeriesReader::GetSeries(const StringContainer &files, bool groupImagesWithGantryTilt, const StringContainer &restrictions) { return GetSeries(files, true, groupImagesWithGantryTilt, restrictions); } DicomSeriesReader::FileNamesGrouping DicomSeriesReader::GetSeries(const StringContainer &files, bool sortTo3DPlust, bool groupImagesWithGantryTilt, const StringContainer & /*restrictions*/) { /** assumption about this method: returns a map of uid-like-key --> list(filename) each entry should contain filenames that have images of same - series instance uid (automatically done by GDCMSeriesFileNames - 0020,0037 image orientation (patient) - 0028,0030 pixel spacing (x,y) - 0018,0050 slice thickness */ // use GDCM directly, itk::GDCMSeriesFileNames does not work with GDCM 2 // PART I: scan files for sorting relevant DICOM tags, // separate images that differ in any of those // attributes (they cannot possibly form a 3D block) // scan for relevant tags in dicom files gdcm::Scanner scanner; const gdcm::Tag tagSOPClassUID(0x0008, 0x0016); // SOP class UID scanner.AddTag(tagSOPClassUID); const gdcm::Tag tagSeriesInstanceUID(0x0020, 0x000e); // Series Instance UID scanner.AddTag(tagSeriesInstanceUID); const gdcm::Tag tagImageOrientation(0x0020, 0x0037); // image orientation scanner.AddTag(tagImageOrientation); const gdcm::Tag tagPixelSpacing(0x0028, 0x0030); // pixel spacing scanner.AddTag(tagPixelSpacing); const gdcm::Tag tagImagerPixelSpacing(0x0018, 0x1164); // imager pixel spacing scanner.AddTag(tagImagerPixelSpacing); const gdcm::Tag tagSliceThickness(0x0018, 0x0050); // slice thickness scanner.AddTag(tagSliceThickness); const gdcm::Tag tagNumberOfRows(0x0028, 0x0010); // number rows scanner.AddTag(tagNumberOfRows); const gdcm::Tag tagNumberOfColumns(0x0028, 0x0011); // number cols scanner.AddTag(tagNumberOfColumns); const gdcm::Tag tagGantryTilt(0x0018, 0x1120); // gantry tilt scanner.AddTag(tagGantryTilt); const gdcm::Tag tagModality(0x0008, 0x0060); // modality scanner.AddTag(tagModality); const gdcm::Tag tagNumberOfFrames(0x0028, 0x0008); // number of frames scanner.AddTag(tagNumberOfFrames); // additional tags read in this scan to allow later analysis // THESE tag are not used for initial separating of files const gdcm::Tag tagImagePositionPatient(0x0020, 0x0032); // Image Position (Patient) scanner.AddTag(tagImagePositionPatient); // TODO add further restrictions from arguments (when anybody asks for it) FileNamesGrouping result; // let GDCM scan files if (!scanner.Scan(files)) { MITK_ERROR << "gdcm::Scanner failed when scanning " << files.size() << " input files."; return result; } // assign files IDs that will separate them for loading into image blocks for (auto fileIter = scanner.Begin(); fileIter != scanner.End(); ++fileIter) { if (std::string(fileIter->first).empty()) continue; // TODO understand why Scanner has empty string entries if (std::string(fileIter->first) == std::string("DICOMDIR")) continue; /* sort out multi-frame if ( scanner.GetValue( fileIter->first , tagNumberOfFrames ) ) { MITK_INFO << "Ignoring " << fileIter->first << " because we cannot handle multi-frame images."; continue; } */ // we const_cast here, because I could not use a map.at() function in CreateMoreUniqueSeriesIdentifier. // doing the same thing with find would make the code less readable. Since we forget the Scanner results // anyway after this function, we can simply tolerate empty map entries introduced by bad operator[] access std::string moreUniqueSeriesId = CreateMoreUniqueSeriesIdentifier(const_cast(fileIter->second)); result[moreUniqueSeriesId].AddFile(fileIter->first); } // PART II: sort slices spatially (or at least consistently if this is NOT possible, see method) for (FileNamesGrouping::const_iterator groupIter = result.begin(); groupIter != result.end(); ++groupIter) { try { result[groupIter->first] = ImageBlockDescriptor(SortSeriesSlices(groupIter->second.GetFilenames())); // sort each slice group spatially } catch (...) { MITK_ERROR << "Caught something."; } } // PART III: analyze pre-sorted images for valid blocks (i.e. blocks of equal z-spacing), // separate into multiple blocks if necessary. // // Analysis performs the following steps: // * imitate itk::ImageSeriesReader: use the distance between the first two images as z-spacing // * check what images actually fulfill ITK's z-spacing assumption // * separate all images that fail the test into new blocks, re-iterate analysis for these blocks // * this includes images which DO NOT PROVIDE spatial information, i.e. all images w/o // ImagePositionPatient will be loaded separately FileNamesGrouping groupsOf3DPlusTBlocks; // final result of this function for (FileNamesGrouping::const_iterator groupIter = result.begin(); groupIter != result.end(); ++groupIter) { FileNamesGrouping groupsOf3DBlocks; // intermediate result for only this group(!) StringContainer filesStillToAnalyze = groupIter->second.GetFilenames(); std::string groupUID = groupIter->first; unsigned int subgroup(0); MITK_DEBUG << "Analyze group " << groupUID << " of " << groupIter->second.GetFilenames().size() << " files"; while (!filesStillToAnalyze.empty()) // repeat until all files are grouped somehow { SliceGroupingAnalysisResult analysisResult = AnalyzeFileForITKImageSeriesReaderSpacingAssumption( filesStillToAnalyze, groupImagesWithGantryTilt, scanner.GetMappings()); // enhance the UID for additional groups std::stringstream newGroupUID; newGroupUID << groupUID << '.' << subgroup; ImageBlockDescriptor thisBlock(analysisResult.GetBlockFilenames()); std::string firstFileInBlock = thisBlock.GetFilenames().front(); thisBlock.SetImageBlockUID(newGroupUID.str()); thisBlock.SetSeriesInstanceUID( DicomSeriesReader::ConstCharStarToString(scanner.GetValue(firstFileInBlock.c_str(), tagSeriesInstanceUID))); thisBlock.SetHasGantryTiltCorrected(analysisResult.ContainsGantryTilt()); thisBlock.SetSOPClassUID( DicomSeriesReader::ConstCharStarToString(scanner.GetValue(firstFileInBlock.c_str(), tagSOPClassUID))); thisBlock.SetNumberOfFrames( ConstCharStarToString(scanner.GetValue(firstFileInBlock.c_str(), tagNumberOfFrames))); thisBlock.SetModality( DicomSeriesReader::ConstCharStarToString(scanner.GetValue(firstFileInBlock.c_str(), tagModality))); thisBlock.SetPixelSpacingInformation( DicomSeriesReader::ConstCharStarToString(scanner.GetValue(firstFileInBlock.c_str(), tagPixelSpacing)), DicomSeriesReader::ConstCharStarToString(scanner.GetValue(firstFileInBlock.c_str(), tagImagerPixelSpacing))); thisBlock.SetHasMultipleTimePoints(false); groupsOf3DBlocks[newGroupUID.str()] = thisBlock; // MITK_DEBUG << "Result: sorted 3D group " << newGroupUID.str() << " with " << groupsOf3DBlocks[ // newGroupUID.str() ].GetFilenames().size() << " files"; MITK_DEBUG << "Result: sorted 3D group with " << groupsOf3DBlocks[newGroupUID.str()].GetFilenames().size() << " files"; StringContainer debugOutputFiles = analysisResult.GetBlockFilenames(); for (StringContainer::const_iterator siter = debugOutputFiles.begin(); siter != debugOutputFiles.end(); ++siter) MITK_DEBUG << " IN " << *siter; ++subgroup; filesStillToAnalyze = analysisResult.GetUnsortedFilenames(); // remember what needs further analysis for (StringContainer::const_iterator siter = filesStillToAnalyze.begin(); siter != filesStillToAnalyze.end(); ++siter) MITK_DEBUG << " OUT " << *siter; } // end of grouping, now post-process groups // PART IV: attempt to group blocks to 3D+t blocks if requested // inspect entries of groupsOf3DBlocks // - if number of files is identical to previous entry, collect for 3D+t block // - as soon as number of files changes from previous entry, record collected blocks as 3D+t block, // start // a new one, continue // decide whether or not to group 3D blocks into 3D+t blocks where possible if (!sortTo3DPlust) { // copy 3D blocks to output groupsOf3DPlusTBlocks.insert(groupsOf3DBlocks.begin(), groupsOf3DBlocks.end()); } else { // sort 3D+t (as described in "PART IV") MITK_DEBUG << "================================================================================"; MITK_DEBUG << "3D+t analysis:"; unsigned int numberOfFilesInPreviousBlock(0); std::string previousBlockKey; for (FileNamesGrouping::const_iterator block3DIter = groupsOf3DBlocks.begin(); block3DIter != groupsOf3DBlocks.end(); ++block3DIter) { unsigned int numberOfFilesInThisBlock = block3DIter->second.GetFilenames().size(); std::string thisBlockKey = block3DIter->first; if (numberOfFilesInPreviousBlock == 0) { numberOfFilesInPreviousBlock = numberOfFilesInThisBlock; groupsOf3DPlusTBlocks[thisBlockKey] = block3DIter->second; MITK_DEBUG << " 3D+t group " << thisBlockKey; previousBlockKey = thisBlockKey; } else { bool identicalOrigins; try { // check whether this and the previous block share a comon origin // TODO should be safe, but a little try/catch or other error handling wouldn't hurt const char *origin_value = scanner.GetValue(groupsOf3DBlocks[thisBlockKey].GetFilenames().front().c_str(), tagImagePositionPatient), *previous_origin_value = scanner.GetValue( groupsOf3DBlocks[previousBlockKey].GetFilenames().front().c_str(), tagImagePositionPatient), *destination_value = scanner.GetValue( groupsOf3DBlocks[thisBlockKey].GetFilenames().back().c_str(), tagImagePositionPatient), *previous_destination_value = scanner.GetValue( groupsOf3DBlocks[previousBlockKey].GetFilenames().back().c_str(), tagImagePositionPatient); if (!origin_value || !previous_origin_value || !destination_value || !previous_destination_value) { identicalOrigins = false; } else { std::string thisOriginString = ConstCharStarToString(origin_value); std::string previousOriginString = ConstCharStarToString(previous_origin_value); // also compare last origin, because this might differ if z-spacing is different std::string thisDestinationString = ConstCharStarToString(destination_value); std::string previousDestinationString = ConstCharStarToString(previous_destination_value); identicalOrigins = ((thisOriginString == previousOriginString) && (thisDestinationString == previousDestinationString)); } } catch (...) { identicalOrigins = false; } if (identicalOrigins && (numberOfFilesInPreviousBlock == numberOfFilesInThisBlock)) { // group with previous block groupsOf3DPlusTBlocks[previousBlockKey].AddFiles(block3DIter->second.GetFilenames()); groupsOf3DPlusTBlocks[previousBlockKey].SetHasMultipleTimePoints(true); MITK_DEBUG << " --> group enhanced with another timestep"; } else { // start a new block groupsOf3DPlusTBlocks[thisBlockKey] = block3DIter->second; int numberOfTimeSteps = groupsOf3DPlusTBlocks[previousBlockKey].GetFilenames().size() / numberOfFilesInPreviousBlock; MITK_DEBUG << " ==> group closed with " << numberOfTimeSteps << " time steps"; previousBlockKey = thisBlockKey; MITK_DEBUG << " 3D+t group " << thisBlockKey << " started"; } } numberOfFilesInPreviousBlock = numberOfFilesInThisBlock; } } } MITK_DEBUG << "================================================================================"; MITK_DEBUG << "Summary: "; for (FileNamesGrouping::const_iterator groupIter = groupsOf3DPlusTBlocks.begin(); groupIter != groupsOf3DPlusTBlocks.end(); ++groupIter) { ImageBlockDescriptor block = groupIter->second; MITK_DEBUG << " " << block.GetFilenames().size() << " '" << block.GetModality() << "' images (" << block.GetSOPClassUIDAsString() << ") in volume " << block.GetImageBlockUID(); MITK_DEBUG << " (gantry tilt : " << (block.HasGantryTiltCorrected() ? "Yes" : "No") << "; " "pixel spacing : " << PixelSpacingInterpretationToString(block.GetPixelSpacingType()) << "; " "3D+t: " << (block.HasMultipleTimePoints() ? "Yes" : "No") << "; " "reader support: " << ReaderImplementationLevelToString(block.GetReaderImplementationLevel()) << ")"; StringContainer debugOutputFiles = block.GetFilenames(); for (StringContainer::const_iterator siter = debugOutputFiles.begin(); siter != debugOutputFiles.end(); ++siter) MITK_DEBUG << " F " << *siter; } MITK_DEBUG << "================================================================================"; return groupsOf3DPlusTBlocks; } DicomSeriesReader::FileNamesGrouping DicomSeriesReader::GetSeries(const std::string &dir, bool groupImagesWithGantryTilt, const StringContainer &restrictions) { gdcm::Directory directoryLister; directoryLister.Load(dir.c_str(), false); // non-recursive return GetSeries(directoryLister.GetFilenames(), groupImagesWithGantryTilt, restrictions); } std::string DicomSeriesReader::CreateSeriesIdentifierPart(gdcm::Scanner::TagToValue &tagValueMap, const gdcm::Tag &tag) { std::string result; try { result = IDifyTagValue(tagValueMap[tag] ? tagValueMap[tag] : std::string("")); } catch (std::exception &) { // we are happy with even nothing, this will just group images of a series // MITK_WARN << "Could not access tag " << tag << ": " << e.what(); } return result; } std::string DicomSeriesReader::CreateMoreUniqueSeriesIdentifier(gdcm::Scanner::TagToValue &tagValueMap) { const gdcm::Tag tagSeriesInstanceUID(0x0020, 0x000e); // Series Instance UID const gdcm::Tag tagImageOrientation(0x0020, 0x0037); // image orientation const gdcm::Tag tagPixelSpacing(0x0028, 0x0030); // pixel spacing const gdcm::Tag tagImagerPixelSpacing(0x0018, 0x1164); // imager pixel spacing const gdcm::Tag tagSliceThickness(0x0018, 0x0050); // slice thickness const gdcm::Tag tagNumberOfRows(0x0028, 0x0010); // number rows const gdcm::Tag tagNumberOfColumns(0x0028, 0x0011); // number cols const gdcm::Tag tagNumberOfFrames(0x0028, 0x0008); // number of frames const char *tagSeriesInstanceUid = tagValueMap[tagSeriesInstanceUID]; if (!tagSeriesInstanceUid) { mitkThrow() << "CreateMoreUniqueSeriesIdentifier() could not access series instance UID. Something is seriously " "wrong with this image, so stopping here."; } std::string constructedID = tagSeriesInstanceUid; constructedID += CreateSeriesIdentifierPart(tagValueMap, tagNumberOfRows); constructedID += CreateSeriesIdentifierPart(tagValueMap, tagNumberOfColumns); constructedID += CreateSeriesIdentifierPart(tagValueMap, tagPixelSpacing); constructedID += CreateSeriesIdentifierPart(tagValueMap, tagImagerPixelSpacing); constructedID += CreateSeriesIdentifierPart(tagValueMap, tagSliceThickness); constructedID += CreateSeriesIdentifierPart(tagValueMap, tagNumberOfFrames); // be a bit tolerant for orienatation, let only the first few digits matter // (http://bugs.mitk.org/show_bug.cgi?id=12263) // NOT constructedID += CreateSeriesIdentifierPart( tagValueMap, tagImageOrientation ); if (tagValueMap.find(tagImageOrientation) != tagValueMap.end()) { bool conversionError(false); Vector3D right; right.Fill(0.0); Vector3D up; right.Fill(0.0); DICOMStringToOrientationVectors(tagValueMap[tagImageOrientation], right, up, conversionError); // string newstring sprintf(simplifiedOrientationString, "%.3f\\%.3f\\%.3f\\%.3f\\%.3f\\%.3f", right[0], // right[1], // right[2], up[0], up[1], up[2]); std::ostringstream ss; ss.setf(std::ios::fixed, std::ios::floatfield); ss.precision(5); ss << right[0] << "\\" << right[1] << "\\" << right[2] << "\\" << up[0] << "\\" << up[1] << "\\" << up[2]; std::string simplifiedOrientationString(ss.str()); constructedID += IDifyTagValue(simplifiedOrientationString); } constructedID.resize(constructedID.length() - 1); // cut of trailing '.' return constructedID; } std::string DicomSeriesReader::IDifyTagValue(const std::string &value) { std::string IDifiedValue(value); if (value.empty()) throw std::logic_error("IDifyTagValue() illegaly called with empty tag value"); // Eliminate non-alnum characters, including whitespace... // that may have been introduced by concats. for (std::size_t i = 0; i < IDifiedValue.size(); i++) { while (i < IDifiedValue.size() && !(IDifiedValue[i] == '.' || (IDifiedValue[i] >= 'a' && IDifiedValue[i] <= 'z') || (IDifiedValue[i] >= '0' && IDifiedValue[i] <= '9') || (IDifiedValue[i] >= 'A' && IDifiedValue[i] <= 'Z'))) { IDifiedValue.erase(i, 1); } } IDifiedValue += "."; return IDifiedValue; } DicomSeriesReader::StringContainer DicomSeriesReader::GetSeries(const std::string &dir, const std::string &series_uid, bool groupImagesWithGantryTilt, const StringContainer &restrictions) { FileNamesGrouping allSeries = GetSeries(dir, groupImagesWithGantryTilt, restrictions); StringContainer resultingFileList; for (FileNamesGrouping::const_iterator idIter = allSeries.begin(); idIter != allSeries.end(); ++idIter) { if (idIter->first.find(series_uid) == 0) // this ID starts with given series_uid { return idIter->second.GetFilenames(); } } return resultingFileList; } DicomSeriesReader::StringContainer DicomSeriesReader::SortSeriesSlices(const StringContainer &unsortedFilenames) { /* we CAN expect a group of equal - series instance uid - image orientation - pixel spacing - imager pixel spacing - slice thickness - number of rows/columns (each piece of information except the rows/columns might be missing) sorting with GdcmSortFunction tries its best by sorting by spatial position and more hints (acquisition number, acquisition time, trigger time) but will always produce a sorting by falling back to SOP Instance UID. */ gdcm::Sorter sorter; sorter.SetSortFunction(DicomSeriesReader::GdcmSortFunction); try { if (sorter.Sort(unsortedFilenames)) { return sorter.GetFilenames(); } else { MITK_WARN << "Sorting error. Leaving series unsorted."; return unsortedFilenames; } } catch (std::logic_error &) { MITK_WARN << "Sorting error. Leaving series unsorted."; return unsortedFilenames; } } bool DicomSeriesReader::GdcmSortFunction(const gdcm::DataSet &ds1, const gdcm::DataSet &ds2) { // This method MUST accept missing location and position information (and all else, too) // because we cannot rely on anything // (restriction on the sentence before: we have to provide consistent sorting, so we // rely on the minimum information all DICOM files need to provide: SOP Instance UID) /* we CAN expect a group of equal - series instance uid - image orientation - pixel spacing - imager pixel spacing - slice thickness - number of rows/columns */ static const gdcm::Tag tagImagePositionPatient(0x0020, 0x0032); // Image Position (Patient) static const gdcm::Tag tagImageOrientation(0x0020, 0x0037); // Image Orientation // see if we have Image Position and Orientation if (ds1.FindDataElement(tagImagePositionPatient) && ds1.FindDataElement(tagImageOrientation) && ds2.FindDataElement(tagImagePositionPatient) && ds2.FindDataElement(tagImageOrientation)) { gdcm::Attribute<0x0020, 0x0032> image_pos1; // Image Position (Patient) gdcm::Attribute<0x0020, 0x0037> image_orientation1; // Image Orientation (Patient) image_pos1.Set(ds1); image_orientation1.Set(ds1); gdcm::Attribute<0x0020, 0x0032> image_pos2; gdcm::Attribute<0x0020, 0x0037> image_orientation2; image_pos2.Set(ds2); image_orientation2.Set(ds2); /* we tolerate very small differences in image orientation, since we got to know about acquisitions where these values change across a single series (7th decimal digit) (http://bugs.mitk.org/show_bug.cgi?id=12263) still, we want to check if our assumption of 'almost equal' orientations is valid */ for (unsigned int dim = 0; dim < 6; ++dim) { if (fabs(image_orientation2[dim] - image_orientation1[dim]) > 0.0001) { MITK_ERROR << "Dicom images have different orientations."; throw std::logic_error( "Dicom images have different orientations. Call GetSeries() first to separate images."); } } double normal[3]; normal[0] = image_orientation1[1] * image_orientation1[5] - image_orientation1[2] * image_orientation1[4]; normal[1] = image_orientation1[2] * image_orientation1[3] - image_orientation1[0] * image_orientation1[5]; normal[2] = image_orientation1[0] * image_orientation1[4] - image_orientation1[1] * image_orientation1[3]; double dist1 = 0.0, dist2 = 0.0; // this computes the distance from world origin (0,0,0) ALONG THE NORMAL of the image planes for (unsigned char i = 0u; i < 3u; ++i) { dist1 += normal[i] * image_pos1[i]; dist2 += normal[i] * image_pos2[i]; } // if we can sort by just comparing the distance, we do exactly that if (fabs(dist1 - dist2) >= mitk::eps) { // default: compare position return dist1 < dist2; } else // we need to check more properties to distinguish slices { // try to sort by Acquisition Number static const gdcm::Tag tagAcquisitionNumber(0x0020, 0x0012); if (ds1.FindDataElement(tagAcquisitionNumber) && ds2.FindDataElement(tagAcquisitionNumber)) { gdcm::Attribute<0x0020, 0x0012> acquisition_number1; // Acquisition number gdcm::Attribute<0x0020, 0x0012> acquisition_number2; acquisition_number1.Set(ds1); acquisition_number2.Set(ds2); if (acquisition_number1 != acquisition_number2) { return acquisition_number1 < acquisition_number2; } else // neither position nor acquisition number are good for sorting, so check more { // try to sort by Acquisition Time static const gdcm::Tag tagAcquisitionTime(0x0008, 0x0032); if (ds1.FindDataElement(tagAcquisitionTime) && ds2.FindDataElement(tagAcquisitionTime)) { gdcm::Attribute<0x0008, 0x0032> acquisition_time1; // Acquisition time gdcm::Attribute<0x0008, 0x0032> acquisition_time2; acquisition_time1.Set(ds1); acquisition_time2.Set(ds2); if (acquisition_time1 != acquisition_time2) { return acquisition_time1 < acquisition_time2; } else // we gave up on image position, acquisition number and acquisition time now { // let's try trigger time static const gdcm::Tag tagTriggerTime(0x0018, 0x1060); if (ds1.FindDataElement(tagTriggerTime) && ds2.FindDataElement(tagTriggerTime)) { gdcm::Attribute<0x0018, 0x1060> trigger_time1; // Trigger time gdcm::Attribute<0x0018, 0x1060> trigger_time2; trigger_time1.Set(ds1); trigger_time2.Set(ds2); if (trigger_time1 != trigger_time2) { return trigger_time1 < trigger_time2; } // ELSE! // for this and many previous ifs we fall through if nothing lets us sort } // . } // . } // . } } } } // . // LAST RESORT: all valuable information for sorting is missing. // Sort by some meaningless but unique identifiers to satisfy the sort function static const gdcm::Tag tagSOPInstanceUID(0x0008, 0x0018); if (ds1.FindDataElement(tagSOPInstanceUID) && ds2.FindDataElement(tagSOPInstanceUID)) { MITK_DEBUG << "Dicom images are missing attributes for a meaningful sorting, falling back to SOP instance UID comparison."; gdcm::Attribute<0x0008, 0x0018> SOPInstanceUID1; // SOP instance UID is mandatory and unique gdcm::Attribute<0x0008, 0x0018> SOPInstanceUID2; SOPInstanceUID1.Set(ds1); SOPInstanceUID2.Set(ds2); return SOPInstanceUID1 < SOPInstanceUID2; } else { // no DICOM file should really come down here, this should only be reached with unskillful and unlucky // manipulation // of files std::string error_message("Malformed DICOM images, which do not even contain a SOP Instance UID."); MITK_ERROR << error_message; throw std::logic_error(error_message); } } std::string DicomSeriesReader::GetConfigurationString() { std::stringstream configuration; configuration << "MITK_USE_GDCMIO: "; configuration << "true"; configuration << "\n"; configuration << "GDCM_VERSION: "; #ifdef GDCM_MAJOR_VERSION configuration << GDCM_VERSION; #endif // configuration << "\n"; return configuration.str(); } void DicomSeriesReader::CopyMetaDataToImageProperties(StringContainer filenames, const gdcm::Scanner::MappingType &tagValueMappings_, DcmIoType *io, const ImageBlockDescriptor &blockInfo, Image *image) { std::list imageBlock; imageBlock.push_back(filenames); CopyMetaDataToImageProperties(imageBlock, tagValueMappings_, io, blockInfo, image); } void DicomSeriesReader::CopyMetaDataToImageProperties(std::list imageBlock, const gdcm::Scanner::MappingType &tagValueMappings_, DcmIoType *io, const ImageBlockDescriptor &blockInfo, Image *image) { if (!io || !image) return; StringLookupTable filesForSlices; StringLookupTable sliceLocationForSlices; StringLookupTable instanceNumberForSlices; StringLookupTable SOPInstanceNumberForSlices; auto &tagValueMappings = const_cast(tagValueMappings_); // DICOM tags which should be added to the image properties const gdcm::Tag tagSliceLocation(0x0020, 0x1041); // slice location const gdcm::Tag tagInstanceNumber(0x0020, 0x0013); // (image) instance number const gdcm::Tag tagSOPInstanceNumber(0x0008, 0x0018); // SOP instance number unsigned int timeStep(0); std::string propertyKeySliceLocation = "dicom.image.0020.1041"; std::string propertyKeyInstanceNumber = "dicom.image.0020.0013"; std::string propertyKeySOPInstanceNumber = "dicom.image.0008.0018"; // tags for each image for (auto i = imageBlock.begin(); i != imageBlock.end(); i++, timeStep++) { const StringContainer &files = (*i); unsigned int slice(0); for (auto fIter = files.begin(); fIter != files.end(); ++fIter, ++slice) { filesForSlices.SetTableValue(slice, *fIter); gdcm::Scanner::TagToValue tagValueMapForFile = tagValueMappings[fIter->c_str()]; if (tagValueMapForFile.find(tagSliceLocation) != tagValueMapForFile.end()) sliceLocationForSlices.SetTableValue(slice, tagValueMapForFile[tagSliceLocation]); if (tagValueMapForFile.find(tagInstanceNumber) != tagValueMapForFile.end()) instanceNumberForSlices.SetTableValue(slice, tagValueMapForFile[tagInstanceNumber]); if (tagValueMapForFile.find(tagSOPInstanceNumber) != tagValueMapForFile.end()) SOPInstanceNumberForSlices.SetTableValue(slice, tagValueMapForFile[tagSOPInstanceNumber]); } image->SetProperty("files", StringLookupTableProperty::New(filesForSlices)); // If more than one time step add postfix ".t" + timestep if (timeStep != 0) { std::ostringstream postfix; postfix << ".t" << timeStep; propertyKeySliceLocation.append(postfix.str()); propertyKeyInstanceNumber.append(postfix.str()); propertyKeySOPInstanceNumber.append(postfix.str()); } image->SetProperty(propertyKeySliceLocation.c_str(), StringLookupTableProperty::New(sliceLocationForSlices)); image->SetProperty(propertyKeyInstanceNumber.c_str(), StringLookupTableProperty::New(instanceNumberForSlices)); image->SetProperty(propertyKeySOPInstanceNumber.c_str(), StringLookupTableProperty::New(SOPInstanceNumberForSlices)); } // Copy tags for series, study, patient level (leave interpretation to application). // These properties will be copied to the DataNode by DicomSeriesReader. // tags for the series (we just use the one that ITK copied to its dictionary (proably that of the last slice) const itk::MetaDataDictionary &dict = io->GetMetaDataDictionary(); const TagToPropertyMapType &propertyLookup = DicomSeriesReader::GetDICOMTagsToMITKPropertyMap(); auto dictIter = dict.Begin(); while (dictIter != dict.End()) { // MITK_DEBUG << "Key " << dictIter->first; std::string value; if (itk::ExposeMetaData(dict, dictIter->first, value)) { // MITK_DEBUG << "Value " << value; auto valuePosition = propertyLookup.find(dictIter->first); if (valuePosition != propertyLookup.end()) { std::string propertyKey = valuePosition->second; // MITK_DEBUG << "--> " << propertyKey; image->SetProperty(propertyKey.c_str(), StringProperty::New(value)); } } else { MITK_WARN << "Tag " << dictIter->first << " not read as string as expected. Ignoring..."; } ++dictIter; } // copy imageblockdescriptor as properties image->SetProperty("dicomseriesreader.SOPClass", StringProperty::New(blockInfo.GetSOPClassUIDAsString())); image->SetProperty( "dicomseriesreader.ReaderImplementationLevelString", StringProperty::New(ReaderImplementationLevelToString(blockInfo.GetReaderImplementationLevel()))); image->SetProperty("dicomseriesreader.ReaderImplementationLevel", GenericProperty::New(blockInfo.GetReaderImplementationLevel())); image->SetProperty("dicomseriesreader.PixelSpacingInterpretationString", StringProperty::New(PixelSpacingInterpretationToString(blockInfo.GetPixelSpacingType()))); image->SetProperty("dicomseriesreader.PixelSpacingInterpretation", GenericProperty::New(blockInfo.GetPixelSpacingType())); image->SetProperty("dicomseriesreader.MultiFrameImage", BoolProperty::New(blockInfo.IsMultiFrameImage())); image->SetProperty("dicomseriesreader.GantyTiltCorrected", BoolProperty::New(blockInfo.HasGantryTiltCorrected())); image->SetProperty("dicomseriesreader.3D+t", BoolProperty::New(blockInfo.HasMultipleTimePoints())); } void DicomSeriesReader::FixSpacingInformation(mitk::Image *image, const ImageBlockDescriptor &imageBlockDescriptor) { // spacing provided by ITK/GDCM Vector3D imageSpacing = image->GetGeometry()->GetSpacing(); ScalarType imageSpacingX = imageSpacing[0]; ScalarType imageSpacingY = imageSpacing[1]; // spacing as desired by MITK (preference for "in patient", else "on detector", or "1.0/1.0") ScalarType desiredSpacingX = imageSpacingX; ScalarType desiredSpacingY = imageSpacingY; imageBlockDescriptor.GetDesiredMITKImagePixelSpacing(desiredSpacingX, desiredSpacingY); MITK_DEBUG << "Loaded spacing: " << imageSpacingX << "/" << imageSpacingY; MITK_DEBUG << "Corrected spacing: " << desiredSpacingX << "/" << desiredSpacingY; imageSpacing[0] = desiredSpacingX; imageSpacing[1] = desiredSpacingY; image->GetGeometry()->SetSpacing(imageSpacing); } void DicomSeriesReader::LoadDicom(const StringContainer &filenames, DataNode &node, bool sort, bool load4D, bool correctTilt, UpdateCallBackMethod callback, Image::Pointer preLoadedImageBlock) { mitk::LocaleSwitch localeSwitch("C"); std::locale previousCppLocale(std::cin.getloc()); std::locale l("C"); std::cin.imbue(l); ImageBlockDescriptor imageBlockDescriptor; const gdcm::Tag tagImagePositionPatient(0x0020, 0x0032); // Image Position (Patient) const gdcm::Tag tagImageOrientation(0x0020, 0x0037); // Image Orientation const gdcm::Tag tagSeriesInstanceUID(0x0020, 0x000e); // Series Instance UID const gdcm::Tag tagSOPClassUID(0x0008, 0x0016); // SOP class UID const gdcm::Tag tagModality(0x0008, 0x0060); // modality const gdcm::Tag tagPixelSpacing(0x0028, 0x0030); // pixel spacing const gdcm::Tag tagImagerPixelSpacing(0x0018, 0x1164); // imager pixel spacing const gdcm::Tag tagNumberOfFrames(0x0028, 0x0008); // number of frames try { Image::Pointer image = preLoadedImageBlock.IsNull() ? Image::New() : preLoadedImageBlock; CallbackCommand *command = callback ? new CallbackCommand(callback) : nullptr; bool initialize_node = false; /* special case for Philips 3D+t ultrasound images */ if (DicomSeriesReader::IsPhilips3DDicom(filenames.front().c_str())) { // TODO what about imageBlockDescriptor? // TODO what about preLoadedImageBlock? ReadPhilips3DDicom(filenames.front().c_str(), image); initialize_node = true; } else { /* default case: assume "normal" image blocks, possibly 3D+t */ bool canLoadAs4D(true); gdcm::Scanner scanner; ScanForSliceInformation(filenames, scanner); // need non-const access for map auto &tagValueMappings = const_cast(scanner.GetMappings()); std::list imageBlocks = SortIntoBlocksFor3DplusT(filenames, tagValueMappings, sort, canLoadAs4D); unsigned int volume_count = imageBlocks.size(); imageBlockDescriptor.SetSeriesInstanceUID( DicomSeriesReader::ConstCharStarToString(scanner.GetValue(filenames.front().c_str(), tagSeriesInstanceUID))); imageBlockDescriptor.SetSOPClassUID( DicomSeriesReader::ConstCharStarToString(scanner.GetValue(filenames.front().c_str(), tagSOPClassUID))); imageBlockDescriptor.SetModality( DicomSeriesReader::ConstCharStarToString(scanner.GetValue(filenames.front().c_str(), tagModality))); imageBlockDescriptor.SetNumberOfFrames( ConstCharStarToString(scanner.GetValue(filenames.front().c_str(), tagNumberOfFrames))); imageBlockDescriptor.SetPixelSpacingInformation( ConstCharStarToString(scanner.GetValue(filenames.front().c_str(), tagPixelSpacing)), ConstCharStarToString(scanner.GetValue(filenames.front().c_str(), tagImagerPixelSpacing))); GantryTiltInformation tiltInfo; // check possibility of a single slice with many timesteps. In this case, don't check for tilt, no second slice // possible if (!imageBlocks.empty() && imageBlocks.front().size() > 1 && correctTilt) { // check tiltedness here, potentially fixup ITK's loading result by shifting slice contents // check first and last position slice from tags, make some calculations to detect tilt std::string firstFilename(imageBlocks.front().front()); // calculate from first and last slice to minimize rounding errors std::string secondFilename(imageBlocks.front().back()); std::string imagePosition1( ConstCharStarToString(tagValueMappings[firstFilename.c_str()][tagImagePositionPatient])); std::string imageOrientation( ConstCharStarToString(tagValueMappings[firstFilename.c_str()][tagImageOrientation])); std::string imagePosition2( ConstCharStarToString(tagValueMappings[secondFilename.c_str()][tagImagePositionPatient])); bool ignoredConversionError(-42); // hard to get here, no graceful way to react Point3D origin1(DICOMStringToPoint3D(imagePosition1, ignoredConversionError)); Point3D origin2(DICOMStringToPoint3D(imagePosition2, ignoredConversionError)); Vector3D right; right.Fill(0.0); Vector3D up; right.Fill(0.0); // might be down as well, but it is just a name at this point DICOMStringToOrientationVectors(imageOrientation, right, up, ignoredConversionError); tiltInfo = GantryTiltInformation(origin1, origin2, right, up, filenames.size() - 1); correctTilt = tiltInfo.IsSheared() && tiltInfo.IsRegularGantryTilt(); } else { correctTilt = false; // we CANNOT do that } imageBlockDescriptor.SetHasGantryTiltCorrected(correctTilt); if (volume_count == 1 || !canLoadAs4D || !load4D) { DcmIoType::Pointer io; image = MultiplexLoadDICOMByITK( imageBlocks.front(), correctTilt, tiltInfo, io, command, preLoadedImageBlock); // load first 3D block imageBlockDescriptor.AddFiles(imageBlocks.front()); // only the first part is loaded imageBlockDescriptor.SetHasMultipleTimePoints(false); FixSpacingInformation(image, imageBlockDescriptor); CopyMetaDataToImageProperties(imageBlocks.front(), scanner.GetMappings(), io, imageBlockDescriptor, image); initialize_node = true; } else if (volume_count > 1) { imageBlockDescriptor.AddFiles(filenames); // all is loaded imageBlockDescriptor.SetHasMultipleTimePoints(true); DcmIoType::Pointer io; image = MultiplexLoadDICOMByITK4D( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); initialize_node = true; } } if (initialize_node) { // forward some image properties to node node.GetPropertyList()->ConcatenatePropertyList(image->GetPropertyList(), true); std::string patientName = "NoName"; if (node.GetProperty("dicom.patient.PatientsName")) patientName = node.GetProperty("dicom.patient.PatientsName")->GetValueAsString(); node.SetData(image); node.SetName(patientName); std::cin.imbue(previousCppLocale); } MITK_DEBUG << "--------------------------------------------------------------------------------"; MITK_DEBUG << "DICOM files loaded (from series UID " << imageBlockDescriptor.GetSeriesInstanceUID() << "):"; MITK_DEBUG << " " << imageBlockDescriptor.GetFilenames().size() << " '" << imageBlockDescriptor.GetModality() << "' files (" << imageBlockDescriptor.GetSOPClassUIDAsString() << ") loaded into 1 mitk::Image"; MITK_DEBUG << " multi-frame: " << (imageBlockDescriptor.IsMultiFrameImage() ? "Yes" : "No"); MITK_DEBUG << " reader support: " << ReaderImplementationLevelToString(imageBlockDescriptor.GetReaderImplementationLevel()); MITK_DEBUG << " pixel spacing type: " << PixelSpacingInterpretationToString(imageBlockDescriptor.GetPixelSpacingType()) << " " << image->GetGeometry()->GetSpacing()[0] << "/" << image->GetGeometry()->GetSpacing()[0]; MITK_DEBUG << " gantry tilt corrected: " << (imageBlockDescriptor.HasGantryTiltCorrected() ? "Yes" : "No"); MITK_DEBUG << " 3D+t: " << (imageBlockDescriptor.HasMultipleTimePoints() ? "Yes" : "No"); MITK_DEBUG << "--------------------------------------------------------------------------------"; } catch (std::exception &e) { // reset locale then throw up std::cin.imbue(previousCppLocale); MITK_DEBUG << "Caught exception in DicomSeriesReader::LoadDicom"; throw e; } } void DicomSeriesReader::ScanForSliceInformation(const StringContainer &filenames, gdcm::Scanner &scanner) { const gdcm::Tag tagImagePositionPatient(0x0020, 0x0032); // Image position (Patient) scanner.AddTag(tagImagePositionPatient); const gdcm::Tag tagSeriesInstanceUID(0x0020, 0x000e); // Series Instance UID scanner.AddTag(tagSeriesInstanceUID); const gdcm::Tag tagImageOrientation(0x0020, 0x0037); // Image orientation scanner.AddTag(tagImageOrientation); const gdcm::Tag tagSliceLocation(0x0020, 0x1041); // slice location scanner.AddTag(tagSliceLocation); const gdcm::Tag tagInstanceNumber(0x0020, 0x0013); // (image) instance number scanner.AddTag(tagInstanceNumber); const gdcm::Tag tagSOPInstanceNumber(0x0008, 0x0018); // SOP instance number scanner.AddTag(tagSOPInstanceNumber); const gdcm::Tag tagPixelSpacing(0x0028, 0x0030); // Pixel Spacing scanner.AddTag(tagPixelSpacing); const gdcm::Tag tagImagerPixelSpacing(0x0018, 0x1164); // Imager Pixel Spacing scanner.AddTag(tagImagerPixelSpacing); const gdcm::Tag tagModality(0x0008, 0x0060); // Modality scanner.AddTag(tagModality); const gdcm::Tag tagSOPClassUID(0x0008, 0x0016); // SOP Class UID scanner.AddTag(tagSOPClassUID); const gdcm::Tag tagNumberOfFrames(0x0028, 0x0008); // number of frames scanner.AddTag(tagNumberOfFrames); scanner.Scan(filenames); // make available image information for each file } std::list DicomSeriesReader::SortIntoBlocksFor3DplusT( const StringContainer &presortedFilenames, const gdcm::Scanner::MappingType &tagValueMappings, bool /*sort*/, bool &canLoadAs4D) { std::list imageBlocks; // ignore sort request, because most likely re-sorting is now needed due to changes in GetSeries(bug #8022) StringContainer sorted_filenames = DicomSeriesReader::SortSeriesSlices(presortedFilenames); std::string firstPosition; unsigned int numberOfBlocks(0); // number of 3D image blocks static const gdcm::Tag tagImagePositionPatient(0x0020, 0x0032); // Image position (Patient) const gdcm::Tag tagModality(0x0008, 0x0060); // loop files to determine number of image blocks for (StringContainer::const_iterator fileIter = sorted_filenames.begin(); fileIter != sorted_filenames.end(); ++fileIter) { gdcm::Scanner::TagToValue tagToValueMap = tagValueMappings.find(fileIter->c_str())->second; if (tagToValueMap.find(tagImagePositionPatient) == tagToValueMap.end()) { const std::string &modality = tagToValueMap.find(tagModality)->second; if (modality.compare("RTIMAGE ") == 0 || modality.compare("RTIMAGE") == 0) { MITK_WARN << "Modality " << modality << " is not fully supported yet."; numberOfBlocks = 1; break; } else { // we expect to get images w/ missing position information ONLY as separated blocks. assert(presortedFilenames.size() == 1); numberOfBlocks = 1; break; } } std::string position = tagToValueMap.find(tagImagePositionPatient)->second; MITK_DEBUG << " " << *fileIter << " at " << position; if (firstPosition.empty()) { firstPosition = position; } if (position == firstPosition) { ++numberOfBlocks; } else { break; // enough information to know the number of image blocks } } MITK_DEBUG << " ==> Assuming " << numberOfBlocks << " time steps"; if (numberOfBlocks == 0) return imageBlocks; // only possible if called with no files // loop files to sort them into image blocks unsigned int numberOfExpectedSlices(0); for (unsigned int block = 0; block < numberOfBlocks; ++block) { StringContainer filesOfCurrentBlock; for (StringContainer::const_iterator fileIter = sorted_filenames.begin() + block; fileIter != sorted_filenames.end(); // fileIter += numberOfBlocks) // TODO shouldn't this work? give invalid iterators on first attempts ) { filesOfCurrentBlock.push_back(*fileIter); for (unsigned int b = 0; b < numberOfBlocks; ++b) { if (fileIter != sorted_filenames.end()) ++fileIter; } } imageBlocks.push_back(filesOfCurrentBlock); if (block == 0) { numberOfExpectedSlices = filesOfCurrentBlock.size(); } else { if (filesOfCurrentBlock.size() != numberOfExpectedSlices) { MITK_WARN << "DicomSeriesReader expected " << numberOfBlocks << " image blocks of " << numberOfExpectedSlices << " images each. Block " << block << " got " << filesOfCurrentBlock.size() << " instead. Cannot load this as 3D+t"; // TODO implement recovery (load as many slices 3D+t as much // as possible) canLoadAs4D = false; } } } return imageBlocks; } Image::Pointer DicomSeriesReader::MultiplexLoadDICOMByITK(const StringContainer &filenames, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, Image::Pointer preLoadedImageBlock) { io = DcmIoType::New(); io->SetFileName(filenames.front().c_str()); io->ReadImageInformation(); if (io->GetPixelType() == itk::ImageIOBase::SCALAR) { return MultiplexLoadDICOMByITKScalar(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); } else if (io->GetPixelType() == itk::ImageIOBase::RGB) { return MultiplexLoadDICOMByITKRGBPixel(filenames, correctTilt, tiltInfo, io, command, preLoadedImageBlock); } else { return nullptr; } } Image::Pointer DicomSeriesReader::MultiplexLoadDICOMByITK4D(std::list &imageBlocks, ImageBlockDescriptor imageBlockDescriptor, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, Image::Pointer preLoadedImageBlock) { io = DcmIoType::New(); io->SetFileName(imageBlocks.front().front().c_str()); io->ReadImageInformation(); if (io->GetPixelType() == itk::ImageIOBase::SCALAR) { return MultiplexLoadDICOMByITK4DScalar( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); } else if (io->GetPixelType() == itk::ImageIOBase::RGB) { return MultiplexLoadDICOMByITK4DRGBPixel( imageBlocks, imageBlockDescriptor, correctTilt, tiltInfo, io, command, preLoadedImageBlock); } else { return nullptr; } } } // end namespace mitk diff --git a/Modules/Core/include/mitkDicomSeriesReader.h b/Modules/DICOMReader/src/legacy/mitkDicomSeriesReader.h similarity index 99% rename from Modules/Core/include/mitkDicomSeriesReader.h rename to Modules/DICOMReader/src/legacy/mitkDicomSeriesReader.h index 2250c8f41d..863792524c 100644 --- a/Modules/Core/include/mitkDicomSeriesReader.h +++ b/Modules/DICOMReader/src/legacy/mitkDicomSeriesReader.h @@ -1,1023 +1,1023 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkDicomSeriesReader_h #define mitkDicomSeriesReader_h #include "mitkConfig.h" #include "mitkDataNode.h" #include #include #include #ifdef NOMINMAX #define DEF_NOMINMAX #undef NOMINMAX #endif #include #ifdef DEF_NOMINMAX #ifndef NOMINMAX #define NOMINMAX #endif #undef DEF_NOMINMAX #endif #include #include namespace mitk { /** \brief Loading DICOM images as MITK images. - \ref DicomSeriesReader_purpose - \ref DicomSeriesReader_limitations - \ref DicomSeriesReader_usage - \ref DicomSeriesReader_sorting - \ref DicomSeriesReader_sorting1 - \ref DicomSeriesReader_sorting2 - \ref DicomSeriesReader_sorting3 - \ref DicomSeriesReader_sorting4 - \ref DicomSeriesReader_gantrytilt - \ref DicomSeriesReader_pixelspacing - \ref DicomSeriesReader_nextworkitems - \ref DicomSeriesReader_whynotinitk - \ref DicomSeriesReader_tests \section DicomSeriesReader_purpose Purpose DicomSeriesReader serves as a central class for loading DICOM images as mitk::Image. As the term "DICOM image" covers a huge variety of possible modalities and implementations, and since MITK assumes that 3D images are made up of continuous blocks of slices without any gaps or changes in orientation, the loading mechanism must implement a number of decisions and compromises. The main intention of this implementation is not efficiency but correctness of generated slice positions and pixel spacings! \section DicomSeriesReader_limitations Assumptions and limitations The class is working only with GDCM 2.0.14 (or possibly newer). This version is the default of an MITK super-build. Support for other versions or ITK's DicomIO was dropped because of the associated complexity of DicomSeriesReader. \b Assumptions - expected to work with certain SOP Classes (mostly CT Image Storage and MR Image Storage) - see ImageBlockDescriptor.GetReaderImplementationLevel() method for the details - special treatment for a certain type of Philips 3D ultrasound (recogized by tag 3001,0010 set to "Philips3D") - loader will always attempt to read multiple single slices as a single 3D image volume (i.e. mitk::Image) - slices will be grouped by basic properties such as orientation, rows, columns, spacing and grouped into as large blocks as possible - images which do NOT report a position or orientation in space (Image Position Patient, Image Orientation) will be assigned defaults - image position (0,0,0) - image orientation (1,0,0), (0,1,0) - such images will always be grouped separately since spatial grouping / sorting makes no sense for them \b Options - images that cover the same piece of space (i.e. position, orientation, and dimensions are equal) can be interpreted as time-steps of the same image, i.e. a series will be loaded as 3D+t \b Limitations - the 3D+t assumption only works if all time-steps have an equal number of slices and if all have the Acquisition Time attribute set to meaningful values \section DicomSeriesReader_usage Usage The starting point for an application is a set of DICOM files that should be loaded. For convenience, DicomSeriesReader can also parse a whole directory for DICOM files, but an application should better know exactly what to load. Loading is then done in two steps: 1. Group the files into spatial blocks by calling GetSeries(). This method will sort all passed files into meaningful blocks that could fit into an mitk::Image. Sorting for 3D+t loading is optional but default. The \b return value of this function is a list of descriptors, which describe a grouped list of files with its most basic properties: - SOP Class (CT Image Storage, Secondary Capture Image Storage, etc.) - Modality - What type of pixel spacing can be read from the provided DICOM tags - How well DicomSeriesReader is prepared to load this type of data 2. Load a sorted set of files by calling LoadDicomSeries(). This method expects go receive the sorting output of GetSeries(). The method will then invoke ITK methods configured with GDCM-IO classes to actually load the files into memory and put them into mitk::Images. Again, loading as 3D+t is optional. Example: \code // only a directory is known at this point: /home/who/dicom DicomSeriesReader::FileNamesGrouping allImageBlocks = DicomSeriesReader::GetSeries("/home/who/dicom/"); // file now divided into groups of identical image size, orientation, spacing, etc. // each of these lists should be loadable as an mitk::Image. DicomSeriesReader::StringContainer seriesToLoad = allImageBlocks[...]; // decide what to load // final step: load into DataNode (can result in 3D+t image) DataNode::Pointer node = DicomSeriesReader::LoadDicomSeries( oneBlockSorted ); itk::SmartPointer image = dynamic_cast( node->GetData() ); \endcode \section DicomSeriesReader_sorting Logic for sorting 2D slices from DICOM images into 3D+t blocks for mitk::Image The general sorting mechanism (implemented in GetSeries) groups and sorts a set of DICOM files, each assumed to contain a single CT/MR slice. In the following we refer to those file groups as "blocks", since this is what they are meant to become when loaded into an mitk::Image. \subsection DicomSeriesReader_sorting1 Step 1: Avoiding pure non-sense A first pass separates slices that cannot possibly be loaded together because of restrictions of mitk::Image. After this steps, each block contains only slices that match in all of the following DICOM tags: - (0020,000e) Series Instance UID - (0020,0037) Image Orientation - (0028,0030) Pixel Spacing - (0018,1164) Imager Pixel Spacing - (0018,0050) Slice Thickness - (0028,0010) Number Of Rows - (0028,0011) Number Of Columns - (0028,0008) Number Of Frames \subsection DicomSeriesReader_sorting2 Step 2: Sort slices spatially Before slices are further analyzed, they are sorted spatially. As implemented by GdcmSortFunction(), slices are sorted by 1. distance from origin (calculated using (0020,0032) Image Position Patient and (0020,0037) Image Orientation) 2. when distance is equal, (0020,0012) Aquisition Number, (0008,0032) Acquisition Time and (0018,1060) Trigger Time are used as a backup criterions (necessary for meaningful 3D+t sorting) \subsection DicomSeriesReader_sorting3 Step 3: Ensure equal z spacing Since inter-slice distance is not recorded in DICOM tags, we must ensure that blocks are made up of slices that have equal distances between neighboring slices. This is especially necessary because itk::ImageSeriesReader is later used for the actual loading, and this class expects (and does nocht verify) equal inter-slice distance (see \ref DicomSeriesReader_whatweknowaboutitk). To achieve such grouping, the inter-slice distance is calculated from the first two different slice positions of a block. Following slices are added to a block as long as they can be added by adding the calculated inter-slice distance to the last slice of the block. Slices that do not fit into the expected distance pattern, are set aside for further analysis. This grouping is done until each file has been assigned to a group. Slices that share a position in space are also sorted into separate blocks during this step. So the result of this step is a set of blocks that contain only slices with equal z spacing and uniqe slices at each position. \subsection DicomSeriesReader_sorting4 Step 4 (optional): group 3D blocks as 3D+t when possible This last step depends on an option of GetSeries(). When requested, image blocks from the previous step are merged again whenever two blocks occupy the same portion of space (i.e. same origin, number of slices and z-spacing). \section DicomSeriesReader_gantrytilt Handling of gantry tilt When CT gantry tilt is used, the gantry plane (= X-Ray source and detector ring) and the vertical plane do not align anymore. This scanner feature is used for example to reduce metal artifacs (e.g. Lee C , Evaluation of Using CT Gantry Tilt Scan on Head and Neck Cancer Patients with Dental Structure: Scans Show Less Metal Artifacts. Presented at: Radiological Society of North America 2011 Scientific Assembly and Annual Meeting; November 27- December 2, 2011 Chicago IL.). The acquired planes of such CT series do not match the expectations of a orthogonal geometry in mitk::Image: if you stack the slices, they show a small shift along the Y axis: \verbatim without tilt with tilt |||||| ////// |||||| ////// -- |||||| --------- ////// -------- table orientation |||||| ////// |||||| ////// Stacked slices: without tilt with tilt -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- \endverbatim As such gemetries do not in conjunction with mitk::Image, DicomSeriesReader performs a correction for such series if the groupImagesWithGantryTilt or correctGantryTilt flag in GetSeries and LoadDicomSeries is set (default = on). The correction algorithms undoes two errors introduced by ITK's ImageSeriesReader: - the plane shift that is ignored by ITK's reader is recreated by applying a shearing transformation using itk::ResampleFilter. - the spacing is corrected (it is calculated by ITK's reader from the distance between two origins, which is NOT the slice distance in this special case) Both errors are introduced in itkImageSeriesReader.txx (ImageSeriesReader::GenerateOutputInformation(void)), lines 176 to 245 (as of ITK 3.20) For the correction, we examine two consecutive slices of a series, both described as a pair (origin/orientation): - we calculate if the first origin is on a line along the normal of the second slice - if this is not the case, the geometry will not fit a normal mitk::Image/mitk::Geometry3D - we then project the second origin into the first slice's coordinate system to quantify the shift - both is done in class GantryTiltInformation with quite some comments. The geometry of image stacks with tilted geometries is illustrated below: - green: the DICOM images as described by their tags: origin as a point with the line indicating the orientation - red: the output of ITK ImageSeriesReader: wrong, larger spacing, no tilt - blue: how much a shear must correct \image tilt-correction.jpg \section DicomSeriesReader_whatweknowaboutitk The actual image loading process When calling LoadDicomSeries(), this method "mainly" uses an instance of itk::ImageSeriesReader, configured with an itk::GDCMImageIO object. Because DicomSeriesReader works around some of the behaviors of these classes, the following is a list of features that we find in the code and need to work with: - itk::ImageSeriesReader::GenerateOutputInformation() does the z-spacing handling + spacing is directly determined by comparing (euclidean distance) the origins of the first two slices of a series * this is GOOD because there is no reliable z-spacing information in DICOM images * this is bad because it does not work with gantry tilt, in which case the slice distance is SMALLER than the distance between two origins (see section on tilt) - origin and spacing are calculated by GDCMImageIO and re-used in itk::ImageSeriesReader + the origins are read from appropriate tags, nothing special about that + the spacing is read by gdcm::ImageReader, gdcm::ImageHelper::GetSpacingValue() from a tag determined by gdcm::ImageHelper::GetSpacingTagFromMediaStorage(), which basically determines ONE appropriate pixel spacing tag for each media storage type (ct image, mr image, secondary capture image, etc.) * this is fine for modalities such as CT/MR where the "Pixel Spacing" tag is mandatory, but for other modalities such as CR or Secondary Capture, the tag "Imager Pixel Spacing" is taken, which is no only optional but also has a more complicated relation with the "Pixel Spacing" tag. For this reason we check/modify the pixel spacing reported by itk::ImageSeriesReader after loading the image (see \ref DicomSeriesReader_pixelspacing) AFTER loading, DicomSeriesReader marks some of its findings as mitk::Properties to the loaded Image and DataNode: - dicomseriesreader.SOPClass : DICOM SOP Class as readable string (instead of a UID) - dicomseriesreader.ReaderImplementationLevelString : Confidence /Support level of the reader for this image as readable string - dicomseriesreader.ReaderImplementationLevel : Confidence /Support level of the reader for this image as enum value of type ReaderImplementationLevel - dicomseriesreader.PixelSpacingInterpretationString : Appropriate interpreteation of pixel spacing for this Image as readable string - dicomseriesreader.PixelSpacingInterpretation : Appropriate interpreteation of pixel spacing for this Image as enum value of type PixelSpacingInterpretation - dicomseriesreader.MultiFrameImage : bool flag to mark multi-frame images - dicomseriesreader.GantyTiltCorrected : bool flag to mark images where a gantry tilt was corrected to fit slices into an mitk::Image - dicomseriesreader.3D+t : bool flag to mark images with a time dimension (multiple 3D blocks of the same size at the same position in space) \section DicomSeriesReader_pixelspacing Handling of pixel spacing The reader implementes what is described in DICOM Part 3, chapter 10.7 (Basic Pixel Spacing Calibration Macro): Both tags - (0028,0030) Pixel Spacing and - (0018,1164) Imager Pixel Spacing are evaluated and the pixel spacing is set to the spacing within the patient when tags allow that. The result of pixel spacing interpretation can be read from a property "dicomseriesreader.PixelSpacingInterpretation", which refers to one of the enumerated values of type PixelSpacingInterpretation; \section DicomSeriesReader_supportedmodalities Limitations for specific modalities - Enhanced Computed Tomography / Magnetic Resonance Images are currently NOT supported at all, because we lack general support for multi-frame images. - Nuclear Medicine Images are not supported fully supported, only the single-frame variants are loaded properly. \section DicomSeriesReader_nextworkitems Possible enhancements This is a short list of ideas for enhancement: - Class has historically grown and should be reviewed again. There is probably too many duplicated scanning code - Multi-frame images don't mix well with the curent assumption of "one file - one slice", which is assumed by our code - It should be checked how well GDCM and ITK support these files (some load, some don't) - Specializations such as the Philips 3D code should be handled in a more generic way. The current handling of Philips 3D images is not nice at all \section DicomSeriesReader_whynotinitk Why is this not in ITK? Some of this code would probably be better located in ITK. It is just a matter of resources that this is not the case yet. Any attempts into this direction are welcome and can be supported. At least the gantry tilt correction should be a simple addition to itk::ImageSeriesReader. \section DicomSeriesReader_tests Tests regarding DICOM loading A number of tests have been implemented to check our assumptions regarding DICOM loading. Please see \ref DICOMTesting \todo refactor all the protected helper objects/methods into a separate header so we compile faster */ class Image; - class MITKCORE_EXPORT DicomSeriesReader + class DicomSeriesReader { public: /** \brief Lists of filenames. */ typedef std::vector StringContainer; /** \brief Interface for the progress callback. */ typedef void (*UpdateCallBackMethod)(float); /** \brief Describes how well the reader is tested for a certain file type. Applications should not rely on the outcome for images which are reported ReaderImplementationLevel_Implemented or ReaderImplementationLevel_Unsupported. Errors to load images which are reported as ReaderImplementationLevel_Supported are considered bugs. For ReaderImplementationLevel_PartlySupported please check the appropriate paragraph in \ref DicomSeriesReader_supportedmodalities */ typedef enum { ReaderImplementationLevel_Supported, /// loader code and tests are established ReaderImplementationLevel_PartlySupported, /// loader code and tests are establised for specific parts of a SOP /// Class ReaderImplementationLevel_Implemented, /// loader code is implemented but not accompanied by tests ReaderImplementationLevel_Unsupported, /// loader code is not working with this SOP Class } ReaderImplementationLevel; /** \brief How the mitk::Image spacing should be interpreted. Compare DICOM PS 3.3 10.7 (Basic Pixel Spacing Calibration Macro). */ typedef enum { PixelSpacingInterpretation_SpacingInPatient, /// distances are mm within a patient PixelSpacingInterpretation_SpacingAtDetector, /// distances are mm at detector surface PixelSpacingInterpretation_SpacingUnknown /// NO spacing information is present, we use (1,1) as default } PixelSpacingInterpretation; /** \brief Return type of GetSeries, describes a logical group of files. Files grouped into a single 3D or 3D+t block are described by an instance of this class. Relevant descriptive properties can be used to provide the application user with meaningful choices. */ - class MITKCORE_EXPORT ImageBlockDescriptor + class ImageBlockDescriptor { public: /// List of files in this group StringContainer GetFilenames() const; /// A unique ID describing this bloc (enhanced Series Instance UID). std::string GetImageBlockUID() const; /// The Series Instance UID. std::string GetSeriesInstanceUID() const; /// Series Modality (CT, MR, etc.) std::string GetModality() const; /// SOP Class UID as readable string (Computed Tomography Image Storage, Secondary Capture Image Storage, etc.) std::string GetSOPClassUIDAsString() const; /// SOP Class UID as DICOM UID std::string GetSOPClassUID() const; /// Confidence of the reader that this block can be read successfully. ReaderImplementationLevel GetReaderImplementationLevel() const; /// Whether or not the block contains a gantry tilt which will be "corrected" during loading bool HasGantryTiltCorrected() const; /// Whether or not mitk::Image spacing relates to the patient bool PixelSpacingRelatesToPatient() const; /// Whether or not mitk::Image spacing relates to the detector surface bool PixelSpacingRelatesToDetector() const; /// Whether or not mitk::Image spacing is of unknown origin bool PixelSpacingIsUnknown() const; /// How the mitk::Image spacing can meaningfully be interpreted. PixelSpacingInterpretation GetPixelSpacingType() const; /// 3D+t or not bool HasMultipleTimePoints() const; /// Multi-frame image(s) or not bool IsMultiFrameImage() const; ImageBlockDescriptor(); ~ImageBlockDescriptor(); private: friend class DicomSeriesReader; ImageBlockDescriptor(const StringContainer &files); void AddFile(const std::string &file); void AddFiles(const StringContainer &files); void SetImageBlockUID(const std::string &uid); void SetSeriesInstanceUID(const std::string &uid); void SetModality(const std::string &modality); void SetNumberOfFrames(const std::string &); void SetSOPClassUID(const std::string &mediaStorageSOPClassUID); void SetHasGantryTiltCorrected(bool); void SetPixelSpacingInformation(const std::string &pixelSpacing, const std::string &imagerPixelSpacing); void SetHasMultipleTimePoints(bool); void GetDesiredMITKImagePixelSpacing(ScalarType &spacingX, ScalarType &spacingY) const; StringContainer m_Filenames; std::string m_ImageBlockUID; std::string m_SeriesInstanceUID; std::string m_Modality; std::string m_SOPClassUID; bool m_HasGantryTiltCorrected; std::string m_PixelSpacing; std::string m_ImagerPixelSpacing; bool m_HasMultipleTimePoints; bool m_IsMultiFrameImage; }; typedef std::map FileNamesGrouping; /** \brief Provide combination of preprocessor defines that was active during compilation. Since this class is a combination of several possible implementations, separated only by ifdef's, calling instances might want to know which flags were active at compile time. */ static std::string GetConfigurationString(); /** \brief Checks if a specific file contains DICOM data. */ static bool IsDicom(const std::string &filename); /** \brief see other GetSeries(). Find all series (and sub-series -- see details) in a particular directory. */ static FileNamesGrouping GetSeries(const std::string &dir, bool groupImagesWithGantryTilt, const StringContainer &restrictions = StringContainer()); /** \brief see other GetSeries(). \warning Untested, could or could not work. This differs only by having an additional restriction to a single known DICOM series. Internally, it uses the other GetSeries() method. */ static StringContainer GetSeries(const std::string &dir, const std::string &series_uid, bool groupImagesWithGantryTilt, const StringContainer &restrictions = StringContainer()); /** \brief PREFERRED version of this method - scan and sort DICOM files. Parse a list of files for images of DICOM series. For each series, an enumeration of the files contained in it is created. \return The resulting maps UID-like keys (based on Series Instance UID and slice properties) to sorted lists of file names. SeriesInstanceUID will be enhanced to be unique for each set of file names that is later loadable as a single mitk::Image. This implies that Image orientation, slice thickness, pixel spacing, rows, and columns must be the same for each file (i.e. the image slice contained in the file). If this separation logic requires that a SeriesInstanceUID must be made more specialized, it will follow the same logic as itk::GDCMSeriesFileNames to enhance the UID with more digits and dots. Optionally, more tags can be used to separate files into different logical series by setting the restrictions parameter. \warning Adding restrictions is not yet implemented! */ static FileNamesGrouping GetSeries(const StringContainer &files, bool sortTo3DPlust, bool groupImagesWithGantryTilt, const StringContainer &restrictions = StringContainer()); /** \brief See other GetSeries(). Use GetSeries(const StringContainer& files, bool sortTo3DPlust, const StringContainer &restrictions) instead. */ static FileNamesGrouping GetSeries(const StringContainer &files, bool groupImagesWithGantryTilt, const StringContainer &restrictions = StringContainer()); /** Loads a DICOM series composed by the file names enumerated in the file names container. If a callback method is supplied, it will be called after every progress update with a progress value in [0,1]. \param filenames The filenames to load. \param sort Whether files should be sorted spatially (true) or not (false - maybe useful if presorted) \param load4D Whether to load the files as 3D+t (if possible) */ static DataNode::Pointer LoadDicomSeries(const StringContainer &filenames, bool sort = true, bool load4D = true, bool correctGantryTilt = true, UpdateCallBackMethod callback = nullptr, itk::SmartPointer preLoadedImageBlock = nullptr); /** \brief See LoadDicomSeries! Just a slightly different interface. If \p preLoadedImageBlock is provided, the reader will only "fake" loading and create appropriate mitk::Properties. */ static bool LoadDicomSeries(const StringContainer &filenames, DataNode &node, bool sort = true, bool load4D = true, bool correctGantryTilt = true, UpdateCallBackMethod callback = nullptr, itk::SmartPointer preLoadedImageBlock = nullptr); protected: /** \brief Return type of DicomSeriesReader::AnalyzeFileForITKImageSeriesReaderSpacingAssumption. Class contains the grouping result of method DicomSeriesReader::AnalyzeFileForITKImageSeriesReaderSpacingAssumption, which takes as input a number of images, which are all equally oriented and spatially sorted along their normal direction. The result contains of two blocks: a first one is the grouping result, all of those images can be loaded into one image block because they have an equal origin-to-origin distance without any gaps in-between. */ class SliceGroupingAnalysisResult { public: SliceGroupingAnalysisResult(); /** \brief Grouping result, all same origin-to-origin distance w/o gaps. */ StringContainer GetBlockFilenames(); /** \brief Remaining files, which could not be grouped. */ StringContainer GetUnsortedFilenames(); /** \brief Wheter or not the grouped result contain a gantry tilt. */ bool ContainsGantryTilt(); /** \brief Meant for internal use by AnalyzeFileForITKImageSeriesReaderSpacingAssumption only. */ void AddFileToSortedBlock(const std::string &filename); /** \brief Meant for internal use by AnalyzeFileForITKImageSeriesReaderSpacingAssumption only. */ void AddFileToUnsortedBlock(const std::string &filename); void AddFilesToUnsortedBlock(const StringContainer &filenames); /** \brief Meant for internal use by AnalyzeFileForITKImageSeriesReaderSpacingAssumption only. \todo Could make sense to enhance this with an instance of GantryTiltInformation to store the whole result! */ void FlagGantryTilt(); /** \brief Only meaningful for use by AnalyzeFileForITKImageSeriesReaderSpacingAssumption. */ void UndoPrematureGrouping(); protected: StringContainer m_GroupedFiles; StringContainer m_UnsortedFiles; bool m_GantryTilt; }; /** \brief Gantry tilt analysis result. Takes geometry information for two slices of a DICOM series and calculates whether these fit into an orthogonal block or not. If NOT, they can either be the result of an acquisition with gantry tilt OR completly broken by some shearing transformation. Most calculations are done in the constructor, results can then be read via the remaining methods. */ class GantryTiltInformation { public: // two types to avoid any rounding errors typedef itk::Point Point3Dd; typedef itk::Vector Vector3Dd; /** \brief Just so we can create empty instances for assigning results later. */ GantryTiltInformation(); /** \brief THE constructor, which does all the calculations. Determining the amount of tilt is done by checking the distances of origin1 from planes through origin2. Two planes are considered: - normal vector along normal of slices (right x up): gives the slice distance - normal vector along orientation vector "up": gives the shift parallel to the plane orientation The tilt angle can then be calculated from these distances \param origin1 origin of the first slice \param origin2 origin of the second slice \param right right/up describe the orientatation of borth slices \param up right/up describe the orientatation of borth slices \param numberOfSlicesApart how many slices are the given origins apart (1 for neighboring slices) */ GantryTiltInformation(const Point3D &origin1, const Point3D &origin2, const Vector3D &right, const Vector3D &up, unsigned int numberOfSlicesApart); /** \brief Whether the slices were sheared. True if any of the shifts along right or up vector are non-zero. */ bool IsSheared() const; /** \brief Whether the shearing is a gantry tilt or more complicated. Gantry tilt will only produce shifts in ONE orientation, not in both. Since the correction code currently only coveres one tilt direction AND we don't know of medical images with two tilt directions, the loading code wants to check if our assumptions are true. */ bool IsRegularGantryTilt() const; /** \brief The offset distance in Y direction for each slice in mm (describes the tilt result). */ double GetMatrixCoefficientForCorrectionInWorldCoordinates() const; /** \brief The z / inter-slice spacing. Needed to correct ImageSeriesReader's result. */ double GetRealZSpacing() const; /** \brief The shift between first and last slice in mm. Needed to resize an orthogonal image volume. */ double GetTiltCorrectedAdditionalSize() const; /** \brief Calculated tilt angle in degrees. */ double GetTiltAngleInDegrees() const; protected: /** \brief Projection of point p onto line through lineOrigin in direction of lineDirection. */ Point3D projectPointOnLine(Point3Dd p, Point3Dd lineOrigin, Vector3Dd lineDirection); double m_ShiftUp; double m_ShiftRight; double m_ShiftNormal; double m_ITKAssumedSliceSpacing; unsigned int m_NumberOfSlicesApart; }; /** \brief for internal sorting. */ typedef std::pair TwoStringContainers; /** \brief Maps DICOM tags to MITK properties. */ typedef std::map TagToPropertyMapType; /** \brief Ensure an equal z-spacing for a group of files. Takes as input a number of images, which are all equally oriented and spatially sorted along their normal direction. Internally used by GetSeries. Returns two lists: the first one contins slices of equal inter-slice spacing. The second list contains remaining files, which need to be run through AnalyzeFileForITKImageSeriesReaderSpacingAssumption again. Relevant code that is matched here is in itkImageSeriesReader.txx (ImageSeriesReader::GenerateOutputInformation(void)), lines 176 to 245 (as of ITK 3.20) */ static SliceGroupingAnalysisResult AnalyzeFileForITKImageSeriesReaderSpacingAssumption( const StringContainer &files, bool groupsOfSimilarImages, const gdcm::Scanner::MappingType &tagValueMappings_); /** \brief Safely convert const char* to std::string. */ static std::string ConstCharStarToString(const char *s); /** \brief Safely convert a string into pixel spacing x and y. */ static bool DICOMStringToSpacing(const std::string &s, ScalarType &spacingX, ScalarType &spacingY); /** \brief Convert DICOM string describing a point to Point3D. DICOM tags like ImagePositionPatient contain a position as float numbers separated by backslashes: \verbatim 42.7131\13.77\0.7 \endverbatim */ static Point3D DICOMStringToPoint3D(const std::string &s, bool &successful); /** \brief Convert DICOM string describing a point two Vector3D. DICOM tags like ImageOrientationPatient contain two vectors as float numbers separated by backslashes: \verbatim 42.7131\13.77\0.7\137.76\0.3 \endverbatim */ static void DICOMStringToOrientationVectors(const std::string &s, Vector3D &right, Vector3D &up, bool &successful); template static typename ImageType::Pointer // TODO this is NOT inplace! InPlaceFixUpTiltedGeometry(ImageType *input, const GantryTiltInformation &tiltInfo); /** \brief Sort a set of file names in an order that is meaningful for loading them into an mitk::Image. \warning This method assumes that input files are similar in basic properties such as slice thicknes, image orientation, pixel spacing, rows, columns. It should always be ok to put the result of a call to GetSeries(..) into this method. Sorting order is determined by 1. image position along its normal (distance from world origin) 2. acquisition time If P denotes a position and T denotes a time step, this method will order slices from three timesteps like this: \verbatim P1T1 P1T2 P1T3 P2T1 P2T2 P2T3 P3T1 P3T2 P3T3 \endverbatim */ static StringContainer SortSeriesSlices(const StringContainer &unsortedFilenames); public: /** \brief Checks if a specific file is a Philips3D ultrasound DICOM file. */ static bool IsPhilips3DDicom(const std::string &filename); static std::string ReaderImplementationLevelToString(const ReaderImplementationLevel &enumValue); static std::string PixelSpacingInterpretationToString(const PixelSpacingInterpretation &enumValue); protected: /** \brief Read a Philips3D ultrasound DICOM file and put into an mitk::Image. */ static bool ReadPhilips3DDicom(const std::string &filename, itk::SmartPointer output_image); /** \brief Construct a UID that takes into account sorting criteria from GetSeries(). */ static std::string CreateMoreUniqueSeriesIdentifier(gdcm::Scanner::TagToValue &tagValueMap); /** \brief Helper for CreateMoreUniqueSeriesIdentifier */ static std::string CreateSeriesIdentifierPart(gdcm::Scanner::TagToValue &tagValueMap, const gdcm::Tag &tag); /** \brief Helper for CreateMoreUniqueSeriesIdentifier */ static std::string IDifyTagValue(const std::string &value); typedef itk::GDCMImageIO DcmIoType; /** \brief Progress callback for DicomSeriesReader. */ class CallbackCommand : public itk::Command { public: CallbackCommand(UpdateCallBackMethod callback) : m_Callback(callback) {} void Execute(const itk::Object *caller, const itk::EventObject &) override { (*this->m_Callback)(static_cast(caller)->GetProgress()); } void Execute(itk::Object *caller, const itk::EventObject &) override { (*this->m_Callback)(static_cast(caller)->GetProgress()); } protected: UpdateCallBackMethod m_Callback; }; static void FixSpacingInformation(Image *image, const ImageBlockDescriptor &imageBlockDescriptor); /** \brief Scan for slice image information */ static void ScanForSliceInformation(const StringContainer &filenames, gdcm::Scanner &scanner); /** \brief Performs actual loading of a series and creates an image having the specified pixel type. */ static void LoadDicom(const StringContainer &filenames, DataNode &node, bool sort, bool check_4d, bool correctTilt, UpdateCallBackMethod callback, itk::SmartPointer preLoadedImageBlock); /** \brief Feed files into itk::ImageSeriesReader and retrieve a 3D MITK image. \param command can be used for progress reporting */ template static itk::SmartPointer LoadDICOMByITK(const StringContainer &, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer preLoadedImageBlock); static itk::SmartPointer MultiplexLoadDICOMByITK(const StringContainer &, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer preLoadedImageBlock); static itk::SmartPointer MultiplexLoadDICOMByITKScalar(const StringContainer &, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer preLoadedImageBlock); static itk::SmartPointer MultiplexLoadDICOMByITKRGBPixel(const StringContainer &, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer preLoadedImageBlock); template static itk::SmartPointer LoadDICOMByITK4D(std::list &imageBlocks, ImageBlockDescriptor imageBlockDescriptor, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer preLoadedImageBlock); static itk::SmartPointer MultiplexLoadDICOMByITK4D(std::list &imageBlocks, ImageBlockDescriptor imageBlockDescriptor, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer preLoadedImageBlock); static itk::SmartPointer MultiplexLoadDICOMByITK4DScalar(std::list &imageBlocks, ImageBlockDescriptor imageBlockDescriptor, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer preLoadedImageBlock); static itk::SmartPointer MultiplexLoadDICOMByITK4DRGBPixel(std::list &imageBlocks, ImageBlockDescriptor imageBlockDescriptor, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer preLoadedImageBlock); /** \brief Sort files into time step blocks of a 3D+t image. Called by LoadDicom. Expects to be fed a single list of filenames that have been sorted by GetSeries previously (one map entry). This method will check how many timestep can be filled with given files. Assumption is that the number of time steps is determined by how often the first position in space repeats. I.e. if the first three files in the input parameter all describe the same location in space, we'll construct three lists of files. and sort the remaining files into them. \todo We can probably remove this method if we somehow transfer 3D+t information from GetSeries to LoadDicomSeries. */ static std::list SortIntoBlocksFor3DplusT(const StringContainer &presortedFilenames, const gdcm::Scanner::MappingType &tagValueMappings_, bool sort, bool &canLoadAs4D); /** \brief Defines spatial sorting for sorting by GDCM 2. Sorts by image position along image normal (distance from world origin). In cases of conflict, acquisition time is used as a secondary sort criterium. */ static bool GdcmSortFunction(const gdcm::DataSet &ds1, const gdcm::DataSet &ds2); /** \brief Copy information about files and DICOM tags from ITK's MetaDataDictionary and from the list of input files to the PropertyList of mitk::Image. \todo Tag copy must follow; image level will cause some additional files parsing, probably. */ static void CopyMetaDataToImageProperties(StringContainer filenames, const gdcm::Scanner::MappingType &tagValueMappings_, DcmIoType *io, const ImageBlockDescriptor &blockInfo, Image *image); static void CopyMetaDataToImageProperties(std::list imageBlock, const gdcm::Scanner::MappingType &tagValueMappings_, DcmIoType *io, const ImageBlockDescriptor &blockInfo, Image *image); /** \brief Map between DICOM tags and MITK properties. Uses as a positive list for copying specified DICOM tags (from ITK's ImageIO) to MITK properties. ITK provides MetaDataDictionary entries of form "gggg|eeee" (g = group, e = element), e.g. "0028,0109" (Largest Pixel in Series), which we want to sort as dicom.series.largest_pixel_in_series". */ static const TagToPropertyMapType &GetDICOMTagsToMITKPropertyMap(); }; } #endif /* mitkDicomSeriesReader_h */ diff --git a/Modules/Core/include/mitkDicomSeriesReader.txx b/Modules/DICOMReader/src/legacy/mitkDicomSeriesReader.txx similarity index 99% rename from Modules/Core/include/mitkDicomSeriesReader.txx rename to Modules/DICOMReader/src/legacy/mitkDicomSeriesReader.txx index c397f02181..1ca27290b5 100644 --- a/Modules/Core/include/mitkDicomSeriesReader.txx +++ b/Modules/DICOMReader/src/legacy/mitkDicomSeriesReader.txx @@ -1,308 +1,308 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKDICOMSERIESREADER_TXX_ #define MITKDICOMSERIESREADER_TXX_ -#include +#include #include #include #include #include #include #include #include #include namespace mitk { template Image::Pointer DicomSeriesReader::LoadDICOMByITK4D(std::list &imageBlocks, ImageBlockDescriptor imageBlockDescriptor, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, Image::Pointer preLoadedImageBlock) { mitk::Image::Pointer image = mitk::Image::New(); // It is 3D+t! Read it and store into mitk image typedef itk::Image ImageType; typedef itk::ImageSeriesReader ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); reader->SetImageIO(io); reader->ReverseOrderOff(); if (command) { reader->AddObserver(itk::ProgressEvent(), command); } if (preLoadedImageBlock.IsNull()) { reader->SetFileNames(imageBlocks.front()); reader->Update(); typename ImageType::Pointer readVolume = reader->GetOutput(); // if we detected that the images are from a tilted gantry acquisition, we need to push some pixels into the right // position if (correctTilt) { readVolume = InPlaceFixUpTiltedGeometry(reader->GetOutput(), tiltInfo); } unsigned int volume_count = imageBlocks.size(); image->InitializeByItk(readVolume.GetPointer(), 1, volume_count); image->SetImportVolume(readVolume->GetBufferPointer(), 0u); FixSpacingInformation(image, imageBlockDescriptor); } else { StringContainer fakeList; fakeList.push_back(imageBlocks.front().front()); reader->SetFileNames(fakeList); // only ONE first filename to get MetaDataDictionary image = preLoadedImageBlock; } gdcm::Scanner scanner; ScanForSliceInformation(imageBlockDescriptor.GetFilenames(), scanner); CopyMetaDataToImageProperties(imageBlocks, scanner.GetMappings(), io, imageBlockDescriptor, image); MITK_DEBUG << "Volume dimension: [" << image->GetDimension(0) << ", " << image->GetDimension(1) << ", " << image->GetDimension(2) << ", " << image->GetDimension(3) << "]"; MITK_DEBUG << "Volume spacing: [" << image->GetGeometry()->GetSpacing()[0] << ", " << image->GetGeometry()->GetSpacing()[1] << ", " << image->GetGeometry()->GetSpacing()[2] << "]"; if (preLoadedImageBlock.IsNull()) { unsigned int act_volume = 1u; for (auto df_it = ++imageBlocks.begin(); df_it != imageBlocks.end(); ++df_it) { reader->SetFileNames(*df_it); reader->Update(); typename ImageType::Pointer readVolume = reader->GetOutput(); if (correctTilt) { readVolume = InPlaceFixUpTiltedGeometry(reader->GetOutput(), tiltInfo); } image->SetImportVolume(readVolume->GetBufferPointer(), act_volume++); } } return image; } template Image::Pointer DicomSeriesReader::LoadDICOMByITK(const StringContainer &filenames, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, Image::Pointer preLoadedImageBlock) { /******** Normal Case, 3D (also for GDCM < 2 usable) ***************/ mitk::Image::Pointer image = mitk::Image::New(); typedef itk::Image ImageType; typedef itk::ImageSeriesReader ReaderType; io = DcmIoType::New(); typename ReaderType::Pointer reader = ReaderType::New(); reader->SetImageIO(io); reader->ReverseOrderOff(); if (command) { reader->AddObserver(itk::ProgressEvent(), command); } if (preLoadedImageBlock.IsNull()) { reader->SetFileNames(filenames); reader->Update(); typename ImageType::Pointer readVolume = reader->GetOutput(); // if we detected that the images are from a tilted gantry acquisition, we need to push some pixels into the right // position if (correctTilt) { readVolume = InPlaceFixUpTiltedGeometry(reader->GetOutput(), tiltInfo); } image->InitializeByItk(readVolume.GetPointer()); image->SetImportVolume(readVolume->GetBufferPointer()); } else { image = preLoadedImageBlock; StringContainer fakeList; fakeList.push_back(filenames.front()); reader->SetFileNames(fakeList); // we always need to load at least one file to get the MetaDataDictionary reader->Update(); } MITK_DEBUG << "Volume dimension: [" << image->GetDimension(0) << ", " << image->GetDimension(1) << ", " << image->GetDimension(2) << "]"; MITK_DEBUG << "Volume spacing: [" << image->GetGeometry()->GetSpacing()[0] << ", " << image->GetGeometry()->GetSpacing()[1] << ", " << image->GetGeometry()->GetSpacing()[2] << "]"; return image; } template typename ImageType::Pointer DicomSeriesReader::InPlaceFixUpTiltedGeometry(ImageType *input, const GantryTiltInformation &tiltInfo) { typedef itk::ResampleImageFilter ResampleFilterType; typename ResampleFilterType::Pointer resampler = ResampleFilterType::New(); resampler->SetInput(input); /* Transform for a point is - transform from actual position to index coordinates - apply a shear that undoes the gantry tilt - transform back into world coordinates Anybody who does this in a simpler way: don't forget to write up how and why your solution works */ typedef itk::ScalableAffineTransform TransformType; typename TransformType::Pointer transformShear = TransformType::New(); /** - apply a shear and spacing correction to the image block that corrects the ITK reader's error - ITK ignores the shear and loads slices into an orthogonal volume - ITK calculates the spacing from the origin distance, which is more than the actual spacing with gantry tilt images - to undo the effect - we have calculated some information in tiltInfo: - the shift in Y direction that is added with each additional slice is the most important information - the Y-shift is calculated in mm world coordinates - we apply a shearing transformation to the ITK-read image volume - to do this locally, - we transform the image volume back to origin and "normal" orientation by applying the inverse of its transform (this brings us into the image's "index coordinate" system) - we apply a shear with the Y-shift factor put into a unit transform at row 1, col 2 - we transform the image volume back to its actual position (from index to world coordinates) - we lastly apply modify the image spacing in z direction by replacing this number with the correctly calulcated inter-slice distance */ ScalarType factor = tiltInfo.GetMatrixCoefficientForCorrectionInWorldCoordinates() / input->GetSpacing()[1]; // row 1, column 2 corrects shear in parallel to Y axis, proportional to distance in Z direction transformShear->Shear(1, 2, factor); typename TransformType::Pointer imageIndexToWorld = TransformType::New(); imageIndexToWorld->SetOffset(input->GetOrigin().GetVectorFromOrigin()); typename TransformType::MatrixType indexToWorldMatrix; indexToWorldMatrix = input->GetDirection(); typename ImageType::DirectionType scale; for (unsigned int i = 0; i < ImageType::ImageDimension; i++) { scale[i][i] = input->GetSpacing()[i]; } indexToWorldMatrix *= scale; imageIndexToWorld->SetMatrix(indexToWorldMatrix); typename TransformType::Pointer imageWorldToIndex = TransformType::New(); imageIndexToWorld->GetInverse(imageWorldToIndex); typename TransformType::Pointer gantryTiltCorrection = TransformType::New(); gantryTiltCorrection->Compose(imageWorldToIndex); gantryTiltCorrection->Compose(transformShear); gantryTiltCorrection->Compose(imageIndexToWorld); resampler->SetTransform(gantryTiltCorrection); typedef itk::LinearInterpolateImageFunction InterpolatorType; typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); resampler->SetInterpolator(interpolator); /* This would be the right place to invent a meaningful value for positions outside of the image. For CT, HU -1000 might be meaningful, but a general solution seems not possible. Even for CT, -1000 would only look natural for many not all images. */ // TODO use (0028,0120) Pixel Padding Value if present resampler->SetDefaultPixelValue(itk::NumericTraits::min()); // adjust size in Y direction! (maybe just transform the outer last pixel to see how much space we would need resampler->SetOutputParametersFromImage(input); // we basically need the same image again, just sheared // if tilt positive, then we need additional pixels BELOW origin, otherwise we need pixels behind the end of the // block // in any case we need more size to accomodate shifted slices typename ImageType::SizeType largerSize = resampler->GetSize(); // now the resampler already holds the input image's size. largerSize[1] += static_cast( tiltInfo.GetTiltCorrectedAdditionalSize() / input->GetSpacing()[1] + 2.0); resampler->SetSize(largerSize); // in SOME cases this additional size is below/behind origin if (tiltInfo.GetMatrixCoefficientForCorrectionInWorldCoordinates() > 0.0) { typename ImageType::DirectionType imageDirection = input->GetDirection(); Vector3D yDirection; yDirection[0] = imageDirection[0][1]; yDirection[1] = imageDirection[1][1]; yDirection[2] = imageDirection[2][1]; yDirection.Normalize(); typename ImageType::PointType shiftedOrigin; shiftedOrigin = input->GetOrigin(); // add some pixels to make everything fit shiftedOrigin[0] -= yDirection[0] * (tiltInfo.GetTiltCorrectedAdditionalSize() + 1.0 * input->GetSpacing()[1]); shiftedOrigin[1] -= yDirection[1] * (tiltInfo.GetTiltCorrectedAdditionalSize() + 1.0 * input->GetSpacing()[1]); shiftedOrigin[2] -= yDirection[2] * (tiltInfo.GetTiltCorrectedAdditionalSize() + 1.0 * input->GetSpacing()[1]); resampler->SetOutputOrigin(shiftedOrigin); } resampler->Update(); typename ImageType::Pointer result = resampler->GetOutput(); // ImageSeriesReader calculates z spacing as the distance between the first two origins. // This is not correct in case of gantry tilt, so we set our calculated spacing. typename ImageType::SpacingType correctedSpacing = result->GetSpacing(); correctedSpacing[2] = tiltInfo.GetRealZSpacing(); result->SetSpacing(correctedSpacing); return result; } } #endif diff --git a/Modules/DICOMReader/src/mitkBaseDICOMReaderService.cpp b/Modules/DICOMReader/src/mitkBaseDICOMReaderService.cpp index bef9a7bb25..08c5d5ba30 100644 --- a/Modules/DICOMReader/src/mitkBaseDICOMReaderService.cpp +++ b/Modules/DICOMReader/src/mitkBaseDICOMReaderService.cpp @@ -1,199 +1,199 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkBaseDICOMReaderService.h" #include #include #include #include #include #include #include -#include +#include "legacy/mitkDicomSeriesReader.h" #include #include #include #include #include namespace mitk { BaseDICOMReaderService::BaseDICOMReaderService(const std::string& description) : AbstractFileReader(CustomMimeType(IOMimeTypes::DICOM_MIMETYPE()), description) { } BaseDICOMReaderService::BaseDICOMReaderService(const mitk::CustomMimeType& customType, const std::string& description) : AbstractFileReader(customType, description) { } std::vector > BaseDICOMReaderService::Read() { std::vector result; - //special handling of Philips 3D US DICOM. - //Copied from DICOMSeriesReaderService std::string fileName = this->GetLocalFileName(); + //special handling of Philips 3D US DICOM. + //Copied from DICOMSeriesReaderService if (DicomSeriesReader::IsPhilips3DDicom(fileName)) { MITK_INFO << "it is a Philips3D US Dicom file" << std::endl; mitk::LocaleSwitch localeSwitch("C"); std::locale previousCppLocale(std::cin.getloc()); std::locale l("C"); std::cin.imbue(l); DataNode::Pointer node = DataNode::New(); mitk::DicomSeriesReader::StringContainer stringvec; stringvec.push_back(fileName); if (DicomSeriesReader::LoadDicomSeries(stringvec, *node)) { BaseData::Pointer data = node->GetData(); StringProperty::Pointer nameProp = StringProperty::New(itksys::SystemTools::GetFilenameName(fileName)); data->GetPropertyList()->SetProperty("name", nameProp); result.push_back(data); } std::cin.imbue(previousCppLocale); return result; } //Normal DICOM handling (It wasn't a Philips 3D US) mitk::StringList relevantFiles = this->GetRelevantFiles(); // check whether directory or file // if directory try to find first file within it instead // We only support this for a single directory at once if (relevantFiles.empty()) { bool pathIsDirectory = itksys::SystemTools::FileIsDirectory(this->GetLocalFileName()); if (pathIsDirectory) { itksys::Directory input; input.Load(this->GetLocalFileName().c_str()); std::vector files; for (unsigned long idx = 0; idxGetLocalFileName() + "/" + std::string(input.GetFile(idx)); files.push_back(fullpath.c_str()); } } relevantFiles = files; } } if (relevantFiles.empty()) { MITK_INFO << "DICOMReader service found no relevant files in specified location. No data is loaded. Location: "<GetReader(relevantFiles); if(reader.IsNull()) { MITK_INFO << "DICOMReader service found no suitable reader configuration for relevant files."; } else { const unsigned int ntotalfiles = relevantFiles.size(); for( unsigned int i=0; i< ntotalfiles; i++) { m_ReadFiles.push_back( relevantFiles.at(i) ); } reader->SetAdditionalTagsOfInterest(mitk::GetCurrentDICOMTagsOfInterest()); reader->SetTagLookupTableToPropertyFunctor(mitk::GetDICOMPropertyForDICOMValuesFunctor); reader->SetInputFiles(relevantFiles); mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New(); scanner->AddTagPaths(reader->GetTagsOfInterest()); scanner->SetInputFiles(relevantFiles); scanner->Scan(); reader->SetTagCache(scanner->GetScanCache()); reader->AnalyzeInputFiles(); reader->LoadImages(); for (unsigned int i = 0; i < reader->GetNumberOfOutputs(); ++i) { const mitk::DICOMImageBlockDescriptor& desc = reader->GetOutput(i); mitk::BaseData::Pointer data = desc.GetMitkImage().GetPointer(); std::string nodeName = "Unnamed_DICOM"; std::string studyDescription = desc.GetPropertyAsString("studyDescription"); std::string seriesDescription = desc.GetPropertyAsString("seriesDescription"); if (!studyDescription.empty()) { nodeName = studyDescription; } if (!seriesDescription.empty()) { if (!studyDescription.empty()) { nodeName += "/"; } nodeName += seriesDescription; } StringProperty::Pointer nameProp = StringProperty::New(nodeName); data->SetProperty("name", nameProp); result.push_back(data); } } } return result; } StringList BaseDICOMReaderService::GetRelevantFiles() const { std::string fileName = this->GetLocalFileName(); mitk::StringList relevantFiles = mitk::GetDICOMFilesInSameDirectory(fileName); return relevantFiles; } IFileReader::ConfidenceLevel BaseDICOMReaderService::GetConfidenceLevel() const { IFileReader::ConfidenceLevel abstractConfidence = AbstractFileReader::GetConfidenceLevel(); if (Unsupported == abstractConfidence) { if (itksys::SystemTools::FileIsDirectory(this->GetInputLocation().c_str())) { // In principle we support dicom directories return Supported; } } return abstractConfidence; } } diff --git a/Modules/DICOMTesting/test/mitkDICOMLocaleTest.cpp b/Modules/DICOMTesting/test/mitkDICOMLocaleTest.cpp index 6348ba798e..e7192e7aeb 100644 --- a/Modules/DICOMTesting/test/mitkDICOMLocaleTest.cpp +++ b/Modules/DICOMTesting/test/mitkDICOMLocaleTest.cpp @@ -1,131 +1,136 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ /* This test is meant to reproduce the following error: - The machine or current user has a German locale. - This esp. means that stream IO expects the decimal separator as a comma: "," - DICOM files use a point "." as the decimal separator to be locale independent - The parser used by MITK (ITK's GDCM) seems to use the current locale instead of the "C" or "POSIX" locale - This leads to spacings (and probably other numbers) being trimmed/rounded, e.g. the correct spacing of 0.314 is read as 1.0 etc. */ -#include "mitkDataNodeFactory.h" #include "mitkStandardFileLocations.h" -#include "mitkDicomSeriesReader.h" +#include "mitkTestDICOMLoading.h" #include "mitkTestingMacros.h" #include #include #include bool mitkDICOMLocaleTestChangeLocale(const std::string& locale) { try { MITK_TEST_OUTPUT(<< " ** Changing locale from " << setlocale(LC_ALL, nullptr) << " to '" << locale << "'"); setlocale(LC_ALL, locale.c_str()); std::locale l( locale.c_str() ); std::cin.imbue(l); return true; } catch(...) { MITK_TEST_OUTPUT(<< "Could not activate locale " << locale); return false; } } void mitkDICOMLocaleTestWithReferenceImage(std::string filename) { - mitk::Image::Pointer image; - mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New(); - factory->SetFileName( filename ); - factory->Update(); - MITK_TEST_CONDITION_REQUIRED(factory->GetNumberOfOutputs() > 0, "file " << filename << " loaded"); + mitk::TestDICOMLoading loader; + + mitk::TestDICOMLoading::ImageList images = loader.LoadFiles({ filename }); + + MITK_TEST_CONDITION_REQUIRED(images.size() > 0, "file " << filename << " loaded"); mitk::DataNode::Pointer node = factory->GetOutput( 0 ); image = dynamic_cast(node->GetData()); - if(image.IsNull()) + + mitk::Image::Pointer image; + if(images.empty()) { MITK_TEST_FAILED_MSG(<< "File "<< filename << " is not an image - test will not be applied." ); return; } + else + { + image = images[0]; + } // note importance of minor differences in spacings: // DICOM has order y-spacing, x-spacing, while in MITK we assume x-spacing, y-spacing (both meant for 0 and 1 index in array) MITK_TEST_CONDITION_REQUIRED(mitk::Equal(image->GetGeometry()->GetSpacing()[0], 0.3141592), "correct x spacing? found " << image->GetGeometry()->GetSpacing()[0]); MITK_TEST_CONDITION_REQUIRED(mitk::Equal(image->GetGeometry()->GetSpacing()[1], 0.3411592), "correct y spacing? found " << image->GetGeometry()->GetSpacing()[1]); } int mitkDICOMLocaleTest(int argc, char* argv[]) { MITK_TEST_BEGIN("DICOMLocaleTest"); MITK_TEST_CONDITION_REQUIRED(argc >= 2, "File to load has been specified on commandline"); MITK_TEST_OUTPUT(<< "Configuration: \n" << mitk::DicomSeriesReader::GetConfigurationString() ); std::string filename = argv[1]; // load a reference DICOM file with the "C" locale being set mitkDICOMLocaleTestChangeLocale("C"); mitkDICOMLocaleTestWithReferenceImage(filename); // load a reference DICOM file with German locales being set typedef std::list StringList; StringList alllocales; alllocales.push_back("de_DE"); alllocales.push_back("de_DE.utf8"); alllocales.push_back("de_DE.UTF8"); alllocales.push_back("de_DE@euro"); alllocales.push_back("German_Germany"); // supressing this test to be run on MacOS X // See bug #3894 #if defined (__APPLE__) || defined(MACOSX) alllocales.push_back("C"); #endif unsigned int numberOfTestedGermanLocales(0); for (StringList::iterator iter = alllocales.begin(); iter != alllocales.end(); ++iter) { if ( mitkDICOMLocaleTestChangeLocale(*iter) ) { ++numberOfTestedGermanLocales; mitkDICOMLocaleTestWithReferenceImage(filename); } } if(numberOfTestedGermanLocales == 0) { MITK_TEST_OUTPUT(<< "Warning: No German locale was found on the system."); } //MITK_TEST_CONDITION_REQUIRED( numberOfTestedGermanLocales > 0, "Verify that at least one German locale has been tested."); MITK_TEST_END(); } diff --git a/Modules/DataTypesExt/src/mitkOrganTypeProperty.cpp b/Modules/DataTypesExt/src/mitkOrganTypeProperty.cpp index dc8cdce685..1e8c8f4b3a 100644 --- a/Modules/DataTypesExt/src/mitkOrganTypeProperty.cpp +++ b/Modules/DataTypesExt/src/mitkOrganTypeProperty.cpp @@ -1,120 +1,118 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkOrganTypeProperty.h" mitk::OrganTypeProperty::OrganTypeProperty() { AddEnumerationTypes(); } mitk::OrganTypeProperty::OrganTypeProperty(const IdType &value) { AddEnumerationTypes(); if (IsValidEnumerationValue(value)) { SetValue(value); } else { SetValue(0); } } mitk::OrganTypeProperty::OrganTypeProperty(const std::string &value) { AddEnumerationTypes(); if (IsValidEnumerationValue(value)) { SetValue(value); } else { SetValue("undefined"); } } mitk::OrganTypeProperty::~OrganTypeProperty() { } void mitk::OrganTypeProperty::AddEnumerationTypes() { auto newId = static_cast(EnumerationProperty::Size()); - // On changes, please also change mitk::DataNodeFactory::DefaultColorForOrgan() - AddEnum("undefined", newId++); AddEnum("Ankle", newId++); AddEnum("Appendix", newId++); AddEnum("Blood vessels", newId++); AddEnum("Bone", newId++); AddEnum("Brain", newId++); AddEnum("Bronchial tree", newId++); AddEnum("Coccyx", newId++); AddEnum("Colon", newId++); AddEnum("Cyst", newId++); AddEnum("Elbow", newId++); AddEnum("Eye", newId++); AddEnum("Fallopian tube", newId++); AddEnum("Fat", newId++); AddEnum("Gall bladder", newId++); AddEnum("Hand", newId++); AddEnum("Heart", newId++); AddEnum("Hip", newId++); AddEnum("Hippocampus", newId++); AddEnum("Kidney", newId++); AddEnum("Knee", newId++); AddEnum("Larynx", newId++); AddEnum("Liver", newId++); AddEnum("Lung", newId++); AddEnum("Lymph node", newId++); AddEnum("Muscle", newId++); AddEnum("Nerve", newId++); AddEnum("Nose", newId++); AddEnum("Oesophagus", newId++); AddEnum("Ovaries", newId++); AddEnum("Pancreas", newId++); AddEnum("Pelvis", newId++); AddEnum("Penis", newId++); AddEnum("Pharynx", newId++); AddEnum("Prostate", newId++); AddEnum("Rectum", newId++); AddEnum("Sacrum", newId++); AddEnum("Seminal vesicle", newId++); AddEnum("Shoulder", newId++); AddEnum("Spinal cord", newId++); AddEnum("Spleen", newId++); AddEnum("Stomach", newId++); AddEnum("Teeth", newId++); AddEnum("Testicles", newId++); AddEnum("Thyroid", newId++); AddEnum("Tongue", newId++); AddEnum("Tumor", newId++); AddEnum("Urethra", newId++); AddEnum("Urinary bladder", newId++); AddEnum("Uterus", newId++); AddEnum("Vagina", newId++); AddEnum("Vertebra", newId++); AddEnum("Wrist", newId++); } itk::LightObject::Pointer mitk::OrganTypeProperty::InternalClone() const { itk::LightObject::Pointer result(new Self(*this)); result->UnRegister(); return result; } diff --git a/Modules/DicomRT/include/mitkDoseImageVtkMapper2D.h b/Modules/DicomRT/include/mitkDoseImageVtkMapper2D.h index 24011d6bff..2136d8903b 100644 --- a/Modules/DicomRT/include/mitkDoseImageVtkMapper2D.h +++ b/Modules/DicomRT/include/mitkDoseImageVtkMapper2D.h @@ -1,313 +1,313 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKDoseImageVtkMapper2D2D_H_HEADER_INCLUDED #define MITKDoseImageVtkMapper2D2D_H_HEADER_INCLUDED //MITK #include #include //MITK Rendering #include "mitkBaseRenderer.h" #include "mitkVtkMapper.h" #include "mitkExtractSliceFilter.h" //VTK #include #include #include class vtkActor; class vtkPolyDataMapper; class vtkPlaneSource; class vtkImageData; class vtkLookupTable; class vtkImageExtractComponents; class vtkImageReslice; class vtkImageChangeInformation; class vtkPoints; class vtkMitkThickSlicesFilter; class vtkPolyData; class vtkMitkApplyLevelWindowToRGBFilter; class vtkMitkLevelWindowFilter; namespace mitk { /** \brief Mapper to resample and display 2D slices of a 3D image. * * The following image gives a brief overview of the mapping and the involved parts. * * \image html DoseImageVtkMapper2Darchitecture.png * * First, the image is resliced by means of vtkImageReslice. The volume image * serves as input to the mapper in addition to spatial placement of the slice and a few other * properties such as thick slices. This code was already present in the old version * (mitkImageMapperGL2D). * * Next, the obtained slice (m_ReslicedImage) is put into a vtkMitkLevelWindowFilter * and the scalar levelwindow, opacity levelwindow and optional clipping to * local image bounds are applied * * Next, the output of the vtkMitkLevelWindowFilter is used to create a texture * (m_Texture) and a plane onto which the texture is rendered (m_Plane). For * mapping purposes, a vtkPolyDataMapper (m_Mapper) is utilized. Orthographic * projection is applied to create the effect of a 2D image. The mapper and the * texture are assigned to the actor (m_Actor) which is passed to the VTK rendering * pipeline via the method GetVtkProp(). * * In order to transform the textured plane to the correct position in space, the * same transformation as used for reslicing is applied to both the camera and the * vtkActor. All important steps are explained in more detail below. The resulting * 2D image (by reslicing the underlying 3D input image appropriately) can either * be directly rendered in a 2D view or just be calculated to be used later by another * rendering entity, e.g. in texture mapping in a 3D view. * * Properties that can be set for images and influence the imageMapper2D are: * * - \b "opacity": (FloatProperty) Opacity of the image * - \b "color": (ColorProperty) Color of the image * - \b "LookupTable": (mitkLookupTableProperty) If this property is set, * the default lookuptable will be ignored and the "LookupTable" value * will be used instead. * - \b "Image Rendering.Mode": This property decides which mode is used to render images. (E.g. if a lookup table or a transferfunction is applied). Detailed documentation about the modes can be found here: \link mitk::RenderingerModeProperty \endlink * - \b "Image Rendering.Transfer Function": (mitkTransferFunctionProperty) If this * property is set, a color transferfunction will be used to color the image. * - \b "binary": (BoolProperty) is the image a binary image or not * - \b "outline binary": (BoolProperty) show outline of the image or not * - \b "texture interpolation": (BoolProperty) texture interpolation of the image * - \b "reslice interpolation": (VtkResliceInterpolationProperty) reslice interpolation of the image * - \b "in plane resample extent by geometry": (BoolProperty) Do it or not * - \b "bounding box": (BoolProperty) Is the Bounding Box of the image shown or not * - \b "layer": (IntProperty) Layer of the image * - \b "volume annotation color": (ColorProperty) color of the volume annotation, TODO has to be reimplemented * - \b "volume annotation unit": (StringProperty) annotation unit as string (does not implicit convert the unit!) unit is ml or cm3, TODO has to be reimplemented * The default properties are: * - \b "opacity", mitk::FloatProperty::New(0.3f), renderer, overwrite ) * - \b "color", ColorProperty::New(1.0,0.0,0.0), renderer, overwrite ) * - \b "binary", mitk::BoolProperty::New( true ), renderer, overwrite ) * - \b "outline binary", mitk::BoolProperty::New( false ), renderer, overwrite ) - * - \b "texture interpolation", mitk::BoolProperty::New( mitk::DataNodeFactory::m_TextureInterpolationActive ) ) + * - \b "texture interpolation", mitk::BoolProperty::New( false ) ) * - \b "reslice interpolation", mitk::VtkResliceInterpolationProperty::New() ) * - \b "in plane resample extent by geometry", mitk::BoolProperty::New( false ) ) * - \b "bounding box", mitk::BoolProperty::New( false ) ) * - \b "layer", mitk::IntProperty::New(10), renderer, overwrite) * - \b "Image Rendering.Transfer Function": Default color transfer function for CTs * - \b "LookupTable": Rainbow color. * If the modality-property is set for an image, the mapper uses modality-specific default properties, * e.g. color maps, if they are defined. * \ingroup Mapper */ class MITKDICOMRT_EXPORT DoseImageVtkMapper2D : public VtkMapper { public: /** Standard class typedefs. */ mitkClassMacro( DoseImageVtkMapper2D,VtkMapper ); /** Method for creation through the object factory. */ itkFactorylessNewMacro(Self) itkCloneMacro(Self) /** \brief Get the Image to map */ const mitk::Image *GetInput(void); /** \brief Checks whether this mapper needs to update itself and generate * data. */ void Update(mitk::BaseRenderer * renderer) override; //### methods of MITK-VTK rendering pipeline vtkProp* GetVtkProp(mitk::BaseRenderer* renderer) override; //### end of methods of MITK-VTK rendering pipeline /** \brief Internal class holding the mapper, actor, etc. for each of the 3 2D render windows */ /** * To render transveral, coronal, and sagittal, the mapper is called three times. * For performance reasons, the corresponding data for each view is saved in the * internal helper class LocalStorage. This allows rendering n views with just * 1 mitkMapper using n vtkMapper. * */ class MITKDICOMRT_EXPORT LocalStorage : public mitk::Mapper::BaseLocalStorage { public: /** \brief Actor of a 2D render window. */ vtkSmartPointer m_Actor; vtkSmartPointer m_Actors; /** \brief Mapper of a 2D render window. */ vtkSmartPointer m_Mapper; vtkSmartPointer m_VectorComponentExtractor; /** \brief Current slice of a 2D render window.*/ vtkSmartPointer m_ReslicedImage; /** \brief Empty vtkPolyData that is set when rendering geometry does not * intersect the image geometry. * \warning This member variable is set to nullptr, * if no image geometry is inside the plane geometry * of the respective render window. Any user of this * slice has to check whether it is set to nullptr! */ vtkSmartPointer m_EmptyPolyData; /** \brief Plane on which the slice is rendered as texture. */ vtkSmartPointer m_Plane; /** \brief The texture which is used to render the current slice. */ vtkSmartPointer m_Texture; /** \brief The lookuptables for colors and level window */ vtkSmartPointer m_DefaultLookupTable; vtkSmartPointer m_BinaryLookupTable; vtkSmartPointer m_ColorLookupTable; /** \brief The actual reslicer (one per renderer) */ mitk::ExtractSliceFilter::Pointer m_Reslicer; /** \brief Filter for thick slices */ vtkSmartPointer m_TSFilter; /** \brief PolyData object containg all lines/points needed for outlining the contour. This container is used to save a computed contour for the next rendering execution. For instance, if you zoom or pann, there is no need to recompute the contour. */ vtkSmartPointer m_OutlinePolyData; /** \brief Timestamp of last update of stored data. */ itk::TimeStamp m_LastUpdateTime; /** \brief mmPerPixel relation between pixel and mm. (World spacing).*/ mitk::ScalarType* m_mmPerPixel; /** \brief This filter is used to apply the level window to Grayvalue and RBG(A) images. */ vtkSmartPointer m_LevelWindowFilter; /** \brief Default constructor of the local storage. */ LocalStorage(); /** \brief Default deconstructor of the local storage. */ ~LocalStorage() override; }; /** \brief The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows. */ mitk::LocalStorageHandler m_LSH; /** \brief Get the LocalStorage corresponding to the current renderer. */ LocalStorage* GetLocalStorage(mitk::BaseRenderer* renderer); /** \brief Set the default properties for general image rendering. */ static void SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer = nullptr, bool overwrite = false); /** \brief This method switches between different rendering modes (e.g. use a lookup table or a transfer function). * Detailed documentation about the modes can be found here: \link mitk::RenderingerModeProperty \endlink */ void ApplyRenderingMode(mitk::BaseRenderer *renderer); protected: /** \brief Transforms the actor to the actual position in 3D. * \param renderer The current renderer corresponding to the render window. */ void TransformActor(mitk::BaseRenderer* renderer); /** \brief Generates a plane according to the size of the resliced image in milimeters. * * \image html texturedPlane.png * * In VTK a vtkPlaneSource is defined through three points. The origin and two * points defining the axes of the plane (see VTK documentation). The origin is * set to (xMin; yMin; Z), where xMin and yMin are the minimal bounds of the * resliced image in space. Z is relevant for blending and the layer property. * The center of the plane (C) is also the center of the view plane (cf. the image above). * * \note For the standard MITK view with three 2D render windows showing three * different slices, three such planes are generated. All these planes are generated * in the XY-plane (even if they depict a YZ-slice of the volume). * */ void GeneratePlane(mitk::BaseRenderer* renderer, double planeBounds[6]); /** \brief Generates a vtkPolyData object containing the outline of a given binary slice. \param renderer: Pointer to the renderer containing the needed information \note This code is based on code from the iil library. */ vtkSmartPointer CreateOutlinePolyData(mitk::BaseRenderer* renderer); /** Default constructor */ DoseImageVtkMapper2D(); /** Default deconstructor */ ~DoseImageVtkMapper2D() override; /** \brief Does the actual resampling, without rendering the image yet. * All the data is generated inside this method. The vtkProp (or Actor) * is filled with content (i.e. the resliced image). * * After generation, a 4x4 transformation matrix(t) of the current slice is obtained * from the vtkResliceImage object via GetReslicesAxis(). This matrix is * applied to each textured plane (actor->SetUserTransform(t)) to transform everything * to the actual 3D position (cf. the following image). * * \image html cameraPositioning3D.png * */ void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override; /** \brief This method uses the vtkCamera clipping range and the layer property * to calcualte the depth of the object (e.g. image or contour). The depth is used * to keep the correct order for the final VTK rendering.*/ float CalculateLayerDepth(mitk::BaseRenderer* renderer); /** \brief This method applies (or modifies) the lookuptable for all types of images. * \warning To use the lookup table, the property 'Lookup Table' must be set and a 'Image Rendering.Mode' * which uses the lookup table must be set. */ void ApplyLookuptable(mitk::BaseRenderer* renderer); /** \brief This method applies a color transfer function. * Internally, a vtkColorTransferFunction is used. This is usefull for coloring continous * images (e.g. float) * \warning To use the color transfer function, the property 'Image Rendering.Transfer Function' must be set and a 'Image Rendering.Mode' which uses the color transfer function must be set. */ void ApplyColorTransferFunction(mitk::BaseRenderer* renderer); /** * @brief ApplyLevelWindow Apply the level window for the given renderer. * \warning To use the level window, the property 'LevelWindow' must be set and a 'Image Rendering.Mode' which uses the level window must be set. * @param renderer Level window for which renderer? */ void ApplyLevelWindow(mitk::BaseRenderer* renderer); /** \brief Set the color of the image/polydata */ void ApplyColor( mitk::BaseRenderer* renderer ); /** \brief Set the opacity of the actor. */ void ApplyOpacity( mitk::BaseRenderer* renderer ); /** * \brief Calculates whether the given rendering geometry intersects the * given SlicedGeometry3D. * * This method checks if the given PlaneGeometry intersects the given * SlicedGeometry3D. It calculates the distance of the PlaneGeometry to all * 8 cornerpoints of the SlicedGeometry3D. If all distances have the same * sign (all positive or all negative) there is no intersection. * If the distances have different sign, there is an intersection. **/ bool RenderingGeometryIntersectsImage( const PlaneGeometry* renderingGeometry, SlicedGeometry3D* imageGeometry ); private: void CreateLevelOutline(mitk::BaseRenderer* renderer, const mitk::IsoDoseLevel* level, float pref, vtkSmartPointer points, vtkSmartPointer lines, vtkSmartPointer colors); }; } // namespace mitk #endif /* MITKDoseImageVtkMapper2D_H_HEADER_INCLUDED_C10E906E */ diff --git a/Modules/DiffusionImaging/DiffusionCore/autoload/IO/mitkDiffusionCoreIOMimeTypes.cpp b/Modules/DiffusionImaging/DiffusionCore/autoload/IO/mitkDiffusionCoreIOMimeTypes.cpp index 37bb1546d9..ebf019b60f 100644 --- a/Modules/DiffusionImaging/DiffusionCore/autoload/IO/mitkDiffusionCoreIOMimeTypes.cpp +++ b/Modules/DiffusionImaging/DiffusionCore/autoload/IO/mitkDiffusionCoreIOMimeTypes.cpp @@ -1,642 +1,642 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkDiffusionCoreIOMimeTypes.h" #include "mitkIOMimeTypes.h" #include #include #include #include #include #include #include #include #include namespace mitk { std::vector DiffusionCoreIOMimeTypes::Get() { std::vector mimeTypes; // order matters here (descending rank for mime types) mimeTypes.push_back(DWI_NRRD_MIMETYPE().Clone()); mimeTypes.push_back(DWI_NIFTI_MIMETYPE().Clone()); mimeTypes.push_back(DWI_FSL_MIMETYPE().Clone()); mimeTypes.push_back(DWI_DICOM_MIMETYPE().Clone()); mimeTypes.push_back(DTI_MIMETYPE().Clone()); mimeTypes.push_back(ODF_MIMETYPE().Clone()); mimeTypes.push_back(PEAK_MIMETYPE().Clone()); mimeTypes.push_back(SH_MIMETYPE().Clone()); return mimeTypes; } // Mime Types DiffusionCoreIOMimeTypes::DiffusionImageNrrdMimeType::DiffusionImageNrrdMimeType() : CustomMimeType(DWI_NRRD_MIMETYPE_NAME()) { std::string category = "Diffusion Weighted Images"; this->SetCategory(category); this->SetComment("Diffusion Weighted Images"); this->AddExtension("dwi"); //this->AddExtension("hdwi"); // saving with detached header does not work out of the box this->AddExtension("nrrd"); } bool DiffusionCoreIOMimeTypes::DiffusionImageNrrdMimeType::AppliesTo(const std::string &path) const { bool canRead( CustomMimeType::AppliesTo(path) ); // fix for bug 18572 // Currently this function is called for writing as well as reading, in that case // the image information can of course not be read // This is a bug, this function should only be called for reading. if( ! itksys::SystemTools::FileExists( path.c_str() ) ) { return canRead; } //end fix for bug 18572 - std::string ext = this->GetExtension( path ); - ext = itksys::SystemTools::LowerCase( ext ); - + itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); // Simple NRRD files should only be considered for this mime type if they contain // corresponding tags - if( ext == ".nrrd" ) + if( io->CanReadFile(path.c_str())) { - itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); io->SetFileName(path); try { io->ReadImageInformation(); itk::MetaDataDictionary imgMetaDictionary = io->GetMetaDataDictionary(); std::vector imgMetaKeys = imgMetaDictionary.GetKeys(); std::vector::const_iterator itKey = imgMetaKeys.begin(); std::string metaString; for (; itKey != imgMetaKeys.end(); itKey ++) { itk::ExposeMetaData (imgMetaDictionary, *itKey, metaString); if (itKey->find("modality") != std::string::npos) { if (metaString.find("DWMRI") != std::string::npos) { return canRead; } } } } catch( const itk::ExceptionObject &e ) { MITK_ERROR << "ITK Exception: " << e.what(); } canRead = false; } return canRead; } DiffusionCoreIOMimeTypes::DiffusionImageNrrdMimeType* DiffusionCoreIOMimeTypes::DiffusionImageNrrdMimeType::Clone() const { return new DiffusionImageNrrdMimeType(*this); } DiffusionCoreIOMimeTypes::DiffusionImageNrrdMimeType DiffusionCoreIOMimeTypes::DWI_NRRD_MIMETYPE() { return DiffusionImageNrrdMimeType(); } DiffusionCoreIOMimeTypes::DiffusionImageNiftiMimeType::DiffusionImageNiftiMimeType() : CustomMimeType(DWI_NIFTI_MIMETYPE_NAME()) { std::string category = "Diffusion Weighted Images"; this->SetCategory(category); this->SetComment("Diffusion Weighted Images"); this->AddExtension("nii.gz"); this->AddExtension("nii"); } bool DiffusionCoreIOMimeTypes::DiffusionImageNiftiMimeType::AppliesTo(const std::string &path) const { bool canRead(CustomMimeType::AppliesTo(path)); // fix for bug 18572 // Currently this function is called for writing as well as reading, in that case // the image information can of course not be read // This is a bug, this function should only be called for reading. if (!itksys::SystemTools::FileExists(path.c_str())) { return canRead; } //end fix for bug 18572 std::string ext = this->GetExtension(path); ext = itksys::SystemTools::LowerCase(ext); // Nifti files should only be considered for this mime type if they are // accompanied by bvecs and bvals files defining the diffusion information if (ext == ".nii" || ext == ".nii.gz") { std::string base_path = itksys::SystemTools::GetFilenamePath(path); std::string base = this->GetFilenameWithoutExtension(path); std::string filename = base; if (!base_path.empty()) { base = base_path + "/" + base; base_path += "/"; } if (itksys::SystemTools::FileExists(std::string(base + ".bvec").c_str()) && itksys::SystemTools::FileExists(std::string(base + ".bval").c_str()) ) { return canRead; } if (itksys::SystemTools::FileExists(std::string(base + ".bvecs").c_str()) && itksys::SystemTools::FileExists(std::string(base + ".bvals").c_str()) ) { return canRead; } // hack for HCP data if ( filename=="data" && itksys::SystemTools::FileExists(std::string(base_path + "bvec").c_str()) && itksys::SystemTools::FileExists(std::string(base_path + "bval").c_str()) ) { return canRead; } if ( filename=="data" && itksys::SystemTools::FileExists(std::string(base_path + "bvecs").c_str()) && itksys::SystemTools::FileExists(std::string(base_path + "bvals").c_str()) ) { return canRead; } canRead = false; } return canRead; } DiffusionCoreIOMimeTypes::DiffusionImageNiftiMimeType* DiffusionCoreIOMimeTypes::DiffusionImageNiftiMimeType::Clone() const { return new DiffusionImageNiftiMimeType(*this); } DiffusionCoreIOMimeTypes::DiffusionImageNiftiMimeType DiffusionCoreIOMimeTypes::DWI_NIFTI_MIMETYPE() { return DiffusionImageNiftiMimeType(); } DiffusionCoreIOMimeTypes::DiffusionImageFslMimeType::DiffusionImageFslMimeType() : CustomMimeType(DWI_FSL_MIMETYPE_NAME()) { std::string category = "Diffusion Weighted Images"; this->SetCategory(category); this->SetComment("Diffusion Weighted Images"); this->AddExtension("fslgz"); this->AddExtension("fsl"); } bool DiffusionCoreIOMimeTypes::DiffusionImageFslMimeType::AppliesTo(const std::string &path) const { bool canRead(CustomMimeType::AppliesTo(path)); // fix for bug 18572 // Currently this function is called for writing as well as reading, in that case // the image information can of course not be read // This is a bug, this function should only be called for reading. if (!itksys::SystemTools::FileExists(path.c_str())) { return canRead; } //end fix for bug 18572 std::string ext = this->GetExtension(path); ext = itksys::SystemTools::LowerCase(ext); // Nifti files should only be considered for this mime type if they are // accompanied by bvecs and bvals files defining the diffusion information if (ext == ".fsl" || ext == ".fslgz") { std::string base_path = itksys::SystemTools::GetFilenamePath(path); std::string base = this->GetFilenameWithoutExtension(path); if (!base_path.empty()) base = base_path + "/" + base; if (itksys::SystemTools::FileExists(std::string(base + ".bvec").c_str()) && itksys::SystemTools::FileExists(std::string(base + ".bval").c_str()) ) { return canRead; } if (itksys::SystemTools::FileExists(std::string(base + ".bvecs").c_str()) && itksys::SystemTools::FileExists(std::string(base + ".bvals").c_str()) ) { return canRead; } if (itksys::SystemTools::FileExists(std::string(base + ext + ".bvec").c_str()) && itksys::SystemTools::FileExists(std::string(base + ext + ".bval").c_str()) ) { return canRead; } if (itksys::SystemTools::FileExists(std::string(base + ext + ".bvecs").c_str()) && itksys::SystemTools::FileExists(std::string(base + ext + ".bvals").c_str()) ) { return canRead; } canRead = false; } return canRead; } DiffusionCoreIOMimeTypes::DiffusionImageFslMimeType* DiffusionCoreIOMimeTypes::DiffusionImageFslMimeType::Clone() const { return new DiffusionImageFslMimeType(*this); } DiffusionCoreIOMimeTypes::DiffusionImageFslMimeType DiffusionCoreIOMimeTypes::DWI_FSL_MIMETYPE() { return DiffusionImageFslMimeType(); } DiffusionCoreIOMimeTypes::DiffusionImageDicomMimeType::DiffusionImageDicomMimeType() : CustomMimeType(DWI_DICOM_MIMETYPE_NAME()) { std::string category = "Diffusion Weighted Images"; this->SetCategory(category); this->SetComment("Diffusion Weighted Images"); this->AddExtension("gdcm"); this->AddExtension("dcm"); this->AddExtension("DCM"); this->AddExtension("dc3"); this->AddExtension("DC3"); this->AddExtension("ima"); this->AddExtension("img"); } bool DiffusionCoreIOMimeTypes::DiffusionImageDicomMimeType::AppliesTo(const std::string &path) const { itk::GDCMImageIO::Pointer gdcmIO = itk::GDCMImageIO::New(); bool canRead = gdcmIO->CanReadFile(path.c_str()); if (!canRead) return canRead; mitk::DICOMDCMTKTagScanner::Pointer scanner = mitk::DICOMDCMTKTagScanner::New(); mitk::DICOMTag ImageTypeTag(0x0008, 0x0008); mitk::DICOMTag SeriesDescriptionTag(0x0008, 0x103E); mitk::StringList relevantFiles; relevantFiles.push_back(path); scanner->AddTag(ImageTypeTag); scanner->AddTag(SeriesDescriptionTag); scanner->SetInputFiles(relevantFiles); scanner->Scan(); mitk::DICOMTagCache::Pointer tagCache = scanner->GetScanCache(); mitk::DICOMImageFrameList imageFrameList = mitk::ConvertToDICOMImageFrameList(tagCache->GetFrameInfoList()); mitk::DICOMImageFrameInfo *firstFrame = imageFrameList.begin()->GetPointer(); std::string byteString = tagCache->GetTagValue(firstFrame, ImageTypeTag).value; if (byteString.empty()) return false; std::string byteString2 = tagCache->GetTagValue(firstFrame, SeriesDescriptionTag).value; if (byteString2.empty()) return false; if (byteString.find("DIFFUSION")==std::string::npos && byteString2.find("diff")==std::string::npos) return false; // if (byteString.find("NONE")==std::string::npos) // return false; return canRead; } DiffusionCoreIOMimeTypes::DiffusionImageDicomMimeType* DiffusionCoreIOMimeTypes::DiffusionImageDicomMimeType::Clone() const { return new DiffusionImageDicomMimeType(*this); } DiffusionCoreIOMimeTypes::DiffusionImageDicomMimeType DiffusionCoreIOMimeTypes::DWI_DICOM_MIMETYPE() { return DiffusionImageDicomMimeType(); } DiffusionCoreIOMimeTypes::PeakImageMimeType::PeakImageMimeType() : CustomMimeType(PEAK_MIMETYPE_NAME()) { std::string category = "Peak Image"; this->SetCategory(category); this->SetComment("Peak Image"); this->AddExtension("nrrd"); this->AddExtension("nii"); this->AddExtension("nii.gz"); this->AddExtension("peak"); } bool DiffusionCoreIOMimeTypes::PeakImageMimeType::AppliesTo(const std::string &path) const { std::string ext = itksys::SystemTools::GetFilenameExtension(path); if (ext==".peak") return true; try { itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); if ( io->CanReadFile( path.c_str() ) ) { io->SetFileName( path.c_str() ); io->ReadImageInformation(); if ( io->GetPixelType() == itk::ImageIOBase::SCALAR && io->GetNumberOfDimensions()==4 && io->GetDimensions(3)%3==0) return true; } } catch(...) {} try { itk::NiftiImageIO::Pointer io = itk::NiftiImageIO::New(); if ( io->CanReadFile( path.c_str() ) ) { io->SetFileName( path.c_str() ); io->ReadImageInformation(); if ( io->GetPixelType() == itk::ImageIOBase::SCALAR && io->GetNumberOfDimensions()==4 && io->GetDimensions(3)%3==0) return true; } } catch(...) {} return false; } DiffusionCoreIOMimeTypes::PeakImageMimeType* DiffusionCoreIOMimeTypes::PeakImageMimeType::Clone() const { return new PeakImageMimeType(*this); } DiffusionCoreIOMimeTypes::PeakImageMimeType DiffusionCoreIOMimeTypes::PEAK_MIMETYPE() { return PeakImageMimeType(); } DiffusionCoreIOMimeTypes::SHImageMimeType::SHImageMimeType() : CustomMimeType(SH_MIMETYPE_NAME()) { std::string category = "SH Image"; this->SetCategory(category); this->SetComment("SH Image"); this->AddExtension("nii.gz"); this->AddExtension("nii"); this->AddExtension("nrrd"); this->AddExtension("shi"); } bool DiffusionCoreIOMimeTypes::SHImageMimeType::AppliesTo(const std::string &path) const { { - itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); try { - io->SetFileName( path.c_str() ); - io->ReadImageInformation(); - if ( io->GetPixelType() == itk::ImageIOBase::SCALAR && io->GetNumberOfDimensions()==4) + itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); + if (io->CanReadFile(path.c_str())) { - switch (io->GetDimensions(3)) + io->SetFileName(path.c_str()); + io->ReadImageInformation(); + if (io->GetPixelType() == itk::ImageIOBase::SCALAR && io->GetNumberOfDimensions() == 4) { - case 6: - return true; - break; - case 15: - return true; - break; - case 28: - return true; - break; - case 45: - return true; - break; - case 66: - return true; - break; - case 91: - return true; - break; - default : - return false; + switch (io->GetDimensions(3)) + { + case 6: + return true; + break; + case 15: + return true; + break; + case 28: + return true; + break; + case 45: + return true; + break; + case 66: + return true; + break; + case 91: + return true; + break; + default: + return false; + } } } } catch(...) {} } { itk::NiftiImageIO::Pointer io = itk::NiftiImageIO::New(); if ( io->CanReadFile( path.c_str() ) ) { io->SetFileName( path.c_str() ); io->ReadImageInformation(); if ( io->GetPixelType() == itk::ImageIOBase::SCALAR && io->GetNumberOfDimensions()==4) { switch (io->GetDimensions(3)) { case 6: return true; break; case 15: return true; break; case 28: return true; break; case 45: return true; break; case 66: return true; break; case 91: return true; break; default : return false; } } } } return false; } DiffusionCoreIOMimeTypes::SHImageMimeType* DiffusionCoreIOMimeTypes::SHImageMimeType::Clone() const { return new SHImageMimeType(*this); } DiffusionCoreIOMimeTypes::SHImageMimeType DiffusionCoreIOMimeTypes::SH_MIMETYPE() { return SHImageMimeType(); } CustomMimeType DiffusionCoreIOMimeTypes::DTI_MIMETYPE() { CustomMimeType mimeType(DTI_MIMETYPE_NAME()); std::string category = "Tensor Image"; mimeType.SetComment("Diffusion Tensor Image"); mimeType.SetCategory(category); mimeType.AddExtension("dti"); return mimeType; } CustomMimeType DiffusionCoreIOMimeTypes::ODF_MIMETYPE() { CustomMimeType mimeType(ODF_MIMETYPE_NAME()); std::string category = "ODF Image"; mimeType.SetComment("Diffusion ODF Image"); mimeType.SetCategory(category); mimeType.AddExtension("odf"); mimeType.AddExtension("qbi"); // legacy support return mimeType; } // Names std::string DiffusionCoreIOMimeTypes::PEAK_MIMETYPE_NAME() { static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + "_PEAKS"; return name; } std::string DiffusionCoreIOMimeTypes::DWI_NRRD_MIMETYPE_NAME() { static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dwi"; return name; } std::string DiffusionCoreIOMimeTypes::DWI_NIFTI_MIMETYPE_NAME() { static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".nii.gz"; return name; } std::string DiffusionCoreIOMimeTypes::DWI_FSL_MIMETYPE_NAME() { static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".fslgz"; return name; } std::string DiffusionCoreIOMimeTypes::DWI_DICOM_MIMETYPE_NAME() { static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".IMA"; return name; } std::string DiffusionCoreIOMimeTypes::DTI_MIMETYPE_NAME() { static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".dti"; return name; } std::string DiffusionCoreIOMimeTypes::ODF_MIMETYPE_NAME() { static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + ".odf"; return name; } std::string DiffusionCoreIOMimeTypes::SH_MIMETYPE_NAME() { static std::string name = IOMimeTypes::DEFAULT_BASE_NAME() + "_SH"; return name; } // Descriptions std::string DiffusionCoreIOMimeTypes::PEAK_MIMETYPE_DESCRIPTION() { static std::string description = "Peak Image"; return description; } std::string DiffusionCoreIOMimeTypes::DWI_NRRD_MIMETYPE_DESCRIPTION() { static std::string description = "Diffusion Weighted Images"; return description; } std::string DiffusionCoreIOMimeTypes::DWI_NIFTI_MIMETYPE_DESCRIPTION() { static std::string description = "Diffusion Weighted Images"; return description; } std::string DiffusionCoreIOMimeTypes::DWI_FSL_MIMETYPE_DESCRIPTION() { static std::string description = "Diffusion Weighted Images"; return description; } std::string DiffusionCoreIOMimeTypes::DWI_DICOM_MIMETYPE_DESCRIPTION() { static std::string description = "Diffusion Weighted Images"; return description; } std::string DiffusionCoreIOMimeTypes::DTI_MIMETYPE_DESCRIPTION() { static std::string description = "Diffusion Tensor Image"; return description; } std::string DiffusionCoreIOMimeTypes::ODF_MIMETYPE_DESCRIPTION() { static std::string description = "ODF Image"; return description; } std::string DiffusionCoreIOMimeTypes::SH_MIMETYPE_DESCRIPTION() { static std::string description = "SH Image"; return description; } } diff --git a/Modules/DiffusionImaging/DiffusionCore/autoload/IO/mitkDiffusionImageDicomReaderService.cpp b/Modules/DiffusionImaging/DiffusionCore/autoload/IO/mitkDiffusionImageDicomReaderService.cpp index a57dabb4f4..d2ff95a095 100644 --- a/Modules/DiffusionImaging/DiffusionCore/autoload/IO/mitkDiffusionImageDicomReaderService.cpp +++ b/Modules/DiffusionImaging/DiffusionCore/autoload/IO/mitkDiffusionImageDicomReaderService.cpp @@ -1,337 +1,337 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef __mitkDiffusionImageDicomReaderService_cpp #define __mitkDiffusionImageDicomReaderService_cpp #include "mitkDiffusionImageDicomReaderService.h" #include #include // Diffusion properties #include #include #include #include #include #include #include "itksys/SystemTools.hxx" #include "itkImageFileReader.h" #include "itkMetaDataObject.h" #include "itkNrrdImageIO.h" #include "mitkCustomMimeType.h" #include "mitkDiffusionCoreIOMimeTypes.h" #include #include #include #include #include #include #include #include #include #include #include #include namespace mitk { DiffusionImageDicomReaderService:: DiffusionImageDicomReaderService(const DiffusionImageDicomReaderService & other) : AbstractFileReader(other) { } DiffusionImageDicomReaderService* DiffusionImageDicomReaderService::Clone() const { return new DiffusionImageDicomReaderService(*this); } DiffusionImageDicomReaderService:: ~DiffusionImageDicomReaderService() {} DiffusionImageDicomReaderService:: DiffusionImageDicomReaderService() : mitk::AbstractFileReader( CustomMimeType( mitk::DiffusionCoreIOMimeTypes::DWI_DICOM_MIMETYPE() ), mitk::DiffusionCoreIOMimeTypes::DWI_DICOM_MIMETYPE_DESCRIPTION() ) { Options defaultOptions; defaultOptions["Load recursive"] = false; defaultOptions["Split mosaic"] = true; this->SetDefaultOptions(defaultOptions); m_ServiceReg = this->RegisterService(); } std::vector > DiffusionImageDicomReaderService::Read() { return InternalRead(); } std::vector > DiffusionImageDicomReaderService::InternalRead() { std::vector > result_images; OutputType::Pointer outputForCache = OutputType::New(); if ( this->GetInputLocation() == "") { throw itk::ImageFileReaderException(__FILE__, __LINE__, "Sorry, the filename to be read is empty!"); } else { const std::string& locale = "C"; const std::string& currLocale = setlocale( LC_ALL, nullptr ); if ( locale.compare(currLocale)!=0 ) { try { setlocale(LC_ALL, locale.c_str()); } catch(...) { MITK_INFO << "Could not set locale " << locale; } } try { Options options = this->GetOptions(); bool load_recursive = us::any_cast(options["Load recursive"]); bool split_mosaic = us::any_cast(options["Split mosaic"]); gdcm::Directory::FilenamesType complete_list; std::string folderName = itksys::SystemTools::GetFilenamePath( this->GetInputLocation() ); if( load_recursive ) { std::string subdir_prefix = ""; itksys::Directory rootdir; rootdir.Load( folderName.c_str() ); for( unsigned int idx=0; idxAddDistinguishingTag( mitk::DICOMTag(0x0028, 0x0010) ); // Number of Rows tagSorter->AddDistinguishingTag( mitk::DICOMTag(0x0028, 0x0011) ); // Number of Columns tagSorter->AddDistinguishingTag( mitk::DICOMTag(0x0028, 0x0030) ); // Pixel Spacing tagSorter->AddDistinguishingTag( mitk::DICOMTag(0x0018, 0x1164) ); // Imager Pixel Spacing tagSorter->AddDistinguishingTag( mitk::DICOMTag(0x0020, 0x0037) ); // Image Orientation (Patient) // TODO add tolerance parameter (l. 1572 of original code) // TODO handle as real vectors! cluster with configurable errors! tagSorter->AddDistinguishingTag( mitk::DICOMTag(0x0020, 0x000e) ); // Series Instance UID tagSorter->AddDistinguishingTag( mitk::DICOMTag(0x0018, 0x0050) ); // Slice Thickness tagSorter->AddDistinguishingTag( mitk::DICOMTag(0x0028, 0x0008) ); // Number of Frames //tagSorter->AddDistinguishingTag( mitk::DICOMTag(0x0020, 0x0052) ); // Frame of Reference UID // gdcmReader->AddSortingElement( tagSorter ); //mitk::DICOMFileReaderTestHelper::TestOutputsContainInputs( gdcmReader ); mitk::DICOMSortCriterion::ConstPointer sorting = mitk::SortByImagePositionPatient::New( // Image Position (Patient) //mitk::DICOMSortByTag::New( mitk::DICOMTag(0x0020, 0x0013), // instance number mitk::DICOMSortByTag::New( mitk::DICOMTag(0x0020, 0x0012), // aqcuisition number mitk::DICOMSortByTag::New( mitk::DICOMTag(0x0008, 0x0032), // aqcuisition time mitk::DICOMSortByTag::New( mitk::DICOMTag(0x0018, 0x1060), // trigger time mitk::DICOMSortByTag::New( mitk::DICOMTag(0x0008, 0x0018) // SOP instance UID (last resort, not really meaningful but decides clearly) ).GetPointer() ).GetPointer() ).GetPointer() ).GetPointer() // ).GetPointer() ).GetPointer(); tagSorter->SetSortCriterion( sorting ); // mosaic gdcmReader->SetResolveMosaic( split_mosaic ); gdcmReader->AddSortingElement( tagSorter ); gdcmReader->SetInputFiles( complete_list ); try { gdcmReader->AnalyzeInputFiles(); } catch( const itk::ExceptionObject &e) { MITK_ERROR << "Failed to analyze data. " << e.what(); } catch( const std::exception &se) { MITK_ERROR << "Std Exception " << se.what(); } gdcmReader->LoadImages(); for( unsigned int o = 0; o < gdcmReader->GetNumberOfOutputs(); o++ ) { mitk::Image::Pointer loaded_image = gdcmReader->GetOutput(o).GetMitkImage(); StringProperty::Pointer nameProp; if (gdcmReader->GetSeriesName(o)!="-") nameProp = StringProperty::New(gdcmReader->GetSeriesName(o)); else if (gdcmReader->GetStudyName(o)!="-") nameProp = StringProperty::New(gdcmReader->GetStudyName(o)); else nameProp = StringProperty::New(folderName); loaded_image->SetProperty("name", nameProp); std::string val = "-"; if (gdcmReader->patient_ids().size()>o) { val = gdcmReader->patient_ids().at(o); loaded_image->GetPropertyList()->SetStringProperty("DICOM.patient_id",val.c_str()); } if (gdcmReader->patient_names().size()>o) { val = gdcmReader->patient_names().at(o); loaded_image->GetPropertyList()->SetStringProperty("DICOM.patient_name",val.c_str()); } if (gdcmReader->study_instance_uids().size()>o) { val = gdcmReader->study_instance_uids().at(o); loaded_image->GetPropertyList()->SetStringProperty("DICOM.study_instance_uid",val.c_str()); } if (gdcmReader->series_instance_uids().size()>o) { val = gdcmReader->series_instance_uids().at(o); loaded_image->GetPropertyList()->SetStringProperty("DICOM.series_instance_uid",val.c_str()); } if (gdcmReader->sop_instance_uids().size()>o) { val = gdcmReader->sop_instance_uids().at(o); loaded_image->GetPropertyList()->SetStringProperty("DICOM.sop_instance_uid",val.c_str()); } if (gdcmReader->frame_of_reference_uids().size()>o) { val = gdcmReader->frame_of_reference_uids().at(o); loaded_image->GetPropertyList()->SetStringProperty("DICOM.frame_of_reference_uid",val.c_str()); } result_images.push_back(loaded_image.GetPointer()); } // Since we have already read the tree, we can store it in a cache variable // so that it can be assigned to the DataObject in GenerateData(); m_OutputCache = outputForCache; m_CacheTime.Modified(); try { setlocale(LC_ALL, currLocale.c_str()); } catch(...) { MITK_INFO << "Could not reset locale " << currLocale; } } catch(std::exception& e) { try { setlocale(LC_ALL, currLocale.c_str()); } catch(...) { MITK_INFO << "Could not reset locale " << currLocale; } MITK_INFO << "Std::Exception while reading file!!"; MITK_INFO << e.what(); throw itk::ImageFileReaderException(__FILE__, __LINE__, e.what()); } catch(...) { try { setlocale(LC_ALL, currLocale.c_str()); } catch(...) { MITK_INFO << "Could not reset locale " << currLocale; } MITK_INFO << "Exception while reading file!!"; throw itk::ImageFileReaderException(__FILE__, __LINE__, "Sorry, an error occurred while reading the requested vessel tree file!"); } } return result_images; } } //namespace MITK #endif diff --git a/Modules/DiffusionImaging/DiffusionCore/cmdapps/CMakeLists.txt b/Modules/DiffusionImaging/DiffusionCore/cmdapps/CMakeLists.txt index c94d269842..ad3d4173e3 100644 --- a/Modules/DiffusionImaging/DiffusionCore/cmdapps/CMakeLists.txt +++ b/Modules/DiffusionImaging/DiffusionCore/cmdapps/CMakeLists.txt @@ -1,46 +1,41 @@ option(BUILD_DiffusionCoreCmdApps "Build commandline tools for diffusion" OFF) if(BUILD_DiffusionCoreCmdApps OR MITK_BUILD_ALL_APPS) # needed include directories include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) # list of diffusion cmdapps # if an app requires additional dependencies # they are added after a "^^" and separated by "_" set( diffusioncorecmdapps ImageResampler^^ CopyGeometry^^ Registration^^ DiffusionDICOMLoader^^ ResampleGradients^^ ShToOdfImage^^ DImp^^ DReg^^ ) foreach(diffusioncorecmdapp ${diffusioncorecmdapps}) # extract cmd app name and dependencies string(REPLACE "^^" "\\;" cmdapp_info ${diffusioncorecmdapp}) set(cmdapp_info_list ${cmdapp_info}) list(GET cmdapp_info_list 0 appname) list(GET cmdapp_info_list 1 raw_dependencies) string(REPLACE "_" "\\;" dependencies "${raw_dependencies}") set(dependencies_list ${dependencies}) mitkFunctionCreateCommandLineApp( NAME ${appname} DEPENDS MitkCore MitkDiffusionCore ${dependencies_list} PACKAGE_DEPENDS ITK ) endforeach() endif() - -mitkFunctionCreateCommandLineApp( - NAME Dicom2Nrrd - DEPENDS MitkCore ${dependencies_list} -) diff --git a/Modules/DiffusionImaging/DiffusionCore/cmdapps/Dicom2Nrrd.cpp b/Modules/DiffusionImaging/DiffusionCore/cmdapps/Dicom2Nrrd.cpp deleted file mode 100644 index 663d519a82..0000000000 --- a/Modules/DiffusionImaging/DiffusionCore/cmdapps/Dicom2Nrrd.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#include "mitkDicomSeriesReader.h" -#include "mitkProperties.h" - -#include "mitkCommandLineParser.h" -#include "mitkIOUtil.h" - -int main(int argc, char* argv[]) -{ - mitkCommandLineParser parser; - - parser.setTitle("Dicom Loader"); - parser.setCategory("Preprocessing Tools"); - parser.setDescription(""); - parser.setContributor("MIC"); - - parser.setArgumentPrefix("--","-"); - // Add command line argument names - parser.addArgument("help", "h",mitkCommandLineParser::Bool, "Help:", "Show this help text"); - parser.addArgument("input", "i", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder",us::Any(),false); - parser.addArgument("output", "o", mitkCommandLineParser::OutputFile, "Output file:", "Output file",us::Any(),false); - - - std::map parsedArgs = parser.parseArguments(argc, argv); - - if (parsedArgs.size()==0) - return EXIT_FAILURE; - - // Show a help message - if ( parsedArgs.count("help") || parsedArgs.count("h")) - { - std::cout << parser.helpText(); - return EXIT_SUCCESS; - } - - std::string inputFolder = us::any_cast(parsedArgs["input"]); - std::string outFileName = us::any_cast(parsedArgs["output"]); - - //check if DICOMTags have been set as property for mitk::Image - mitk::DicomSeriesReader::FileNamesGrouping seriesInFiles = mitk::DicomSeriesReader::GetSeries( inputFolder, true ); - std::list images; - std::map fileMap; - - // TODO sort series UIDs, implementation of map iterator might differ on different platforms (or verify this is a standard topic??) - for (mitk::DicomSeriesReader::FileNamesGrouping::const_iterator seriesIter = seriesInFiles.begin(); - seriesIter != seriesInFiles.end(); - ++seriesIter) - { - mitk::DicomSeriesReader::StringContainer files = seriesIter->second.GetFilenames(); - - mitk::DataNode::Pointer node = mitk::DicomSeriesReader::LoadDicomSeries( files ); - - if (node.IsNotNull()) - { - mitk::Image::Pointer image = dynamic_cast( node->GetData() ); - - images.push_back( image ); - fileMap.insert( std::pair(image,files)); - } - } - - // WARN: EXPECT ONLY ONE ITEM PER FOLDER - for ( std::list::const_iterator imageIter = images.begin(); - imageIter != images.end(); - ++imageIter ) - { - const mitk::Image::Pointer image = *imageIter; - mitk::IOUtil::Save(image,outFileName); - } - return EXIT_SUCCESS; -} diff --git a/Modules/ImageExtraction/Testing/mitkExtractImageFilterTest.cpp b/Modules/ImageExtraction/Testing/mitkExtractImageFilterTest.cpp index f6b9ba8cbc..177640f4c3 100644 --- a/Modules/ImageExtraction/Testing/mitkExtractImageFilterTest.cpp +++ b/Modules/ImageExtraction/Testing/mitkExtractImageFilterTest.cpp @@ -1,414 +1,413 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkCompareImageSliceTestHelper.h" #include "mitkCoreObjectFactory.h" -#include "mitkDataNodeFactory.h" #include "mitkExtractImageFilter.h" #include "mitkImageTimeSelector.h" +#include "mitkIOUtil.h" unsigned int CompareImageSliceTestHelper::m_Dimension0 = 0; unsigned int CompareImageSliceTestHelper::m_Dimension1 = 0; unsigned int CompareImageSliceTestHelper::m_SliceDimension = 0; unsigned int CompareImageSliceTestHelper::m_SliceIndex = 0; bool CompareImageSliceTestHelper::m_ComparisonResult = false; mitk::Image *CompareImageSliceTestHelper::m_SliceImage = nullptr; class mitkExtractImageFilterTestClass { public: static void Test3D(mitk::ExtractImageFilter *filter, mitk::Image *image, unsigned int &numberFailed) { // we expect the result to be the same as the input for 2D (the only possible slice) assert(filter); assert(image); filter->SetInput(image); unsigned int initialNumberFailed = numberFailed; for (unsigned int sliceDimension = 0; sliceDimension < 6; ++sliceDimension) { for (unsigned int sliceIndex = 1; sliceIndex < 3; ++sliceIndex) { filter->SetSliceDimension(sliceDimension); filter->SetSliceIndex(sliceIndex); // second slice in that direction try { filter->Update(); } catch (...) { if (sliceDimension < 3) { ++numberFailed; std::cerr << " (EE) Extracting produced an exception for " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; continue; } else { // this was expected and is nice to see continue; } } if (sliceDimension >= 3) { // we would expect to get an exception earlier ++numberFailed; std::cerr << " (EE) Extracting produced no exception (although it should) for " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; continue; } mitk::Image::Pointer output = filter->GetOutput(); if (output.GetPointer() == filter->GetInput()) { ++numberFailed; std::cerr << " (EE) Extracting failed with wrong result (output == input) for " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; } if (output->GetDimension() == 2) { try { if (!CompareImageSliceTestHelper::CompareSlice(image, sliceDimension, sliceIndex, output)) { ++numberFailed; std::cerr << " (EE) Extracting extracted the wrong pixels or somehow messed up with a " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; } else { std::cerr << " :-) Extracting extracted somehow correct pixels with a " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; } } catch (std::exception &e) { ++numberFailed; std::cerr << " (EE) Extracting extracted the wrong pixels or somehow SEVERELY messed up with a " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; std::cerr << "Following exception was thrown: " << e.what() << std::endl; } } else { ++numberFailed; std::cerr << " (EE) Extracting failed with wrong result (not 2D) for " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; } } } if (numberFailed == initialNumberFailed) { std::cout << " (II) Extracting works like expected (2D result and all pixels the same) for " << image->GetDimension() << "-dimensional image." << "(l. " << __LINE__ << ")" << std::endl; } } static void Test2D(mitk::ExtractImageFilter *filter, mitk::Image *image, unsigned int &numberFailed) { // we expect the result to be the same as the input for 2D (the only possible slice) assert(filter); assert(image); filter->SetInput(image); unsigned int initialNumberFailed = numberFailed; for (unsigned int sliceDimension = 0; sliceDimension < 6; ++sliceDimension) { filter->SetSliceDimension(sliceDimension); filter->SetSliceIndex(1); // second slice in that direction try { filter->Update(); } catch (...) { ++numberFailed; std::cerr << " (EE) Extracting produced an exception for " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex 1." << "(l. " << __LINE__ << ")" << std::endl; continue; } mitk::Image::Pointer output = filter->GetOutput(); if (output.GetPointer() != filter->GetInput()) { ++numberFailed; std::cerr << " (EE) Extracting failed with wrong result for " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex 1." << "(l. " << __LINE__ << ")" << std::endl; } } if (numberFailed == initialNumberFailed) { std::cout << " (II) Extracting works like expected for " << image->GetDimension() << "-dimensional image." << "(l. " << __LINE__ << ")" << std::endl; } } static void Test4D(mitk::ExtractImageFilter *filter, mitk::Image *image, unsigned int &numberFailed) { // we expect the result to be the same as the input for 2D (the only possible slice) assert(filter); assert(image); filter->SetInput(image); unsigned int initialNumberFailed = numberFailed; for (unsigned int timeStep = 0; timeStep < image->GetTimeSteps(); ++timeStep) { mitk::ImageTimeSelector::Pointer timeSelector = mitk::ImageTimeSelector::New(); timeSelector->SetInput(image); timeSelector->SetTimeNr(timeStep); timeSelector->UpdateLargestPossibleRegion(); mitk::Image::Pointer image3D = timeSelector->GetOutput(); for (unsigned int sliceDimension = 0; sliceDimension < 6; ++sliceDimension) { unsigned int maxSliceIndex = 3; if (image->GetDimension(sliceDimension) < 3) maxSliceIndex = 2; if (image->GetDimension(sliceDimension) < 2) maxSliceIndex = 1; for (unsigned int sliceIndex = 1; sliceIndex < maxSliceIndex; ++sliceIndex) { filter->SetTimeStep(timeStep); filter->SetSliceDimension(sliceDimension); filter->SetSliceIndex(sliceIndex); // second slice in that direction try { filter->Update(); } catch (...) { if (sliceDimension < 3) { ++numberFailed; std::cerr << " (EE) Extracting produced an exception for " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; continue; } else { // this was expected and is nice to see continue; } } if (sliceDimension >= 3) { // we would expect to get an exception earlier ++numberFailed; std::cerr << " (EE) Extracting produced no exception (although it should) for " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; continue; } mitk::Image::Pointer output = filter->GetOutput(); if (output.GetPointer() == filter->GetInput()) { ++numberFailed; std::cerr << " (EE) Extracting failed with wrong result (output == input) for " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; } if (output->GetDimension() == 2) { if (!CompareImageSliceTestHelper::CompareSlice(image3D, sliceDimension, sliceIndex, output)) { ++numberFailed; std::cerr << " (EE) Extracting extracted the wrong pixels or somehow messed up with a " << image->GetDimension() << "-dimensional image, time step " << timeStep << "sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; } } else { ++numberFailed; std::cerr << " (EE) Extracting failed with wrong result (not 2D) for " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex " << sliceIndex << "." << "(l. " << __LINE__ << ")" << std::endl; } } } if (numberFailed == initialNumberFailed) { std::cout << " (II) Extracting works like expected (2D result and all pixels the same) for " << image->GetDimension() << "-dimensional image." << "(l. " << __LINE__ << ")" << std::endl; } } } static void TestOtherD(mitk::ExtractImageFilter *filter, mitk::Image *image, unsigned int &numberFailed) { // we expect the result to be empty for images other than 2D or 3D assert(filter); assert(image); filter->SetInput(image); unsigned int initialNumberFailed = numberFailed; for (unsigned int sliceDimension = 0; sliceDimension < 6; ++sliceDimension) { filter->SetSliceDimension(sliceDimension); filter->SetSliceIndex(1); // second slice in that direction try { filter->Update(); } catch (...) { continue; } // no exception ++numberFailed; std::cerr << " (EE) Extracting produced no exception for " << image->GetDimension() << "-dimensional image, sliceDimension " << sliceDimension << " sliceIndex 1." << "(l. " << __LINE__ << ")" << std::endl; } if (numberFailed == initialNumberFailed) { std::cout << " (II) Extracting works like expected for " << image->GetDimension() << "-dimensional image." << "(l. " << __LINE__ << ")" << std::endl; } } }; /// ctest entry point int mitkExtractImageFilterTest(int argc, char *argv[]) { // one big variable to tell if anything went wrong unsigned int numberFailed(0); // need one parameter (image filename) if (argc == 0) { std::cerr << "No file specified [FAILED]" << std::endl; return EXIT_FAILURE; } // load the image mitk::Image::Pointer image = nullptr; - mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New(); try { std::cout << "Testing with parameter '" << argv[1] << "'" << std::endl; - factory->SetFileName(argv[1]); - factory->Update(); + auto results = mitk::IOUtil::Load(argv[1]); - if (factory->GetNumberOfOutputs() < 1) + if (results.empty()) { std::cerr << "File could not be loaded [FAILED]" << std::endl; return EXIT_FAILURE; } - mitk::DataNode::Pointer node = factory->GetOutput(0); + + mitk::DataNode::Pointer node = results[0]; image = dynamic_cast(node->GetData()); if (image.IsNull()) { std::cout << "File not an image - test will not be applied [PASSED]" << std::endl; std::cout << "[TEST DONE]" << std::endl; return EXIT_SUCCESS; } } catch (itk::ExceptionObject &ex) { ++numberFailed; std::cerr << "Exception: " << ex << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << " (II) Could load image." << std::endl; std::cout << "Testing filter instantiation" << std::endl; // instantiation mitk::ExtractImageFilter::Pointer filter = mitk::ExtractImageFilter::New(); if (filter.IsNotNull()) { std::cout << " (II) Instantiation works." << std::endl; } else { ++numberFailed; std::cout << "Test failed, and it's the ugliest one!" << std::endl; return EXIT_FAILURE; } // some real work if (image->GetDimension() == 2) { mitkExtractImageFilterTestClass::Test2D(filter, image, numberFailed); } else if (image->GetDimension() == 3) { mitkExtractImageFilterTestClass::Test3D(filter, image, numberFailed); } else if (image->GetDimension() == 4) { mitkExtractImageFilterTestClass::Test4D(filter, image, numberFailed); } std::cout << "Testing filter destruction" << std::endl; // freeing filter = nullptr; std::cout << " (II) Freeing works." << std::endl; if (numberFailed > 0) { std::cerr << numberFailed << " tests failed." << std::endl; return EXIT_FAILURE; } else { std::cout << "PASSED all tests." << std::endl; return EXIT_SUCCESS; } } diff --git a/Modules/LegacyIO/Testing/files.cmake b/Modules/LegacyIO/Testing/files.cmake deleted file mode 100644 index 0e81f8005f..0000000000 --- a/Modules/LegacyIO/Testing/files.cmake +++ /dev/null @@ -1,8 +0,0 @@ -# test with image filename as an extra command line parameter -set(MODULE_IMAGE_TESTS - mitkDataNodeFactoryTest.cpp #runs on all types of data -) - -set(MODULE_SURFACE_TESTS - mitkDataNodeFactoryTest.cpp #runs on all types of data -) diff --git a/Modules/LegacyIO/Testing/mitkDataNodeFactoryTest.cpp b/Modules/LegacyIO/Testing/mitkDataNodeFactoryTest.cpp deleted file mode 100644 index f5c2e1219c..0000000000 --- a/Modules/LegacyIO/Testing/mitkDataNodeFactoryTest.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#include "mitkDataNodeFactory.h" -#include "mitkTestingMacros.h" - -#include "mitkProperties.h" - -#include -#include -/** - * Test for the class "DataNodeFactory". - * - * argc and argv are the command line parameters which were passed to - * the ADD_TEST command in the CMakeLists.txt file. For the automatic - * tests, argv is either empty for the simple tests or contains the filename - * of a test image for the image tests (see CMakeLists.txt). - */ -int mitkDataNodeFactoryTest(int, char *argv[]) -{ - // always start with this! - MITK_TEST_BEGIN("DataNodeFactory") - - mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New(); - MITK_TEST_OUTPUT(<< "Loading file: " << argv[1]); - - factory->SetFileName(argv[1]); - MITK_TEST_CONDITION_REQUIRED(strcmp(factory->GetFileName(), argv[1]) == 0, "Test for Set/GetFileName()"); - - factory->Update(); - MITK_TEST_CONDITION_REQUIRED(factory->GetNumberOfOutputs() > 0, "file loaded"); - - MITK_TEST_OUTPUT(<< "Test function SetDefaultCommonProperties()"); - mitk::DataNode::Pointer node = factory->GetOutput(0); - - MITK_TEST_CONDITION_REQUIRED(node.IsNotNull(), "DataNodeFactory has returned a non-empty node.") - - factory->SetDefaultCommonProperties(node); - // get file path and property - std::string filePath = itksys::SystemTools::GetFilenamePath(factory->GetFileName()); - mitk::StringProperty::Pointer pathProp = - dynamic_cast(node->GetProperty(mitk::StringProperty::PATH)); - - MITK_TEST_CONDITION_REQUIRED(strcmp(pathProp->GetValue(), filePath.c_str()) == 0, "Test for file path"); - - std::string fileName = factory->GetFileName(); - std::string fileExtension = itksys::SystemTools::GetFilenameExtension(fileName); - if (fileName.substr(fileName.size() - 3) == ".gz") - fileName = fileName.substr(0, fileName.length() - 3); - fileName = fileName.substr(0, fileName.length() - fileExtension.length()); - fileName = fileName.substr(filePath.length() + 1, fileName.length()); - mitk::StringProperty::Pointer nameProp = dynamic_cast(node->GetProperty("name")); - MITK_TEST_CONDITION_REQUIRED(strcmp(nameProp->GetValue(), fileName.c_str()) == 0, "Test for file name"); - - mitk::BoolProperty::Pointer visibleProp = dynamic_cast(node->GetProperty("visible")); - MITK_TEST_CONDITION_REQUIRED(visibleProp->GetValue() == true, "Test for visibility"); - // always end with this! - MITK_TEST_END() -} diff --git a/Modules/LegacyIO/files.cmake b/Modules/LegacyIO/files.cmake index 5790303f08..f801775e91 100644 --- a/Modules/LegacyIO/files.cmake +++ b/Modules/LegacyIO/files.cmake @@ -1,30 +1,29 @@ set(H_FILES ) set(CPP_FILES mitkBaseDataIOFactory.cpp - mitkDataNodeFactory.cpp mitkFileSeriesReader.cpp mitkImageWriter.cpp mitkImageWriterFactory.cpp mitkItkImageFileIOFactory.cpp mitkItkImageFileReader.cpp mitkItkPictureWrite.cpp mitkPointSetIOFactory.cpp mitkPointSetReader.cpp mitkPointSetWriter.cpp mitkPointSetWriterFactory.cpp mitkRawImageFileReader.cpp mitkSTLFileIOFactory.cpp mitkSTLFileReader.cpp mitkSurfaceVtkWriter.cpp mitkSurfaceVtkWriterFactory.cpp mitkVtiFileIOFactory.cpp mitkVtiFileReader.cpp mitkVtkImageIOFactory.cpp mitkVtkImageReader.cpp mitkVtkSurfaceIOFactory.cpp mitkVtkSurfaceReader.cpp vtkPointSetXMLParser.cpp ) diff --git a/Modules/LegacyIO/mitkDataNodeFactory.cpp b/Modules/LegacyIO/mitkDataNodeFactory.cpp deleted file mode 100644 index d4ce152f41..0000000000 --- a/Modules/LegacyIO/mitkDataNodeFactory.cpp +++ /dev/null @@ -1,496 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#include -#include -#include -#include -#include -#include - -// C-Standard library includes -#include -#include - -// STL-related includes -#include -#include -#include -#include -#include - -// VTK-related includes -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -// ITK-related includes - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef NOMINMAX -#define DEF_NOMINMAX -#undef NOMINMAX -#endif - -#include - -#ifdef DEF_NOMINMAX -#ifndef NOMINMAX -#define NOMINMAX -#endif -#undef DEF_NOMINMAX -#endif - -#include -#include - -// MITK-related includes -#include "mitkPointSet.h" -#include "mitkProperties.h" -#include "mitkStringProperty.h" -#include "mitkSurface.h" -//#include "mitkMaterialProperty.h" -#include "mitkCoreObjectFactory.h" -#include "mitkImage.h" -#include "mitkImageChannelSelector.h" -#include "mitkImageSliceSelector.h" -#include "mitkLevelWindowProperty.h" -#include "mitkLookupTable.h" -#include "mitkLookupTableProperty.h" -#include "mitkProgressBar.h" -#include "mitkPropertyNameHelper.h" -#include "mitkTransferFunctionProperty.h" -#include "mitkVtkInterpolationProperty.h" -#include "mitkVtkRepresentationProperty.h" -#include "mitkVtkResliceInterpolationProperty.h" -#include "mitkVtkScalarModeProperty.h" -#include - -bool mitk::DataNodeFactory::m_TextureInterpolationActive = - false; // default value for texture interpolation if nothing is defined in global options (see QmitkMainTemplate.ui.h) - -mitk::DataNodeFactory::DataNodeFactory() -{ - m_Serie = false; - m_OldProgress = 0; - this->Modified(); - // ensure that a CoreObjectFactory has been instantiated - mitk::CoreObjectFactory::GetInstance(); -} - -mitk::DataNodeFactory::~DataNodeFactory() -{ -} - -void mitk::DataNodeFactory::SetImageSerie(bool serie) -{ - m_Serie = serie; -} - -void mitk::DataNodeFactory::GenerateData() -{ - // IF filename is something.pic, and something.pic does not exist, try to read something.pic.gz - // if there are both, something.pic and something.pic.gz, only the requested file is read - // not only for images, but for all formats - std::ifstream exists(m_FileName.c_str()); - if (!exists) - { - std::string testfilename = m_FileName + ".gz"; - - std::ifstream exists(testfilename.c_str()); - if (exists.good()) - { - m_FileName += ".gz"; - } - else - { - testfilename = m_FileName + ".GZ"; - std::ifstream exists(testfilename.c_str()); - if (exists.good()) - { - m_FileName += ".GZ"; - } - else - { - std::string message("File does not exist, or cannot be read. Filename = "); - message += m_FileName; - MITK_ERROR << message; - itkExceptionMacro(<< message.str()); - } - } - } - - // part for DICOM - // const char *numbers = "0123456789."; - // std::string::size_type first_non_number; - // first_non_number = itksys::SystemTools::GetFilenameName(m_FileName).find_first_not_of ( numbers ); - - if (DicomSeriesReader::IsDicom(this->m_FileName) /*|| first_non_number == std::string::npos*/) - { - this->ReadFileSeriesTypeDCM(); - } - else - { - bool usedNewDTNF = false; - - // the mitkBaseDataIO class returns a pointer of a vector of BaseData objects - std::vector baseDataVector = - mitk::BaseDataIO::LoadBaseDataFromFile(m_FileName, m_FilePrefix, m_FilePattern, m_Serie); - - if (!baseDataVector.empty()) - this->ResizeOutputs((unsigned int)baseDataVector.size()); - - for (int i = 0; i < (int)baseDataVector.size(); i++) - { - mitk::BaseData::Pointer baseData = baseDataVector.at(i); - - if (baseData.IsNotNull()) - { - usedNewDTNF = true; - mitk::DataNode::Pointer node = mitk::DataNode::New(); - node->SetData(baseData); - this->SetDefaultCommonProperties(node); - - this->SetOutput(this->MakeNameFromOutputIndex(i), node); - } - } - if (!usedNewDTNF && (m_FileName != "") && !(m_Serie == false)) - ReadFileSeriesTypeITKImageSeriesReader(); - } -} - -void mitk::DataNodeFactory::ResizeOutputs(const unsigned int &num) -{ - unsigned int prevNum = this->GetNumberOfOutputs(); - this->SetNumberOfIndexedOutputs(num); - for (unsigned int i = prevNum; i < num; ++i) - { - this->SetNthOutput(i, this->MakeOutput(i).GetPointer()); - } -} - -bool mitk::DataNodeFactory::FileNameEndsWith(const std::string &name) -{ - if (m_FileName.size() < name.size()) - return false; - - return m_FileName.substr(m_FileName.size() - name.size()) == name; -} - -bool mitk::DataNodeFactory::FilePatternEndsWith(const std::string &name) -{ - return m_FilePattern.find(name) != std::string::npos; -} - -std::string mitk::DataNodeFactory::GetBaseFileName() -{ - return itksys::SystemTools::GetFilenameName(m_FileName); -} - -std::string mitk::DataNodeFactory::GetBaseFilePrefix() -{ - return itksys::SystemTools::GetFilenameName(m_FilePrefix); -} - -std::string mitk::DataNodeFactory::GetDirectory() -{ - if (!m_FileName.empty()) - return itksys::SystemTools::GetFilenamePath(m_FileName); - if (!m_FilePrefix.empty()) - return itksys::SystemTools::GetFilenamePath(m_FilePrefix); - - return std::string(); -} - -void mitk::DataNodeFactory::ReadFileSeriesTypeDCM() -{ - mitk::LocaleSwitch localeSwitch("C"); - std::locale previousCppLocale(std::cin.getloc()); - std::locale l("C"); - std::cin.imbue(l); - - if (DicomSeriesReader::IsPhilips3DDicom(this->GetFileName())) - { - MITK_INFO << "it is a Philips3D US Dicom file" << std::endl; - this->ResizeOutputs(1); - DataNode::Pointer node = this->GetOutput(); - mitk::DicomSeriesReader::StringContainer stringvec; - stringvec.push_back(this->GetFileName()); - if (DicomSeriesReader::LoadDicomSeries(stringvec, *node)) - { - node->SetName(this->GetBaseFileName()); - } - std::cin.imbue(previousCppLocale); - return; - } - - DicomSeriesReader::FileNamesGrouping imageBlocks = DicomSeriesReader::GetSeries( - this->GetDirectory(), true, this->m_SeriesRestrictions); // true = group gantry tilt images - const unsigned int size = imageBlocks.size(); - - this->ResizeOutputs(size); - ProgressBar::GetInstance()->AddStepsToDo(size); - ProgressBar::GetInstance()->Progress(); - - unsigned int outputIndex = 0u; - const DicomSeriesReader::FileNamesGrouping::const_iterator n_end = imageBlocks.end(); - - for (DicomSeriesReader::FileNamesGrouping::const_iterator n_it = imageBlocks.begin(); n_it != n_end; ++n_it) - { - const std::string &uid = n_it->first; - DataNode::Pointer node = this->GetOutput(outputIndex); - - const DicomSeriesReader::ImageBlockDescriptor &imageBlockDescriptor(n_it->second); - - MITK_INFO << "--------------------------------------------------------------------------------"; - MITK_INFO << "DataNodeFactory: Loading DICOM series " << outputIndex << ": Series UID " - << imageBlockDescriptor.GetSeriesInstanceUID() << std::endl; - MITK_INFO << " " << imageBlockDescriptor.GetFilenames().size() << " '" << imageBlockDescriptor.GetModality() - << "' files (" << imageBlockDescriptor.GetSOPClassUIDAsString() << ") loaded into 1 mitk::Image"; - MITK_INFO << " multi-frame: " << (imageBlockDescriptor.IsMultiFrameImage() ? "Yes" : "No"); - MITK_INFO << " reader support: " << DicomSeriesReader::ReaderImplementationLevelToString( - imageBlockDescriptor.GetReaderImplementationLevel()); - MITK_INFO << " pixel spacing type: " - << DicomSeriesReader::PixelSpacingInterpretationToString(imageBlockDescriptor.GetPixelSpacingType()); - MITK_INFO << " gantry tilt corrected: " << (imageBlockDescriptor.HasGantryTiltCorrected() ? "Yes" : "No"); - MITK_INFO << " 3D+t: " << (imageBlockDescriptor.HasMultipleTimePoints() ? "Yes" : "No"); - MITK_INFO << "--------------------------------------------------------------------------------"; - - if (DicomSeriesReader::LoadDicomSeries(n_it->second.GetFilenames(), *node, true, true, true)) - { - std::string nodeName(uid); - std::string studyDescription; - - if (GetBackwardsCompatibleDICOMProperty( - 0x0008, 0x1030, "dicom.study.StudyDescription", node->GetPropertyList(), studyDescription)) - { - nodeName = studyDescription; - std::string seriesDescription; - - if (GetBackwardsCompatibleDICOMProperty( - 0x0008, 0x103e, "dicom.study.SeriesDescription", node->GetPropertyList(), seriesDescription)) - { - nodeName += "/" + seriesDescription; - } - } - - node->SetName(nodeName); - - ++outputIndex; - } - else - { - MITK_ERROR << "DataNodeFactory: Skipping series " << outputIndex << " due to some unspecified error..." - << std::endl; - } - - ProgressBar::GetInstance()->Progress(); - } - - std::cin.imbue(previousCppLocale); -} - -void mitk::DataNodeFactory::ReadFileSeriesTypeITKImageSeriesReader() -{ - typedef itk::Image ImageType; - typedef itk::ImageSeriesReader ReaderType; - - if (!this->GenerateFileList()) - { - itkWarningMacro("Sorry, file list could not be generated!"); - return; - } - if (m_MatchedFileNames.size() == 0) - { - itkWarningMacro("Sorry, no files matched the given filename (" << m_FileName << ")!"); - return; - } - - // - // Finally, initialize the ITK-reader and load the files! - // - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileNames(m_MatchedFileNames); - try - { - reader->Update(); - ResizeOutputs(reader->GetNumberOfOutputs()); - for (unsigned int i = 0; i < reader->GetNumberOfOutputs(); ++i) - { - // Initialize mitk image from itk - mitk::Image::Pointer image = mitk::Image::New(); - image->InitializeByItk(reader->GetOutput(i)); - image->SetVolume(reader->GetOutput(i)->GetBufferPointer()); - - // add the mitk image to the node - mitk::DataNode::Pointer node = this->GetOutput(i); - node->SetData(image); - - mitk::StringProperty::Pointer nameProp = mitk::StringProperty::New(m_FileName); - node->SetProperty("name", nameProp); - } - } - catch (const std::exception &e) - { - itkWarningMacro(<< e.what()); - return; - } -} - -mitk::ColorProperty::Pointer mitk::DataNodeFactory::DefaultColorForOrgan(const std::string &organ) -{ - static bool initialized = false; - static std::map s_ColorMap; - - if (!initialized) - { - // all lowercase here, please! - - s_ColorMap.insert(std::make_pair("ankle", "0xe38686")); - s_ColorMap.insert(std::make_pair("appendix", "0xe38686")); - s_ColorMap.insert(std::make_pair("blood vessels", "0xff3131")); - s_ColorMap.insert(std::make_pair("bronchial tree", "0x3168ff")); - s_ColorMap.insert(std::make_pair("bone", "0xd5d5d5")); - s_ColorMap.insert(std::make_pair("brain", "0xff9cca")); - s_ColorMap.insert(std::make_pair("coccyx", "0xe38686")); - s_ColorMap.insert(std::make_pair("colon", "0xe38686")); - s_ColorMap.insert(std::make_pair("cyst", "0xe38686")); - s_ColorMap.insert(std::make_pair("elbow", "0xe38686")); - s_ColorMap.insert(std::make_pair("eye", "0xe38686")); - s_ColorMap.insert(std::make_pair("fallopian tube", "0xe38686")); - s_ColorMap.insert(std::make_pair("fat", "0xff2bee")); - s_ColorMap.insert(std::make_pair("hand", "0xe38686")); - s_ColorMap.insert(std::make_pair("gall bladder", "0x567f18")); - s_ColorMap.insert(std::make_pair("heart", "0xeb1d32")); - s_ColorMap.insert(std::make_pair("hip", "0xe38686")); - s_ColorMap.insert(std::make_pair("kidney", "0xd33f00")); - s_ColorMap.insert(std::make_pair("knee", "0xe38686")); - s_ColorMap.insert(std::make_pair("larynx", "0xe38686")); - s_ColorMap.insert(std::make_pair("liver", "0xffcc3d")); - s_ColorMap.insert(std::make_pair("lung", "0x6bdcff")); - s_ColorMap.insert(std::make_pair("lymph node", "0xff0000")); - s_ColorMap.insert(std::make_pair("muscle", "0xff456a")); - s_ColorMap.insert(std::make_pair("nerve", "0xffea4f")); - s_ColorMap.insert(std::make_pair("nose", "0xe38686")); - s_ColorMap.insert(std::make_pair("oesophagus", "0xe38686")); - s_ColorMap.insert(std::make_pair("ovaries", "0xe38686")); - s_ColorMap.insert(std::make_pair("pancreas", "0xf9ab3d")); - s_ColorMap.insert(std::make_pair("pelvis", "0xe38686")); - s_ColorMap.insert(std::make_pair("penis", "0xe38686")); - s_ColorMap.insert(std::make_pair("pharynx", "0xe38686")); - s_ColorMap.insert(std::make_pair("prostate", "0xe38686")); - s_ColorMap.insert(std::make_pair("rectum", "0xe38686")); - s_ColorMap.insert(std::make_pair("sacrum", "0xe38686")); - s_ColorMap.insert(std::make_pair("seminal vesicle", "0xe38686")); - s_ColorMap.insert(std::make_pair("shoulder", "0xe38686")); - s_ColorMap.insert(std::make_pair("spinal cord", "0xf5f93d")); - s_ColorMap.insert(std::make_pair("spleen", "0xf96c3d")); - s_ColorMap.insert(std::make_pair("stomach", "0xf96c3d")); - s_ColorMap.insert(std::make_pair("teeth", "0xfffcd8")); - s_ColorMap.insert(std::make_pair("testicles", "0xe38686")); - s_ColorMap.insert(std::make_pair("thyroid", "0xfff694")); - s_ColorMap.insert(std::make_pair("tongue", "0xe38686")); - s_ColorMap.insert(std::make_pair("tumor", "0x937011")); - s_ColorMap.insert(std::make_pair("urethra", "0xf8ff32")); - s_ColorMap.insert(std::make_pair("urinary bladder", "0xf8ff32")); - s_ColorMap.insert(std::make_pair("uterus", "0xe38686")); - s_ColorMap.insert(std::make_pair("vagina", "0xe38686")); - s_ColorMap.insert(std::make_pair("vertebra", "0xe38686")); - s_ColorMap.insert(std::make_pair("wrist", "0xe38686")); - initialized = true; - } - - std::string lowercaseOrgan(organ); - for (unsigned int i = 0; i < organ.length(); i++) - { - lowercaseOrgan[i] = tolower(lowercaseOrgan[i]); - } - - std::map::iterator iter = s_ColorMap.find(lowercaseOrgan); - if (iter != s_ColorMap.end()) - { - std::string hexColor = iter->second; - std::string hexRed = std::string("0x") + hexColor.substr(2, 2); - std::string hexGreen = std::string("0x") + hexColor.substr(4, 2); - std::string hexBlue = std::string("0x") + hexColor.substr(6, 2); - - long int red = strtol(hexRed.c_str(), nullptr, 16); - long int green = strtol(hexGreen.c_str(), nullptr, 16); - long int blue = strtol(hexBlue.c_str(), nullptr, 16); - - return ColorProperty::New((float)red / 255.0, (float)green / 255.0, (float)blue / 255.0); - } - else - { - // a default color (green) - return ColorProperty::New(0.0, 1.0, 0.0); - } -} - -void mitk::DataNodeFactory::SetDefaultCommonProperties(mitk::DataNode::Pointer &node) -{ - // path - mitk::StringProperty::Pointer pathProp = mitk::StringProperty::New(itksys::SystemTools::GetFilenamePath(m_FileName)); - node->SetProperty(StringProperty::PATH, pathProp); - - // name already defined? - mitk::StringProperty::Pointer nameProp = dynamic_cast(node->GetProperty("name")); - if (nameProp.IsNull() || (strcmp(nameProp->GetValue(), "No Name!") == 0)) - { - // name already defined in BaseData - mitk::StringProperty::Pointer baseDataNameProp = - dynamic_cast(node->GetData()->GetProperty("name").GetPointer()); - if (baseDataNameProp.IsNull() || (strcmp(baseDataNameProp->GetValue(), "No Name!") == 0)) - { - // name neither defined in node, nor in BaseData -> name = filename - if (FileNameEndsWith(".gz")) - m_FileName = m_FileName.substr(0, m_FileName.length() - 3); - - nameProp = mitk::StringProperty::New(itksys::SystemTools::GetFilenameWithoutLastExtension(m_FileName)); - - node->SetProperty("name", nameProp); - } - else - { - // name defined in BaseData! - nameProp = mitk::StringProperty::New(baseDataNameProp->GetValue()); - node->SetProperty("name", nameProp); - } - } - - // visibility - if (!node->GetProperty("visible")) - node->SetVisibility(true); -} diff --git a/Modules/LegacyIO/mitkDataNodeFactory.h b/Modules/LegacyIO/mitkDataNodeFactory.h deleted file mode 100644 index d6f9174284..0000000000 --- a/Modules/LegacyIO/mitkDataNodeFactory.h +++ /dev/null @@ -1,175 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#ifndef _DATA_TREE_NODE_FACTORY_H_ -#define _DATA_TREE_NODE_FACTORY_H_ - -#include "mitkColorProperty.h" -#include "mitkDataNodeSource.h" -#include "mitkFileSeriesReader.h" - -#include -#include - -namespace mitk -{ - /** - * @brief Factory, which creates instances of mitk::DataNodes filled with - * data read from a given file - * - * This class reads files, creates an appropriate mitk::BaseData and adds the - * BaseData to a mitk::DataNode. This filter may produce one or more outputs - * (i.e. mitk::DataNodes). The number of generated nodes can be retrieved by a - * call of GetNumberOfOutputs(). - * - * If you want to add a new file type, you have to register the factory - * of the file reader in the class mitk::BaseDataIOFactory. - * @ingroup MitkLegacyIOModule - * @deprecatedSince{2014_10} Use mitk::IOUtils or mitk::FileReaderRegistry instead. - */ - class MITKLEGACYIO_EXPORT DataNodeFactory : public DataNodeSource, public FileSeriesReader - { - public: - mitkClassMacro(DataNodeFactory, DataNodeSource); - - DEPRECATED(itkFactorylessNewMacro(Self)) - itkCloneMacro(Self) - - /** - * Sets the filename of the file to read. - * @param FileName the name of the file to read. - */ - itkSetStringMacro(FileName); - - /** - * @returns the name of the file to be read from disk. - */ - itkGetStringMacro(FileName); - - /** - * \brief Set prefix for multiple load - */ - itkSetStringMacro(FilePrefix); - - /** - * \brief Get prefix for multiple load - */ - itkGetStringMacro(FilePrefix); - - /** - * \brief Set pattern for multiple load - */ - itkSetStringMacro(FilePattern); - - /** - * \brief Get pattern for multiple load - */ - itkGetStringMacro(FilePattern); - - /** - * Nice default colors for segmentations of some "normal" organs. - */ - static ColorProperty::Pointer DefaultColorForOrgan(const std::string &); - - void SetDefaultCommonProperties(mitk::DataNode::Pointer &node); - - /** - * if true -> loaded image is part of a serie - */ - void SetImageSerie(bool serie); - - void AddSeriesRestriction(const std::string &tag) { m_SeriesRestrictions.push_back(tag); } - static bool m_TextureInterpolationActive; - - protected: - /** - * Constructor. - */ - DataNodeFactory(); - - /** - * Virtual destructor. - */ - ~DataNodeFactory() override; - - bool m_Serie; - - /** - * Determines of which file type a given file is and calls the - * appropriate reader function. - */ - void GenerateData() override; - - /** - * Resizes the number of outputs of the factory. - * The outputs are initialized by empty DataNodes - * @param num the new number of outputs - */ - virtual void ResizeOutputs(const unsigned int &num); - - /** - * Checks if the file name m_FileName ends with the given name. - * Currently, this check is done by a dumb search for name in - * the filename. - * @param name the extension of the file - * @returns true, if the filename contains name. - */ - virtual bool FileNameEndsWith(const std::string &name); - - /** - * Checks if the file pattern m_FilePattern ends with the given name. - * Currently, this check is done by a dumb search for name in - * the filename. - * @param name the extension of the file - * @returns true, if the filepattern contains name. - */ - virtual bool FilePatternEndsWith(const std::string &name); - - /** - * @returns the plain filename, that is, without any directory. - */ - virtual std::string GetBaseFileName(); - - /** - * @returns the plain file prefix, that is, without any directory. - */ - virtual std::string GetBaseFilePrefix(); - - /** - * @returns the directory of the file name m_FileName. - */ - virtual std::string GetDirectory(); - -#ifdef MBI_INTERNAL - virtual void ReadFileTypeHPSONOS(); -#ifdef HAVE_IPDICOM - virtual void ReadFileTypeIPDCM(); -#endif /* HAVE_IPDICOM */ -#ifdef USE_TUS_READER - virtual void ReadFileTypeTUS(); -#endif -#endif /* MBI_INTERNAL */ - - virtual void ReadFileSeriesTypeDCM(); - - virtual void ReadFileSeriesTypeITKImageSeriesReader(); - - std::vector m_SeriesRestrictions; - int m_OldProgress; - }; -} - -#endif //#ifndef __DATA_TREE_NODE_FACTORY_H diff --git a/Plugins/org.mitk.gui.common/src/mitkWorkbenchUtil.h b/Plugins/org.mitk.gui.common/src/mitkWorkbenchUtil.h index 469d0d1054..b3dc8a8e86 100644 --- a/Plugins/org.mitk.gui.common/src/mitkWorkbenchUtil.h +++ b/Plugins/org.mitk.gui.common/src/mitkWorkbenchUtil.h @@ -1,189 +1,189 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKWORKBENCHUTIL_H #define MITKWORKBENCHUTIL_H #include #include "mitkDataStorageEditorInput.h" #include #include class ctkPluginContext; namespace mitk { /** * @ingroup org_mitk_gui_common * * @brief Utility class for loading data, opening editors and other tasks in a MITK Workbench. * * @note Infering the content type is not yet supported (ignore the comments about it * in the method documentation). */ struct MITK_GUI_COMMON_PLUGIN WorkbenchUtil { /** * Loads the set of given files into the active data storage of the given Workbench window. * * If the window already has an editor open on the active datastorage then that editor * is activated; otherwise the default editor for the "mitk" extension is activated. * * @param fileNames * A list of file names with absolute path. * @param wnd * The Workbench window in which the data will be loaded. * @param openEditor * Whether an Editor is to be opened on file loading (for cases there is none). * - * @see mitk::IDataNodeReader + * @see mitk::IOUtil */ static void LoadFiles(const QStringList& fileNames, berry::IWorkbenchWindow::Pointer wnd, bool openEditor = true); /** * Opens an editor on the given object. *

* If the page already has an editor open on the target object then that * editor is brought to front; otherwise, a new editor is opened. If * activate == true the editor will be activated. *

* * @param page * the page in which the editor will be opened * @param input * the editor input * @param editorId * the id of the editor extension to use * @param activate * if true the editor will be activated * @return an open editor or null if an external editor was * opened * @exception PartInitException * if the editor could not be initialized * @see IWorkbenchPage#OpenEditor(IEditorInput::Pointer, std::string, bool) */ static berry::IEditorPart::Pointer OpenEditor(berry::IWorkbenchPage::Pointer page, berry::IEditorInput::Pointer input, const QString& editorId, bool activate = false); /** * Opens an editor on the given file resource. This method will attempt to * resolve the editor based on content-type bindings as well as traditional * name/extension bindings if determineContentType is * true. *

* If the page already has an editor open on the target object then that * editor is brought to front; otherwise, a new editor is opened. If * activate == true the editor will be activated. *

* * @param page * the page in which the editor will be opened * @param input * the editor input * @param activate * if true the editor will be activated * @param determineContentType * attempt to resolve the content type for this file * @return an open editor or null if an external editor was * opened * @exception PartInitException * if the editor could not be initialized * @see IWorkbenchPage#OpenEditor(IEditorInput::Pointer,std::string,bool) */ static berry::IEditorPart::Pointer OpenEditor(berry::IWorkbenchPage::Pointer page, mitk::DataStorageEditorInput::Pointer input, bool activate = false, bool determineContentType = false); /** * Returns an editor descriptor appropriate for opening a file resource with * the given name. *

* The editor descriptor is determined using a multi-step process. This * method will attempt to infer the content type of the file if * inferContentType is true. *

*
    *
  1. The file is consulted for a persistent property named * IDE.EDITOR_KEY containing the preferred editor id to be * used.
  2. *
  3. The workbench editor registry is consulted to determine if an editor * extension has been registered for the file type. If so, an instance of * the editor extension is opened on the file. See * IEditorRegistry#GetDefaultEditor(std::string).
  4. *
  5. The operating system is consulted to determine if an in-place * component editor is available (e.g. OLE editor on Win32 platforms).
  6. *
  7. The operating system is consulted to determine if an external editor * is available.
  8. *
*

* * @param name * the file name * @param inferContentType * attempt to infer the content type from the file name if this * is true * @return an editor descriptor, appropriate for opening the file * @throws PartInitException * if no editor can be found */ static berry::IEditorDescriptor::Pointer GetEditorDescriptor( const QString& name, bool inferContentType = true); /** * Returns the default editor for a given file. This method will attempt to * resolve the editor based on content-type bindings as well as traditional * name/extension bindings if determineContentType is * true. *

* A default editor id may be registered for a specific file using * setDefaultEditor. If the given file has a registered * default editor id the default editor will derived from it. If not, the * default editor is determined by taking the file name for the file and * obtaining the default editor for that name. *

* * @param file * the file * @param determineContentType * determine the content type for the given file * @return the descriptor of the default editor, or null if * not found */ static berry::IEditorDescriptor::Pointer GetDefaultEditor(const QString& file, bool determineContentType); /** * Set the "DepartmentLogo" preference using a Qt resource path. * * This is a convenience method to set the preference for a "deparment" logo which is usually * shown in render windows in the MITK workbench. * * @param logoResource A Qt resource path to the logo, e.g. ":/MyLogo.png". * @param context The plugin context of the plug-in containing the logo resource. * @return \c true if the preference was set successfully, \c false otherwise. */ static bool SetDepartmentLogoPreference(const QString& logoResource, ctkPluginContext* context); }; } #endif // MITKWORKBENCHUTIL_H diff --git a/Plugins/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.cpp b/Plugins/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.cpp index e488dee9ad..1ed2168d9f 100644 --- a/Plugins/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.cpp +++ b/Plugins/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.cpp @@ -1,265 +1,261 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkPluginActivator.h" #include "DicomEventHandler.h" #include #include #include #include #include #include #include #include #include #include "mitkImage.h" #include #include #include #include #include #include -#include -#include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include DicomEventHandler::DicomEventHandler() { } DicomEventHandler::~DicomEventHandler() { } void DicomEventHandler::OnSignalAddSeriesToDataManager(const ctkEvent& ctkEvent) { QStringList listOfFilesForSeries; listOfFilesForSeries = ctkEvent.getProperty("FilesForSeries").toStringList(); if (!listOfFilesForSeries.isEmpty()) { //for rt data, if the modality tag isn't defined or is "CT" the image is handled like before if(ctkEvent.containsProperty("Modality") && (ctkEvent.getProperty("Modality").toString().compare("RTDOSE",Qt::CaseInsensitive) == 0 || ctkEvent.getProperty("Modality").toString().compare("RTSTRUCT",Qt::CaseInsensitive) == 0 || ctkEvent.getProperty("Modality").toString().compare("RTPLAN", Qt::CaseInsensitive) == 0)) { QString modality = ctkEvent.getProperty("Modality").toString(); if(modality.compare("RTDOSE",Qt::CaseInsensitive) == 0) { auto doseReader = mitk::RTDoseReaderService(); doseReader.SetInput(listOfFilesForSeries.front().toStdString()); std::vector > readerOutput = doseReader.Read(); if (!readerOutput.empty()){ mitk::Image::Pointer doseImage = dynamic_cast(readerOutput.at(0).GetPointer()); mitk::DataNode::Pointer doseImageNode = mitk::DataNode::New(); doseImageNode->SetData(doseImage); doseImageNode->SetName("RTDose"); if (doseImage != nullptr) { - auto sopUIDProperty = doseImage->GetProperty("dicomseriesreader.SOPClassUID"); - if (sopUIDProperty.IsNotNull()){ - auto sopUIDStringProperty = dynamic_cast(sopUIDProperty.GetPointer()); - if (sopUIDStringProperty != nullptr){ - std::string sopUID = sopUIDStringProperty->GetValue(); - doseImageNode->SetName(sopUID); - } - } + std::string sopUID; + if (mitk::GetBackwardsCompatibleDICOMProperty(0x0008, 0x0016, "dicomseriesreader.SOPClassUID", doseImage->GetPropertyList(), sopUID)) + { + doseImageNode->SetName(sopUID); + }; berry::IPreferencesService* prefService = berry::Platform::GetPreferencesService(); berry::IPreferences::Pointer prefNode = prefService->GetSystemPreferences()->Node(mitk::RTUIConstants::ROOT_DOSE_VIS_PREFERENCE_NODE_ID.c_str()); if (prefNode.IsNull()) { mitkThrow() << "Error in preference interface. Cannot find preset node under given name. Name: " << prefNode->ToString().toStdString(); } //set some specific colorwash and isoline properties bool showColorWashGlobal = prefNode->GetBool(mitk::RTUIConstants::GLOBAL_VISIBILITY_COLORWASH_ID.c_str(), true); bool showIsolinesGlobal = prefNode->GetBool(mitk::RTUIConstants::GLOBAL_VISIBILITY_ISOLINES_ID.c_str(), true); //Set reference dose property double referenceDose = prefNode->GetDouble(mitk::RTUIConstants::REFERENCE_DOSE_ID.c_str(), mitk::RTUIConstants::DEFAULT_REFERENCE_DOSE_VALUE); mitk::ConfigureNodeAsDoseNode(doseImageNode, mitk::GeneratIsoLevels_Virtuos(), referenceDose, showColorWashGlobal); ctkServiceReference serviceReference = mitk::PluginActivator::getContext()->getServiceReference(); mitk::IDataStorageService* storageService = mitk::PluginActivator::getContext()->getService(serviceReference); mitk::DataStorage* dataStorage = storageService->GetDefaultDataStorage().GetPointer()->GetDataStorage(); dataStorage->Add(doseImageNode); mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(dataStorage); } }//END DOSE } else if(modality.compare("RTSTRUCT",Qt::CaseInsensitive) == 0) { auto structReader = mitk::RTStructureSetReaderService(); structReader.SetInput(listOfFilesForSeries.front().toStdString()); std::vector > readerOutput = structReader.Read(); if (readerOutput.empty()){ MITK_ERROR << "No structure sets were created" << endl; } else { std::vector modelVector; ctkServiceReference serviceReference = mitk::PluginActivator::getContext()->getServiceReference(); mitk::IDataStorageService* storageService = mitk::PluginActivator::getContext()->getService(serviceReference); mitk::DataStorage* dataStorage = storageService->GetDefaultDataStorage().GetPointer()->GetDataStorage(); for (const auto& aStruct : readerOutput){ mitk::ContourModelSet::Pointer countourModelSet = dynamic_cast(aStruct.GetPointer()); mitk::DataNode::Pointer structNode = mitk::DataNode::New(); structNode->SetData(countourModelSet); structNode->SetProperty("name", aStruct->GetProperty("name")); structNode->SetProperty("color", aStruct->GetProperty("contour.color")); structNode->SetProperty("contour.color", aStruct->GetProperty("contour.color")); structNode->SetProperty("includeInBoundingBox", mitk::BoolProperty::New(false)); structNode->SetVisibility(true, mitk::BaseRenderer::GetInstance( mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget1"))); structNode->SetVisibility(false, mitk::BaseRenderer::GetInstance( mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget2"))); structNode->SetVisibility(false, mitk::BaseRenderer::GetInstance( mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget3"))); structNode->SetVisibility(true, mitk::BaseRenderer::GetInstance( mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget4"))); dataStorage->Add(structNode); } mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(dataStorage); } } else if (modality.compare("RTPLAN", Qt::CaseInsensitive) == 0) { auto planReader = mitk::RTPlanReaderService(); planReader.SetInput(listOfFilesForSeries.front().toStdString()); std::vector > readerOutput = planReader.Read(); if (!readerOutput.empty()){ //there is no image, only the properties are interesting mitk::Image::Pointer planDummyImage = dynamic_cast(readerOutput.at(0).GetPointer()); mitk::DataNode::Pointer planImageNode = mitk::DataNode::New(); planImageNode->SetData(planDummyImage); planImageNode->SetName("RTPlan"); ctkServiceReference serviceReference = mitk::PluginActivator::getContext()->getServiceReference(); mitk::IDataStorageService* storageService = mitk::PluginActivator::getContext()->getService(serviceReference); mitk::DataStorage* dataStorage = storageService->GetDefaultDataStorage().GetPointer()->GetDataStorage(); dataStorage->Add(planImageNode); } } } else { mitk::StringList seriesToLoad; QStringListIterator it(listOfFilesForSeries); while (it.hasNext()) { seriesToLoad.push_back(it.next().toStdString()); } //Get Reference for default data storage. ctkServiceReference serviceReference = mitk::PluginActivator::getContext()->getServiceReference(); mitk::IDataStorageService* storageService = mitk::PluginActivator::getContext()->getService(serviceReference); mitk::DataStorage* dataStorage = storageService->GetDefaultDataStorage().GetPointer()->GetDataStorage(); std::vector baseDatas = mitk::IOUtil::Load(seriesToLoad.front()); for (const auto &data : baseDatas) { mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(data); std::string nodeName = "Unnamed Dicom"; std::string studyUID = ""; std::string seriesUID = ""; data->GetPropertyList()->GetStringProperty("DICOM.0020.000D", studyUID); data->GetPropertyList()->GetStringProperty("DICOM.0020.000E", seriesUID); if (!studyUID.empty()) { nodeName = studyUID; } if (!seriesUID.empty()) { if (!studyUID.empty()) { nodeName += "/"; } nodeName += seriesUID; } dataStorage->Add(node); } } } else { MITK_INFO << "There are no files for the current series"; } } void DicomEventHandler::OnSignalRemoveSeriesFromStorage(const ctkEvent& /*ctkEvent*/) { } void DicomEventHandler::SubscribeSlots() { ctkServiceReference ref = mitk::PluginActivator::getContext()->getServiceReference(); if (ref) { ctkEventAdmin* eventAdmin = mitk::PluginActivator::getContext()->getService(ref); ctkDictionary properties; properties[ctkEventConstants::EVENT_TOPIC] = "org/mitk/gui/qt/dicom/ADD"; eventAdmin->subscribeSlot(this, SLOT(OnSignalAddSeriesToDataManager(ctkEvent)), properties); properties[ctkEventConstants::EVENT_TOPIC] = "org/mitk/gui/qt/dicom/DELETED"; eventAdmin->subscribeSlot(this, SLOT(OnSignalRemoveSeriesFromStorage(ctkEvent)), properties); } } diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/deprecated/QmitkDiffusionTensorEstimation.cpp b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/deprecated/QmitkDiffusionTensorEstimation.cpp index 25b1b8868c..c7f57373ea 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/deprecated/QmitkDiffusionTensorEstimation.cpp +++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/deprecated/QmitkDiffusionTensorEstimation.cpp @@ -1,2494 +1,2493 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "itkTimeProbe.h" #include "QmitkDiffusionTensorEstimation.h" #include "QmitkDiffusionTensorEstimationControls.h" #include #include "QmitkDataTreeComboBox.h" #include "QmitkDataTreeListView.h" #include "QmitkDiffusionTensorIcon.h" #include #include "QmitkPropertyViewFactory.h" #include #include #include #include #include #include #include // properties #include "mitkStringProperty.h" #include "mitkProperties.h" #include "mitkMaterialProperty.h" #include "mitkLevelWindowProperty.h" #include "mitkVtkRepresentationProperty.h" #include "mitkVtkInterpolationProperty.h" #include "mitkVtkScalarModeProperty.h" #include "mitkLookupTableProperty.h" #include "mitkLookupTable.h" #include "mitkTransferFunctionProperty.h" #include "mitkGridRepresentationProperty.h" #include "mitkGridVolumeMapperProperty.h" #include "mitkVtkResliceInterpolationProperty.h" #include "mitkVectorImageMapper2D.h" #include "mitkOdfVtkMapper2D.h" #include "itkOrientedImage.h" #include "itkVectorImage.h" #include "itkImageSeriesReader.h" #include "itkImageFileWriter.h" #include "itkExceptionObject.h" #include "itkDiffusionTensor3DReconstructionImageFilter.h" #include "itkDiffusionTensor3D.h" #include "itkTensorFractionalAnisotropyImageFilter.h" #include "itkTensorRelativeAnisotropyImageFilter.h" #include "itkGDCMSeriesFileNames.h" #include "itkImageRegionConstIterator.h" #include "itkRescaleIntensityImageFilter.h" #include "itkDiffusionQballReconstructionImageFilter.h" #include "itkAnalyticalDiffusionQballReconstructionImageFilter.h" #include "itkPointShell.h" #include "itkRGBPixel.h" #include "itkOrientationDistributionFunction.h" #include "itkDiffusionOdfPrincipleDirectionsImageFilter.h" #include "itkDiffusionOdfGeneralizedFaImageFilter.h" #include "itkShiftScaleImageFilter.h" #include "itkDiffusionOdfPrepareVisualizationImageFilter.h" #include "itkDiffusionTensorPrincipleDirectionImageFilter.h" #include "itkDiffusionOdfSphericalDeconvolutionImageFilter.h" #include "itkVectorImagesAngularErrorImageFilter.h" #include "mitkDicomDiffusionVolumeHeaderReader.h" #include "mitkGroupDiffusionHeadersFilter.h" #include "mitkDicomDiffusionVolumesReader.h" #include "mitkNrrdDiffusionVolumesWriter.h" #include "mitkNrrdDiffusionVolumesReader.h" #include "mitkDiffusionVolumes.h" #include "mitkDataTreeFilterFunctions.h" #include "mitkProgressBar.h" #include "mitkStatusBar.h" #include "mitkTeemDiffusionTensor3DReconstructionImageFilter.h" #include "mitkSurface.h" -#include "mitkDataNodeFactory.h" #include "vtkPolyData.h" #include "vtkPoints.h" #include "vtkCellArray.h" #include "vtkDelaunay2D.h" #include "vtkCleanPolyData.h" #include "vtkAppendPolyData.h" #include "mitkImageCast.h" #include #include #include typedef float TTensorPixelType; typedef itk::DiffusionTensor3D< TTensorPixelType > TensorPixelType; typedef itk::Image< TensorPixelType, 3 > TensorImageType; typedef itk::VectorImage< DiffusionPixelType, 3 > DiffusionImageType; //CAST_N_VEC(3) //CAST_N_VEC(42) //CAST_N_VEC(92) //CAST_N_VEC(162) //CAST_N_VEC(252) //CAST_N_VEC(362) //CAST_N_VEC(492) //CAST_N_VEC(642) //CAST_N_VEC(812) //CAST_N_VEC(1002) const int QmitkDiffusionTensorEstimation::odfsize = 252; const int QmitkDiffusionTensorEstimation::nrconvkernels = 252; // Compile-time Square Root Computation: ceil(sqrt(N)) template struct Root; template struct Root { static const int root = Mid; }; template struct Root { static const int mean = (Low + High)/2; static const bool down = (mean * mean >= Size); static const int root = Root::root; }; QmitkDiffusionTensorEstimation::QmitkDiffusionTensorEstimation(QObject *parent, const char *name, mitk::DataTreeIteratorBase* it) : QmitkAbstractView(parent, name, it), m_Controls(nullptr) { SetAvailability(true); m_FilterInitialized = false; } QmitkDiffusionTensorEstimation::~QmitkDiffusionTensorEstimation() {} QWidget * QmitkDiffusionTensorEstimation::CreateControlWidget(QWidget *parent) { if (m_Controls == nullptr) { m_Controls = new QmitkDiffusionTensorEstimationControls(parent); } m_Controls->m_TensorEstimationTeemErrorImage->setChecked(false); m_Controls->m_TensorEstimationTeemSigmaEdit->setText("NaN"); m_Controls->m_TensorEstimationTeemEstimationMethodCombo->insertItem("LLS (Linear Least Squares)"); m_Controls->m_TensorEstimationTeemEstimationMethodCombo->insertItem("MLE (Maximum Likelihood)"); m_Controls->m_TensorEstimationTeemEstimationMethodCombo->insertItem("NLS (Nonlinear Least Squares)"); m_Controls->m_TensorEstimationTeemEstimationMethodCombo->insertItem("WLS (Weighted Least Squares)"); m_Controls->m_TensorEstimationTeemNumItsSpin->setValue(1); m_Controls->m_TensorEstimationTeemConfThresholdEdit->setText("NaN"); m_Controls->m_TensorEstimationTeemFuzzyEdit->setText("0.0"); m_Controls->m_TensorEstimationTeemMinValEdit->setText("1.0"); m_Controls->m_OdfReconstructionThreasholdEdit->setText("0.0"); m_Controls->m_OdfStandardAlgorithmsOrderSpinbox->setValue(0); m_Controls->m_OdfStandardAlgorithmsProbThreshEdit->setText(QString::number(1.0/double(odfsize))); m_Controls->m_OdfReconstructionNumberThreadsSpinbox->setValue(4); m_Controls->m_OdfReconstructionMaxLLevelComboBox->insertItem( QString("2") ); m_Controls->m_OdfReconstructionMaxLLevelComboBox->insertItem( QString("4") ); m_Controls->m_OdfReconstructionMaxLLevelComboBox->insertItem( QString("6") ); m_Controls->m_OdfReconstructionMaxLLevelComboBox->insertItem( QString("8") ); m_Controls->m_OdfReconstructionMaxLLevelComboBox->setCurrentItem( 3 ); m_Controls->m_OdfReconstructionNumberThreadsAnalyticalSpinbox->setValue(4); m_Controls->m_OdfReconstructionThreasholdAnalyticalEdit->setText("0.0"); m_Controls->m_OdfReconstructionLambdaLineEdit->setText("0.006"); m_Controls->m_OdfStandardAlgorithmsNumberThreadsSpinbox->setValue(4); m_Controls->m_OdfStandardAlgorithmsDeconvNumberThreadsSpinbox->setValue(4); m_Controls->m_OdfStandardAlgorithmsDeconvolutionThreshEdit->setText("0.1"); m_Controls->m_OdfStandardAlgorithmsDeconvolutionAngResThresholdEdit->setText("15"); m_Controls->m_OdfStandardAlgorithmsGFAParam1->setText("2"); m_Controls->m_OdfStandardAlgorithmsGFAParam2->setText("1"); return m_Controls; } void QmitkDiffusionTensorEstimation::CreateConnections() { if ( m_Controls ) { connect( (QObject*)(m_Controls->m_TensorEstimationButton), SIGNAL(clicked()),(QObject*) this, SLOT(TensorEstimationButton())); connect( (QObject*)(m_Controls->m_OdfReconstructionButton), SIGNAL(clicked()),(QObject*) this, SLOT(OdfReconstructionButton())); connect( (QObject*)(m_Controls->m_OdfReconstructionAnalyticalButton), SIGNAL(clicked()),(QObject*) this, SLOT(OdfReconstructionAnalyticalButton())); connect( (QObject*)(m_Controls->m_TensorEstimationTeemEstimateButton), SIGNAL(clicked()),(QObject*) this, SLOT(TensorEstimationTeemEstimateButton())); connect( (QObject*)(m_Controls->m_TensorVolumesSaveButton), SIGNAL(clicked()),(QObject*) this, SLOT(TensorVolumesSaveButton())); connect( (QObject*)(m_Controls->m_TensorVolumesLoadButton), SIGNAL(clicked()),(QObject*) this, SLOT(TensorVolumesLoadButton())); connect( (QObject*)(m_Controls->m_TensorVolumesRemoveButton), SIGNAL(clicked()),(QObject*) this, SLOT(TensorVolumesRemoveButton())); connect( (QObject*)(m_Controls->m_StandardAlgorithmsFAButton), SIGNAL(clicked()),(QObject*) this, SLOT(StandardAlgorithmsFAButton())); connect( (QObject*)(m_Controls->m_StandardAlgorithmsRAButton), SIGNAL(clicked()),(QObject*) this, SLOT(StandardAlgorithmsRAButton())); connect( (QObject*)(m_Controls->m_StandardAlgorithmsDirectionButton), SIGNAL(clicked()),(QObject*) this, SLOT(StandardAlgorithmsDirectionButton())); connect( (QObject*)(m_Controls->m_OdfVolumesSaveButton), SIGNAL(clicked()),(QObject*) this, SLOT(OdfVolumesSaveButton())); connect( (QObject*)(m_Controls->m_OdfVolumesLoadButton), SIGNAL(clicked()),(QObject*) this, SLOT(OdfVolumesLoadButton())); connect( (QObject*)(m_Controls->m_OdfVolumesRemoveButton), SIGNAL(clicked()),(QObject*) this, SLOT(OdfVolumesRemoveButton())); connect( (QObject*)(m_Controls->m_OdfStandardAlgorithmsDirectionButton), SIGNAL(clicked()),(QObject*) this, SLOT(OdfStandardAlgorithmsDirectionButton())); connect( (QObject*)(m_Controls->m_OdfStandardAlgorithmsDeconvolutionButton), SIGNAL(clicked()),(QObject*) this, SLOT(OdfStandardAlgorithmsDeconvolutionButton())); connect( (QObject*)(m_Controls->m_OdfStandardAlgorithmsGFAButton), SIGNAL(clicked()),(QObject*) this, SLOT(OdfStandardAlgorithmsGFAButton())); connect( (QObject*)(m_Controls->m_OdfVolumesVisualizeSelectedButton), SIGNAL(clicked()),(QObject*) this, SLOT(OdfVolumesVisualizeSelectedButton())); connect( (QObject*)(m_Controls->m_DirectionVolumesSaveButton), SIGNAL(clicked()),(QObject*) this, SLOT(DirectionVolumesSaveButton())); connect( (QObject*)(m_Controls->m_DirectionVolumesLoadButton), SIGNAL(clicked()),(QObject*) this, SLOT(DirectionVolumesLoadButton())); connect( (QObject*)(m_Controls->m_DirectionVolumesRemoveButton), SIGNAL(clicked()),(QObject*) this, SLOT(DirectionVolumesRemoveButton())); connect( (QObject*)(m_Controls->m_DirectionVolumesAngularErrorButton), SIGNAL(clicked()),(QObject*) this, SLOT(DirectionVolumesAngularErrorButton())); connect( (QObject*)(m_Controls->m_DiffusionVolumesLoadButton), SIGNAL(clicked()),(QObject*) this, SLOT(DiffusionVolumesLoadButton())); connect( (QObject*)(m_Controls->m_DiffusionVolumeSaveButton), SIGNAL(clicked()),(QObject*) this, SLOT(DiffusionVolumeSaveButton())); connect( (QObject*)(m_Controls->m_DiffusionVolumesRemoveButton), SIGNAL(clicked()),(QObject*) this, SLOT(DiffusionVolumesRemoveButton())); connect( (QObject*)(m_Controls->m_TensorEstimationDiffusionVolumesSelectAllButton), SIGNAL(clicked()),(QObject*) this, SLOT(DiffusionVolumesSelectAll())); } } QAction * QmitkDiffusionTensorEstimation::CreateAction(QActionGroup *parent) { //action = new QAction( tr( "Brain Atrophy" ), pixmap, tr( "BrainAtrophy" ), 0, parent, "BrainAtrophy" ); QImage icon = qembed_findImage("QmitkDiffusionTensorEstimation"); QPixmap pixmap(icon); QAction* action; action = new QAction( tr( "Diffusion Tensor Estimation" ), pixmap, tr( "QmitkDiffusionTensorEstimation menu" ), 0, parent, "QmitkDiffusionTensorEstimation" ); return action; } void QmitkDiffusionTensorEstimation::TreeChanged() { m_Controls->m_TensorEstimationDiffusionVolumesSelector->Update(); m_Controls->m_TensorVolumesSelector->Update(); m_Controls->m_OdfVolumesSelector->Update(); m_Controls->m_DirectionVolumesSelector->Update(); if(m_DiffusionVolumesDataTreeFilter &&m_DiffusionVolumesDataTreeFilter->GetItems()->Size() > 0) { m_Controls->m_TensorEstimationButton->setEnabled(true); m_Controls->m_OdfReconstructionButton->setEnabled(true); m_Controls->m_OdfReconstructionAnalyticalButton->setEnabled(true); } else { m_Controls->m_OdfReconstructionButton->setEnabled(false); m_Controls->m_OdfReconstructionAnalyticalButton->setEnabled(false); m_Controls->m_TensorEstimationButton->setEnabled(false); } if(m_TensorVolumesDataTreeFilter && m_TensorVolumesDataTreeFilter->GetItems()->Size() > 0) { m_Controls->m_TensorVolumesSaveButton->setEnabled(true); m_Controls->m_TensorVolumesRemoveButton->setEnabled(true); } else { m_Controls->m_TensorVolumesSaveButton->setEnabled(false); m_Controls->m_TensorVolumesRemoveButton->setEnabled(false); } if(m_OdfVolumesDataTreeFilter && m_OdfVolumesDataTreeFilter->GetItems()->Size() > 0) { m_Controls->m_OdfVolumesSaveButton->setEnabled(true); m_Controls->m_OdfVolumesRemoveButton->setEnabled(true); m_Controls->m_OdfVolumesVisualizeSelectedButton->setEnabled(true); } else { m_Controls->m_OdfVolumesSaveButton->setEnabled(false); m_Controls->m_OdfVolumesRemoveButton->setEnabled(false); m_Controls->m_OdfVolumesVisualizeSelectedButton->setEnabled(false); } if(m_DirectionVolumesDataTreeFilter && m_DirectionVolumesDataTreeFilter->GetItems()->Size() > 0) { m_Controls->m_DirectionVolumesSaveButton->setEnabled(true); m_Controls->m_DirectionVolumesRemoveButton->setEnabled(true); } else { m_Controls->m_DirectionVolumesSaveButton->setEnabled(false); m_Controls->m_DirectionVolumesRemoveButton->setEnabled(false); } if(m_DirectionVolumesDataTreeFilter && m_DirectionVolumesDataTreeFilter->GetItems()->Size() > 1) { m_Controls->m_DirectionVolumesAngularErrorButton->setEnabled(true); } else { m_Controls->m_DirectionVolumesAngularErrorButton->setEnabled(false); } } void QmitkDiffusionTensorEstimation::Activated() { if (m_FilterInitialized) return; // diffusion volumes filter m_DiffusionVolumesDataTreeFilter = mitk::DataTreeFilter::New( GetDataTreeIterator()->GetTree() ); m_DiffusionVolumesDataTreeFilter->SetSelectionMode(mitk::DataTreeFilter::MULTI_SELECT); m_DiffusionVolumesDataTreeFilter->SetHierarchyHandling(mitk::DataTreeFilter::FLATTEN_HIERARCHY); m_DiffusionVolumesDataTreeFilter->SetFilter( mitk::IsBaseDataType >() ); // show diffusion volumes mitk::DataTreeFilter::PropertyList visible_props; visible_props.push_back("name"); m_DiffusionVolumesDataTreeFilter->SetVisibleProperties(visible_props); mitk::DataTreeFilter::PropertyList property_labels; property_labels.push_back("Diffusion Volumes"); m_DiffusionVolumesDataTreeFilter->SetPropertiesLabels(property_labels); m_Controls->m_TensorEstimationDiffusionVolumesSelector->SetDataTree( GetDataTreeIterator()->GetTree() ); m_Controls->m_TensorEstimationDiffusionVolumesSelector->SetFilter( m_DiffusionVolumesDataTreeFilter ); m_Controls->m_TensorEstimationDiffusionVolumesSelector->SetAutoUpdate( false ); m_Controls->m_TensorEstimationDiffusionVolumesSelector->setStretchedColumn(1); // tensor volumes filter m_TensorVolumesDataTreeFilter = mitk::DataTreeFilter::New( GetDataTreeIterator()->GetTree() ); m_TensorVolumesDataTreeFilter->SetSelectionMode(mitk::DataTreeFilter::SINGLE_SELECT); m_TensorVolumesDataTreeFilter->SetHierarchyHandling(mitk::DataTreeFilter::FLATTEN_HIERARCHY); m_TensorVolumesDataTreeFilter->SetFilter( mitk::IsBaseDataTypeWithBoolProperty("IsTensorVolume") ); // show tensor volumes m_TensorVolumesDataTreeFilter->SetVisibleProperties(visible_props); mitk::DataTreeFilter::PropertyList tensor_property_labels; tensor_property_labels.push_back("Tensor Volumes"); m_TensorVolumesDataTreeFilter->SetPropertiesLabels(tensor_property_labels); m_Controls->m_TensorVolumesSelector->SetDataTree( GetDataTreeIterator()->GetTree() ); m_Controls->m_TensorVolumesSelector->SetFilter( m_TensorVolumesDataTreeFilter ); m_Controls->m_TensorVolumesSelector->SetAutoUpdate( false ); m_Controls->m_TensorVolumesSelector->setStretchedColumn(1); // Odf volumes filter m_OdfVolumesDataTreeFilter = mitk::DataTreeFilter::New( GetDataTreeIterator()->GetTree() ); m_OdfVolumesDataTreeFilter->SetSelectionMode(mitk::DataTreeFilter::MULTI_SELECT); m_OdfVolumesDataTreeFilter->SetHierarchyHandling(mitk::DataTreeFilter::FLATTEN_HIERARCHY); m_OdfVolumesDataTreeFilter->SetFilter( mitk::IsBaseDataTypeWithBoolProperty("IsOdfVolume") ); m_OdfVolumesDataTreeFilter->SetVisibleProperties(visible_props); mitk::DataTreeFilter::PropertyList Odf_property_labels; Odf_property_labels.push_back("ODF Volumes"); m_OdfVolumesDataTreeFilter->SetPropertiesLabels(Odf_property_labels); m_Controls->m_OdfVolumesSelector->SetDataTree( GetDataTreeIterator()->GetTree() ); m_Controls->m_OdfVolumesSelector->SetFilter( m_OdfVolumesDataTreeFilter ); m_Controls->m_OdfVolumesSelector->SetAutoUpdate( false ); m_Controls->m_OdfVolumesSelector->setStretchedColumn(1); // direction volumes filter m_DirectionVolumesDataTreeFilter = mitk::DataTreeFilter::New( GetDataTreeIterator()->GetTree() ); m_DirectionVolumesDataTreeFilter->SetSelectionMode(mitk::DataTreeFilter::MULTI_SELECT); m_DirectionVolumesDataTreeFilter->SetHierarchyHandling(mitk::DataTreeFilter::FLATTEN_HIERARCHY); m_DirectionVolumesDataTreeFilter->SetFilter( mitk::IsBaseDataTypeWithBoolProperty("IsDirectionVolume") ); m_DirectionVolumesDataTreeFilter->SetVisibleProperties(visible_props); mitk::DataTreeFilter::PropertyList direction_property_labels; direction_property_labels.push_back("Direction Volumes"); m_DirectionVolumesDataTreeFilter->SetPropertiesLabels(direction_property_labels); m_Controls->m_DirectionVolumesSelector->SetDataTree( GetDataTreeIterator()->GetTree() ); m_Controls->m_DirectionVolumesSelector->SetFilter( m_DirectionVolumesDataTreeFilter ); m_Controls->m_DirectionVolumesSelector->SetAutoUpdate( false ); m_Controls->m_DirectionVolumesSelector->setStretchedColumn(1); m_FilterInitialized = true; TreeChanged(); } void QmitkDiffusionTensorEstimation::Deactivated() { } void QmitkDiffusionTensorEstimation::Visible() { } void QmitkDiffusionTensorEstimation::Hidden() { } void QmitkDiffusionTensorEstimation::TensorVolumesSaveButton() { // GET SELECTED ITEM const mitk::DataTreeFilter::Item* selectedItem = m_TensorVolumesDataTreeFilter->GetSelectedItem(); if( !selectedItem ) return; mitk::Image::Pointer tensorVol = static_cast(selectedItem->GetNode()->GetData()); TensorImageType::Pointer itkTensorVol = TensorImageType::New(); mitk::CastToItkImage(tensorVol, itkTensorVol); // SELECT FILE DIALOG std::string sName = selectedItem->GetNode()->GetName(); QString qName; qName.sprintf("%s.nhdr",sName.c_str()); QString filename = QFileDialog::getSaveFileName( qName, "Nrrd Images (*.nrrd *.nhdr)", this->m_Controls, "save file dialog", "Select Nrrd Outputfile" ); if ( !filename ) return; // WRITING TENSORS TO FILE MBI_INFO << "Writing tensors "; typedef itk::ImageFileWriter TensorWriterType; TensorWriterType::Pointer tensorWriter = TensorWriterType::New(); tensorWriter->SetFileName(filename.ascii()); tensorWriter->SetInput(itkTensorVol); tensorWriter->Update(); } void QmitkDiffusionTensorEstimation::TensorVolumesLoadButton() { // SELECT FOLDER DIALOG QFileDialog* w = new QFileDialog( this->m_Controls, "Select DWI data file", TRUE ); w->setMode( QFileDialog::ExistingFiles ); w->setFilter( "Nrrd Images (*.nrrd *.nhdr)" ); // RETRIEVE SELECTION if ( w->exec() != QDialog::Accepted ) return; QStringList filenames = w->selectedFiles(); QStringList::Iterator it = filenames.begin(); while( it != filenames.end() ) { std::string filename = ( *it ).ascii(); ++it; // READING TENSOR VOLUME typedef itk::ImageFileReader ReaderType; ReaderType::Pointer tensorReader = ReaderType::New(); tensorReader->SetFileName(filename); try { tensorReader->Update(); } catch (itk::ExceptionObject e) { std::cout << e << std::endl; } // Tensorvolume mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( tensorReader->GetOutput() ); image->SetVolume( tensorReader->GetOutput()->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); mitk::DataStorage::GetInstance()->Add(node); SetDefaultNodeProperties(node, itksys::SystemTools::GetFilenameName(filename)); node->SetProperty( "IsTensorVolume", mitk::BoolProperty::New( true ) ); TreeChanged(); } } void QmitkDiffusionTensorEstimation::TensorVolumesRemoveButton() { m_TensorVolumesDataTreeFilter->DeleteSelectedItems(); } void QmitkDiffusionTensorEstimation::OdfVolumesSaveButton() { // GET SELECTED ITEM const mitk::DataTreeFilter::Item* selectedItem = m_OdfVolumesDataTreeFilter->GetSelectedItem(); if( !selectedItem ) return; mitk::Image::Pointer OdfVol = static_cast(selectedItem->GetNode()->GetData()); if( !OdfVol)return; typedef itk::Image,3 > IType; IType::Pointer itkOdfVol = IType::New(); mitk::CastToItkImage(OdfVol, itkOdfVol); typedef itk::VectorImage VarVecImgType; VarVecImgType::Pointer vecImg = VarVecImgType::New(); vecImg->SetSpacing( itkOdfVol->GetSpacing() ); // Set the image spacing vecImg->SetOrigin( itkOdfVol->GetOrigin() ); // Set the image origin vecImg->SetDirection( itkOdfVol->GetDirection() ); // Set the image direction vecImg->SetLargestPossibleRegion( itkOdfVol->GetLargestPossibleRegion()); vecImg->SetBufferedRegion( itkOdfVol->GetLargestPossibleRegion() ); vecImg->SetVectorLength(odfsize); vecImg->Allocate(); itk::ImageRegionIterator ot (vecImg, vecImg->GetLargestPossibleRegion() ); ot = ot.Begin(); itk::ImageRegionIterator it (itkOdfVol, itkOdfVol->GetLargestPossibleRegion() ); it = it.Begin(); MBI_DEBUG << it.Get(); for (it = it.Begin(); !it.IsAtEnd(); ++it) { itk::Vector vec = it.Get(); VarVecImgType::PixelType varvec(vec.GetDataPointer(), odfsize); ot.Set(varvec); ++ot; } // SELECT FILE DIALOG std::string sName = selectedItem->GetNode()->GetName(); QString qName; qName.sprintf("%s.nhdr",sName.c_str()); QString filename = QFileDialog::getSaveFileName( qName, "Nrrd Images (*.nrrd *.nhdr)", this->m_Controls, "save file dialog", "Select Nrrd Outputfile" ); if ( !filename ) return; // WRITING TENSORS TO FILE MBI_INFO << "Writing data "; typedef itk::ImageFileWriter OdfWriterType; OdfWriterType::Pointer OdfWriter = OdfWriterType::New(); OdfWriter->SetFileName(filename.ascii()); OdfWriter->SetInput(vecImg); OdfWriter->Update(); } void QmitkDiffusionTensorEstimation::OdfVolumesLoadButton() { // SELECT FOLDER DIALOG QFileDialog* w = new QFileDialog( this->m_Controls, "Select DWI data file", TRUE ); w->setMode( QFileDialog::ExistingFiles ); w->setFilter( "Nrrd Images (*.nrrd *.nhdr)" ); // RETRIEVE SELECTION if ( w->exec() != QDialog::Accepted ) return; QStringList filenames = w->selectedFiles(); QStringList::Iterator it = filenames.begin(); while( it != filenames.end() ) { std::string filename = ( *it ).ascii(); ++it; // READING TENSOR VOLUME typedef itk::Image,3 > IVType; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer OdfReader = ReaderType::New(); OdfReader->SetFileName(filename); try { OdfReader->Update(); } catch (itk::ExceptionObject e) { MBI_LOG << e; } //itk::ImageRegionConstIterator it (OdfReader->GetOutput(), OdfReader->GetOutput()->GetLargestPossibleRegion() ); //it = it.Begin(); //std::cout << it.Get() << std::endl; // Tensorvolume mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( OdfReader->GetOutput() ); image->SetVolume( OdfReader->GetOutput()->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); mitk::DataStorage::GetInstance()->Add(node); SetDefaultNodeProperties(node, itksys::SystemTools::GetFilenameName(filename)); node->SetProperty( "IsOdfVolume", mitk::BoolProperty::New( true ) ); node->SetProperty( "visible", mitk::BoolProperty::New( false ) ); TreeChanged(); } } void QmitkDiffusionTensorEstimation::OdfVolumesRemoveButton() { m_OdfVolumesDataTreeFilter->DeleteSelectedItems(); } void QmitkDiffusionTensorEstimation::OdfVolumesVisualizeSelectedButton() { itk::TimeProbe clock; QString status; const mitk::DataTreeFilter::Item* item = m_OdfVolumesDataTreeFilter->GetSelectedItem(); if(!item)return; typedef itk::Vector OdfVectorType; typedef itk::Image OdfVectorImgType; mitk::Image* vol = static_cast(item->GetNode()->GetData()); OdfVectorImgType::Pointer itkvol = OdfVectorImgType::New(); mitk::CastToItkImage(vol, itkvol); std::string nodename = item->GetProperty("name"); // PREPARE FOR VISUALIZATION clock.Start(); MBI_INFO << "Preparing for Visualization "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "Preparing for Visualization of %s", nodename.c_str())); typedef itk::DiffusionOdfPrepareVisualizationImageFilter FilterType; FilterType::Pointer filter = FilterType::New(); filter->SetInput(itkvol); filter->SetNumberOfThreads(4); switch(m_Controls->m_OdfVolumesVisualizeNormalizationMethod->currentItem()) { case 0: { filter->SetNormalizationMethod(FilterType::PV_MIN_MAX); break; } case 1: { filter->SetNormalizationMethod(FilterType::PV_NONE); break; } case 2: { filter->SetNormalizationMethod(FilterType::PV_MAX); break; } case 3: { filter->SetNormalizationMethod(FilterType::PV_GLOBAL_MAX); break; } case 4: { filter->SetNormalizationMethod(FilterType::PV_MIN_MAX_INVERT); break; } default: { filter->SetNormalizationMethod(FilterType::PV_MIN_MAX); break; } } if(m_Controls->m_OdfVolumesVisualizeScaleGfaCheckbox->isChecked() ) { typedef itk::DiffusionOdfGeneralizedFaImageFilter GfaFilterType; filter->SetDoScaleGfa(true); float p1 = m_Controls->m_OdfStandardAlgorithmsGFAParam1->text().toFloat(); float p2 = m_Controls->m_OdfStandardAlgorithmsGFAParam2->text().toFloat(); switch(m_Controls->m_OdfStandardAlgorithmsGFAMethod->currentItem()) { case 0: filter->SetScaleByGfaType(GfaFilterType::GFA_STANDARD); break; case 1: filter->SetScaleByGfaType(GfaFilterType::GFA_QUANTILES_HIGH_LOW); break; case 2: filter->SetScaleByGfaType(GfaFilterType::GFA_QUANTILE_HIGH); break; case 3: filter->SetScaleByGfaType(GfaFilterType::GFA_MAX_ODF_VALUE); break; case 4: filter->SetScaleByGfaType(GfaFilterType::GFA_DECONVOLUTION_COEFFS); break; case 5: filter->SetScaleByGfaType(GfaFilterType::GFA_MIN_MAX_NORMALIZED_STANDARD); break; case 6: filter->SetScaleByGfaType(GfaFilterType::GFA_NORMALIZED_ENTROPY); break; case 7: filter->SetScaleByGfaType(GfaFilterType::GFA_NEMATIC_ORDER_PARAMETER); break; case 8: filter->SetScaleByGfaType(GfaFilterType::GFA_QUANTILES_LOW_HIGH); break; case 9: filter->SetScaleByGfaType(GfaFilterType::GFA_QUANTILE_LOW); break; case 10: filter->SetScaleByGfaType(GfaFilterType::GFA_MIN_ODF_VALUE); break; case 11: filter->SetScaleByGfaType(GfaFilterType::GFA_STD_BY_MAX); break; case 12: filter->SetScaleByGfaType(GfaFilterType::GFA_PRINCIPLE_CURVATURE); filter->SetGfaParam1(p1); break; case 13: filter->SetScaleByGfaType(GfaFilterType::GFA_GENERALIZED_GFA); filter->SetGfaParam1(p1); filter->SetGfaParam2(p2); break; default: filter->SetScaleByGfaType(GfaFilterType::GFA_STANDARD); } } filter->Update(); clock.Stop(); MBI_DEBUG << "took " << clock.GetMeanTime() << "s."; // VIZ TO DATATREE mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( filter->GetOutput() ); image->SetVolume( filter->GetOutput()->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); mitk::DataStorage::GetInstance()->Add(node); SetDefaultNodeProperties(node, nodename.append(" Viz")); node->SetProperty( "IsOdfVolume", mitk::BoolProperty::New( true ) ); node->SetProperty( "ShowMaxNumber", mitk::IntProperty::New( 1500 ) ); node->SetProperty( "DoRefresh", mitk::BoolProperty::New( true ) ); node->SetProperty( "layer", mitk::IntProperty::New( 1 ) ); node->SetProperty( "global_scaling", mitk::FloatProperty::New( 1.0 ) ); mitk::OdfVtkMapper2D::Pointer odfMapper = mitk::OdfVtkMapper2D::New(); node->SetMapper(1,odfMapper); mitk::StatusBar::GetInstance()->DisplayText("Computation complete."); m_DataTreeIterator->GetTree()->Modified(); this->GetRenderWindowPart()->RequestUpdate(); TreeChanged(); m_Controls->update(); } void QmitkDiffusionTensorEstimation::DirectionVolumesSaveButton() { // GET SELECTED ITEM const mitk::DataTreeFilter::Item* selectedItem = m_DirectionVolumesDataTreeFilter->GetSelectedItem(); if( !selectedItem ) return; mitk::Image::Pointer vol = static_cast(selectedItem->GetNode()->GetData()); if( !vol)return; typedef itk::Image,3 > IType; IType::Pointer itkVol = IType::New(); mitk::CastToItkImage(vol, itkVol); typedef itk::VectorImage VarVecImgType; VarVecImgType::Pointer vecImg = VarVecImgType::New(); vecImg->SetSpacing( itkVol->GetSpacing() ); // Set the image spacing vecImg->SetOrigin( itkVol->GetOrigin() ); // Set the image origin vecImg->SetDirection( itkVol->GetDirection() ); // Set the image direction vecImg->SetLargestPossibleRegion( itkVol->GetLargestPossibleRegion()); vecImg->SetBufferedRegion( itkVol->GetLargestPossibleRegion() ); vecImg->SetVectorLength(3); vecImg->Allocate(); itk::ImageRegionIterator ot (vecImg, vecImg->GetLargestPossibleRegion() ); ot = ot.Begin(); itk::ImageRegionIterator it (itkVol, itkVol->GetLargestPossibleRegion() ); it = it.Begin(); for (it = it.Begin(); !it.IsAtEnd(); ++it) { itk::Vector vec = it.Get(); VarVecImgType::PixelType varvec(vec.GetDataPointer(), 3); ot.Set(varvec); ++ot; } // SELECT FILE DIALOG std::string sName = selectedItem->GetNode()->GetName(); QString qName; qName.sprintf("%s.nhdr",sName.c_str()); QString filename = QFileDialog::getSaveFileName( qName, "Nrrd Images (*.nrrd *.nhdr)", this->m_Controls, "save file dialog", "Select Nrrd Outputfile" ); if ( !filename ) return; // WRITING TENSORS TO FILE MBI_INFO << "Writing data "; typedef itk::ImageFileWriter WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetFileName(filename.ascii()); writer->SetInput(vecImg); writer->Update(); } void QmitkDiffusionTensorEstimation::DirectionVolumesLoadButton() { // SELECT FOLDER DIALOG QFileDialog* w = new QFileDialog( this->m_Controls, "Select DWI data file", TRUE ); w->setMode( QFileDialog::ExistingFiles ); w->setFilter( "Nrrd Images (*.nrrd *.nhdr)" ); // RETRIEVE SELECTION if ( w->exec() != QDialog::Accepted ) return; QStringList filenames = w->selectedFiles(); QStringList::Iterator it = filenames.begin(); while( it != filenames.end() ) { std::string filename = ( *it ).ascii(); ++it; // READING VOLUME typedef itk::Image,3 > IType; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(filename); try { reader->Update(); } catch (itk::ExceptionObject e) { MBI_INFO << e << std::endl; } // Tensorvolume mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( reader->GetOutput() ); image->SetVolume( reader->GetOutput()->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); mitk::DataStorage::GetInstance()->Add(node); SetDefaultNodeProperties(node, itksys::SystemTools::GetFilenameName(filename)); node->SetProperty( "IsDirectionVolume", mitk::BoolProperty::New( true ) ); mitk::VectorImageMapper2D::Pointer mapper = mitk::VectorImageMapper2D::New(); node->SetMapper(1,mapper); TreeChanged(); } } void QmitkDiffusionTensorEstimation::DirectionVolumesRemoveButton() { m_DirectionVolumesDataTreeFilter->DeleteSelectedItems(); } void QmitkDiffusionTensorEstimation::TensorEstimationTeemEstimateButton() { try { itk::TimeProbe clock; const mitk::DataTreeFilter::ItemSet* selectedItems = m_DiffusionVolumesDataTreeFilter->GetSelectedItems(); int nrFiles = selectedItems->size(); if (!nrFiles) return; QString status; mitk::ProgressBar::GetInstance()->AddStepsToDo(nrFiles); mitk::DataTreeFilter::ItemSet::const_iterator itemiter( selectedItems->begin() ); mitk::DataTreeFilter::ItemSet::const_iterator itemiterend( selectedItems->end() ); std::vector nodes; while ( itemiter != itemiterend ) // for all items { mitk::DiffusionVolumes* vols = static_cast*>( (*itemiter)->GetNode()->GetData()); std::string nodename = (*itemiter)->GetProperty("name"); itemiter++; // TENSOR RECONSTRUCTION clock.Start(); MBI_INFO << "Teem Tensor reconstruction "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "Teem Tensor reconstruction for %s", nodename.c_str())); typedef mitk::TeemDiffusionTensor3DReconstructionImageFilter< DiffusionPixelType, TTensorPixelType > TensorReconstructionImageFilterType; TensorReconstructionImageFilterType::Pointer tensorReconstructionFilter = TensorReconstructionImageFilterType::New(); tensorReconstructionFilter->SetInput( vols ); tensorReconstructionFilter->SetEstimateErrorImage( m_Controls->m_TensorEstimationTeemErrorImage->isChecked() ); if(!m_Controls->m_TensorEstimationTeemSigmaEdit->text().contains(QString("NaN"))) tensorReconstructionFilter->SetSigma( m_Controls->m_TensorEstimationTeemSigmaEdit->text().toFloat() ); switch(m_Controls->m_TensorEstimationTeemEstimationMethodCombo->currentItem()) { case 0: tensorReconstructionFilter->SetEstimationMethod(mitk::TeemTensorEstimationMethodsLLS); break; case 1: tensorReconstructionFilter->SetEstimationMethod(mitk::TeemTensorEstimationMethodsNLS); break; case 2: tensorReconstructionFilter->SetEstimationMethod(mitk::TeemTensorEstimationMethodsWLS); break; case 3: tensorReconstructionFilter->SetEstimationMethod(mitk::TeemTensorEstimationMethodsMLE); break; default: tensorReconstructionFilter->SetEstimationMethod(mitk::TeemTensorEstimationMethodsLLS); } tensorReconstructionFilter->SetNumIterations( m_Controls->m_TensorEstimationTeemNumItsSpin->value() ); if(!m_Controls->m_TensorEstimationTeemConfThresholdEdit->text().contains(QString("NaN"))) tensorReconstructionFilter->SetConfidenceThreshold( m_Controls->m_TensorEstimationTeemConfThresholdEdit->text().toDouble() ); tensorReconstructionFilter->SetConfidenceFuzzyness( m_Controls->m_TensorEstimationTeemFuzzyEdit->text().toFloat() ); tensorReconstructionFilter->SetMinPlausibleValue( m_Controls->m_TensorEstimationTeemMinValEdit->text().toDouble() ); tensorReconstructionFilter->Update(); clock.Stop(); MBI_DEBUG << "took " << clock.GetMeanTime() << "s."; // TENSORS TO DATATREE //mitk::DataNode::Pointer node=mitk::DataNode::New(); //node->SetData( tensorReconstructionFilter->GetOutput() ); //mitk::DataStorage::GetInstance()->Add(node); //SetDefaultNodeProperties(node, nodename.append(" tensors")); //node->SetProperty( "IsConfidenceTensorVolume", mitk::BoolProperty::New( true ) ); mitk::DataNode::Pointer node2=mitk::DataNode::New(); node2->SetData( tensorReconstructionFilter->GetOutputItk() ); SetDefaultNodeProperties(node2, nodename.append(" (itk)")); node2->SetProperty( "IsTensorVolume", mitk::BoolProperty::New( true ) ); nodes.push_back(node2); mitk::ProgressBar::GetInstance()->Progress(); } std::vector::iterator nodeIt; for(nodeIt = nodes.begin(); nodeIt != nodes.end(); ++nodeIt) mitk::DataStorage::GetInstance()->Add(*nodeIt); mitk::ProgressBar::GetInstance()->Progress(); TreeChanged(); m_Controls->update(); mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles)); } catch (itk::ExceptionObject &ex) { MBI_INFO << ex; return ; } } void QmitkDiffusionTensorEstimation::TensorEstimationButton() { try { itk::TimeProbe clock; const mitk::DataTreeFilter::ItemSet* selectedItems = m_DiffusionVolumesDataTreeFilter->GetSelectedItems(); int nrFiles = selectedItems->size(); if (!nrFiles) return; QString status; mitk::ProgressBar::GetInstance()->AddStepsToDo(nrFiles); mitk::DataTreeFilter::ItemSet::const_iterator itemiter( selectedItems->begin() ); mitk::DataTreeFilter::ItemSet::const_iterator itemiterend( selectedItems->end() ); std::vector nodes; while ( itemiter != itemiterend ) // for all items { mitk::DiffusionVolumes* vols = static_cast*>( (*itemiter)->GetNode()->GetData()); std::string nodename = (*itemiter)->GetProperty("name"); itemiter++; // TENSOR RECONSTRUCTION clock.Start(); MBI_INFO << "Tensor reconstruction "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "Tensor reconstruction for %s", nodename.c_str())); typedef itk::DiffusionTensor3DReconstructionImageFilter< DiffusionPixelType, DiffusionPixelType, TTensorPixelType > TensorReconstructionImageFilterType; TensorReconstructionImageFilterType::Pointer tensorReconstructionFilter = TensorReconstructionImageFilterType::New(); tensorReconstructionFilter->SetGradientImage( vols->GetDirections(), vols->GetImage() ); tensorReconstructionFilter->SetNumberOfThreads( m_Controls->m_TensorEstimationNumberThreadsSpinbox->value() ); tensorReconstructionFilter->SetBValue(vols->GetB_Value()); tensorReconstructionFilter->SetThreshold( m_Controls->m_TensorEstimationThreasholdEdit->text().toFloat() ); tensorReconstructionFilter->Update(); clock.Stop(); MBI_DEBUG << "took " << clock.GetMeanTime() << "s."; // TENSORS TO DATATREE mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( tensorReconstructionFilter->GetOutput() ); image->SetVolume( tensorReconstructionFilter->GetOutput()->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); SetDefaultNodeProperties(node, nodename.append(" tensors")); node->SetProperty( "IsTensorVolume", mitk::BoolProperty::New( true ) ); nodes.push_back(node); mitk::ProgressBar::GetInstance()->Progress(); } std::vector::iterator nodeIt; for(nodeIt = nodes.begin(); nodeIt != nodes.end(); ++nodeIt) mitk::DataStorage::GetInstance()->Add(*nodeIt); mitk::ProgressBar::GetInstance()->Progress(); TreeChanged(); m_Controls->update(); mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles)); } catch (itk::ExceptionObject &ex) { MBI_INFO << ex; return ; } } void QmitkDiffusionTensorEstimation::OdfReconstructionButton() { try { itk::TimeProbe clock; const mitk::DataTreeFilter::ItemSet* selectedItems = m_DiffusionVolumesDataTreeFilter->GetSelectedItems(); int nrFiles = selectedItems->size(); if (!nrFiles) return; QString status; mitk::ProgressBar::GetInstance()->AddStepsToDo(nrFiles); mitk::DataTreeFilter::ItemSet::const_iterator itemiter( selectedItems->begin() ); mitk::DataTreeFilter::ItemSet::const_iterator itemiterend( selectedItems->end() ); std::vector nodes; while ( itemiter != itemiterend ) // for all items { mitk::DiffusionVolumes* vols = static_cast*>( (*itemiter)->GetNode()->GetData()); std::string nodename = (*itemiter)->GetProperty("name"); ++itemiter; // Odf RECONSTRUCTION clock.Start(); MBI_INFO << "Odf reconstruction "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "Odf reconstruction for %s", nodename.c_str())); typedef itk::DiffusionQballReconstructionImageFilter< DiffusionPixelType, DiffusionPixelType, TTensorPixelType, odfsize> //int NOdfDirections = 162, QballReconstructionImageFilterType; QballReconstructionImageFilterType::Pointer filter = QballReconstructionImageFilterType::New(); filter->SetGradientImage( vols->GetDirections(), vols->GetImage() ); filter->SetNumberOfThreads( m_Controls->m_OdfReconstructionNumberThreadsSpinbox->value() ); filter->SetBValue(vols->GetB_Value()); filter->SetThreshold( m_Controls->m_OdfReconstructionThreasholdEdit->text().toFloat() ); int normalization = m_Controls->m_OdfReconstructionPostprocessingMethod->currentItem(); switch(normalization) { case 0: { filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_STANDARD); break; } case 1: { filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_B_ZERO_B_VALUE); break; } case 2: { filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_B_ZERO); break; } case 3: { filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_NONE); break; } default: { filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_STANDARD); } } filter->Update(); clock.Stop(); MBI_DEBUG << "took " << clock.GetMeanTime() << "s." << std::endl; // ODFs TO DATATREE mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( filter->GetOutput() ); //image->SetImportVolume( filter->GetOutput()->GetBufferPointer(), 0, 0, mitk::Image::ImportMemoryManagementType::ManageMemory ); image->SetVolume( filter->GetOutput()->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); QString newname; newname = newname.append(nodename.c_str()); newname = newname.append("_QN%1").arg(normalization); SetDefaultNodeProperties(node, newname.ascii()); node->SetProperty( "IsOdfVolume", mitk::BoolProperty::New( true ) ); nodes.push_back(node); // B-Zero TO DATATREE mitk::Image::Pointer image4 = mitk::Image::New(); image4->InitializeByItk( filter->GetBZeroImage().GetPointer() ); image4->SetVolume( filter->GetBZeroImage()->GetBufferPointer() ); mitk::DataNode::Pointer node4=mitk::DataNode::New(); node4->SetData( image4 ); SetDefaultNodeProperties(node4, nodename.append("B0")); nodes.push_back(node4); mitk::ProgressBar::GetInstance()->Progress(); } std::vector::iterator nodeIt; for(nodeIt = nodes.begin(); nodeIt != nodes.end(); ++nodeIt) mitk::DataStorage::GetInstance()->Add(*nodeIt); mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles)); m_DataTreeIterator->GetTree()->Modified(); this->GetRenderWindowPart()->RequestUpdate(); TreeChanged(); m_Controls->update(); } catch (itk::ExceptionObject &ex) { MBI_INFO << ex; return ; } } template void QmitkDiffusionTensorEstimation::ReconstructAnalytically( mitk::DiffusionVolumes* vols, float lambda, std::string nodename, std::vector* nodes) { typedef itk::AnalyticalDiffusionQballReconstructionImageFilter FilterType; typename FilterType::Pointer filter = FilterType::New(); filter->SetGradientImage( vols->GetDirections(), vols->GetImage() ); filter->SetNumberOfThreads( m_Controls->m_OdfReconstructionNumberThreadsAnalyticalSpinbox->value() ); filter->SetBValue(vols->GetB_Value()); filter->SetThreshold( m_Controls->m_OdfReconstructionThreasholdAnalyticalEdit->text().toFloat() ); filter->SetLambda(lambda); filter->SetAdcProfileOnly(m_Controls->m_OdfReconstructionAdcOnlyCheckbox->isChecked()); int normalization = m_Controls->m_OdfReconstructionPostprocessingMethodAnalytical->currentItem(); switch(normalization) { case 0: { filter->SetNormalizationMethod(FilterType::QBAR_STANDARD); break; } case 1: { filter->SetNormalizationMethod(FilterType::QBAR_B_ZERO_B_VALUE); break; } case 2: { filter->SetNormalizationMethod(FilterType::QBAR_B_ZERO); break; } case 3: { filter->SetNormalizationMethod(FilterType::QBAR_NONE); break; } default: { filter->SetNormalizationMethod(FilterType::QBAR_STANDARD); } } filter->Update(); // ODFs TO DATATREE mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( filter->GetOutput() ); image->SetVolume( filter->GetOutput()->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); nodes->push_back(node); QString newname; newname = newname.append(nodename.c_str()); newname = newname.append("_QA%1").arg(normalization); SetDefaultNodeProperties(node, newname.ascii()); node->SetProperty( "IsOdfVolume", mitk::BoolProperty::New( true ) ); // B-Zero TO DATATREE mitk::Image::Pointer image4 = mitk::Image::New(); image4->InitializeByItk( filter->GetBZeroImage().GetPointer() ); image4->SetVolume( filter->GetBZeroImage()->GetBufferPointer() ); mitk::DataNode::Pointer node4=mitk::DataNode::New(); node4->SetData( image4 ); nodes->push_back(node4); SetDefaultNodeProperties(node4, nodename.append("B0")); } void QmitkDiffusionTensorEstimation::OdfReconstructionAnalyticalButton() { try { itk::TimeProbe clock; const mitk::DataTreeFilter::ItemSet* selectedItems = m_DiffusionVolumesDataTreeFilter->GetSelectedItems(); int nrFiles = selectedItems->size(); if (!nrFiles) return; std::vector lambdas; float minLambda = m_Controls->m_OdfReconstructionLambdaLineEdit->text().toFloat(); if(m_Controls->m_OdfReconstructionLambdaMultiCheckbox->isChecked()) { float stepLambda = m_Controls->m_OdfReconstructionLambdaStepLineEdit->text().toFloat(); float maxLambda = m_Controls->m_QBallReconstructionLambdaMaxLineEdit->text().toFloat(); for(float l=minLambda; lAddStepsToDo(nrFiles*nLambdas); mitk::DataTreeFilter::ItemSet::const_iterator itemiter( selectedItems->begin() ); mitk::DataTreeFilter::ItemSet::const_iterator itemiterend( selectedItems->end() ); std::vector* nodes = new std::vector(); while ( itemiter != itemiterend ) // for all items { mitk::DiffusionVolumes* vols = static_cast*>( (*itemiter)->GetNode()->GetData()); std::string nodename = (*itemiter)->GetProperty("name"); itemiter++; // Odf RECONSTRUCTION clock.Start(); MBI_INFO << "Odf reconstruction "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "Odf reconstruction for %s", nodename.c_str())); for(int i=0; im_OdfReconstructionMaxLLevelComboBox->currentItem()) { case 0: { ReconstructAnalytically<2>(vols, currentLambda, nodename, nodes); break; } case 1: { ReconstructAnalytically<4>(vols, currentLambda, nodename, nodes); break; } case 2: { ReconstructAnalytically<6>(vols, currentLambda, nodename, nodes); break; } case 3: { ReconstructAnalytically<8>(vols, currentLambda, nodename, nodes); break; } } clock.Stop(); MBI_DEBUG << "took " << clock.GetMeanTime() << "s."; mitk::ProgressBar::GetInstance()->Progress(); } } std::vector::iterator nodeIt; for(nodeIt = nodes->begin(); nodeIt != nodes->end(); ++nodeIt) mitk::DataStorage::GetInstance()->Add(*nodeIt); m_DataTreeIterator->GetTree()->Modified(); this->GetRenderWindowPart()->RequestUpdate(); TreeChanged(); m_Controls->update(); mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles)); } catch (itk::ExceptionObject &ex) { MBI_INFO << ex; return ; } } void QmitkDiffusionTensorEstimation::StandardAlgorithmsFAButton() { itk::TimeProbe clock; QString status; const mitk::DataTreeFilter::Item* item = m_TensorVolumesDataTreeFilter->GetSelectedItem(); if(!item)return; mitk::Image* vol = static_cast(item->GetNode()->GetData()); itk::Image::Pointer itkvol = itk::Image::New(); mitk::CastToItkImage(vol, itkvol); std::string nodename = item->GetProperty("name"); // COMPUTE FA clock.Start(); MBI_INFO << "Computing FA "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "Computing FA for %s", nodename.c_str())); typedef TensorPixelType::RealValueType RealValueType; typedef itk::Image< RealValueType, 3 > FAImageType; typedef itk::TensorFractionalAnisotropyImageFilter< TensorImageType, FAImageType > FAFilterType; FAFilterType::Pointer fractionalAnisotropyFilter = FAFilterType::New(); fractionalAnisotropyFilter->SetInput( itkvol ); typedef itk::ShiftScaleImageFilter ShiftScaleFilterType; ShiftScaleFilterType::Pointer multi = ShiftScaleFilterType::New(); multi->SetShift(0); multi->SetScale(200);//itk::NumericTraits::max() multi->SetInput(fractionalAnisotropyFilter->GetOutput()); multi->Update(); clock.Stop(); MBI_DEBUG << "took " << clock.GetMeanTime() << "s."; // FA TO DATATREE mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( multi->GetOutput() ); image->SetVolume( multi->GetOutput()->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); mitk::DataStorage::GetInstance()->Add(node); SetDefaultNodeProperties(node, nodename.append(" FA")); node->SetProperty( "IsFAVolume", mitk::BoolProperty::New( true ) ); mitk::StatusBar::GetInstance()->DisplayText("Computation complete."); m_DataTreeIterator->GetTree()->Modified(); this->GetRenderWindowPart()->RequestUpdate(); TreeChanged(); m_Controls->update(); } void QmitkDiffusionTensorEstimation::StandardAlgorithmsRAButton() { itk::TimeProbe clock; QString status; const mitk::DataTreeFilter::Item* item = m_TensorVolumesDataTreeFilter->GetSelectedItem(); if(!item)return; mitk::Image* vol = static_cast(item->GetNode()->GetData()); itk::Image::Pointer itkvol = itk::Image::New(); mitk::CastToItkImage(vol, itkvol); std::string nodename = item->GetProperty("name"); // COMPUTE RA clock.Start(); MBI_INFO << "Computing RA "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "Computing RA for %s", nodename.c_str())); typedef TensorPixelType::RealValueType RealValueType; typedef itk::Image< RealValueType, 3 > RAImageType; typedef itk::TensorRelativeAnisotropyImageFilter< TensorImageType, RAImageType > RAFilterType; RAFilterType::Pointer relativeAnisotropyFilter = RAFilterType::New(); relativeAnisotropyFilter->SetInput( itkvol ); relativeAnisotropyFilter->Update(); clock.Stop(); MBI_DEBUG << "took " << clock.GetMeanTime() << "s."; // FA TO DATATREE mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( relativeAnisotropyFilter->GetOutput() ); image->SetVolume( relativeAnisotropyFilter->GetOutput()->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); mitk::DataStorage::GetInstance()->Add(node); SetDefaultNodeProperties(node, nodename.append(" RA")); node->SetProperty( "IsRAVolume", mitk::BoolProperty::New( true ) ); mitk::StatusBar::GetInstance()->DisplayText("Computation complete."); m_DataTreeIterator->GetTree()->Modified(); this->GetRenderWindowPart()->RequestUpdate(); TreeChanged(); m_Controls->update(); } void QmitkDiffusionTensorEstimation::StandardAlgorithmsDirectionButton() { itk::TimeProbe clock; QString status; const mitk::DataTreeFilter::Item* item = m_TensorVolumesDataTreeFilter->GetSelectedItem(); if(!item)return; typedef itk::DiffusionTensor3D TensorType; typedef itk::Image TensorImgType; mitk::Image* vol = static_cast(item->GetNode()->GetData()); TensorImgType::Pointer itkvol = TensorImgType::New(); mitk::CastToItkImage(vol, itkvol); std::string nodename = item->GetProperty("name"); clock.Start(); MBI_INFO << "Computing Diffusion Direction "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "Computing Diffusion Direction for %s", nodename.c_str())); typedef itk::DiffusionTensorPrincipleDirectionImageFilter FilterType; FilterType::Pointer filter = FilterType::New(); filter->SetInput(itkvol); filter->SetNumberOfThreads(4); filter->Update(); itk::ImageRegionIterator it (filter->GetOutput(), filter->GetOutput()->GetLargestPossibleRegion() ); it = it.Begin(); // VECTORFIELD MBI_DEBUG << "Converting to Vectorfield"; typedef itk::Image, 3> VecImgType2; VecImgType2::Pointer vecImg5 = VecImgType2::New(); vecImg5->SetSpacing( itkvol->GetSpacing() ); // Set the image spacing vecImg5->SetOrigin( itkvol->GetOrigin() ); // Set the image origin vecImg5->SetDirection( itkvol->GetDirection() ); // Set the image direction vecImg5->SetLargestPossibleRegion( itkvol->GetLargestPossibleRegion()); vecImg5->SetBufferedRegion( vecImg5->GetLargestPossibleRegion() ); vecImg5->Allocate(); itk::ImageRegionIterator ot5 (vecImg5, vecImg5->GetLargestPossibleRegion() ); ot5 = ot5.Begin(); typedef FilterType::OutputImageType::PixelType VecPixType; for (it = it.Begin(); !it.IsAtEnd(); ++it) { VecPixType vec = it.Get(); itk::Vector pix; TTensorPixelType uvec[3] = {(TTensorPixelType)(vec[0]),(TTensorPixelType)(vec[1]),(TTensorPixelType)(vec[2])}; //TTensorPixelType uvec[3] = {(TTensorPixelType)(vec[1]),(TTensorPixelType)(-vec[0]),(TTensorPixelType)(vec[2])}; pix = uvec; ot5.Set(pix); ++ot5; } // Vectors TO DATATREE mitk::Image::Pointer image5 = mitk::Image::New(); image5->InitializeByItk( vecImg5.GetPointer() ); image5->SetVolume( vecImg5->GetBufferPointer() ); mitk::DataNode::Pointer node5=mitk::DataNode::New(); node5->SetData( image5 ); node5->SetName( nodename.append(" vecs").c_str()); mitk::DataStorage::GetInstance()->Add(node5); node5->SetProperty( "IsDirectionVolume", mitk::BoolProperty::New( true ) ); node5->SetProperty( "NormalizeVecs", mitk::BoolProperty::New( true ) ); node5->SetProperty( "Scale", mitk::FloatProperty::New( 1.0 ) ); node5->SetProperty( "LineWidth", mitk::FloatProperty::New( 1 ) ); mitk::VectorImageMapper2D::Pointer vecMapper5 = mitk::VectorImageMapper2D::New(); node5->SetMapper(1,vecMapper5); m_DataTreeIterator->GetTree()->Modified(); this->GetRenderWindowPart()->RequestUpdate(); TreeChanged(); m_Controls->update(); } void QmitkDiffusionTensorEstimation::OdfStandardAlgorithmsGFAButton() { itk::TimeProbe clock; QString status; const mitk::DataTreeFilter::ItemSet* selectedItems = m_OdfVolumesDataTreeFilter->GetSelectedItems(); int nrFiles = selectedItems->size(); if (!nrFiles) return; mitk::DataTreeFilter::ItemSet::const_iterator itemiter( selectedItems->begin() ); mitk::DataTreeFilter::ItemSet::const_iterator itemiterend( selectedItems->end() ); std::vector nodes; while ( itemiter != itemiterend ) // for all items { typedef itk::Vector OdfVectorType; typedef itk::Image OdfVectorImgType; mitk::Image* vol = static_cast((*itemiter)->GetNode()->GetData()); OdfVectorImgType::Pointer itkvol = OdfVectorImgType::New(); mitk::CastToItkImage(vol, itkvol); std::string nodename = (*itemiter)->GetProperty("name"); ++itemiter; float p1 = m_Controls->m_OdfStandardAlgorithmsGFAParam1->text().toFloat(); float p2 = m_Controls->m_OdfStandardAlgorithmsGFAParam2->text().toFloat(); // COMPUTE RA clock.Start(); MBI_INFO << "Computing GFA "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "Computing GFA for %s", nodename.c_str())); typedef OdfVectorType::ValueType RealValueType; typedef itk::Image< RealValueType, 3 > RAImageType; typedef itk::DiffusionOdfGeneralizedFaImageFilter GfaFilterType; GfaFilterType::Pointer gfaFilter = GfaFilterType::New(); gfaFilter->SetInput(itkvol); gfaFilter->SetNumberOfThreads(4); double scale = 1; std::string newname; newname.append(nodename); newname.append(" GFA"); switch(m_Controls->m_OdfStandardAlgorithmsGFAMethod->currentItem()) { case 0: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_STANDARD); newname.append("00"); scale = 200.0; break; } case 1: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_QUANTILES_HIGH_LOW); newname.append("01"); scale = 200.0; break; } case 2: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_QUANTILE_HIGH); newname.append("02"); scale = 200.0; break; } case 3: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_MAX_ODF_VALUE); newname.append("03"); scale = 200.0; break; } case 4: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_DECONVOLUTION_COEFFS); newname.append("04"); scale = 200.0; break; } case 5: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_MIN_MAX_NORMALIZED_STANDARD); newname.append("05"); scale = 200.0; break; } case 6: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_NORMALIZED_ENTROPY); newname.append("06"); break; } case 7: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_NEMATIC_ORDER_PARAMETER); newname.append("07"); scale = 200.0; break; } case 8: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_QUANTILES_LOW_HIGH); newname.append("08"); scale = 200.0; break; } case 9: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_QUANTILE_LOW); newname.append("09"); scale = 200.0; break; } case 10: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_MIN_ODF_VALUE); newname.append("10"); scale = 200.0; break; } case 11: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_STD_BY_MAX); newname.append("11"); scale = 200.0; break; } case 12: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_PRINCIPLE_CURVATURE); newname.append("12"); gfaFilter->SetParam1(p1); scale = 200.0; break; } case 13: { gfaFilter->SetComputationMethod(GfaFilterType::GFA_GENERALIZED_GFA); QString paramString; paramString = paramString.append(" K%1P%2").arg(p1).arg(p2); newname.append("13").append(paramString.ascii()); gfaFilter->SetParam1(p1); gfaFilter->SetParam2(p2); scale = 200.0; break; } default: { newname.append("0"); gfaFilter->SetComputationMethod(GfaFilterType::GFA_STANDARD); scale = 200.0; } } gfaFilter->Update(); clock.Stop(); MBI_DEBUG << "took " << clock.GetMeanTime() << "s."; typedef itk::Image ImgType; ImgType::Pointer img = ImgType::New(); img->SetSpacing( gfaFilter->GetOutput()->GetSpacing() ); // Set the image spacing img->SetOrigin( gfaFilter->GetOutput()->GetOrigin() ); // Set the image origin img->SetDirection( gfaFilter->GetOutput()->GetDirection() ); // Set the image direction img->SetLargestPossibleRegion( gfaFilter->GetOutput()->GetLargestPossibleRegion()); img->SetBufferedRegion( gfaFilter->GetOutput()->GetLargestPossibleRegion() ); img->Allocate(); itk::ImageRegionIterator ot (img, img->GetLargestPossibleRegion() ); ot = ot.Begin(); itk::ImageRegionConstIterator it (gfaFilter->GetOutput(), gfaFilter->GetOutput()->GetLargestPossibleRegion() ); it = it.Begin(); for (it = it.Begin(); !it.IsAtEnd(); ++it) { GfaFilterType::OutputImageType::PixelType val = it.Get(); ot.Set(val * scale); ++ot; } // GFA TO DATATREE mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( img.GetPointer() ); image->SetVolume( img->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); nodes.push_back(node); SetDefaultNodeProperties(node, newname.c_str()); node->SetProperty( "IsGFAVolume", mitk::BoolProperty::New( true ) ); mitk::StatusBar::GetInstance()->DisplayText("Computation complete."); } std::vector::iterator nodeIt; for(nodeIt = nodes.begin(); nodeIt != nodes.end(); ++nodeIt) mitk::DataStorage::GetInstance()->Add(*nodeIt); m_DataTreeIterator->GetTree()->Modified(); this->GetRenderWindowPart()->RequestUpdate(); TreeChanged(); m_Controls->update(); } void QmitkDiffusionTensorEstimation::OdfStandardAlgorithmsDirectionButton() { itk::TimeProbe clock; QString status; const mitk::DataTreeFilter::Item* item = m_OdfVolumesDataTreeFilter->GetSelectedItem(); if(!item)return; typedef itk::Vector OdfVectorType; typedef itk::Image OdfVectorImgType; mitk::Image* vol = static_cast(item->GetNode()->GetData()); OdfVectorImgType::Pointer itkvol = OdfVectorImgType::New(); mitk::CastToItkImage(vol, itkvol); std::string nodename = item->GetProperty("name"); clock.Start(); MBI_INFO << "Computing Diffusion Direction "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "Computing Diffusion Direction for %s", nodename.c_str())); typedef itk::DiffusionOdfGeneralizedFaImageFilter GfaFilterType; GfaFilterType::Pointer gfaFilter = GfaFilterType::New(); gfaFilter->SetInput(itkvol); gfaFilter->SetNumberOfThreads(4); gfaFilter->Update(); itk::ImageRegionIterator itGfa (gfaFilter->GetOutput(), gfaFilter->GetOutput()->GetLargestPossibleRegion() ); itGfa = itGfa.Begin(); int numdir = m_Controls->m_OdfStandardAlgorithmsOrderSpinbox->value(); typedef itk::DiffusionOdfPrincipleDirectionsImageFilter PrincipleDirectionsFilterType; PrincipleDirectionsFilterType::Pointer principleDirectionsFilter = PrincipleDirectionsFilterType::New(); principleDirectionsFilter->SetThreshold(m_Controls->m_OdfStandardAlgorithmsProbThreshEdit->text().toFloat()); principleDirectionsFilter->SetNrDirectionToExtract(numdir); principleDirectionsFilter->SetInput(itkvol); principleDirectionsFilter->SetNumberOfThreads(m_Controls->m_OdfStandardAlgorithmsNumberThreadsSpinbox->value()); principleDirectionsFilter->SetMultiplyGfa(false); principleDirectionsFilter->Update(); itk::ImageRegionIterator it (principleDirectionsFilter->GetOutput(), principleDirectionsFilter->GetOutput()->GetLargestPossibleRegion() ); if(numdir == 0) { MBI_INFO << "Converting to RGB"; typedef itk::Image, 3> VecImgType; VecImgType::Pointer vecImg = VecImgType::New(); vecImg->SetSpacing( itkvol->GetSpacing() ); // Set the image spacing vecImg->SetOrigin( itkvol->GetOrigin() ); // Set the image origin vecImg->SetDirection( itkvol->GetDirection() ); // Set the image direction vecImg->SetLargestPossibleRegion( itkvol->GetLargestPossibleRegion()); vecImg->SetBufferedRegion( vecImg->GetLargestPossibleRegion() ); vecImg->Allocate(); itk::ImageRegionIterator ot (vecImg, vecImg->GetLargestPossibleRegion() ); ot = ot.Begin(); typedef PrincipleDirectionsFilterType::OutputImageType::PixelType VecPixType; for (it = it.Begin(); !it.IsAtEnd(); ++it) { VecPixType vec = it.Get(); itk::RGBPixel pix; vec*=200*itGfa.Get(); vec[0] = abs(vec[0]); vec[1] = abs(vec[1]); vec[2] = abs(vec[2]); if(vec[0] > 255 || vec[1] > 255 || vec[2] > 255) { // should never get in here double max = vec[0]; max = maxInitializeByItk( vecImg.GetPointer() ); image2->SetVolume( vecImg->GetBufferPointer() ); mitk::DataNode::Pointer node2=mitk::DataNode::New(); node2->SetData( image2 ); mitk::DataStorage::GetInstance()->Add(node2); switch(numdir) { case 0: { SetDefaultNodeProperties(node2, nodename.append(" PD0")); break; } case 1: { SetDefaultNodeProperties(node2, nodename.append(" PD1")); } case 2: { SetDefaultNodeProperties(node2, nodename.append(" PD2")); } default: { SetDefaultNodeProperties(node2, nodename.append(" PDn")); } } node2->SetProperty( "IsRGBVolume", mitk::BoolProperty::New( true ) ); } // VECTORFIELD MBI_DEBUG << "Converting to Vectorfield"; typedef itk::Image, 3> VecImgType2; VecImgType2::Pointer vecImg5 = VecImgType2::New(); vecImg5->SetSpacing( itkvol->GetSpacing() ); // Set the image spacing vecImg5->SetOrigin( itkvol->GetOrigin() ); // Set the image origin vecImg5->SetDirection( itkvol->GetDirection() ); // Set the image direction vecImg5->SetLargestPossibleRegion( itkvol->GetLargestPossibleRegion()); vecImg5->SetBufferedRegion( vecImg5->GetLargestPossibleRegion() ); vecImg5->Allocate(); itk::ImageRegionIterator ot5 (vecImg5, vecImg5->GetLargestPossibleRegion() ); ot5 = ot5.Begin(); typedef PrincipleDirectionsFilterType::OutputImageType::PixelType VecPixType; for (it = it.Begin(); !it.IsAtEnd(); ++it) { VecPixType vec = it.Get(); itk::Vector pix; TTensorPixelType uvec[3] = {(TTensorPixelType)(vec[0]),(TTensorPixelType)(vec[1]),(TTensorPixelType)(vec[2])}; pix = uvec; ot5.Set(pix); ++ot5; } // Vectors TO DATATREE mitk::Image::Pointer image5 = mitk::Image::New(); image5->InitializeByItk( vecImg5.GetPointer() ); image5->SetVolume( vecImg5->GetBufferPointer() ); mitk::DataNode::Pointer node5=mitk::DataNode::New(); node5->SetData( image5 ); mitk::DataStorage::GetInstance()->Add(node5); switch(numdir) { case 0: { SetDefaultNodeProperties(node5, nodename.append(" Vec0")); break; } case 1: { SetDefaultNodeProperties(node5, nodename.append(" Vec1")); } case 2: { SetDefaultNodeProperties(node5, nodename.append(" Vec2")); } default: { SetDefaultNodeProperties(node5, nodename.append(" Vecn")); } } node5->SetProperty( "IsDirectionVolume", mitk::BoolProperty::New( true ) ); node5->SetProperty( "NormalizeVecs", mitk::BoolProperty::New( true ) ); node5->SetProperty( "Scale", mitk::FloatProperty::New( 0.8 ) ); node5->SetProperty( "LineWidth", mitk::FloatProperty::New( 3 ) ); mitk::VectorImageMapper2D::Pointer vecMapper5 = mitk::VectorImageMapper2D::New(); node5->SetMapper(1,vecMapper5); m_DataTreeIterator->GetTree()->Modified(); this->GetRenderWindowPart()->RequestUpdate(); TreeChanged(); m_Controls->update(); } void QmitkDiffusionTensorEstimation::OdfStandardAlgorithmsDeconvolutionButton() { itk::TimeProbe clock; QString status; const mitk::DataTreeFilter::Item* item = m_OdfVolumesDataTreeFilter->GetSelectedItem(); if(!item)return; typedef itk::Vector OdfVectorType; typedef itk::Image OdfVectorImgType; mitk::Image* vol = static_cast(item->GetNode()->GetData()); OdfVectorImgType::Pointer itkvol = OdfVectorImgType::New(); mitk::CastToItkImage(vol, itkvol); std::string nodename = item->GetProperty("name"); clock.Start(); MBI_INFO << "Computing Diffusion Direction "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "Computing Diffusion Direction for %s", nodename.c_str())); typedef itk::DiffusionOdfGeneralizedFaImageFilter GfaFilterType; GfaFilterType::Pointer gfaFilter = GfaFilterType::New(); gfaFilter->SetInput(itkvol); gfaFilter->SetNumberOfThreads(4); gfaFilter->Update(); itk::ImageRegionIterator itGfa (gfaFilter->GetOutput(), gfaFilter->GetOutput()->GetLargestPossibleRegion() ); itGfa = itGfa.Begin(); int numdirs = m_Controls->m_OdfStandardAlgorithmsDeconvolutionSpinbox->value(); //vnl_matrix_fixed* kernels // = new vnl_matrix_fixed(); //itk::ImageRegionIterator inIt(itkvol, itkvol->GetLargestPossibleRegion()); //inIt.GoToBegin(); //for(int i=0; i DeconvolutionFilterType; DeconvolutionFilterType::Pointer devonvolutionFilter = DeconvolutionFilterType::New(); devonvolutionFilter->SetFractionalThreshold(m_Controls->m_OdfStandardAlgorithmsDeconvolutionThreshEdit->text().toFloat()); if(!m_Controls->m_OdfStandardAlgorithmsDeconvolutionAngResThresholdEdit->text().contains(QString("NaN"))) { float angRes = m_Controls->m_OdfStandardAlgorithmsDeconvolutionAngResThresholdEdit->text().toFloat(); angRes /= 360/itk::Math::pi; devonvolutionFilter->SetAngularResolutionThreshold(angRes); } devonvolutionFilter->SetSamplingQuantileStart(m_Controls->m_OdfStandardAlgorithmsDeconvQuantStart->text().toFloat()); devonvolutionFilter->SetSamplingQuantileStep(m_Controls->m_OdfStandardAlgorithmsDeconvQuantStep->text().toFloat()); devonvolutionFilter->SetMinimumNumberOfSamples(m_Controls->m_OdfStandardAlgorithmsDeconvQuantMinNr->text().toInt()); devonvolutionFilter->SetIterateQuantiles(m_Controls->m_OdfStandardAlgorithmsDeconvQuantMulti->isChecked()); devonvolutionFilter->SetNrDirectionsToExtract(numdirs); devonvolutionFilter->SetInput(itkvol); devonvolutionFilter->SetNumberOfThreads(m_Controls->m_OdfStandardAlgorithmsDeconvNumberThreadsSpinbox->value()); devonvolutionFilter->SetGfaImage(gfaFilter->GetOutput()); //devonvolutionFilter->SetPresetConvolutionKernels(kernels); devonvolutionFilter->Update(); for(int i=0; i it (devonvolutionFilter->GetOutput(i), devonvolutionFilter->GetOutput()->GetLargestPossibleRegion() ); it = it.Begin(); if(i==0) { MBI_INFO << "Converting to RGB"; typedef itk::Image, 3> VecImgType; VecImgType::Pointer vecImg = VecImgType::New(); vecImg->SetSpacing( itkvol->GetSpacing() ); // Set the image spacing vecImg->SetOrigin( itkvol->GetOrigin() ); // Set the image origin vecImg->SetDirection( itkvol->GetDirection() ); // Set the image direction vecImg->SetLargestPossibleRegion( itkvol->GetLargestPossibleRegion()); vecImg->SetBufferedRegion( vecImg->GetLargestPossibleRegion() ); vecImg->Allocate(); itk::ImageRegionIterator ot (vecImg, vecImg->GetLargestPossibleRegion() ); ot = ot.Begin(); typedef DeconvolutionFilterType::OutputImageType::PixelType VecPixType; for (it = it.Begin(); !it.IsAtEnd(); ++it) { VecPixType vec = it.Get(); vnl_vector_fixed vnlvec = vec.GetVnlVector(); TTensorPixelType len = vnlvec.two_norm(); vnlvec = vnlvec.normalize(); itk::RGBPixel pix; vnlvec*=200*itGfa.Get(); vnlvec[0] = abs(vnlvec[0]); vnlvec[1] = abs(vnlvec[1]); vnlvec[2] = abs(vnlvec[2]); if(vnlvec[0] > 255 || vnlvec[1] > 255 || vnlvec[2] > 255) { //should never get in here double max = vnlvec[0]; max = maxInitializeByItk( vecImg.GetPointer() ); image2->SetVolume( vecImg->GetBufferPointer() ); mitk::DataNode::Pointer node2=mitk::DataNode::New(); node2->SetData( image2 ); mitk::DataStorage::GetInstance()->Add(node2); switch(i) { case 0: { SetDefaultNodeProperties(node2, nodename.append(" PD0")); break; } case 1: { SetDefaultNodeProperties(node2, nodename.append(" PD1")); break; } case 2: { SetDefaultNodeProperties(node2, nodename.append(" PD2")); break; } default: { SetDefaultNodeProperties(node2, nodename.append(" PDn")); break; } } node2->SetProperty( "IsRGBVolume", mitk::BoolProperty::New( true ) ); } // VECTORFIELD MBI_INFO << "Converting to Vectorfield"; typedef itk::Image, 3> VecImgType2; VecImgType2::Pointer vecImg5 = VecImgType2::New(); vecImg5->SetSpacing( itkvol->GetSpacing() ); // Set the image spacing vecImg5->SetOrigin( itkvol->GetOrigin() ); // Set the image origin vecImg5->SetDirection( itkvol->GetDirection() ); // Set the image direction vecImg5->SetLargestPossibleRegion( itkvol->GetLargestPossibleRegion()); vecImg5->SetBufferedRegion( vecImg5->GetLargestPossibleRegion() ); vecImg5->Allocate(); itk::ImageRegionIterator ot5 (vecImg5, vecImg5->GetLargestPossibleRegion() ); ot5 = ot5.Begin(); typedef DeconvolutionFilterType::OutputImageType::PixelType VecPixType; for (it = it.Begin(); !it.IsAtEnd(); ++it) { VecPixType vec = it.Get(); vnl_vector_fixed vnlvec = vec.GetVnlVector(); vnlvec = vnlvec.normalize(); itk::Vector pix; TTensorPixelType uvec[3] = {(TTensorPixelType)(vnlvec[0]),(TTensorPixelType)(vnlvec[1]),(TTensorPixelType)(vnlvec[2])}; pix = uvec; ot5.Set(pix); ++ot5; } // Vectors TO DATATREE mitk::Image::Pointer image5 = mitk::Image::New(); image5->InitializeByItk( vecImg5.GetPointer() ); image5->SetVolume( vecImg5->GetBufferPointer() ); mitk::DataNode::Pointer node5=mitk::DataNode::New(); node5->SetData( image5 ); mitk::DataStorage::GetInstance()->Add(node5); switch(i) { case 0: { SetDefaultNodeProperties(node5, nodename.append(" Vec0")); break; } case 1: { SetDefaultNodeProperties(node5, nodename.append(" Vec1")); break; } case 2: { SetDefaultNodeProperties(node5, nodename.append(" Vec2")); break; } default: { SetDefaultNodeProperties(node5, nodename.append(" Vecn")); break; } } node5->SetProperty( "IsDirectionVolume", mitk::BoolProperty::New( true ) ); node5->SetProperty( "NormalizeVecs", mitk::BoolProperty::New( true ) ); node5->SetProperty( "Scale", mitk::FloatProperty::New( 0.8 ) ); node5->SetProperty( "LineWidth", mitk::FloatProperty::New( 3 ) ); mitk::VectorImageMapper2D::Pointer vecMapper5 = mitk::VectorImageMapper2D::New(); node5->SetMapper(1,vecMapper5); } m_DataTreeIterator->GetTree()->Modified(); this->GetRenderWindowPart()->RequestUpdate(); TreeChanged(); m_Controls->update(); } void QmitkDiffusionTensorEstimation::SetDefaultNodeProperties(mitk::DataNode::Pointer node, std::string name) { node->SetProperty( "volumerendering", mitk::BoolProperty::New( false ) ); node->SetProperty( "use color", mitk::BoolProperty::New( true ) ); node->SetProperty( "texture interpolation", mitk::BoolProperty::New( true ) ); node->SetProperty( "reslice interpolation", mitk::VtkResliceInterpolationProperty::New() ); node->SetProperty( "layer", mitk::IntProperty::New(0)); node->SetProperty( "in plane resample extent by geometry", mitk::BoolProperty::New( false ) ); node->SetOpacity(1.0f); node->SetColor(1.0,1.0,1.0); node->SetVisibility(true); mitk::LevelWindowProperty::Pointer levWinProp = mitk::LevelWindowProperty::New(); mitk::LevelWindow levelwindow; // levelwindow.SetAuto( image ); levWinProp->SetLevelWindow( levelwindow ); node->GetPropertyList()->SetProperty( "levelwindow", levWinProp ); // add a default rainbow lookup table for color mapping if(!node->GetProperty("LookupTable")) { mitk::LookupTable::Pointer mitkLut = mitk::LookupTable::New(); vtkLookupTable* vtkLut = mitkLut->GetVtkLookupTable(); vtkLut->SetHueRange(0.6667, 0.0); vtkLut->SetTableRange(0.0, 20.0); vtkLut->Build(); mitk::LookupTableProperty::Pointer mitkLutProp = mitk::LookupTableProperty::New(); mitkLutProp->SetLookupTable(mitkLut); node->SetProperty( "LookupTable", mitkLutProp ); } if(!node->GetProperty("binary")) node->SetProperty( "binary", mitk::BoolProperty::New( false ) ); // add a default transfer function mitk::TransferFunction::Pointer tf = mitk::TransferFunction::New(); node->SetProperty ( "TransferFunction", mitk::TransferFunctionProperty::New ( tf.GetPointer() ) ); // set foldername as string property mitk::StringProperty::Pointer nameProp = mitk::StringProperty::New( name ); node->SetProperty( "name", nameProp ); } void QmitkDiffusionTensorEstimation::DirectionVolumesAngularErrorButton() { try { const mitk::DataTreeFilter::ItemSet* selectedItems = m_DirectionVolumesDataTreeFilter->GetSelectedItems(); int nrFiles = selectedItems->size(); if (nrFiles != 2) return; mitk::DataTreeFilter::ItemSet::const_iterator itemiter( selectedItems->begin() ); mitk::Image::Pointer vol1 = static_cast((*itemiter)->GetNode()->GetData()); if( !vol1)return; std::string nodename1 = (*itemiter)->GetProperty("name"); itemiter++; mitk::Image::Pointer vol2 = static_cast((*itemiter)->GetNode()->GetData()); if( !vol2)return; std::string nodename2 = (*itemiter)->GetProperty("name"); typedef itk::Image,3 > IType; IType::Pointer itkVol1 = IType::New(); mitk::CastToItkImage(vol1, itkVol1); IType::Pointer itkVol2 = IType::New(); mitk::CastToItkImage(vol2, itkVol2); typedef itk::VectorImagesAngularErrorImageFilter FilterType; FilterType::Pointer filter = FilterType::New(); filter->SetInput(itkVol1); filter->SetImage2(itkVol2.GetPointer()); filter->SetNumberOfThreads(4); filter->Update(); // Angluar Error TO DATATREE mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( filter->GetOutput() ); image->SetVolume( filter->GetOutput()->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); mitk::DataStorage::GetInstance()->Add(node); SetDefaultNodeProperties(node, nodename1.append(" ").append(nodename2).append(" ERR")); node->SetProperty( "IsErrorVolume", mitk::BoolProperty::New( true ) ); TreeChanged(); m_Controls->update(); QString status; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished computing Angular Error")); } catch (itk::ExceptionObject &ex) { MBI_INFO << ex; return ; } } //void QmitkDiffusionTensorEstimation::DwiStandardAlgorithmsGFAButton() //{ // // itk::TimeProbe clock; // QString status; // const mitk::DataTreeFilter::Item* item // = m_DiffusionVolumesDataTreeFilter->GetSelectedItem(); // if(!item)return; // // typedef itk::Vector OdfVectorType; // typedef itk::Image OdfVectorImgType; // mitk::Image* vol = // static_cast(item->GetNode()->GetData()); // OdfVectorImgType::Pointer itkvol = OdfVectorImgType::New(); // mitk::CastToItkImage(vol, itkvol); // std::string nodename = item->GetProperty("name"); // // // COMPUTE RA // clock.Start(); // std::cout << "Computing GFA "; // mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( // "Computing GFA for %s", nodename.c_str())); // typedef OdfVectorType::ValueType RealValueType; // typedef itk::Image< RealValueType, 3 > RAImageType; // typedef itk::DiffusionOdfGeneralizedFaImageFilter // GfaFilterType; // GfaFilterType::Pointer gfaFilter = GfaFilterType::New(); // gfaFilter->SetInput(itkvol); // gfaFilter->SetNumberOfThreads(4); // switch(m_Controls->m_OdfStandardAlgorithmsGFAMethodSpinbox->value()) // { // case 1: // { // gfaFilter->SetComputationMethod(GfaFilterType::STANDARD); // break; // } // case 2: // { // gfaFilter->SetComputationMethod(GfaFilterType::QUANTILES_HIGH_LOW); // break; // } // case 3: // { // gfaFilter->SetComputationMethod(GfaFilterType::QUANTILES_MIDDLE); // break; // } // case 4: // { // gfaFilter->SetComputationMethod(GfaFilterType::MAX_ODF_VALUE); // break; // } // case 5: // { // gfaFilter->SetComputationMethod(GfaFilterType::DECONVOLUTION_COEFFS); // break; // } // default: // { // gfaFilter->SetComputationMethod(GfaFilterType::STANDARD); // } // } // gfaFilter->Update(); // clock.Stop(); // std::cout << "took " << clock.GetMeanTime() << "s." << std::endl; // // typedef itk::Image ImgType; // ImgType::Pointer img = ImgType::New(); // img->SetSpacing( gfaFilter->GetOutput()->GetSpacing() ); // Set the image spacing // img->SetOrigin( gfaFilter->GetOutput()->GetOrigin() ); // Set the image origin // img->SetDirection( gfaFilter->GetOutput()->GetDirection() ); // Set the image direction // img->SetLargestPossibleRegion( gfaFilter->GetOutput()->GetLargestPossibleRegion()); // img->SetBufferedRegion( gfaFilter->GetOutput()->GetLargestPossibleRegion() ); // img->Allocate(); // itk::ImageRegionIterator ot (img, img->GetLargestPossibleRegion() ); // ot = ot.Begin(); // itk::ImageRegionConstIterator it // (gfaFilter->GetOutput(), gfaFilter->GetOutput()->GetLargestPossibleRegion() ); // it = it.Begin(); // // for (it = it.Begin(); !it.IsAtEnd(); ++it) // { // GfaFilterType::OutputImageType::PixelType val = it.Get(); // ot.Set(val * 200); // ++ot; // } // // // // GFA TO DATATREE // mitk::Image::Pointer image = mitk::Image::New(); // image->InitializeByItk( img.GetPointer() ); // image->SetVolume( img->GetBufferPointer() ); // mitk::DataNode::Pointer node=mitk::DataNode::New(); // node->SetData( image ); // mitk::DataStorage::GetInstance()->Add(node); // SetDefaultNodeProperties(node, nodename.append(" GFA")); // node->SetProperty( "IsGFAVolume", mitk::BoolProperty::New( true ) ); // // mitk::StatusBar::GetInstance()->DisplayText("Computation complete."); // // m_DataTreeIterator->GetTree()->Modified(); // this->GetRenderWindowPart()->RequestUpdate(); // TreeChanged(); // m_Controls->update(); // //} void QmitkDiffusionTensorEstimation::DiffusionVolumeSaveButton() { // GET SELECTED ITEM const mitk::DataTreeFilter::Item* selectedItem = m_DiffusionVolumesDataTreeFilter->GetSelectedItem(); if( !selectedItem ) return; mitk::DiffusionVolumes::Pointer diffVolumes = static_cast*>(selectedItem->GetNode()->GetData()); std::string sName = selectedItem->GetNode()->GetName(); QString qName; qName.sprintf("%s.nhdr",sName.c_str()); // SELECT FILE DIALOG //QFileDialog::getSaveFileName() //QFileDialog* w = new QFileDialog( this->m_Controls, "Select Nrrd Outputfile", TRUE ); //w->setMode( QFileDialog::AnyFile ); //w->setFilter( "Nrrd Images (*.nrrd *.nhdr)" ); //w->setName(qName); //if ( w->exec() != QDialog::Accepted ) // return; //QString filename = w->selectedFile(); QString filename = QFileDialog::getSaveFileName( qName, "Nrrd Images (*.nrrd *.nhdr)", this->m_Controls, "save file dialog", "Select Nrrd Outputfile" ); if ( !filename ) return; // WRITING DWIs TO NRRD VOLUME typedef mitk::NrrdDiffusionVolumesWriter WriterType; WriterType::Pointer nrrdWriter = WriterType::New(); nrrdWriter->SetInput( diffVolumes->GetImage() ); nrrdWriter->SetDirections(diffVolumes->GetDirections()); nrrdWriter->SetB_Value(diffVolumes->GetB_Value()); nrrdWriter->SetFileName(filename.ascii()); try { nrrdWriter->Update(); } catch (itk::ExceptionObject e) { MBI_INFO << e; } } void QmitkDiffusionTensorEstimation::DiffusionVolumesLoadButton() { // SELECT FOLDER DIALOG QFileDialog* w = new QFileDialog( this->m_Controls, "Select DWI data file", TRUE ); w->setMode( QFileDialog::ExistingFiles ); w->setFilter( "Nrrd Images (*.nrrd *.nhdr)" ); // RETRIEVE SELECTION if ( w->exec() != QDialog::Accepted ) return; QStringList filenames = w->selectedFiles(); QStringList::Iterator it = filenames.begin(); while( it != filenames.end() ) { std::string filename = ( *it ).ascii(); ++it; // READING NRRD DWI VOLUMES typedef mitk::NrrdDiffusionVolumesReader ReaderType; ReaderType::Pointer nrrdReader = ReaderType::New(); nrrdReader->SetFileName(filename); try { nrrdReader->Update(); // DWI TO DATATREE typedef mitk::DiffusionVolumes DiffVolumesType; DiffVolumesType::Pointer diffVolumes = DiffVolumesType::New(); diffVolumes->SetDirections(nrrdReader->GetDiffusionVectors()); diffVolumes->SetB_Value(nrrdReader->GetB_Value()); diffVolumes->SetImage(nrrdReader->GetOutput()); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( diffVolumes ); mitk::DataStorage::GetInstance()->Add(node); SetDefaultNodeProperties(node, itksys::SystemTools::GetFilenameName(filename)); TreeChanged(); } catch (itk::ExceptionObject e) { MBI_INFO << e; } } } void QmitkDiffusionTensorEstimation::DiffusionVolumesRemoveButton() { m_DiffusionVolumesDataTreeFilter->DeleteSelectedItems(); } void QmitkDiffusionTensorEstimation::DiffusionVolumesSelectAll() { const mitk::DataTreeFilter::ItemList* items = m_DiffusionVolumesDataTreeFilter->GetItems(); mitk::DataTreeFilter::ConstItemIterator itemiter( items->Begin() ); mitk::DataTreeFilter::ConstItemIterator itemiterend( items->End() ); while ( itemiter != itemiterend ) { m_DiffusionVolumesDataTreeFilter->SelectItem(*itemiter); ++itemiter; } }