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