freConstrainedAccuracySOMetricController.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: freConstrainedAccuracySOMetricController.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 __freConstrainedAccuracySOMetricController_h
00023 #define __freConstrainedAccuracySOMetricController_h
00024 
00025 #include "freAccuracySOMetricController.h"
00026 
00027 #include "freConstrainedAccuracySOMetric.h"
00028 
00029 namespace FREE
00030 {
00031 
00032 freControllerIDMacro(ConstrainedAccuracySOMetricControllerBase, "ConstrainedAccuracySOMetricBase");
00042 template <class TControlledMetric>
00043 class ConstrainedAccuracySOMetricControllerBase : public AccuracySOMetricControllerBase<TControlledMetric>
00044 {
00045 public:  
00046   DeclareParameterMacro(MaxConstraintPenalty);
00047   DeclareParameterMacro(FailureThreshold);
00048   DeclareParameterMacro(Constraints);
00049 
00050         typedef TControlledMetric ComponentType;
00051   typedef AccuracySOMetricControllerBase<ComponentType> Superclass;
00052 
00053         itkTypeMacro(ConstrainedAccuracySOMetricControllerBase, AccuracySOMetricControllerBase);
00054 
00055 protected:
00056         ConstrainedAccuracySOMetricControllerBase()
00057         {
00058                 //Profile settings
00059                 this->UpdateControllerID(ControllerID::ConstrainedSetupOptimizationMetricControllerBase);
00060                 this->UpdateControllerID(ControllerID::AccuracySOMetricControllerBase);
00061                 this->UpdateControllerID(ControllerID::ConstrainedAccuracySOMetricControllerBase);
00062                 this->m_Description = "Base class for accuracy registration metric which supports constraints.";
00063         };
00064 
00065   virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00066                   const SessionComponentCache* pComponentCache,
00067                   bool bRegardOldSetup) const
00068   {
00069     Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00070 
00071                 //Parameters
00072                 profile.Parameters().AddParameter(cParam_Constraints,CtrlProfile::Parameter::PVTString,cParamDsc_Constraints,4,"",-1);
00073                 profile.Parameters().AddParameter(cParam_MaxConstraintPenalty,CtrlProfile::Parameter::PVTDouble,cParamDsc_MaxConstraintPenalty,1,"0");
00074                 profile.Parameters().AddParameter(cParam_FailureThreshold,CtrlProfile::Parameter::PVTDouble,cParamDsc_FailureThreshold,1,"0.0");
00075   };
00076 
00077         virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00078                                       SessionComponentCache* pComponentCache,
00079                                       SessionInfo* pSessionInfo,
00080                                                                                                                                                         const unsigned int& iActLevel) const
00081         {
00082                 Superclass::ActualizeMainComponent(pMainComponent, pComponentCache,
00083                                                                                                                                                          pSessionInfo, iActLevel);
00084 
00085                 double dMaxPenalty;
00086                 double dThreshold;
00087 
00088     Parameter::Pointer smpConstraints = SessionAccessor::GetParameter(pComponentCache,cParam_Constraints);
00089                 if (smpConstraints.IsNull()) throwExceptionMacro("Missing parameter: " << cParam_Constraints);
00090 
00091                 for (unsigned int index = 0; index < smpConstraints->LayerCount(); index++)
00092                 {
00093                         int iParamID;
00094                         std::string sRelationType;
00095                         std::string sTerm;
00096                         double dBarrierSize;
00097 
00098                         if (!smpConstraints->GetParameterValue(iParamID,0,index)) throwExceptionMacro("Faulty parameter; cannot retrieve parameter id. constraint #: " << index);
00099                         if (!smpConstraints->GetParameterValue(sRelationType,1,index)) throwExceptionMacro("Faulty parameter; cannot retrieve relation type. constraint #: " << index);
00100                         if (!smpConstraints->GetParameterValue(sTerm,2,index)) throwExceptionMacro("Faulty parameter; cannot retrieve constraint term. constraint #: " << index);
00101                         if (!smpConstraints->GetParameterValue(dBarrierSize,3,index)) throwExceptionMacro("Faulty parameter; cannot retrieve barrier size. constraint #: " << index);
00102 
00103       SetupParameterConstraint::Pointer smpNewCnstr = SetupParameterConstraint::New(iParamID,Convert::ToRelationType(sRelationType),sTerm);
00104                         pMainComponent->AddConstraint(*(smpNewCnstr.GetPointer()),dBarrierSize);
00105                 }
00106 
00107     try
00108     {
00109       SessionAccessor::GetParameterValue(pComponentCache,cParam_MaxConstraintPenalty,dMaxPenalty);
00110       SessionAccessor::GetParameterValue(pComponentCache,cParam_FailureThreshold,dThreshold);
00111     }
00112     catchAllNPassMacro("Error while retrieving parameter values.");    
00113 
00114                 pMainComponent->SetMaxConstraintPenalty(dMaxPenalty);
00115                 pMainComponent->SetFailureThreshold(dThreshold);
00116         };
00117 
00118         void
00119         SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00120                                              ComponentType* pMainComponent,
00121                                              SessionComponentCache* pMainComponentCache,
00122                                              SessionInfo* pSessionInfo,
00123                                              StatisticDictionary& rDictionary) const
00124         {
00125                 typename ComponentType::DecomposedMeasureType values = pMainComponent->GetCurrentDecomposedValue();
00126 
00127                 std::string sIDPath = pMainComponentCache->GetIDPath();
00128                 StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,"mean error");
00129             
00130                 if (!pEntry) //Entry is not recorded yet, so do so.
00131                 {
00132                         pEntry = rDictionary.AddValueDefinition(sIDPath,"mean error", "mean error of the registration.");
00133                         rDictionary.AddValueDefinition(sIDPath,"std error", "standard deviation of the error.");
00134                         rDictionary.AddValueDefinition(sIDPath,"min error", "minimum error of the registration.");
00135                         rDictionary.AddValueDefinition(sIDPath,"max error", "maximum error of the registration.");
00136                         rDictionary.AddValueDefinition(sIDPath,"failure", "number of failed registration.");
00137                         rDictionary.AddValueDefinition(sIDPath,"unevaluated points", "number of reference points that could not be evaluated.");
00138                         rDictionary.AddValueDefinition(sIDPath,"mean duration", "mean duration of a registration (tenth of a second).");
00139                         rDictionary.AddValueDefinition(sIDPath,"std duration", "standard deviation of a registration (tenth of a second).");
00140                         rDictionary.AddValueDefinition(sIDPath,"min duration", "minimum duration of a registration (tenth of a second).");
00141                         rDictionary.AddValueDefinition(sIDPath,"max duration", "maximum duration of a registration (tenth of a second).");
00142   
00143                         for (unsigned int i = 0; i<values.Size()-10; i++)
00144                         {
00145                                 rDictionary.AddValueDefinition(sIDPath,"constraint penalty #"+Convert::ToStr(i), "penalty of the constraint #"+Convert::ToStr(i));
00146                         }
00147                 }
00148           
00149                 for (unsigned int i = 0; i<values.Size(); i++)
00150                 {
00151                         rStatisticEntry.AddValue(Convert::ToStr(values[i]),pEntry->GetRefID()+i);
00152                 }
00153         };
00154 
00155 };
00156 
00157 template <class TControlledMetric>
00158 const char* const ConstrainedAccuracySOMetricControllerBase<TControlledMetric>::cParam_Constraints = "Constraints";
00159 template <class TControlledMetric>
00160 const char* const ConstrainedAccuracySOMetricControllerBase<TControlledMetric>::cParamDsc_Constraints = "The constraints of the metric. First element is the ID of the constrained parameter, second value indicates the type of relation (0: equal; 1: lesser or equal; 2: greater or equal). The third value is the constraint term. The fourth value is the barrier size.\nParameter IDs, if used in the term have an underscore as prefix.\nExample: 1 | 2 | (_2 * 4) + _3\nBy this constrained parameter 1 should be greater or equal four times parameter 2 + parameter 3.";
00161 
00162 template <class TControlledMetric>
00163 const char* const ConstrainedAccuracySOMetricControllerBase<TControlledMetric>::cParam_MaxConstraintPenalty = "MaxConstraintPenalty";
00164 template <class TControlledMetric>
00165 const char* const ConstrainedAccuracySOMetricControllerBase<TControlledMetric>::cParamDsc_MaxConstraintPenalty = "Maximum penalty the barrier function of a constraint can return. This value will be scaled be metric scales, if there is any defined for a constrained.";
00166 
00167 template <class TControlledMetric>
00168 const char* const ConstrainedAccuracySOMetricControllerBase<TControlledMetric>::cParam_FailureThreshold = "FailureThreshold";
00169 template <class TControlledMetric>
00170 const char* const ConstrainedAccuracySOMetricControllerBase<TControlledMetric>::cParamDsc_FailureThreshold = "Threshold for the penalty computation, if the penalty is equal or above this threshold, the computation will be accounted as a failure. No evaluations of the adaptations will be done. A value of 0.0 or less deactivates the threshold.";
00171 
00172 freControllerIDMacro(ConstrainedAccuracy2DSOMetricController, "Constrained Accuracy 2D SO Metric");
00173 
00182 class ConstrainedAccuracy2DSOMetricController : public ConstrainedAccuracySOMetricControllerBase< ConstrainedAccuracySOMetric<2> >
00183 {
00184 public:  
00185   typedef ConstrainedAccuracySOMetric<2> ComponentType;
00186   typedef ConstrainedAccuracySOMetricControllerBase<ComponentType> Superclass;
00187 
00188         itkTypeMacro(ConstrainedAccuracy2DSOMetricController, ConstrainedAccuracySOMetricControllerBase);
00189 
00190   ConstrainedAccuracy2DSOMetricController();
00191 
00192 };
00193 
00194 freControllerIDMacro(ConstrainedAccuracy3DSOMetricController, "Constrained Accuracy 3D SO Metric");
00195 
00204 class ConstrainedAccuracy3DSOMetricController : public ConstrainedAccuracySOMetricControllerBase< ConstrainedAccuracySOMetric<3> >
00205 {
00206 public:  
00207   typedef ConstrainedAccuracySOMetric<3> ComponentType;
00208   typedef ConstrainedAccuracySOMetricControllerBase<ComponentType> Superclass;
00209 
00210         itkTypeMacro(ConstrainedAccuracy3DSOMetricController, ConstrainedAccuracySOMetricControllerBase);
00211 
00212   ConstrainedAccuracy3DSOMetricController();
00213 
00214 };
00215 
00216 } //end of namespace free
00217 
00218 #endif

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