diff --git a/code/io/itk/ITK5/itkMaskAccessorImageSource.cpp b/code/io/itk/ITK5/itkMaskAccessorImageSource.cpp index d1b8173..881ab93 100644 --- a/code/io/itk/ITK5/itkMaskAccessorImageSource.cpp +++ b/code/io/itk/ITK5/itkMaskAccessorImageSource.cpp @@ -1,94 +1,94 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ #include "itkMaskAccessorImageSource.h" #include "itkImageRegionIterator.h" #include "itkImageRegionConstIteratorWithIndex.h" -#include "itkExceptionObject.h" +#include "itkMacro.h" #include "rttbGeometricInfo.h" namespace itk { /** * Constructor */ MaskAccessorImageSource ::MaskAccessorImageSource() = default; void MaskAccessorImageSource ::DynamicThreadedGenerateData(const OutputImageRegionType& outputRegionForThread) { using OutputImageRegionIteratorType = ImageRegionIterator; OutputImagePointer outputPtr = dynamic_cast< OutputImageType* >(ProcessObject::GetOutput(0)); OutputImageRegionIteratorType outputItr; if (outputPtr) { outputItr = OutputImageRegionIteratorType(outputPtr, outputRegionForThread); for (; !(outputItr.IsAtEnd()); ++outputItr) { OutputImageType::IndexType index = outputItr.GetIndex(); rttb::VoxelGridIndex3D maskIndex(index[0], index[1], index[2]); rttb::VoxelGridID id = 0; if (m_Accessor->getGeometricInfo().convert(maskIndex, id)) { auto finding = m_idMap.find(id); if (finding != m_idMap.end()) { // Set the current pixel outputItr.Set(m_MaskedVoxels->at(finding->second).getRelevantVolumeFraction()); } } else { if (m_FailsOnInvalidIDs) { itkExceptionMacro(<<"invalid Mask index. Index:"<(ProcessObject::GetOutput(0)); outputPtr->FillBuffer(0.0); //The id map approach and working with relevant voxel vector is a workarround till task T22067 is solved and and can be used again. m_MaskedVoxels = m_Accessor->getRelevantVoxelVector(); m_idMap.clear(); for (rttb::core::MaskAccessorInterface::MaskVoxelList::size_type pos = 0; pos < m_MaskedVoxels->size(); ++pos) { m_idMap.insert(std::make_pair((*m_MaskedVoxels)[pos].getVoxelGridID(), pos)); } } } // end namespace itk diff --git a/code/io/itk/rttbGenericImageReader.cpp b/code/io/itk/rttbGenericImageReader.cpp index 9d3d872..6bb0786 100644 --- a/code/io/itk/rttbGenericImageReader.cpp +++ b/code/io/itk/rttbGenericImageReader.cpp @@ -1,294 +1,294 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ #include "rttbGenericImageReader.h" namespace rttb { namespace io { namespace itk { void GenericImageReader::load() { _spImage = nullptr; FileNameString probeFileName = this->_fileName; if (this->_seriesReadStyle == ImageSeriesReadStyle::Numeric) { using NamesType = ::itk::NumericSeriesFileNames; NamesType::Pointer names = NamesType::New(); names->SetStartIndex(1); names->SetEndIndex(1); names->SetSeriesFormat(this->_fileName.c_str()); probeFileName = names->GetFileNames()[0]; } ::itk::ImageIOBase::Pointer imageIO = ::itk::ImageIOFactory::CreateImageIO(probeFileName.c_str(), - ::itk::ImageIOFactory::ReadMode); + ::itk::IOFileModeEnum::ReadMode); if (!imageIO) { throw ::itk::ExceptionObject("No ImageIO found for given file. Please check if the file exists and has a supported format. File:" + probeFileName); } // Now that we found the appropriate ImageIO class, ask it to // read the meta data from the image file. imageIO->SetFileName(probeFileName.c_str()); imageIO->ReadImageInformation(); this->_loadedComponentType = imageIO->GetComponentType(); this->_loadedPixelType = imageIO->GetPixelType(); - if (this->_loadedPixelType == ::itk::ImageIOBase::RGB && imageIO->GetNumberOfComponents() == 1) + if (this->_loadedPixelType == ::itk::IOPixelEnum::RGB && imageIO->GetNumberOfComponents() == 1) { //if only one channel per pixel handle as scalar as long as RGB etc. is not supported - this->_loadedPixelType = ::itk::ImageIOBase::SCALAR; + this->_loadedPixelType = ::itk::IOPixelEnum::SCALAR; } this->_loadedComponentTypeStr = imageIO->GetComponentTypeAsString(this->_loadedComponentType); this->_loadedPixelTypeStr = imageIO->GetPixelTypeAsString(this->_loadedPixelType); this->_loadedDimensions = imageIO->GetNumberOfDimensions(); if (this->_seriesReadStyle == ImageSeriesReadStyle::Numeric && this->_loadedDimensions == 2) { this->_loadedDimensions = 3; //it is a stack of 2D images -> 3D } if (this->_loadedDimensions < 2 || this->_loadedDimensions > 3) { throw ::itk::ExceptionObject("The file uses a number of dimensions that is not supported in this application. Only dim<=3 supported "); } switch (_loadedPixelType) { - case ::itk::ImageIOBase::SCALAR: + case ::itk::IOPixelEnum::SCALAR: { if (this->_loadedDimensions == 2) { loadScalar<2>(); } else { loadScalar<3>(); } break; } default: { throw ::itk::ExceptionObject("The file uses a pixel type that is not supported in this application. Only SCALAR pixel type supported "); } } _upToDate = true; }; template void GenericImageReader:: loadScalar() { // Use the pixel type to instantiate the appropriate reader switch (this->_loadedComponentType) { - case ::itk::ImageIOBase::UCHAR: + case ::itk::IOComponentEnum::UCHAR: { this->_spImage = readImage(_fileName, _seriesReadStyle, false, 0, 0, _upperSeriesLimit, &_dictionaryArray); break; } - case ::itk::ImageIOBase::CHAR: + case ::itk::IOComponentEnum::CHAR: { this->_spImage = readImage(_fileName, _seriesReadStyle, false, 0, 0, _upperSeriesLimit, &_dictionaryArray); break; } - case ::itk::ImageIOBase::USHORT: + case ::itk::IOComponentEnum::USHORT: { this->_spImage = readImage(_fileName, _seriesReadStyle, false, 0, 0, _upperSeriesLimit, &_dictionaryArray); break; } - case ::itk::ImageIOBase::SHORT: + case ::itk::IOComponentEnum::SHORT: { this->_spImage = readImage(_fileName, _seriesReadStyle, false, 0, 0, _upperSeriesLimit, &_dictionaryArray); break; } - case ::itk::ImageIOBase::UINT: + case ::itk::IOComponentEnum::UINT: { this->_spImage = readImage(_fileName, _seriesReadStyle, false, 0, 0, _upperSeriesLimit, &_dictionaryArray); break; } - case ::itk::ImageIOBase::INT: + case ::itk::IOComponentEnum::INT: { this->_spImage = readImage(_fileName, _seriesReadStyle, false, 0, 0, _upperSeriesLimit, &_dictionaryArray); break; } - case ::itk::ImageIOBase::ULONG: + case ::itk::IOComponentEnum::ULONG: { this->_spImage = readImage(_fileName, _seriesReadStyle, false, 0, 0, _upperSeriesLimit, &_dictionaryArray); break; } - case ::itk::ImageIOBase::LONG: + case ::itk::IOComponentEnum::LONG: { this->_spImage = readImage(_fileName, _seriesReadStyle, false, 0, 0, _upperSeriesLimit, &_dictionaryArray); break; } - case ::itk::ImageIOBase::FLOAT: + case ::itk::IOComponentEnum::FLOAT: { this->_spImage = readImage(_fileName, _seriesReadStyle, false, 0, 0, _upperSeriesLimit, &_dictionaryArray); break; } - case ::itk::ImageIOBase::DOUBLE: + case ::itk::IOComponentEnum::DOUBLE: { this->_spImage = readImage(_fileName, _seriesReadStyle, false, 0, 0, _upperSeriesLimit, &_dictionaryArray); break; } default: { throw ::itk::ExceptionObject("The file uses a pixel component type that is not supported in this application. ComponentType: " + this->_loadedComponentTypeStr); } } }; const FileNameString& GenericImageReader:: getFileName() const { return _fileName; }; void GenericImageReader:: setFileName(const FileNameString& fileName) { if (fileName != _fileName) { _upToDate = false; _fileName = fileName; } } const unsigned int GenericImageReader:: getUpperSeriesLimit() const { return _upperSeriesLimit; }; void GenericImageReader:: setUpperSeriesLimit(const unsigned int upperLimit) { if (upperLimit != _upperSeriesLimit) { _upToDate = false; _upperSeriesLimit = upperLimit; }; }; const ImageSeriesReadStyle::Type GenericImageReader:: getSeriesReadStyle() const { return _seriesReadStyle; }; void GenericImageReader:: setSeriesReadStyle(ImageSeriesReadStyle::Type readStyle) { if (readStyle != _seriesReadStyle) { _upToDate = false; _seriesReadStyle = readStyle; }; }; GenericImageReader::GenericOutputImageType* GenericImageReader:: GetOutput(unsigned int& loadedDimensions, LoadedPixelType& loadedPixelType, LoadedComponentType& loadedComponentType) { if (!_upToDate) { load(); loadedPixelType = _loadedPixelType; loadedComponentType = _loadedComponentType; loadedDimensions = _loadedDimensions; }; return _spImage; }; GenericImageReader:: GenericImageReader() : _fileName() { }; GenericImageReader:: ~GenericImageReader() = default; const GenericImageReader::MetaDataDictionaryArrayType& GenericImageReader:: getMetaDictionaryArray() { return _dictionaryArray; }; }//end namespace itk }//end namespace io }//end namespace rttb diff --git a/code/io/itk/rttbGenericImageReader.h b/code/io/itk/rttbGenericImageReader.h index cfead1f..45c0d4e 100644 --- a/code/io/itk/rttbGenericImageReader.h +++ b/code/io/itk/rttbGenericImageReader.h @@ -1,156 +1,156 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ #ifndef __RTTB_GENERIC_IMAGE_READER_H #define __RTTB_GENERIC_IMAGE_READER_H #include "rttbImageReader.h" namespace rttb { namespace io { namespace itk { /** @class ImageReader * @brief Helper class manages the generic loading (unspecified dimension and pixel type) of 2D/3D images ... * * GenericImageReader uses the ImageReader class and dispatches the dimension and pixel type information from the specified image file. * GenericImageReader supports 2D and 3D images and the following pixel types: * - (unsigned) char * - (unsigned) short * - (unsigned) int * - (unsigned) long * - float * - double * . * Due to the fact that it builds upon the itk io infrastructure, all formats supported by ITK * can be read. * For further information regarding the usage see documentation of ImageReader. * @sa ImageReader * @note code copied from MatchPoint, see documentation (http://sourceforge.net/projects/matchpoint/) */ class GenericImageReader : public ::itk::Object { public: using Self = rttb::io::itk::GenericImageReader; using Superclass = ::itk::Object; using Pointer = ::itk::SmartPointer; using ConstPointer = ::itk::SmartPointer; itkTypeMacro(GenericImageReader, ::itk::Object); itkNewMacro(Self); using GenericOutputImageType = ::itk::DataObject; - using LoadedPixelType = ::itk::ImageIOBase::IOPixelType; + using LoadedPixelType = ::itk::IOPixelEnum; - using LoadedComponentType = ::itk::ImageIOBase::IOComponentType; + using LoadedComponentType = ::itk::IOComponentEnum; using MetaDataDictionaryArrayType = std::vector< ::itk::MetaDataDictionary>; private: /** Loaded Image.*/ GenericOutputImageType::Pointer _spImage; /** The file name of the image. */ FileNameString _fileName; /** The upper limit for the searching of series files in the path.*/ unsigned int _upperSeriesLimit{255}; /** Indicates if the image data is up to date or should be read again.*/ bool _upToDate{false}; /** Defines if the specified image file is part of a series and the * whole series should be read into one image. Only relevant for 3D images.*/ ImageSeriesReadStyle::Type _seriesReadStyle{ImageSeriesReadStyle::Default}; unsigned int _loadedDimensions; LoadedPixelType _loadedPixelType; LoadedComponentType _loadedComponentType; std::string _loadedComponentTypeStr; std::string _loadedPixelTypeStr; MetaDataDictionaryArrayType _dictionaryArray; /** Loads the image. First identifies pixel type and dimension and then deligates according * to the pixel type. * @exception map::core::ExceptionObject If no ImageIO is found. * @exception map::core::ExceptionObject If dimension of the image is not supported. Only 2D/3D is supported. * @exception map::core::ExceptionObject If pixel type is not supported. Currently only scalar pixels are supported. */ void load(); /** Loads an scalar image. * @exception map::core::ExceptionObject If pixel component type is not supported. */ template void loadScalar(); //template //void loadRGB(); public: /** Function to access the member variable _FileName. _FileName represents the filename of the * headerfile. The path must be included, the file extension may left away. * @return File name of the header file.*/ const FileNameString& getFileName() const; /** Function to access the member variable _FileName. _FileName represents the filename of the * headerfile. The path must be included, the file extension may left away. * @param [in] sFileName The file name of the header file.*/ void setFileName(const FileNameString& sFileName); /** Function to access the member variable _upperSeriesLimit. _upperSeriesLimit represents * the upper limit for the series file search. * @return The upper limit of the series search.*/ const unsigned int getUpperSeriesLimit() const; /** Function to access the member variable _upperSeriesLimit. _upperSeriesLimit represents * the upper limit for the series file search. Changing the series limit out dates the ImageReader. * @remark It is only relevant if series style is set to "Numeric". * @param [in] upperLimit The upper limit of the header file.*/ void setUpperSeriesLimit(const unsigned int upperLimit); /** Function to access the member variable _seriesReadStyle (see member description for more information).*/ const ImageSeriesReadStyle::Type getSeriesReadStyle() const; /** Function to access the member variable _seriesReadStyle (see member description for more information). * Changing the style out dates the ImageReader.*/ void setSeriesReadStyle(ImageSeriesReadStyle::Type readStyle); /** Function loads the image if needed and returns the data. * @return Pointer to loaded image. * @exception map::core::ExceptionObject If no ImageIO is found. * @exception map::core::ExceptionObject If dimension of the image is not supported. Only 2D/3D is supported. * @exception map::core::ExceptionObject If pixel type is not supported. Currently only scalar pixels are supported. * @exception map::core::ExceptionObject If pixel component type is not supported. */ GenericOutputImageType* GetOutput(unsigned int& loadedDimensions, LoadedPixelType& loadedPixelType, LoadedComponentType& loadedComponentType); /** Function returns the reference to the meta data dictionary(ies) of the latest file(s) loaded by this class. * Array may be empty if no MetaDictionary exists.*/ const MetaDataDictionaryArrayType& getMetaDictionaryArray(); protected: GenericImageReader(); ~GenericImageReader() override; }; }//end namespace itk }//end namespace io }//end namespace rttb #endif diff --git a/code/io/itk/rttbITKIOHelper.cpp b/code/io/itk/rttbITKIOHelper.cpp index be8ee1d..a6d44ea 100644 --- a/code/io/itk/rttbITKIOHelper.cpp +++ b/code/io/itk/rttbITKIOHelper.cpp @@ -1,165 +1,165 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ #include "rttbITKIOHelper.h" #include "rttbException.h" #include "rttbInvalidDoseException.h" #include "rttbInvalidParameterException.h" namespace rttb { namespace io { namespace itk { ITKImageType::Pointer readITKDoubleImage(FileNameType aITKImageFile, bool isDicom) { ITKImageType::Pointer itkDoubleImage; GenericImageReader::Pointer spReader = GenericImageReader::New(); if (isDicom) { spReader->setSeriesReadStyle(ImageSeriesReadStyle::Type::Dicom); } spReader->setFileName(aITKImageFile); GenericImageReader::GenericOutputImageType::Pointer itkGenericImage; ITKImageType::ConstPointer itkDoubleImageConst; try { unsigned int loadedDimensions; GenericImageReader::LoadedPixelType loadedPixelType; GenericImageReader::LoadedComponentType loadedComponentType; itkGenericImage = spReader->GetOutput(loadedDimensions, loadedPixelType, loadedComponentType); if (loadedDimensions != 3) { throw core::InvalidParameterException("image dimensions != 3. Only dim = 3 supported."); } - if (loadedPixelType != ::itk::ImageIOBase::SCALAR) + if (loadedPixelType != ::itk::IOPixelEnum::SCALAR) { throw core::InvalidParameterException("image component type != SCALAR. Only SCALAR supported."); } - if (loadedComponentType == ::itk::ImageIOBase::DOUBLE) + if (loadedComponentType == ::itk::IOComponentEnum::DOUBLE) { itkDoubleImage = dynamic_cast(itkGenericImage.GetPointer()); } else { itkDoubleImage = handleGenericImage(itkGenericImage, loadedComponentType); } if (itkDoubleImage.IsNull()) { throw core::InvalidDoseException("Error!!! unable to load input image. File is not existing or has an unsupported format."); } } catch (::itk::ExceptionObject& e) { std::cerr << "Error!!!" << std::endl; std::cerr << e << std::endl; throw rttb::core::InvalidDoseException(e.GetDescription()); } return itkDoubleImage; } ITKImageType::Pointer handleGenericImage( GenericImageReader::GenericOutputImageType* itkGenericImage, - ::itk::ImageIOBase::IOComponentType& loadedComponentType) + ::itk::IOComponentEnum& loadedComponentType) { ITKImageType::Pointer itkDoubleImage; switch (loadedComponentType) { - case ::itk::ImageIOBase::UCHAR: + case ::itk::IOComponentEnum::UCHAR: { itkDoubleImage = doCasting(itkGenericImage); break; } - case ::itk::ImageIOBase::CHAR: + case ::itk::IOComponentEnum::CHAR: { itkDoubleImage = doCasting(itkGenericImage); break; } - case ::itk::ImageIOBase::USHORT: + case ::itk::IOComponentEnum::USHORT: { itkDoubleImage = doCasting(itkGenericImage); break; } - case ::itk::ImageIOBase::SHORT: + case ::itk::IOComponentEnum::SHORT: { itkDoubleImage = doCasting(itkGenericImage); break; } - case ::itk::ImageIOBase::UINT: + case ::itk::IOComponentEnum::UINT: { itkDoubleImage = doCasting(itkGenericImage); break; } - case ::itk::ImageIOBase::INT: + case ::itk::IOComponentEnum::INT: { itkDoubleImage = doCasting(itkGenericImage); break; } - case ::itk::ImageIOBase::ULONG: + case ::itk::IOComponentEnum::ULONG: { itkDoubleImage = doCasting(itkGenericImage); break; } - case ::itk::ImageIOBase::LONG: + case ::itk::IOComponentEnum::LONG: { itkDoubleImage = doCasting(itkGenericImage); break; } - case ::itk::ImageIOBase::FLOAT: + case ::itk::IOComponentEnum::FLOAT: { itkDoubleImage = doCasting(itkGenericImage); break; } - case ::itk::ImageIOBase::DOUBLE: + case ::itk::IOComponentEnum::DOUBLE: { itkDoubleImage = doCasting(itkGenericImage); break; } default: { throw core::InvalidParameterException("image type unknown"); } } return itkDoubleImage; } }//end namespace itk }//end namespace io }//end namespace rttb diff --git a/code/io/itk/rttbITKIOHelper.h b/code/io/itk/rttbITKIOHelper.h index 7757582..630945c 100644 --- a/code/io/itk/rttbITKIOHelper.h +++ b/code/io/itk/rttbITKIOHelper.h @@ -1,58 +1,58 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ #ifndef __ITK_IO_HELPER_H #define __ITK_IO_HELPER_H #include "rttbBaseType.h" #include "rttbGenericImageReader.h" #include "itkImage.h" namespace rttb { namespace io { namespace itk { typedef ::itk::Image ITKImageType; /*! @brief Read a itk image file into itkImage */ ITKImageType::Pointer readITKDoubleImage(FileNameType aITKImageFile, bool isDicom = false); /*! @brief Converts a generic image to itkImage @param itkGenericImage the image read by GenericImageReader @param loadedComponentType the component type (used for casting later on) @exception InvalidParameterException if component type is not supported @sa GenericImageReader */ ITKImageType::Pointer handleGenericImage(GenericImageReader::GenericOutputImageType* itkGenericImage, - ::itk::ImageIOBase::IOComponentType& loadedComponentType); + ::itk::IOComponentEnum& loadedComponentType); /*! @brief Casts into itkImage */ template ITKImageType::Pointer doCasting( GenericImageReader::GenericOutputImageType* genericImage); }//end namespace itk }//end namespace io }//end namespace rttb #include "rttbITKIOHelper.tpp" #endif