freHistogramMetricControllerBase.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freHistogramMetricControllerBase.h,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 #ifndef __freHistogramMetricControllerBase_h
00023 #define __freHistogramMetricControllerBase_h
00024 
00025 #include "freImageToImageMetricControllerBase.h"
00026 #include "freTransformSetupAdaptor.h"
00027 
00028 #include "itkHistogramImageToImageMetric.h"
00029 
00030 namespace FREE
00031 {
00032 
00042   freControllerIDMacro( HistogramMetricControllerBase, "HistogramMetricBase");
00043 template <class TControlledMetric>
00044 class HistogramMetricControllerBase : public ImageToImageMetricControllerBase< TControlledMetric >
00045 {
00046 public:  
00047   typedef TControlledMetric ComponentType;
00048   typedef ImageToImageMetricControllerBase<ComponentType> Superclass;
00049 
00050   itkTypeMacro( HistogramMetricControllerBase, ImageToImageMetricControllerBase);
00051 
00052 protected:
00055   HistogramMetricControllerBase()
00056   {
00057                 //Profile settings
00058     this->UpdateControllerID(ControllerID::HistogramMetricControllerBase);
00059     this->m_Description = "Base class for metrics using the intensity histograms.";
00060         };
00061 
00062   virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00063                                  const SessionComponentCache* pComponentCache,
00064                                  bool bRegardOldSetup) const
00065   {
00066       Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00067 
00068       //Parameters
00069       profile.Parameters().AddParameter(cParam_HistSize,Parameter::PVTULong,cParamDsc_HistSize,2,"255",-1,true);
00070       profile.Parameters().AddParameter(cParam_HistPadValue,Parameter::PVTLong,cParamDsc_HistPadValue,1,"-1",-1,true);
00071       profile.Parameters().AddParameter(cParam_HistDerivativeStep,Parameter::PVTDouble,cParamDsc_HistDerivativeStep,1,"0.1",-1,true);
00072                   profile.Parameters().AddParameter(cParam_UpperBoundIncreaseFactor,Parameter::PVTDouble,cParamDsc_UpperBoundIncreaseFactor,1,"0.001");
00073 
00074       //The number of scales must be equal to the number of transformations added to the registration "MainTransform"
00075       int iScaleCount = 1;
00076       if (pComponentCache)
00077       {
00078         Parameter::Pointer smpTransformParams = SessionAccessor::GetParameterByIDPath(pComponentCache,IDPath("../MainTransform/TransformScale"));
00079         if (smpTransformParams.IsNotNull())
00080         {
00081           iScaleCount = smpTransformParams->ParameterSize();
00082         }
00083       }
00084 
00085       profile.Parameters().AddParameter(cParam_HistDerivativeScales,Parameter::PVTDouble,cParamDsc_HistDerivativeScales,iScaleCount,"0",-1,true);
00086   };
00087 
00092         virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00093                                       SessionComponentCache* pComponentCache,
00094                                       SessionInfo* pSessionInfo,
00095                                                                                                                                                         const unsigned int& iActLevel) const
00096         {
00097                 unsigned long lHistSize;
00098     long lPadValue;
00099     double dDerivativeStep;
00100     bool bDerivativeScales;
00101                 double dUpperBoundFactor;
00102     itk::Size<2> histSize;
00103     try
00104     {
00105       SessionAccessor::GetParameterValue(pComponentCache,cParam_HistSize,lHistSize,0,iActLevel,true);
00106       histSize[0] = lHistSize;
00107       SessionAccessor::GetParameterValue(pComponentCache,cParam_HistSize,lHistSize,1,iActLevel,true);
00108       histSize[1] = lHistSize;
00109 
00110       SessionAccessor::GetParameterValue(pComponentCache,cParam_HistPadValue,lPadValue,0,iActLevel,true);
00111       SessionAccessor::GetParameterValue(pComponentCache,cParam_HistDerivativeStep,dDerivativeStep,0,iActLevel,true);
00112       SessionAccessor::GetParameterValue(pComponentCache,cParam_HistDerivativeScales,bDerivativeScales,0,iActLevel,true);
00113       SessionAccessor::GetParameterValue(pComponentCache,cParam_UpperBoundIncreaseFactor,dUpperBoundFactor,0,iActLevel,true);
00114     }
00115     catchAllNPassMacro("Error while retrieving parameter values.");   
00116 
00117     TransformSetupAdaptor adaptor(pComponentCache->Setup()->GetComponentByIDPath("../"+ComponentID(cComp_MainTransform)));
00118     if (adaptor.GetActualComponent()==NULL) throwCtrlExceptionMacro("","No main transform found to get the number of transform parameters. Ensure to use the metric with a rigid registration processor.");
00119 
00120     itk::Array<double> scales = adaptor.GetScales(iActLevel);
00121     if (!bDerivativeScales) scales.Fill(1); //if !bDerivativeScales, all parameters should be treated equal
00122 
00123     pMainComponent->SetHistogramSize( histSize );
00124     pMainComponent->SetPaddingValue( lPadValue );
00125     pMainComponent->SetUsePaddingValue( lPadValue>-1 );
00126     pMainComponent->SetDerivativeStepLength( dDerivativeStep );
00127     pMainComponent->SetDerivativeStepLengthScales( scales );
00128                 pMainComponent->SetUpperBoundIncreaseFactor( dUpperBoundFactor );
00129   };
00130 };
00131 
00132 } //end of namespace free
00133 
00134 #endif

Generated at Sat Oct 13 16:02:18 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000