00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freScaleTransformController_h
00023 #define __freScaleTransformController_h
00024
00025 #include "freITKTransformControllerBase.h"
00026 #include "freTransformInitializer.h"
00027 #include "freTransformSetupAdaptor.h"
00028
00029 #include "itkScaleTransform.h"
00030
00031 namespace FREE
00032 {
00033
00043 freControllerIDMacro(ScaleTransformControllerBase, "ScaleTransformBase");
00044 template <int iDimension>
00045 class ScaleTransformControllerBase : public ITKTransformControllerBase< itk::ScaleTransform < ScalarType, iDimension >, iDimension >
00046 {
00047 public:
00048 typedef itk::ScaleTransform < ScalarType, iDimension > ComponentType;
00049 typedef ITKTransformControllerBase<ComponentType, iDimension> Superclass;
00050
00051 itkTypeMacro(ScaleTransformControllerBase, ITKTransformControllerBase);
00052
00053 protected:
00056 ScaleTransformControllerBase()
00057 {
00058
00059 this->UpdateControllerID(ControllerID::ScaleTransformControllerBase);
00060 this->m_Description = "A rigid scale transform.";
00061 };
00062
00063 virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00064 const SessionComponentCache* pComponentCache,
00065 bool bRegardOldSetup) const
00066 {
00067 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00068
00069
00070 profile.Parameters().AddParameter(cParam_InitialisationMethod,Parameter::PVTInteger,std::string(cParamDsc_InitialisationMethod)+"\n1: scales are set by itv",1,"0");
00071 };
00072
00073 virtual bool SetInitialTransformValues( ComponentType* pTransformComponent,
00074 SessionComponentCache* pComponentCache,
00075 SessionInfo* pSessionInfo,
00076 const int& iInitializeByITV) const
00077 {
00078 if (!iInitializeByITV)
00079 {
00080 ComponentSetup* pTransformSetup = pComponentCache->Setup();
00081 TransformSetupAdaptor adaptor(pTransformSetup);
00082 ReferencePointsAccessor<iDimension> pointsAccessor(pComponentCache);
00083
00084 if (!pointsAccessor.MovingPointsExist()) throwCtrlExceptionMacro("","Cannot estimate scaling via reference points. No moving reference point set defined. Please check media linkage.");
00085 if (!pointsAccessor.FixedPointsExist()) throwCtrlExceptionMacro("","Cannot estimate scaling via via reference points. No fixed reference point set defined. Please check media linkage.");
00086
00087 ParameterArrayType scaling(iDimension);
00088
00089 scaling.fill(0);
00090 for (int iIndex = 0; iIndex<pointsAccessor.GetFixedPointsCount(); iIndex++)
00091 {
00092 ParameterArrayType movingRef = pointsAccessor.GetMovingPointArray(iIndex);
00093 ParameterArrayType fixedRef = pointsAccessor.GetFixedPointArray(iIndex);
00094
00095 for (int iIndex=0; iIndex<iDimension; iIndex++)
00096 {
00097 scaling[iIndex] += movingRef[iIndex]/fixedRef[iIndex];
00098 };
00099 };
00100
00101 int iCoupleCount = pointsAccessor.GetFixedPointsCount();
00102 if (iCoupleCount<1) iCoupleCount = 1;
00103
00104 for (int iIndex=0; iIndex<iDimension; iIndex++)
00105 {
00106 scaling[iIndex] = scaling[iIndex]/iCoupleCount;
00107 pTransformSetup->Parameters().SetParameterValue(cParam_CurrentTransformValues,scaling[iIndex],iIndex);
00108 }
00109 };
00110 return true;
00111 };
00112 };
00113
00123 freControllerIDMacro(Scale2DTransformController, "Scale 2D Transform");
00124 class Scale2DTransformController : public ScaleTransformControllerBase<2>
00125 {
00126 public:
00127 itkTypeMacro(Scale2DTransformController, ScaleTransformControllerBase);
00128
00129 Scale2DTransformController();
00130
00131 protected:
00132 virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00133 const SessionComponentCache* pComponentCache,
00134 bool bRegardOldSetup) const;
00135 };
00136
00146 freControllerIDMacro(Scale3DTransformController, "Scale 3D Transform");
00147 class Scale3DTransformController : public ScaleTransformControllerBase<3>
00148 {
00149 public:
00150 itkTypeMacro(Scale3DTransformController, ScaleTransformControllerBase);
00151
00152 Scale3DTransformController();
00153
00154 protected:
00155 virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00156 const SessionComponentCache* pComponentCache,
00157 bool bRegardOldSetup) const;
00158 };
00159
00160 }
00161
00162 #endif