freParameterListMediaController.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2007/04/12 12:00:00 $
00006   Module:    $RCSfile: freParameterListMediaController.txx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 
00023 #include "freParameterListMediaController.h"
00024 #include "freExceptions.h"
00025 
00026 namespace FREE
00027 {
00028 
00032   DefineParameterMacro(ParameterListMediaController,ReadMode,"ReadMode","Indicates if this component should be used in read (true) or write mode (false).");
00033   DefineParameterMacro(ParameterListMediaController,ParameterLink,"ParameterLink","Link specifing a parameter in the setup that should be read or written.");
00034 
00035   ParameterListMediaController::
00036     ParameterListMediaController()
00037   {
00038     //Profile settings
00039     this->UpdateControllerID(ControllerID::ParameterListMediaController);
00040     this->m_Description = "Controller for a parameter list.";
00041   };
00042 
00043   ParameterListMediaController::
00044     ~ParameterListMediaController()
00045   {}
00046   ;
00047 
00048   ParameterListMediaController::GenericMediaPointer
00049     ParameterListMediaController::
00050     ComputeActualizedMedia(GenericMediaType* pGenericMedia,
00051     GenericMediaType* pGenericTransformationField) const
00052   {
00053     //parameter list has nothing to actualize
00054     return GenericMediaPointer(pGenericMedia);
00055   };
00056 
00057   ParameterListMediaController::GenericMediaPointer
00058     ParameterListMediaController::
00059     ComputeActualizedMediaByFunction(GenericMediaType* pGenericMedia,
00060     GenericMediaType* pGenericTransformationFunction) const
00061   {
00062     //parameter list has nothing to actualize
00063     return GenericMediaPointer(pGenericMedia);
00064   };
00065 
00066   bool
00067     ParameterListMediaController::
00068     SaveMedia(std::string sMediaPath, GenericMediaType* pMedia) const
00069   {
00070     //parameter list cannot save directly allways need a session
00071 
00072     return false;
00073   };
00074 
00075   bool
00076     ParameterListMediaController::
00077     SaveMedia(SessionComponentCache* pCache) const
00078   {
00079     if (!pCache) throwCtrlExceptionMacro("", "Cannot save media. Passed session cache is NULL.");
00080     if (!pCache->SetupIsAssigned())
00081       throwCtrlExceptionMacro("","Error. Setup is missing in cache.");
00082     if (!pCache->ComponentIsAssigned())
00083       throwCtrlExceptionMacro("","Error. Component is missing in cache.");
00084 
00085     ComponentPointer smpIO = dynamic_cast<ComponentType*>(pCache->Component().GetPointer());
00086 
00087     std::string sMediaFile;
00088     if (!pCache->Setup()->Parameters().GetParameterValue(cParam_MediaFile,sMediaFile))
00089       throwCtrlExceptionMacro("", "Missing parameter" << cParam_MediaFile);
00090 
00091     for (ParameterCollection::ParameterCountType index=0; index<pCache->Setup()->Parameters().Size(); index++)
00092     { //search for all paramter link specifications
00093       Parameter* pParam = pCache->Setup()->Parameters().GetParameter(index);
00094       if ((pParam->GetParameterName()!=cParam_MediaFile) &&
00095         (pParam->GetParameterName()!=cParam_ReadMode))
00096       { //assume that it is a parameter link and add it
00097         std::string sLink = "";
00098         pParam->GetParameterValue(sLink);
00099         smpIO->AddParameterLink(pParam->GetParameterName(),sLink);
00100       }
00101     }
00102 
00103     smpIO->SetComponentCache(pCache);
00104     smpIO->SaveListToFile(sMediaFile);
00105 
00106     return true; //point set is saved to setup
00107   };
00108 
00109   bool
00110     ParameterListMediaController::
00111     LoadMedia(SessionComponentCache* pCache) const
00112   {
00113     if (!pCache) throwCtrlExceptionMacro("", "Cannot load media. Passed session cache is NULL.");
00114     if (!pCache->SetupIsAssigned())
00115       throwCtrlExceptionMacro("","Error. Setup is missing in cache.");
00116     if (!pCache->ComponentIsAssigned())
00117       throwCtrlExceptionMacro("","Error. Component is missing in cache.");
00118 
00119     ComponentPointer smpIO = dynamic_cast<ComponentType*>(pCache->Component().GetPointer());
00120 
00121     std::string sMediaFile;
00122     if (!pCache->Setup()->Parameters().GetParameterValue(cParam_MediaFile,sMediaFile))
00123       throwCtrlExceptionMacro("", "Missing parameter" << cParam_MediaFile);
00124 
00125     for (ParameterCollection::ParameterCountType index=0; index<pCache->Setup()->Parameters().Size(); index++)
00126     { //search for all paramter link specifications
00127       Parameter* pParam = pCache->Setup()->Parameters().GetParameter(index);
00128       if ((pParam->GetParameterName()!=cParam_MediaFile) &&
00129         (pParam->GetParameterName()!=cParam_ReadMode))
00130       { //assume that it is a parameter link and add it
00131         std::string sLink = "";
00132         pParam->GetParameterValue(sLink);
00133         smpIO->AddParameterLink(pParam->GetParameterName(),sLink);
00134       }
00135     }
00136 
00137     smpIO->SetComponentCache(pCache);
00138     smpIO->LoadListFromFile(sMediaFile);
00139 
00140     this->NotifyProgress(1,"Loading finished",pCache);
00141 
00142     return true;
00143   };
00144 
00145   unsigned long
00146     ParameterListMediaController::
00147     GetMediaDimension() const
00148   {
00149     return 0;
00150   };
00151 
00152   void
00153     ParameterListMediaController::
00154     GenerateProfile(CtrlProfile::ControllerProfile& profile,
00155     const SessionComponentCache* pComponentCache,
00156     bool bRegardOldSetup) const
00157   {
00158     Superclass::GenerateProfile(profile, pComponentCache, bRegardOldSetup);
00159 
00160     //Parameters
00161     profile.Parameters().AddParameter(cParam_ReadMode,Parameter::PVTBool,cParamDsc_ReadMode,1,"false");
00162     //TODO eigentlich als Template nötig
00163     profile.Parameters().AddParameter(cParam_ParameterLink,Parameter::PVTIDPath,cParamDsc_ParameterLink,1,"");
00164   };
00165 
00166   ParameterListMediaController::
00167     ComponentPointer
00168     ParameterListMediaController::
00169     BuildMainComponent(ComponentSetup* pComponentSetup, SessionComponentCache* pComponentCache) const
00170   {
00171     ComponentPointer smpComp = Superclass::BuildMainComponent(pComponentSetup, pComponentCache);
00172 
00173     bool bRead;
00174     if (!pComponentCache->Setup()->Parameters().GetParameterValue(cParam_ReadMode,bRead))
00175       throwCtrlExceptionMacro("", "Missing parameter" << cParam_ReadMode);
00176 
00177     if (bRead)
00178     {
00179       if (!LoadMedia(pComponentCache)) throwCtrlExceptionMacro("", "Unable to parameter list.");
00180     }
00181 
00182     return smpComp;
00183   };
00184 
00185 ValidityTag::Pointer
00186 ParameterListMediaController::
00187 GetMediaValidityTagRequirement(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00188 {
00189   if (mediaID == "media")
00190   {
00191     ValidityTag::Pointer tag = ValidityTag::New();
00192     tag->Actualize();
00193     return tag;
00194   }
00195 
00196   return Superclass::GetMediaValidityTagRequirement(mediaID, pComponentCache);
00197 };
00198 
00199 } //end of namespace free

Generated at Sat Oct 13 16:57:19 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000