diff --git a/Code/Algorithms/ITK/boxed/mapITKEuler3DMattesMIMultiResRegistrationAlgorithmTemplate.h b/Code/Algorithms/ITK/boxed/mapITKEuler3DMattesMIMultiResRegistrationAlgorithmTemplate.h index f24e1b7..c996c21 100644 --- a/Code/Algorithms/ITK/boxed/mapITKEuler3DMattesMIMultiResRegistrationAlgorithmTemplate.h +++ b/Code/Algorithms/ITK/boxed/mapITKEuler3DMattesMIMultiResRegistrationAlgorithmTemplate.h @@ -1,123 +1,127 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __MAP_ITK_EULER3D_MATTES_MI_MULTI_RES_REGISTRATION_ALGORITHM_TEMPLATE_H #define __MAP_ITK_EULER3D_MATTES_MI_MULTI_RES_REGISTRATION_ALGORITHM_TEMPLATE_H #include "mapITKInitializedMultiResImageRegistrationAlgorithm.h" #include "mapITKRegularStepGradientDescentOptimizer.h" #include "mapITKMattesMutualInformationImageToImageMetric.h" #include "mapITKEuler3DTransform.h" #include "mapITKLinearInterpolateImageFunction.h" #include "mapFixedImageToImageMetricPolicy.h" #include "mapFixedInterpolatorPolicy.h" #include "mapFixedSVNLOptimizerPolicy.h" #include "mapFixedTransformPolicy.h" #include "mapSealedImagePyramidesPolicy.h" #include "mapNoComponentInitializationPolicy.h" namespace map { namespace algorithm { namespace boxed { mapGenerateAlgorithmUIDPolicyMacro(DefaultEuler3DMattesMultiResRegistrationAlgorithmUIDPolicy, "de.dkfz.matchpoint", "Euler3DMattesMIMultiResRegistrationAlgorithm.default", "1.1.0", ""); template < class TMovingImage, class TTargetImage = TMovingImage, typename TUIDPolicy = DefaultEuler3DMattesMultiResRegistrationAlgorithmUIDPolicy, class TInterpolatorPolicy = SealedFixedInterpolatorPolicyMacro< ::itk::LinearInterpolateImageFunction >, class TPyramideInitializationPolicy = algorithm::itk::NoComponentInitializationPolicy > class ITKEuler3DMattesMIMultiResRegistrationAlgorithm : public algorithm::boxed::ITKInitializedMultiResImageRegistrationAlgorithm < TMovingImage, TTargetImage, TUIDPolicy, TInterpolatorPolicy, SealedFixedImageToImageMetricPolicyMacro< ::itk::MattesMutualInformationImageToImageMetric >, SealedFixedSVNLOptimizerPolicyMacro< ::itk::RegularStepGradientDescentOptimizer>, SealedFixedTransformPolicyMacro< ::itk::Euler3DTransform >, SealedImagePyramidesPolicy< ::itk::MultiResolutionPyramidImageFilter, ::itk::MultiResolutionPyramidImageFilter, TPyramideInitializationPolicy > > { public: typedef ITKEuler3DMattesMIMultiResRegistrationAlgorithm < TMovingImage, TTargetImage, TUIDPolicy, TInterpolatorPolicy, TPyramideInitializationPolicy > Self; typedef typename algorithm::boxed::ITKInitializedMultiResImageRegistrationAlgorithm < TMovingImage, TTargetImage, TUIDPolicy, TInterpolatorPolicy, SealedFixedImageToImageMetricPolicyMacro< ::itk::MattesMutualInformationImageToImageMetric >, SealedFixedSVNLOptimizerPolicyMacro< ::itk::RegularStepGradientDescentOptimizer >, SealedFixedTransformPolicyMacro< ::itk::Euler3DTransform >, SealedImagePyramidesPolicy< ::itk::MultiResolutionPyramidImageFilter, ::itk::MultiResolutionPyramidImageFilter, TPyramideInitializationPolicy > > Superclass; typedef ::itk::SmartPointer Pointer; typedef ::itk::SmartPointer ConstPointer; itkTypeMacro(ITKEuler3DMattesMIMultiResRegistrationAlgorithm, ITKMultiResImageRegistrationAlgorithm); mapNewAlgorithmMacro(Self); typedef ::itk::Array ParametersType; typedef typename Superclass::MetaPropertyType MetaPropertyType; typedef typename Superclass::MetaPropertyPointer MetaPropertyPointer; typedef typename Superclass::MetaPropertyNameType MetaPropertyNameType; typedef typename Superclass::MetaPropertyVectorType MetaPropertyVectorType; + using ScalesType = typename Superclass::ConcreteOptimizerType::ScalesType; + + using MovingImageType = TMovingImage; + using TargetImageType = TTargetImage; protected: ITKEuler3DMattesMIMultiResRegistrationAlgorithm(); virtual ~ITKEuler3DMattesMIMultiResRegistrationAlgorithm(); virtual void configureAlgorithm(); virtual void compileInfos(MetaPropertyVectorType& infos) const; virtual MetaPropertyPointer doGetProperty(const MetaPropertyNameType& name) const; virtual void doSetProperty(const MetaPropertyNameType& name, const MetaPropertyType* pProperty); virtual void doInterLevelSetup(); private: ITKEuler3DMattesMIMultiResRegistrationAlgorithm(const Self& source); //purposely not implemented void operator=(const Self&); //purposely not implemented }; } } } #ifndef MatchPoint_MANUAL_TPP #include "mapITKEuler3DMattesMIMultiResRegistrationAlgorithmTemplate.tpp" #endif #endif diff --git a/Code/Algorithms/ITK/boxed/mapITKEuler3DMattesMIMultiResRegistrationAlgorithmTemplate.tpp b/Code/Algorithms/ITK/boxed/mapITKEuler3DMattesMIMultiResRegistrationAlgorithmTemplate.tpp index 83669c3..3f1f9b0 100644 --- a/Code/Algorithms/ITK/boxed/mapITKEuler3DMattesMIMultiResRegistrationAlgorithmTemplate.tpp +++ b/Code/Algorithms/ITK/boxed/mapITKEuler3DMattesMIMultiResRegistrationAlgorithmTemplate.tpp @@ -1,328 +1,328 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __MAP_ITK_EULER3D_MATTES_MI_MULTI_RES_REGISTRATION_ALGORITHM_TEMPLATE_TPP #define __MAP_ITK_EULER3D_MATTES_MI_MULTI_RES_REGISTRATION_ALGORITHM_TEMPLATE_TPP #include "mapITKEuler3DMattesMIMultiResRegistrationAlgorithmTemplate.h" #include "mapMetaProperty.h" #include "mapMetaPropertyAccessor.h" #include "itkCenteredTransformInitializer.h" #include namespace map { namespace algorithm { namespace boxed { template < class TMovingImage, class TTargetImage, typename TUIDPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy > ITKEuler3DMattesMIMultiResRegistrationAlgorithm < TMovingImage, TTargetImage, TUIDPolicy, TInterpolatorPolicy, TPyramideInitializationPolicy >:: ITKEuler3DMattesMIMultiResRegistrationAlgorithm() { }; template < class TMovingImage, class TTargetImage, typename TUIDPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy > ITKEuler3DMattesMIMultiResRegistrationAlgorithm < TMovingImage, TTargetImage, TUIDPolicy, TInterpolatorPolicy, TPyramideInitializationPolicy >:: ~ITKEuler3DMattesMIMultiResRegistrationAlgorithm() { }; template < class TMovingImage, class TTargetImage, typename TUIDPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy > void ITKEuler3DMattesMIMultiResRegistrationAlgorithm < TMovingImage, TTargetImage, TUIDPolicy, TInterpolatorPolicy, TPyramideInitializationPolicy >:: configureAlgorithm() { Superclass::configureAlgorithm(); this->setResolutionLevels(3); - typename Superclass::ConcreteOptimizerType::ScalesType scales(6); + ScalesType scales(6); scales[0] = 1.0; scales[1] = 1.0; scales[2] = 1.0; scales[3] = 1.0 / 1000; scales[4] = 1.0 / 1000; scales[5] = 1.0 / 1000; this->getConcreteTransformModel()->SetIdentity(); this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetScales(scales); this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetMaximumStepLength(4.00); this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetMinimumStepLength(0.01); this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetNumberOfIterations(200); this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetRelaxationFactor(0.5); this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetGradientMagnitudeTolerance(1e-4); this->getConcreteMetricControl()->getConcreteMetric()->SetNumberOfHistogramBins(20); this->getConcreteMetricControl()->getConcreteMetric()->SetNumberOfSpatialSamples(20000); this->getConcreteMetricControl()->getConcreteMetric()->ReinitializeSeed(); this->getConcreteMetricControl()->getConcreteMetric()->UseExplicitPDFDerivativesOn(); }; template < class TMovingImage, class TTargetImage, typename TUIDPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy > void ITKEuler3DMattesMIMultiResRegistrationAlgorithm < TMovingImage, TTargetImage, TUIDPolicy, TInterpolatorPolicy, TPyramideInitializationPolicy >:: compileInfos(MetaPropertyVectorType& infos) const { Superclass::compileInfos(infos); typedef typename Superclass::OptimizerBaseType::OptimizerBaseType::ScalesType ScalesType; typedef typename Superclass::TransformBaseType::ParametersType ParametersType; #ifndef MAP_SEAL_ALGORITHMS infos.push_back(map::algorithm::MetaPropertyInfo::New("TransformParameters", typeid(ParametersType), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("Scales", typeid(ScalesType), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("MaximumStepLength", typeid(double), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("MinimumStepLength", typeid(double), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("RelaxationFactor", typeid(double), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("NumberOfIterations", typeid(unsigned long), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("GradientMagnitudeTolerance", typeid(double), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("NumberOfHistogramBins", typeid(unsigned long), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("NumberOfSpatialSamples", typeid(unsigned long), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("UseAllPixels", typeid(bool), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("ResolutionLevels", typeid(typename Superclass::ResolutionLevelCountType), true, true)); #endif }; template < class TMovingImage, class TTargetImage, typename TUIDPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy > typename ITKEuler3DMattesMIMultiResRegistrationAlgorithm < TMovingImage, TTargetImage, TUIDPolicy, TInterpolatorPolicy, TPyramideInitializationPolicy >::MetaPropertyPointer ITKEuler3DMattesMIMultiResRegistrationAlgorithm < TMovingImage, TTargetImage, TUIDPolicy, TInterpolatorPolicy, TPyramideInitializationPolicy >:: doGetProperty(const MetaPropertyNameType& name) const { MetaPropertyPointer spResult; typedef typename Superclass::OptimizerBaseType::OptimizerBaseType::ScalesType ScalesType; typedef typename Superclass::TransformBaseType::ParametersType ParametersType; if (name == "TransformParameters") { spResult = map::core::MetaProperty::New( this->getTransformInternal()->GetParameters()); } else if (name == "Scales") { spResult = map::core::MetaProperty::New(this->getConcreteITKOptimizer()->GetScales()); } else if (name == "MaximumStepLength") { spResult = map::core::MetaProperty::New( this->getConcreteITKOptimizer()->GetMaximumStepLength()); } else if (name == "MinimumStepLength") { spResult = map::core::MetaProperty::New( this->getConcreteITKOptimizer()->GetMinimumStepLength()); } else if (name == "RelaxationFactor") { spResult = map::core::MetaProperty::New( this->getConcreteITKOptimizer()->GetRelaxationFactor()); } else if (name == "NumberOfIterations") { spResult = map::core::MetaProperty::New( this->getConcreteITKOptimizer()->GetNumberOfIterations()); } else if (name == "GradientMagnitudeTolerance") { spResult = map::core::MetaProperty::New( this->getConcreteITKOptimizer()->GetGradientMagnitudeTolerance()); } else if (name == "NumberOfHistogramBins") { spResult = map::core::MetaProperty::New( this->getConcreteMetricControl()->getConcreteMetric()->GetNumberOfHistogramBins()); } else if (name == "NumberOfSpatialSamples") { spResult = map::core::MetaProperty::New( this->getConcreteMetricControl()->getConcreteMetric()->GetNumberOfFixedImageSamples()); } else if (name == "UseAllPixels") { spResult = map::core::MetaProperty::New( this->getConcreteMetricControl()->getConcreteMetric()->GetUseAllPixels()); } else if (name == "ResolutionLevels") { spResult = map::core::MetaProperty::New( this->getResolutionLevels()); } else { spResult = Superclass::doGetProperty(name); } return spResult; }; template < class TMovingImage, class TTargetImage, typename TUIDPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy > void ITKEuler3DMattesMIMultiResRegistrationAlgorithm < TMovingImage, TTargetImage, TUIDPolicy, TInterpolatorPolicy, TPyramideInitializationPolicy >:: doSetProperty(const MetaPropertyNameType& name, const MetaPropertyType* pProperty) { typedef typename Superclass::OptimizerBaseType::OptimizerBaseType::ScalesType ScalesType; typedef typename Superclass::TransformBaseType::ParametersType ParametersType; if (name == "TransformParameters") { ParametersType params; map::core::unwrapMetaProperty(pProperty, params); this->getTransformInternal()->SetParameters(params); } else if (name == "Scales") { ScalesType scales; map::core::unwrapMetaProperty(pProperty, scales); this->getConcreteITKOptimizer()->SetScales(scales); } else if (name == "MaximumStepLength") { double length; map::core::unwrapMetaProperty(pProperty, length); this->getConcreteITKOptimizer()->SetMaximumStepLength(length); } else if (name == "MinimumStepLength") { double length; map::core::unwrapMetaProperty(pProperty, length); this->getConcreteITKOptimizer()->SetMinimumStepLength(length); } else if (name == "RelaxationFactor") { double factor; map::core::unwrapMetaProperty(pProperty, factor); this->getConcreteITKOptimizer()->SetRelaxationFactor(factor); } else if (name == "NumberOfIterations") { unsigned long iterations; map::core::unwrapMetaProperty(pProperty, iterations); this->getConcreteITKOptimizer()->SetNumberOfIterations(iterations); } else if (name == "GradientMagnitudeTolerance") { double tolerance; map::core::unwrapMetaProperty(pProperty, tolerance); this->getConcreteITKOptimizer()->SetGradientMagnitudeTolerance(tolerance); } else if (name == "NumberOfHistogramBins") { unsigned long nr; map::core::unwrapMetaProperty(pProperty, nr); this->getConcreteMetricControl()->getConcreteMetric()->SetNumberOfHistogramBins(nr); } else if (name == "NumberOfSpatialSamples") { unsigned long nr; map::core::unwrapMetaProperty(pProperty, nr); this->getConcreteMetricControl()->getConcreteMetric()->SetNumberOfSpatialSamples(nr); } else if (name == "UseAllPixels") { bool useAll; map::core::unwrapMetaProperty(pProperty, useAll); this->getConcreteMetricControl()->getConcreteMetric()->SetUseAllPixels(useAll); } else if (name == "ResolutionLevels") { typename Superclass::ResolutionLevelCountType lvls; map::core::unwrapMetaProperty(pProperty, lvls); this->setResolutionLevels(lvls); } else { Superclass::doSetProperty(name, pProperty); } }; template < class TMovingImage, class TTargetImage, typename TUIDPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolic > void ITKEuler3DMattesMIMultiResRegistrationAlgorithm < TMovingImage, TTargetImage, TUIDPolicy, TInterpolatorPolicy, TPyramideInitializationPolic >:: doInterLevelSetup() { if (this->getCurrentLevel() > 0) { this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetMaximumStepLength( this->getConcreteOptimizerControl()->getConcreteOptimizer()->GetCurrentStepLength() * 2.0); this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetMinimumStepLength( this->getConcreteOptimizerControl()->getConcreteOptimizer()->GetMinimumStepLength() / 10.0); } }; } } } #endif diff --git a/Code/Algorithms/ITK/boxed/mapITKRigid3DMattesMIBoundingBoxRegistrationAlgorithmTemplate.h b/Code/Algorithms/ITK/boxed/mapITKRigid3DMattesMIBoundingBoxRegistrationAlgorithmTemplate.h index e467f1e..9253b14 100644 --- a/Code/Algorithms/ITK/boxed/mapITKRigid3DMattesMIBoundingBoxRegistrationAlgorithmTemplate.h +++ b/Code/Algorithms/ITK/boxed/mapITKRigid3DMattesMIBoundingBoxRegistrationAlgorithmTemplate.h @@ -1,98 +1,111 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __MAP_ITK_RIGID_MMI_BOUNDINGBOX_REGISTRATION_ALGORITHM_H #define __MAP_ITK_RIGID_MMI_BOUNDINGBOX_REGISTRATION_ALGORITHM_H #include "mapITKEuler3DMattesMIMultiResRegistrationAlgorithmTemplate.h" namespace map { namespace algorithm { namespace boxed { /** \class ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm * \ingroup Data_image MetaProperty Model_rigid Det_comp_iterative Det_stochastic Det_res_multi Dim_3D_3D Mod_multi PreInit_Geo * Algorithm is used for special cases where a head image should be registered onto a head/neck image (target image). It skips the lower part of * the target image if a preinitialization (via geometric center or centroid) is used, to establish a better initialization. By default initializes via geometric centers. */ template >, class TPyramideInitializationPolicy = algorithm::itk::NoComponentInitializationPolicy> class ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm : public map::algorithm::boxed::ITKEuler3DMattesMIMultiResRegistrationAlgorithm { public: typedef ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm Self; typedef ITKEuler3DMattesMIMultiResRegistrationAlgorithm Superclass; typedef ::itk::SmartPointer Pointer; typedef ::itk::SmartPointer ConstPointer; + typedef typename Superclass::MetaPropertyType MetaPropertyType; + typedef typename Superclass::MetaPropertyPointer MetaPropertyPointer; + typedef typename Superclass::MetaPropertyNameType MetaPropertyNameType; + typedef typename Superclass::MetaPropertyVectorType MetaPropertyVectorType; + typedef typename Superclass::ConcreteOptimizerType::ScalesType ScalesType; + + using MovingImageType = typename Superclass::MovingImageType; + using TargetImageType = typename Superclass::TargetImageType; + + using MaskRegistrationAlgorithmBaseType = MaskedRegistrationAlgorithmBase; + using MovingMaskBaseType = typename MaskRegistrationAlgorithmBaseType::MovingMaskBaseType; + using TargetMaskBaseType = typename MaskRegistrationAlgorithmBaseType::TargetMaskBaseType; + itkTypeMacro(ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm, ITKEuler3DMattesMIMultiResRegistrationAlgorithm); mapNewAlgorithmMacro(Self); mapSetMetaMacro(ActivateBoundingBox, bool); mapSetMetaMacro(ActivateMargin, bool); mapGetMetaMacro(ActivateBoundingBox, bool); mapGetMetaMacro(ActivateMargin, bool); protected: ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm(); virtual ~ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm(); void configureAlgorithm() override; void doInterLevelSetup() override; void prepPerpareInternalInputData() override; void prepSetInternalInputData() override; void compileInfos(MetaPropertyVectorType& infos) const override; MetaPropertyPointer doGetProperty(const MetaPropertyNameType& name) const override; void doSetProperty(const MetaPropertyNameType& name, const MetaPropertyType* pProperty) override; bool _ActivateBoundingBox; bool _ActivateMargin; /**Margins that should be used to dilate masks/bounding boxes in mm (per side). E.G. 3 mm margin in 1st dimension will make the bounding box bigger by 6 mm.*/ ::itk::FixedArray _margins; private: ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm(const Self& source); //purposely not implemented void operator=(const Self&); //purposely not implemented }; } } } #ifndef MatchPoint_MANUAL_TPP #include "mapITKRigid3DMattesMIBoundingBoxRegistrationAlgorithmTemplate.tpp" #endif #endif diff --git a/Code/Algorithms/ITK/boxed/mapITKRigid3DMattesMIBoundingBoxRegistrationAlgorithmTemplate.tpp b/Code/Algorithms/ITK/boxed/mapITKRigid3DMattesMIBoundingBoxRegistrationAlgorithmTemplate.tpp index a37f5f7..534b0d0 100644 --- a/Code/Algorithms/ITK/boxed/mapITKRigid3DMattesMIBoundingBoxRegistrationAlgorithmTemplate.tpp +++ b/Code/Algorithms/ITK/boxed/mapITKRigid3DMattesMIBoundingBoxRegistrationAlgorithmTemplate.tpp @@ -1,352 +1,352 @@ // ----------------------------------------------------------------------- // RAP - Registration Algoritm Portfolio // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rapCopyright.txt and/or notes within this file // // 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: 4933 $ (last changed revision) // @date $Date: 2013-09-05 17:19:45 +0200 (Do, 05 Sep 2013) $ (last change date) // @author $Author: floca $ (last changed by) // Subversion HeadURL: $HeadURL: http://sidt-hpc1/dkfz_repository/NotMeVisLab/SIDT/RAP/trunk/Algorithms/Diffusion/difRigid_MattesMI.cpp $ */ #include "mapDeploymentDLLHelper.h" #include "mapDiscreteElements.h" #include "mapITKRigid3DMattesMIBoundingBoxRegistrationAlgorithmTemplate.h" #include "mapConfigure.h" #include "itkRegionOfInterestImageFilter.h" #include "itkBinaryErodeImageFilter.h" #include "itkFlatStructuringElement.h" #include "itkImageMaskSpatialObject.h" namespace map { namespace algorithm { namespace boxed { template < class TImageType, class TIdentificationPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy> ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm:: ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm() : _ActivateBoundingBox(false), _ActivateMargin(false) { }; template < class TImageType, class TIdentificationPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy> ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm:: ~ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm() { }; template < class TImageType, class TIdentificationPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy> void ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm:: configureAlgorithm() { Superclass::configureAlgorithm(); this->setResolutionLevels(3); this->_preInitialize = true; this->_useCenterOfGravity = false; this->_ActivateBoundingBox = false; this->_ActivateMargin = false; this->_margins.Fill(0.0); //optimizer - ConcreteOptimizerType::ScalesType scales(6); + ScalesType scales(6); scales[0] = 10.0; scales[1] = 10.0; scales[2] = 10.0; scales[3] = 1.0 / 10000; scales[4] = 1.0 / 10000; scales[5] = 1.0 / 10000; this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetMaximumStepLength(3.00); this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetMinimumStepLength(0.5); this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetNumberOfIterations(200); this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetRelaxationFactor(0.8); this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetGradientMagnitudeTolerance(1e-4); //metric this->getConcreteMetricControl()->getConcreteMetric()->SetNumberOfHistogramBins(30); this->getConcreteMetricControl()->getConcreteMetric()->SetUseAllPixels(true); this->getConcreteMetricControl()->getConcreteMetric()->ReinitializeSeed(); this->getConcreteMetricControl()->getConcreteMetric()->UseExplicitPDFDerivativesOn(); } template < class TImageType, class TIdentificationPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy> void ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm:: doInterLevelSetup() { Superclass::doInterLevelSetup(); if (this->getCurrentLevel() != 0) { - getConcreteMetricControl()->getConcreteMetric()->SetUseAllPixels(false); + this->getConcreteMetricControl()->getConcreteMetric()->SetUseAllPixels(false); - OptimizerBaseType::SVNLOptimizerBaseType::ScalesType scales(6); + ScalesType scales(6); scales[0] = 1.0; scales[1] = 1.0; scales[2] = 1.0; scales[3] = 1.0 / 1000; scales[4] = 1.0 / 1000; scales[5] = 1.0 / 1000; - getConcreteOptimizerControl()->getConcreteOptimizer()->SetScales(scales); + this->getConcreteOptimizerControl()->getConcreteOptimizer()->SetScales(scales); unsigned int nrOfSmpl = ::itk::Math::Round (this->getMovingImage()->GetLargestPossibleRegion().GetNumberOfPixels() * 0.15); - getConcreteMetricControl()->getConcreteMetric()->SetNumberOfSpatialSamples(nrOfSmpl); + this->getConcreteMetricControl()->getConcreteMetric()->SetNumberOfSpatialSamples(nrOfSmpl); } }; template < class TImageType, class TIdentificationPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy> void ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm:: prepPerpareInternalInputData() { ::map::core::OStringStream os; ::map::core::OStringStream os2; if (this->_ActivateMargin) { using TargetImageSOType = ::itk::ImageSpatialObject; auto targetMask = this->getInternalTargetMask(); auto targetImageMask = dynamic_cast(targetMask.GetPointer()); if (targetImageMask) { //we have a mask -> add margin using TargetImageMaskImageType = typename TargetImageSOType::ImageType; auto spacing = this->getInternalTargetImage()->GetSpacing(); using StructuringElementType = ::itk::FlatStructuringElement; - StructuringElementType::RadiusType radius; + typename StructuringElementType::RadiusType radius; for (unsigned int i = 0; i < spacing.Size(); ++i) { radius[i] = ::itk::Math::Round(_margins[i] / spacing[i]); } StructuringElementType structuringElement = StructuringElementType::Ball(radius); //We don't know the mask lables, but we know that background is always 0. Therefore we erode //the background. using BinaryErodeImageFilterType = ::itk::BinaryErodeImageFilter; - BinaryErodeImageFilterType::Pointer erodeFilter = BinaryErodeImageFilterType::New(); + typename BinaryErodeImageFilterType::Pointer erodeFilter = BinaryErodeImageFilterType::New(); erodeFilter->SetInput(targetImageMask->GetImage()); erodeFilter->SetKernel(structuringElement); erodeFilter->SetErodeValue(0); erodeFilter->SetBackgroundValue(::itk::NumericTraits::max()); erodeFilter->Update(); auto dilatedImage = erodeFilter->GetOutput(); using TargetImageMaskSOType = ::itk::ImageMaskSpatialObject< TargetImageType::ImageDimension >; - TargetImageMaskSOType::Pointer newMask = TargetImageMaskSOType::New(); + typename TargetImageMaskSOType::Pointer newMask = TargetImageMaskSOType::New(); newMask->SetImage(dilatedImage); this->setInternalTargetMask(newMask); os << "Target mask: add margin with size (in mm): " << _margins << " (pixels: "<< radius<<")"; } else { os << "Target mask: is not image based. No margins added."; } this->InvokeEvent(::map::events::AlgorithmEvent(this, os.str())); using MovingImageSOType = ::itk::ImageSpatialObject; auto movingMask = this->getInternalMovingMask(); auto movingImageMask = dynamic_cast(movingMask.GetPointer()); if (movingImageMask) { //we have a mask -> add margin using MovingImageMaskImageType = typename MovingImageSOType::ImageType; auto spacing = this->getInternalMovingImage()->GetSpacing(); using StructuringElementType = ::itk::FlatStructuringElement; - StructuringElementType::RadiusType radius; + typename StructuringElementType::RadiusType radius; for (unsigned int i = 0; i < spacing.Size(); ++i) { radius[i] = ::itk::Math::Round(_margins[i] / spacing[i]); } StructuringElementType structuringElement = StructuringElementType::Ball(radius); //We don't know the mask lables, but we know that background is always 0. Therefore we erode //the background. using BinaryErodeImageFilterType = ::itk::BinaryErodeImageFilter; - BinaryErodeImageFilterType::Pointer erodeFilter = BinaryErodeImageFilterType::New(); + typename BinaryErodeImageFilterType::Pointer erodeFilter = BinaryErodeImageFilterType::New(); erodeFilter->SetInput(movingImageMask->GetImage()); erodeFilter->SetKernel(structuringElement); erodeFilter->SetErodeValue(0); erodeFilter->SetBackgroundValue(::itk::NumericTraits::max()); erodeFilter->Update(); auto dilatedImage = erodeFilter->GetOutput(); using MovingImageMaskSOType = ::itk::ImageMaskSpatialObject< MovingImageType::ImageDimension >; - MovingImageMaskSOType::Pointer newMask = MovingImageMaskSOType::New(); + typename MovingImageMaskSOType::Pointer newMask = MovingImageMaskSOType::New(); newMask->SetImage(dilatedImage); this->setInternalMovingMask(newMask); os << "Moving mask: add margin with size (in mm): " << _margins << " (pixels: " << radius << ")"; } else { os << "Moving mask: is not image based. No margins added."; } this->InvokeEvent(::map::events::AlgorithmEvent(this, os2.str())); } if (this->_ActivateBoundingBox) { this->_ActivateBoundingBox = true; } Superclass::prepPerpareInternalInputData(); } template < class TImageType, class TIdentificationPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy> void ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm:: prepSetInternalInputData() { Superclass::prepSetInternalInputData(); if (this->_ActivateBoundingBox) { //the internal moving and target images have already cropped to the bpunding box. This we only //have to deactivate the use of the mask. this->InvokeEvent(events::AlgorithmEvent(this, "Deactivate masks -> use bounding box instead.")); - MovingMaskBaseType::Pointer nullMMask; - TargetMaskBaseType::Pointer nullTMask; + typename MovingMaskBaseType::Pointer nullMMask; + typename TargetMaskBaseType::Pointer nullTMask; this->getMetricInternal()->getImageToImageMetric()->SetMovingImageMask(nullMMask); this->getMetricInternal()->getImageToImageMetric()->SetFixedImageMask(nullTMask); } } template < class TImageType, class TIdentificationPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy> void ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm:: compileInfos(MetaPropertyVectorType& infos) const { Superclass::compileInfos(infos); #ifndef MAP_SEAL_ALGORITHMS infos.push_back(map::algorithm::MetaPropertyInfo::New("ActivateBoundingBox", typeid(bool), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("ActivateMargins", typeid(bool), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("Margin_X", typeid(double), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("Margin_Y", typeid(double), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("Margin_Z", typeid(double), true, true)); #endif } template < class TImageType, class TIdentificationPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy> typename ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm::MetaPropertyPointer ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm:: doGetProperty(const MetaPropertyNameType& name) const { MetaPropertyPointer spResult; if (name == "ActivateBoundingBox") { spResult = map::core::MetaProperty::New(this->_ActivateBoundingBox); } else if (name == "ActivateMargins") { spResult = map::core::MetaProperty::New(this->_ActivateMargin); } else if (name == "Margin_X") { spResult = map::core::MetaProperty::New(this->_margins[0]); } else if (name == "Margin_Y") { spResult = map::core::MetaProperty::New(this->_margins[1]); } else if (name == "Margin_Z") { spResult = map::core::MetaProperty::New(this->_margins[2]); } else { spResult = Superclass::doGetProperty(name); } return spResult; }; template < class TImageType, class TIdentificationPolicy, class TInterpolatorPolicy, class TPyramideInitializationPolicy> void ITKRigid3DMattesMIBoundingBoxRegistrationAlgorithm:: doSetProperty(const MetaPropertyNameType& name, const MetaPropertyType* pProperty) { if (name == "ActivateBoundingBox") { bool activate; map::core::unwrapMetaProperty(pProperty, activate); this->_ActivateBoundingBox = activate; if (activate) { this->_CropInputImagesByMask = true; } } else if (name == "ActivateMargins") { bool activate; map::core::unwrapMetaProperty(pProperty, activate); this->_ActivateMargin = activate; } else if (name == "Margin_X") { double margin; map::core::unwrapMetaProperty(pProperty, margin); this->_margins[0] = margin; } else if (name == "Margin_Y") { double margin; map::core::unwrapMetaProperty(pProperty, margin); this->_margins[1] = margin; } else if (name == "Margin_Z") { double margin; map::core::unwrapMetaProperty(pProperty, margin); this->_margins[2] = margin; } else { Superclass::doSetProperty(name, pProperty); } }; } } -} \ No newline at end of file +}