00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __freClosedFormRegistrationControllerBase_txx
00024 #define __freClosedFormRegistrationControllerBase_txx
00025
00026 #include "freClosedFormRegistrationControllerBase.h"
00027
00028 #include "freRegistrationProcessEventHandler.h"
00029 #include "freIntensityImageMediaController.h"
00030 #include "freTransformFieldMediaController.h"
00031 #include "frePointSetMediaController.h"
00032 #include "freRigid2DTransformController.h"
00033 #include "freVersorRigid3DTransformController.h"
00034 #include "freTransformFunctionMediaController.h"
00035
00036 namespace FREE
00037 {
00041 template <class ComponentType>
00042 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: cParam_PersistentFinalField = "PersistentFinalField";
00043 template <class ComponentType>
00044 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: cParamDsc_PersistentFinalField = "Indicates if the final field should be stored internally and only will be recomputed if registration is outdated. Keeping the image persistent accelerates the processing, but requires more memory.";
00045
00046 template <class ComponentType>
00047 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaID_finalField = "finalField";
00048 template <class ComponentType>
00049 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaIDDsc_finalField = "Transformation field generated by using the current/final transform of the registration.";
00050 template <class ComponentType>
00051 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaID_fieldReference = "fieldReference";
00052 template <class ComponentType>
00053 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaIDDsc_fieldReference = "Image that is reference for origin, size and spacing of the final field.";
00054 template <class ComponentType>
00055 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaID_finalTransform = "finalTransform";
00056 template <class ComponentType>
00057 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaIDDsc_finalTransform = "Transformation function of the current/final transform of the registration.";
00058 template <class ComponentType>
00059 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaID_finalInverseTransform = "finalInverseTransform";
00060 template <class ComponentType>
00061 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaIDDsc_finalInverseTransform = "Transformation function of the current/final transform of the registration. This media is only valid if the transform can be inverted";
00062
00063 template <class ComponentType>
00064 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaID_fixedPointSet = "fixedPointSet";
00065 template <class ComponentType>
00066 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaIDDsc_fixedPointSet = "Fixed point set of the registration.";
00067 template <class ComponentType>
00068 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaID_movingPointSet = "movingPointSet";
00069 template <class ComponentType>
00070 const char* const ClosedFormRegistrationControllerBase<ComponentType> :: MediaIDDsc_movingPointSet = "Moving point set of the registration.";
00071
00072
00073 template <class ComponentType>
00074 typename ClosedFormRegistrationControllerBase<ComponentType>::ComponentPointer
00075 ClosedFormRegistrationControllerBase<ComponentType>::
00076 BuildMainComponent(ComponentSetup* pComponentSetup, SessionComponentCache* pComponentCache) const
00077 {
00078 ComponentPointer mainComponent = Superclass::BuildMainComponent(pComponentSetup,pComponentCache);
00079 DirectSessionComponentAccessor::SetRepositoryElement(SessionComponentRepositoryKeys::Validity("Registration"),ValidityTag::NewNull(),pComponentCache);
00080 return mainComponent;
00081 };
00082
00083 template <class ComponentType>
00084 void
00085 ClosedFormRegistrationControllerBase<ComponentType>::
00086 ActualizeMainComponent(ComponentType* pMainComponent,
00087 SessionComponentCache* pComponentCache,
00088 SessionInfo* pSessionInfo,
00089 const unsigned int& iActLevel) const
00090 {
00091 Superclass::ActualizeMainComponent(pMainComponent,pComponentCache, pSessionInfo, iActLevel);
00092
00093
00094 pMainComponent->SetSessionInfo(pSessionInfo);
00095 pMainComponent->SetComponentCache(pComponentCache);
00096 }
00097
00098 template <class ComponentType>
00099 ValidityTag::Pointer
00100 ClosedFormRegistrationControllerBase<ComponentType>::
00101 GetMediaValidityTagRequirement(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00102 {
00103 if ((mediaID == MediaID_finalField) || (mediaID == MediaID_finalTransform) || (mediaID == MediaID_finalInverseTransform))
00104 {
00105 ValidityTag::Pointer smpReq = ValidityTag::New(this->GetMediaValidityTag(mediaID,pComponentCache)->GetTimeStamp());
00106
00107
00108 ValidityTag::Pointer smpRegistrationReq = this->GetValidityTagRequirement("Registration",pComponentCache);
00109 if (smpReq->IsOutdated(smpRegistrationReq))
00110 {
00111 smpReq->SetTag(smpRegistrationReq);
00112 }
00113 return smpReq;
00114 }
00115
00116 return Superclass::GetMediaValidityTagRequirement(mediaID, pComponentCache);
00117 }
00118
00119 template <class ComponentType>
00120 ValidityTag::Pointer
00121 ClosedFormRegistrationControllerBase<ComponentType>::
00122 GetValidityTagRequirement(const std::string& id, SessionComponentCache* pComponentCache) const
00123 {
00124 if (id == "Registration")
00125 {
00126 ValidityTag::Pointer smpReq = ValidityTag::New(this->GetValidityTag(id,pComponentCache)->GetTimeStamp());
00127
00128
00129 this->CompareValidityTagRequirement(MediaID_movingPointSet,smpReq,pComponentCache);
00130 this->CompareValidityTagRequirement(MediaID_fixedPointSet,smpReq,pComponentCache);
00131
00132 return smpReq;
00133 }
00134
00135 return Superclass::GetMediaValidityTagRequirement(id, pComponentCache);
00136 }
00137
00138 template <class ComponentType>
00139 ClosedFormRegistrationControllerBase<ComponentType>::
00140 ClosedFormRegistrationControllerBase()
00141 {
00142
00143 this->UpdateControllerID(ControllerID::ClosedFormRegistrationControllerBase);
00144 this->m_Description = "Realizes a rigid registration via closed form solution using reference point sets.";
00145 };
00146
00147 template <class ComponentType>
00148 void
00149 ClosedFormRegistrationControllerBase<ComponentType>::
00150 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00151 const SessionComponentCache* pComponentCache,
00152 bool bRegardOldSetup) const
00153 {
00154 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00155
00156
00157 profile.Parameters().AddParameter(cParam_PersistentFinalField,Parameter::PVTBool,cParamDsc_PersistentFinalField,1,"true");
00158
00159
00160 profile.SubComponents().AddSubComponent(cComp_MainTransform,1,csUndefinedController,cCompDsc_MainTransform);
00161
00162
00163 if (ComponentType::ImageDimension == 2)
00164 {
00165 profile.MediaMap().AddMedia(MediaID_finalField,ControllerID::TransformField2DMediaController,DAGet,ComponentType::ImageDimension);
00166
00167 profile.MediaMap().AddMedia(MediaID_movingPointSet,ControllerID::PointSet2DMediaController,DAGet,ComponentType::ImageDimension);
00168 profile.MediaMap().AddMedia(MediaID_fixedPointSet,ControllerID::PointSet2DMediaController,DAGet,ComponentType::ImageDimension);
00169 }
00170 else
00171 {
00172 profile.MediaMap().AddMedia(MediaID_finalField,ControllerID::TransformField3DMediaController,DAGet,ComponentType::ImageDimension);
00173
00174 profile.MediaMap().AddMedia(MediaID_movingPointSet,ControllerID::PointSet3DMediaController,DAGet,ComponentType::ImageDimension);
00175 profile.MediaMap().AddMedia(MediaID_fixedPointSet,ControllerID::PointSet3DMediaController,DAGet,ComponentType::ImageDimension);
00176 }
00177
00178 profile.MediaMap().AddMedia(MediaID_fieldReference,ControllerID::ImageMediaControllerBase, DASet,ComponentType::ImageDimension,0);
00179
00180 profile.MediaMap().AddMedia(MediaID_finalTransform,ControllerID::TransformFunctionMediaControllerBase, DAGet,ComponentType::ImageDimension);
00181 profile.MediaMap().AddMedia(MediaID_finalInverseTransform,ControllerID::TransformFunctionMediaControllerBase, DAGet,ComponentType::ImageDimension);
00182
00183
00184 CtrlProfile::ProfileOption* pOption;
00185
00186
00187 pOption = profile.Requirements().AddRequirement(cComp_MainTransform)->AddProfileOption();
00188 if (ComponentType::ImageDimension == 2)
00189 {
00190 pOption->Inheritance().AddAncestor(ControllerID::Rigid2DTransformController);
00191 }
00192 else
00193 {
00194 pOption->Inheritance().AddAncestor(ControllerID::VersorRigid3DTransformController);
00195 }
00196 pOption->CheckForInheritance();
00197 pOption->CheckForIO();
00198 };
00199
00200 template <class ComponentType>
00201 typename ClosedFormRegistrationControllerBase<ComponentType>::GenericComponentType*
00202 ClosedFormRegistrationControllerBase<ComponentType>::
00203 GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00204 SessionComponentCache* pMainComponentCache) const
00205 {
00206 if (compID == cComp_MainTransform) return pMainComponent->GetTransform();
00207
00208 return Superclass::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00209 };
00210
00211 template <class ComponentType>
00212 void
00213 ClosedFormRegistrationControllerBase<ComponentType>::
00214 SetSubComponentCasted(GenericComponentType* pSubComponent, ComponentType* pMainComponent,
00215 const ComponentID compID, SessionComponentCache* pMainComponentCache) const
00216 {
00217 if (compID == cComp_MainTransform) pMainComponent->SetTransform(dynamic_cast<typename ComponentType::TransformType*>(pSubComponent));
00218 else Superclass::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00219 };
00220
00221 template <class ComponentType>
00222 typename ClosedFormRegistrationControllerBase<ComponentType>::GenericMediaPointer
00223 ClosedFormRegistrationControllerBase<ComponentType>::
00224 GetMediaCasted(const MediaID& mediaID,ComponentType* pComponent, SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00225 {
00226 GenericMediaPointer smpMedia;
00227
00228 if ((mediaID == MediaID_finalField) || (mediaID == MediaID_finalTransform) || (mediaID == MediaID_finalInverseTransform))
00229 {
00230 typename ValidityTag::Pointer smpRegistrationValidity = this->GetValidityTag("Registration",pComponentCache);
00231 typename ValidityTag::Pointer smpRegistrationValidityReq = this->GetValidityTagRequirement("Registration",pComponentCache);
00232
00233 if (smpRegistrationValidity->IsOutdated(smpRegistrationValidityReq))
00234 {
00235 this->NotifyProgress(1,"Registration outdated -> actualize",pComponentCache);
00236 SessionBuilder::LinkMediaToComponent(pComponentCache, pSessionInfo);
00237 SessionBuilder::ActualizeComponent(pComponentCache, pSessionInfo);
00238
00239 StatisticEntry* pRegistrationEntry = Superclass::AddStatisticEntry(pComponentCache, pSessionInfo, "Registration", "a closed form registration");
00240
00241 pComponent->StartRegistration();
00242
00243 if (pRegistrationEntry) pRegistrationEntry->CloseEntry();
00244
00245 this->ResetComponent(pComponentCache, pSessionInfo);
00246
00247 this->ActualizeValidityTag("Registration",pComponentCache);
00248 this->NotifyProgress(1,"Registration updated",pComponentCache);
00249 }
00250
00251 if (mediaID == MediaID_finalField)
00252 {
00253 ValidityTag::Pointer smpVal = this->GetMediaValidityTag(mediaID,pComponentCache);
00254 ValidityTag::Pointer smpValReq = this->GetMediaValidityTagRequirement(mediaID,pComponentCache);
00255
00256 bool bKeep = true;
00257 SessionAccessor::GetParameterValue(pComponentCache,cParam_PersistentFinalField,bKeep);
00258
00259 if (smpVal->IsOutdated(smpValReq) || (!bKeep))
00260 {
00261 this->NotifyProgress(1,"Final field outdated -> actualize",pComponentCache);
00262
00263 StatisticEntry* pRegistrationFieldEntry = Superclass::AddStatisticEntry(pComponentCache, pSessionInfo, "ComputeDeformationField", "Computation of a deformation field");
00264
00265 try
00266 {
00267 typename ComponentMediaLink::Pointer smpLink = pComponentCache->Setup()->MediaLinks().GetElement(MediaID_fieldReference);
00268 if (smpLink.IsNull())
00269 {
00270 throwCtrlExceptionMacro("","Error. Cannot generate transformation field. No field reference set for closed form registration.");
00271 }
00272 else
00273 {
00274 GenericMediaPointer smpFieldRef = SessionAccessor::GetMedia(smpLink->GetSourceIDPath(), pSessionInfo);
00275
00276 typedef typename ComponentType::ImageType::Superclass ComponentImageBaseType;
00277 ComponentImageBaseType* pFieldRef = dynamic_cast<ComponentImageBaseType*>(smpFieldRef.GetPointer());
00278 if (!pFieldRef) throwCtrlExceptionMacro("","Error. Link for field reference found, but field seems to have wrong type.");
00279
00280 smpMedia = pComponent->GetTransformationField(pFieldRef->GetOrigin(),pFieldRef->GetLargestPossibleRegion(),pFieldRef->GetSpacing());
00281 }
00282 }
00283 catchAllNPassMacro("Unkown error while computing transormation field.");
00284
00285 if (pRegistrationFieldEntry) pRegistrationFieldEntry->CloseEntry();
00286
00287 if (bKeep) DirectSessionComponentAccessor::SetRepositoryElement(mediaID,smpMedia,pComponentCache);
00288 this->ActualizeMediaValidityTag(mediaID,pComponentCache);
00289 }
00290 else
00291 {
00292 smpMedia = DirectSessionComponentAccessor::GetRepositoryElement(mediaID,pComponentCache);
00293 }
00294 }
00295 else
00296 {
00297 try
00298 {
00299 ComponentMediaLink::Pointer smpLink = pComponentCache->Setup()->MediaLinks().GetElement(MediaID_fieldReference);
00300 if (smpLink.IsNull())
00301 {
00302 if (mediaID == MediaID_finalTransform)
00303 {
00304 smpMedia = pComponent->GetTransformationFunction();
00305 }
00306 else
00307 {
00308 smpMedia = pComponent->GetInverseTransformationFunction();
00309 }
00310 }
00311 else
00312 {
00313 GenericMediaPointer smpFieldRef = SessionAccessor::GetMedia(smpLink->GetSourceIDPath(), pSessionInfo);
00314
00315 typedef typename ComponentType::ImageType::Superclass ComponentImageBaseType;
00316 ComponentImageBaseType* pFieldRef = dynamic_cast<ComponentImageBaseType*>(smpFieldRef.GetPointer());
00317 if (!pFieldRef) throwCtrlExceptionMacro("","Error. Link for field reference found, but field seems to have wrong type.");
00318
00319 if (mediaID == MediaID_finalTransform)
00320 {
00321 smpMedia = pComponent->GetTransformationFunction(pFieldRef->GetOrigin(),pFieldRef->GetLargestPossibleRegion(),pFieldRef->GetSpacing());
00322 }
00323 else
00324 {
00325 smpMedia = pComponent->GetInverseTransformationFunction(pFieldRef->GetOrigin(),pFieldRef->GetLargestPossibleRegion(),pFieldRef->GetSpacing());
00326 }
00327 }
00328 }
00329 catchAllNPassMacro("Unkown error while computing transormation function.");
00330
00331 this->ActualizeMediaValidityTag(mediaID,pComponentCache);
00332 }
00333 return smpMedia;
00334 }
00335
00336 return Superclass::GetMediaCasted(mediaID, pComponent, pComponentCache, pSessionInfo);
00337 };
00338
00339
00340 template <class ComponentType>
00341 void
00342 ClosedFormRegistrationControllerBase<ComponentType>::
00343 SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia, ComponentType* pComponent, SessionComponentCache* pComponentCache,
00344 SessionInfo* pSessionInfo) const
00345 {
00346 if (mediaID == MediaID_movingPointSet)
00347 {
00348 pComponent->SetMovingPointSet(dynamic_cast<typename ComponentType::PointSetType*>(pMedia));
00349 this->ActualizeMediaValidityTag(MediaID_movingPointSet,pComponentCache);
00350 }
00351 else if (mediaID == MediaID_fixedPointSet)
00352 {
00353 pComponent->SetFixedPointSet(dynamic_cast<typename ComponentType::PointSetType*>(pMedia));
00354 this->ActualizeMediaValidityTag(MediaID_fixedPointSet,pComponentCache);
00355 }
00356 else if (mediaID == MediaID_fieldReference)
00357 {
00358
00359 }
00360 else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00361 };
00362
00363 template <class ComponentType>
00364 void
00365 ClosedFormRegistrationControllerBase<ComponentType>::
00366 ResetSubComponents(SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00367 {
00369 };
00370
00371 template <class ComponentType>
00372 void
00373 ClosedFormRegistrationControllerBase<ComponentType>::
00374 ResetMainComponent(SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00375 {
00377 };
00378
00379 }
00380
00381 #endif