From: delmon Date: Thu, 10 Mar 2011 16:14:11 +0000 (+0000) Subject: Romulo: X-Git-Tag: v1.2.0~184 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=f2e26bdbb8afd27a2db962db87889f355865396a;p=clitk.git Romulo: - Added functionality to generate the BSpline coefficients during the registration. - Added new command-line option --CoeffEveryN (requires --coeff and --verbose) - see ggo file - Created new observer class (as specified by ITK) to catch iteration events triggered by the optmizer --- diff --git a/registration/clitkBLUTDIR.ggo b/registration/clitkBLUTDIR.ggo index 8be34e7..55ac19f 100755 --- a/registration/clitkBLUTDIR.ggo +++ b/registration/clitkBLUTDIR.ggo @@ -25,6 +25,7 @@ section "Output" option "vf" - "Result DVF" string yes option "coeff" - "Result coefficient images" string no +option "coeffEveryN" - "Result coefficient images at every N iterations (requires --coeff and --verbose)" int no default="20" option "output" o "Deformed target image" string yes option "before" - "Difference image before (but after rigid transform)" string no option "after" - "Difference image after " string no diff --git a/registration/clitkBLUTDIRCommandIterationUpdateDVF.h b/registration/clitkBLUTDIRCommandIterationUpdateDVF.h new file mode 100644 index 0000000..7a113e5 --- /dev/null +++ b/registration/clitkBLUTDIRCommandIterationUpdateDVF.h @@ -0,0 +1,119 @@ +/*========================================================================= +Program: vv http://www.creatis.insa-lyon.fr/rio/vv + +Authors belong to: +- University of LYON http://www.universite-lyon.fr/ +- Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr +- CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the copyright notices for more information. + +It is distributed under dual licence + +- BSD See included LICENSE.txt file +- CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ +#ifndef clitkBLUTDIRCommandIterationUpdateDVF_h +#define clitkBLUTDIRCommandIterationUpdateDVF_h + +/* ================================================= + * @file clitkBLUTDIRCommandIterationUpdateDVF.h + * @author Romulo Pinho + * @date 16/02/2011 + * + * @brief ITK observer class to respond to iteration events of B-LUT DIR. This + * observer is meant to output the DVF of the registration at each iteration. + * + ===================================================*/ + +#include "clitkBLUTDIRGenericFilter.h" + +namespace clitk +{ + template + class CommandIterationUpdateDVF : public itk::Command + { + public: + typedef CommandIterationUpdateDVF Self; + typedef itk::Command Superclass; + typedef itk::SmartPointer Pointer; + itkNewMacro( Self ); + protected: + CommandIterationUpdateDVF() : m_Iteration(0) {}; + public: + + typedef typename FixedImageType::Pointer ImagePointer; + typedef typename TransformType::Pointer TransformPointer; + + // Set the fixed image, from the specs of the DVF are obtained. + void SetFixedImage(ImagePointer i) { m_FixedImage = i; } + + // Set the transform + void SetTransform(TransformPointer t){ m_Transform = t;} + + // Set command line parameters + void SetArgsInfo(args_info_clitkBLUTDIR a){m_ArgsInfo=a;} + + // Execute + void Execute(itk::Object *object, const itk::EventObject & event) + { + //Execute( (const itk::Object *)caller, event); + if( !(itk::IterationEvent().CheckEvent( &event )) ) + { + std::cout << "CommandIterationUpdateDVF::Execute(): check event failed!\n"; + return; + } + + std::cout << "CommandIterationUpdateDVF::Execute()\n"; + + typedef typename OptimizerType::ParametersType ParametersType; + OptimizerType* optmizer = dynamic_cast(object); + ParametersType parameters = optmizer->GetCurrentPosition(); + std::cout << "Iteration " << ++m_Iteration << endl;// << " -> Optimizer parameters: " << parameters << endl; + + //======================================================= + // RP: Copy-paste from BLUTDIRGenericFilter::UpdateWithInputImageType() + //======================================================= + //======================================================= + // Get the BSpline coefficient images and write them + //======================================================= + int niter = m_ArgsInfo.coeffEveryN_arg; + if ((m_Iteration % niter == 0) && m_ArgsInfo.coeff_given) + { + typedef typename TransformType::CoefficientImageType CoefficientImageType; + std::vector coefficientImages = m_Transform->GetCoefficientImages(); + typedef itk::ImageFileWriter CoeffWriterType; + typename CoeffWriterType::Pointer coeffWriter = CoeffWriterType::New(); + unsigned nLabels = m_Transform->GetnLabels(); + + std::string fname(m_ArgsInfo.coeff_arg); + int dotpos = fname.length() - 1; + while (dotpos >= 0 && fname[dotpos] != '.') + dotpos--; + + for (unsigned i = 0; i < nLabels; ++i) + { + std::ostringstream osfname; + osfname << fname.substr(0, dotpos) << '_' << i << '_' << m_Iteration << fname.substr(dotpos); + coeffWriter->SetInput(coefficientImages[i]); + coeffWriter->SetFileName(osfname.str()); + coeffWriter->Update(); + } + } + } + + void Execute(const itk::Object * object, const itk::EventObject & event) + { + std::cout << "const CommandIterationUpdateDVF::Execute()\n"; + } + + unsigned int m_Iteration; + ImagePointer m_FixedImage; + TransformPointer m_Transform; + args_info_clitkBLUTDIR m_ArgsInfo; + }; +} + +#endif // clitkBLUTDIRCommandIterationUpdateDVF_h diff --git a/registration/clitkBLUTDIRGenericFilter.cxx b/registration/clitkBLUTDIRGenericFilter.cxx index c8c42f0..dbb38e3 100755 --- a/registration/clitkBLUTDIRGenericFilter.cxx +++ b/registration/clitkBLUTDIRGenericFilter.cxx @@ -28,6 +28,7 @@ It is distributed under dual licence ===================================================*/ #include "clitkBLUTDIRGenericFilter.h" +#include "clitkBLUTDIRCommandIterationUpdateDVF.h" namespace clitk { @@ -78,7 +79,7 @@ namespace clitk { InitializeImageType<2>(); InitializeImageType<3>(); - m_Verbose=true; + m_Verbose=false; } //=========================================================================// @@ -93,6 +94,8 @@ namespace clitk } if (m_ArgsInfo.output_given) SetOutputFilename(m_ArgsInfo.output_arg); + + if (m_ArgsInfo.verbose_given) m_Verbose=true; } //=========================================================================// @@ -273,6 +276,8 @@ namespace clitk template void BLUTDIRGenericFilter::UpdateWithInputImageType() { + if (m_Verbose) std::cout << "BLUTDIRGenericFilter::UpdateWithInputImageType()" << std::endl; + //============================================================================= //Input //============================================================================= @@ -667,6 +672,17 @@ namespace clitk command->SetMaximize(genericMetric->GetMaximize()); command->SetMetricRegion(metricRegion); registration->AddObserver( itk::IterationEvent(), command ); + + if (m_ArgsInfo.coeff_given) + { + std::cout << std::endl << "Output coefficient images every " << m_ArgsInfo.coeffEveryN_arg << " iterations." << std::endl; + typedef CommandIterationUpdateDVF DVFCommandType; + typename DVFCommandType::Pointer observerdvf = DVFCommandType::New(); + observerdvf->SetFixedImage(fixedImage); + observerdvf->SetTransform(transform); + observerdvf->SetArgsInfo(m_ArgsInfo); + optimizer->AddObserver( itk::IterationEvent(), observerdvf ); + } }