diff --git a/code/io/itk/CMakeLists.txt b/code/io/itk/CMakeLists.txt index ece1f8a..5a01901 100644 --- a/code/io/itk/CMakeLists.txt +++ b/code/io/itk/CMakeLists.txt @@ -1,2 +1,9 @@ -RTTB_CREATE_MODULE(RTTBITKIO DEPENDS RTTBCore PACKAGE_DEPENDS Boost ITK) - +IF(RTTB_ITK5_SUPPORT) + SET(ITK_DEPENDENT_HEADER_FILES "ITK5/itkDoseAccessorImageFilter.h" "ITK5/itkMaskAccessorImageSource.h" ) + SET(ITK_DEPENDENT_SOURCE_FILES "ITK5/itkDoseAccessorImageFilter.cpp" "ITK5/itkMaskAccessorImageSource.cpp") + RTTB_CREATE_MODULE(RTTBITKIO INTERNAL_INCLUDE_DIRS ITK5 DEPENDS RTTBCore PACKAGE_DEPENDS Boost ITK) +ELSE() + SET(ITK_DEPENDENT_HEADER_FILES "ITK4/itkDoseAccessorImageFilter.h" "ITK4/itkMaskAccessorImageSource.h") + SET(ITK_DEPENDENT_SOURCE_FILES "ITK4/itkDoseAccessorImageFilter.cpp" "ITK4/itkMaskAccessorImageSource.cpp") + RTTB_CREATE_MODULE(RTTBITKIO INTERNAL_INCLUDE_DIRS ITK4 DEPENDS RTTBCore PACKAGE_DEPENDS Boost ITK) +ENDIF() \ No newline at end of file diff --git a/code/io/itk/itkDoseAccessorImageFilter.cpp b/code/io/itk/ITK4/itkDoseAccessorImageFilter.cpp similarity index 96% copy from code/io/itk/itkDoseAccessorImageFilter.cpp copy to code/io/itk/ITK4/itkDoseAccessorImageFilter.cpp index 2be3390..642a13d 100644 --- a/code/io/itk/itkDoseAccessorImageFilter.cpp +++ b/code/io/itk/ITK4/itkDoseAccessorImageFilter.cpp @@ -1,76 +1,76 @@ -// ----------------------------------------------------------------------- -// 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 "itkDoseAccessorImageFilter.h" -#include "itkImageRegionIterator.h" -#include "itkImageRegionConstIteratorWithIndex.h" -#include "itkProgressReporter.h" - -namespace itk -{ - /** - * Constructor - */ - DoseAccessorImageFilter - ::DoseAccessorImageFilter() - { - this->SetNumberOfRequiredInputs(1); - } - - void - DoseAccessorImageFilter - ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, - ThreadIdType threadId) - { - ProgressReporter progress(this, threadId, - outputRegionForThread.GetNumberOfPixels()); - - using ImageRegionConstIteratorType = ImageRegionConstIteratorWithIndex; - using OutputImageRegionIteratorType = ImageRegionIterator; - - InputImagePointer inputPtr = dynamic_cast< InputImageType* >(ProcessObject::GetInput(0)); - ImageRegionConstIteratorType inputItr; - - if (inputPtr) - { - inputItr = ImageRegionConstIteratorType(inputPtr, outputRegionForThread); - } - - OutputImagePointer outputPtr = dynamic_cast< OutputImageType* >(ProcessObject::GetOutput(0)); - OutputImageRegionIteratorType outputItr; - - if (outputPtr) - { - outputItr = OutputImageRegionIteratorType(outputPtr, outputRegionForThread); - } - - if (inputPtr && outputPtr) - { - while (!(outputItr.IsAtEnd())) - { - ImageRegionConstIteratorType::IndexType index = inputItr.GetIndex(); - rttb::VoxelGridIndex3D doseIndex(index[0], index[1], index[2]); - - outputItr.Set(m_Accessor->getValueAt(doseIndex)); - - ++outputItr; - ++inputItr; - - progress.CompletedPixel(); - } - } - } -} // end namespace itk - +// ----------------------------------------------------------------------- +// 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 "itkDoseAccessorImageFilter.h" +#include "itkImageRegionIterator.h" +#include "itkImageRegionConstIteratorWithIndex.h" +#include "itkProgressReporter.h" + +namespace itk +{ + /** + * Constructor + */ + DoseAccessorImageFilter + ::DoseAccessorImageFilter() + { + this->SetNumberOfRequiredInputs(1); + } + + void + DoseAccessorImageFilter + ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, + ThreadIdType threadId) + { + ProgressReporter progress(this, threadId, + outputRegionForThread.GetNumberOfPixels()); + + using ImageRegionConstIteratorType = ImageRegionConstIteratorWithIndex; + using OutputImageRegionIteratorType = ImageRegionIterator; + + InputImagePointer inputPtr = dynamic_cast< InputImageType* >(ProcessObject::GetInput(0)); + ImageRegionConstIteratorType inputItr; + + if (inputPtr) + { + inputItr = ImageRegionConstIteratorType(inputPtr, outputRegionForThread); + } + + OutputImagePointer outputPtr = dynamic_cast< OutputImageType* >(ProcessObject::GetOutput(0)); + OutputImageRegionIteratorType outputItr; + + if (outputPtr) + { + outputItr = OutputImageRegionIteratorType(outputPtr, outputRegionForThread); + } + + if (inputPtr && outputPtr) + { + while (!(outputItr.IsAtEnd())) + { + ImageRegionConstIteratorType::IndexType index = inputItr.GetIndex(); + rttb::VoxelGridIndex3D doseIndex(index[0], index[1], index[2]); + + outputItr.Set(m_Accessor->getValueAt(doseIndex)); + + ++outputItr; + ++inputItr; + + progress.CompletedPixel(); + } + } + } +} // end namespace itk + diff --git a/code/io/itk/itkDoseAccessorImageFilter.h b/code/io/itk/ITK4/itkDoseAccessorImageFilter.h similarity index 97% copy from code/io/itk/itkDoseAccessorImageFilter.h copy to code/io/itk/ITK4/itkDoseAccessorImageFilter.h index 9d072f6..33d8f73 100644 --- a/code/io/itk/itkDoseAccessorImageFilter.h +++ b/code/io/itk/ITK4/itkDoseAccessorImageFilter.h @@ -1,112 +1,112 @@ -// ----------------------------------------------------------------------- -// 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 __itkDoseAccessorImageFilter_h -#define __itkDoseAccessorImageFilter_h - -#include "itkImageToImageFilter.h" - -#include "rttbDoseAccessorInterface.h" -#include "rttbITKImageAccessor.h" - -namespace itk -{ - /** \class DoseAccessorImageFilter - * \brief Perform a generic pixel-wise operation on the input image by setting its pixel values according to the dose accessor output. - * - * \ingroup IntensityImageFilters MultiThreaded - * \ingroup ITKImageIntensity - */ - - typedef rttb::io::itk::ITKImageAccessor::ITKImageType RTTBDoseImageType; - - class ITK_EXPORT DoseAccessorImageFilter: - public ImageToImageFilter< RTTBDoseImageType, RTTBDoseImageType > - - { - public: - /** Standard class typedefs. */ - typedef DoseAccessorImageFilter Self; - typedef ImageToImageFilter< RTTBDoseImageType, RTTBDoseImageType > Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(DoseAccessorImageFilter, ImageToImageFilter); - - /** Some typedefs. */ - typedef RTTBDoseImageType InputImageType; - typedef InputImageType::Pointer InputImagePointer; - typedef InputImageType::RegionType InputImageRegionType; - typedef InputImageType::PixelType InputImagePixelType; - typedef RTTBDoseImageType OutputImageType; - typedef OutputImageType::Pointer OutputImagePointer; - typedef OutputImageType::RegionType OutputImageRegionType; - typedef OutputImageType::PixelType OutputImagePixelType; - - typedef rttb::core::DoseAccessorInterface DoseAccessorType; - typedef rttb::core::DoseAccessorInterface::Pointer DoseAccessorPointer; - - /** Get the accessor pointer. */ - DoseAccessorPointer GetAccessor() - { - return m_Accessor; - } - - /** Set the accessor pointer. */ - void SetAccessor(DoseAccessorPointer accessor) - { - if (m_Accessor != accessor) - { - m_Accessor = accessor; - this->Modified(); - } - } - - /** ImageDimension constants */ - itkStaticConstMacro( - InputImageDimension, unsigned int, InputImageType::ImageDimension); - itkStaticConstMacro( - OutputImageDimension, unsigned int, OutputImageType::ImageDimension); - - protected: - DoseAccessorImageFilter(); - ~DoseAccessorImageFilter() override {} - - /** DoseAccessorImageFilter can be implemented as a multi threaded filter. - * Therefore, this implementation provides a ThreadedGenerateData() routine - * which is called for each processing thread. The output image data is - * allocated automatically by the superclass prior to calling - * ThreadedGenerateData(). ThreadedGenerateData can only write to the - * portion of the output image specified by the parameter - * "outputRegionForThread" - * - * \sa ImageToImageFilter::ThreadedGenerateData(), - * ImageToImageFilter::GenerateData() */ - void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, - ThreadIdType threadId) override; - - private: - DoseAccessorImageFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - DoseAccessorPointer m_Accessor; - }; -} // end namespace itk - - -#endif +// ----------------------------------------------------------------------- +// 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 __itkDoseAccessorImageFilter_h +#define __itkDoseAccessorImageFilter_h + +#include "itkImageToImageFilter.h" + +#include "rttbDoseAccessorInterface.h" +#include "rttbITKImageAccessor.h" + +namespace itk +{ + /** \class DoseAccessorImageFilter + * \brief Perform a generic pixel-wise operation on the input image by setting its pixel values according to the dose accessor output. + * + * \ingroup IntensityImageFilters MultiThreaded + * \ingroup ITKImageIntensity + */ + + typedef rttb::io::itk::ITKImageAccessor::ITKImageType RTTBDoseImageType; + + class ITK_EXPORT DoseAccessorImageFilter: + public ImageToImageFilter< RTTBDoseImageType, RTTBDoseImageType > + + { + public: + /** Standard class typedefs. */ + typedef DoseAccessorImageFilter Self; + typedef ImageToImageFilter< RTTBDoseImageType, RTTBDoseImageType > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(DoseAccessorImageFilter, ImageToImageFilter); + + /** Some typedefs. */ + typedef RTTBDoseImageType InputImageType; + typedef InputImageType::Pointer InputImagePointer; + typedef InputImageType::RegionType InputImageRegionType; + typedef InputImageType::PixelType InputImagePixelType; + typedef RTTBDoseImageType OutputImageType; + typedef OutputImageType::Pointer OutputImagePointer; + typedef OutputImageType::RegionType OutputImageRegionType; + typedef OutputImageType::PixelType OutputImagePixelType; + + typedef rttb::core::DoseAccessorInterface DoseAccessorType; + typedef rttb::core::DoseAccessorInterface::Pointer DoseAccessorPointer; + + /** Get the accessor pointer. */ + DoseAccessorPointer GetAccessor() + { + return m_Accessor; + } + + /** Set the accessor pointer. */ + void SetAccessor(DoseAccessorPointer accessor) + { + if (m_Accessor != accessor) + { + m_Accessor = accessor; + this->Modified(); + } + } + + /** ImageDimension constants */ + itkStaticConstMacro( + InputImageDimension, unsigned int, InputImageType::ImageDimension); + itkStaticConstMacro( + OutputImageDimension, unsigned int, OutputImageType::ImageDimension); + + protected: + DoseAccessorImageFilter(); + ~DoseAccessorImageFilter() override {} + + /** DoseAccessorImageFilter can be implemented as a multi threaded filter. + * Therefore, this implementation provides a ThreadedGenerateData() routine + * which is called for each processing thread. The output image data is + * allocated automatically by the superclass prior to calling + * ThreadedGenerateData(). ThreadedGenerateData can only write to the + * portion of the output image specified by the parameter + * "outputRegionForThread" + * + * \sa ImageToImageFilter::ThreadedGenerateData(), + * ImageToImageFilter::GenerateData() */ + void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, + ThreadIdType threadId) override; + + private: + DoseAccessorImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + DoseAccessorPointer m_Accessor; + }; +} // end namespace itk + + +#endif diff --git a/code/io/itk/ITK4/itkMaskAccessorImageSource.cpp b/code/io/itk/ITK4/itkMaskAccessorImageSource.cpp new file mode 100644 index 0000000..5f6aaaf --- /dev/null +++ b/code/io/itk/ITK4/itkMaskAccessorImageSource.cpp @@ -0,0 +1,101 @@ +// ----------------------------------------------------------------------- +// 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 "itkProgressReporter.h" +#include "itkExceptionObject.h" + +#include "rttbGeometricInfo.h" + +namespace itk +{ + /** + * Constructor + */ + MaskAccessorImageSource + ::MaskAccessorImageSource() + = default; + + void + MaskAccessorImageSource + ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, + ThreadIdType threadId) + { + ProgressReporter progress(this, threadId, + outputRegionForThread.GetNumberOfPixels()); + + 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/ITK4/itkMaskAccessorImageSource.h b/code/io/itk/ITK4/itkMaskAccessorImageSource.h new file mode 100644 index 0000000..20d6a06 --- /dev/null +++ b/code/io/itk/ITK4/itkMaskAccessorImageSource.h @@ -0,0 +1,105 @@ +// ----------------------------------------------------------------------- +// 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 __itkMaskAccessorImageSource_h +#define __itkMaskAccessorImageSource_h + +#include "itkGenerateImageSource.h" + +#include "rttbMaskAccessorInterface.h" +#include "rttbITKImageMaskAccessor.h" + +namespace itk +{ + /** \class MaskAccessorImageSource + * \brief Converts a given mask accessor into an itk image. + * + */ + + typedef rttb::io::itk::ITKImageMaskAccessor::ITKMaskImageType RTTBMaskImageType; + + class ITK_EXPORT MaskAccessorImageSource: + public GenerateImageSource< RTTBMaskImageType> + + { + public: + /** Standard class typedefs. */ + typedef MaskAccessorImageSource Self; + typedef GenerateImageSource< RTTBMaskImageType > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(MaskAccessorImageSource, ImageToImageFilter); + + /** Some typedefs. */ + typedef RTTBMaskImageType OutputImageType; + typedef OutputImageType::Pointer OutputImagePointer; + typedef OutputImageType::RegionType OutputImageRegionType; + typedef OutputImageType::PixelType OutputImagePixelType; + + typedef rttb::core::MaskAccessorInterface AccessorType; + typedef rttb::core::MaskAccessorInterface::Pointer AccessorPointer; + + /** Get the accessor pointer. */ + itkGetConstMacro(Accessor, AccessorPointer); + + /** Set the accessor pointer. */ + void SetAccessor(AccessorPointer accessor) + { + if (m_Accessor != accessor) + { + m_Accessor = accessor; + this->Modified(); + } + } + + itkSetMacro(FailsOnInvalidIDs, bool); + itkGetConstMacro(FailsOnInvalidIDs, bool); + + itkSetMacro(InvalidMaskValue, OutputImageType::ValueType); + itkGetConstMacro(InvalidMaskValue, OutputImageType::ValueType); + + /** ImageDimension constants */ + itkStaticConstMacro( + OutputImageDimension, unsigned int, OutputImageType::ImageDimension); + + protected: + MaskAccessorImageSource(); + ~MaskAccessorImageSource() override {} + + void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, + ThreadIdType threadId) override; + + void BeforeThreadedGenerateData() override; + + private: + MaskAccessorImageSource(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + typedef std::map VoxelMapType; + VoxelMapType m_idMap; + rttb::core::MaskAccessorInterface::MaskVoxelListPointer m_MaskedVoxels; + + AccessorPointer m_Accessor; + bool m_FailsOnInvalidIDs{true}; + OutputImageType::ValueType m_InvalidMaskValue{0}; + }; +} // end namespace itk + + +#endif diff --git a/code/io/itk/itkDoseAccessorImageFilter.cpp b/code/io/itk/ITK5/itkDoseAccessorImageFilter.cpp similarity index 85% rename from code/io/itk/itkDoseAccessorImageFilter.cpp rename to code/io/itk/ITK5/itkDoseAccessorImageFilter.cpp index 2be3390..21eab51 100644 --- a/code/io/itk/itkDoseAccessorImageFilter.cpp +++ b/code/io/itk/ITK5/itkDoseAccessorImageFilter.cpp @@ -1,76 +1,75 @@ -// ----------------------------------------------------------------------- -// 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 "itkDoseAccessorImageFilter.h" -#include "itkImageRegionIterator.h" -#include "itkImageRegionConstIteratorWithIndex.h" -#include "itkProgressReporter.h" - -namespace itk -{ - /** - * Constructor - */ - DoseAccessorImageFilter - ::DoseAccessorImageFilter() - { - this->SetNumberOfRequiredInputs(1); - } - - void - DoseAccessorImageFilter - ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, - ThreadIdType threadId) - { - ProgressReporter progress(this, threadId, - outputRegionForThread.GetNumberOfPixels()); - - using ImageRegionConstIteratorType = ImageRegionConstIteratorWithIndex; - using OutputImageRegionIteratorType = ImageRegionIterator; - - InputImagePointer inputPtr = dynamic_cast< InputImageType* >(ProcessObject::GetInput(0)); - ImageRegionConstIteratorType inputItr; - - if (inputPtr) - { - inputItr = ImageRegionConstIteratorType(inputPtr, outputRegionForThread); - } - - OutputImagePointer outputPtr = dynamic_cast< OutputImageType* >(ProcessObject::GetOutput(0)); - OutputImageRegionIteratorType outputItr; - - if (outputPtr) - { - outputItr = OutputImageRegionIteratorType(outputPtr, outputRegionForThread); - } - - if (inputPtr && outputPtr) - { - while (!(outputItr.IsAtEnd())) - { - ImageRegionConstIteratorType::IndexType index = inputItr.GetIndex(); - rttb::VoxelGridIndex3D doseIndex(index[0], index[1], index[2]); - - outputItr.Set(m_Accessor->getValueAt(doseIndex)); - - ++outputItr; - ++inputItr; - - progress.CompletedPixel(); - } - } - } -} // end namespace itk - +// ----------------------------------------------------------------------- +// 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 "itkDoseAccessorImageFilter.h" +#include "itkImageRegionIterator.h" +#include "itkImageRegionConstIteratorWithIndex.h" +#include "itkProgressReporter.h" + +namespace itk +{ + /** + * Constructor + */ + DoseAccessorImageFilter + ::DoseAccessorImageFilter() + { + this->SetNumberOfRequiredInputs(1); + } + + void + DoseAccessorImageFilter + ::DynamicThreadedGenerateData(const OutputImageRegionType& outputRegionForThread) + { + //ProgressReporter progress(this, threadId, + // outputRegionForThread.GetNumberOfPixels()); + + using ImageRegionConstIteratorType = ImageRegionConstIteratorWithIndex; + using OutputImageRegionIteratorType = ImageRegionIterator; + + InputImagePointer inputPtr = dynamic_cast< InputImageType* >(ProcessObject::GetInput(0)); + ImageRegionConstIteratorType inputItr; + + if (inputPtr) + { + inputItr = ImageRegionConstIteratorType(inputPtr, outputRegionForThread); + } + + OutputImagePointer outputPtr = dynamic_cast< OutputImageType* >(ProcessObject::GetOutput(0)); + OutputImageRegionIteratorType outputItr; + + if (outputPtr) + { + outputItr = OutputImageRegionIteratorType(outputPtr, outputRegionForThread); + } + + if (inputPtr && outputPtr) + { + while (!(outputItr.IsAtEnd())) + { + ImageRegionConstIteratorType::IndexType index = inputItr.GetIndex(); + rttb::VoxelGridIndex3D doseIndex(index[0], index[1], index[2]); + + outputItr.Set(m_Accessor->getValueAt(doseIndex)); + + ++outputItr; + ++inputItr; + + //progress.CompletedPixel(); + } + } + } +} // end namespace itk + diff --git a/code/io/itk/itkDoseAccessorImageFilter.h b/code/io/itk/ITK5/itkDoseAccessorImageFilter.h similarity index 88% rename from code/io/itk/itkDoseAccessorImageFilter.h rename to code/io/itk/ITK5/itkDoseAccessorImageFilter.h index 9d072f6..f3164af 100644 --- a/code/io/itk/itkDoseAccessorImageFilter.h +++ b/code/io/itk/ITK5/itkDoseAccessorImageFilter.h @@ -1,112 +1,111 @@ -// ----------------------------------------------------------------------- -// 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 __itkDoseAccessorImageFilter_h -#define __itkDoseAccessorImageFilter_h - -#include "itkImageToImageFilter.h" - -#include "rttbDoseAccessorInterface.h" -#include "rttbITKImageAccessor.h" - -namespace itk -{ - /** \class DoseAccessorImageFilter - * \brief Perform a generic pixel-wise operation on the input image by setting its pixel values according to the dose accessor output. - * - * \ingroup IntensityImageFilters MultiThreaded - * \ingroup ITKImageIntensity - */ - - typedef rttb::io::itk::ITKImageAccessor::ITKImageType RTTBDoseImageType; - - class ITK_EXPORT DoseAccessorImageFilter: - public ImageToImageFilter< RTTBDoseImageType, RTTBDoseImageType > - - { - public: - /** Standard class typedefs. */ - typedef DoseAccessorImageFilter Self; - typedef ImageToImageFilter< RTTBDoseImageType, RTTBDoseImageType > Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(DoseAccessorImageFilter, ImageToImageFilter); - - /** Some typedefs. */ - typedef RTTBDoseImageType InputImageType; - typedef InputImageType::Pointer InputImagePointer; - typedef InputImageType::RegionType InputImageRegionType; - typedef InputImageType::PixelType InputImagePixelType; - typedef RTTBDoseImageType OutputImageType; - typedef OutputImageType::Pointer OutputImagePointer; - typedef OutputImageType::RegionType OutputImageRegionType; - typedef OutputImageType::PixelType OutputImagePixelType; - - typedef rttb::core::DoseAccessorInterface DoseAccessorType; - typedef rttb::core::DoseAccessorInterface::Pointer DoseAccessorPointer; - - /** Get the accessor pointer. */ - DoseAccessorPointer GetAccessor() - { - return m_Accessor; - } - - /** Set the accessor pointer. */ - void SetAccessor(DoseAccessorPointer accessor) - { - if (m_Accessor != accessor) - { - m_Accessor = accessor; - this->Modified(); - } - } - - /** ImageDimension constants */ - itkStaticConstMacro( - InputImageDimension, unsigned int, InputImageType::ImageDimension); - itkStaticConstMacro( - OutputImageDimension, unsigned int, OutputImageType::ImageDimension); - - protected: - DoseAccessorImageFilter(); - ~DoseAccessorImageFilter() override {} - - /** DoseAccessorImageFilter can be implemented as a multi threaded filter. - * Therefore, this implementation provides a ThreadedGenerateData() routine - * which is called for each processing thread. The output image data is - * allocated automatically by the superclass prior to calling - * ThreadedGenerateData(). ThreadedGenerateData can only write to the - * portion of the output image specified by the parameter - * "outputRegionForThread" - * - * \sa ImageToImageFilter::ThreadedGenerateData(), - * ImageToImageFilter::GenerateData() */ - void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, - ThreadIdType threadId) override; - - private: - DoseAccessorImageFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - DoseAccessorPointer m_Accessor; - }; -} // end namespace itk - - -#endif +// ----------------------------------------------------------------------- +// 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 __itkDoseAccessorImageFilter_h +#define __itkDoseAccessorImageFilter_h + +#include "itkImageToImageFilter.h" + +#include "rttbDoseAccessorInterface.h" +#include "rttbITKImageAccessor.h" + +namespace itk +{ + /** \class DoseAccessorImageFilter + * \brief Perform a generic pixel-wise operation on the input image by setting its pixel values according to the dose accessor output. + * + * \ingroup IntensityImageFilters MultiThreaded + * \ingroup ITKImageIntensity + */ + + typedef rttb::io::itk::ITKImageAccessor::ITKImageType RTTBDoseImageType; + + class ITK_EXPORT DoseAccessorImageFilter: + public ImageToImageFilter< RTTBDoseImageType, RTTBDoseImageType > + + { + public: + /** Standard class typedefs. */ + typedef DoseAccessorImageFilter Self; + typedef ImageToImageFilter< RTTBDoseImageType, RTTBDoseImageType > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(DoseAccessorImageFilter, ImageToImageFilter); + + /** Some typedefs. */ + typedef RTTBDoseImageType InputImageType; + typedef InputImageType::Pointer InputImagePointer; + typedef InputImageType::RegionType InputImageRegionType; + typedef InputImageType::PixelType InputImagePixelType; + typedef RTTBDoseImageType OutputImageType; + typedef OutputImageType::Pointer OutputImagePointer; + typedef OutputImageType::RegionType OutputImageRegionType; + typedef OutputImageType::PixelType OutputImagePixelType; + + typedef rttb::core::DoseAccessorInterface DoseAccessorType; + typedef rttb::core::DoseAccessorInterface::Pointer DoseAccessorPointer; + + /** Get the accessor pointer. */ + DoseAccessorPointer GetAccessor() + { + return m_Accessor; + } + + /** Set the accessor pointer. */ + void SetAccessor(DoseAccessorPointer accessor) + { + if (m_Accessor != accessor) + { + m_Accessor = accessor; + this->Modified(); + } + } + + /** ImageDimension constants */ + itkStaticConstMacro( + InputImageDimension, unsigned int, InputImageType::ImageDimension); + itkStaticConstMacro( + OutputImageDimension, unsigned int, OutputImageType::ImageDimension); + + protected: + DoseAccessorImageFilter(); + ~DoseAccessorImageFilter() override {} + + /** DoseAccessorImageFilter can be implemented as a multi threaded filter. + * Therefore, this implementation provides a DynamicThreadedGenerateData() routine + * which is called for each processing thread. The output image data is + * allocated automatically by the superclass prior to calling + * DynamicThreadedGenerateData(). ThreadedGenerateData can only write to the + * portion of the output image specified by the parameter + * "outputRegionForThread" + * + * \sa ImageToImageFilter::DynamicThreadedGenerateData(), + * ImageToImageFilter::GenerateData() */ + void DynamicThreadedGenerateData(const OutputImageRegionType& outputRegionForThread) override; + + private: + DoseAccessorImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + DoseAccessorPointer m_Accessor; + }; +} // end namespace itk + + +#endif diff --git a/code/io/itk/ITK5/itkMaskAccessorImageSource.cpp b/code/io/itk/ITK5/itkMaskAccessorImageSource.cpp new file mode 100644 index 0000000..d1b8173 --- /dev/null +++ b/code/io/itk/ITK5/itkMaskAccessorImageSource.cpp @@ -0,0 +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 "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/ITK5/itkMaskAccessorImageSource.h b/code/io/itk/ITK5/itkMaskAccessorImageSource.h new file mode 100644 index 0000000..f890c87 --- /dev/null +++ b/code/io/itk/ITK5/itkMaskAccessorImageSource.h @@ -0,0 +1,104 @@ +// ----------------------------------------------------------------------- +// 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 __itkMaskAccessorImageSource_h +#define __itkMaskAccessorImageSource_h + +#include "itkGenerateImageSource.h" + +#include "rttbMaskAccessorInterface.h" +#include "rttbITKImageMaskAccessor.h" + +namespace itk +{ + /** \class MaskAccessorImageSource + * \brief Converts a given mask accessor into an itk image. + * + */ + + typedef rttb::io::itk::ITKImageMaskAccessor::ITKMaskImageType RTTBMaskImageType; + + class ITK_EXPORT MaskAccessorImageSource: + public GenerateImageSource< RTTBMaskImageType> + + { + public: + /** Standard class typedefs. */ + typedef MaskAccessorImageSource Self; + typedef GenerateImageSource< RTTBMaskImageType > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(MaskAccessorImageSource, ImageToImageFilter); + + /** Some typedefs. */ + typedef RTTBMaskImageType OutputImageType; + typedef OutputImageType::Pointer OutputImagePointer; + typedef OutputImageType::RegionType OutputImageRegionType; + typedef OutputImageType::PixelType OutputImagePixelType; + + typedef rttb::core::MaskAccessorInterface AccessorType; + typedef rttb::core::MaskAccessorInterface::Pointer AccessorPointer; + + /** Get the accessor pointer. */ + itkGetConstMacro(Accessor, AccessorPointer); + + /** Set the accessor pointer. */ + void SetAccessor(AccessorPointer accessor) + { + if (m_Accessor != accessor) + { + m_Accessor = accessor; + this->Modified(); + } + } + + itkSetMacro(FailsOnInvalidIDs, bool); + itkGetConstMacro(FailsOnInvalidIDs, bool); + + itkSetMacro(InvalidMaskValue, OutputImageType::ValueType); + itkGetConstMacro(InvalidMaskValue, OutputImageType::ValueType); + + /** ImageDimension constants */ + itkStaticConstMacro( + OutputImageDimension, unsigned int, OutputImageType::ImageDimension); + + protected: + MaskAccessorImageSource(); + ~MaskAccessorImageSource() override {} + + void DynamicThreadedGenerateData(const OutputImageRegionType& outputRegionForThread) override; + + void BeforeThreadedGenerateData() override; + + private: + MaskAccessorImageSource(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + typedef std::map VoxelMapType; + VoxelMapType m_idMap; + rttb::core::MaskAccessorInterface::MaskVoxelListPointer m_MaskedVoxels; + + AccessorPointer m_Accessor; + bool m_FailsOnInvalidIDs{true}; + OutputImageType::ValueType m_InvalidMaskValue{0}; + }; +} // end namespace itk + + +#endif diff --git a/code/io/itk/files.cmake b/code/io/itk/files.cmake index 56e4ece..0d031e6 100644 --- a/code/io/itk/files.cmake +++ b/code/io/itk/files.cmake @@ -1,40 +1,38 @@ SET(CPP_FILES rttbFileDispatch.cpp rttbGenericImageReader.cpp rttbImageWriter.cpp rttbITKImageAccessor.cpp rttbITKImageAccessorConverter.cpp rttbITKImageAccessorGenerator.cpp rttbITKImageFileAccessorGenerator.cpp rttbITKImageFileMaskAccessorGenerator.cpp rttbITKImageMaskAccessor.cpp rttbITKImageMaskAccessorGenerator.cpp rttbITKImageMaskAccessorConverter.cpp rttbITKIOHelper.cpp - itkDoseAccessorImageFilter.cpp - itkMaskAccessorImageSource.cpp + ${ITK_DEPENDENT_SOURCE_FILES} ) SET(H_FILES rttbDoseAccessorConversionSettingInterface.h rttbDoseAccessorProcessorBase.h rttbDoseAccessorProcessorInterface.h rttbFileDispatch.h rttbGenericImageReader.h rttbImageReader.h rttbImageReader.tpp rttbImageWriter.h rttbITKException.h rttbITKImageAccessor.h rttbITKImageAccessorConverter.h rttbITKImageAccessorGenerator.h rttbITKImageFileAccessorGenerator.h rttbITKImageFileMaskAccessorGenerator.h rttbITKImageMaskAccessor.h rttbITKImageMaskAccessorConverter.h rttbITKImageMaskAccessorGenerator.h rttbITKIOHelper.h rttbITKIOHelper.tpp - itkDoseAccessorImageFilter.h - itkMaskAccessorImageSource.h -) + ${ITK_DEPENDENT_HEADER_FILES} +) \ No newline at end of file