freExhaustiveOptimizerController.cxx

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: freExhaustiveOptimizerController.cxx,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 
00023 #include "freExhaustiveOptimizerController.h"
00024 #include "freExceptions.h"
00025 
00026 namespace FREE
00027 {
00028 
00032 
00033 DefineParameterMacro(ExhaustiveOptimizerController, StepLength, "StepLength", "Steplength of each step in each direction.");
00034 DefineParameterMacro(ExhaustiveOptimizerController, NumberOfSteps, "NumberOfSteps", "Number of steps in each dimension along each direction. Thus there will be (2*NumberOfSteps)+1 steps in each dimension. One value per parameter.");
00035 
00036 ExhaustiveOptimizerController::
00037 ExhaustiveOptimizerController()
00038 {
00039   //Profile settings
00040   this->UpdateControllerID(ControllerID::ExhaustiveOptimizerController);
00041   this->m_Description = "Optimizes by an exhaustive search along the specified grid.";
00042 };
00043 
00044 void
00045 ExhaustiveOptimizerController::
00046 GenerateProfile(CtrlProfile::ControllerProfile& profile, 
00047                 const SessionComponentCache* pComponentCache,
00048                 bool bRegardOldSetup) const
00049 {
00050   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00051 
00052         //Parameters
00053   profile.Parameters().AddParameter(cParam_StepLength,CtrlProfile::Parameter::PVTDouble,cParamDsc_StepLength,1,"1",-1,true);
00054   profile.Parameters().AddParameter(cParam_NumberOfSteps,Parameter::PVTULong,cParamDsc_NumberOfSteps,1,"10",-1,true);
00055 };
00056 
00057 ExhaustiveOptimizerController::
00058 ~ExhaustiveOptimizerController()
00059 {
00060 };
00061 
00062 void
00063 ExhaustiveOptimizerController::
00064 ActualizeMainComponent(ComponentType* pMainComponent,
00065                        SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00066                                                                                          const unsigned int& iActLevel) const
00067 {
00068   double dStepLength;
00069 
00070   try
00071   {
00072     SessionAccessor::GetParameterValue(pComponentCache,cParam_StepLength,dStepLength,0,iActLevel,true);
00073   }
00074   catchAllNPassMacro("Error while retrieving parameter values.");
00075   pMainComponent->SetStepLength(dStepLength);
00076 
00077   ComponentType::StepsType steps;
00078   
00079   Parameter::Pointer smpSteps = SessionAccessor::GetParameter(pComponentCache,cParam_NumberOfSteps);
00080   if (smpSteps.IsNull()) throwCtrlExceptionMacro("","Error; missing Parameter, cannot get "<<cParam_NumberOfSteps<<".");
00081   if (smpSteps->LayerCount()==0) throwCtrlExceptionMacro("","Error; parameter "<<cParam_NumberOfSteps<<" has no layer. Please check if the setup is valid.");
00082   unsigned int i = iActLevel;
00083   if (i>=smpSteps->LayerCount()) i = smpSteps->LayerCount()-1;
00084   steps = Convert::ParameterLayerToArray<ComponentType::StepsType>(*(smpSteps->GetParameterLayer(i)));
00085   pMainComponent->SetNumberOfSteps(steps);
00086 
00087   ParameterArrayType scales = this->GetTransformScales(pComponentCache,iActLevel);
00088   pMainComponent->SetScales(scales);
00089 };
00090 
00091 void
00092 ExhaustiveOptimizerController::
00093 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00094                                              ComponentType* pMainComponent,
00095                                              SessionComponentCache* pMainComponentCache,
00096                                              SessionInfo* pSessionInfo,
00097                                              StatisticDictionary& rDictionary) const
00098 {
00099   Superclass::SetStatisticEntryMainComponent(rStatisticEntry, pMainComponent, pMainComponentCache,
00100                                             pSessionInfo, rDictionary);
00101   std::string sName = "OptimizerValue";
00102   std::string sIDPath = pMainComponentCache->GetIDPath();
00103   StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath, sName);
00104     
00105   if (!pEntry) //Entry is not recorded yet, so do so.
00106   {
00107     pEntry = rDictionary.AddValueDefinition(sName, sIDPath, "Current value of the optimizer");
00108   }
00109 
00110   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCurrentValue()),pEntry->GetRefID());
00111 };
00112 
00113 ExhaustiveOptimizerController::MeasuresType
00114 ExhaustiveOptimizerController::
00115 GetCurrentValue(ComponentType* pOptimizer) const
00116 {
00117         MeasuresType values(1);
00118         values.Fill(pOptimizer->GetCurrentValue());
00119         return values;
00120 };
00121 
00122 } //end of namespace free

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