00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "freSimilarity2DTransformController.h"
00024 #include "freTransformSetupAdaptor.h"
00025
00026 #include "itkPoint.h"
00027 #include "itkCenteredTransformInitializer.h"
00028
00029 namespace FREE
00030 {
00031
00035
00036
00037 Similarity2DTransformController::
00038 Similarity2DTransformController()
00039 {
00040 this->UpdateControllerID(ControllerID::Similarity2DTransformController);
00041 this->m_Description = "A combination of rotation, translation and homogeneous scaling in 2D.";
00042 };
00043
00044 void
00045 Similarity2DTransformController::
00046 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00047 const SessionComponentCache* pComponentCache,
00048 bool bRegardOldSetup) const
00049 {
00050 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00051
00052
00053 profile.Parameters().AddParameter(cParam_InitialisationMethod,Parameter::PVTInteger,std::string(cParamDsc_InitialisationMethod)+"\n1:estimate rotation by initial reference points\n2: estimate scaling by initial reference points\n3: estimate translation by initial reference points",1,"0");
00054 profile.Parameters().AddParameter(cParam_InitialTransformValues,CtrlProfile::Parameter::PVTDouble,"1: rotation angel (in radian)\n2: scaling factor\n3: x translation\n4: y translation",4,"0");
00055 profile.Parameters().AddParameter(cParam_CurrentTransformValues,CtrlProfile::Parameter::PVTDouble,"1: rotation angel (in radian)\n2: scaling factor\n3: x translation\n4: y translation",4,"0");
00056 profile.Parameters().AddParameter(cParam_TransformScale,CtrlProfile::Parameter::PVTDouble,"1: rotation angel (in radian)\n2: scaling factor\n3: x translation\n4: y translation",4,"1",-1,true);
00057 };
00058
00059 bool
00060 Similarity2DTransformController::
00061 SetInitialTransformValues( ComponentType* pTransformComponent,
00062 SessionComponentCache* pComponentCache,
00063 SessionInfo* pSessionInfo,
00064 const int& iInitializeByITV) const
00065 {
00066 if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("","Cannot initialize transform values, transform setup is not assigned in cache.");
00067 ComponentSetup* pTransformSetup = pComponentCache->Setup();
00068
00069 TransformSetupAdaptor adaptor(pTransformSetup);
00070 ReferencePointsAccessor<2> pointsAccessor(pComponentCache);
00071
00072
00073 if (iInitializeByITV==3)
00074 {
00075 if (!pointsAccessor.MovingPointsExist()) throwCtrlExceptionMacro("","Cannot estimate rotation via reference points. No moving reference point set defined. Please check media linkage.");
00076 if (!pointsAccessor.FixedPointsExist()) throwCtrlExceptionMacro("","Cannot estimate rotation via via reference points. No fixed reference point set defined. Please check media linkage.");
00077
00078 ParameterArrayType translation(2);
00079 for (int iRefIndex=0; iRefIndex<pointsAccessor.GetFixedPointsCount(); iRefIndex++)
00080 {
00081 ParameterArrayType movingPoint = pointsAccessor.GetMovingPointArray(iRefIndex);
00082 ParameterArrayType fixedPoint = pointsAccessor.GetFixedPointArray(iRefIndex);
00083
00084 for (int iIndex=0; iIndex<2; iIndex++)
00085 {
00086 translation[iIndex] += movingPoint[iIndex]-fixedPoint[iIndex];
00087 };
00088 };
00089
00090 for (int iIndex=0; iIndex<2; iIndex++)
00091 {
00092 translation[iIndex] = translation[iIndex]/pointsAccessor.GetFixedPointsCount();
00093 pTransformSetup->Parameters().SetParameterValue(cParam_CurrentTransformValues,translation[iIndex],3+iIndex);
00094 };
00095
00096 }
00097 else if (iInitializeByITV==2)
00098 {
00099 }
00100 else if (iInitializeByITV==1)
00101 {
00102 if (!pointsAccessor.MovingPointsExist()) throwCtrlExceptionMacro("","Cannot estimate rotation via reference points. No moving reference point set defined. Please check media linkage.");
00103 if (!pointsAccessor.FixedPointsExist()) throwCtrlExceptionMacro("","Cannot estimate rotation via via reference points. No fixed reference point set defined. Please check media linkage.");
00104
00105 RotationInitializer<2> rotationInitializer;
00106 ParameterArrayType center(2);
00107 center.Fill(0.0);
00108
00109 rotationInitializer.SetCenterPair(center,center);
00110
00111
00112 for (int iIndex = 0; iIndex<pointsAccessor.GetFixedPointsCount(); iIndex++)
00113 {
00114 rotationInitializer.AddReferencePair(pointsAccessor.GetMovingPointArray(iIndex),pointsAccessor.GetFixedPointArray(iIndex));
00115 };
00116
00117
00118 rotationInitializer.ClearSchedule(false);
00119 rotationInitializer.AddToSchedule(RA_Z);
00120
00121 rotationInitializer.ComputeRotations();
00122
00123
00124
00125
00126 pTransformSetup->Parameters().SetParameterValue(cParam_CurrentTransformValues,-1*rotationInitializer.GetRotation(RA_Z),0);
00127 };
00128
00129 return true;
00130 };
00131
00132 }