diff --git a/code/core/files.cmake b/code/core/files.cmake index 89f189f..069db8c 100644 --- a/code/core/files.cmake +++ b/code/core/files.cmake @@ -1,56 +1,58 @@ SET(CPP_FILES rttbDoseIteratorInterface.cpp rttbDVH.cpp rttbDVHCalculator.cpp rttbDVHSet.cpp rttbException.cpp rttbGenericDoseIterator.cpp rttbGenericMaskedDoseIterator.cpp rttbGeometricInfo.cpp rttbIndexOutOfBoundsException.cpp rttbInvalidDoseException.cpp rttbInvalidParameterException.cpp rttbMappingOutsideOfImageException.cpp rttbMaskedDoseIteratorInterface.cpp rttbMaskVoxel.cpp rttbNullPointerException.cpp rttbPaddingException.cpp rttbPhysicalInfo.cpp rttbStructure.cpp rttbStructureSet.cpp rttbStrVectorStructureSetGenerator.cpp ) SET(H_FILES rttbBaseType.h rttbDoseAccessorGeneratorBase.h rttbDoseAccessorGeneratorInterface.h rttbDoseAccessorInterface.h rttbDoseIteratorInterface.h rttbDVH.h rttbDVHCalculator.h rttbDVHGeneratorInterface.h rttbDVHSet.h rttbException.h rttbExceptionMacros.h rttbGenericDoseIterator.h rttbGenericMaskedDoseIterator.h rttbGeometricInfo.h rttbIndexConversionInterface.h rttbIndexOutOfBoundsException.h rttbInvalidDoseException.h rttbInvalidParameterException.h rttbMappingOutsideOfImageException.h + rttbMaskAccessorGeneratorBase.h + rttbMaskAccessorGeneratorInterface.h rttbMaskAccessorInterface.h rttbMaskedDoseIteratorInterface.h rttbMaskVoxel.h rttbMutableDoseAccessorInterface.h rttbMutableMaskAccessorInterface.h rttbNullPointerException.h rttbPaddingException.h rttbPhysicalInfo.h rttbStructure.h rttbStructureSet.h rttbStructureSetGeneratorInterface.h rttbStrVectorStructureSetGenerator.h ) diff --git a/code/io/mask/files.cmake b/code/io/mask/files.cmake index e02dd40..d69f35f 100644 --- a/code/io/mask/files.cmake +++ b/code/io/mask/files.cmake @@ -1,11 +1,14 @@ SET(CPP_FILES + rttbITKImageFileMaskAccessorGenerator.cpp rttbITKImageMaskAccessor.cpp rttbITKImageMaskAccessorGenerator.cpp rttbITKImageMaskAccessorConverter.cpp ) SET(H_FILES + rttbITKImageFileMaskAccessorGenerator.h + rttbITKImageFileMaskAccessorGenerator.tpp rttbITKImageMaskAccessor.h rttbITKImageMaskAccessorGenerator.h rttbITKImageMaskAccessorConverter.h ) diff --git a/code/io/mask/rttbITKImageFileMaskAccessorGenerator.cpp b/code/io/mask/rttbITKImageFileMaskAccessorGenerator.cpp new file mode 100644 index 0000000..5ac21e1 --- /dev/null +++ b/code/io/mask/rttbITKImageFileMaskAccessorGenerator.cpp @@ -0,0 +1,177 @@ +// ----------------------------------------------------------------------- +// 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. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: 793 $ (last changed revision) +// @date $Date: 2014-10-10 10:24:45 +0200 (Fr, 10 Okt 2014) $ (last change date) +// @author $Author: hentsch $ (last changed by) +*/ + +#include +#include + +#include "rttbITKImageFileMaskAccessorGenerator.h" +#include "rttbException.h" +#include "rttbInvalidDoseException.h" +#include "rttbInvalidParameterException.h" + + +namespace rttb +{ + namespace io + { + namespace mask + { + ITKImageFileMaskAccessorGenerator::~ITKImageFileMaskAccessorGenerator() + { + + } + + ITKImageFileMaskAccessorGenerator::ITKImageFileMaskAccessorGenerator(const FileNameType& fileName) + { + _itkMaskFileName = fileName; + } + + rttb::core::MaskAccessorGeneratorBase::MaskAccessorPointer + ITKImageFileMaskAccessorGenerator::generateMaskAccessor() + { + io::itk::GenericImageReader::Pointer spReader = io::itk::GenericImageReader::New(); + + spReader->setFileName(_itkMaskFileName); + + io::itk::GenericImageReader::GenericOutputImageType::Pointer itkGenericImage; + + ITKImageMaskAccessor::ITKMaskImageType::ConstPointer itkDoubleImageConst; + + try + { + unsigned int loadedDimensions; + io::itk::GenericImageReader::LoadedPixelType loadedPixelType; + io::itk::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) + { + throw core::InvalidParameterException("image component type != SCALAR. Only SCALAR supported."); + } + + if (loadedComponentType == ::itk::ImageIOBase::DOUBLE) + { + _itkDoubleImage = dynamic_cast(itkGenericImage.GetPointer()); + } + else + { + handleGenericImage(itkGenericImage, loadedComponentType); + } + + if (_itkDoubleImage.IsNull()) + { + throw core::InvalidDoseException("Error!!! unable to load input image. File is not existing or has an unsupported format."); + return core::MaskAccessorGeneratorInterface::MaskAccessorPointer(); + } + } + catch (::itk::ExceptionObject& e) + { + std::cerr << "Error!!!" << std::endl; + std::cerr << e << std::endl; + throw rttb::core::InvalidDoseException(e.GetDescription()); + return core::MaskAccessorGeneratorInterface::MaskAccessorPointer(); + } + + _maskAccessor = boost::make_shared(_itkDoubleImage.GetPointer()); + return _maskAccessor; + } + + void ITKImageFileMaskAccessorGenerator::handleGenericImage( + io::itk::GenericImageReader::GenericOutputImageType* itkGenericImage, + ::itk::ImageIOBase::IOComponentType& loadedComponentType) + { + switch (loadedComponentType) + { + case ::itk::ImageIOBase::UCHAR: + { + doCasting(itkGenericImage); + break; + } + + case ::itk::ImageIOBase::CHAR: + { + doCasting(itkGenericImage); + break; + } + + case ::itk::ImageIOBase::USHORT: + { + doCasting(itkGenericImage); + break; + } + + case ::itk::ImageIOBase::SHORT: + { + doCasting(itkGenericImage); + break; + } + + case ::itk::ImageIOBase::UINT: + { + doCasting(itkGenericImage); + break; + } + + case ::itk::ImageIOBase::INT: + { + doCasting(itkGenericImage); + break; + } + + case ::itk::ImageIOBase::ULONG: + { + doCasting(itkGenericImage); + break; + } + + case ::itk::ImageIOBase::LONG: + { + doCasting(itkGenericImage); + break; + } + + case ::itk::ImageIOBase::FLOAT: + { + doCasting(itkGenericImage); + break; + } + + case ::itk::ImageIOBase::DOUBLE: + { + doCasting(itkGenericImage); + break; + } + + default: + { + throw core::InvalidParameterException("image type unknown"); + } + } + } + }//end namespace itk + }//end namespace io +}//end namespace rttb + diff --git a/code/io/mask/rttbITKImageFileMaskAccessorGenerator.h b/code/io/mask/rttbITKImageFileMaskAccessorGenerator.h new file mode 100644 index 0000000..7e9f90b --- /dev/null +++ b/code/io/mask/rttbITKImageFileMaskAccessorGenerator.h @@ -0,0 +1,98 @@ +// ----------------------------------------------------------------------- +// 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. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: 793 $ (last changed revision) +// @date $Date: 2014-10-10 10:24:45 +0200 (Fr, 10 Okt 2014) $ (last change date) +// @author $Author: hentsch $ (last changed by) +*/ +#ifndef __ITK_IMAGE_MASK_FILE_ACCESSOR_GENERATOR_H +#define __ITK_IMAGE_MASK_FILE_ACCESSOR_GENERATOR_H + +#include +#include + +#include "rttbMaskAccessorGeneratorBase.h" +#include "rttbBaseType.h" +#include "rttbITKImageMaskAccessor.h" +#include "../itk/rttbGenericImageReader.h" + +#include "itkImage.h" +#include "itkCastImageFilter.h" + + +namespace rttb +{ + namespace io + { + namespace mask + { + + /*! @class ITKImageFileMaskAccessorGenerator + @brief Load Mask data using the itk loading methods and wraps the resulting itk image in a ITKImageMaskAccessor. + * this is normally used if Mask distributions are stored in formats like meta image, nrrd... + * @note it implies that the Mask information is stored in absolute Gy values. + */ + class ITKImageFileMaskAccessorGenerator: public core::MaskAccessorGeneratorBase + { + public: + typedef MaskAccessorGeneratorBase::MaskAccessorPointer MaskAccessorPointer; + + private: + FileNameType _itkMaskFileName; + /** @brief The dose as itkImage */ + ITKImageMaskAccessor::ITKMaskImageType::Pointer _itkDoubleImage; + + ITKImageFileMaskAccessorGenerator(); + + /*! @brief Casts into itkImage + @details result is stored into _itkDoubleImage + */ + template void doCasting(rttb::io::itk::GenericImageReader::GenericOutputImageType* + genericImage); + + /*! @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 + */ + void handleGenericImage(rttb::io::itk::GenericImageReader::GenericOutputImageType* itkGenericImage, + ::itk::ImageIOBase::IOComponentType& loadedComponentType); + + + public: + ~ITKImageFileMaskAccessorGenerator(); + + ITKImageFileMaskAccessorGenerator(const FileNameType& fileName); + + /*! @brief Generate MaskAccessor + @return Return shared pointer of MaskAccessor. + @exception InvalidDoseException Thrown if file could not be read + @exception InvalidParameterException Thrown if file has imageDimension !=3 or image component type != SCALAR + @details is always converted into a itkImage by using a CastImageFilter + @sa doCasting, handleGenericImage + */ + MaskAccessorPointer generateMaskAccessor(); + + + }; + }//end namespace itk + }//end namespace io +}//end namespace rttb + +#include "rttbITKImageFileMaskAccessorGenerator.tpp" + +#endif diff --git a/code/io/mask/rttbITKImageFileMaskAccessorGenerator.tpp b/code/io/mask/rttbITKImageFileMaskAccessorGenerator.tpp new file mode 100644 index 0000000..d511798 --- /dev/null +++ b/code/io/mask/rttbITKImageFileMaskAccessorGenerator.tpp @@ -0,0 +1,64 @@ +// ----------------------------------------------------------------------- +// 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. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: 793 $ (last changed revision) +// @date $Date: 2014-10-10 10:24:45 +0200 (Fr, 10 Okt 2014) $ (last change date) +// @author $Author: hentsch $ (last changed by) +// Subversion HeadURL: $HeadURL: https://svn/sbr/Sources/SBR-Projects/MatchPoint/trunk/Code/IO/include/mapImageReader.tpp $ +*/ + +#ifndef __RTTB_ITK_IMAGE_FILE_MASK_ACCESSOR_GENERATOR_TPP +#define __RTTB_ITK_IMAGE_FILE_MASK_ACCESSOR_GENERATOR_TPP + +#include "rttbITKImageFileMaskAccessorGenerator.h" +#include "rttbInvalidParameterException.h" +#include "rttbInvalidDoseException.h" +#include "rttbITKImageMaskAccessor.h" + +namespace rttb +{ + namespace io + { + namespace mask + { + + template void ITKImageFileMaskAccessorGenerator::doCasting( + io::itk::GenericImageReader::GenericOutputImageType* genericImage) + { + typedef ::itk::Image InputImageType; + typedef ITKImageMaskAccessor::ITKMaskImageType OutputImageType; + InputImageType::Pointer pCastedInput = dynamic_cast(genericImage); + typedef ::itk::CastImageFilter CastFilterType; + CastFilterType::Pointer castFilter = CastFilterType::New(); + castFilter->SetInput(pCastedInput); + + try + { + //important to update the filter! + castFilter->Update(); + _itkDoubleImage = castFilter->GetOutput(); + } + catch (::itk::ExceptionObject& e) + { + std::cerr << "ITK Error!!!" << std::endl; + std::cerr << e << std::endl; + } + } + + } + } +} +#endif diff --git a/code/io/mask/rttbITKImageMaskAccessor.cpp b/code/io/mask/rttbITKImageMaskAccessor.cpp index 5a63d4c..3c2b8d4 100644 --- a/code/io/mask/rttbITKImageMaskAccessor.cpp +++ b/code/io/mask/rttbITKImageMaskAccessor.cpp @@ -1,173 +1,173 @@ // ----------------------------------------------------------------------- // 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. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 793 $ (last changed revision) // @date $Date: 2014-10-10 10:24:45 +0200 (Fr, 10 Okt 2014) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #include #include "rttbITKImageMaskAccessor.h" #include "rttbException.h" #include "rttbInvalidDoseException.h" namespace rttb { namespace io { namespace mask { - ITKImagMaskAccessor::ITKImagMaskAccessor(ITKDoseImageType::ConstPointer aMaskImage) + ITKImageMaskAccessor::ITKImageMaskAccessor(ITKMaskImageType::ConstPointer aMaskImage) : _mask(aMaskImage) { if (_mask.IsNull()) { - throw core::InvalidDoseException("Dose image = 0!") ; + throw core::InvalidDoseException("Mask image = 0!") ; } assembleGeometricInfo(); } - ITKImagMaskAccessor::~ITKImagMaskAccessor() + ITKImageMaskAccessor::~ITKImageMaskAccessor() { }; - bool ITKImagMaskAccessor::assembleGeometricInfo() + bool ITKImageMaskAccessor::assembleGeometricInfo() { _geoInfo->setSpacing(SpacingVectorType3D(_mask->GetSpacing()[0], _mask->GetSpacing()[1], _mask->GetSpacing()[2])); if (_geoInfo->getSpacing()[0] == 0 || _geoInfo->getSpacing()[1] == 0 || _geoInfo->getSpacing()[2] == 0) { throw core::InvalidDoseException("Pixel spacing = 0!"); } _geoInfo->setImagePositionPatient(WorldCoordinate3D(_mask->GetOrigin()[0], _mask->GetOrigin()[1], _mask->GetOrigin()[2])); OrientationMatrix OM(0); for (int col = 0; col < 3; ++col) { for (int row = 0; row < 3; ++row) { OM(col, row) = _mask->GetDirection()(col, row); } } _geoInfo->setOrientationMatrix(OM); _geoInfo->setNumColumns(_mask->GetLargestPossibleRegion().GetSize()[0]); _geoInfo->setNumRows(_mask->GetLargestPossibleRegion().GetSize()[1]); _geoInfo->setNumSlices(_mask->GetLargestPossibleRegion().GetSize()[2]); if (_geoInfo->getNumColumns() == 0 || _geoInfo->getNumRows() == 0 || _geoInfo->getNumSlices() == 0) { - throw core::InvalidDoseException("Empty dicom dose!") ; + throw core::InvalidDoseException("Empty mask!") ; } return true; } - void ITKImagMaskAccessor::updateMask() + void ITKImageMaskAccessor::updateMask() { return; } - ITKImagMaskAccessor::MaskVoxelListPointer ITKImagMaskAccessor::getRelevantVoxelVector() + ITKImageMaskAccessor::MaskVoxelListPointer ITKImageMaskAccessor::getRelevantVoxelVector() { // if not already generated start voxelization here updateMask(); for(int gridIndex =0 ; gridIndex < _geoInfo->getNumColumns()*_geoInfo->getNumRows()*_geoInfo->getNumSlices(); gridIndex++){ core::MaskVoxel currentVoxel = core::MaskVoxel(gridIndex); if(getMaskAt(gridIndex, currentVoxel)){ if(currentVoxel.getRelevantVolumeFraction() > 0){ _spRelevantVoxelVector->push_back(currentVoxel); } } } return _spRelevantVoxelVector; } - ITKImagMaskAccessor::MaskVoxelListPointer ITKImagMaskAccessor::getRelevantVoxelVector(float lowerThreshold) + ITKImageMaskAccessor::MaskVoxelListPointer ITKImageMaskAccessor::getRelevantVoxelVector(float lowerThreshold) { MaskVoxelListPointer filteredVoxelVectorPointer(new MaskVoxelList); updateMask(); // filter relevant voxels - ITKImagMaskAccessor::MaskVoxelList::iterator it = _spRelevantVoxelVector->begin(); + ITKImageMaskAccessor::MaskVoxelList::iterator it = _spRelevantVoxelVector->begin(); while (it != _spRelevantVoxelVector->end()) { if ((*it).getRelevantVolumeFraction() > lowerThreshold) { filteredVoxelVectorPointer->push_back(*it); } ++it; } // if mask calculation was not successful this is empty! return filteredVoxelVectorPointer; } - bool ITKImagMaskAccessor::getMaskAt(VoxelGridID aID, core::MaskVoxel& voxel) const + bool ITKImageMaskAccessor::getMaskAt(VoxelGridID aID, core::MaskVoxel& voxel) const { VoxelGridIndex3D aVoxelGridIndex; if (_geoInfo->convert(aID, aVoxelGridIndex)) { return getMaskAt(aVoxelGridIndex, voxel); } else { return false; } } - bool ITKImagMaskAccessor::getMaskAt(const VoxelGridIndex3D& aIndex, core::MaskVoxel& voxel) const + bool ITKImageMaskAccessor::getMaskAt(const VoxelGridIndex3D& aIndex, core::MaskVoxel& voxel) const { voxel.setRelevantVolumeFraction(0); if (_geoInfo->validIndex(aIndex)) { - const ITKDoseImageType::IndexType pixelIndex = {{aIndex[0], aIndex[1], aIndex[2]}}; + const ITKMaskImageType::IndexType pixelIndex = {{aIndex[0], aIndex[1], aIndex[2]}}; double value = _mask->GetPixel(pixelIndex); VoxelGridID gridId; _geoInfo->convert(aIndex, gridId); if(value >= 0 && value <=1 ){ voxel.setRelevantVolumeFraction(value); } else{ return false; } } else { return false; } } - const core::GeometricInfo& ITKImagMaskAccessor::getGeometricInfo() const + const core::GeometricInfo& ITKImageMaskAccessor::getGeometricInfo() const { return *_geoInfo; }; } } } diff --git a/code/io/mask/rttbITKImageMaskAccessor.h b/code/io/mask/rttbITKImageMaskAccessor.h index ed2b6da..ebe294e 100644 --- a/code/io/mask/rttbITKImageMaskAccessor.h +++ b/code/io/mask/rttbITKImageMaskAccessor.h @@ -1,121 +1,120 @@ // ----------------------------------------------------------------------- // 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. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 793 $ (last changed revision) // @date $Date: 2014-10-10 10:24:45 +0200 (Fr, 10 Okt 2014) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #ifndef __ITK_IMAGE_MASK_ACCESSOR_H #define __ITK_IMAGE_MASK_ACCESSOR_H #include #include #include "rttbMaskAccessorInterface.h" #include "rttbGeometricInfo.h" #include "rttbBaseType.h" #include "itkImage.h" namespace rttb { namespace io { namespace mask { /*! @class ITKImageMaskAccessor @brief This class gives access to mask information stored in an itk image - @details _doseGridScaling is always 1.0. Thus, it is assumed that the values in the itkImage are absolute. */ - class ITKImagMaskAccessor: public core::MaskAccessorInterface + class ITKImageMaskAccessor: public core::MaskAccessorInterface { public: - typedef ::itk::Image ITKDoseImageType; + typedef ::itk::Image ITKMaskImageType; typedef ::itk::ImageBase<3> ITKImageBaseType; typedef core::MaskAccessorInterface::MaskVoxelList MaskVoxelList; typedef core::MaskAccessorInterface::MaskVoxelListPointer MaskVoxelListPointer; typedef boost::shared_ptr GeometricInfoPtr; private: /** @brief The mask as itkImage */ - ITKDoseImageType::ConstPointer _mask; + ITKMaskImageType::ConstPointer _mask; IDType _maskUID; GeometricInfoPtr _geoInfo; /*! vector containing list of mask voxels*/ MaskVoxelListPointer _spRelevantVoxelVector; - /*! @brief get all required data from the itk image contained in _dose + /*! @brief get all required data from the itk image contained in _Mask @exception InvalidDoseException if PixelSpacing is 0 or size in any dimension is 0. */ bool assembleGeometricInfo(); public: - ~ITKImagMaskAccessor(); + ~ITKImageMaskAccessor(); // import of structure sets (loading from data) is done elsewhere. Structures are only voxelized here. // here the original RTToolbox voxelization shall be implemented - ITKImagMaskAccessor(ITKDoseImageType::ConstPointer aMaskImage); + ITKImageMaskAccessor(ITKMaskImageType::ConstPointer aMaskImage); /*! @brief voxelization of the given structures according to the original RTToolbox algorithm*/ void updateMask(); /*! @brief get vector conatining al relevant voxels that are inside the given structure*/ MaskVoxelListPointer getRelevantVoxelVector(); /*! @brief get vector conatining al relevant voxels that have a relevant volume above the given threshold and are inside the given structure*/ MaskVoxelListPointer getRelevantVoxelVector(float lowerThreshold); /*!@brief determine how a given voxel on the dose grid is masked * @param aID ID of the voxel in grid. * @param voxel Reference to the voxel. * @post after a valid call voxel containes the information of the specified grid voxel. If aID is not valid, voxel values are undefined. * The relevant volume fraction will be set to zero. * @return Indicates of the voxel exists and therefore if parameter voxel containes valid values.*/ bool getMaskAt(const VoxelGridID aID, core::MaskVoxel& voxel) const; bool getMaskAt(const VoxelGridIndex3D& aIndex, core::MaskVoxel& voxel) const; /*! @brief give access to GeometricInfo*/ const core::GeometricInfo& getGeometricInfo() const; - /* @ brief is true if dose is on a homogeneous grid */ + /* @ brief is true if Mask is on a homogeneous grid */ // Inhomogeneous grids are not supported at the moment, but if they will // be supported in the future the interface does not need to change. bool isGridHomogeneous() const { return true; }; IDType getMaskUID() const { return _maskUID; }; }; } } } #endif diff --git a/code/io/mask/rttbITKImageMaskAccessorGenerator.cpp b/code/io/mask/rttbITKImageMaskAccessorGenerator.cpp index d9bcdb4..75a5c61 100644 --- a/code/io/mask/rttbITKImageMaskAccessorGenerator.cpp +++ b/code/io/mask/rttbITKImageMaskAccessorGenerator.cpp @@ -1,40 +1,52 @@ // ----------------------------------------------------------------------- // 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. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 793 $ (last changed revision) // @date $Date: 2014-10-10 10:24:45 +0200 (Fr, 10 Okt 2014) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #include #include #include #include "rttbITKImageMaskAccessorGenerator.h" #include "rttbException.h" #include "rttbInvalidDoseException.h" namespace rttb{ namespace io{ namespace mask{ + ITKImageMaskAccessorGenerator::ITKImageMaskAccessorGenerator(const ITKImageMaskAccessor::ITKMaskImageType* aMaskImage){ + if (aMaskImage == NULL){ + throw core::InvalidDoseException("MaskImage is NULL"); + } + + _maskPtr = aMaskImage; + } + + core::MaskAccessorGeneratorBase::MaskAccessorPointer ITKImageMaskAccessorGenerator::generateMaskAccessor(){ + _maskAccessor = boost::make_shared(_maskPtr); + return _maskAccessor; + } }//end namespace mask }//end namespace io }//end namespace rttb diff --git a/code/io/mask/rttbITKImageMaskAccessorGenerator.h b/code/io/mask/rttbITKImageMaskAccessorGenerator.h index d4fc4e4..f0d5082 100644 --- a/code/io/mask/rttbITKImageMaskAccessorGenerator.h +++ b/code/io/mask/rttbITKImageMaskAccessorGenerator.h @@ -1,48 +1,71 @@ // ----------------------------------------------------------------------- // 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. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 793 $ (last changed revision) // @date $Date: 2014-10-10 10:24:45 +0200 (Fr, 10 Okt 2014) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #ifndef __ITK_IMAGE_MASK_ACCESSOR_GENERATOR_H #define __ITK_IMAGE_MASK_ACCESSOR_GENERATOR_H #include #include -#include "rttbDoseAccessorGeneratorBase.h" #include "rttbBaseType.h" #include "rttbITKImageMaskAccessor.h" +#include "rttbMaskAccessorGeneratorBase.h" +#include "rttbITKImageMaskAccessor.h" #include "itkImage.h" namespace rttb { namespace io { namespace mask { - class ITKImageMaskAccessorGenerator + class ITKImageMaskAccessorGenerator: public core::MaskAccessorGeneratorBase { + public: + typedef MaskAccessorGeneratorBase::MaskAccessorPointer MaskAccessorPointer; + + private: + /** @brief The Mask as itkImage */ + ITKImageMaskAccessor::ITKMaskImageType::ConstPointer _maskPtr; + + ITKImageMaskAccessorGenerator(); + + public: + virtual ~ITKImageMaskAccessorGenerator() {}; + + /*! + @pre aMaskImage must point to a valid instance. + @exception InvalidDoseException Thrown if aMaskImage is invalid. + */ + ITKImageMaskAccessorGenerator(const ITKImageMaskAccessor::ITKMaskImageType* aMaskImage); + + /*! @brief Generate MaskAccessor + @return Return shared pointer of MaskAccessor. + */ + MaskAccessorPointer generateMaskAccessor() ; }; } } } #endif