freWarpImageFilterController.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: freWarpImageFilterController.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 __freWarpImageFilterController_h
00023 #define __freWarpImageFilterController_h
00024 
00025 #include "freImageToImageFilterControllerBase.h"
00026 #include "freTransformFieldMediaController.h"
00027 #include "freInterpolatorControllerBase.h"
00028 
00029 #include "itkWarpImageFilter.h"
00030 
00031 namespace FREE
00032 {
00033 
00043   freControllerIDMacro(WarpImageFilterControllerBase, "WarpImageFilterBase");
00044 template <class TInputImage, class TDeformationField>
00045 class WarpImageFilterControllerBase : public ImageToImageFilterControllerBase< itk::WarpImageFilter<TInputImage, TInputImage, TDeformationField> >
00046 {
00047 public:  
00048   typedef itk::WarpImageFilter<TInputImage, TInputImage, TDeformationField> ComponentType;
00049   typedef ImageToImageFilterControllerBase<ComponentType> Superclass;
00050   typedef WarpImageFilterControllerBase<TInputImage, TDeformationField> Self;
00051 
00052   typedef typename ComponentType::Pointer ComponentPointer;
00053   typedef typename Superclass::GenericComponentType GenericComponentType;
00054   typedef typename Superclass::GenericComponentPointer GenericComponentPointer;
00055   typedef typename Superclass::GenericMediaPointer GenericMediaPointer;
00056 
00057   DeclareParameterMacro(EdgePaddingValue);
00058   DeclareParameterMacro(OutputOrigin);
00059   DeclareParameterMacro(OutputSpacing);
00060   DeclareParameterMacro(UseFieldInfo);
00061 
00062   itkTypeMacro(WarpImageFilterControllerBase, ImageToImageFilterControllerBase);
00063 
00064   ValidityTag::Pointer
00065   GetMediaValidityTagRequirement(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00066   {
00067     if (mediaID == "output")
00068     {
00069       ValidityTag::Pointer smpReq = ValidityTag::New(this->GetMediaValidityTag(mediaID,pComponentCache)->GetTimeStamp());
00070       this->CompareValidityTagRequirement("input",smpReq,pComponentCache);
00071       this->CompareValidityTagRequirement("deformationField",smpReq,pComponentCache);
00072       return smpReq;
00073     }
00074 
00075     return Superclass::GetMediaValidityTagRequirement(mediaID, pComponentCache);
00076   }
00077 
00078 protected:
00079   WarpImageFilterControllerBase()
00080   {
00081     //Profile settings
00082     this->UpdateControllerID(ControllerID::WarpImageFilterControllerBase);
00083     this->m_Description = "Basis for itk::WarpImageFilter";
00084   };
00085 
00086   virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00087                   const SessionComponentCache* pComponentCache,
00088                   bool bRegardOldSetup) const
00089   {
00090     Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00091 
00092     //Parameters
00093     profile.Parameters().AddParameter(cParam_EdgePaddingValue,Parameter::PVTDouble,cParamDsc_EdgePaddingValue,1,"0.0");
00094     profile.Parameters().AddParameter(cParam_OutputOrigin,Parameter::PVTDouble,cParamDsc_OutputOrigin,ComponentType::ImageDimension,"0.0");
00095     profile.Parameters().AddParameter(cParam_OutputSpacing,Parameter::PVTDouble,cParam_OutputSpacing,ComponentType::ImageDimension,"1.0");
00096     profile.Parameters().AddParameter(cParam_UseFieldInfo,Parameter::PVTBool,cParam_UseFieldInfo,1,"true");
00097 
00098     //Media
00099     if (ComponentType::DeformationFieldDimension == 2)
00100     {
00101       profile.MediaMap().AddMedia("deformationField",ControllerID::TransformField2DMediaController,DASet,2);
00102     }
00103     else
00104     {
00105       profile.MediaMap().AddMedia("deformationField",ControllerID::TransformField3DMediaController,DASet,2);
00106     }
00107 
00108     //Subcomponents
00109     profile.SubComponents().AddSubComponent(cComp_MainInterpolator,0,csUndefinedController,cCompDsc_MainInterpolator);
00110 
00111     //requirements
00112                 CtrlProfile::ProfileOption* pOption;
00113                   //interpolator
00114                 pOption = profile.Requirements().AddRequirement(cComp_MainInterpolator)->AddProfileOption();
00115                 pOption->Inheritance().AddAncestor(ControllerID::InterpolatorControllerBase);
00116     pOption->MediaMap().AddMedia("inputImage",ControllerID::ImageMediaControllerBase, DASet, ComponentType::ImageDimension,1,true);
00117                 pOption->CheckForInheritance();
00118                 pOption->CheckForIO();
00119   };
00120 
00121         virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00122                                       SessionComponentCache* pComponentCache,
00123                                       SessionInfo* pSessionInfo,
00124                                                                                                                                                         const unsigned int& iActLevel) const
00125   {
00126     Superclass::ActualizeMainComponent(pMainComponent,pComponentCache, pSessionInfo, iActLevel);
00127 
00128           double dEdgePaddingValue;
00129     typename ComponentType::PointType outputOrigin;
00130     typename ComponentType::SpacingType outputSpacing;
00131           bool bUseFieldInfo;
00132 
00133     try
00134     {
00135       SessionAccessor::GetParameterValue(pComponentCache,cParam_EdgePaddingValue,dEdgePaddingValue);
00136       SessionAccessor::GetParameterValue(pComponentCache,cParam_UseFieldInfo,bUseFieldInfo);
00137 
00138       for (unsigned int iIndex = 0; iIndex<ComponentType::ImageDimension; iIndex++)
00139       {
00140         SessionAccessor::GetParameterValue(pComponentCache,cParam_OutputOrigin,outputOrigin[iIndex],iIndex);
00141         SessionAccessor::GetParameterValue(pComponentCache,cParam_OutputSpacing,outputSpacing[iIndex],iIndex);
00142       }
00143     }
00144     catchAllNPassMacro("Error while retrieving parameter values.");
00145 
00146           pMainComponent->SetEdgePaddingValue(dEdgePaddingValue);
00147     if(bUseFieldInfo)
00148     {
00149       typename ComponentType::DeformationFieldType* pField = pMainComponent->GetDeformationField();
00150       if (!pField) throwCtrlExceptionMacro("","Error. Deformation field was not set. Check if media link is missing. ComponentID: "<<pComponentCache->GetIDPath().ToStr());
00151             pMainComponent->SetOutputOrigin(pField->GetOrigin());
00152             pMainComponent->SetOutputSpacing(pField->GetSpacing());
00153     }
00154     else
00155     {
00156             pMainComponent->SetOutputOrigin(outputOrigin);
00157             pMainComponent->SetOutputSpacing(outputSpacing);
00158     }
00159   };
00160 
00161   virtual GenericComponentType* GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00162                                                       SessionComponentCache* pMainComponentCache) const
00163   {
00164           if (compID == cComp_MainInterpolator) return pMainComponent->GetInterpolator();
00165 
00166           return Superclass::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00167   }; 
00168 
00169   virtual void SetSubComponentCasted(GenericComponentType* pSubComponent, ComponentType* pMainComponent,
00170                                const ComponentID compID, SessionComponentCache* pMainComponentCache) const
00171   {
00172           if (compID == cComp_MainInterpolator) pMainComponent->SetInterpolator(dynamic_cast<typename ComponentType::InterpolatorType*>(pSubComponent));
00173           else Superclass::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00174   };
00175 
00176 
00177   virtual GenericMediaPointer GetMediaCasted(const MediaID& mediaID,
00178                                                                                                                                                                                                  ComponentType* pComponent,
00179                                                                                                                                                                                                  SessionComponentCache* pComponentCache,
00180                                                  SessionInfo* pSessionInfo) const
00181         {
00182                 if (mediaID == "deformationField") return GenericMediaPointer(pComponent->GetDeformationField());
00183       
00184                 return Superclass::GetMediaCasted(mediaID, pComponent, pComponentCache, pSessionInfo);
00185         }; 
00186   
00187         virtual void SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia,
00188                                                                                                                         ComponentType* pComponent, SessionComponentCache* pComponentCache,
00189                               SessionInfo* pSessionInfo) const
00190         {
00191                 if (mediaID == "deformationField")
00192     {
00193       pComponent->SetDeformationField(dynamic_cast<typename ComponentType::DeformationFieldType*>(pMedia));
00194     }
00195                 else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00196         }; 
00197 
00198 };
00199 
00200 template <class TInputImage, class TDeformationField>
00201 const char* const WarpImageFilterControllerBase<TInputImage,TDeformationField> :: cParam_EdgePaddingValue = "EdgePaddingValue";
00202 template <class TInputImage, class TDeformationField>
00203 const char* const WarpImageFilterControllerBase<TInputImage,TDeformationField> :: cParamDsc_EdgePaddingValue = "Value of all pixels that are mapped outside the input image.";
00204 template <class TInputImage, class TDeformationField>
00205 const char* const WarpImageFilterControllerBase<TInputImage,TDeformationField> :: cParam_OutputOrigin = "OutputOrigin";
00206 template <class TInputImage, class TDeformationField>
00207 const char* const WarpImageFilterControllerBase<TInputImage,TDeformationField> :: cParamDsc_OutputOrigin = "Origin of the output image.";
00208 template <class TInputImage, class TDeformationField>
00209 const char* const WarpImageFilterControllerBase<TInputImage,TDeformationField> :: cParam_OutputSpacing = "OutputSpacing";
00210 template <class TInputImage, class TDeformationField>
00211 const char* const WarpImageFilterControllerBase<TInputImage,TDeformationField> :: cParamDsc_OutputSpacing = "Spacing of the output image.";
00212 template <class TInputImage, class TDeformationField>
00213 const char* const WarpImageFilterControllerBase<TInputImage,TDeformationField> :: cParam_UseFieldInfo = "UseFieldInfo";
00214 template <class TInputImage, class TDeformationField>
00215 const char* const WarpImageFilterControllerBase<TInputImage,TDeformationField> :: cParamDsc_UseFieldInfo = "If true spacing and origin of the deformation field instead of the parameters of the setup.";
00216 
00222 freControllerIDMacro(Warp2DImageFilterController, "Warp 2D Image Filter");
00223 class Warp2DImageFilterController : public WarpImageFilterControllerBase< ImageTypes<2>::InternalImageType, ImageTypes<2>::TransformationFieldType >
00224 {
00225 public:  
00226   typedef WarpImageFilterControllerBase< ImageTypes<2>::InternalImageType, ImageTypes<2>::TransformationFieldType> Superclass;
00227   typedef Warp2DImageFilterController Self;
00228 
00229   typedef Superclass::ComponentType ComponentType;
00230   typedef ComponentType::Pointer ComponentPointer;
00231   typedef Superclass::GenericComponentType GenericComponentType;
00232   typedef Superclass::GenericComponentPointer GenericComponentPointer;
00233   typedef Superclass::GenericMediaPointer GenericMediaPointer;
00234 
00235   itkTypeMacro(Warp2DImageFilterController, WarpImageFilterControllerBase);
00236 
00237   Warp2DImageFilterController();
00238 };
00239 
00245 freControllerIDMacro(Warp3DImageFilterController, "Warp 3D Image Filter");
00246 class Warp3DImageFilterController : public WarpImageFilterControllerBase< ImageTypes<3>::InternalImageType, ImageTypes<3>::TransformationFieldType >
00247 {
00248 public:  
00249   typedef WarpImageFilterControllerBase< ImageTypes<3>::InternalImageType, ImageTypes<3>::TransformationFieldType> Superclass;
00250   typedef Warp3DImageFilterController Self;
00251 
00252   typedef Superclass::ComponentType ComponentType;
00253   typedef ComponentType::Pointer ComponentPointer;
00254   typedef Superclass::GenericComponentType GenericComponentType;
00255   typedef Superclass::GenericComponentPointer GenericComponentPointer;
00256   typedef Superclass::GenericMediaPointer GenericMediaPointer;
00257 
00258   itkTypeMacro(Warp3DImageFilterController, WarpImageFilterControllerBase);
00259 
00260   Warp3DImageFilterController();
00261 };
00262 
00263 } //end of namespace free
00264 
00265 #endif

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