diff --git a/Modules/CMakeLists.txt b/Modules/CMakeLists.txt index 5055934cf3..4c17d27011 100644 --- a/Modules/CMakeLists.txt +++ b/Modules/CMakeLists.txt @@ -1,64 +1,65 @@ set(LIBPOSTFIX "Ext") # Modules must be listed according to their dependencies set(module_dirs + DICOMReader SceneSerializationBase PlanarFigure ImageExtraction ImageStatistics LegacyAdaptors IpPicSupport MitkExt SceneSerialization GraphAlgorithms SurfaceInterpolation Segmentation PlanarFigureSegmentation Qmitk QmitkExt SegmentationUI Properties DiffusionImaging GPGPU IGT CameraCalibration IGTUI RigidRegistration RigidRegistrationUI DeformableRegistration DeformableRegistrationUI OpenCL OpenCVVideoSupport Overlays InputDevices ToFHardware ToFProcessing ToFUI US ClippingTools USUI DicomUI Simulation Remeshing Python ) set(MITK_DEFAULT_SUBPROJECTS MITK-Modules) foreach(module_dir ${module_dirs}) add_subdirectory(${module_dir}) endforeach() if(MITK_PRIVATE_MODULES) file(GLOB all_subdirs RELATIVE ${MITK_PRIVATE_MODULES} ${MITK_PRIVATE_MODULES}/*) foreach(subdir ${all_subdirs}) string(FIND ${subdir} "." _result) if(_result EQUAL -1) if(EXISTS ${MITK_PRIVATE_MODULES}/${subdir}/CMakeLists.txt) message(STATUS "Found private module ${subdir}") add_subdirectory(${MITK_PRIVATE_MODULES}/${subdir} private_modules/${subdir}) endif() endif() endforeach() endif(MITK_PRIVATE_MODULES) diff --git a/Modules/DICOMReader/CMakeLists.txt b/Modules/DICOMReader/CMakeLists.txt new file mode 100644 index 0000000000..355cc4eced --- /dev/null +++ b/Modules/DICOMReader/CMakeLists.txt @@ -0,0 +1,6 @@ + +MITK_CREATE_MODULE(DICOMReader + DEPENDS Mitk +) + +add_subdirectory(Testing) diff --git a/Modules/DICOMReader/Testing/CMakeLists.txt b/Modules/DICOMReader/Testing/CMakeLists.txt new file mode 100644 index 0000000000..153cd81e2e --- /dev/null +++ b/Modules/DICOMReader/Testing/CMakeLists.txt @@ -0,0 +1 @@ +MITK_CREATE_MODULE_TESTS() diff --git a/Modules/DICOMReader/Testing/files.cmake b/Modules/DICOMReader/Testing/files.cmake new file mode 100644 index 0000000000..7806367218 --- /dev/null +++ b/Modules/DICOMReader/Testing/files.cmake @@ -0,0 +1,7 @@ +set(MODULE_TESTS + mitkDICOMFileReaderTest.cpp +) + +set(TEST_CPP_FILES + mitkDICOMNullFileReader.cpp +) diff --git a/Modules/DICOMReader/Testing/mitkDICOMFileReaderTest.cpp b/Modules/DICOMReader/Testing/mitkDICOMFileReaderTest.cpp new file mode 100644 index 0000000000..7a47ee04ef --- /dev/null +++ b/Modules/DICOMReader/Testing/mitkDICOMFileReaderTest.cpp @@ -0,0 +1,94 @@ +/*=================================================================== + +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 "mitkDICOMNullFileReader.h" + +#include "mitkTestingMacros.h" + +class mitkDICOMFileReaderTestClass +{ + public: + +static void TestInputFilenames(mitk::DICOMFileReader* reader) +{ + mitk::StringList inputFiles; + + inputFiles.push_back("one"); + inputFiles.push_back("two"); + inputFiles.push_back("three"); + + reader->SetInputFiles( inputFiles ); + + const mitk::StringList& inputFilesReturned = reader->GetInputFiles(); + MITK_TEST_CONDITION(inputFilesReturned.size() == inputFiles.size(), "Input file list is received") + MITK_TEST_CONDITION( reader->GetNumberOfOutputs() == 0, "No outputs without analysis") + + // TODO: check strings +} + +static void TestOutputsContainInputs(mitk::DICOMNullFileReader* reader) +{ + mitk::StringList inputFiles; + + inputFiles.push_back("one"); + inputFiles.push_back("two"); + inputFiles.push_back("three"); + + reader->SetInputFiles( inputFiles ); + + reader->AnalyzeInputFiles(); + + unsigned int numberOfOutputs = reader->GetNumberOfOutputs(); + MITK_TEST_CONDITION(numberOfOutputs == inputFiles.size(), "DICOMNullFileReader repeats each input as an output") + + for (unsigned int o = 0; o < numberOfOutputs; ++o) + { + mitk::DICOMImageBlockDescriptor block = reader->GetOutput(o); + + // TODO: check if all files are in inputs + } + + // TODO: check that no files are in TWO outputs + // TODO: check that no files are forgotten + + try + { + mitk::DICOMImageBlockDescriptor block = reader->GetOutput( inputFiles.size() ); + MITK_TEST_CONDITION(false, "Invalid indices for GetOutput() should throw exception") + } + catch( std::invalid_argument& ) + { + MITK_TEST_CONDITION(true, "Invalid indices for GetOutput() should throw exception") + } +} + + + +}; // end test class + +int mitkDICOMFileReaderTest(int /* argc */, char* /*argv*/[]) +{ + MITK_TEST_BEGIN("mitkDICOMFileReaderTest"); + + mitk::DICOMNullFileReader::Pointer simpleReader = mitk::DICOMNullFileReader::New(); + MITK_TEST_CONDITION_REQUIRED(simpleReader.IsNotNull(), "DICOMNullFileReader can be instantiated."); + + mitkDICOMFileReaderTestClass::TestInputFilenames( simpleReader ); + + mitkDICOMFileReaderTestClass::TestOutputsContainInputs( simpleReader ); + + MITK_TEST_END(); +} diff --git a/Modules/DICOMReader/Testing/mitkDICOMNullFileReader.cpp b/Modules/DICOMReader/Testing/mitkDICOMNullFileReader.cpp new file mode 100644 index 0000000000..d10f88eecb --- /dev/null +++ b/Modules/DICOMReader/Testing/mitkDICOMNullFileReader.cpp @@ -0,0 +1,88 @@ +/*=================================================================== + +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 "mitkDICOMNullFileReader.h" + +mitk::DICOMNullFileReader +::DICOMNullFileReader() +:DICOMFileReader() +{ +} + +mitk::DICOMNullFileReader +::~DICOMNullFileReader() +{ +} + +mitk::DICOMNullFileReader +::DICOMNullFileReader(const DICOMNullFileReader& other ) +:DICOMFileReader(other) +{ +} + +mitk::DICOMNullFileReader& +mitk::DICOMNullFileReader +::operator=(const DICOMNullFileReader& other) +{ + if (this != &other) + { + DICOMFileReader::operator=(other); + } + return *this; +} + + +void +mitk::DICOMNullFileReader +::AnalyzeInputFiles() +{ + this->ClearOutputs(); + + StringList inputFilenames = this->GetInputFiles(); + this->SetNumberOfOutputs( inputFilenames.size() ); + + //generates one output for each input + unsigned int o = 0; + for (StringList::const_iterator inputIter = inputFilenames.begin(); + inputIter != inputFilenames.end(); + ++o, ++inputIter) + { + DICOMImageBlockDescriptor block; + StringList outputFiles; + outputFiles.push_back( *inputIter ); + + block.SetFilenames( outputFiles ); + + this->SetOutput( o, block ); + } +} + +// void AllocateOutputImages(); + +bool +mitk::DICOMNullFileReader +::LoadImages() +{ + // does nothing + return true; +} + +bool +mitk::DICOMNullFileReader +::CanHandleFile(const std::string& itkNotUsed(filename)) +{ + return true; // can handle all +} diff --git a/Modules/DICOMReader/Testing/mitkDICOMNullFileReader.h b/Modules/DICOMReader/Testing/mitkDICOMNullFileReader.h new file mode 100644 index 0000000000..708a59e21f --- /dev/null +++ b/Modules/DICOMReader/Testing/mitkDICOMNullFileReader.h @@ -0,0 +1,53 @@ +/*=================================================================== + +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 mitkDICOMNullFileReader_h +#define mitkDICOMNullFileReader_h + +#include "mitkDICOMFileReader.h" + +namespace mitk +{ + +class DICOMNullFileReader : public DICOMFileReader +{ + public: + + mitkClassMacro( DICOMNullFileReader, DICOMFileReader ); + mitkCloneMacro( DICOMNullFileReader ); + itkNewMacro( DICOMNullFileReader ); + + virtual void AnalyzeInputFiles(); + + // void AllocateOutputImages(); + virtual bool LoadImages(); + + virtual bool CanHandleFile(const std::string& filename); + + protected: + + DICOMNullFileReader(); + virtual ~DICOMNullFileReader(); + + DICOMNullFileReader(const DICOMNullFileReader& other); + DICOMNullFileReader& operator=(const DICOMNullFileReader& other); + + private: +}; + +} + +#endif diff --git a/Modules/DICOMReader/files.cmake b/Modules/DICOMReader/files.cmake new file mode 100644 index 0000000000..2c6496ff00 --- /dev/null +++ b/Modules/DICOMReader/files.cmake @@ -0,0 +1,9 @@ +set(H_FILES + mitkDICOMFileReader.h + mitkDICOMImageBlockDescriptor.h +) + +set(CPP_FILES + mitkDICOMFileReader.cpp + mitkDICOMImageBlockDescriptor.cpp +) diff --git a/Modules/DICOMReader/mitkDICOMEnums.h b/Modules/DICOMReader/mitkDICOMEnums.h new file mode 100644 index 0000000000..453fafd73a --- /dev/null +++ b/Modules/DICOMReader/mitkDICOMEnums.h @@ -0,0 +1,34 @@ +/*=================================================================== + +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 mitkDICOMEnums_h +#define mitkDICOMEnums_h + +namespace mitk +{ + typedef std::vector StringList; + typedef std::vector BoolList; + + typedef enum + { + SpacingInPatient, /// distances are mm within a patient + SpacingAtDetector, /// distances are mm at detector surface + SpacingUnknown /// NO spacing information is present, we use (1,1) as default + } PixelSpacingInterpretation; + +} + +#endif diff --git a/Modules/DICOMReader/mitkDICOMFileReader.cpp b/Modules/DICOMReader/mitkDICOMFileReader.cpp new file mode 100644 index 0000000000..36b523b2be --- /dev/null +++ b/Modules/DICOMReader/mitkDICOMFileReader.cpp @@ -0,0 +1,114 @@ +/*=================================================================== + +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 "mitkDICOMFileReader.h" + +mitk::DICOMFileReader +::DICOMFileReader() +:itk::LightObject() +{ +} + +mitk::DICOMFileReader +::~DICOMFileReader() +{ +} + +mitk::DICOMFileReader +::DICOMFileReader(const DICOMFileReader& other ) +:itk::LightObject() +,m_Outputs( other.m_Outputs ) // TODO copy instead of reference! +{ +} + +mitk::DICOMFileReader& +mitk::DICOMFileReader +::operator=(const DICOMFileReader& other) +{ + if (this != &other) + { + m_InputFilenames = other.m_InputFilenames; + m_Outputs = other.m_Outputs; // TODO copy instead of reference! + } + return *this; +} + +void +mitk::DICOMFileReader +::SetInputFiles(StringList filenames) +{ + m_InputFilenames = filenames; +} + +const mitk::StringList& +mitk::DICOMFileReader +::GetInputFiles() const +{ + return m_InputFilenames; +} + +unsigned int +mitk::DICOMFileReader +::GetNumberOfOutputs() const +{ + return m_Outputs.size(); +} + +void +mitk::DICOMFileReader +::ClearOutputs() +{ + m_Outputs.clear(); +} + +void +mitk::DICOMFileReader +::SetNumberOfOutputs(unsigned int numberOfOutputs) +{ + m_Outputs.resize(numberOfOutputs); +} + +void +mitk::DICOMFileReader +::SetOutput(unsigned int index, const mitk::DICOMImageBlockDescriptor& output) +{ + if (index < m_Outputs.size()) + { + m_Outputs[index] = output; + } + else + { + std::stringstream ss; + ss << "Index " << index << " out of range (" << m_Outputs.size() << " indices reserved)"; + throw std::invalid_argument( ss.str() ); + } +} + +const mitk::DICOMImageBlockDescriptor& +mitk::DICOMFileReader +::GetOutput(unsigned int index) const +{ + if (index < m_Outputs.size()) + { + return m_Outputs[index]; + } + else + { + std::stringstream ss; + ss << "Index " << index << " out of range (" << m_Outputs.size() << " indices reserved)"; + throw std::invalid_argument( ss.str() ); + } +} diff --git a/Modules/DICOMReader/mitkDICOMFileReader.h b/Modules/DICOMReader/mitkDICOMFileReader.h new file mode 100644 index 0000000000..93a53b2c4e --- /dev/null +++ b/Modules/DICOMReader/mitkDICOMFileReader.h @@ -0,0 +1,75 @@ +/*=================================================================== + +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 mitkDICOMFileReader_h +#define mitkDICOMFileReader_h + +#include "itkObjectFactory.h" +#include "mitkCommon.h" + +#include "DICOMReaderExports.h" + +#include "mitkDICOMImageBlockDescriptor.h" + +namespace mitk +{ + +class DICOMReader_EXPORT DICOMFileReader : public itk::LightObject +{ + public: + + enum LoadingConfidence + { + NoSupport = 0, + FullSupport = 1, + PartialSupport = 2, + }; + + mitkClassMacro( DICOMFileReader, itk::LightObject ) + + void SetInputFiles(StringList filenames); + const StringList& GetInputFiles() const; + + virtual void AnalyzeInputFiles() = 0; + unsigned int GetNumberOfOutputs() const; + const DICOMImageBlockDescriptor& GetOutput(unsigned int index) const; + + // void AllocateOutputImages(); + virtual bool LoadImages() = 0; + + virtual bool CanHandleFile(const std::string& filename) = 0; + + protected: + + DICOMFileReader(); + virtual ~DICOMFileReader(); + + DICOMFileReader(const DICOMFileReader& other); + DICOMFileReader& operator=(const DICOMFileReader& other); + + void ClearOutputs(); + void SetNumberOfOutputs(unsigned int numberOfOutputs); + void SetOutput(unsigned int index, const DICOMImageBlockDescriptor& output); + + private: + + StringList m_InputFilenames; + std::vector< DICOMImageBlockDescriptor > m_Outputs; +}; + +} + +#endif diff --git a/Modules/DICOMReader/mitkDICOMImageBlockDescriptor.cpp b/Modules/DICOMReader/mitkDICOMImageBlockDescriptor.cpp new file mode 100644 index 0000000000..9db8558bea --- /dev/null +++ b/Modules/DICOMReader/mitkDICOMImageBlockDescriptor.cpp @@ -0,0 +1,179 @@ +/*=================================================================== + +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 "mitkDICOMImageBlockDescriptor.h" + +mitk::DICOMImageBlockDescriptor +::DICOMImageBlockDescriptor() +:m_PixelsInterpolated(false) +,m_PixelSpacingInterpretation() +{ +} + +mitk::DICOMImageBlockDescriptor +::~DICOMImageBlockDescriptor() +{ +} + +mitk::DICOMImageBlockDescriptor +::DICOMImageBlockDescriptor(const DICOMImageBlockDescriptor& other) +:m_Filenames( other.m_Filenames ) +,m_MitkImage( other.m_MitkImage ) +,m_SliceIsLoaded( other.m_SliceIsLoaded ) +,m_PixelsInterpolated( other.m_PixelsInterpolated ) +,m_PixelSpacingInterpretation( other.m_PixelSpacingInterpretation ) +{ + if (m_MitkImage) + { + m_MitkImage = m_MitkImage->Clone(); + } +} + +mitk::DICOMImageBlockDescriptor& +mitk::DICOMImageBlockDescriptor +::operator=(const DICOMImageBlockDescriptor& other) +{ + if (this != &other) + { + m_Filenames = other.m_Filenames; + m_MitkImage = other.m_MitkImage; + m_SliceIsLoaded = other.m_SliceIsLoaded; + m_PixelsInterpolated = other.m_PixelsInterpolated; + m_PixelSpacingInterpretation = other.m_PixelSpacingInterpretation; + + if (m_MitkImage) + { + m_MitkImage = m_MitkImage->Clone(); + } + } + return *this; +} + +void +mitk::DICOMImageBlockDescriptor +::SetFilenames(StringList filenames) +{ + m_Filenames = filenames; + m_SliceIsLoaded.resize(filenames.size()); + m_SliceIsLoaded.assign(filenames.size(), false); +} + +const mitk::StringList& +mitk::DICOMImageBlockDescriptor +::GetFilenames() const +{ + return m_Filenames; +} + +void +mitk::DICOMImageBlockDescriptor +::SetMitkImage(Image::Pointer image) +{ + if (m_MitkImage != image) + { + m_MitkImage = image; + } +} + +mitk::Image::Pointer +mitk::DICOMImageBlockDescriptor +::GetMitkImage() const +{ + return m_MitkImage; +} + +void +mitk::DICOMImageBlockDescriptor +::SetSliceIsLoaded(unsigned int index, bool isLoaded) +{ + if (index < m_SliceIsLoaded.size()) + { + m_SliceIsLoaded[index] = isLoaded; + } + else + { + std::stringstream ss; + ss << "Index " << index << " out of range (" << m_SliceIsLoaded.size() << " indices reserved)"; + throw std::invalid_argument( ss.str() ); + } +} + +bool +mitk::DICOMImageBlockDescriptor +::IsSliceLoaded(unsigned int index) const +{ + if (index < m_SliceIsLoaded.size()) + { + return m_SliceIsLoaded[index]; + } + else + { + std::stringstream ss; + ss << "Index " << index << " out of range (" << m_SliceIsLoaded.size() << " indices reserved)"; + throw std::invalid_argument( ss.str() ); + } +} + +bool +mitk::DICOMImageBlockDescriptor +::AllSlicesAreLoaded() const +{ + bool allLoaded = true; + for (BoolList::const_iterator iter = m_SliceIsLoaded.begin(); + iter != m_SliceIsLoaded.end(); + ++iter) + { + allLoaded &= *iter; + } + + return allLoaded; +} + + +void +mitk::DICOMImageBlockDescriptor +::SetPixelsInterpolated(bool pixelsAreInterpolated) +{ + if (m_PixelsInterpolated != pixelsAreInterpolated) + { + m_PixelsInterpolated = pixelsAreInterpolated; + } +} + +bool +mitk::DICOMImageBlockDescriptor +::GetPixelsInterpolated() const +{ + return m_PixelsInterpolated; +} + + +void +mitk::DICOMImageBlockDescriptor +::SetPixelSpacingInterpretation( PixelSpacingInterpretation interpretation ) +{ + if (m_PixelSpacingInterpretation != interpretation) + { + m_PixelSpacingInterpretation = interpretation; + } +} + +mitk::PixelSpacingInterpretation +mitk::DICOMImageBlockDescriptor +::GetPixelSpacingInterpretation() const +{ + return m_PixelSpacingInterpretation; +} diff --git a/Modules/DICOMReader/mitkDICOMImageBlockDescriptor.h b/Modules/DICOMReader/mitkDICOMImageBlockDescriptor.h new file mode 100644 index 0000000000..80c79793dd --- /dev/null +++ b/Modules/DICOMReader/mitkDICOMImageBlockDescriptor.h @@ -0,0 +1,66 @@ +/*=================================================================== + +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 mitkDICOMImageBlockDescriptor_h +#define mitkDICOMImageBlockDescriptor_h + +#include "mitkImage.h" + +#include "mitkDICOMEnums.h" + +#include "DICOMReaderExports.h" + +namespace mitk +{ + +class DICOMReader_EXPORT DICOMImageBlockDescriptor +{ + public: + + DICOMImageBlockDescriptor(); + ~DICOMImageBlockDescriptor(); + + DICOMImageBlockDescriptor(const DICOMImageBlockDescriptor& other); + DICOMImageBlockDescriptor& operator=(const DICOMImageBlockDescriptor& other); + + void SetFilenames(StringList filenames); + const StringList& GetFilenames() const; + + void SetMitkImage(Image::Pointer image); + Image::Pointer GetMitkImage() const; + + void SetSliceIsLoaded(unsigned int index, bool isLoaded); + bool IsSliceLoaded(unsigned int index) const; + bool AllSlicesAreLoaded() const; + + void SetPixelsInterpolated(bool pixelsAreInterpolated); + bool GetPixelsInterpolated() const; + + void SetPixelSpacingInterpretation( PixelSpacingInterpretation interpretation ); + PixelSpacingInterpretation GetPixelSpacingInterpretation() const; + + private: + + StringList m_Filenames; + Image::Pointer m_MitkImage; + BoolList m_SliceIsLoaded; + bool m_PixelsInterpolated; + PixelSpacingInterpretation m_PixelSpacingInterpretation; +}; + +} + +#endif