freEuler3DTransformController.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: freEuler3DTransformController.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 "freEuler3DTransformController.h"
00024 #include "freTransformSetupAdaptor.h"
00025 
00026 namespace FREE
00027 {
00028 
00032 
00033 
00034 Euler3DTransformController::
00035 Euler3DTransformController()
00036 {
00037   this->UpdateControllerID(ControllerID::Euler3DTransformController);
00038   this->m_Description = "A combination of rotation and translation in 3 dimensions.";
00039 };
00040 
00041 void
00042 Euler3DTransformController::
00043 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00044                 const SessionComponentCache* pComponentCache,
00045                 bool bRegardOldSetup) const
00046 {
00047   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00048 
00049   //Parameters
00050   profile.Parameters().AddParameter(cParam_InitialTransformValues,CtrlProfile::Parameter::PVTDouble,"1..3: rotation angel (in radian)\n4..6: x/y/z translation",6,"0");
00051   profile.Parameters().AddParameter(cParam_CurrentTransformValues,CtrlProfile::Parameter::PVTDouble,"1..3: rotation angel (in radian)\n4..6: x/y/z translation",6,"0");
00052   profile.Parameters().AddParameter(cParam_TransformScale,CtrlProfile::Parameter::PVTDouble,"1..3: rotation angel (in radian)\n4..6: x/y/z translation",6,"1",-1,true);
00053   profile.Parameters().AddParameter("InitialRotationAxis",Parameter::PVTInteger,"Indicates the rotiation axis used for initialisation, if the reference initialisation is used. The order of rotation is always z y x. \n-1: z y x (smart)\n0: z y x.\n1: x\n2: y\n3: y x\n4: z\n5: z x\n6: z y",1,"0");
00054 
00055   //Media
00056   profile.MediaMap().AddMedia("movingInitialImage",ControllerID::IntensityImage3DMediaController,DASet,3);
00057   profile.MediaMap().AddMedia("fixedInitialImage",ControllerID::IntensityImage3DMediaController,DASet,3);
00058 };
00059 
00060 bool
00061 Euler3DTransformController::
00062 SetInitialTransformValues( ComponentType* pTransformComponent,
00063                            SessionComponentCache* pComponentCache,
00064                            SessionInfo* pSessionInfo,
00065                            const int& iInitializeByITV) const
00066 {
00067   //let the transform be initialized by MatrixOffsetTransformController
00068   Superclass::SetInitialTransformValues( pTransformComponent, pComponentCache, pSessionInfo, iInitializeByITV);
00069 
00070   int iCenterType;
00071 
00072   if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("","Cannot initialize transform values, transform setup is not assigned in cache.");
00073   ComponentSetup* pTransformSetup = pComponentCache->Setup();
00074 
00075   if (!pTransformSetup->Parameters().GetParameterValue(cParam_CenterInitializationType,iCenterType)) throwExceptionMacro("Missing parameter: " << "CenterType");
00076 
00077   TransformSetupAdaptor adaptor(pTransformSetup);
00078   ParameterArrayType itv = adaptor.GetInitialTransformParameters();
00079 
00080   //set current transform values to initial transform values by default
00081   for (int iIndex=0; iIndex<itv.Size(); iIndex++)
00082   {
00083     pTransformSetup->Parameters().SetParameterValue(cParam_CurrentTransformValues,itv[iIndex],iIndex);
00084   };
00085 
00086   if (iCenterType>1)
00087   { //the translation was initialized by controller and not defined
00088     //by ITV so copy translation to current transform values
00089     for (int iIndex=0; iIndex<3; iIndex++)
00090     {
00091       pTransformSetup->Parameters().SetParameterValue(cParam_CurrentTransformValues,pTransformComponent->GetTranslation().GetElement(iIndex),iIndex+3);
00092     }
00093   }
00094 
00095   return true;
00096 
00097   //TODO: old version insufficient initializer use VersorRigidTransform instead or freTensoInitializer
00098   //int iCenterType;
00099 
00100   //if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("","Cannot initialize transform values, transform setup is not assigned in cache.");
00101   //ComponentSetup* pTransformSetup = pComponentCache->Setup();
00102 
00103   //if (!pTransformSetup->Parameters().GetParameterValue(cParam_CenterInitializationType,iCenterType)) throwExceptionMacro("Missing parameter: " << "CenterType");
00104 
00105   //TransformSetupAdaptor adaptor(3, pTransformSetup);
00106   //ReferencePointsAccessor<3> pointsAccessor(pComponentCache);
00107 
00109   //ParameterArrayType fixedCenter(3);
00110   //ParameterArrayType movingCenter(3);
00111 
00112   //if (2==(iInitializeByITV&2))
00113   //{ //translation is stored in the ITV and should be used
00114   //  // center point x/y/z
00115   //  ParameterArrayType itv = adaptor.GetInitialTransformParameters();
00116   //  for (int iIndex=0; iIndex<3; iIndex++)
00117   //  {
00118   //    movingCenter[iIndex] = itv[3+iIndex];
00119   //    fixedCenter[iIndex] = 0;
00120   //  };
00121   //}
00122   //else
00123   //{ 
00124   //  if (iCenterType==0)
00125   //  { //First paire of reference points are the center points
00126   //    if (!pointsAccessor.MovingPointsExist()) throwCtrlExceptionMacro("","Cannot set moving center via reference points. No moving reference point set defined. Please check media linkage.");
00127   //    if (!pointsAccessor.FixedPointsExist()) throwCtrlExceptionMacro("","Cannot set fixed center via reference points. No fixed reference point set defined. Please check media linkage.");
00128   //    fixedCenter = pointsAccessor.GetFixedPointArray(0);
00129   //    movingCenter = pointsAccessor.GetMovingPointArray(0);
00130   //  }
00131   //  else
00132   //  {
00133   //    //Center should be calculated
00134   //    CenterInitializer<PixelType,3> centerInitializer;
00135 
00136   //    if (iCenterType==1) centerInitializer.GeometryOn();
00137   //    else centerInitializer.MomentsOn();
00138 
00139   //    typedef ImageTypes<3>::InternalImageType InternalImageType;
00140   //    
00141   //    SessionAccessor::GenericMediaPointer smpGenericInitialFixedImage = SessionAccessor::GetLinkedMedia("fixedInitialImage",pComponentCache,pSessionInfo);
00142   //    if (smpGenericInitialFixedImage.IsNull()) throwCtrlExceptionMacro("","Cannot set fixed center via initial image. No initial fixed image linked. Please check media linkage.");
00143   //    SessionAccessor::GenericMediaPointer smpGenericInitialMovingImage = SessionAccessor::GetLinkedMedia("movingInitialImage",pComponentCache,pSessionInfo);
00144   //    if (smpGenericInitialMovingImage.IsNull()) throwCtrlExceptionMacro("","Cannot set moving center via initial image. No initial fixed image linked. Please check media linkage.");
00145   //    
00146   //    InternalImageType* pInitialFixedImage = 0;
00147   //    InternalImageType* pInitialMovingImage = 0;
00148 
00149   //    try
00150   //    {
00151   //      pInitialFixedImage = dynamic_cast<InternalImageType*>(smpGenericInitialFixedImage.GetPointer());
00152   //    }
00153   //    catchAllNPassMacro("Error while casting initial fixed image");
00154   //    if (!pInitialFixedImage) throwCtrlExceptionMacro("","Error while casting initial fixed image.");
00155 
00156   //    try
00157   //    {
00158   //      pInitialMovingImage = dynamic_cast<InternalImageType*>(smpGenericInitialMovingImage.GetPointer());
00159   //    }
00160   //    catchAllNPassMacro("Error while casting initial fixed image");
00161   //    if (!pInitialMovingImage) throwCtrlExceptionMacro("","Error while casting initial fixed image.");
00162 
00163   //    centerInitializer.SetImage(pInitialFixedImage);
00164   //    centerInitializer.GetCenter(fixedCenter);
00165 
00166   //    centerInitializer.SetImage(pInitialMovingImage);
00167   //    centerInitializer.GetCenter(movingCenter);
00168   //  }
00169   //}
00170 
00172   //ParameterArrayType translation(3);
00173   //for (int iIndex=0; iIndex<3; iIndex++)
00174   //{
00175   //  translation[iIndex] = movingCenter[iIndex]-fixedCenter[iIndex];
00176   //};
00177 
00178   //  //add the calculated initial translation and center to the setup - to be present
00179   //  //for the Registrator - when using set initial position.
00180   //for (int iIndex=0; iIndex<3; iIndex++)
00181   //{
00182   //  pTransformSetup->Parameters().SetParameterValue(cParam_CurrentTransformValues,translation[iIndex],3+iIndex);
00183   //};
00184 
00185   //if (!(1==(iInitializeByITV&1)))
00186   //{ //Rotation should be calculated
00187   //  if (!pointsAccessor.MovingPointsExist()) throwCtrlExceptionMacro("","Cannot estimate rotation via reference points. No moving reference point set defined. Please check media linkage.");
00188   //  if (!pointsAccessor.FixedPointsExist()) throwCtrlExceptionMacro("","Cannot estimate rotation via via reference points. No fixed reference point set defined. Please check media linkage.");
00189 
00190   //  RotationInitializer<3> rotationInitializer;
00191 
00192   //  rotationInitializer.SetCenterPair(movingCenter,fixedCenter);
00193 
00194   //  //Add all references
00195   //  int iIndex = 0;
00196   //  if (iCenterType==0) iIndex = 1; //first reference is the center point;
00197   //  for (iIndex; iIndex<pointsAccessor.GetFixedPointsCount(); iIndex++)
00198   //  {
00199   //    rotationInitializer.AddReferencePair(pointsAccessor.GetMovingPointArray(iIndex),pointsAccessor.GetFixedPointArray(iIndex));
00200   //  };
00201 
00202   //  //set schedule
00203   //  int iInitialRotationAxis;
00204   //  if (!pTransformSetup->Parameters().GetParameterValue("InitialRotationAxis",iInitialRotationAxis)) throwExceptionMacro("Missing parameter: " << "InitialRotationAxis");
00205 
00206   //  rotationInitializer.ClearSchedule(false);
00207   //  if ((iInitialRotationAxis<1) | (4 == (iInitialRotationAxis & 4))) rotationInitializer.AddToSchedule(RA_Z);
00208   //  if ((iInitialRotationAxis<1) | (2 == (iInitialRotationAxis & 2))) rotationInitializer.AddToSchedule(RA_Y);
00209   //  if ((iInitialRotationAxis<1) | (1 == (iInitialRotationAxis & 1))) rotationInitializer.AddToSchedule(RA_X);
00210 
00211   //  rotationInitializer.SetUseRotationWeight(iInitialRotationAxis==-1);
00212 
00213   //  rotationInitializer.ComputeRotations();
00214 
00215   //  //add angel to the parameters. Angel must be inverted, because itk uses back transform
00216   //  //(fixed to moving) and the initial calculation uses forward transform to allow an intuitive
00217   //  //parameter setting
00218   //  pTransformSetup->Parameters().SetParameterValue(cParam_CurrentTransformValues,-1*rotationInitializer.GetRotation(RA_X),0);
00219   //  pTransformSetup->Parameters().SetParameterValue(cParam_CurrentTransformValues,-1*rotationInitializer.GetRotation(RA_Y),1);
00220   //  pTransformSetup->Parameters().SetParameterValue(cParam_CurrentTransformValues,-1*rotationInitializer.GetRotation(RA_Z),2);
00221   //};
00222   //return true;
00223 };
00224 
00225 } //end of namespace free

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