diff --git a/Code/Algorithms/Common/boxed/mapDummyImageRegistrationAlgorithm.tpp b/Code/Algorithms/Common/boxed/mapDummyImageRegistrationAlgorithm.tpp index abf172f..e14f0ee 100644 --- a/Code/Algorithms/Common/boxed/mapDummyImageRegistrationAlgorithm.tpp +++ b/Code/Algorithms/Common/boxed/mapDummyImageRegistrationAlgorithm.tpp @@ -1,163 +1,163 @@ // ----------------------------------------------------------------------- // 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 __DUMMY_IMAGE_REGISTRATION_ALGORITHM_TPP #define __DUMMY_IMAGE_REGISTRATION_ALGORITHM_TPP #include #include "mapAlgorithmException.h" #include "mapPreCachedRegistrationKernel.h" #include "mapRegistrationManipulator.h" namespace map { namespace algorithm { template typename DummyImageRegistrationAlgorithm::FieldRepRequirement::Type DummyImageRegistrationAlgorithm:: isMovingRepresentationRequired() const { return FieldRepRequirement::No; }; template typename DummyImageRegistrationAlgorithm::FieldRepRequirement::Type DummyImageRegistrationAlgorithm:: isTargetRepresentationRequired() const { return FieldRepRequirement::No; }; template typename DummyImageRegistrationAlgorithm::AlgorithmType DummyImageRegistrationAlgorithm:: getAlgorithmType() const { return Superclass::ATAnalytic; }; template DummyImageRegistrationAlgorithm:: DummyImageRegistrationAlgorithm() { }; template DummyImageRegistrationAlgorithm:: ~DummyImageRegistrationAlgorithm() { }; template bool DummyImageRegistrationAlgorithm:: isReusable() const { return true; }; template void DummyImageRegistrationAlgorithm:: configureAlgorithm() { }; template typename DummyImageRegistrationAlgorithm::RegistrationPointer DummyImageRegistrationAlgorithm:: doGetRegistration() const { return _spFinalizedRegistration; }; template bool DummyImageRegistrationAlgorithm:: doDetermineRegistration() { - RegistrationPointer spResult = NULL; + RegistrationPointer spResult; typedef ::itk::AffineTransform< ::map::core::continuous::ScalarType, RegistrationType::MovingDimensions> TransformModelType; typename TransformModelType::Pointer spFinalTransformModel = TransformModelType::New(); spFinalTransformModel->SetIdentity(); //now build the inverse kernel (main kernel of a image based registration algorithm) typedef core::PreCachedRegistrationKernel InverseKernelType; typedef core::PreCachedRegistrationKernel DirectKernelType; typename InverseKernelType::Pointer spIKernel = InverseKernelType::New(); spIKernel->setTransformModel(spFinalTransformModel); typename DirectKernelType::Pointer spDKernel = DirectKernelType::New(); spDKernel->setTransformModel(spFinalTransformModel); //now create the registration and set the kernels spResult = RegistrationType::New(); core::RegistrationManipulator manipulator(spResult); manipulator.setDirectMapping(spDKernel); manipulator.setInverseMapping(spIKernel); manipulator.getTagValues()[tags::AlgorithmUID] = this->getUID()->toStr(); _spFinalizedRegistration = spResult; return true; }; template bool DummyImageRegistrationAlgorithm:: registrationIsOutdated() const { bool outdated = _spFinalizedRegistration.IsNull(); return outdated; }; template void DummyImageRegistrationAlgorithm:: PrintSelf(std::ostream& os, ::itk::Indent indent) const { Superclass::PrintSelf(os, indent); ImageRegistrationAlgorithmBase::PrintSelf(os, indent); }; } // end namespace algorithm } // end namespace map #endif diff --git a/Code/Algorithms/ITK/include/mapITKClosedFormRegistrationAlgorithm.tpp b/Code/Algorithms/ITK/include/mapITKClosedFormRegistrationAlgorithm.tpp index 8ad3ece..0bdeaf9 100644 --- a/Code/Algorithms/ITK/include/mapITKClosedFormRegistrationAlgorithm.tpp +++ b/Code/Algorithms/ITK/include/mapITKClosedFormRegistrationAlgorithm.tpp @@ -1,261 +1,261 @@ // ----------------------------------------------------------------------- // 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 __ITK_CLOSED_FORM_REGISTRATION_ALGORITHM_TPP #define __ITK_CLOSED_FORM_REGISTRATION_ALGORITHM_TPP #include "mapAlgorithmException.h" #include "mapPreCachedRegistrationKernel.h" #include "mapInverseRegistrationKernelGenerator.h" #include "mapRegistrationManipulator.h" #include "mapAlgorithmWrapperEvent.h" namespace map { namespace algorithm { namespace itk { template bool ITKClosedFormRegistrationAlgorithm:: isReusable() const { return true; }; template typename ITKClosedFormRegistrationAlgorithm::FieldRepRequirement::Type ITKClosedFormRegistrationAlgorithm:: isMovingRepresentationRequired() const { return FieldRepRequirement::No; }; template typename ITKClosedFormRegistrationAlgorithm::FieldRepRequirement::Type ITKClosedFormRegistrationAlgorithm:: isTargetRepresentationRequired() const { typename TransformModelType::InverseTransformBasePointer spInverseModel = this->_spTransform->GetInverseTransform(); if (spInverseModel.IsNotNull()) { // you can invert it thus no rep is needed return FieldRepRequirement::No; } else { return FieldRepRequirement::Unkown; } }; template ITKClosedFormRegistrationAlgorithm:: ITKClosedFormRegistrationAlgorithm() { }; template ITKClosedFormRegistrationAlgorithm:: ~ITKClosedFormRegistrationAlgorithm() { }; template typename ITKClosedFormRegistrationAlgorithm::AlgorithmType ITKClosedFormRegistrationAlgorithm:: getAlgorithmType() const { return Superclass::ATAnalytic; }; template void ITKClosedFormRegistrationAlgorithm:: configureAlgorithm() { //default implementation does nothing. }; template bool ITKClosedFormRegistrationAlgorithm:: doDetermineRegistration() { bool resultAvailable = true; this->InvokeEvent(::map::events::InitializingAlgorithmEvent()); if (!this->getMovingPointSet()) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; no moving point set."); } if (!this->getTargetPointSet()) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; no target point set."); } //create method this->_internalSolver = InternalSolverMethodType::New(); this->_spTransform = TransformModelType::New(); //assemble registration components this->InvokeEvent(::map::events::AlgorithmEvent(this, "Initializing solver.")); this->_internalSolver->SetTransform(_spTransform); //Connect point sets this->InvokeEvent(::map::events::AlgorithmEvent(this, "Connect point sets to itk registration method.")); typename InternalSolverMethodType::LandmarkPointContainer mLm; typename InternalSolverMethodType::LandmarkPointContainer tLm; convertPointSetToLandmarks(this->getMovingPointSet().GetPointer(), mLm); convertPointSetToLandmarks(this->getTargetPointSet().GetPointer(), tLm); this->_internalSolver->SetFixedLandmarks(tLm); this->_internalSolver->SetMovingLandmarks(mLm); this->InvokeEvent(::map::events::StartingAlgorithmEvent()); this->_internalSolver->InitializeTransform(); this->InvokeEvent(::map::events::StoppedAlgorithmEvent()); this->finalizeAlgorithm(); this->InvokeEvent(::map::events::FinalizedAlgorithmEvent()); return resultAvailable; }; template void ITKClosedFormRegistrationAlgorithm:: finalizeAlgorithm() { - RegistrationPointer spResult = NULL; + RegistrationPointer spResult; if (!_spTransform) { mapExceptionMacro(AlgorithmException, << "Error. Cannot determine final registration. No transform model present on internal level (getTransformInternal()). Please ensure proper setup of algorithm."); } //clone the transform model typename TransformModelType::Pointer spFinalTransformModel = dynamic_cast(_spTransform->Clone().GetPointer()); if (spFinalTransformModel.IsNull()) { std::ostringstream modelStrm; _spTransform->Print(modelStrm); mapExceptionMacro(AlgorithmException, << "Error. Cannot determine final registration. Unable to clone transform model. Current model: " < InverseKernelType; typename InverseKernelType::Pointer spIKernel = InverseKernelType::New(); spIKernel->setTransformModel(spFinalTransformModel); //now build the direct kernel via inversion of the inverse kernel typedef core::InverseRegistrationKernelGenerator GeneratorType; typename GeneratorType::Pointer spGenerator = GeneratorType::New(); typedef typename GeneratorType::InverseKernelBaseType DirectKernelType; typename DirectKernelType::Pointer spDKernel = spGenerator->generateInverse(* (spIKernel.GetPointer()), this->getMovingRepresentation()); if (spDKernel.IsNull()) { mapExceptionMacro(AlgorithmException, << "Error. Cannot determine direct mapping kernel of final registration. Current inverse kernel: " << spIKernel); } //now create the registration an set the kernels spResult = RegistrationType::New(); ::map::core::RegistrationManipulator manipulator(spResult); manipulator.setDirectMapping(spDKernel); manipulator.setInverseMapping(spIKernel); manipulator.getTagValues()[tags::AlgorithmUID] = this->getUID()->toStr(); _spFinalizedRegistration = spResult; }; template typename ITKClosedFormRegistrationAlgorithm::RegistrationPointer ITKClosedFormRegistrationAlgorithm:: doGetRegistration() const { return _spFinalizedRegistration; }; template bool ITKClosedFormRegistrationAlgorithm:: registrationIsOutdated() const { bool outdated = _spFinalizedRegistration.IsNull(); if (_spFinalizedRegistration.IsNotNull()) { if (!outdated) { //check if the inputs have been changed outdated = _spFinalizedRegistration->GetMTime() < this->getMovingPointSetMTime(); } if (!outdated) { //check if the inputs have been changed outdated = _spFinalizedRegistration->GetMTime() < this->getTargetPointSetMTime(); } } return outdated; }; template void ITKClosedFormRegistrationAlgorithm:: PrintSelf(std::ostream& os, ::itk::Indent indent) const { Superclass::PrintSelf(os, indent); PointSetRegistrationAlgorithmBase::PrintSelf(os, indent); os << indent << "Finalized registration: " << _spFinalizedRegistration << std::endl; }; } // end namespace itk } // end namespace algorithm } // end namespace map #endif diff --git a/Code/Algorithms/ITK/include/mapITKLandmarkKernelRegistrationAlgorithm.tpp b/Code/Algorithms/ITK/include/mapITKLandmarkKernelRegistrationAlgorithm.tpp index c11e404..40f842b 100644 --- a/Code/Algorithms/ITK/include/mapITKLandmarkKernelRegistrationAlgorithm.tpp +++ b/Code/Algorithms/ITK/include/mapITKLandmarkKernelRegistrationAlgorithm.tpp @@ -1,263 +1,263 @@ // ----------------------------------------------------------------------- // 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 __ITK_LANDMARK_KERNEL_REGISTRATION_ALGORITHM_TPP #define __ITK_LANDMARK_KERNEL_REGISTRATION_ALGORITHM_TPP #include "mapAlgorithmException.h" #include "mapPreCachedRegistrationKernel.h" #include "mapInverseRegistrationKernelGenerator.h" #include "mapRegistrationManipulator.h" #include "mapAlgorithmWrapperEvent.h" #include "itkKernelTransform.h" namespace map { namespace algorithm { namespace itk { template typename ITKLandmarkKernelRegistrationAlgorithm::FieldRepRequirement::Type ITKLandmarkKernelRegistrationAlgorithm:: isMovingRepresentationRequired() const { if (this->m_GenerateField) { return FieldRepRequirement::Yes; } else { return FieldRepRequirement::No; } }; template typename ITKLandmarkKernelRegistrationAlgorithm::FieldRepRequirement::Type ITKLandmarkKernelRegistrationAlgorithm:: isTargetRepresentationRequired() const { return FieldRepRequirement::Yes; }; template ITKLandmarkKernelRegistrationAlgorithm:: ITKLandmarkKernelRegistrationAlgorithm() { m_Stiffness = 0.01; m_GenerateField = false; }; template ITKLandmarkKernelRegistrationAlgorithm:: ~ITKLandmarkKernelRegistrationAlgorithm() { }; template typename ITKLandmarkKernelRegistrationAlgorithm::AlgorithmType ITKLandmarkKernelRegistrationAlgorithm:: getAlgorithmType() const { return Superclass::ATAnalytic; }; template bool ITKLandmarkKernelRegistrationAlgorithm:: isReusable() const { return true; }; template void ITKLandmarkKernelRegistrationAlgorithm:: configureAlgorithm() { }; template bool ITKLandmarkKernelRegistrationAlgorithm:: doDetermineRegistration() { bool resultAvailable = true; this->InvokeEvent(::map::events::InitializingAlgorithmEvent()); if (!this->getMovingPointSet()) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; no moving point set."); } if (!this->getTargetPointSet()) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; no target point set."); } this->_spFinalizedRegistration = NULL; //create method this->_spTransform = TransformModelType::New(); //assemble registration components this->InvokeEvent(::map::events::AlgorithmEvent(this, "Initializing kernel trasform.")); this->InvokeEvent(::map::events::StartingAlgorithmEvent()); _spTransform->SetStiffness(this->m_Stiffness); typedef typename TITKTransform::PointSetPointer InternalPointSetPointer; InternalPointSetPointer internalTargetPS; InternalPointSetPointer internalMovingPS; convertPointSetToKernelPointSet(this->getTargetPointSet(), internalTargetPS); convertPointSetToKernelPointSet(this->getMovingPointSet(), internalMovingPS); _spTransform->SetTargetLandmarks(internalTargetPS); _spTransform->SetSourceLandmarks(internalMovingPS); _spTransform->UpdateParameters(); this->InvokeEvent(::map::events::StoppedAlgorithmEvent()); this->finalizeAlgorithm(); this->InvokeEvent(::map::events::FinalizedAlgorithmEvent()); return resultAvailable; }; template void ITKLandmarkKernelRegistrationAlgorithm:: finalizeAlgorithm() { - RegistrationPointer spResult = NULL; + RegistrationPointer spResult; if (!_spTransform) { mapExceptionMacro(AlgorithmException, << "Error. Cannot determine final registration. No transform model present on internal level (getTransformInternal()). Please ensure proper setup of algorithm."); } //clone the transform model typename TransformModelType::Pointer spFinalTransformModel = _spTransform->Clone(); if (spFinalTransformModel.IsNull()) { std::ostringstream modelStrm; _spTransform->Print(modelStrm); mapExceptionMacro(AlgorithmException, << "Error. Cannot determine final registration. Unable to clone transform model. Current model: " << modelStrm.str()); } //now build the inverse kernel (main kernel of a closed form based registration algorithm using itk::LandmarkInitializer) typedef core::PreCachedRegistrationKernel InverseKernelType; typename InverseKernelType::Pointer spIKernel = InverseKernelType::New(); spIKernel->setTransformModel(spFinalTransformModel); typedef core::NullRegistrationKernel DirectKernelType; typename DirectKernelType::Pointer spDKernel = DirectKernelType::New(); //now create the registration an set the kernels spResult = RegistrationType::New(); ::map::core::RegistrationManipulator manipulator(spResult); manipulator.setDirectMapping(spDKernel); manipulator.setInverseMapping(spIKernel); manipulator.getTagValues()[tags::AlgorithmUID] = this->getUID()->toStr(); _spFinalizedRegistration = spResult; }; template typename ITKLandmarkKernelRegistrationAlgorithm::RegistrationPointer ITKLandmarkKernelRegistrationAlgorithm:: doGetRegistration() const { return _spFinalizedRegistration; }; template bool ITKLandmarkKernelRegistrationAlgorithm:: registrationIsOutdated() const { bool outdated = _spFinalizedRegistration.IsNull(); if (_spFinalizedRegistration.IsNotNull()) { if (!outdated) { //check if the inputs have been changed outdated = _spFinalizedRegistration->GetMTime() < this->getMovingPointSetMTime(); } if (!outdated) { //check if the inputs have been changed outdated = _spFinalizedRegistration->GetMTime() != this->getTargetPointSetMTime(); } } return outdated; }; template void ITKLandmarkKernelRegistrationAlgorithm:: PrintSelf(std::ostream& os, ::itk::Indent indent) const { Superclass::PrintSelf(os, indent); PointSetRegistrationAlgorithmBase::PrintSelf(os, indent); os << indent << "Finalized registration: " << _spFinalizedRegistration << std::endl; }; template void ITKLandmarkKernelRegistrationAlgorithm:: convertPointSetToKernelPointSet(const TPointSet* ps, typename TITKTransform::PointSetPointer& kernelPS) { kernelPS = TITKTransform::PointSetType::New(); typename TITKTransform::PointSetType::PointsContainer* pPoints = kernelPS->GetPoints(); pPoints->insert(pPoints->begin(), ps->GetPoints()->begin(), ps->GetPoints()->end()); }; } // end namespace itk } // end namespace algorithm } // end namespace map #endif diff --git a/Code/Algorithms/ITK/include/mapITKPDEDeformableRegistrationAlgorithmBase.tpp b/Code/Algorithms/ITK/include/mapITKPDEDeformableRegistrationAlgorithmBase.tpp index 2c6e4d2..1cc893f 100644 --- a/Code/Algorithms/ITK/include/mapITKPDEDeformableRegistrationAlgorithmBase.tpp +++ b/Code/Algorithms/ITK/include/mapITKPDEDeformableRegistrationAlgorithmBase.tpp @@ -1,696 +1,696 @@ // ----------------------------------------------------------------------- // 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 __ITK_PDE_DEFORMABLE_REGISTRATION_ALGORITHM_BASE_TPP #define __ITK_PDE_DEFORMABLE_REGISTRATION_ALGORITHM_BASE_TPP #include #include "mapAlgorithmException.h" #include "mapPreCachedRegistrationKernel.h" #include "mapInverseRegistrationKernelGenerator.h" #include "mapRegistrationManipulator.h" #include "mapAlgorithmWrapperEvent.h" #include "mapMetaProperty.h" namespace map { namespace algorithm { namespace itk { template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> typename ITKPDEDeformableRegistrationAlgorithmBase::FieldRepRequirement::Type ITKPDEDeformableRegistrationAlgorithmBase:: isMovingRepresentationRequired() const { return FieldRepRequirement::No; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> typename ITKPDEDeformableRegistrationAlgorithmBase::FieldRepRequirement::Type ITKPDEDeformableRegistrationAlgorithmBase:: isTargetRepresentationRequired() const { return FieldRepRequirement::No; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> bool ITKPDEDeformableRegistrationAlgorithmBase:: isStoppable() const { return true; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> typename ITKPDEDeformableRegistrationAlgorithmBase::IterationCountType ITKPDEDeformableRegistrationAlgorithmBase:: doGetCurrentIteration() const { return this->_currentIterationCount; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> typename ITKPDEDeformableRegistrationAlgorithmBase::IterationCountType ITKPDEDeformableRegistrationAlgorithmBase:: doGetMaxIterations() const { IterationCountType result = 0; MetaPropertyPointer prop = this->getProperty("NumberOfIterations"); map::core::unwrapMetaProperty(prop, result); return result; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> bool ITKPDEDeformableRegistrationAlgorithmBase:: hasIterationCount() const { return true; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> bool ITKPDEDeformableRegistrationAlgorithmBase:: hasMaxIterationCount() const { bool result = _internalRegistrationMethod.IsNotNull(); return result; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> bool ITKPDEDeformableRegistrationAlgorithmBase:: hasCurrentOptimizerValue() const { bool result = _internalRegistrationMethod.IsNotNull(); return result; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> bool ITKPDEDeformableRegistrationAlgorithmBase:: isReusable() const { return true; } template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> ITKPDEDeformableRegistrationAlgorithmBase:: ITKPDEDeformableRegistrationAlgorithmBase() : _currentIterationCount(0), _matchHistograms(true), _thresholdAtMeanIntensity(true), _numberOfHistogramLevels(1024), _numberOfHistogramMatchPoints(7) { _spInternalMovingImage = NULL; _spInternalTargetImage = NULL; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> ITKPDEDeformableRegistrationAlgorithmBase:: ~ITKPDEDeformableRegistrationAlgorithmBase() { }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: configureAlgorithm() { this->_internalRegistrationMethod = InternalRegistrationMethodType::New(); } template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> typename ITKPDEDeformableRegistrationAlgorithmBase::InterimRegistrationPointer ITKPDEDeformableRegistrationAlgorithmBase:: determineInterimRegistration(const MovingRepresentationDescriptorType* pMovingRepresentation, const TargetRepresentationDescriptorType* pTargetRepresentation) const { - InterimRegistrationPointer spResult = NULL; + InterimRegistrationPointer spResult; if (this->_currentIterationCount > 0) { //now build the inverse kernel (main kernel of a image based registration algorithm) typedef typename ::map::core::PreCachedRegistrationKernel InverseKernelType; typename FieldTransformType::Pointer transform = FieldTransformType::New(); transform->SetDisplacementField(_internalRegistrationMethod->GetDisplacementField()); typename InverseKernelType::Pointer spIKernel = InverseKernelType::New(); spIKernel->setTransformModel(transform); //now build the direct kernel via inversion of the inverse kernel typedef core::InverseRegistrationKernelGenerator GeneratorType; typename GeneratorType::Pointer spGenerator = GeneratorType::New(); typedef typename GeneratorType::InverseKernelBaseType DirectKernelType; typename DirectKernelType::Pointer spDKernel = spGenerator->generateInverse(* (spIKernel.GetPointer()), pMovingRepresentation); if (spDKernel.IsNull()) { mapExceptionMacro(AlgorithmException, << "Error. Cannot determine direct mapping kernel of interim registration. Current inverse kernel: " << spIKernel); } //now create the registration an set the kernels spResult = InterimRegistrationType::New(); ::map::core::RegistrationManipulator manipulator(spResult); manipulator.setDirectMapping(spDKernel); manipulator.setInverseMapping(spIKernel); manipulator.getTagValues()[tags::AlgorithmUID] = this->getUID()->toStr(); } return spResult; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: prepCheckValidity() { if (!this->getMovingImage()) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; no moving image."); } if (!this->getTargetImage()) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; no target image."); } if (this->getTargetRepresentation()) { typename TargetRepresentationDescriptorType::Pointer targetImageRep = map::core::createFieldRepresentation(*(this->getTargetImage())); if (!(*(this->getTargetRepresentation()) == (*targetImageRep))) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; user defined target representation does not match the target image."); } } if (this->getMovingRepresentation()) { typename MovingRepresentationDescriptorType::Pointer movingImageRep = map::core::createFieldRepresentation(*(this->getMovingImage())); if (!(*(this->getMovingRepresentation()) == (*movingImageRep))) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; user defined moving representation does not match the moving image."); } } } template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: prepPrepareSubComponents() { } template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: prepAssembleSubComponents() { } template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: prepPerpareInternalInputData() { if (this->_matchHistograms) { map::core::OStringStream strm; strm << "Match histograms of images. Threshold: " << this->_thresholdAtMeanIntensity << "; histogram levels: " << this->_numberOfHistogramLevels << "; match points: " << this->_numberOfHistogramMatchPoints; this->InvokeEvent(::map::events::AlgorithmEvent(this, strm.str())); typedef typename ::itk::HistogramMatchingImageFilter< TImageType, TImageType> MatchingFilterType; typename MatchingFilterType::Pointer matcher = MatchingFilterType::New(); matcher->SetInput(this->_spInternalMovingImage); matcher->SetReferenceImage(this->_spInternalTargetImage); matcher->SetNumberOfHistogramLevels(this->_numberOfHistogramLevels); matcher->SetNumberOfMatchPoints(this->_numberOfHistogramMatchPoints); matcher->SetThresholdAtMeanIntensity(this->_thresholdAtMeanIntensity); matcher->Update(); this->_spInternalMovingImage = matcher->GetOutput(); } } template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: prepInitializeTransformation() { }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: prepFinalizePreparation() { }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: prepareAlgorithm() { this->prepCheckValidity(); this->_currentIterationCount = 0; this->_spFinalizedRegistration = NULL; //create method this->_internalRegistrationMethod = InternalRegistrationMethodType::New(); //initialize registration components this->InvokeEvent(::map::events::AlgorithmEvent(this, "Transfer cached MetaProperties.")); this->configureAlgorithmByMetaProperties(); //initialize registration components this->InvokeEvent(::map::events::AlgorithmEvent(this, "Initializing registration components.")); this->prepPrepareSubComponents(); //assemble registration components this->InvokeEvent(::map::events::AlgorithmEvent(this, "Initializing PDE deformable registration method.")); this->prepAssembleSubComponents(); this->InvokeEvent(::map::events::AlgorithmEvent(this, "Initializing/Preparing input data.")); _spInternalMovingImage = this->getMovingImage(); _spInternalTargetImage = this->getTargetImage(); this->prepPerpareInternalInputData(); this->InvokeEvent(::map::events::AlgorithmEvent(this, "Passing input data to internal algorithm.")); this->prepSetInternalInputData(); //possibility to initialize internal registration method after assembly this->prepInitializeTransformation(); //initialize registration components after assembly this->InvokeEvent(::map::events::AlgorithmEvent(this, "Finalizing initialization...")); this->prepFinalizePreparation(); //Register observers typename ::itk::MemberCommand::Pointer spCommand = ::itk::MemberCommand::New(); spCommand->SetCallbackFunction(this, &Self::onIterationEvent); this->_internalRegistrationMethod->AddObserver(::itk::IterationEvent(), spCommand); spCommand = ::itk::MemberCommand::New(); spCommand->SetCallbackFunction(this, &Self::onGeneralRegistrationMethodEvent); this->_internalRegistrationMethod->AddObserver(::itk::AnyEvent(), spCommand); }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: finalizeAlgorithm() { - RegistrationPointer spResult = NULL; + RegistrationPointer spResult; //now build the inverse kernel (main kernel of a image based registration algorithm) typedef typename ::map::core::PreCachedRegistrationKernel InverseKernelType; typename InverseKernelType::Pointer spIKernel = InverseKernelType::New(); typename FieldTransformType::Pointer transform = FieldTransformType::New(); transform->SetDisplacementField(this->getFinalDisplacementField()); spIKernel->setTransformModel(transform); //now build the direct kernel via inversion of the inverse kernel typedef core::InverseRegistrationKernelGenerator GeneratorType; typename GeneratorType::Pointer spGenerator = GeneratorType::New(); typedef typename GeneratorType::InverseKernelBaseType DirectKernelType; typename MovingRepresentationDescriptorType::ConstPointer movingImageRep = this->getMovingRepresentation(); if (movingImageRep.IsNull()) { movingImageRep = map::core::createFieldRepresentation(*(this->getMovingImage())); } typename DirectKernelType::Pointer spDKernel = spGenerator->generateInverse(* (spIKernel.GetPointer()), movingImageRep); if (spDKernel.IsNull()) { mapExceptionMacro(AlgorithmException, << "Error. Cannot determine direct mapping kernel of final registration. Current inverse kernel: " << spIKernel); } //now create the registration an set the kernels spResult = RegistrationType::New(); ::map::core::RegistrationManipulator manipulator(spResult); manipulator.setDirectMapping(spDKernel); manipulator.setInverseMapping(spIKernel); manipulator.getTagValues()[tags::AlgorithmUID] = this->getUID()->toStr(); //ensure that settings changed to the registration determination process are reseted to default this->configureAlgorithm(); //store the final results _spFinalizedRegistration = spResult; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> typename ITKPDEDeformableRegistrationAlgorithmBase::RegistrationPointer ITKPDEDeformableRegistrationAlgorithmBase:: doGetRegistration() const { return _spFinalizedRegistration; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: onIterationEvent(::itk::Object* caller, const ::itk::EventObject& eventObject) { ::map::core::OStringStream os; bool hasCurrentValue = this->hasCurrentOptimizerValue(); OptimizerMeasureType currentValue = this->getCurrentOptimizerValue(); this->_currentIterationLock.Lock(); ++_currentIterationCount; os << "Iteration #" << _currentIterationCount << "; metric value: "; if (hasCurrentValue && currentValue.size() > 0) { os << currentValue[0]; } else { os << "unkown"; } os << "; RMS error change: " << this->_internalRegistrationMethod->GetRMSChange(); this->_currentIterationLock.Unlock(); this->InvokeEvent(::map::events::AlgorithmIterationEvent(this, os.str())); }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: onGeneralRegistrationMethodEvent(::itk::Object* caller, const ::itk::EventObject& eventObject) { ::map::events::AlgorithmWrapperEvent wrappedEvent(eventObject, caller, "internal registration method event"); this->InvokeEvent(wrappedEvent); }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> bool ITKPDEDeformableRegistrationAlgorithmBase:: registrationIsOutdated() const { bool outdated = _spFinalizedRegistration.IsNull(); if (_spFinalizedRegistration.IsNotNull()) { if (!outdated) { outdated = _spFinalizedRegistration->GetMTime() < MetaPropertyAlgorithmBase::GetMTime(); } if (!outdated) { //check if the inputs have been changed outdated = this->_spInternalMovingImage->GetMTime() < this->getMovingImage()->GetMTime(); } if (!outdated) { //check if the inputs have been changed outdated = this->_spInternalTargetImage->GetMTime() < this->getTargetImage()->GetMTime(); } } return outdated; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> typename ITKPDEDeformableRegistrationAlgorithmBase::OptimizerMeasureType ITKPDEDeformableRegistrationAlgorithmBase:: doGetCurrentOptimizerValue() const { OptimizerMeasureType result; if (this->_internalRegistrationMethod.IsNotNull()) { result.push_back(this->_internalRegistrationMethod->GetMetric()); } return result; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> typename ITKPDEDeformableRegistrationAlgorithmBase::InternalRegistrationMethodType& ITKPDEDeformableRegistrationAlgorithmBase:: getInternalRegistrationMethod() { return *(this->_internalRegistrationMethod.GetPointer()); }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: PrintSelf(std::ostream& os, ::itk::Indent indent) const { Superclass::PrintSelf(os, indent); ImageRegistrationAlgorithmBase::PrintSelf(os, indent); os << indent << "Current itertation count: " << _currentIterationCount << std::endl; os << indent << "Finalized registration: " << _spFinalizedRegistration << std::endl; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: compileInfos(MetaPropertyVectorType& infos) const { #ifndef MAP_SEAL_ALGORITHMS infos.push_back(map::algorithm::MetaPropertyInfo::New("MatchHistograms", typeid(bool), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("ThresholdAtMeanIntensity", typeid(bool), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("NumberOfHistogramLevels", typeid(unsigned int), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("NumberOfHistogramMatchPoints", typeid(unsigned int), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("NumberOfIterations", typeid(unsigned long), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("MaximumKernelWidth", typeid(unsigned int), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("MaximumKernelError", typeid(double), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("SmoothDisplacementField", typeid(bool), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("DisplacementFieldStandardDeviations", typeid(double), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("SmoothUpdateField", typeid(bool), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("UpdateFieldStandardDeviations", typeid(double), true, true)); #endif }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> typename ITKPDEDeformableRegistrationAlgorithmBase::MetaPropertyPointer ITKPDEDeformableRegistrationAlgorithmBase:: doGetProperty(const MetaPropertyNameType& name) const { MetaPropertyPointer spResult; if (name == "MatchHistograms") { spResult = map::core::MetaProperty::New(this->_matchHistograms); } else if (name == "ThresholdAtMeanIntensity") { spResult = map::core::MetaProperty::New(this->_thresholdAtMeanIntensity); } else if (name == "NumberOfHistogramLevels") { spResult = map::core::MetaProperty::New(this->_numberOfHistogramLevels); } else if (name == "NumberOfHistogramMatchPoints") { spResult = map::core::MetaProperty::New(this->_numberOfHistogramMatchPoints); } else if (name == "NumberOfIterations") { spResult = map::core::MetaProperty::New(static_cast (this->_internalRegistrationMethod->GetNumberOfIterations())); } else if (name == "MaximumKernelWidth") { spResult = map::core::MetaProperty::New(static_cast (this->_internalRegistrationMethod->GetMaximumKernelWidth())); } else if (name == "MaximumKernelError") { spResult = map::core::MetaProperty::New(static_cast (this->_internalRegistrationMethod->GetMaximumError())); } else if (name == "SmoothDisplacementField") { spResult = map::core::MetaProperty::New( this->_internalRegistrationMethod->GetSmoothDisplacementField()); } else if (name == "DisplacementFieldStandardDeviations") { spResult = map::core::MetaProperty::New(static_cast(( this->_internalRegistrationMethod->GetStandardDeviations())[0])); } else if (name == "SmoothUpdateField") { spResult = map::core::MetaProperty::New( this->_internalRegistrationMethod->GetSmoothUpdateField()); } else if (name == "UpdateFieldStandardDeviations") { spResult = map::core::MetaProperty::New(static_cast(( this->_internalRegistrationMethod->GetUpdateFieldStandardDeviations())[0])); } else { assert(false); //any other property name should have been excluded by the calling function. } return spResult; }; template < class TImageType, class TIdentificationPolicy, class TDisplacementField, class TInternalRegistrationFilter> void ITKPDEDeformableRegistrationAlgorithmBase:: doSetProperty(const MetaPropertyNameType& name, const MetaPropertyType* pProperty) { if (name == "MatchHistograms") { bool match; map::core::unwrapMetaProperty(pProperty, match); this->_matchHistograms = match; } else if (name == "ThresholdAtMeanIntensity") { bool thresholdOn; map::core::unwrapMetaProperty(pProperty, thresholdOn); this->_thresholdAtMeanIntensity = thresholdOn; } else if (name == "NumberOfHistogramLevels") { unsigned int value; map::core::unwrapMetaProperty(pProperty, value); this->_numberOfHistogramLevels = value; } else if (name == "NumberOfHistogramMatchPoints") { unsigned int value; map::core::unwrapMetaProperty(pProperty, value); this->_numberOfHistogramMatchPoints = value; } else if (name == "NumberOfIterations") { unsigned long num; map::core::unwrapMetaProperty(pProperty, num); this->_internalRegistrationMethod->SetNumberOfIterations(num); } else if (name == "MaximumKernelWidth") { unsigned int num; map::core::unwrapMetaProperty(pProperty, num); this->_internalRegistrationMethod->SetMaximumKernelWidth(num); } else if (name == "MaximumKernelError") { double num; map::core::unwrapMetaProperty(pProperty, num); this->_internalRegistrationMethod->SetMaximumError(num); } else if (name == "SmoothDisplacementField") { bool value; map::core::unwrapMetaProperty(pProperty, value); this->_internalRegistrationMethod->SetSmoothDisplacementField(value); } else if (name == "DisplacementFieldStandardDeviations") { double value; map::core::unwrapMetaProperty(pProperty, value); this->_internalRegistrationMethod->SetStandardDeviations(value); } else if (name == "SmoothUpdateField") { bool value; map::core::unwrapMetaProperty(pProperty, value); this->_internalRegistrationMethod->SetSmoothUpdateField(value); } else if (name == "UpdateFieldStandardDeviations") { double value; map::core::unwrapMetaProperty(pProperty, value); this->_internalRegistrationMethod->SetUpdateFieldStandardDeviations(value); } else { assert(false); //any other property name should have been excluded by the calling function. } }; } // end namespace itk } // end namespace algorithm } // end namespace map #endif diff --git a/Code/Algorithms/Plastimatch/include/mapPlmCLIRegistrationAlgorithmBase.tpp b/Code/Algorithms/Plastimatch/include/mapPlmCLIRegistrationAlgorithmBase.tpp index dc93816..b597c1e 100644 --- a/Code/Algorithms/Plastimatch/include/mapPlmCLIRegistrationAlgorithmBase.tpp +++ b/Code/Algorithms/Plastimatch/include/mapPlmCLIRegistrationAlgorithmBase.tpp @@ -1,840 +1,840 @@ // ----------------------------------------------------------------------- // 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_PLM_CLI_REGISTRATION_ALGORITHM_BASE_TPP #define __MAP_PLM_CLI_REGISTRATION_ALGORITHM_BASE_TPP #include "itkSpatialObjectToImageFilter.h" #include "itkImage.h" #include "mapAlgorithmException.h" #include "mapPreCachedRegistrationKernel.h" #include "mapInverseRegistrationKernelGenerator.h" #include "mapRegistrationManipulator.h" #include "mapAlgorithmWrapperEvent.h" #include "mapImageWriter.h" #include "mapProcessExecutor.h" #include "mapConvert.h" #include "mapMetaProperty.h" #include "mapString.h" #include "mapFieldByFileLoadFunctor.h" #include "mapFieldDecomposer.h" #include "mapSimpleLandMarkFileWriter.h" namespace map { namespace algorithm { namespace plastimatch { template ::itk::ModifiedTimeType CLIRegistrationAlgorithmBase:: getNthTargetPointSetMTime(SlotIndexType index) const { return _targetPSMTime.getMTime(); }; template ::itk::ModifiedTimeType CLIRegistrationAlgorithmBase:: getNthMovingPointSetMTime(SlotIndexType index) const { return _movingPSMTime.getMTime(); }; template typename CLIRegistrationAlgorithmBase::FieldRepRequirement::Type CLIRegistrationAlgorithmBase:: isMovingRepresentationRequired() const { return FieldRepRequirement::No; }; template typename CLIRegistrationAlgorithmBase::FieldRepRequirement::Type CLIRegistrationAlgorithmBase:: isTargetRepresentationRequired() const { return FieldRepRequirement::No; }; template bool CLIRegistrationAlgorithmBase:: isStoppable() const { return false; }; template typename CLIRegistrationAlgorithmBase::IterationCountType CLIRegistrationAlgorithmBase:: doGetCurrentIteration() const { return 0; }; template typename CLIRegistrationAlgorithmBase::IterationCountType CLIRegistrationAlgorithmBase:: doGetMaxIterations() const { return 0; }; template bool CLIRegistrationAlgorithmBase:: hasIterationCount() const { return false; }; template bool CLIRegistrationAlgorithmBase:: hasMaxIterationCount() const { return false; }; template bool CLIRegistrationAlgorithmBase:: hasCurrentOptimizerValue() const { return false; }; template CLIRegistrationAlgorithmBase:: CLIRegistrationAlgorithmBase() : _deleteTempDirectory(true) { _spInternalMovingImage = NULL; _spInternalTargetImage = NULL; }; template CLIRegistrationAlgorithmBase:: ~CLIRegistrationAlgorithmBase() { }; template bool CLIRegistrationAlgorithmBase:: isReusable() const { return true; }; template void CLIRegistrationAlgorithmBase:: configureAlgorithm() { if (this->isFirstConfiguration()) { _plastimatchDir = ""; ::map::core::String envDir = ""; if (itksys::SystemTools::GetEnv("MAP_PLASTIMATCH_PATH", envDir)) { _plastimatchDir = envDir; } _workingDir = itksys::SystemTools::GetCurrentWorkingDirectory(); _deleteTempDirectory = true; } }; template void CLIRegistrationAlgorithmBase:: compileInfos(MetaPropertyVectorType& infos) const { #ifndef MAP_SEAL_ALGORITHMS infos.push_back(map::algorithm::MetaPropertyInfo::New("WorkingDirectory", typeid(map::core::String), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("PlastimatchDirectory", typeid(map::core::String), true, true)); infos.push_back(map::algorithm::MetaPropertyInfo::New("DeleteTempDirectory", typeid(bool), true, true)); #endif }; template typename CLIRegistrationAlgorithmBase::MetaPropertyPointer CLIRegistrationAlgorithmBase:: doGetProperty(const MetaPropertyNameType& name) const { MetaPropertyPointer spResult; if (name == "WorkingDirectory") { spResult = map::core::MetaProperty::New(this->_workingDir); } else if (name == "PlastimatchDirectory") { spResult = map::core::MetaProperty::New(this->_plastimatchDir); } else if (name == "DeleteTempDirectory") { spResult = map::core::MetaProperty::New(this->_deleteTempDirectory); } else { assert(false); //any other property name should have been excluded by the calling function. } return spResult; }; template void CLIRegistrationAlgorithmBase:: doSetProperty(const MetaPropertyNameType& name, const MetaPropertyType* pProperty) { if (name == "WorkingDirectory") { ::map::core::String dir; map::core::unwrapMetaProperty(pProperty, dir); this->_workingDir = dir; } else if (name == "PlastimatchDirectory") { ::map::core::String dir; map::core::unwrapMetaProperty(pProperty, dir); this->_plastimatchDir = dir; } else if (name == "DeleteTempDirectory") { bool del; map::core::unwrapMetaProperty(pProperty, del); this->_deleteTempDirectory = del; } else { assert(false); //any other property name should have been excluded by the calling function. } }; template typename CLIRegistrationAlgorithmBase::InterimRegistrationPointer CLIRegistrationAlgorithmBase:: determineInterimRegistration(const MovingRepresentationDescriptorType* pMovingRepresentation, const TargetRepresentationDescriptorType* pTargetRepresentation) const { - InterimRegistrationPointer spResult = NULL; + InterimRegistrationPointer spResult; return spResult; }; template bool CLIRegistrationAlgorithmBase:: doStopAlgorithm() { assert(false); mapExceptionMacro(AlgorithmException, << "Cannot stop Plastimatch algorithm. Interim stop feature is not supported. Wrong usage of iterative algorithm interface"); }; template void CLIRegistrationAlgorithmBase:: initializeCurrentTempDir() { srand(time(NULL)); ::map::core::OStringStream stream; stream << itksys::SystemTools::GetCurrentDateTime("%Y-%m-%d_%H-%M-%S") << "_#" << rand(); ::map::core::String currentTempDir = core::FileDispatch::createFullPath(_workingDir, stream.str()); if (!itksys::SystemTools::MakeDirectory(currentTempDir.c_str())) { mapExceptionMacro(AlgorithmException, << "Cannot create temporary working sub dir. Please check validity of given working dir and ensure right privileges for the application. Failed temporary sub dir: " << _currentTempDir); } _currentTempDir = currentTempDir; }; template void CLIRegistrationAlgorithmBase:: prepareAlgorithm() { try { this->prepCheckValidity(); this->_spFinalizedRegistration = NULL; //initialize registration components this->InvokeEvent(::map::events::AlgorithmEvent(this, "Transfer cached MetaProperties.")); this->configureAlgorithmByMetaProperties(); this->InvokeEvent(::map::events::AlgorithmEvent(this, "Initializing registration.")); this->initializeCurrentTempDir(); //preparing data this->InvokeEvent(::map::events::AlgorithmEvent(this, "Initializing/Preparing input data.")); _spInternalMovingImage = this->getMovingImage(); _spInternalTargetImage = this->getTargetImage(); this->prepPerpareInternalInputData(); //storing temporary images this->InvokeEvent(::map::events::AlgorithmEvent(this, "Passing input data to plastimatch working directory.")); this->prepSavePlastimatchInputData(); this->InvokeEvent(::map::events::AlgorithmEvent(this, "Generating parameter maps for plastimatch.")); this->prepConfigurationPLM(); this->ensureCorrectGlobalConfigSettings(); this->InvokeEvent(::map::events::AlgorithmEvent(this, "Store plastimatch configuration.")); saveConfigurationToFile(this->_configurationPLM, this->getParameterFilePath()); } catch (...) { cleanTempDir(); throw; } }; template void CLIRegistrationAlgorithmBase:: cleanTempDir() const { try { if (itksys::SystemTools::FileExists(_currentTempDir.c_str()) && this->_deleteTempDirectory) { itksys::SystemTools::RemoveADirectory(_currentTempDir.c_str()); } } catch (...) { mapLogWarningObjMacro(<< "Cannot clean up. Exception while removing the directory. Directory" << this->_currentTempDir); } }; template void CLIRegistrationAlgorithmBase:: prepCheckValidity() { if (!this->getMovingImage()) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; no moving image."); } if (!this->getTargetImage()) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; no target image."); } } template void CLIRegistrationAlgorithmBase:: prepPerpareInternalInputData() { //default implementation does nothing } template void CLIRegistrationAlgorithmBase:: ensureCorrectGlobalConfigSettings() { if (this->_configurationPLM.empty()) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; no configuration is defined."); } if (this->_configurationPLM.size() < 2) { mapExceptionMacro(AlgorithmException, << "Cannot start algorithm; invalid configuration (need at least the global section and one stage section)."); } ConfigurationType checkedConfig = this->_configurationPLM; checkedConfig[0]["moving"] = plastimatch::ParamGenerator().add(this->_movingImageTempPath); checkedConfig[0]["fixed"] = plastimatch::ParamGenerator().add(this->_targetImageTempPath); checkedConfig[0]["vf_out"] = plastimatch::ParamGenerator().add(this->_finalFieldTempPath); if (this->getMovingMask().IsNotNull()) { //add moving mask checkedConfig[0]["moving_mask"] = plastimatch::ParamGenerator().add(this->_movingMaskTempPath); } if (this->getTargetMask().IsNotNull()) { //add target mask checkedConfig[0]["fixed_mask"] = plastimatch::ParamGenerator().add(this->_targetMaskTempPath); } if (this->getMovingPointSet().IsNotNull()) { //add moving mask checkedConfig[0]["moving_landmarks"] = plastimatch::ParamGenerator().add(this->_movingPointSetTempPath); } if (this->getTargetPointSet().IsNotNull()) { //add target mask checkedConfig[0]["fixed_landmarks"] = plastimatch::ParamGenerator().add(this->_targetPointSetTempPath); } checkedConfig[0].erase("xform_out"); checkedConfig[0].erase("img_out"); checkedConfig[0].erase("img_out_fmt"); checkedConfig[0].erase("img_out_type"); this->_configurationPLM.swap(checkedConfig); } template void saveTempImage(const TImage* image, const core::String& filePath) { typedef typename ::map::io::ImageWriter < typename TImage::PixelType, typename TImage::PixelType, TImage::ImageDimension > WriterType; typename WriterType::Pointer spWriter = WriterType::New(); spWriter->setInput(image); spWriter->setFilePath(filePath); spWriter->update(); }; template typename ::itk::Image::Pointer generateMaskImage(const ::itk::SpatialObject* so, const core::FieldRepresentationDescriptor* descriptor) { assert(so); assert(descriptor); typedef ::itk::Image MaskImageType; typedef ::itk::SpatialObject ObjectType; typedef ::itk::SpatialObjectToImageFilter FilterType; typename FilterType::Pointer spFilter = FilterType::New(); spFilter->SetInput(so); typename MaskImageType::SizeType size; for (unsigned long i = 0; i < VDimension; ++i) { size[i] = static_cast (descriptor->getSize()[i] / descriptor->getSpacing()[i]); } spFilter->SetSize(size); spFilter->SetSpacing(descriptor->getSpacing()); spFilter->SetOrigin(descriptor->getOrigin()); spFilter->SetDirection(descriptor->getDirection()); spFilter->Update(); spFilter->SetInsideValue(1); spFilter->SetOutsideValue(0); return spFilter->GetOutput(); }; template void CLIRegistrationAlgorithmBase:: prepSavePlastimatchInputData() { //save the images _movingImageTempPath = core::FileDispatch::createFullPath(_currentTempDir, "moving.mhd"); _targetImageTempPath = core::FileDispatch::createFullPath(_currentTempDir, "target.mhd"); _finalFieldTempPath = core::FileDispatch::createFullPath(_currentTempDir, "deformationField.mhd"); _movingMaskTempPath = ""; _targetMaskTempPath = ""; _movingPointSetTempPath = ""; _targetPointSetTempPath = ""; this->InvokeEvent(::map::events::AlgorithmEvent(this, "Write temporary moving image. Path: " + _movingImageTempPath)); saveTempImage(_spInternalMovingImage.GetPointer(), _movingImageTempPath); this->InvokeEvent(::map::events::AlgorithmEvent(this, "Write temporary target image. Path: " + _targetImageTempPath)); saveTempImage(_spInternalTargetImage.GetPointer(), _targetImageTempPath); //save the masks if (this->getMovingMask().IsNotNull()) { typedef ::itk::Image MaskImageType; typename MaskImageType::Pointer spMovingMaskImage = generateMaskImage (this->getMovingMask(), core::createFieldRepresentation(*(_spInternalMovingImage)).GetPointer()); _movingMaskTempPath = core::FileDispatch::createFullPath(_currentTempDir, "movingMask.mhd"); this->InvokeEvent(::map::events::AlgorithmEvent(this, "Write temporary moving mask image. Path: " + _movingMaskTempPath)); saveTempImage(spMovingMaskImage.GetPointer(), _movingMaskTempPath); } if (this->getTargetMask().IsNotNull()) { typedef ::itk::Image MaskImageType; typename MaskImageType::Pointer spTargetMaskImage = generateMaskImage (this->getTargetMask(), core::createFieldRepresentation(*(_spInternalTargetImage)).GetPointer()); _targetMaskTempPath = core::FileDispatch::createFullPath(_currentTempDir, "targetMask.mhd"); this->InvokeEvent(::map::events::AlgorithmEvent(this, "Write temporary target mask image. Path: " + _targetMaskTempPath)); saveTempImage(spTargetMaskImage.GetPointer(), _targetMaskTempPath); } //save the pointsets if (this->getMovingPointSet().IsNotNull()) { _movingPointSetTempPath = core::FileDispatch::createFullPath(_currentTempDir, "movingPointSet.txt"); this->InvokeEvent(::map::events::AlgorithmEvent(this, "Write temporary moving point set. Path: " + _movingPointSetTempPath)); ::map::utilities::saveLandMarksToFile(_movingPointSetTempPath, this->getMovingPointSet().GetPointer()); } if (this->getTargetPointSet().IsNotNull()) { _targetPointSetTempPath = core::FileDispatch::createFullPath(_currentTempDir, "targetPointSet.txt"); this->InvokeEvent(::map::events::AlgorithmEvent(this, "Write temporary target point set. Path: " + _targetPointSetTempPath)); ::map::utilities::saveLandMarksToFile(_targetPointSetTempPath, this->getTargetPointSet().GetPointer()); } } template bool CLIRegistrationAlgorithmBase:: runAlgorithm() { map::utilities::ProcessExecutor::Pointer spExec = map::utilities::ProcessExecutor::New(); typename ::itk::MemberCommand::Pointer spCommand = ::itk::MemberCommand::New(); spCommand->SetCallbackFunction(this, &Self::onPlmOutputEvent); spExec->AddObserver(map::events::ExternalProcessStdOutEvent(), spCommand); map::utilities::ProcessExecutor::ArgumentListType args; args.push_back("register"); args.push_back(this->getParameterFilePath()); ::map::core::OStringStream ostr; ostr << "Calling plastimatch (" << _plastimatchDir << ") with arguments:"; for (map::utilities::ProcessExecutor::ArgumentListType::const_iterator pos = args.begin(); pos != args.end(); ++pos) { ostr << " " << *pos; } this->InvokeEvent(::map::events::AlgorithmEvent(this, ostr.str())); if (!spExec->execute(_plastimatchDir, core::FileDispatch::createFullPath(_plastimatchDir, "plastimatch"), args)) { mapExceptionMacro(AlgorithmException, << "Error when executing plastimatch to determine the registration."); } return spExec->getExitValue() == 0; }; template typename CLIRegistrationAlgorithmBase::FinalFieldPointer CLIRegistrationAlgorithmBase:: generateField() const { typedef map::core::functors::FieldByFileLoadFunctor < Superclass::TargetDimensions, Superclass::MovingDimensions > FunctorType; typename FunctorType::Pointer spFunctor = FunctorType::New(_finalFieldTempPath); FinalFieldPointer spField; ::map::core::FieldDecomposer::decomposeTransform(spFunctor->generateTransform(), spField); if (spField.IsNull()) { mapExceptionMacro(AlgorithmException, << "Error when loading Plastimatch deformation field. File name: " << _finalFieldTempPath); } return spField; }; template ::map::core::String map::algorithm::plastimatch::CLIRegistrationAlgorithmBase:: getParameterFilePath() const { ::map::core::String result = core::FileDispatch::createFullPath(_currentTempDir, "parameters.txt"); return result; }; template ::map::core::String map::algorithm::plastimatch::CLIRegistrationAlgorithmBase:: getFinalTransformFilePath() const { if (this->_configurationPLM.empty()) { mapExceptionMacro(AlgorithmException, << "Cannot determine final transform file path; no parameter maps are defined."); } ::map::core::OStringStream ostr; ostr << "TransformParameters." << this->_configurationPLM.size() - 1 << ".txt"; ::map::core::String result = core::FileDispatch::createFullPath(_currentTempDir, ostr.str()); return result; }; template void CLIRegistrationAlgorithmBase:: finalizeAlgorithm() { - RegistrationPointer spResult = NULL; + RegistrationPointer spResult; try { _spFinalizedField = this->generateField(); typedef typename map::core::PreCachedRegistrationKernel InverseKernelType; typename FieldTransformType::Pointer transform = FieldTransformType::New(); transform->SetDisplacementField(_spFinalizedField.GetPointer()); typename InverseKernelType::Pointer spIKernel = InverseKernelType::New(); spIKernel->setTransformModel(transform); //now build the direct kernel via inversion of the inverse kernel typedef core::InverseRegistrationKernelGenerator < RegistrationType::TargetDimensions, RegistrationType::MovingDimensions > GeneratorType; typename GeneratorType::Pointer spGenerator = GeneratorType::New(); typedef typename GeneratorType::InverseKernelBaseType DirectKernelType; typename Superclass::MovingRepresentationDescriptorType::ConstPointer spMovingRep = ::map::core::createFieldRepresentation(*(this->getMovingImage())).GetPointer(); if (this->getMovingRepresentation()) { //user has defined a representation descriptor -> use this one spMovingRep = this->getMovingRepresentation(); } typename DirectKernelType::Pointer spDKernel = spGenerator->generateInverse(* (spIKernel.GetPointer()), spMovingRep); if (spDKernel.IsNull()) { mapExceptionMacro(AlgorithmException, << "Error. Cannot determine direct mapping kernel of final registration. Current inverse kernel: " << spIKernel); } //now create the registration and set the kernels spResult = RegistrationType::New(); ::map::core::RegistrationManipulator manipulator(spResult); manipulator.setDirectMapping(spDKernel); manipulator.setInverseMapping(spIKernel); manipulator.getTagValues()[tags::AlgorithmUID] = this->getUID()->toStr(); _spFinalizedRegistration = spResult; } catch (...) { //delete temp dir even in case of an exception cleanTempDir(); throw; } //delete temp dir cleanTempDir(); _currentTempDir = ""; }; template typename CLIRegistrationAlgorithmBase::RegistrationPointer CLIRegistrationAlgorithmBase:: doGetRegistration() const { return _spFinalizedRegistration; }; template bool CLIRegistrationAlgorithmBase:: registrationIsOutdated() const { bool outdated = _spFinalizedRegistration.IsNull(); if (_spFinalizedRegistration.IsNotNull()) { if (!outdated) { outdated = _spFinalizedRegistration->GetMTime() < MetaPropertyAlgorithmBase::GetMTime(); } if (!outdated) { //check if the inputs have been changed outdated = this->_spInternalMovingImage != this->getMovingImage(); } if (!outdated) { //check if the inputs have been changed outdated = this->_spInternalTargetImage != this->getTargetImage(); } if (!outdated) { outdated = _spFinalizedRegistration->GetMTime() < this->getTargetImageMTime(); } if (!outdated) { outdated = _spFinalizedRegistration->GetMTime() < this->getMovingImageMTime(); } if (!outdated) { outdated = _spFinalizedRegistration->GetMTime() < this->getTargetPointSetMTime(); } if (!outdated) { outdated = _spFinalizedRegistration->GetMTime() < this->getMovingPointSetMTime(); } if (!outdated) { outdated = _spFinalizedRegistration->GetMTime() < this->getTargetMaskMTime(); } if (!outdated) { outdated = _spFinalizedRegistration->GetMTime() < this->getMovingMaskMTime(); } } return outdated; }; template typename CLIRegistrationAlgorithmBase::OptimizerMeasureType CLIRegistrationAlgorithmBase:: doGetCurrentOptimizerValue() const { OptimizerMeasureType result; return result; }; template void CLIRegistrationAlgorithmBase:: PrintSelf(std::ostream& os, ::itk::Indent indent) const { Superclass::PrintSelf(os, indent); ImageRegistrationAlgorithmBase::PrintSelf(os, indent); os << indent << "Finalized registration: " << _spFinalizedRegistration << std::endl; }; template void CLIRegistrationAlgorithmBase:: onPlmOutputEvent(::itk::Object* caller, const ::itk::EventObject& eventObject) { const events::ExternalProcessStdOutEvent* pStdEvent = dynamic_cast(&eventObject); if (pStdEvent) { this->InvokeEvent(::map::events::AlgorithmIterationEvent(this, pStdEvent->getComment())); } } template typename CLIRegistrationAlgorithmBase::MovingPointSetConstPointer CLIRegistrationAlgorithmBase:: doGetNthMovingPointSet(SlotIndexType index) const { return this->_spMovingPointSet; }; template typename CLIRegistrationAlgorithmBase::TargetPointSetConstPointer CLIRegistrationAlgorithmBase:: doGetNthTargetPointSet(SlotIndexType index) const { return this->_spTargetPointSet; }; template void CLIRegistrationAlgorithmBase:: doSetNthMovingPointSet(SlotIndexType index, const MovingPointSetType* pMovingPointSet) { _spMovingPointSet = pMovingPointSet; this->_movingPSMTime.setWatchedObject(pMovingPointSet); }; template void CLIRegistrationAlgorithmBase:: doSetNthTargetPointSet(SlotIndexType index, const TargetPointSetType* pTargetPointSet) { _spTargetPointSet = pTargetPointSet; this->_targetPSMTime.setWatchedObject(pTargetPointSet); }; } // end namespace plastimatch } // end namespace algorithm } // end namespace map #endif diff --git a/Code/Core/include/mapNullRegistrationKernel.tpp b/Code/Core/include/mapNullRegistrationKernel.tpp index 7e82fee..bddff86 100644 --- a/Code/Core/include/mapNullRegistrationKernel.tpp +++ b/Code/Core/include/mapNullRegistrationKernel.tpp @@ -1,92 +1,92 @@ // ----------------------------------------------------------------------- // 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 __NULL_REGISTRATION_KERNEL_TPP #define __NULL_REGISTRATION_KERNEL_TPP #include "mapExceptionObjectMacros.h" namespace map { namespace core { template typename NullRegistrationKernel::RepresentationDescriptorConstPointer NullRegistrationKernel:: getLargestPossibleRepresentation() const { - RepresentationDescriptorConstPointer spRep = NULL; + RepresentationDescriptorConstPointer spRep; return spRep; }; template void NullRegistrationKernel:: precomputeKernel() const { mapDefaultExceptionMacro( << "Error. Cannot precompute kernel/field. NullRegistrationKernel is not a valid Kernel and cannot be precomputed."); }; template NullRegistrationKernel:: NullRegistrationKernel() { }; template NullRegistrationKernel:: ~NullRegistrationKernel() { }; template bool NullRegistrationKernel:: doMapPoint(const InputPointType& inPoint, OutputPointType& outPoint) const { return false; }; template void NullRegistrationKernel:: PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); }; template ::itk::LightObject::Pointer NullRegistrationKernel:: InternalClone() const { Pointer clone = Self::New(); return clone.GetPointer(); } } // end namespace core } // end namespace map #endif diff --git a/Code/Core/include/mapPreCachedRegistrationKernel.tpp b/Code/Core/include/mapPreCachedRegistrationKernel.tpp index 9c9d259..0ba8920 100644 --- a/Code/Core/include/mapPreCachedRegistrationKernel.tpp +++ b/Code/Core/include/mapPreCachedRegistrationKernel.tpp @@ -1,173 +1,173 @@ // ----------------------------------------------------------------------- // 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: 1285 $ (last changed revision) // @date $Date: 2016-03-30 17:47:52 +0200 (Mi, 30 Mrz 2016) $ (last change date) // @author $Author: floca $ (last changed by) // Subversion HeadURL: $HeadURL: https://svn/sbr/Sources/SBR-Projects/MatchPoint/branches/Issue-1505/Code/Core/include/mapPreCachedRegistrationKernel.tpp $ */ #ifndef __PRE_CACHED_REGISTRATION_KERNEL_TPP #define __PRE_CACHED_REGISTRATION_KERNEL_TPP #include "mapExceptionObjectMacros.h" #include "mapGenericVectorFieldTransform.h" #include "mapFieldDecomposer.h" namespace map { namespace core { template void PreCachedRegistrationKernel:: setTransformModel(TransformType* transform) { _spTransform = transform; }; template bool PreCachedRegistrationKernel:: transformExists() const { return _spTransform.IsNotNull(); }; template typename PreCachedRegistrationKernel::RepresentationDescriptorConstPointer PreCachedRegistrationKernel:: getLargestPossibleRepresentation() const { if (_spTransform.IsNull()) { mapDefaultExceptionStaticMacro(<< "Error. Cannot get representation descriptor in PreCachedTransformPolicy. Transform is not set."); } - RepresentationDescriptorConstPointer spRepresentation = NULL; + RepresentationDescriptorConstPointer spRepresentation; typename ::map::core::FieldDecomposer::FieldConstPointer pField; if (::map::core::FieldDecomposer::decomposeTransform(_spTransform, pField)) { spRepresentation = createFieldRepresentation(*(pField.GetPointer())); } return spRepresentation; }; template const typename PreCachedRegistrationKernel::TransformType* PreCachedRegistrationKernel:: getTransformModel() const { return _spTransform; }; template bool PreCachedRegistrationKernel:: checkAndPrepareTransform() const { return _spTransform.IsNotNull(); }; template const typename PreCachedRegistrationKernel::OutputPointType PreCachedRegistrationKernel:: getNullPoint() const { typedef itk::GenericVectorFieldTransform< ::map::core::continuous::ScalarType, VInputDimensions, VOutputDimensions> CastedTransformType; const CastedTransformType* castedTrans = dynamic_cast(_spTransform.GetPointer()); MappingVectorType result; if (castedTrans) { typedef typename MappingVectorType::Superclass VectorSuperclassType; result.VectorSuperclassType::operator = (castedTrans->GetNullPoint()); } return result; }; template bool PreCachedRegistrationKernel:: usesNullPoint() const { typedef itk::GenericVectorFieldTransform< ::map::core::continuous::ScalarType, VInputDimensions, VOutputDimensions> CastedTransformType; const CastedTransformType* castedTrans = dynamic_cast(_spTransform.GetPointer()); if (castedTrans) { return castedTrans->GetUseNullPoint(); } else { return false; } }; template PreCachedRegistrationKernel:: - PreCachedRegistrationKernel() : _spTransform(NULL) + PreCachedRegistrationKernel() { }; template PreCachedRegistrationKernel:: ~PreCachedRegistrationKernel() { }; template ::itk::LightObject::Pointer PreCachedRegistrationKernel:: InternalClone() const { Pointer clone = Self::New(); clone->_spTransform = this->_spTransform; return clone.GetPointer(); } template void PreCachedRegistrationKernel:: PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); if (_spTransform.IsNotNull()) { os << indent << "Transform : " << std::endl << _spTransform << std::endl; } else { os << indent << "Transform : NULL" << std::endl; } os << indent << "Use null vector: " << this->usesNullPoint() << std::endl; os << indent << "Null vector: " << this->getNullPoint() << std::endl; }; } // end namespace core } // end namespace map #endif diff --git a/Code/Core/test/mapFieldByFieldInversionFunctorTest.cpp b/Code/Core/test/mapFieldByFieldInversionFunctorTest.cpp index 3bf22dc..60c7776 100644 --- a/Code/Core/test/mapFieldByFieldInversionFunctorTest.cpp +++ b/Code/Core/test/mapFieldByFieldInversionFunctorTest.cpp @@ -1,159 +1,159 @@ // ----------------------------------------------------------------------- // 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$ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "mapFieldByModelFunctor.h" #include "mapFieldByFieldInversionFunctor.h" #include "litCheckMacros.h" #include "litTransformFieldTester.h" #include "mapPreCachedRegistrationKernel.h" #include "mapArtifactGenerator.h" #include "itkScaleTransform.h" #include "itkImageRegionIterator.h" namespace map { namespace testing { int mapFieldByFieldInversionFunctorTest(int argc, char* argv[]) { //ARGUMENTS: 1: Number of iterations // 2: Stop value // 3: Check threshold PREPARE_DEFAULT_TEST_REPORTING; unsigned int nrOfIterations = 40; double stopValue = 0.1; double checkThreshold = 0.1; if (argc > 1) { std::istringstream istream; istream.str(argv[1]); istream >> nrOfIterations; } if (argc > 2) { std::istringstream istream; istream.str(argv[2]); istream >> stopValue; } if (argc > 3) { std::istringstream istream; istream.str(argv[3]); istream >> checkThreshold; } // We need a field, so we build one here using the FieldByModelFunctor typedef core::functors::FieldByModelFunctor<2, 2> ModelFunctorType; typedef itk::ScaleTransform< ::map::core::continuous::ScalarType, 2> TransformType; TransformType::Pointer spModel = TransformType::New(); ModelFunctorType::InFieldRepresentationType::SpacingType spacing(0.5); ModelFunctorType::InFieldRepresentationType::PointType origin; origin.Fill(0); ModelFunctorType::InFieldRepresentationType::SizeType size; size.fill(2); ModelFunctorType::TransformType::ParametersType params(2); params.fill(3.0); spModel->SetParameters(params); ModelFunctorType::InFieldRepresentationType::Pointer spInRep = ModelFunctorType::InFieldRepresentationType::New(); spInRep->setSize(size); spInRep->setSpacing(spacing); spInRep->setOrigin(origin); ModelFunctorType::Pointer spFunc = ModelFunctorType::New(spModel, spInRep); - ModelFunctorType::TransformPointer spSourceFieldTransform = NULL; + ModelFunctorType::TransformPointer spSourceFieldTransform; spSourceFieldTransform = spFunc->generateTransform(); // we use the source model for analytic inversion TransformType::InverseTransformBasePointer spInverseModel = spModel->GetInverseTransform(); // test the FieldByFieldInversionFunctor typedef core::functors::FieldByFieldInversionFunctor<2, 2> FieldInversionFunctorType; typedef core::PreCachedRegistrationKernel<2,2> PreCachedKernelType; PreCachedKernelType::Pointer spSourceKernel = PreCachedKernelType::New(); spSourceKernel->setTransformModel(spSourceFieldTransform.GetPointer()); // reuse of spInRep FieldInversionFunctorType::Pointer spFieldInversionFunc = FieldInversionFunctorType::New( spSourceKernel, spInRep); spFieldInversionFunc->setStopValue(stopValue); spFieldInversionFunc->setNumberOfIterations(nrOfIterations); CHECK(spFieldInversionFunc.IsNotNull()); CHECK(spFieldInversionFunc->getStopValue() == stopValue); CHECK(spFieldInversionFunc->getNumberOfIterations() == nrOfIterations); CHECK(spSourceKernel == spFieldInversionFunc->getSourceFieldKernel()); // test CreateAnother FieldInversionFunctorType::Pointer spFieldInversionFuncAnother = dynamic_cast(spFieldInversionFunc->CreateAnother().GetPointer()); CHECK(spFieldInversionFuncAnother->getSourceFieldKernel() == spFieldInversionFunc->getSourceFieldKernel()); CHECK(spFieldInversionFuncAnother->getInFieldRepresentation() == spFieldInversionFunc->getInFieldRepresentation()); CHECK(spFieldInversionFuncAnother->GetNameOfClass() == spFieldInversionFunc->GetNameOfClass()); CHECK(spFieldInversionFuncAnother->getStopValue() == spFieldInversionFunc->getStopValue()); CHECK(spFieldInversionFuncAnother->getNumberOfIterations() == spFieldInversionFunc->getNumberOfIterations()); // test generateField - FieldInversionFunctorType::TransformPointer spGeneratedFieldTransform = NULL; + FieldInversionFunctorType::TransformPointer spGeneratedFieldTransform; CHECK_NO_THROW(spGeneratedFieldTransform = spFieldInversionFunc->generateTransform()); CHECK(spGeneratedFieldTransform.IsNotNull()); FieldInversionFunctorType::FieldType::Pointer spGeneratedField = testing::unwrapTransformField(spGeneratedFieldTransform.GetPointer()); // use the inverted model spInverseModel to compare results lit::TransformFieldTester tester; tester.setReferenceTransform(spInverseModel); tester.setActualField(spGeneratedField); tester.setCheckThreshold(checkThreshold); CHECK_TESTER(tester); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/Core/test/mapFieldByFileLoadFunctorTest.cpp b/Code/Core/test/mapFieldByFileLoadFunctorTest.cpp index 82a5999..148d068 100644 --- a/Code/Core/test/mapFieldByFileLoadFunctorTest.cpp +++ b/Code/Core/test/mapFieldByFileLoadFunctorTest.cpp @@ -1,109 +1,109 @@ // ----------------------------------------------------------------------- // 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$ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "mapFieldByFileLoadFunctor.h" #include "litCheckMacros.h" #include "litFieldTester.h" #include "mapLazyRegistrationKernel.h" #include "mapFieldDecomposer.h" #include "itkImageRegionIterator.h" #include "itkImageFileReader.h" namespace map { namespace testing { int mapFieldByFileLoadFunctorTest(int argc, char* argv[]) { //ARGUMENTS: 1: test field file PREPARE_DEFAULT_TEST_REPORTING; ::map::core::String filePath = ""; double checkThreshold = 0.1; if (argc > 1) { std::istringstream istream; istream.str(argv[1]); istream >> filePath; } if (argc > 2) { std::istringstream istream; istream.str(argv[2]); istream >> checkThreshold; } typedef core::functors::FieldByFileLoadFunctor<2, 2> FieldFunctorType; FieldFunctorType::Pointer spFieldFunc = FieldFunctorType::New(filePath, NULL); CHECK(spFieldFunc.IsNotNull()); CHECK(spFieldFunc->getFieldFilePath() == filePath); // test CreateAnother FieldFunctorType::Pointer spFieldFuncAnother = dynamic_cast (spFieldFunc->CreateAnother().GetPointer()); CHECK(spFieldFuncAnother->getInFieldRepresentation() == spFieldFunc->getInFieldRepresentation()); CHECK(spFieldFuncAnother->GetNameOfClass() == spFieldFunc->GetNameOfClass()); CHECK(spFieldFuncAnother->getFieldFilePath() == spFieldFunc->getFieldFilePath()); // test generateTransform - FieldFunctorType::FieldType::Pointer spGeneratedField = NULL; - FieldFunctorType::TransformPointer spGeneratedFieldTransform = NULL; + FieldFunctorType::FieldType::Pointer spGeneratedField; + FieldFunctorType::TransformPointer spGeneratedFieldTransform; CHECK_NO_THROW(spGeneratedFieldTransform = spFieldFunc->generateTransform()); ::map::core::FieldDecomposer<2, 2>::decomposeTransform(spGeneratedFieldTransform, spGeneratedField); CHECK(spGeneratedField.IsNotNull()); typedef ::itk::ImageFileReader ReaderType; ReaderType::Pointer spReader = ReaderType::New(); spReader->SetFileName(filePath); FieldFunctorType::FieldType::Pointer spRefField = spReader->GetOutput(); spReader->Update(); //test the fields lit::FieldTester tester; tester.setExpectedField(spRefField); tester.setActualField(spGeneratedField); tester.setCheckThreshold(checkThreshold); CHECK_TESTER(tester); //test invalid path FieldFunctorType::Pointer spInvalidFieldFunc = FieldFunctorType::New("lalalal", NULL); CHECK_THROW_EXPLICIT(spGeneratedFieldTransform = spInvalidFieldFunc->generateTransform(), ::itk::ExceptionObject); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/Core/test/mapFieldByModelFunctorTest.cpp b/Code/Core/test/mapFieldByModelFunctorTest.cpp index 1facff0..d976786 100644 --- a/Code/Core/test/mapFieldByModelFunctorTest.cpp +++ b/Code/Core/test/mapFieldByModelFunctorTest.cpp @@ -1,98 +1,98 @@ // ----------------------------------------------------------------------- // 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$ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "mapFieldByModelFunctor.h" #include "litCheckMacros.h" #include "litTransformFieldTester.h" #include "itkScaleTransform.h" #include "mapArtifactGenerator.h" namespace map { namespace testing { int mapFieldByModelFunctorTest(int, char* []) { PREPARE_DEFAULT_TEST_REPORTING; typedef core::functors::FieldByModelFunctor<3, 3> FunctorType; //Model kernel generation typedef itk::ScaleTransform< ::map::core::continuous::ScalarType, 3> ScaleTransformType; FunctorType::TransformType::Pointer spModel = ScaleTransformType::New().GetPointer(); FunctorType::InFieldRepresentationType::SpacingType spacing(0.5); FunctorType::InFieldRepresentationType::PointType origin; origin.Fill(0); FunctorType::InFieldRepresentationType::SizeType size; size.fill(2); FunctorType::TransformType::ParametersType params(3); params.fill(2.0); spModel->SetParameters(params); FunctorType::InFieldRepresentationType::Pointer spInRep = FunctorType::InFieldRepresentationType::New(); spInRep->setSize(size); spInRep->setSpacing(spacing); spInRep->setOrigin(origin); FunctorType::Pointer spFunc = FunctorType::New(spModel, spInRep); CHECK(spFunc.IsNotNull()); CHECK(spModel == spFunc->getSourceTransformModel()); FunctorType::Pointer spFuncAnother = dynamic_cast (spFunc->CreateAnother().GetPointer()); CHECK(spFuncAnother->getSourceTransformModel() == spFunc->getSourceTransformModel()); CHECK(spFuncAnother->getInFieldRepresentation() == spFunc->getInFieldRepresentation()); CHECK(spFuncAnother->GetNameOfClass() == spFunc->GetNameOfClass()); // test generateField - FunctorType::TransformPointer spFieldTransform = NULL; + FunctorType::TransformPointer spFieldTransform; CHECK_NO_THROW(spFieldTransform = spFunc->generateTransform()); CHECK(spFieldTransform.IsNotNull()); FunctorType::FieldType::Pointer spField = testing::unwrapTransformField(spFieldTransform.GetPointer()); lit::TransformFieldTester tester; tester.setReferenceTransform(spModel); tester.setActualField(spField); tester.setCheckThreshold(0.0); CHECK_TESTER(tester); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/Core/test/mapFieldByModelInversionFunctorTest.cpp b/Code/Core/test/mapFieldByModelInversionFunctorTest.cpp index 863ff1b..4252035 100644 --- a/Code/Core/test/mapFieldByModelInversionFunctorTest.cpp +++ b/Code/Core/test/mapFieldByModelInversionFunctorTest.cpp @@ -1,134 +1,134 @@ // ----------------------------------------------------------------------- // 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$ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "mapFieldByModelInversionFunctor.h" #include "mapFieldDecomposer.h" #include "litCheckMacros.h" #include "litTransformFieldTester.h" #include "itkScaleTransform.h" #include "itkImageRegionIterator.h" namespace map { namespace testing { int mapFieldByModelInversionFunctorTest(int argc, char* argv[]) { //ARGUMENTS: 1: Number of iterations // 2: Stop value // 3: Check threshold PREPARE_DEFAULT_TEST_REPORTING; unsigned int nrOfIterations = 40; double stopValue = 0.1; double checkThreshold = 0.1; if (argc > 1) { std::istringstream istream; istream.str(argv[1]); istream >> nrOfIterations; } if (argc > 2) { std::istringstream istream; istream.str(argv[2]); istream >> stopValue; } if (argc > 3) { std::istringstream istream; istream.str(argv[3]); istream >> checkThreshold; } typedef core::functors::FieldByModelInversionFunctor<2, 2> FunctorType; typedef itk::ScaleTransform< ::map::core::continuous::ScalarType, 2> TransformType; TransformType::Pointer spModel = TransformType::New(); FunctorType::InFieldRepresentationType::SpacingType spacing(0.5); FunctorType::InFieldRepresentationType::PointType origin; origin.Fill(0); FunctorType::InFieldRepresentationType::SizeType size; size.fill(10); FunctorType::SourceTransformModelType::ParametersType params(2); params.fill(3.0); spModel->SetParameters(params); FunctorType::InFieldRepresentationType::Pointer spInRep = FunctorType::InFieldRepresentationType::New(); spInRep->setSize(size); spInRep->setSpacing(spacing); spInRep->setOrigin(origin); FunctorType::Pointer spFunc = FunctorType::New(spModel, spInRep); spFunc->setStopValue(stopValue); spFunc->setNumberOfIterations(nrOfIterations); CHECK(spFunc.IsNotNull()); CHECK(spFunc->getStopValue() == stopValue); CHECK(spFunc->getNumberOfIterations() == nrOfIterations); CHECK(spModel == spFunc->getSourceTransformModel()); FunctorType::Pointer spFuncAnother = dynamic_cast (spFunc->CreateAnother().GetPointer()); CHECK(spFuncAnother->getSourceTransformModel() == spFunc->getSourceTransformModel()); CHECK(spFuncAnother->getInFieldRepresentation() == spFunc->getInFieldRepresentation()); CHECK(spFuncAnother->GetNameOfClass() == spFunc->GetNameOfClass()); CHECK(spFuncAnother->getStopValue() == spFunc->getStopValue()); CHECK(spFuncAnother->getNumberOfIterations() == spFunc->getNumberOfIterations()); // test generateField - FunctorType::TransformPointer spTransform = NULL; + FunctorType::TransformPointer spTransform; CHECK_NO_THROW(spTransform = spFunc->generateTransform()); CHECK(spTransform.IsNotNull()); TransformType::InverseTransformBasePointer spInverseModel = spModel->GetInverseTransform(); FunctorType::FieldType::Pointer spField; ::map::core::FieldDecomposer<2, 2>::decomposeTransform(spTransform, spField); lit::TransformFieldTester tester; tester.setReferenceTransform(spInverseModel); tester.setActualField(spField); tester.setCheckThreshold(checkThreshold); CHECK_TESTER(tester); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/Core/test/mapGenericFieldGeneratingCombinationFunctorTest.cpp b/Code/Core/test/mapGenericFieldGeneratingCombinationFunctorTest.cpp index 3614193..6631ed6 100644 --- a/Code/Core/test/mapGenericFieldGeneratingCombinationFunctorTest.cpp +++ b/Code/Core/test/mapGenericFieldGeneratingCombinationFunctorTest.cpp @@ -1,168 +1,168 @@ // ----------------------------------------------------------------------- // 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$ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "itkScaleTransform.h" #include "mapGenericFieldGeneratingCombinationFunctor.h" #include "mapFieldByModelFunctor.h" #include "litCheckMacros.h" #include "litTransformFieldTester.h" #include "mapPreCachedRegistrationKernel.h" #include "mapLazyRegistrationKernel.h" #include "mapFieldDecomposer.h" #include "itkIdentityTransform.h" namespace map { namespace testing { int mapGenericFieldGeneratingCombinationFunctorTest(int, char* []) { PREPARE_DEFAULT_TEST_REPORTING; typedef core::PreCachedRegistrationKernel<2, 2> PreCachedKernelType; PreCachedKernelType::RepresentationDescriptorType::SpacingType spacing(0.5); PreCachedKernelType::RepresentationDescriptorType::PointType origin; origin.Fill(0); PreCachedKernelType::RepresentationDescriptorType::SizeType size; size.fill(10); PreCachedKernelType::RepresentationDescriptorType::Pointer spInRep = PreCachedKernelType::RepresentationDescriptorType::New(); spInRep->setSize(size); spInRep->setSpacing(spacing); spInRep->setOrigin(origin); PreCachedKernelType::RepresentationDescriptorType::PointType illegalOrigin; illegalOrigin.Fill(100); PreCachedKernelType::RepresentationDescriptorType::Pointer spIllegalInRep = PreCachedKernelType::RepresentationDescriptorType::New(); spIllegalInRep->setSize(size); spIllegalInRep->setSpacing(spacing); spIllegalInRep->setOrigin(illegalOrigin); //Model kernel generation typedef ::itk::ScaleTransform< ::map::core::continuous::ScalarType, 2> TransformType; PreCachedKernelType::Pointer spModelKernel = PreCachedKernelType::New(); TransformType::Pointer spTransform = TransformType::New(); TransformType::ParametersType params(2); params[0] = 0.3; params[1] = 0.3; spTransform->SetParameters(params); //Field kernel (generate by using inverse transform) TransformType::InverseTransformBasePointer spInverseTransform = spTransform->GetInverseTransform(); spModelKernel->setTransformModel(spTransform); typedef core::functors::FieldByModelFunctor<2, 2> FunctorType; FunctorType::Pointer spFieldFunctor = FunctorType::New(spInverseTransform, spInRep); spFieldFunctor->setNullPointUsage(true); //uses this functor to generate the test field typedef core::LazyRegistrationKernel<2, 2> FieldKernelType; FieldKernelType::Pointer spFieldKernel = FieldKernelType::New(); spFieldKernel->setTransformFunctor(spFieldFunctor); //Establish combination functor for test typedef core::functors::GenericFieldGeneratingCombinationFunctor<2, 2, 2> CombinatorFunctorType; CombinatorFunctorType::Pointer spTestFunctor = CombinatorFunctorType::New( spModelKernel, spFieldKernel, spInRep); //Test the functor io CHECK(spTestFunctor.IsNotNull()); CHECK(spModelKernel.GetPointer() == spTestFunctor->get1stSourceKernelBase()); CHECK(spFieldKernel.GetPointer() == spTestFunctor->get2ndSourceKernelBase()); CombinatorFunctorType::Pointer spFuncAnother = dynamic_cast (spTestFunctor->CreateAnother().GetPointer()); CHECK(spFuncAnother->get1stSourceKernelBase() == spTestFunctor->get1stSourceKernelBase()); CHECK(spFuncAnother->get2ndSourceKernelBase() == spTestFunctor->get2ndSourceKernelBase()); CHECK(spFuncAnother->getInFieldRepresentation() == spTestFunctor->getInFieldRepresentation()); CHECK(spFuncAnother->GetNameOfClass() == spTestFunctor->GetNameOfClass()); //Test field generation, hence we've combined a field with its inverse transform model //the resulting field must be an identity transform - CombinatorFunctorType::TransformPointer spResult = NULL; + CombinatorFunctorType::TransformPointer spResult; CHECK_NO_THROW(spResult = spTestFunctor->generateTransform()); CHECK(spResult.IsNotNull()); ::map::core::FieldDecomposer<2, 2>::FieldConstPointer actualField; bool validField = ::map::core::FieldDecomposer<2, 2>::decomposeTransform(spResult, actualField); CHECK(validField); lit::TransformFieldTester< ::map::core::FieldDecomposer<2, 2>::FieldType, PreCachedKernelType::TransformType> tester; typedef itk::IdentityTransform< ::map::core::continuous::ScalarType, 2> IdentityTransformType; IdentityTransformType::Pointer spIdentityTransform = IdentityTransformType::New(); tester.setReferenceTransform(spIdentityTransform); tester.setActualField(actualField); tester.setCheckThreshold(1e-6); CHECK_TESTER(tester); //Test invalid mapping request: In field representation descriptor specifies unsupported region CombinatorFunctorType::Pointer spIllegalTestFunctor = CombinatorFunctorType::New(spModelKernel, spFieldKernel, spIllegalInRep); - CombinatorFunctorType::TransformPointer spIllegalResultFieldTransform = NULL; + CombinatorFunctorType::TransformPointer spIllegalResultFieldTransform; spIllegalTestFunctor->setNullPointUsage(false); CHECK_THROW(spIllegalResultFieldTransform = spIllegalTestFunctor->generateTransform()); //now activiate padding to avoid the exception and get a padded field spIllegalTestFunctor->setNullPointUsage(true); CombinatorFunctorType::PaddingVectorType paddingValue; paddingValue.Fill(42); spIllegalTestFunctor->setNullPoint(paddingValue); CHECK_NO_THROW(spIllegalResultFieldTransform = spIllegalTestFunctor->generateTransform()); CHECK(spIllegalTestFunctor.IsNotNull()); validField = ::map::core::FieldDecomposer<2, 2>::decomposeTransform(spIllegalResultFieldTransform, actualField); CHECK(validField); //check if the padding value was used ::map::core::FieldDecomposer<2, 2>::FieldType::IndexType index; index.Fill(1); CHECK_EQUAL(actualField->GetPixel(index), paddingValue); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/Core/test/mapGenericKernelCombiningFieldSourceTest.cpp b/Code/Core/test/mapGenericKernelCombiningFieldSourceTest.cpp index ed3a609..4d9438d 100644 --- a/Code/Core/test/mapGenericKernelCombiningFieldSourceTest.cpp +++ b/Code/Core/test/mapGenericKernelCombiningFieldSourceTest.cpp @@ -1,140 +1,140 @@ // ----------------------------------------------------------------------- // 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: 1316 $ (last changed revision) // @date $Date: 2016-04-13 14:50:09 +0200 (Mi, 13 Apr 2016) $ (last change date) // @author $Author: floca $ (last changed by) // Subversion HeadURL: $HeadURL: https://svn.inet.dkfz-heidelberg.de/sbr/Sources/SBR-Projects/MatchPoint/trunk/Code/Core/test/mapGenericFieldGeneratingCombinationFunctorTest.cpp $ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "itkScaleTransform.h" #include "litCheckMacros.h" #include "litTransformFieldTester.h" #include "mapGenericKernelCombinationFieldSource.h" #include "mapFieldByModelFunctor.h" #include "mapPreCachedRegistrationKernel.h" #include "mapLazyRegistrationKernel.h" #include "mapFieldDecomposer.h" #include "itkIdentityTransform.h" namespace map { namespace testing { int mapGenericKernelCombiningFieldSourceTest(int, char*[]) { PREPARE_DEFAULT_TEST_REPORTING; typedef core::PreCachedRegistrationKernel<2, 2> PreCachedKernelType; PreCachedKernelType::RepresentationDescriptorType::SpacingType spacing(0.5); PreCachedKernelType::RepresentationDescriptorType::PointType origin; origin.Fill(0); PreCachedKernelType::RepresentationDescriptorType::SizeType size; size.fill(10); PreCachedKernelType::RepresentationDescriptorType::Pointer spInRep = PreCachedKernelType::RepresentationDescriptorType::New(); spInRep->setSize(size); spInRep->setSpacing(spacing); spInRep->setOrigin(origin); PreCachedKernelType::RepresentationDescriptorType::PointType illegalOrigin; illegalOrigin.Fill(100); PreCachedKernelType::RepresentationDescriptorType::Pointer spIllegalInRep = PreCachedKernelType::RepresentationDescriptorType::New(); spIllegalInRep->setSize(size); spIllegalInRep->setSpacing(spacing); spIllegalInRep->setOrigin(illegalOrigin); //Model kernel generation typedef ::itk::ScaleTransform< ::map::core::continuous::ScalarType, 2> TransformType; PreCachedKernelType::Pointer spModelKernel = PreCachedKernelType::New(); TransformType::Pointer spTransform = TransformType::New(); TransformType::ParametersType params(2); params[0] = 0.3; params[1] = 0.3; spTransform->SetParameters(params); //Field kernel (generate by using inverse transform) TransformType::InverseTransformBasePointer spInverseTransform = spTransform->GetInverseTransform(); spModelKernel->setTransformModel(spTransform); typedef core::functors::FieldByModelFunctor<2, 2> FunctorType; FunctorType::Pointer spFieldFunctor = FunctorType::New(spInverseTransform, spInRep); //uses this functor to generate the test field typedef core::LazyRegistrationKernel<2, 2> FieldKernelType; FieldKernelType::Pointer spFieldKernel = FieldKernelType::New(); spFieldKernel->setTransformFunctor(spFieldFunctor); //Establish combination functor for test typedef core::GenericKernelCombinationFieldSource<2, 2, 2, ::map::core::continuous::ScalarType> SourceType; SourceType::Pointer spSource = SourceType::New(); CHECK(NULL == spSource->GetSourceKernel1()); CHECK(NULL == spSource->GetSourceKernel2()); spSource->SetSourceKernel1(spModelKernel); spSource->SetSourceKernel2(spFieldKernel); spSource->SetSize(spInRep->getRepresentedLocalImageRegion().GetSize()); spSource->SetOrigin(spInRep->getOrigin()); spSource->SetSpacing(spInRep->getSpacing()); spSource->SetDirection(spInRep->getDirection()); //Test the functor io CHECK(spSource.IsNotNull()); CHECK(spModelKernel.GetPointer() == spSource->GetSourceKernel1()); CHECK(spFieldKernel.GetPointer() == spSource->GetSourceKernel2()); //Test field generation, hence we've combined a field with its inverse transform model //the resulting field must be an identity transform - SourceType::OutputImageType::Pointer spResult = NULL; + SourceType::OutputImageType::Pointer spResult; CHECK_NO_THROW(spSource->Update()); spResult = spSource->GetOutput(); CHECK(spResult.IsNotNull()); lit::TransformFieldTester< SourceType::OutputImageType, PreCachedKernelType::TransformType> tester; typedef itk::IdentityTransform< ::map::core::continuous::ScalarType, 2> IdentityTransformType; IdentityTransformType::Pointer spIdentityTransform = IdentityTransformType::New(); tester.setReferenceTransform(spIdentityTransform); tester.setActualField(spResult); tester.setCheckThreshold(1e-6); CHECK_TESTER(tester); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/Core/test/mapTestKernelBase.h b/Code/Core/test/mapTestKernelBase.h index ffa4d38..c000cc9 100644 --- a/Code/Core/test/mapTestKernelBase.h +++ b/Code/Core/test/mapTestKernelBase.h @@ -1,71 +1,71 @@ // ----------------------------------------------------------------------- // 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_TEST_KERNEL_BASE_H #define __MAP_TEST_KERNEL_BASE_H #include "mapRegistrationKernelBase.h" namespace map { namespace testing { /*!@brief Dummy Kernel used if a simple testing kernel is needed that does nothing.*/ template class TestKernelBase: public core::RegistrationKernelBase { public: /*! Standard class typedefs. */ typedef TestKernelBase Self; typedef core::RegistrationKernelBase Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; itkTypeMacro(TestKernelBase, core::RegistrationKernelBase); itkNewMacro(Self); typename Superclass::RepresentationDescriptorConstPointer getLargestPossibleRepresentation() const { - typename Superclass::RepresentationDescriptorConstPointer spTemp = NULL; + typename Superclass::RepresentationDescriptorConstPointer spTemp; return spTemp; } void precomputeKernel() const override { // do nothing } bool doMapPoint(const typename Superclass::InputPointType& inPoint, typename Superclass::OutputPointType& outPoint) const { return false; } }; } // end namespace testing } // end namespace map #endif diff --git a/Code/Utilities/include/mapSimpleLandMarkFileWriter.h b/Code/Utilities/include/mapSimpleLandMarkFileWriter.h index a7d3c23..99cb9a5 100644 --- a/Code/Utilities/include/mapSimpleLandMarkFileWriter.h +++ b/Code/Utilities/include/mapSimpleLandMarkFileWriter.h @@ -1,84 +1,84 @@ // ----------------------------------------------------------------------- // 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: 797 $ (last changed revision) // @date $Date: 2014-10-10 11:42:05 +0200 (Fr, 10 Okt 2014) $ (last change date) // @author $Author: floca $ (last changed by) // Subversion HeadURL: $HeadURL: https://svn.inet.dkfz-heidelberg.de/sbr/Sources/SBR-Projects/MatchPoint/trunk/Code/Utilities/include/mapSimpleLandMarkFileReader.h $ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "mapString.h" #include namespace map { namespace utilities { /** Loads a simple land mark file (one land mark per line, values of a landmark seperated by space) into the point set type. This function is used for some tests and examples. It asumes the standard itk coordinate system (LPS) */ template bool saveLandMarksToFile(const core::String& lmFileName, const TPointSet* pointSet) { using LandmarksType = TPointSet; std::ofstream pointsFile; pointsFile.open(lmFileName.c_str()); - typename LandmarksType::Pointer spLMs = NULL; + typename LandmarksType::Pointer spLMs; if (pointsFile.fail()) { return false; } if (pointSet) { typename LandmarksType::PointType point; spLMs = LandmarksType::New(); spLMs->SetPoints(LandmarksType::PointsContainer::New()); typename LandmarksType::PointsContainer::ConstPointer points = pointSet->GetPoints(); typename LandmarksType::PointsContainer::ConstIterator pointIterator = points->Begin(); typename LandmarksType::PointsContainer::ConstIterator end = points->End(); while (pointIterator != end) { typename LandmarksType::PointType p = pointIterator.Value(); for (unsigned int i = 0; i < LandmarksType::PointDimension; ++i) { if (i > 0) { pointsFile << " "; } pointsFile << p[i]; } pointsFile << std::endl; ++pointIterator; } } pointsFile.close(); return true; } } //namespace utilities } //namespace map diff --git a/Examples/Deployment/mapDemoDeploymentPropertiedAlgorithm.cpp b/Examples/Deployment/mapDemoDeploymentPropertiedAlgorithm.cpp index bac0db0..0e0e0b8 100644 --- a/Examples/Deployment/mapDemoDeploymentPropertiedAlgorithm.cpp +++ b/Examples/Deployment/mapDemoDeploymentPropertiedAlgorithm.cpp @@ -1,345 +1,345 @@ // ----------------------------------------------------------------------- // 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$ */ /*!@file * @ingroup Examples ********************************************************* * Demo: demoDeploymentPropertiedAlgorithm * Topics: * - How to use a deployed boxed algorithm via DLL and its * MetaProperty interface? * * This example is very similar to demoHelloWorldDeployment1. * The difference is that this time a algorithm is loaded via * DLL which implements the MetaPropertyInterface. The demo * will used the interface to access the Properties display them * and change them. *********************************************************/ #undef MAP_SEAL_ALGORITHMS #include "../Algorithms/mapDemoHelloWorldRegistration1Helper.h" #include "mapImageRegistrationAlgorithmInterface.h" #include "mapRegistrationAlgorithm.h" #include "mapImageMappingTask.h" #include "mapDeploymentDLLAccess.h" #include "mapMetaProperty.h" #include "mapMetaPropertyAccessor.h" #include "mapMetaPropertyAlgorithmInterface.h" #include "itksys/SystemTools.hxx" #include "itkDynamicLoader.h" #include "itkCommand.h" void onRegistrationEvent(itk::Object* pCaller, const itk::EventObject& e, void*) { const map::events::AlgorithmEvent* pChangeEvent = dynamic_cast (&e); if (pChangeEvent) { std::cout << std::endl << pChangeEvent->GetEventName() << " (@" << pCaller << "): " << pChangeEvent->getComment() << std::endl; } } int determinAndTestRegistration(map::deployment::RegistrationAlgorithmBase* pAlgorithmBase, AppGlobals& globals) { /*************************************************************** * Determine registration ***************************************************************/ int result = EXIT_FAILURE; std::cout << "Starting to determine the registration..." << std::endl; typedef map::algorithm::facet::RegistrationAlgorithmInterface<2, 2> RegistrationAlgorithmType; RegistrationAlgorithmType::RegistrationType::Pointer spRegistration; try { RegistrationAlgorithmType* pAlgorithmInterface = dynamic_cast (pAlgorithmBase); if (!pAlgorithmInterface) { mapDefaultExceptionStaticMacro("Error. Wrong algorithm seemed to be loaded. Not a 2D-2D algorithm. Check DLL."); } spRegistration = pAlgorithmInterface->getRegistration(); } catch (const map::core::ExceptionObject& e) { std::cerr << "ERROR: Caught an MatchPoint exception:\n"; e.Print(std::cerr); std::cerr << "\n"; throw; } std::cout << std::endl << "Registration determined..." << std::endl; //Thats all. Now we have a registration that map the moving image into the target image //space. But the algorithm only delivers the registration as a mapping function between //moving and target image space. So the moving image must be mapped... /*************************************************************** * Register the data by tasks ***************************************************************/ //define registration tasks std::cout << "Define registration task..." << std::endl; typedef map::core::ImageMappingTask ImageMappingTaskType; ImageMappingTaskType::Pointer spImageTask = ImageMappingTaskType::New(); spImageTask->setInputImage(globals.spMovingImage); spImageTask->setRegistration(spRegistration); //Process the task std::cout << "Process registration task..." << std::endl; spImageTask->execute(); /*************************************************************** * Save or test the results ***************************************************************/ globals.spResultImage = spImageTask->getResultImage(); if (globals.doTest) { result = testResults(globals); } else { result = saveResults(globals); } return result; } void showProperties(map::deployment::RegistrationAlgorithmBase* pAlgorithmBase, AppGlobals& globals) { try { typedef map::algorithm::facet::MetaPropertyAlgorithmInterface PropertyInterfaceType; PropertyInterfaceType* pPropertyInterface = dynamic_cast(pAlgorithmBase); if (!pPropertyInterface) { mapDefaultExceptionStaticMacro("Error. Wrong algorithm seemed to be loaded. No MetaPropertyInterface. Check DLL."); } std::cout << std::endl << std::endl << "Properties:" << std::endl; PropertyInterfaceType::MetaPropertyVectorType infos = pPropertyInterface->getPropertyInfos(); //go through all properties PropertyInterfaceType::MetaPropertyVectorType::iterator pos; for (pos = infos.begin(); pos != infos.end(); ++pos) { //print property information (*pos)->Print(std::cout); std::cout << std::endl; } //show number of iterations as on example for value access std::cout << std::endl << std::endl << "Retrieve value of the property \"NumberOfIterations\"..." << std::endl; map::core::MetaPropertyBase::Pointer spIterationCount = pPropertyInterface->getProperty("NumberOfIterations"); unsigned long count = 0; if (!::map::core::unwrapMetaProperty(spIterationCount, count)) { mapDefaultExceptionStaticMacro("Error. Wrong algorithm seemed to be loaded. No property \"NumberOfIterations\" exists. Check DLL."); } std::cout << "NumberOfIterations: " << count << std::endl; } catch (const map::core::ExceptionObject& e) { std::cerr << "ERROR: Caught an MatchPoint exception:\n"; e.Print(std::cerr); std::cerr << "\n"; throw e; } } int main(int argc, char* argv[]) { AppGlobals globals; int result = EXIT_FAILURE; //parse command line arguments if (parseArguments(argc, argv, globals) == EXIT_FAILURE) { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0]; std::cerr << " "; std::cerr << " [[]"; std::cerr << " |[-test "; std::cerr << " ]]" << std::endl; return EXIT_FAILURE; } //load image and landmark files std::cout << "Load images..." << std::endl; if (loadData(globals) == EXIT_FAILURE) { return EXIT_FAILURE; } /*************************************************************** * Load and prepare registration algorithm ***************************************************************/ - map::deployment::RegistrationAlgorithmBasePointer spAlgorithmBase = NULL; + map::deployment::RegistrationAlgorithmBasePointer spAlgorithmBase; try { std::cout << "Load registration algorithm..." << std::endl; std::string dllPath = itksys::SystemTools::GetProgramPath(argv[0]); dllPath = dllPath + "/" + itksys::DynamicLoader::LibPrefix() + "demoPropertiedAlgorithm2D" + map::deployment::getDeploymentDLLExtension(); std::cout << "DLL location: " << dllPath << std::endl; - map::deployment::DLLHandle::Pointer spHandle = NULL; + map::deployment::DLLHandle::Pointer spHandle; spHandle = map::deployment::openDeploymentDLL(dllPath); std::cout << "Algorithm information: " << std::endl; spHandle->getAlgorithmUID().Print(std::cout, 2); //Now load the algorthm from DLL spAlgorithmBase = map::deployment::getRegistrationAlgorithm(spHandle); std::cout << "... algorithm is loaded" << std::endl; //Now cast to the right interface (ImageRegistrationAlgorithmBase) //to set the images typedef map::algorithm::facet::ImageRegistrationAlgorithmInterface ImageRegistrationAlgorithmInterfaceType; ImageRegistrationAlgorithmInterfaceType* pImageInterface = dynamic_cast(spAlgorithmBase.GetPointer()); if (pImageInterface) { //Finally we set moving and target image for that should be //used by the image based registration algorithm pImageInterface->setMovingImage(globals.spMovingImage); pImageInterface->setTargetImage(globals.spTargetImage); } else { mapDefaultExceptionStaticMacro("Error. Wrong algorithm seemed to be loaded. Image Registration interface is missing. Check DLL."); } //The algorithm is set up and ready to run... } catch (const map::core::ExceptionObject& e) { std::cerr << "ERROR: Caught an MatchPoint exception:\n"; e.Print(std::cerr); std::cerr << "\n"; throw; } //Add observer for algorithm events. ::itk::CStyleCommand::Pointer spRegCommand = itk::CStyleCommand::New(); spRegCommand->SetCallback(&onRegistrationEvent); spAlgorithmBase->AddObserver(map::events::AlgorithmEvent(), spRegCommand); /*************************************************************** * Show properties ***************************************************************/ std::cout << "Show the properties of the algorithm directly loaded from DLL and bevor usage..." << std::endl; showProperties(spAlgorithmBase, globals); /*************************************************************** * Determine registration ***************************************************************/ result = determinAndTestRegistration(spAlgorithmBase, globals); /*************************************************************** * Change number of iterations ***************************************************************/ std::cout << "Now we change the number of iterations via a meta property..." << std::endl; try { typedef map::algorithm::facet::MetaPropertyAlgorithmInterface PropertyInterfaceType; PropertyInterfaceType* pPropertyInterface = dynamic_cast (spAlgorithmBase.GetPointer()); if (!pPropertyInterface) { mapDefaultExceptionStaticMacro("Error. Wrong algorithm seemed to be loaded. No MetaPropertyInterface. Check DLL."); } //show number of iterations as on example for value access map::core::MetaPropertyBase::Pointer spIterationCount = map::core::MetaProperty::New( 1).GetPointer(); pPropertyInterface->setProperty("NumberOfIterations", spIterationCount); } catch (map::core::ExceptionObject& e) { std::cerr << "ERROR: Caught an MatchPoint exception:\n"; e.Print(std::cerr); std::cerr << "\n"; throw; } /*************************************************************** * Show properties ***************************************************************/ std::cout << "Show the properties of the algorithm after the change..." << std::endl; showProperties(spAlgorithmBase, globals); /*************************************************************** * Determine registration ***************************************************************/ int tempResult = EXIT_FAILURE; std::cout << std::endl << std::endl << "Now compute the registration again. This time it should fail, due to the new number of iterations (not enough to converge to a proper result). ..." << std::endl; globals.testShouldFail = true; tempResult = determinAndTestRegistration(spAlgorithmBase, globals); if (tempResult == EXIT_FAILURE) { //the second registration should have failed due to the new iteration count! result = EXIT_FAILURE; } return result; } diff --git a/Examples/Deployment/mapDemoHelloWorldDeployment1.cpp b/Examples/Deployment/mapDemoHelloWorldDeployment1.cpp index dfd610b..588e52c 100644 --- a/Examples/Deployment/mapDemoHelloWorldDeployment1.cpp +++ b/Examples/Deployment/mapDemoHelloWorldDeployment1.cpp @@ -1,211 +1,211 @@ // ----------------------------------------------------------------------- // 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$ */ /*!@file * @ingroup Examples ********************************************************* * Demo: demoHelloWorldDeployment1 * Topics: * - How to use a deployed boxed algorithm via DLL? * * In the first hello world deployment example it is shown how * to load a specific deployed and boxed algorithm from a * DLL, set the moving an target image via the right * facet (ImageRegistrationAlgorithmInterface) and then * calculate the registration. Afterwards the moving image * will be registered with a appropriated task. * The outcome and used algorithm is the very same like * demoHelloWorldRegistration2. The differenc is that the later * uses static binding to the algorithm (it is integrated * in the executable). This example gets the algorithm * via DLL at runtime. Thus you may change the used algorithm * without changing this demo program by just exchanging the * used DLL. *********************************************************/ #undef MAP_SEAL_ALGORITHMS #include "../Algorithms/mapDemoHelloWorldRegistration1Helper.h" #include "mapImageRegistrationAlgorithmInterface.h" #include "mapRegistrationAlgorithm.h" #include "mapImageMappingTask.h" #include "mapDeploymentDLLAccess.h" #include "itkDynamicLoader.h" #include "itksys/SystemTools.hxx" int main(int argc, char* argv[]) { AppGlobals globals; int result = EXIT_FAILURE; //parse command line arguments if (parseArguments(argc, argv, globals) == EXIT_FAILURE) { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0]; std::cerr << " "; std::cerr << " [[]"; std::cerr << " |[-test "; std::cerr << " ]]" << std::endl; return EXIT_FAILURE; } //load image and landmark files std::cout << "Load images..." << std::endl; if (loadData(globals) == EXIT_FAILURE) { return EXIT_FAILURE; } /*************************************************************** * Load and prepare registration algorithm ***************************************************************/ - map::deployment::RegistrationAlgorithmBasePointer spAlgorithmBase = NULL; + map::deployment::RegistrationAlgorithmBasePointer spAlgorithmBase; try { std::cout << "Load registration algorithm..." << std::endl; std::string dllPath = itksys::SystemTools::GetProgramPath(argv[0]); dllPath = dllPath + "/" + itksys::DynamicLoader::LibPrefix() + "demoRegistrationAlgorithm2D" + map::deployment::getDeploymentDLLExtension(); std::cout << "DLL location: " << dllPath << std::endl; - map::deployment::DLLHandle::Pointer spHandle = NULL; + map::deployment::DLLHandle::Pointer spHandle; spHandle = map::deployment::openDeploymentDLL(dllPath); std::cout << "Algorithm information: " << std::endl; spHandle->getAlgorithmUID().Print(std::cout, 2); //Now load the algorthm from DLL spAlgorithmBase = map::deployment::getRegistrationAlgorithm(spHandle); std::cout << "... algorithm is loaded" << std::endl; //Now cast to the right interface (ImageRegistrationAlgorithmInterface) //to set the images typedef map::algorithm::facet::ImageRegistrationAlgorithmInterface ImageRegistrationAlgorithmInterfaceType; ImageRegistrationAlgorithmInterfaceType* pImageInterface = dynamic_cast(spAlgorithmBase.GetPointer()); if (pImageInterface) { //Finally we set moving and target image for that should be //used by the image based registration algorithm pImageInterface->setMovingImage(globals.spMovingImage); pImageInterface->setTargetImage(globals.spTargetImage); } else { mapDefaultExceptionStaticMacro("Error. Wrong algorithm seemed to be loaded. Image Registration interface is missing. Check DLL."); } //The algorithm is set up and ready to run... } catch (const map::core::ExceptionObject& e) { std::cerr << "ERROR: Caught an MatchPoint exception:\n"; e.Print(std::cerr); std::cerr << "\n"; throw; } /*************************************************************** * Determine registration ***************************************************************/ std::cout << "Starting to determine the registration..." << std::endl; typedef map::algorithm::facet::RegistrationAlgorithmInterface<2, 2> RegistrationAlgorithmType; RegistrationAlgorithmType::RegistrationType::Pointer spRegistration; try { RegistrationAlgorithmType* pAlgorithmInterface = dynamic_cast (spAlgorithmBase.GetPointer()); if (!pAlgorithmInterface) { mapDefaultExceptionStaticMacro("Error. Wrong algorithm seemed to be loaded. Not a 2D-2D algorithm. Check DLL."); } spRegistration = pAlgorithmInterface->getRegistration(); } catch (const map::core::ExceptionObject& e) { std::cerr << "ERROR: Caught an MatchPoint exception:\n"; e.Print(std::cerr); std::cerr << "\n"; throw; } std::cout << std::endl << "Registration determined..." << std::endl; //Thats all. Now we have a registration that map the moving image into the target image //space. But the algorithm only delivers the registration as a mapping function between //moving and target image space. So the moving image must be mapped... /*************************************************************** * Map the data by tasks ***************************************************************/ //define mapping tasks std::cout << "Define mapping task..." << std::endl; typedef map::core::ImageMappingTask ImageMappingTaskType; ImageMappingTaskType::Pointer spImageTask = ImageMappingTaskType::New(); spImageTask->setInputImage(globals.spMovingImage); spImageTask->setRegistration(spRegistration); //Process the task std::cout << "Process mapping task..." << std::endl; spImageTask->execute(); /*************************************************************** * Save or test the results ***************************************************************/ globals.spResultImage = spImageTask->getResultImage(); if (globals.doTest) { result = testResults(globals); } else { result = saveResults(globals); } return result; }