00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freResampleImageFilterController_h
00023 #define __freResampleImageFilterController_h
00024
00025 #include "freImageToImageFilterControllerBase.h"
00026 #include "freTransformFunctionMediaController.h"
00027 #include "freInterpolatorControllerBase.h"
00028 #include "freOrientImageFilterController.h"
00029
00030 #include "itkResampleImageFilter.h"
00031
00032 namespace FREE
00033 {
00034
00044 freControllerIDMacro(ResampleImageFilterControllerBase, "ResampleImageFilterBase");
00045 template <class TInputImage>
00046 class ResampleImageFilterControllerBase : public ImageToImageFilterControllerBase< itk::ResampleImageFilter<TInputImage, TInputImage> >
00047 {
00048 public:
00049 typedef itk::ResampleImageFilter<TInputImage, TInputImage> ComponentType;
00050 typedef ImageToImageFilterControllerBase<ComponentType> Superclass;
00051 typedef ResampleImageFilterControllerBase Self;
00052
00053 typedef typename ComponentType::Pointer ComponentPointer;
00054 typedef typename Superclass::GenericComponentType GenericComponentType;
00055 typedef typename Superclass::GenericComponentPointer GenericComponentPointer;
00056 typedef typename Superclass::GenericMediaPointer GenericMediaPointer;
00057
00058 DeclareParameterMacro(DefaultPixelValue);
00059 DeclareParameterMacro(OutputOrigin);
00060 DeclareParameterMacro(OutputSpacing);
00061 DeclareParameterMacro(OutputSize);
00062 DeclareParameterMacro(OutputStartIndex);
00063 DeclareParameterMacro(OutputOrientation);
00064 DeclareParameterMacro(UseReferenceInfo);
00065
00066 DeclareMediaIDMacro(transformFunction);
00067 DeclareMediaIDMacro(outputReference);
00068
00069 itkTypeMacro(ResampleImageFilterControllerBase, ImageToImageFilterControllerBase);
00070
00071 ValidityTag::Pointer
00072 GetMediaValidityTagRequirement(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00073 {
00074 if (mediaID == "output")
00075 {
00076 ValidityTag::Pointer smpReq = ValidityTag::New(this->GetMediaValidityTag(mediaID,pComponentCache)->GetTimeStamp());
00077 this->CompareValidityTagRequirement("input",smpReq,pComponentCache);
00078 this->CompareValidityTagRequirement(MediaID_transformFunction,smpReq,pComponentCache);
00079 return smpReq;
00080 }
00081
00082 return Superclass::GetMediaValidityTagRequirement(mediaID, pComponentCache);
00083 }
00084
00085 protected:
00086 ResampleImageFilterControllerBase()
00087 {
00088
00089 this->UpdateControllerID(ControllerID::ResampleImageFilterControllerBase);
00090 this->m_Description = "Basis for itk::ResampleImageFilter";
00091 };
00092
00093 virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00094 const SessionComponentCache* pComponentCache,
00095 bool bRegardOldSetup) const
00096 {
00097 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00098
00099 unsigned int iOrientationGroupID = 0;
00100 unsigned int iOutputGroupID = 0;
00101
00102 if (bRegardOldSetup)
00103 {
00104 int iUseReference;
00105 try
00106 {
00107 SessionAccessor::GetParameterValue(pComponentCache,cParam_UseReferenceInfo,iUseReference);
00108 }
00109 catchAllNPassMacro("Error while generating the profile.");
00110
00111 if (iUseReference == 0)
00112 {
00113 iOrientationGroupID = 1;
00114 iOutputGroupID = 1;
00115 }
00116 else if (iUseReference == 2)
00117 {
00118 iOrientationGroupID = 1;
00119 }
00120 }
00121
00122
00123 profile.Parameters().AddParameter(cParam_DefaultPixelValue,Parameter::PVTDouble,cParamDsc_DefaultPixelValue,1,"0.0");
00124 profile.Parameters().AddParameter(cParam_OutputOrigin,Parameter::PVTDouble,cParamDsc_OutputOrigin,ComponentType::ImageDimension,"0.0",1,false,iOutputGroupID);
00125 profile.Parameters().AddParameter(cParam_OutputSpacing,Parameter::PVTDouble,cParamDsc_OutputSpacing,ComponentType::ImageDimension,"1.0",1,false,iOutputGroupID);
00126 profile.Parameters().AddParameter(cParam_OutputSize,Parameter::PVTULong,cParamDsc_OutputSize,ComponentType::ImageDimension,"1",1,false,iOutputGroupID);
00127 profile.Parameters().AddParameter(cParam_OutputStartIndex,Parameter::PVTULong,cParamDsc_OutputStartIndex,ComponentType::ImageDimension,"0",1,false,iOutputGroupID);
00128 profile.Parameters().AddParameter(cParam_OutputOrientation,Parameter::PVTString,cParamDsc_OutputOrientation,1,"RPI",1,false,iOrientationGroupID);
00129 profile.Parameters().AddParameter(cParam_UseReferenceInfo,Parameter::PVTInteger,cParam_UseReferenceInfo,1,"1");
00130
00131
00132 profile.MediaMap().AddMedia(MediaID_transformFunction,ControllerID::TransformFunctionMediaControllerBase,DASet,ComponentType::ImageDimension);
00133 profile.MediaMap().AddMedia(MediaID_outputReference,ControllerID::IntensityImageMediaControllerBase,DASet,ComponentType::ImageDimension);
00134
00135
00136 profile.SubComponents().AddSubComponent(cComp_MainInterpolator,0,csUndefinedController,cCompDsc_MainInterpolator);
00137
00138
00139 CtrlProfile::ProfileOption* pOption;
00140
00141 pOption = profile.Requirements().AddRequirement(cComp_MainInterpolator)->AddProfileOption();
00142 pOption->Inheritance().AddAncestor(ControllerID::InterpolatorControllerBase);
00143 pOption->MediaMap().AddMedia("inputImage",ControllerID::ImageMediaControllerBase, DASet, ComponentType::ImageDimension,1,true);
00144 pOption->CheckForInheritance();
00145 pOption->CheckForIO();
00146 };
00147
00148 virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00149 SessionComponentCache* pComponentCache,
00150 SessionInfo* pSessionInfo,
00151 const unsigned int& iActLevel) const
00152 {
00153 Superclass::ActualizeMainComponent(pMainComponent,pComponentCache, pSessionInfo, iActLevel);
00154
00155 double dDefaultValue;
00156 typename ComponentType::PointType outputOrigin;
00157 typename ComponentType::SpacingType outputSpacing;
00158 typename ComponentType::SizeType outputSize;
00159 typename ComponentType::IndexType outputStartIndex;
00160 int iUseReference;
00161 std::string sOrientation;
00162
00163 try
00164 {
00165 SessionAccessor::GetParameterValue(pComponentCache,cParam_DefaultPixelValue,dDefaultValue);
00166 SessionAccessor::GetParameterValue(pComponentCache,cParam_UseReferenceInfo,iUseReference);
00167
00168 if (iUseReference == 0)
00169 {
00170 for (unsigned int iIndex = 0; iIndex<ComponentType::ImageDimension; iIndex++)
00171 {
00172 SessionAccessor::GetParameterValue(pComponentCache,cParam_OutputOrigin,outputOrigin[iIndex],iIndex);
00173 SessionAccessor::GetParameterValue(pComponentCache,cParam_OutputSpacing,outputSpacing[iIndex],iIndex);
00174 SessionAccessor::GetParameterValue(pComponentCache,cParam_OutputSize,outputSize[iIndex],iIndex);
00175 SessionAccessor::GetParameterValue(pComponentCache,cParam_OutputStartIndex,outputStartIndex[iIndex],iIndex);
00176 }
00177 }
00178 if ((iUseReference == 0) || (iUseReference == 2))
00179 {
00180 for (unsigned int iIndex = 0; iIndex<ComponentType::ImageDimension; iIndex++)
00181 {
00182 SessionAccessor::GetParameterValue(pComponentCache,cParam_OutputOrientation,sOrientation);
00183 }
00184 }
00185 }
00186 catchAllNPassMacro("Error while retrieving parameter values.");
00187
00188 pMainComponent->SetDefaultPixelValue(dDefaultValue);
00189 if(iUseReference == 0)
00190 {
00191 pMainComponent->SetOutputOrigin(outputOrigin);
00192 pMainComponent->SetOutputSpacing(outputSpacing);
00193 pMainComponent->SetOutputStartIndex(outputStartIndex);
00194
00195
00196 pMainComponent->SetSize(outputSize);
00197 }
00198 else if (iUseReference == 1)
00199 {
00200
00201 const typename ComponentType::InputImageType* pImage = pMainComponent->GetInput();
00202 if (!pImage) throwCtrlExceptionMacro("","Error. Input image was not set. Check if media link is missing. ComponentID: "<<pComponentCache->GetIDPath().ToStr());
00203 pMainComponent->SetOutputOrigin(pImage->GetOrigin());
00204 pMainComponent->SetOutputSpacing(pImage->GetSpacing());
00205 pMainComponent->SetOutputStartIndex(pImage->GetLargestPossibleRegion().GetIndex());
00206 pMainComponent->SetSize(pImage->GetLargestPossibleRegion().GetSize());
00207 pMainComponent->SetOutputDirection(pImage->GetDirection());
00208 }
00209 else if (iUseReference == 2)
00210 {
00211
00212 GenericMediaPointer smpFunctRef = SessionAccessor::GetLinkedMedia(MediaID_transformFunction,pComponentCache,pSessionInfo);
00213 if (smpFunctRef.IsNull())
00214 {
00215 throwCtrlExceptionMacro("","Error. Transformation function was not set or is null. Check if media link ("<<MediaID_transformFunction<<") is missing or source is invalid. ComponentID: "<<pComponentCache->GetIDPath().ToStr());
00216 }
00217 else
00218 {
00219 typedef TransformFunctionMedia< ScalarType, ComponentType::ImageDimension,ComponentType::ImageDimension > TransformFunctionType;
00220 TransformFunctionType* pFunction = dynamic_cast<TransformFunctionType*>(smpFunctRef.GetPointer());
00221 if (!pFunction) throwCtrlExceptionMacro("","Error. Link for transform function found, but transform function seems to have wrong type.");
00222
00223 pMainComponent->SetOutputOrigin(pFunction->GetFieldOrigin());
00224 pMainComponent->SetOutputSpacing(pFunction->GetFieldSpacing());
00225 pMainComponent->SetOutputStartIndex(pFunction->GetFieldRegion().GetIndex());
00226 pMainComponent->SetSize(pFunction->GetFieldRegion().GetSize());
00227
00228
00229 }
00230 }
00231 else
00232 {
00233
00234 GenericMediaPointer smpGenericRefImage = SessionAccessor::GetLinkedMedia(MediaID_outputReference,pComponentCache,pSessionInfo);
00235 if (smpGenericRefImage.IsNull())
00236 {
00237 throwCtrlExceptionMacro("","Error. Reference image was not set or is null. Check if media link ("<<MediaID_outputReference<<") is missing or source is invalid. ComponentID: "<<pComponentCache->GetIDPath().ToStr());
00238 }
00239 else
00240 {
00241 typedef typename ImageTypes<ComponentType::ImageDimension>::InternalImageType InternalImageType;
00242 typename InternalImageType::Pointer smpRefImage = dynamic_cast<InternalImageType*>(smpGenericRefImage.GetPointer());
00243 if (smpRefImage.IsNull()) throwCtrlExceptionMacro("","Error. Link for reference image found, but image seems to have wrong type.");
00244
00245 pMainComponent->SetOutputOrigin(smpRefImage->GetOrigin());
00246 pMainComponent->SetOutputSpacing(smpRefImage->GetSpacing());
00247 pMainComponent->SetOutputStartIndex(smpRefImage->GetLargestPossibleRegion().GetIndex());
00248 pMainComponent->SetSize(smpRefImage->GetLargestPossibleRegion().GetSize());
00249 pMainComponent->SetOutputDirection(smpRefImage->GetDirection());
00250 }
00251 }
00252 };
00253
00254 virtual GenericComponentType* GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00255 SessionComponentCache* pMainComponentCache) const
00256 {
00257 if (compID == cComp_MainInterpolator) return const_cast<typename ComponentType::InterpolatorType*>(pMainComponent->GetInterpolator());
00258
00259 return Superclass::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00260 };
00261
00262 virtual void SetSubComponentCasted(GenericComponentType* pSubComponent, ComponentType* pMainComponent,
00263 const ComponentID compID, SessionComponentCache* pMainComponentCache) const
00264 {
00265 if (compID == cComp_MainInterpolator) pMainComponent->SetInterpolator(dynamic_cast<typename ComponentType::InterpolatorType*>(pSubComponent));
00266 else Superclass::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00267 };
00268
00269 virtual void SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia,
00270 ComponentType* pComponent, SessionComponentCache* pComponentCache,
00271 SessionInfo* pSessionInfo) const
00272 {
00273 if (mediaID == MediaID_transformFunction)
00274 {
00275 typedef TransformFunctionMedia< ScalarType, ComponentType::ImageDimension,ComponentType::ImageDimension > TransformFunctionType;
00276
00277 pComponent->SetTransform((dynamic_cast<TransformFunctionType*>(pMedia))->GetTransform());
00278 }
00279 else if (mediaID == MediaID_outputReference)
00280 {
00281
00282 }
00283 else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00284 };
00285
00286 };
00287
00288 template <class TInputImage>
00289 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParam_DefaultPixelValue = "DefaultPixelValue";
00290 template <class TInputImage>
00291 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParamDsc_DefaultPixelValue = "Value of all pixels that are mapped outside the input image.";
00292 template <class TInputImage>
00293 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParam_OutputOrigin = "OutputOrigin";
00294 template <class TInputImage>
00295 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParamDsc_OutputOrigin = "Origin of the output image.";
00296 template <class TInputImage>
00297 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParam_OutputSpacing = "OutputSpacing";
00298 template <class TInputImage>
00299 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParamDsc_OutputSpacing = "Spacing of the output image.";
00300 template <class TInputImage>
00301 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParam_OutputSize = "OutputSize";
00302 template <class TInputImage>
00303 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParamDsc_OutputSize = "Size of the output image (in pixel/voxel).";
00304 template <class TInputImage>
00305 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParam_OutputStartIndex = "OutputStartIndex";
00306 template <class TInputImage>
00307 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParamDsc_OutputStartIndex = "Start index of the output image.";
00308 template <class TInputImage>
00309 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParam_OutputOrientation = "OutputOrientation";
00310 template <class TInputImage>
00311 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParamDsc_OutputOrientation = "Orientation of the output image. Specifies the orientation as a three letter code (see itk::OrientImageFilter documentation).";
00312 template <class TInputImage>
00313 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParam_UseReferenceInfo = "UseReferenceInfo";
00314 template <class TInputImage>
00315 const char* const ResampleImageFilterControllerBase<TInputImage> :: cParamDsc_UseReferenceInfo = "Indicates how the output parameter (origin, spacing etc) should be determined:\n0: setup values.\n1: use the parameters of the input image.\n2: use the field info of the transform function and set orientation via setup.";
00316
00317 template <class TInputImage>
00318 const char* const ResampleImageFilterControllerBase<TInputImage> :: MediaID_transformFunction = "transformFunction";
00319 template <class TInputImage>
00320 const char* const ResampleImageFilterControllerBase<TInputImage> :: MediaIDDsc_transformFunction = "Transform function used for the resampling process.";
00321
00322 template <class TInputImage>
00323 const char* const ResampleImageFilterControllerBase<TInputImage> :: MediaID_outputReference = "outputReference";
00324 template <class TInputImage>
00325 const char* const ResampleImageFilterControllerBase<TInputImage> :: MediaIDDsc_outputReference = "Reference image that can be used as template for the output image parameters (spacing, origin, size, etc.).";
00326
00332 freControllerIDMacro(Resample2DImageFilterController, "Resample 2D Image Filter");
00333 class Resample2DImageFilterController : public ResampleImageFilterControllerBase< ImageTypes<2>::InternalImageType >
00334 {
00335 public:
00336 typedef ResampleImageFilterControllerBase< ImageTypes<2>::InternalImageType > Superclass;
00337 typedef Resample2DImageFilterController Self;
00338
00339 typedef Superclass::ComponentType ComponentType;
00340 typedef ComponentType::Pointer ComponentPointer;
00341 typedef Superclass::GenericComponentType GenericComponentType;
00342 typedef Superclass::GenericComponentPointer GenericComponentPointer;
00343 typedef Superclass::GenericMediaPointer GenericMediaPointer;
00344
00345 itkTypeMacro(Resample2DImageFilterController, ResampleImageFilterControllerBase);
00346
00347 Resample2DImageFilterController();
00348 };
00349
00355 freControllerIDMacro(Resample3DImageFilterController, "Resample 3D Image Filter");
00356 class Resample3DImageFilterController : public ResampleImageFilterControllerBase< ImageTypes<3>::InternalImageType >
00357 {
00358 public:
00359 typedef ResampleImageFilterControllerBase< ImageTypes<3>::InternalImageType > Superclass;
00360 typedef Resample3DImageFilterController Self;
00361
00362 typedef Superclass::ComponentType ComponentType;
00363 typedef ComponentType::Pointer ComponentPointer;
00364 typedef Superclass::GenericComponentType GenericComponentType;
00365 typedef Superclass::GenericComponentPointer GenericComponentPointer;
00366 typedef Superclass::GenericMediaPointer GenericMediaPointer;
00367
00368 itkTypeMacro(Resample3DImageFilterController, ResampleImageFilterControllerBase);
00369
00370 Resample3DImageFilterController();
00371 };
00372
00373 }
00374
00375 #endif