freSetupOptimizationProcessorController.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: freSetupOptimizationProcessorController.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 #include "freSetupOptimizationProcessorController.h"
00023 
00024 #include "freSetupOptimizationMetricControllerBase.h"
00025 #include "freSetupOptimizationOptimizerControllerBase.h"
00026 #include "freSetupTransformController.h"
00027 
00028 namespace FREE
00029 {
00030 
00034 
00035 
00036 
00037 DefineParameterMacro(SetupOptimizationProcessorController,Setup,"Setup","Path to the setup that should be optimized. If a path is set, setup will be loaded automatically.");
00038 DefineParameterMacro(SetupOptimizationProcessorController,AdaptationList,"AdaptationList","Path to the adaptation list used as test basis for the optimization process. If a path is set, adaptation list will be loaded automatically.");
00039 
00040 SetupOptimizationProcessorController::
00041 SetupOptimizationProcessorController() : ComponentControllerBase<ComponentType>()
00042 {
00043   //Profile settings
00044   this->UpdateControllerID(ControllerID::SetupOptimizationProcessorController);
00045   this->m_Description = "Class processing a setup optimization.";
00046 };
00047 
00048 void
00049 SetupOptimizationProcessorController::
00050 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00051                 const SessionComponentCache* pComponentCache,
00052                 bool bRegardOldSetup) const
00053 {
00054   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00055 
00056   //Parameters
00057         profile.Parameters().AddParameter(cParam_Setup,Parameter::PVTURI,cParamDsc_Setup,1,"");
00058   profile.Parameters().AddParameter(cParam_AdaptationList,Parameter::PVTURI,cParamDsc_AdaptationList,1,"");
00059 
00060   //Subcomponents
00061   profile.SubComponents().AddSubComponent(cComp_MainMetric);
00062   profile.SubComponents().AddSubComponent(cComp_MainTransform);
00063   profile.SubComponents().AddSubComponent(cComp_MainOptimizer);
00064 
00065   //Requirements
00066         CtrlProfile::ProfileOption* pOption;
00067     //metric
00068         pOption = profile.Requirements().AddRequirement(cComp_MainMetric)->AddProfileOption();
00069         pOption->Inheritance().AddAncestor(ControllerID::SetupOptimizationMetricControllerBase);
00070         pOption->CheckForInheritance();
00071     //transform
00072         pOption = profile.Requirements().AddRequirement(cComp_MainTransform)->AddProfileOption();
00073         pOption->Inheritance().AddAncestor(ControllerID::SetupTransformControllerBase);
00074         pOption->CheckForInheritance();
00075     //transform
00076         pOption = profile.Requirements().AddRequirement(cComp_MainOptimizer)->AddProfileOption();
00077         pOption->Inheritance().AddAncestor(ControllerID::SetupOptimizationOptimizerControllerBase);
00078         pOption->CheckForInheritance();
00079 };
00080 
00081 SetupOptimizationProcessorController::GenericComponentType* 
00082 SetupOptimizationProcessorController::
00083 GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00084                       SessionComponentCache* pMainComponentCache) const
00085 {
00086         if (compID == cComp_MainMetric) return pMainComponent->GetMetric();
00087         if (compID == cComp_MainTransform) return pMainComponent->GetTransform();
00088         if (compID == cComp_MainOptimizer) return pMainComponent->GetOptimizer();
00089 
00090         return ComponentControllerBase<ComponentType>::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00091 }; 
00092 
00093 void
00094 SetupOptimizationProcessorController::
00095 SetSubComponentCasted(GenericComponentType* pSubComponent, ComponentType* pMainComponent,
00096                       const ComponentID compID, SessionComponentCache* pMainComponentCache) const
00097 {
00098   if (compID == cComp_MainMetric) pMainComponent->SetMetric(static_cast<SetupOptimizationMetric*>(pSubComponent));
00099   else if (compID == cComp_MainTransform) pMainComponent->SetTransform(static_cast<SetupTransform*>(pSubComponent));
00100   else if (compID == cComp_MainOptimizer) pMainComponent->SetOptimizer(static_cast<SetupOptimizationOptimizer*>(pSubComponent));
00101   else ComponentControllerBase<ComponentType>::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00102 }; 
00103 
00104 void
00105 SetupOptimizationProcessorController::
00106 ActualizeMainComponent(ComponentType* pMainComponent,
00107                        SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00108                                                                                          const unsigned int& iActLevel) const
00109 {
00110         std::string sSetupFile;
00111         std::string sAdaptationsFile;
00112 
00113   try
00114   {
00115     SessionAccessor::GetParameterValue(pComponentCache,cParam_Setup,sSetupFile);
00116     SessionAccessor::GetParameterValue(pComponentCache,cParam_AdaptationList,sAdaptationsFile);
00117   }
00118   catchAllNPassMacro("Error while retrieving parameter values.");
00119 
00120   Setup::Pointer smpSetup = Setup::New();
00121 
00122         if (!sSetupFile.empty())
00123         {
00124                 try
00125                 {
00126                         smpSetup->LoadFromFile(sSetupFile);
00127                 }
00128                 catchAllNPassMacro("Unkown error while loading setup for setup optimization processor.");
00129 
00130                 pMainComponent->SetSetup(smpSetup); //also passes the setup to the transform if yet defined.
00131         }
00132 
00133   Adaptation::AdaptationList::Pointer smpAdaptations = Adaptation::AdaptationList::New();
00134 
00135         if (!sAdaptationsFile.empty())
00136         {
00137                 try
00138                 {
00139                         smpAdaptations->LoadFromFile(sAdaptationsFile);
00140                 }
00141                 catchAllNPassMacro("Unkown error while loading adaptation list for setup optimization processor.");
00142 
00143                 pMainComponent->SetAdaptationList(smpAdaptations);
00144         }
00145 };
00146 
00147 void
00148 SetupOptimizationProcessorController::
00149 BuildFinalization(ComponentSetup* pComponentSetup, SessionComponentCache* pComponentCache) const
00150 {
00151   if (!pComponentCache) throwCtrlExceptionMacro("","Error: component cache is invalid (NULL), cannot finalize the building process.");
00152   if (!pComponentCache->ComponentIsAssigned()) throwCtrlExceptionMacro("","Error: component is missing, cannot finalize the building process.");
00153 
00154   ComponentType* pMainComponent = dynamic_cast<ComponentType*>(pComponentCache->Component().GetPointer());
00155 
00156   if (!pMainComponent) throwCtrlExceptionMacro("","Error: wrong main component type, cannot finalize the building process.");
00157 
00158   //plug all subcomponents together to achive proper functionality before the call of pMainComponent->StartOptimization.
00159   //this is needed for the proper use of the optimizer guess functionality in this->ActualizeMainComponent.
00160   pMainComponent->GetMetric()->SetTransform(pMainComponent->GetTransform());
00161   pMainComponent->GetMetric()->SetAdaptationList(pMainComponent->GetAdaptationList());
00162 
00163   pMainComponent->GetOptimizer()->SetCostFunction(pMainComponent->GetMetric());
00164 };
00165 
00166 void
00167 SetupOptimizationProcessorController::
00168 SetStatisticEntrySubComponents(StatisticEntry& rStatisticEntry, SessionComponentCache* pComponentCache,
00169                               SessionInfo* pSessionInfo, StatisticDictionary& rDictionary) const
00170 {
00171   for (unsigned int index=0; index<pComponentCache->SubCaches().Size(); index++)
00172   {
00173     try
00174     {
00175       SessionComponentCache* pSubCache = (pComponentCache->SubCaches()).GetElement(index);
00176 
00177       if (!pSubCache) throwCtrlExceptionMacro("","Error cannot set sub components. Sub cache is present but Null. IDPath: "<<pComponentCache->GetIDPath().ToStr()<<"; sub cache index: "<<index);
00178 
00179       StatisticEntry::Pointer smpSubEntry = rStatisticEntry.CreateChildEntry();
00180 
00181       StatisticEntryDefinition* pSubEntryDef = rDictionary.GetEntryDefinitionByName(pSubCache->GetIDPath(),pSubCache->GetComponentID());
00182       if (!pSubEntryDef)
00183       {
00184         pSubEntryDef = rDictionary.AddEntryDefinition(pSubCache->GetIDPath(),pSubCache->GetComponentID(),pSubCache->GetControllerID(),"sub component information");
00185       }
00186 
00187       smpSubEntry->SetRefID(pSubEntryDef->GetRefID());
00188 
00189       SessionBuilder::SetStatisticEntry(*smpSubEntry, pSubCache, pSessionInfo);
00190     }
00191     catchAllNPassMacro("Error while setting step statistic of subcomponent.");
00192   }
00193 };
00194 
00195 } //end of namespace free

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