00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freSetupTransformController_h
00023 #define __freSetupTransformController_h
00024
00025 #include "freControllerBase.h"
00026
00027 #include "freSetupTransform.h"
00028
00029 namespace FREE
00030 {
00031
00032 freControllerIDMacro(SetupTransformControllerBase, "SetupTransformBase");
00033
00039 template <class TTransformComponent>
00040 class SetupTransformControllerBase : public ComponentControllerBase<TTransformComponent>
00041 {
00042 public:
00043 itkTypeMacro(SetupTransformControllerBase, ComponentControllerBase);
00044
00045 typedef TTransformComponent ComponentType;
00046 typedef ComponentControllerBase<TTransformComponent> Superclass;
00047
00048 DeclareParameterMacro(ParameterIDs);
00049 DeclareParameterMacro(AutoInitialValues);
00050
00051 SetupTransformControllerBase()
00052 {
00053
00054 this->UpdateControllerID(ControllerID::SetupTransformControllerBase);
00055 this->m_Description = "Base controler for a transform of free setups, by changing specified parameters.";
00056 };
00057
00058 protected:
00059 virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00060 const SessionComponentCache* pComponentCache,
00061 bool bRegardOldSetup) const
00062 {
00063
00064 profile.Parameters().AddParameter(cParam_ParameterIDs,CtrlProfile::Parameter::PVTString,cParamDsc_ParameterIDs,1,"");
00065 profile.Parameters().AddParameter(cParam_AutoInitialValues,CtrlProfile::Parameter::PVTBool,cParamDsc_AutoInitialValues,1,"true");
00066
00067 if (bRegardOldSetup)
00068 {
00069 profile.Parameters().AddParameter(cParam_InitialTransformValues,CtrlProfile::Parameter::PVTDouble,"",1,"0.0",-1);
00070 profile.Parameters().AddParameter(cParam_CurrentTransformValues,CtrlProfile::Parameter::PVTDouble,"",1,"0.0",-1);
00071 }
00072 else
00073 {
00074 Parameter* pParam = pComponentCache->Setup()->Parameters().GetParameter(cParam_ParameterIDs);
00075 if (!pParam) throwCtrlExceptionMacro("","Error. Cannot retrieve parameter \"ParameterIDs\". Please ensure that component is properly initialized.");
00076
00077 profile.Parameters().AddParameter(cParam_InitialTransformValues,CtrlProfile::Parameter::PVTDouble,"",1,"0.0",pParam->LayerCount());
00078 profile.Parameters().AddParameter(cParam_CurrentTransformValues,CtrlProfile::Parameter::PVTDouble,"",1,"0.0",pParam->LayerCount());
00079 }
00080 };
00081
00082 virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00083 SessionComponentCache* pComponentCache,
00084 SessionInfo* pSessionInfo,
00085 const unsigned int& iActLevel) const
00086 {
00087 typedef typename ComponentType::ParametersType ComponentParameterType;
00088 ComponentParameterType values;
00089 bool bAutoInitValues;
00090
00091 try
00092 {
00093 SessionAccessor::GetParameterValue(pComponentCache,cParam_AutoInitialValues,bAutoInitValues);
00094 }
00095 catchAllNPassMacro("Error while retrieving parameter values.");
00096
00097 pMainComponent->SetAutoInitialValues(bAutoInitValues);
00098
00099 Parameter::Pointer smpParameter = SessionAccessor::GetParameter(pComponentCache,cParam_ParameterIDs);
00100 if (smpParameter.IsNull()) throwExceptionMacro("Missing parameter: " << cParam_ParameterIDs);
00101
00102 for (unsigned int index = 0; index < smpParameter->ParameterSize(); index++)
00103 {
00104 std::string id;
00105 smpParameter->GetParameterValue(id,index);
00106 pMainComponent->AddParameterID(IDPath(id));
00107 }
00108
00109
00110 if (!bAutoInitValues)
00111 {
00112 smpParameter = SessionAccessor::GetParameter(pComponentCache,cParam_InitialTransformValues);
00113 if (smpParameter.IsNull()) throwExceptionMacro("Missing parameter: " << cParam_InitialTransformValues);
00114 ComponentParameterType values = Convert::ParameterLayerToArray<ComponentParameterType>(*(smpParameter->GetParameterLayer(0)));
00115
00116 pMainComponent->SetParameters( values );
00117 }
00118 };
00119 };
00120
00121 DefineParameterTemplateMacro(SetupTransformControllerBase<TTransformComponent>, class TTransformComponent,ParameterIDs,"ParameterIDs","Determines parameter values that should be changed.");
00122 DefineParameterTemplateMacro(SetupTransformControllerBase<TTransformComponent>, class TTransformComponent,AutoInitialValues,"AutoInitialValues","Determines if the transform should use the values of the passed setup (true) as initial transform values.");
00123
00129 freControllerIDMacro(SetupTransformController, "Setup Transform");
00130 class SetupTransformController : public SetupTransformControllerBase<SetupTransform>
00131 {
00132 public:
00133 itkTypeMacro(SetupTransformController, SetupTransformControllerBase);
00134
00135 typedef SetupTransform ComponentType;
00136 typedef SetupTransformControllerBase<ComponentType> Superclass;
00137
00138 SetupTransformController();
00139 };
00140
00141 }
00142
00143 #endif