freFEMRegistrationController.h

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: freFEMRegistrationController.h,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 #ifndef __freFEMRegistrationController_h
00023 #define __freFEMRegistrationController_h
00024 
00025 #include "freRegistrationProcessorControllerBase.h"
00026 #include "freFEMRegistrationProcessor.h"
00027 
00028 #include "freIntensityImageMediaController.h"
00029 #include "freTransformFieldMediaController.h"
00030 
00031 namespace FREE
00032 {
00042   freControllerIDMacro(FEMRegistrationControllerBase, "FEMRegistrationBase");
00043 template < class TControlledFEMProcessor >
00044 class FEMRegistrationControllerBase : public RegistrationProcessorControllerBase<TControlledFEMProcessor>
00045 {
00046 public:  
00047   itkTypeMacro(FEMRegistrationControllerBase, RegistrationProcessorControllerBase);
00048 
00049   typedef TControlledFEMProcessor ComponentType;
00050   typedef RegistrationProcessorControllerBase<ComponentType> Superclass;
00051   typedef typename Superclass::GenericComponentType GenericComponentType;
00052   typedef typename Superclass::GenericComponentPointer GenericComponentPointer;
00053   typedef typename Superclass::GenericMediaPointer GenericMediaPointer;
00054 
00055   virtual ValidityTag::Pointer GetMediaValidityTagRequirement(const MediaID& mediaID,
00056                                                               SessionComponentCache* pComponentCache) const
00057   {
00058     if (mediaID == "finalField")
00059     {
00060       ValidityTag::Pointer smpReq = ValidityTag::New(this->GetMediaValidityTag(mediaID,pComponentCache)->GetTimeStamp());
00061 
00062       //check moving image 
00063       ComponentMediaLink::Pointer smpLink = pComponentCache->Setup()->MediaLinks().GetElement("movingImage");
00064       if (smpLink.IsNotNull())
00065       {
00066         ValidityTag::Pointer smpImageReq = SessionAccessor::GetValidityTagRequirement(smpLink->GetSourceIDPath(),pComponentCache);
00067         if (smpReq->IsOutdated(smpImageReq))
00068         { //movingImage is newer then result so there is a requirement.
00069           smpReq->SetTag(smpImageReq);
00070         }
00071       }
00072       //check fixed image 
00073       smpLink = pComponentCache->Setup()->MediaLinks().GetElement("fixedImage");
00074       if (smpLink.IsNotNull())
00075       {
00076         ValidityTag::Pointer smpImageReq = SessionAccessor::GetValidityTagRequirement(smpLink->GetSourceIDPath(),pComponentCache);
00077         if (smpReq->IsOutdated(smpImageReq))
00078         { //fixedImage is newer then result so there is a requirement.
00079           smpReq->SetTag(smpImageReq);
00080         }
00081       }
00082       return smpReq;
00083     }
00084 
00085     return Superclass::GetMediaValidityTagRequirement(mediaID, pComponentCache);
00086   }
00087 
00088 protected:
00089   FEMRegistrationControllerBase():Superclass()
00090   {     
00091     //Profile settings
00092     this->UpdateControllerID(ControllerID::FEMRegistrationControllerBase);
00093     this->m_Description = "Realizes a FEM based registration.";
00094         };
00095 
00096   virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00097                                const SessionComponentCache* pComponentCache,
00098                                bool bRegardOldSetup) const
00099   {
00100     Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00101 
00102     //Parameters
00103     profile.Parameters().AddParameter(cParam_FEMSetup,Parameter::PVTURI,cParamDsc_FEMSetup,1);
00104     profile.Parameters().AddParameter(cParam_HistoMatch,Parameter::PVTBool,cParamDsc_HistoMatch,1,"false");
00105     profile.Parameters().AddParameter(cParam_HistoLevels,Parameter::PVTLong,cParamDsc_HistoLevels,1,"1024");
00106     profile.Parameters().AddParameter(cParam_HistoMatchPoints,Parameter::PVTLong,cParamDsc_HistoMatchPoints,1,"5");
00107     profile.Parameters().AddParameter(cParam_HistoThreshold,Parameter::PVTBool,cParamDsc_HistoThreshold,1,"true");
00108 
00109     profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTLong,cParamDsc_Iterations,1,"10",-1,true);
00110     profile.Parameters().AddParameter(cParam_FEMRegLevels,Parameter::PVTInteger,cParamDsc_FEMRegLevels,1,"1");
00111     profile.Parameters().AddParameter(cParam_FEMPPE,Parameter::PVTInteger,cParamDsc_FEMPPE,1,"4",-1,true);
00112     profile.Parameters().AddParameter(cParam_FEMElasticity,CtrlProfile::Parameter::PVTDouble,cParamDsc_FEMElasticity,1,"1.0",-1,true);
00113     profile.Parameters().AddParameter(cParam_FEMDensity,CtrlProfile::Parameter::PVTDouble,cParamDsc_FEMDensity,1,"1.0",-1,true);
00114     profile.Parameters().AddParameter(cParam_FEMEnergyScale,CtrlProfile::Parameter::PVTDouble,cParamDsc_FEMEnergyScale,1,"1.0",-1,true);
00115     profile.Parameters().AddParameter(cParam_FEMNrIntPoints,Parameter::PVTInteger,cParamDsc_FEMNrIntPoints,1,"4",-1,true);
00116     profile.Parameters().AddParameter(cParam_FEMWidthOfMetric,Parameter::PVTInteger,cParamDsc_FEMWidthOfMetric,1,"1",-1,true);
00117     profile.Parameters().AddParameter(cParam_FEMAlpha,CtrlProfile::Parameter::PVTDouble,cParamDsc_FEMAlpha,1,"1.0");
00118     profile.Parameters().AddParameter(cParam_FEMDescentDirection,Parameter::PVTBool,cParamDsc_FEMDescentDirection,1,"false");
00119     profile.Parameters().AddParameter(cParam_FEMDoLineSearch,Parameter::PVTInteger,cParamDsc_FEMDoLineSearch,1,"2");
00120     profile.Parameters().AddParameter(cParam_FEMTimeStep,CtrlProfile::Parameter::PVTDouble,cParamDsc_FEMTimeStep,1,"1.0");
00121     profile.Parameters().AddParameter(cParam_FEMEnergyReduction,CtrlProfile::Parameter::PVTDouble,cParamDsc_FEMEnergyReduction,1,"1.0");
00122     profile.Parameters().AddParameter(cParam_FEMLandmarkFile,Parameter::PVTURI,cParamDsc_FEMLandmarkFile,1);
00123     profile.Parameters().AddParameter(cParam_FEMLandmarks,CtrlProfile::Parameter::PVTDouble,cParamDsc_FEMLandmarks,TControlledFEMProcessor::ImageDimension*2,"",-1);
00124     profile.Parameters().AddParameter(cParam_FEMLandmarkType,Parameter::PVTInteger,cParamDsc_FEMLandmarkType,1,"0");
00125     profile.Parameters().AddParameter(cParam_FEMMetric,Parameter::PVTInteger,cParamDsc_FEMMetric,1,"1");
00126     profile.Parameters().AddParameter(cParam_FEMScaleGradient,Parameter::PVTBool,cParamDsc_FEMScaleGradient,1,"false");
00127     profile.Parameters().AddParameter(cParam_FEMRegridding,Parameter::PVTBool,cParamDsc_FEMRegridding,1,"false");
00128 
00130                 //Media
00131                 std::string sControllerID = ControllerID::IntensityImage2DMediaController;
00132                 if (ComponentType::ImageDimension == 3) sControllerID = ControllerID::IntensityImage3DMediaController;
00133                 profile.MediaMap().AddMedia("movingImage",sControllerID,DASet,ComponentType::ImageDimension);
00134                 profile.MediaMap().AddMedia("fixedImage",sControllerID,DASet,ComponentType::ImageDimension);
00135           
00136                 sControllerID = ControllerID::TransformField2DMediaController;
00137                 if (ComponentType::ImageDimension == 3) sControllerID = ControllerID::TransformField3DMediaController;
00138                 profile.MediaMap().AddMedia("finalField",sControllerID,DAGet,ComponentType::ImageDimension);
00139   };
00140 
00149   virtual GenericComponentType* GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00150                                                       SessionComponentCache* pMainComponentCache) const
00151   {
00152           if (compID == cComp_MainMetric) return pMainComponent->smpMetric.GetPointer();
00153 
00154           return Superclass::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00155   }; 
00156 
00157   virtual void SetSubComponentCasted(GenericComponentType* pSubComponent, ComponentType* pMainComponent,
00158                                const ComponentID compID, SessionComponentCache* pMainComponentCache) const
00159   {
00160           if (compID == cComp_MainMetric) pMainComponent->smpMetric = dynamic_cast<typename ComponentType::MetricType*>(pSubComponent);
00161     else Superclass::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00162   };
00163 
00164   virtual void SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00165                                              ComponentType* pMainComponent,
00166                                              SessionComponentCache* pMainComponentCache,
00167                                              SessionInfo* pSessionInfo,
00168                                              StatisticDictionary& rDictionary) const
00169   {
00170     std::string sName = "Energy";
00171     std::string sIDPath = pMainComponentCache->GetIDPath();
00172     StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,sName);
00173       
00174     if (!pEntry) //Entry is not recorded yet, so do so.
00175     {
00176       pEntry = rDictionary.AddValueDefinition(sIDPath,sName,"Energy within the FEM");
00177     }
00178 
00179     rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->smpRegistration->GetMetric()->GetEnergy()),pEntry->GetRefID());
00180   };
00181 
00182   virtual GenericMediaPointer GetMediaCasted(const MediaID& mediaID,
00183                                                                                                                                                                                                  ComponentType* pComponent,
00184                                                                                                                                                                                                  SessionComponentCache* pComponentCache,
00185                                                  SessionInfo* pSessionInfo) const
00186         {
00187                 GenericMediaPointer smpMedia;
00188                 if (mediaID == "movingImage") return GenericMediaPointer(pComponent->GetMovingImage());
00189                 if (mediaID == "fixedImage") return GenericMediaPointer(pComponent->GetFixedImage());
00190                 if (mediaID == "finalField")
00191     { //Both are based on the registration so check first if registration needed
00192       ValidityTag::Pointer smpValField = this->GetMediaValidityTag(mediaID,pComponentCache);
00193       ValidityTag::Pointer smpValReqField = this->GetMediaValidityTagRequirement(mediaID,pComponentCache);
00194 
00195       if (smpValField->IsOutdated(smpValReqField))
00196       { //registration is outdated -> compute new segmentation
00197         SessionBuilder::ActualizeComponent(pComponentCache, pSessionInfo);
00198         SessionBuilder::LinkMediaToComponent(pComponentCache, pSessionInfo);
00199 
00200         pComponent->StartRegistration();
00201 
00202         this->ActualizeMediaValidityTag(mediaID,pComponentCache);
00203       }
00204 
00205       smpMedia = pComponent->GetTransformationField();
00206 
00207       return smpMedia;
00208     }
00209       
00210                 return Superclass::GetMediaCasted(mediaID, pComponent, pComponentCache, pSessionInfo);
00211   }; 
00212   
00213         virtual void SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia,
00214                                                                                                                         ComponentType* pComponent, SessionComponentCache* pComponentCache,
00215                               SessionInfo* pSessionInfo) const
00216         {
00217                 if (mediaID == "movingImage")
00218     {
00219       pComponent->SetMovingImage(dynamic_cast<typename ComponentType::ImageType*>(pMedia));
00220       this->ActualizeMediaValidityTag("movingImage",pComponentCache);
00221     }
00222                 else if (mediaID == "fixedImage")
00223     {
00224       pComponent->SetFixedImage(dynamic_cast<typename ComponentType::ImageType*>(pMedia));
00225       this->ActualizeMediaValidityTag("fixedImage",pComponentCache);
00226     }
00227                 else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00228         }; 
00229 
00230 };
00231 
00241   freControllerIDMacro(FEM2DRegistrationController, "FEM Registration 2D");
00242 class FEM2DRegistrationController : public FEMRegistrationControllerBase<FEMRegistrationProcessor2D>
00243 {
00244 public:  
00245   typedef FEMRegistrationProcessor2D ComponentType;
00246   typedef FEMRegistrationControllerBase<ComponentType> Superclass;
00247 
00248   itkTypeMacro(FEM2DRegistrationController, FEMRegistrationControllerBase);
00249 
00250   FEM2DRegistrationController();
00251 };
00252 
00262   freControllerIDMacro(FEM3DRegistrationController, "FEM Registration 3D");
00263 class FEM3DRegistrationController : public FEMRegistrationControllerBase<FEMRegistrationProcessor3D>
00264 {
00265 public:  
00266   typedef FEMRegistrationProcessor3D ComponentType;
00267   typedef FEMRegistrationControllerBase<ComponentType> Superclass;
00268 
00269   itkTypeMacro(FEM3DRegistrationController, FEMRegistrationControllerBase);
00270 
00271   FEM3DRegistrationController();
00272 };
00273 
00274 } //end of namespace free
00275 
00276 #endif

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