00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "freMediaActualizerController.h"
00024 #include "freTransformFieldMediaController.h"
00025 #include "freTransformFunctionMediaController.h"
00026
00027 namespace FREE
00028 {
00029 DefineParameterMacro(MediaActualizerController,PersistentResult,"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.");
00030 DefineParameterMacro(MediaActualizerController,UseField,"UseField","Indicates if the media should be actualized by using a field (true) or by using a transformation function (false).");
00031
00032 DefineMediaIDMacro(MediaActualizerController,deformationField,"deformationField","The deformation field that can be used for actualization.");
00033 DefineMediaIDMacro(MediaActualizerController,transformFunction,"deformationTransformFunction","The transformation function that can be used for actualization.");
00034
00035 ValidityTag::Pointer
00036 MediaActualizerController::
00037 GetMediaValidityTag(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00038 {
00039 if (!pComponentCache) throwCtrlExceptionMacro("","Passed component cache is NULL.");
00040
00041 if ((mediaID!=MediaID_deformationField) && (mediaID!=MediaID_transformFunction))
00042 {
00043
00044 std::string sElementKey = SessionComponentRepositoryKeys::MediaValidity(mediaID);
00045 SessionComponentCache::GenericComponentPointer smpGenericTag = DirectSessionComponentAccessor::GetRepositoryElement(sElementKey,pComponentCache);
00046
00047 ValidityTag::Pointer smpTag;
00048
00049 if (smpGenericTag.IsNotNull())
00050 {
00051 try
00052 {
00053 smpTag = dynamic_cast<ValidityTag*>(smpGenericTag.GetPointer());
00054 }
00055 catchAllNPassMacro("Error; cannot determine the media validity tag. Found a repository element, but element was not of type ValidityTag. MediaID :" << mediaID);
00056 if (smpTag.IsNull()) throwCtrlExceptionMacro("","Error; cannot determine the media validity tag. Found a repository element, but element was not of type ValidityTag. MediaID :" << mediaID);
00057 }
00058 else
00059 {
00060 smpTag = ValidityTag::NewNull();
00061 }
00062 return smpTag;
00063 }
00064 else
00065 {
00066
00067 ComponentMediaLink::Pointer smpLink = pComponentCache->Setup()->MediaLinks().GetElement(mediaID);
00068 if (smpLink.IsNotNull())
00069 {
00070 try
00071 {
00072 return SessionAccessor::GetValidityTag(smpLink->GetSourceIDPath(),pComponentCache);
00073 }
00074 catchAllNPassMacro("Error while retrieving validity tag. Media ID: "<<mediaID<<" ; link: "<<smpLink->GetSourceIDPath().ToStr());
00075 }
00076 else
00077 {
00078 return Superclass::GetMediaValidityTag(mediaID, pComponentCache);
00079 }
00080 }
00081 };
00082
00083
00084 ValidityTag::Pointer
00085 MediaActualizerController::
00086 GetMediaValidityTagRequirement(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00087 {
00088 if (!pComponentCache) throwCtrlExceptionMacro("","Passed component cache is NULL.");
00089
00090 if ((mediaID!=MediaID_deformationField) && (mediaID!=MediaID_transformFunction))
00091 {
00092 ValidityTag::Pointer smpReq = ValidityTag::New(this->GetMediaValidityTag(mediaID,pComponentCache)->GetTimeStamp());
00093
00094
00095
00096 ValidityTag::Pointer smpActualizerReq;
00097
00098 if (UseField(pComponentCache))
00099 {
00100 smpActualizerReq = this->GetMediaValidityTagRequirement(MediaID_deformationField,pComponentCache);
00101 }
00102 else
00103 {
00104 smpActualizerReq = this->GetMediaValidityTagRequirement(MediaID_transformFunction,pComponentCache);
00105 }
00106
00107 if (smpReq->IsOutdated(smpActualizerReq))
00108 {
00109 smpReq->SetTag(smpActualizerReq);
00110 }
00111 return smpReq;
00112 }
00113
00114 ComponentMediaLink::Pointer smpLink = pComponentCache->Setup()->MediaLinks().GetElement(mediaID);
00115 if (smpLink.IsNotNull())
00116 {
00117 try
00118 {
00119 return SessionAccessor::GetValidityTagRequirement(smpLink->GetSourceIDPath(),pComponentCache);
00120 }
00121 catchAllNPassMacro("Error while retrieving validity tag requirement. Media ID: "<<mediaID<<" ; link: "<<smpLink->GetSourceIDPath().ToStr());
00122 }
00123 else
00124 {
00125 return Superclass::GetMediaValidityTagRequirement(mediaID, pComponentCache);
00126 }
00127 };
00128
00129 bool
00130 MediaActualizerController::
00131 UseField(SessionComponentCache* pComponentCache) const
00132 {
00133 bool bUseField = true;
00134 SessionAccessor::GetParameterValue(pComponentCache,cParam_UseField,bUseField);
00135
00136 return bUseField;
00137 }
00138
00139 std::string
00140 MediaActualizerController::
00141 GetMediaControllerID(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00142 {
00143 if (!pComponentCache) throwCtrlExceptionMacro("","Passed component cache is NULL.");
00144
00145 ComponentMediaLink::Pointer smpLink = pComponentCache->Setup()->MediaLinks().GetElement(mediaID);
00146 if (smpLink.IsNotNull())
00147 {
00148 try
00149 {
00150 return SessionAccessor::GetMediaControllerID(smpLink->GetSourceIDPath(),pComponentCache);
00151 }
00152 catchAllNPassMacro("Error while retrieving controller id. Media ID: "<<mediaID<<" ; link: "<<smpLink->GetSourceIDPath().ToStr());
00153 }
00154
00155 return csUndefinedController;
00156 };
00157
00158 MediaActualizerController::
00159 MediaActualizerController()
00160 {
00161
00162 this->UpdateControllerID(ControllerID::MediaActualizerController);
00163 this->m_Description = "Actualizes media via a given deformation field";
00164 };
00165
00166 void
00167 MediaActualizerController::
00168 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00169 const SessionComponentCache* pComponentCache,
00170 bool bRegardOldSetup) const
00171 {
00172 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00173
00174
00175 profile.Parameters().AddParameter(cParam_PersistentResult,Parameter::PVTBool,cParamDsc_PersistentResult,1,"true");
00176 profile.Parameters().AddParameter(cParam_UseField,Parameter::PVTBool,cParamDsc_UseField,1,"true");
00177
00178
00179 profile.MediaMap().AddMedia(MediaID_deformationField,ControllerID::TransformFieldMediaControllerBase,DASet,CtrlProfile::Media::DT_AllDimensions,0);
00180 profile.MediaMap().AddMedia(MediaID_transformFunction,ControllerID::TransformFunctionMediaControllerBase,DASet,CtrlProfile::Media::DT_AllDimensions,0);
00181
00182
00183 profile.MediaMap().AddMedia("targetMedia",ControllerID::MediaControllerBase,DAAny)->SetIsTemplate(true);
00184 };
00185
00186 MediaActualizerController::
00187 GenericMediaPointer
00188 MediaActualizerController::
00189 GetMediaCasted(const MediaID& mediaID, ComponentType* pComponent,
00190 SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00191 {
00192 if ((mediaID!=MediaID_deformationField) && (mediaID!=MediaID_transformFunction))
00193 {
00194
00195 ComponentMediaLink::Pointer smpLink = pComponentCache->Setup()->MediaLinks().GetElement(mediaID);
00196 if (smpLink.IsNotNull())
00197 {
00198 GenericMediaPointer smpMedia;
00199
00200 ValidityTag::Pointer smpVal = this->GetMediaValidityTag(mediaID,pComponentCache);
00201 ValidityTag::Pointer smpValReq = this->GetMediaValidityTagRequirement(mediaID,pComponentCache);
00202
00203 bool bKeep = true;
00204 SessionAccessor::GetParameterValue(pComponentCache,cParam_PersistentResult,bKeep);
00205
00206 if (smpVal->IsOutdated(smpValReq) || (!bKeep))
00207 {
00208 this->NotifyProgress(1,"Media outdated -> actualize",pComponentCache);
00209
00210
00211 if (UseField(pComponentCache))
00212 {
00213 ComponentMediaLink::Pointer smpFieldLink = pComponentCache->Setup()->MediaLinks().GetElement(MediaID_deformationField);
00214 if (smpFieldLink.IsNull()) throwCtrlExceptionMacro("","Error, cannot actualize media. Deformation field is not defined.");
00215
00216 try
00217 {
00218
00219 smpMedia = pComponent->ActualizeMediaByField(pSessionInfo,smpLink->GetSourceIDPath(),smpFieldLink->GetSourceIDPath());
00220 }
00221 catchAllNPassMacro("Error while actualizing the media.");
00222 }
00223 else
00224 {
00225 ComponentMediaLink::Pointer smpFunctLink = pComponentCache->Setup()->MediaLinks().GetElement(MediaID_transformFunction);
00226 if (smpFunctLink.IsNull()) throwCtrlExceptionMacro("","Error, cannot actualize media. Transform function is not defined.");
00227
00228 try
00229 {
00230
00231 smpMedia = pComponent->ActualizeMediaByFunction(pSessionInfo,smpLink->GetSourceIDPath(),smpFunctLink->GetSourceIDPath());
00232 }
00233 catchAllNPassMacro("Error while actualizing the media.");
00234 }
00235
00236 if (bKeep) DirectSessionComponentAccessor::SetRepositoryElement(mediaID,smpMedia,pComponentCache);
00237 this->ActualizeMediaValidityTag(mediaID,pComponentCache);
00238 }
00239 else
00240 {
00241 smpMedia = DirectSessionComponentAccessor::GetRepositoryElement(mediaID,pComponentCache);
00242 }
00243 return smpMedia;
00244 }
00245 }
00246
00247 return Superclass::GetMediaCasted(mediaID, pComponent, pComponentCache, pSessionInfo);
00248 };
00249
00250 void
00251 MediaActualizerController::
00252 SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia,
00253 ComponentType* pComponent, SessionComponentCache* pComponentCache,
00254 SessionInfo* pSessionInfo) const
00255 {
00256 if (mediaID == MediaID_deformationField)
00257 {
00258
00259 }
00260 else if (mediaID == MediaID_transformFunction)
00261 {
00262
00263 }
00264 else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00265 };
00266
00267
00268 }