00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freDemonRegistrationController_h
00023 #define __freDemonRegistrationController_h
00024
00025 #include "freRegistrationProcessorControllerBase.h"
00026 #include "freInterpolatorControllerBase.h"
00027 #include "freDemonRegistrationProcessor.h"
00028
00029 #include "freIntensityImageMediaController.h"
00030 #include "freTransformFieldMediaController.h"
00031
00032 namespace FREE
00033 {
00043 freControllerIDMacro(DemonRegistrationControllerBase, "DemonRegistrationBase");
00044 template < class TControlledDemonProcessor >
00045 class DemonRegistrationControllerBase : public RegistrationProcessorControllerBase<TControlledDemonProcessor>
00046 {
00047 public:
00048 typedef TControlledDemonProcessor ComponentType;
00049 typedef RegistrationProcessorControllerBase<ComponentType> Superclass;
00050 typedef typename Superclass::GenericComponentType GenericComponentType;
00051 typedef typename Superclass::GenericComponentPointer GenericComponentPointer;
00052 typedef typename Superclass::GenericMediaPointer GenericMediaPointer;
00053
00054 itkTypeMacro(DemonRegistrationControllerBase, RegistrationProcessorControllerBase);
00055
00056 virtual ValidityTag::Pointer GetMediaValidityTagRequirement(const MediaID& mediaID,
00057 SessionComponentCache* pComponentCache) const
00058 {
00059 if (mediaID == "finalField")
00060 {
00061 ValidityTag::Pointer smpReq = ValidityTag::New(this->GetMediaValidityTagRequirement(mediaID,pComponentCache)->GetTimeStamp());
00062
00063
00064 ComponentMediaLink::Pointer smpLink = pComponentCache->Setup()->MediaLinks().GetElement("movingImage");
00065 if (smpLink.IsNotNull())
00066 {
00067 ValidityTag::Pointer smpImageReq = SessionAccessor::GetValidityTagRequirement(smpLink->GetSourceIDPath(),pComponentCache);
00068 if (smpReq->IsOutdated(smpImageReq))
00069 {
00070 smpReq->SetTag(smpImageReq);
00071 }
00072 }
00073
00074 smpLink = pComponentCache->Setup()->MediaLinks().GetElement("fixedImage");
00075 if (smpLink.IsNotNull())
00076 {
00077 ValidityTag::Pointer smpImageReq = SessionAccessor::GetValidityTagRequirement(smpLink->GetSourceIDPath(),pComponentCache);
00078 if (smpReq->IsOutdated(smpImageReq))
00079 {
00080 smpReq->SetTag(smpImageReq);
00081 }
00082 }
00083 return smpReq;
00084 }
00085
00086 return Superclass::GetMediaValidityTagRequirement(mediaID, pComponentCache);
00087 }
00088
00089 protected:
00090 DemonRegistrationControllerBase():Superclass()
00091 {
00092
00093 this->UpdateControllerID(ControllerID::DemonRegistrationControllerBase);
00094 this->m_Description = "Realizes a demon based registration.";
00095 };
00096
00097 virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00098 const SessionComponentCache* pComponentCache,
00099 bool bRegardOldSetup) const
00100 {
00101 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00102
00103
00104 profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTInteger,cParamDsc_Iterations,1,"10");
00105 profile.Parameters().AddParameter(cParam_StdDev,CtrlProfile::Parameter::PVTDouble,cParamDsc_StdDev,1,"1.0");
00106 profile.Parameters().AddParameter(cParam_HistoMatch,Parameter::PVTBool,cParamDsc_HistoMatch,1,"false");
00107 profile.Parameters().AddParameter(cParam_HistoLevels,Parameter::PVTLong,cParamDsc_HistoLevels,1,"1024");
00108 profile.Parameters().AddParameter(cParam_HistoMatchPoints,Parameter::PVTLong,cParamDsc_HistoMatchPoints,1,"5");
00109 profile.Parameters().AddParameter(cParam_HistoThreshold,Parameter::PVTBool,cParamDsc_HistoThreshold,1,"1");
00110
00111
00112 std::string sImageControllerID = ControllerID::IntensityImage2DMediaController;
00113 if (ComponentType::ImageDimension == 3) sImageControllerID = ControllerID::IntensityImage3DMediaController;
00114 profile.MediaMap().AddMedia("movingImage",sImageControllerID,DASet,ComponentType::ImageDimension);
00115 profile.MediaMap().AddMedia("fixedImage",sImageControllerID,DASet,ComponentType::ImageDimension);
00116
00117 std::string sTransformControllerID = ControllerID::TransformField2DMediaController;
00118 if (ComponentType::ImageDimension == 3) sTransformControllerID = ControllerID::TransformField3DMediaController;
00119 profile.MediaMap().AddMedia("finalField",sTransformControllerID,DAGet,ComponentType::ImageDimension);
00120
00121
00122 profile.SubComponents().AddSubComponent(cComp_MainInterpolator,1,csUndefinedController,cCompDsc_MainInterpolator);
00123
00124
00125 CtrlProfile::ProfileOption* pOption;
00126
00127 pOption = profile.Requirements().AddRequirement(cComp_MainInterpolator)->AddProfileOption();
00128 pOption->Inheritance().AddAncestor(ControllerID::InterpolatorControllerBase);
00129 pOption->MediaMap().AddMedia("inputImage",sImageControllerID,DASet,ComponentType::ImageDimension,0,true);
00130 pOption->CheckForInheritance();
00131 pOption->CheckForIO();
00132 };
00133
00134 virtual GenericComponentType* GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00135 SessionComponentCache* pMainComponentCache) const
00136 {
00137 if (compID == cComp_MainInterpolator) return pMainComponent->smpInterpolate.GetPointer();
00138
00139 return Superclass::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00140 };
00141
00142 virtual void SetSubComponentCasted(GenericComponentType* pSubComponent, ComponentType* pMainComponent,
00143 const ComponentID compID, SessionComponentCache* pMainComponentCache) const
00144 {
00145 if (compID == cComp_MainInterpolator) pMainComponent->smpInterpolate = dynamic_cast<typename ComponentType::InterpolateType*>(pSubComponent);
00146 else Superclass::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00147 };
00148
00149
00150 virtual GenericMediaPointer GetMediaCasted(const MediaID& mediaID,
00151 ComponentType* pComponent,
00152 SessionComponentCache* pComponentCache,
00153 SessionInfo* pSessionInfo) const
00154 {
00155 GenericMediaPointer smpMedia;
00156 if (mediaID == "movingImage") return GenericMediaPointer(pComponent->GetMovingImage());
00157 if (mediaID == "fixedImage") return GenericMediaPointer(pComponent->GetFixedImage());
00158 if (mediaID == "finalField")
00159 {
00160 ValidityTag::Pointer smpValField = this->GetMediaValidityTag(mediaID,pComponentCache);
00161 ValidityTag::Pointer smpValReqField = this->GetMediaValidityTagRequirement(mediaID,pComponentCache);
00162
00163 if (smpValField->IsOutdated(smpValReqField))
00164 {
00165 SessionBuilder::ActualizeComponent(pComponentCache, pSessionInfo);
00166 SessionBuilder::LinkMediaToComponent(pComponentCache, pSessionInfo);
00167
00168 pComponent->StartRegistration();
00169
00170 this->ActualizeMediaValidityTag("finalImage",pComponentCache);
00171 this->ActualizeMediaValidityTag("finalField",pComponentCache);
00172 }
00173
00174 smpMedia = pComponent->GetTransformationField();
00175
00176 return smpMedia;
00177 }
00178
00179 return Superclass::GetMediaCasted(mediaID, pComponent, pComponentCache, pSessionInfo);
00180 };
00181
00182 virtual void SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia,
00183 ComponentType* pComponent, SessionComponentCache* pComponentCache,
00184 SessionInfo* pSessionInfo) const
00185 {
00186 if (mediaID == "movingImage")
00187 {
00188 pComponent->SetMovingImage(dynamic_cast<typename ComponentType::ImageType*>(pMedia));
00189 this->ActualizeMediaValidityTag("movingImage",pComponentCache);
00190 }
00191 else if (mediaID == "fixedImage")
00192 {
00193 pComponent->SetFixedImage(dynamic_cast<typename ComponentType::ImageType*>(pMedia));
00194 this->ActualizeMediaValidityTag("fixedImage",pComponentCache);
00195 }
00196 else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00197 };
00198
00199 };
00200
00210 freControllerIDMacro(Demon2DRegistrationController, "Demon Registration 2D");
00211 class Demon2DRegistrationController : public DemonRegistrationControllerBase<DemonRegistrationProcessor2D>
00212 {
00213 public:
00214 typedef DemonRegistrationProcessor2D ComponentType;
00215 typedef DemonRegistrationControllerBase<ComponentType> Superclass;
00216
00217 itkTypeMacro(Demon2DRegistrationController, DemonRegistrationControllerBase);
00218
00219 Demon2DRegistrationController();
00220 };
00221
00231 freControllerIDMacro(Demon3DRegistrationController, "Demon Registration 3D");
00232 class Demon3DRegistrationController : public DemonRegistrationControllerBase<DemonRegistrationProcessor3D>
00233 {
00234 public:
00235 typedef DemonRegistrationProcessor3D ComponentType;
00236 typedef DemonRegistrationControllerBase<ComponentType> Superclass;
00237
00238 itkTypeMacro(Demon3DRegistrationController, DemonRegistrationControllerBase);
00239
00240 Demon3DRegistrationController();
00241 };
00242
00243 }
00244
00245 #endif