00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freOptimizerControllerBase_txx
00023 #define __freOptimizerControllerBase_txx
00024
00025 #include "freOptimizerControllerBase.h"
00026
00027 namespace FREE
00028 {
00029
00033
00034
00035 template <class TControlledOptimizer>
00036 OptimizerControllerBase<TControlledOptimizer>::
00037 OptimizerControllerBase():ComponentControllerBase<TControlledOptimizer>()
00038 {
00039 this->UpdateControllerID(ControllerID::OptimizerControllerBase);
00040 this->m_Description = "Base class for optimizer controller; not for practical use.";
00041 };
00042
00043 template <class TControlledOptimizer>
00044 void
00045 OptimizerControllerBase<TControlledOptimizer>::
00046 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00047 ComponentType* pMainComponent,
00048 SessionComponentCache* pMainComponentCache,
00049 SessionInfo* pSessionInfo,
00050 StatisticDictionary& rDictionary) const
00051 {
00052 ParameterArrayType parameters = pMainComponent->GetCurrentPosition();
00053 std::string sName = "Position #";
00054 std::string sIDPath = pMainComponentCache->GetIDPath();
00055 std::string sCommment = "Optimizer position. Meaning depends on chosen transformation";
00056 StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,sName+"0");
00057
00058 if (!pEntry)
00059 {
00060 pEntry = rDictionary.AddValueDefinition(sIDPath,sName+"0", sCommment);
00061 for (unsigned int i = 1; i<parameters.Size(); i++)
00062 {
00063 rDictionary.AddValueDefinition(sIDPath,sName+Convert::ToStr(i),sCommment);
00064 }
00065 }
00066
00067 for (unsigned int i = 0; i<parameters.Size(); i++)
00068 {
00069 rStatisticEntry.AddValue(Convert::ToStr(parameters.GetElement(i)),pEntry->GetRefID()+i);
00070 }
00071 };
00072
00073 template <class TControlledOptimizer>
00074 typename OptimizerControllerBase<TControlledOptimizer>::ParametersType
00075 OptimizerControllerBase<TControlledOptimizer>::
00076 GetCurrentPosition(const SessionComponentCache* pComponentCache) const
00077 {
00078 if (!pComponentCache) throwCtrlExceptionMacro("","Passed pComponentCache is NULL.");
00079 if (!pComponentCache->ComponentIsAssigned()) throwCtrlExceptionMacro("","Cache has no component assigned.");
00080
00081 return GetCurrentPosition(dynamic_cast<TControlledOptimizer*>(pComponentCache->Component().GetPointer()));
00082 };
00083
00084 template <class TControlledOptimizer>
00085 typename OptimizerControllerBase<TControlledOptimizer>::ParametersType
00086 OptimizerControllerBase<TControlledOptimizer>::
00087 GetCurrentPosition(TControlledOptimizer* pOptimizer) const
00088 {
00089 return pOptimizer->GetCurrentPosition();
00090 };
00091
00092 template <class TControlledOptimizer>
00093 typename OptimizerControllerBase<TControlledOptimizer>::MeasuresType
00094 OptimizerControllerBase<TControlledOptimizer>::
00095 GetCurrentValue(const SessionComponentCache* pComponentCache) const
00096 {
00097 if (!pComponentCache) throwCtrlExceptionMacro("","Passed pComponentCache is NULL.");
00098 if (!pComponentCache->ComponentIsAssigned()) throwCtrlExceptionMacro("","Cache has no setup assigned.");
00099
00100 return GetCurrentValue(static_cast<TControlledOptimizer*>(pComponentCache->Component().GetPointer()));
00101 };
00102
00103 template <class TControlledOptimizer>
00104 typename OptimizerControllerBase<TControlledOptimizer>::MeasuresType
00105 OptimizerControllerBase<TControlledOptimizer>::
00106 GetCurrentValue(TControlledOptimizer* pOptimizer) const
00107 {
00108
00109 MeasuresType values(1);
00110 values.Fill(0.0);
00111 return values;
00112 };
00113
00114 template <class TControlledOptimizer>
00115 long
00116 OptimizerControllerBase<TControlledOptimizer>::
00117 GetMaxIterationCount(const SessionComponentCache* pComponentCache, unsigned int iResolutionLevel) const
00118 {
00119 if (!pComponentCache) throwCtrlExceptionMacro("","Passed pComponentCache is NULL.");
00120 if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("","Cache has no setup assigned.");
00121
00122 long lIterations;
00123
00124 try
00125 {
00126 SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,lIterations,0,iResolutionLevel,true);
00127 }
00128 catch(...)
00129 {
00130 return -1;
00131 }
00132
00133 return lIterations;
00134 };
00135
00136 template <class TControlledOptimizer>
00137 ParameterArrayType
00138 OptimizerControllerBase<TControlledOptimizer>::
00139 GetTransformScales(SessionComponentCache* pOptimizerCache, const Parameter::LayerCountType& iCurLevel) const
00140 {
00141 Parameter::Pointer param = SessionAccessor::GetParameterByIDPath(pOptimizerCache,IDPath("../"+ComponentID(cComp_MainTransform)+"/@"+cParam_TransformScale));
00142 if (param.IsNull()) throwCtrlExceptionMacro("","Error; no main transform or scale parameter found to retrieve the scaling.");
00143
00144 Parameter::LayerCountType iActLevel = iCurLevel;
00145
00146 if (param->LayerCount()<=iActLevel) iActLevel = param->LayerCount()-1;
00147
00148 ParameterArrayType scales(0);
00149
00150 if (param->LayerCount()>0) scales = Convert::ParameterLayerToArray<ParameterArrayType>(*(param->GetParameterLayer(iActLevel)));
00151
00152 return scales;
00153 };
00154
00155 }
00156
00157 #endif