freOrientImageFilterController.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: freOrientImageFilterController.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 __freOrientImageFilterController_h
00023 #define __freOrientImageFilterController_h
00024 
00025 #include "freImageToImageFilterControllerBase.h"
00026 
00027 #include "itkOrientImageFilter.h"
00028 
00029 namespace FREE
00030 {
00031 
00032 namespace Convert
00033 {
00034   std::string ToStr(const itk::SpatialOrientation::ValidCoordinateOrientationFlags& orient);
00035   itk::SpatialOrientation::ValidCoordinateOrientationFlags ToCoordinateOrientation(const std::string& sValue);
00036 }
00037 
00047   freControllerIDMacro(OrientImageFilterControllerBase, "OrientImageFilterBase");
00048 template <class TInputImage, unsigned int VDimension >
00049 class OrientImageFilterControllerBase : public ImageToImageFilterControllerBase< itk::OrientImageFilter<TInputImage, TInputImage> >
00050 {
00051 public:  
00052   typedef itk::OrientImageFilter<TInputImage, TInputImage> ComponentType;
00053   typedef ImageToImageFilterControllerBase<ComponentType> Superclass;
00054   typedef OrientImageFilterControllerBase<TInputImage, VDimension> Self;
00055 
00056   typedef typename ComponentType::Pointer ComponentPointer;
00057   typedef typename Superclass::GenericComponentType GenericComponentType;
00058   typedef typename Superclass::GenericComponentPointer GenericComponentPointer;
00059   typedef typename Superclass::GenericMediaPointer GenericMediaPointer;
00060 
00061   DeclareParameterMacro(UseImageDirection);
00062   DeclareParameterMacro(GivenCoordinateOrientation);
00063   DeclareParameterMacro(DesiredCoordinateOrientation);
00064   DeclareParameterMacro(UseReferenceImageDirection);
00065 
00066   DeclareMediaIDMacro(referenceImage);
00067 
00068   itkTypeMacro(OrientImageFilterControllerBase, ImageToImageFilterControllerBase);
00069 
00070 protected:
00071   OrientImageFilterControllerBase()
00072   {
00073     //Profile settings
00074     this->UpdateControllerID(ControllerID::OrientImageFilterControllerBase);
00075     this->m_Description = "Basis for itk::OrientImageFilter";
00076   };
00077 
00078   virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00079                   const SessionComponentCache* pComponentCache,
00080                   bool bRegardOldSetup) const
00081   {
00082     Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00083 
00084     //Parameters
00085     profile.Parameters().AddParameter(cParam_UseImageDirection,Parameter::PVTBool,cParamDsc_UseImageDirection,1,"false");
00086     profile.Parameters().AddParameter(cParam_GivenCoordinateOrientation,Parameter::PVTString,cParamDsc_GivenCoordinateOrientation,1,"RIP");
00087     profile.Parameters().AddParameter(cParam_DesiredCoordinateOrientation,Parameter::PVTString,cParamDsc_DesiredCoordinateOrientation,1,"RIP");
00088     profile.Parameters().AddParameter(cParam_UseReferenceImageDirection,Parameter::PVTBool,cParamDsc_UseReferenceImageDirection,1,"false");
00089 
00090     unsigned int iMediaGroupID = 0; //normaly the reference image is not needed
00091 
00092     if (bRegardOldSetup)
00093     {
00094       Parameter* pParamUseRefImage = pComponentCache->Setup()->Parameters().GetParameter(cParam_UseReferenceImageDirection);
00095 
00096       if (!pParamUseRefImage) throwCtrlExceptionMacro("","Error. Parameter "<<cParam_UseReferenceImageDirection<<"could not be found in old setup. Please ensure the creation of valid setups.");
00097       bool bUse = false;
00098       pParamUseRefImage->GetParameterValue(bUse);
00099 
00100       if (bUse) iMediaGroupID = 1;
00101     }
00102 
00103     //Media
00104     profile.MediaMap().AddMedia(MediaID_referenceImage,ControllerID::ImageMediaControllerBase,DASet,TInputImage::GetImageDimension(),iMediaGroupID);
00105   };
00106 
00107         virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00108                                       SessionComponentCache* pComponentCache,
00109                                       SessionInfo* pSessionInfo,
00110                                                                                                                                                         const unsigned int& iActLevel) const
00111   {
00112     Superclass::ActualizeMainComponent(pMainComponent,pComponentCache, pSessionInfo, iActLevel);
00113     
00114           bool bUseImage;
00115           bool bUseReferenceImage;
00116     std::string sGivenOrientation;
00117     std::string sDesiredOrientation;
00118 
00119     try
00120     {
00121       SessionAccessor::GetParameterValue(pComponentCache,cParam_UseImageDirection,bUseImage);
00122       SessionAccessor::GetParameterValue(pComponentCache,cParam_UseReferenceImageDirection,bUseReferenceImage);
00123       SessionAccessor::GetParameterValue(pComponentCache,cParam_GivenCoordinateOrientation,sGivenOrientation);
00124       SessionAccessor::GetParameterValue(pComponentCache,cParam_DesiredCoordinateOrientation,sDesiredOrientation);
00125     }
00126     catchAllNPassMacro("Error while retrieving parameter values.");
00127 
00128     pMainComponent->SetUseImageDirection(bUseImage);
00129     if (!bUseImage)
00130     {
00131       pMainComponent->SetGivenCoordinateOrientation(Convert::ToCoordinateOrientation(sGivenOrientation));
00132     }
00133 
00134     if (!bUseReferenceImage)
00135     {
00136       pMainComponent->SetDesiredCoordinateOrientation(Convert::ToCoordinateOrientation(sDesiredOrientation));
00137     }
00138     else
00139     { //get reference image directions
00140 
00141       SessionAccessor::GenericMediaPointer smpGenericReferenceImage = SessionAccessor::GetLinkedMedia(MediaID_referenceImage,pComponentCache,pSessionInfo);
00142       if (smpGenericReferenceImage.IsNull()) throwCtrlExceptionMacro("","Cannot get desired image direction. No reference image linked. Please check media linkage.");
00143 
00144       typedef typename itk::ImageBase<VDimension> ReferenceImageType;
00145 
00146       ReferenceImageType* pRefImage = 0;
00147 
00148       try
00149       {
00150         pRefImage = dynamic_cast<ReferenceImageType*>(smpGenericReferenceImage.GetPointer());
00151       }
00152       catchAllNPassMacro("Error while casting initial image");
00153       if (!pRefImage) throwCtrlExceptionMacro("","Error while casting initial image.");
00154 
00155       pMainComponent->SetDesiredCoordinateDirection(pRefImage->GetDirection());
00156     }
00157   };
00158 
00159 };
00160 
00161 template <class TInputImage, unsigned int VDimension >
00162 const char* const OrientImageFilterControllerBase<TInputImage, VDimension> :: cParam_UseImageDirection = "UseImageDirection";
00163 template <class TInputImage, unsigned int VDimension >
00164 const char* const OrientImageFilterControllerBase<TInputImage, VDimension> :: cParamDsc_UseImageDirection = "Use image directions of the input image to determine the orientation. If true GivenCoordinateOrientation will be ignored.";
00165 template <class TInputImage, unsigned int VDimension >
00166 const char* const OrientImageFilterControllerBase<TInputImage, VDimension> :: cParam_GivenCoordinateOrientation = "GivenCoordinateOrientation";
00167 template <class TInputImage, unsigned int VDimension >
00168 const char* const OrientImageFilterControllerBase<TInputImage, VDimension> :: cParamDsc_GivenCoordinateOrientation = "Specifies the orientation of the input image coded as a three letter code (see itk::OrientImageFilter documentation). Will be ignored if UseImageDirection is true.";
00169 template <class TInputImage, unsigned int VDimension >
00170 const char* const OrientImageFilterControllerBase<TInputImage, VDimension> :: cParam_DesiredCoordinateOrientation = "DesiredCoordinateOrientation";
00171 template <class TInputImage, unsigned int VDimension >
00172 const char* const OrientImageFilterControllerBase<TInputImage, VDimension> :: cParamDsc_DesiredCoordinateOrientation = "Specifies the orientation of the output image coded as a three letter code (see itk::OrientImageFilter documentation). Will be ignored if UseReferenceImageDirection is true.";
00173 template <class TInputImage, unsigned int VDimension >
00174 const char* const OrientImageFilterControllerBase<TInputImage, VDimension> :: cParam_UseReferenceImageDirection = "UseReferenceImageDirection";
00175 template <class TInputImage, unsigned int VDimension >
00176 const char* const OrientImageFilterControllerBase<TInputImage, VDimension> :: cParamDsc_UseReferenceImageDirection = "Use image directions of the reference image to determine the orientation of the output. If true DesiredCoordinateOrientation will be ignored.";
00177 
00178 template <class TInputImage, unsigned int VDimension >
00179 const char* const OrientImageFilterControllerBase<TInputImage, VDimension> :: MediaID_referenceImage = "referenceImage";
00180 template <class TInputImage, unsigned int VDimension >
00181 const char* const OrientImageFilterControllerBase<TInputImage, VDimension> :: MediaIDDsc_referenceImage = "Reference image used to retrieve the desired output direction.";
00182 
00188 freControllerIDMacro(Orient3DImageFilterController, "Orient 3D Image Filter");
00189 class Orient3DImageFilterController : public OrientImageFilterControllerBase< ImageTypes<3>::InternalImageType, 3 >
00190 {
00191 public:  
00192   typedef OrientImageFilterControllerBase< ImageTypes<3>::InternalImageType, 3 > Superclass;
00193   typedef Orient3DImageFilterController Self;
00194 
00195   typedef Superclass::ComponentType ComponentType;
00196   typedef ComponentType::Pointer ComponentPointer;
00197   typedef Superclass::GenericComponentType GenericComponentType;
00198   typedef Superclass::GenericComponentPointer GenericComponentPointer;
00199   typedef Superclass::GenericMediaPointer GenericMediaPointer;
00200 
00201   itkTypeMacro(Orient3DImageFilterController, OrientImageFilterControllerBase);
00202 
00203   Orient3DImageFilterController();
00204 };
00205 
00206 } //end of namespace free
00207 
00208 #endif

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