freVersorTransformOptimizerController.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: freVersorTransformOptimizerController.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 "freVersorTransformOptimizerController.h"
00024 #include "freExceptions.h"
00025 
00026 namespace FREE
00027 {
00028 
00032 
00033 
00034 VersorTransformOptimizerController::
00035 VersorTransformOptimizerController()
00036 {
00037   //Profile settings
00038   this->UpdateControllerID(ControllerID::VersorTransformOptimizerController);
00039   this->m_Description = "Optimizes versor transformations.";
00040 };
00041 
00042 void
00043 VersorTransformOptimizerController::
00044 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00045                 const SessionComponentCache* pComponentCache,
00046                 bool bRegardOldSetup) const
00047 {
00048   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00049 
00050         //Parameters
00051   profile.Parameters().AddParameter(cParam_DynamicLevelStepLength,Parameter::PVTBool,cParamDsc_DynamicLevelStepLength,1,"true",-1,true);
00052   profile.Parameters().AddParameter(cParam_MaxStepLength,CtrlProfile::Parameter::PVTDouble,cParamDsc_MaxStepLength,1,"1.0",-1,true);
00053   profile.Parameters().AddParameter(cParam_MinStepLength,CtrlProfile::Parameter::PVTDouble,cParamDsc_MinStepLength,1,"0.01",-1,true);
00054   profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTULong,cParamDsc_Iterations,1,"100",-1,true);
00055   profile.Parameters().AddParameter(cParam_GradMagTolerance,CtrlProfile::Parameter::PVTDouble,cParamDsc_GradMagTolerance,1,"0.0001",-1,true);
00056 
00057   //Only verso transforms are allowed to interact with these optimizer
00058   //in the same registration processor, to ensure proper optimization. 
00059         CtrlProfile::ProfileOption* pOption = profile.Requirements().AddRequirement(std::string("../")+cComp_MainTransform)->AddProfileOption();
00060         pOption->Inheritance().AddAncestor("Versor Transform");
00061         pOption->CheckForInheritance();
00062 };
00063 
00064 void
00065 VersorTransformOptimizerController::
00066 ActualizeMainComponent(ComponentType* pMainComponent,
00067                        SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00068                                                                                          const unsigned int& iActLevel) const
00069 {
00070   double dMaxStepLength;
00071   double dMinStepLength;
00072   unsigned long lNrOfIterations;
00073   double dGradMagTolerance;
00074   bool bDynamicLevelStepLength;
00075 
00076   try
00077   {
00078     SessionAccessor::GetParameterValue(pComponentCache,cParam_DynamicLevelStepLength,bDynamicLevelStepLength,0,iActLevel,true);
00079     SessionAccessor::GetParameterValue(pComponentCache,cParam_MaxStepLength,dMaxStepLength,0,iActLevel,true);
00080     SessionAccessor::GetParameterValue(pComponentCache,cParam_MinStepLength,dMinStepLength,0,iActLevel,true);
00081     SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,lNrOfIterations,0,iActLevel,true);
00082     SessionAccessor::GetParameterValue(pComponentCache,cParam_GradMagTolerance,dGradMagTolerance,0,iActLevel,true);
00083   }
00084   catchAllNPassMacro("Error while retrieving parameter values.");
00085 
00086   ParameterArrayType scales = this->GetTransformScales(pComponentCache,iActLevel);
00087   pMainComponent->SetScales(scales);
00088 
00089   Parameter::Pointer smpDirection = pComponentCache->GetParentCache()->Controller()->GetParameter(pComponentCache->GetParentCache(),OptimizerOwnerControllerInterface::cParam_MinimizeToOptimize);
00090   if (smpDirection.IsNull()) throwCtrlExceptionMacro("","Cannot retrieve optimization direction via optimizer owner. Parameter \"MinimizeToOptimize\" is unknown. Please ensure valid session and setup");
00091   bool bMinimize;
00092   smpDirection->GetParameterValue(bMinimize);
00093   pMainComponent->SetMaximize( !bMinimize);
00094 
00095   pMainComponent->SetNumberOfIterations(lNrOfIterations);
00096   pMainComponent->SetGradientMagnitudeTolerance(dGradMagTolerance);
00097   pMainComponent->SetMinimumStepLength(dMinStepLength);
00098 
00099   if ((iActLevel!=0)&(bDynamicLevelStepLength)) pMainComponent->SetMaximumStepLength(pMainComponent->GetCurrentStepLength());
00100   pMainComponent->SetMaximumStepLength(dMaxStepLength);
00101 };
00102 
00103 void
00104 VersorTransformOptimizerController::
00105 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00106                                              ComponentType* pMainComponent,
00107                                              SessionComponentCache* pMainComponentCache,
00108                                              SessionInfo* pSessionInfo,
00109                                              StatisticDictionary& rDictionary) const
00110 {
00111   Superclass::SetStatisticEntryMainComponent(rStatisticEntry,pMainComponent,
00112                                             pMainComponentCache,pSessionInfo,
00113                                             rDictionary);
00114   
00115   std::string sName = "OptimizerValue";
00116   std::string sIDPath = pMainComponentCache->GetIDPath();
00117   StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath, sName);
00118     
00119   if (!pEntry) //Entry is not recorded yet, so do so.
00120   {
00121     pEntry = rDictionary.AddValueDefinition(sName, sIDPath,"Value of the Optimizer");
00122   }
00123 
00124   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetValue()),pEntry->GetRefID());
00125 };
00126 
00127 VersorTransformOptimizerController::MeasuresType
00128 VersorTransformOptimizerController::
00129 GetCurrentValue(ComponentType* pOptimizer) const
00130 {
00131         MeasuresType values(1);
00132         values.Fill(pOptimizer->GetValue());
00133         return values;
00134 };
00135 
00136 } //end of namespace free

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