00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __freImageToImageFilterControllerBase_txx
00024 #define __freImageToImageFilterControllerBase_txx
00025
00026 #include "freImageToImageFilterControllerBase.h"
00027 #include "freIntensityImageMediaController.h"
00028
00029 namespace FREE
00030 {
00034 template <class TControlledFilter>
00035 const char* const ImageToImageFilterControllerBase<TControlledFilter> :: cParam_PersistentResult = "PersistentResult";
00036 template <class TControlledFilter>
00037 const char* const ImageToImageFilterControllerBase<TControlledFilter> :: cParamDsc_PersistentResult = "Indicates if the result should be cached internally and only will be recomputed if the source of the filter is outdated. Keeping the image persistent accelerates the processing, but requires more memory.";
00038
00039 template <class TControlledFilter>
00040 ValidityTag::Pointer
00041 ImageToImageFilterControllerBase<TControlledFilter>::
00042 GetMediaValidityTagRequirement(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00043 {
00044 if (mediaID == "output")
00045 {
00046 ValidityTag::Pointer smpReq = ValidityTag::New(this->GetMediaValidityTag(mediaID,pComponentCache)->GetTimeStamp());
00047 this->CompareValidityTagRequirement("input",smpReq,pComponentCache);
00048 return smpReq;
00049 }
00050
00051 return Superclass::GetMediaValidityTagRequirement(mediaID, pComponentCache);
00052 }
00053
00054 template <class TControlledFilter>
00055 ImageToImageFilterControllerBase<TControlledFilter>::
00056 ImageToImageFilterControllerBase():ProcessorControllerBase<TControlledFilter>()
00057 {
00058
00059 this->UpdateControllerID(ControllerID::ImageToImageFilterControllerBase);
00060 this->m_Description = "Basic class for controller of itk based image filters.";
00061 };
00062
00063 template <class TControlledFilter>
00064 void
00065 ImageToImageFilterControllerBase<TControlledFilter>::
00066 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00067 const SessionComponentCache* pComponentCache,
00068 bool bRegardOldSetup) const
00069 {
00070 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00071
00072
00073 profile.Parameters().AddParameter(cParam_PersistentResult,Parameter::PVTBool,cParamDsc_PersistentResult,1,"true");
00074
00075
00076 profile.MediaMap().AddMedia("input",ControllerID::IntensityImageMediaControllerBase,DASet,ComponentType::InputImageType::ImageDimension);
00077 profile.MediaMap().AddMedia("output",ControllerID::IntensityImageMediaControllerBase,DAGet,ComponentType::InputImageType::ImageDimension);
00078 };
00079
00080 template <class TControlledFilter>
00081 typename ImageToImageFilterControllerBase<TControlledFilter>::GenericMediaPointer
00082 ImageToImageFilterControllerBase<TControlledFilter>::
00083 GetMediaCasted(const MediaID& mediaID,ComponentType* pComponent, SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00084 {
00085 if (mediaID == "output")
00086 {
00087 ValidityTag::Pointer smpVal = this->GetMediaValidityTag("output",pComponentCache);
00088 ValidityTag::Pointer smpValReq = this->GetMediaValidityTagRequirement("output",pComponentCache);
00089
00090 bool bPersistent = false;
00091
00092 try
00093 {
00094 bPersistent = true;
00095 SessionAccessor::GetParameterValue(pComponentCache,cParam_PersistentResult,bPersistent);
00096 }
00097 catchAllNPassMacro("Error; cannot retrieve media \"output\". Parameter is missing in component setup. Missing parameter: "<<cParam_PersistentResult);
00098
00099 GenericMediaPointer smpMedia;
00100
00101 if (smpVal->IsOutdated(smpValReq) || (!bPersistent))
00102 {
00103
00104 this->NotifyProgress(1,"Output outdated -> actualize",pComponentCache);
00105 SessionBuilder::LinkMediaToComponent(pComponentCache, pSessionInfo);
00106 SessionBuilder::ActualizeComponent(pComponentCache, pSessionInfo);
00107
00108 pComponent->ReleaseDataFlagOn();
00109
00110 StatisticEntry* pFilterEntry = this->AddStatisticEntry(pComponentCache, pSessionInfo, "FilterOutput", "Computation of the filter output");
00111
00112 smpMedia = ComputeMedia(mediaID,pComponent,pComponentCache,pSessionInfo);
00113
00114 if (pFilterEntry)
00115 {
00116 this->SetStatisticEntry(*pFilterEntry,pComponentCache,pSessionInfo);
00117 pFilterEntry->CloseEntry();
00118 }
00119
00120 if (bPersistent) DirectSessionComponentAccessor::SetRepositoryElement("output",smpMedia,pComponentCache);
00121
00122 this->ResetComponent(pComponentCache,pSessionInfo);
00123
00124 this->NotifyProgress(1,"Output up to date",pComponentCache);
00125 this->ActualizeMediaValidityTag("output",pComponentCache);
00126 }
00127 else
00128 {
00129 smpMedia = DirectSessionComponentAccessor::GetRepositoryElement("output",pComponentCache);
00130 }
00131
00132 return smpMedia;
00133 }
00134
00135 return Superclass::GetMediaCasted(mediaID, pComponent, pComponentCache, pSessionInfo);
00136 };
00137
00138 template <class TControlledFilter>
00139 void
00140 ImageToImageFilterControllerBase<TControlledFilter>::
00141 ActualizeMainComponent(ComponentType* pMainComponent,
00142 SessionComponentCache* pComponentCache,
00143 SessionInfo* pSessionInfo,
00144 const unsigned int& iActLevel) const
00145 {
00146 Superclass::ActualizeMainComponent(pMainComponent,pComponentCache, pSessionInfo, iActLevel);
00147
00148 bool bPersistent = false;
00149
00150 try
00151 {
00152 bPersistent = true;
00153 SessionAccessor::GetParameterValue(pComponentCache,cParam_PersistentResult,bPersistent);
00154 }
00155 catchAllNPassMacro("Error; cannot actualize setup. Parameter is missing in component setup. Missing parameter: "<<cParam_PersistentResult);
00156
00157 if (bPersistent)
00158 {
00159 pMainComponent->ReleaseDataFlagOff();
00160 pMainComponent->ReleaseDataBeforeUpdateFlagOff();
00161 }
00162 else
00163 {
00164 pMainComponent->ReleaseDataFlagOn();
00165 pMainComponent->ReleaseDataBeforeUpdateFlagOn();
00166 }
00167 };
00168
00169 template <class TControlledFilter>
00170 typename ImageToImageFilterControllerBase<TControlledFilter>::GenericMediaPointer
00171 ImageToImageFilterControllerBase<TControlledFilter>::
00172 ComputeMedia(const MediaID& mediaID,ComponentType* pComponent, SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00173 {
00174 GenericMediaPointer smpMedia;
00175
00176 if (mediaID == "output")
00177 {
00178 pComponent->Update();
00179 typename ComponentType::OutputImagePointer smpOutput = pComponent->GetOutput();
00180
00181
00182
00183
00184
00185 smpOutput->DisconnectPipeline();
00186
00187 smpMedia = smpOutput.GetPointer();
00188 }
00189 else throwCtrlExceptionMacro("", "Error. Only the computation of mediaID \"output\" is possible. Invalide mediaID: "<<mediaID);
00190
00191 return smpMedia;
00192 }
00193
00194 template <class TControlledFilter>
00195 void
00196 ImageToImageFilterControllerBase<TControlledFilter>::
00197 SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia, ComponentType* pComponent, SessionComponentCache* pComponentCache,
00198 SessionInfo* pSessionInfo) const
00199 {
00200 if (mediaID == "input")
00201 {
00202 pComponent->SetInput(dynamic_cast<typename TControlledFilter::InputImageType*>(pMedia));
00203 this->ActualizeMediaValidityTag("input",pComponentCache);
00204 }
00205 else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00206 };
00207
00208 }
00209
00210 #endif