freMatrixOffsetTransformControllerBase.txx

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: freMatrixOffsetTransformControllerBase.txx,v $
00007   Language:  C++
00008 
00009 
00010   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00011   Institute for Medical Biometry and Informatics, University of Heidelberg,
00012   Germany). All rights reserved.
00013   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00014   for details.
00015 
00016      This software is distributed WITHOUT ANY WARRANTY; without even 
00017      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00018      PURPOSE.  See the above copyright notices for more information.
00019 
00020 =========================================================================*/
00021 #ifndef __freMatrixOffsetTransformControllerBase_txx
00022 #define __freMatrixOffsetTransformControllerBase_txx
00023 
00024 #include "freMatrixOffsetTransformControllerBase.h"
00025 
00026 #include "freIntensityImageMediaController.h"
00027 
00028 #include "freTransformSetupAdaptor.h"
00029 
00030 #include "itkCenteredTransformInitializer.h"
00031 
00032 namespace FREE
00033 {
00034 
00035 template <class TMatrixOffsetTransform, unsigned int VDimension>
00036 MatrixOffsetTransformControllerBase<TMatrixOffsetTransform, VDimension>::
00037 MatrixOffsetTransformControllerBase()
00038 {
00039   //Profile settings
00040   this->UpdateControllerID(ControllerID::MatrixOffsetTransformControllerBase);
00041   this->m_Description = "Base class for all trasformations based on itk::MatrixOffsetTransform.";
00042 };
00043 
00044 template <class TMatrixOffsetTransform, unsigned int VDimension>
00045 void
00046 MatrixOffsetTransformControllerBase<TMatrixOffsetTransform, VDimension>::
00047 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00048                 const SessionComponentCache* pComponentCache,
00049                 bool bRegardOldSetup) const
00050 {
00051   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00052 
00053   profile.Parameters().AddParameter(cParam_CenterInitializationType,Parameter::PVTInteger,cParamDsc_CenterInitializationType,1,"0");
00054   profile.Parameters().AddParameter(cParam_Center,Parameter::PVTInteger,cParamDsc_Center,VDimension,"0");
00055   profile.Parameters().AddParameter(cParam_InitialTransformValues,CtrlProfile::Parameter::PVTDouble,"depends on the dimension",1,"0");
00056   profile.Parameters().AddParameter(cParam_CurrentTransformValues,CtrlProfile::Parameter::PVTDouble,"depends on the dimension",1,"0");
00057   profile.Parameters().AddParameter(cParam_TransformScale,CtrlProfile::Parameter::PVTDouble,"depends on the dimension",1,"1",-1,true);
00058 
00059   //Media
00060   if (VDimension==2)
00061   {
00062     profile.MediaMap().AddMedia(MediaID_movingInitialImage,ControllerID::IntensityImage2DMediaController,DASet,VDimension);
00063     profile.MediaMap().AddMedia(MediaID_fixedInitialImage,ControllerID::IntensityImage2DMediaController,DASet,VDimension);
00064   }
00065   else
00066   {
00067     profile.MediaMap().AddMedia(MediaID_movingInitialImage,ControllerID::IntensityImage3DMediaController,DASet,VDimension);
00068     profile.MediaMap().AddMedia(MediaID_fixedInitialImage,ControllerID::IntensityImage3DMediaController,DASet,VDimension);
00069   }
00070 };
00071 
00072 template <class TMatrixOffsetTransform, unsigned int VDimension>
00073 void
00074 MatrixOffsetTransformControllerBase<TMatrixOffsetTransform, VDimension>::
00075 SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia, ComponentType* pComponent, SessionComponentCache* pComponentCache,
00076                SessionInfo* pSessionInfo) const
00077 {
00078   if (mediaID == MediaID_movingInitialImage)
00079   {
00080     DirectSessionComponentAccessor::SetRepositoryElement(MediaID_movingInitialImage,pMedia,pComponentCache);
00081   }
00082   else if (mediaID == MediaID_fixedInitialImage)
00083   {
00084     DirectSessionComponentAccessor::SetRepositoryElement(MediaID_fixedInitialImage,pMedia,pComponentCache);
00085   }
00086   else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00087 }; 
00088 
00089 template <class TMatrixOffsetTransform, unsigned int VDimension>
00090 bool
00091 MatrixOffsetTransformControllerBase<TMatrixOffsetTransform, VDimension>::
00092 SetInitialTransformValues( ComponentType* pTransformComponent,
00093                                SessionComponentCache* pComponentCache,
00094                                SessionInfo* pSessionInfo,
00095                                const int& iInitializeByITV) const
00096 {
00097   int iCenterType;
00098 
00099   if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("","Cannot initialize transform values, transform setup is not assigned in cache.");
00100   ComponentSetup* pTransformSetup = pComponentCache->Setup();
00101 
00102   try
00103   {
00104     SessionAccessor::GetParameterValue(pComponentCache,cParam_CenterInitializationType,iCenterType);
00105   }
00106   catchAllNPassMacro("Error while retrieving parameter values.");
00107 
00108   TransformSetupAdaptor adaptor(pTransformSetup);
00109 
00110   ParameterArrayType itv = adaptor.GetInitialTransformParameters();
00111 
00112   ReferencePointsAccessor<VDimension> pointsAccessor(pComponentCache);
00113 
00114   typedef typename ImageTypes<VDimension>::InternalImageType InternalImageType;
00115 
00116   //default is identity and then set the non fixed parameter to initial transform
00117   pTransformComponent->SetIdentity();
00118   pTransformComponent->SetParameters(itv);
00119 
00120     if (iCenterType==1)
00121     { //no translation, center via "Center" parameter
00122       try
00123       {
00124         double dCenterValue;
00125         typename ImageTypes<VDimension>::PointType centerPoint;
00126       
00127         for (int iIndex=0; iIndex<VDimension; iIndex++)
00128         {
00129           SessionAccessor::GetParameterValue(pComponentCache,cParam_Center,dCenterValue,iIndex);
00130           centerPoint[iIndex] = dCenterValue;
00131         }
00132         pTransformComponent->SetCenter(centerPoint);
00133       }
00134       catchAllNPassMacro("Error while retrieving center point parameter values.");
00135     }
00136     else if ((iCenterType==2)||(iCenterType==3))
00137     { //intitalize center and translation via itk::CenteredTransformInitializer
00138       typedef itk::CenteredTransformInitializer< ComponentType, InternalImageType, InternalImageType> TransformInitializerType;
00139       typename TransformInitializerType::Pointer initializer = TransformInitializerType::New();
00140 
00141       SessionAccessor::GenericMediaPointer smpGenericInitialFixedImage = SessionAccessor::GetLinkedMedia(MediaID_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(MediaID_movingInitialImage,pComponentCache,pSessionInfo);
00144       if (smpGenericInitialMovingImage.IsNull()) throwCtrlExceptionMacro("","Cannot set moving center via initial image. No initial moving 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       initializer->SetTransform( pTransformComponent );
00164       initializer->SetFixedImage( pInitialFixedImage );
00165       initializer->SetMovingImage( pInitialMovingImage );
00166 
00167       if (iCenterType==2) initializer->GeometryOn();
00168       else initializer->MomentsOn();
00169 
00170       initializer->InitializeTransform();
00171     }
00172     else if (iCenterType==4)
00173     { //First reference is the center point
00174       if (!pointsAccessor.MovingPointsExist()) throwCtrlExceptionMacro("","Cannot set moving center via reference points. No moving reference point set defined. Please check media linkage.");
00175       if (!pointsAccessor.FixedPointsExist()) throwCtrlExceptionMacro("","Cannot set fixed center via reference points. No fixed reference point set defined. Please check media linkage.");
00176       typename ComponentType::OutputPointType fixedCenter = pointsAccessor.GetFixedPoint(0);
00177       typename ComponentType::OutputPointType movingCenter = pointsAccessor.GetMovingPoint(0);
00178 
00179       typename ComponentType::TranslationType translation;
00180       translation = movingCenter-fixedCenter;
00181 
00182       pTransformComponent->SetCenter(fixedCenter);
00183       pTransformComponent->SetTranslation(translation);
00184     }
00185     else if (iCenterType==5)
00186     { //centroid of the point sets is reference is the center point
00187       if (!pointsAccessor.MovingPointsExist()) throwCtrlExceptionMacro("","Cannot set moving center via reference points. No moving reference point set defined. Please check media linkage.");
00188       if (!pointsAccessor.FixedPointsExist()) throwCtrlExceptionMacro("","Cannot set fixed center via reference points. No fixed reference point set defined. Please check media linkage.");
00189       if (!pointsAccessor.GetFixedPointsCount()) throwCtrlExceptionMacro("","Cannot set moving center via reference point centroids. Point sets are empty.");
00190       if (!pointsAccessor.GetMovingPointsCount()) throwCtrlExceptionMacro("","Cannot set fixed center via reference point centroids. Point sets are empty.");
00191       typename ComponentType::OutputVectorType fixedCentroid(0.0);
00192       typename ComponentType::OutputVectorType movingCentroid(0.0);
00193 
00194       for (int iIndex=0; iIndex<pointsAccessor.GetFixedPointsCount(); iIndex++)
00195       {
00196         fixedCentroid += pointsAccessor.GetFixedPoint(iIndex).GetVectorFromOrigin();
00197       }
00198 
00199       for (int iIndex=0; iIndex<pointsAccessor.GetMovingPointsCount(); iIndex++)
00200       {
00201         movingCentroid += pointsAccessor.GetMovingPoint(iIndex).GetVectorFromOrigin();
00202       }
00203 
00204       fixedCentroid /= pointsAccessor.GetFixedPointsCount();
00205       movingCentroid /= pointsAccessor.GetMovingPointsCount();
00206 
00207       typename ComponentType::TranslationType translation;
00208       translation = movingCentroid-fixedCentroid;
00209 
00210       typename ComponentType::OutputPointType fixedCentroidPoint(fixedCentroid.GetDataPointer());
00211 
00212       pTransformComponent->SetCenter(fixedCentroidPoint);
00213       pTransformComponent->SetTranslation(translation);
00214     }
00215   //The return is false to remind, that only the component is initialized no.
00216   //To ensure a proper initialization derived classes have to set CurrentTransformValues
00217 
00218   return false;
00219 };
00220 
00221 template <class TMatrixOffsetTransform, unsigned int VDimension>
00222 void
00223 MatrixOffsetTransformControllerBase<TMatrixOffsetTransform, VDimension>::
00224 CopyFixedParameters(ComponentType* pOrigin, ComponentType* pDestination) const
00225 {
00226   pDestination->SetFixedParameters(pOrigin->GetFixedParameters());
00227 };
00228 
00229 template <class TMatrixOffsetTransform, unsigned int VDimension>
00230 const char* const MatrixOffsetTransformControllerBase<TMatrixOffsetTransform,VDimension>::
00231 cParam_Center = "Center";
00232 
00233 template <class TMatrixOffsetTransform, unsigned int VDimension>
00234 const char* const MatrixOffsetTransformControllerBase<TMatrixOffsetTransform,VDimension>::
00235 cParamDsc_Center = "Coordinates of the center used as rotation center if CenterInitializationType = 0.";
00236 
00237 template <class TMatrixOffsetTransform, unsigned int VDimension>
00238 const char* const MatrixOffsetTransformControllerBase<TMatrixOffsetTransform,VDimension>::
00239 cParam_CenterInitializationType = "CenterInitializationType";
00240 
00241 template <class TMatrixOffsetTransform, unsigned int VDimension>
00242 const char* const MatrixOffsetTransformControllerBase<TMatrixOffsetTransform,VDimension>::
00243 cParamDsc_CenterInitializationType = "Type of rotation center computation and translation initialisation.\n0:Center and translation will be set via ITV (if they aren't fixed parameters). \n1:Use the center specified via the parameter 'Center' (translation is set via initial transformation values).\n2: use geometrical center for calculation\n3: use center of mass of images for calculation.\n4: center and translation are defined via the first point in the initial point sets.\n4: center and translation are defined via the centroids of the initial point sets.";
00244 
00245 template <class TMatrixOffsetTransform, unsigned int VDimension>
00246 const char* const MatrixOffsetTransformControllerBase<TMatrixOffsetTransform,VDimension>::
00247 MediaID_movingInitialImage = "movingInitialImage";
00248 
00249 template <class TMatrixOffsetTransform, unsigned int VDimension>
00250 const char* const MatrixOffsetTransformControllerBase<TMatrixOffsetTransform,VDimension>::
00251 MediaIDDsc_movingInitialImage = "Reference for the moving domain that can be used initialize the transform (normaly the moving image itself).";
00252 
00253 template <class TMatrixOffsetTransform, unsigned int VDimension>
00254 const char* const MatrixOffsetTransformControllerBase<TMatrixOffsetTransform,VDimension>::
00255 MediaID_fixedInitialImage = "fixedInitialImage";
00256 
00257 template <class TMatrixOffsetTransform, unsigned int VDimension>
00258 const char* const MatrixOffsetTransformControllerBase<TMatrixOffsetTransform,VDimension>::
00259 MediaIDDsc_fixedInitialImage = "Reference for the fixed domain that can be used initialize the transform (normaly the fixed image itself).";
00260 
00261 } //end of namespace free
00262 
00263 #endif

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