diff --git a/code/io/itk/files.cmake b/code/io/itk/files.cmake index 9c20e7c..ff05187 100644 --- a/code/io/itk/files.cmake +++ b/code/io/itk/files.cmake @@ -1,39 +1,41 @@ SET(CPP_FILES rttbFileDispatch.cpp rttbGenericImageReader.cpp rttbImageWriter.cpp rttbITKException.cpp rttbITKImageAccessor.cpp rttbITKImageAccessorConverter.cpp rttbITKImageAccessorGenerator.cpp rttbITKImageFileAccessorGenerator.cpp rttbITKImageFileMaskAccessorGenerator.cpp rttbITKImageMaskAccessor.cpp rttbITKImageMaskAccessorGenerator.cpp rttbITKImageMaskAccessorConverter.cpp rttbITKIOHelper.cpp itkDoseAccessorImageFilter.cpp + itkMaskAccessorImageSource.cpp ) 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 ) diff --git a/code/io/itk/rttbITKImageMaskAccessorConverter.cpp b/code/io/itk/rttbITKImageMaskAccessorConverter.cpp index 4f0e80a..c777f42 100644 --- a/code/io/itk/rttbITKImageMaskAccessorConverter.cpp +++ b/code/io/itk/rttbITKImageMaskAccessorConverter.cpp @@ -1,126 +1,95 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) */ #include #include "rttbITKImageMaskAccessorConverter.h" #include "rttbInvalidDoseException.h" #include "rttbGeometricInfo.h" #include "itkImageRegionIterator.h" #include "rttbITKImageMaskAccessor.h" +#include "itkMaskAccessorImageSource.h" namespace rttb { namespace io { namespace itk { ITKImageMaskAccessorConverter::ITKImageMaskAccessorConverter(MaskAccessorPointer accessor) { setMaskAccessor(accessor); } bool ITKImageMaskAccessorConverter::process() { //Transfer GeometricInfo to ITK Properties core::GeometricInfo geoInfo = _maskAccessor->getGeometricInfo(); - ITKImageMaskAccessor::ITKMaskImageType::RegionType region; - ITKImageMaskAccessor::ITKMaskImageType::IndexType start = {{0, 0, 0}}; ITKImageMaskAccessor::ITKMaskImageType::SizeType size = {{geoInfo.getNumColumns(), geoInfo.getNumRows(), geoInfo.getNumSlices()}}; ITKImageMaskAccessor::ITKMaskImageType::SpacingType spacing; for (unsigned int i = 0; i < 3; ++i) { spacing[i] = geoInfo.getSpacing()[i]; } ITKImageMaskAccessor::ITKMaskImageType::PointType origin; for (unsigned int i = 0; i < 3; ++i) { origin[i] = geoInfo.getImagePositionPatient()[i]; } ITKImageMaskAccessor::ITKMaskImageType::DirectionType direction; OrientationMatrix OM = geoInfo.getOrientationMatrix(); for (unsigned int col = 0; col < 3; ++col) { for (unsigned int row = 0; row < 3; ++row) { direction(col, row) = OM(col, row); } } - //Create image, assign properties - region.SetSize(size); - region.SetIndex(start); - - _itkImage = ITKImageMaskAccessor::ITKMaskImageType::New(); - _itkImage->SetRegions(region); - _itkImage->SetSpacing(spacing); - _itkImage->SetDirection(direction); - _itkImage->SetOrigin(origin); - _itkImage->Allocate(); - - ::itk::ImageRegionIterator imageIterator(_itkImage, region); - VoxelGridID id = 0; - - //Transfer Mask values to itk image - //Large advantage: rttbVoxelGridId ordering is the same as itk ordering - while (!imageIterator.IsAtEnd()) - { - VoxelGridIndex3D aIndex; - if (_maskAccessor->getGeometricInfo().validID(id)) - { - rttb::core::MaskVoxel maskVoxel = core::MaskVoxel(id);; - _maskAccessor->getMaskAt(id, maskVoxel); - // Set the current pixel - imageIterator.Set(maskVoxel.getRelevantVolumeFraction()); - } - else - { - if (failsOnInvalidIDs()) - { - throw core::InvalidDoseException("invalid Mask id!"); - return false; - } - else - { - imageIterator.Set(_invalidDoseValue); - } - } + ::itk::MaskAccessorImageSource::Pointer imagesource = ::itk::MaskAccessorImageSource::New(); + + imagesource->SetSize(size); + imagesource->SetSpacing(spacing); + imagesource->SetDirection(direction); + imagesource->SetOrigin(origin); + imagesource->SetAccessor(_maskAccessor); + imagesource->SetFailsOnInvalidIDs(failsOnInvalidIDs()); + imagesource->SetInvalidMaskValue(_invalidDoseValue); + imagesource->Update(); + _itkImage = imagesource->GetOutput(); - ++imageIterator; - ++id; - } return true; } }//end namespace mask }//end namespace io }//end namespace rttb