freSetupOptimizationMetricMonitorBase.h

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: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freSetupOptimizationMetricMonitorBase.h,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 #ifndef __freSetupOptimizationMetricMonitorBase_h
00023 #define __freSetupOptimizationMetricMonitorBase_h
00024 
00025 #include "freExceptions.h"
00026 #include "freStatistics.h"
00027 #include "freGenericSetupToImageAdaptor.h"
00028 #include "freControllerEvents.h"
00029 
00030 #include "itkObject.h"
00031 #include "itkMutexLock.h"
00032 
00033 namespace FREE
00034 {
00035 
00045 class SetupOptimizationMetricResult
00046 {
00047 public:
00048   virtual void Reset() = 0;
00049   SetupOptimizationMetricResult() {};
00050 };
00051 
00065 template <typename TResultClass>
00066 class ITK_EXPORT SetupOptimizationMetricMonitorBase : 
00067   public itk::Object
00068 {
00069 public:
00071   typedef SetupOptimizationMetricMonitorBase<TResultClass>   Self;
00072   typedef itk::Object                       Superclass;
00073         typedef itk::SmartPointer<Self>           Pointer;
00074   typedef itk::SmartPointer<const Self>     ConstPointer;
00075 
00078   typedef TResultClass   ResultType;
00079 
00080   typedef unsigned long ThreadIDType;
00081   typedef long AdaptationIDType;
00082   typedef long AdaptationCountType;
00083   typedef long ResultIndexType;
00084 
00085   typedef std::vector<AdaptationIDType> AdaptationIDListType;
00086 
00087   enum AdaptationStateType
00088   {
00089     ASPending = 0,       //*< Adaptation is pending in waiting for being processed
00090     ASProcessing = 1,    //*< Adaptation is right now in the state of being evaluated.
00091     ASFailed = 2,        //*< Adaptation has been processed and evaluation failed.
00092     ASEvaluated = 3,     //*< Adaptation has been processed and successfully evaluated.
00093   };
00094 
00096   itkTypeMacro( SetupOptimizationMetricMonitorBase, itk::Object );
00097 
00115   bool GetUnevaluatedAdaptedSetup(const ThreadIDType& threadID, AdaptationIDType& adaptID, Setup::Pointer& smpSetup);
00116 
00122   void NotifyFailedEvaluation(const ThreadIDType& threadID,const std::string& sError);
00123 
00129   void NotifyProgress(const ThreadIDType& threadID, const ProgressCtrlEventBase::StatusID status, const std::string& sComment);
00130 
00135   void EvaluationFinished(const ThreadIDType& threadID, const ResultType& results);
00136 
00141   void SetMetricStatistic(Statistics* pStatistic);
00147   Statistics* GetMetricStatistic();
00149   void ReleaseMetricStatistic();
00150 
00152   void SetGenericSetup(Setup* pSetup);
00154   void SetAdaptationList(Adaptation::AdaptationList* pAdaptations);
00155 
00163   bool GetAdaptationResults(const AdaptationIDType& adaptID, ResultType& results) const;
00164   
00166   AdaptationIDListType GetListOfPendingAdaptations() const;
00168   AdaptationIDListType GetListOfProcessedAdaptations() const;
00170   AdaptationIDListType GetListOfFailedAdaptations() const;
00172   AdaptationIDListType GetListOfEvaluatedAdaptations() const;
00174   AdaptationIDListType GetListOfAdaptationsByState(const AdaptationStateType& state) const;
00175 
00178   AdaptationStateType GetAdaptationState(const AdaptationIDType& adaptID) const;
00179 
00182   bool EvaluationIsFinished() const;
00183 
00185   bool IsInitialized() const;
00186 
00189   void Initialize();
00190 
00192   AdaptationCountType GetFailureCount() const;
00193 
00194   /*Pass through for events of the metric using the monitor*/
00195   ProgressEventBase::Pointer fnOnEvaluationProgress;
00196   ProgressEventBase::Pointer fnOnEvaluationDone;
00197   ProgressEventBase::Pointer fnOnNextAdaptation;
00198   ProgressEventBase::Pointer fnOnEvaluationFailed;
00199 
00200 protected:
00201 
00202   SetupOptimizationMetricMonitorBase();
00203 
00204   virtual ~SetupOptimizationMetricMonitorBase();
00205 
00211   virtual void InsertEvaluationResults(const ResultType& results) = 0;
00212 
00221   virtual void CopyAdaptationResults(const ResultIndexType& index, ResultType& results) const = 0;
00222 
00232   virtual void EnlistResultsToStatistic(const ResultType& results, StatisticEntry& entry) = 0;
00233 
00240   virtual void EnlistDictionaryEntries(StatisticDictionary& dictionary) = 0;
00241 
00245   bool GetAdaptionProcessedByThread(const ThreadIDType& threadID, AdaptationIDType& adaptationID) const;
00246 
00247   bool ThreadIsProcessing(const ThreadIDType& threadID) const;
00248 
00252   void EnlistThreadAsProcessing(const ThreadIDType& threadID,const AdaptationIDType& adaptationID);
00253 
00255   void RemoveThreadFromProcessingList(const ThreadIDType& threadID);
00256 
00258   ResultIndexType GetResultIndexOfAdaptation(const AdaptationIDType& adaptationID) const;
00259 
00262   void SetAdaptationState(const AdaptationIDType& adaptID, const AdaptationStateType& state);
00263 
00264 private:
00265 
00268   typedef std::vector<AdaptationStateType> AdaptationStateListType;
00269   AdaptationStateListType m_AdaptStates;
00270   mutable itk::SimpleMutexLock m_AdaptStatesMutex;
00271 
00274   AdaptationIDListType m_AdaptOrder;
00275   mutable itk::SimpleMutexLock m_AdaptOrderMutex;
00276 
00279   typedef std::map<ThreadIDType,AdaptationIDType> ThreadMapType;
00280   ThreadMapType m_AdaptThread;
00281   mutable itk::SimpleMutexLock m_AdaptThreadMutex;
00282 
00284   mutable itk::SimpleMutexLock m_ResultMutex;
00285 
00286   Statistics* m_pMetricStatistics;
00288   mutable itk::SimpleMutexLock m_StatisticMutex;
00289 
00290   Setup::Pointer m_smpGenericSetup;
00291   Adaptation::AdaptationList::Pointer m_smpAdaptations;
00292   GenericSetupToImageAdaptor m_Adaptor;
00294   mutable itk::SimpleMutexLock m_SetupMutex;
00295 
00297   mutable itk::SimpleMutexLock m_EventMutex;
00298 
00299   bool m_IsInitialized;
00300 
00301   SetupOptimizationMetricMonitorBase(const Self&); //purposely not implemented
00302   void operator=(const Self&); //purposely not implemented
00303 };
00304 
00305 } // end namespace FREE
00306 
00307 #ifndef ITK_MANUAL_INSTANTIATION
00308 #include "freSetupOptimizationMetricMonitorBase.txx"
00309 #endif
00310 
00311 #endif
00312 
00313 
00314 

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