00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
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
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);
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 }
00133
00134 #endif