00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "freConjugateGradientOptimizerController.h"
00024 #include "freExceptions.h"
00025 #include "freTransformSetupAdaptor.h"
00026
00027 namespace FREE
00028 {
00029
00033
00034
00035 ConjugateGradientOptimizerController::
00036 ConjugateGradientOptimizerController()
00037 {
00038
00039 this->UpdateControllerID(ControllerID::ConjugateGradientOptimizerController);
00040 this->m_Description = "Optimizes by a conjugate gradient optimizer approach.";
00041
00042
00043 };
00044
00045 ConjugateGradientOptimizerController::
00046 ~ConjugateGradientOptimizerController()
00047 {
00048 };
00049
00050 void
00051 ConjugateGradientOptimizerController::
00052 ActualizeMainComponent(ComponentType* pMainComponent,
00053 SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00054 const unsigned int& iActLevel) const
00055 {
00056 ComponentSetup* pTransformSetup = pComponentCache->Setup()->GetComponentByIDPath("../"+ComponentID(cComp_MainTransform));
00057 if (!pTransformSetup) throwCtrlExceptionMacro("","Error; no main transform found to actualize the optimizer.");
00058 TransformSetupAdaptor adaptor(pTransformSetup);
00059
00060 pMainComponent->SetScales(adaptor.GetScales(iActLevel));
00061
00062 Parameter::Pointer smpDirection = pComponentCache->GetParentCache()->Controller()->GetParameter(pComponentCache->GetParentCache(),OptimizerOwnerControllerInterface::cParam_MinimizeToOptimize);
00063 if (smpDirection.IsNull()) throwCtrlExceptionMacro("","Cannot retrieve optimization direction via optimizer owner. Parameter \"MinimizeToOptimize\" is unknown. Please ensure valid session and setup");
00064 bool bMinimize;
00065 smpDirection->GetParameterValue(bMinimize);
00066 pMainComponent->SetMaximize( !bMinimize);
00067 };
00068
00069 void
00070 ConjugateGradientOptimizerController::
00071 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00072 ComponentType* pMainComponent,
00073 SessionComponentCache* pMainComponentCache,
00074 SessionInfo* pSessionInfo,
00075 StatisticDictionary& rDictionary) const
00076 {
00077 ParameterArrayType parameters = pMainComponent->GetCachedCurrentPosition();
00078 std::string sName = "Position #";
00079 std::string sIDPath = pMainComponentCache->GetIDPath();
00080 std::string sCommment = "Optimizer position. Meaning depends on chosen transformation";
00081 StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,sName+"0");
00082
00083 if (!pEntry)
00084 {
00085 pEntry = rDictionary.AddValueDefinition(sIDPath,sName+"0", sCommment);
00086 for (unsigned int i = 1; i<parameters.Size(); i++)
00087 {
00088 rDictionary.AddValueDefinition(sIDPath,sName+Convert::ToStr(i),sCommment);
00089 }
00090 rDictionary.AddValueDefinition(sIDPath,"OptimizerValue", "Value of the optimizer");
00091 }
00092
00093 for (unsigned int i = 0; i<parameters.Size(); i++)
00094 {
00095 rStatisticEntry.AddValue(Convert::ToStr(parameters.GetElement(i)),pEntry->GetRefID()+i);
00096 }
00097
00098 rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCachedValue()),pEntry->GetRefID()+parameters.Size());
00099 };
00100
00101 }