freSimilarity2DTransformController.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freSimilarity2DTransformController.cxx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
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   //Parameters
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         //Calculate the translation
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           //Add all references
00112           for (int iIndex = 0; iIndex<pointsAccessor.GetFixedPointsCount(); iIndex++)
00113           {
00114                 rotationInitializer.AddReferencePair(pointsAccessor.GetMovingPointArray(iIndex),pointsAccessor.GetFixedPointArray(iIndex));
00115           };
00116 
00117           //set schedule
00118           rotationInitializer.ClearSchedule(false);
00119           rotationInitializer.AddToSchedule(RA_Z);
00120 
00121           rotationInitializer.ComputeRotations();
00122 
00123           //add angel to the parameters. Angel must be inverted, because itk uses back transform
00124           //(fixed to moving) and the initial calculation uses forward transform to allow an intuitive
00125           //parameter setting
00126           pTransformSetup->Parameters().SetParameterValue(cParam_CurrentTransformValues,-1*rotationInitializer.GetRotation(RA_Z),0);
00127         };
00128  
00129   return true;
00130 };
00131 
00132 } //end of namespace free

Generated at Sat Oct 13 17:36:09 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000