freSetupOptimizationMetricThreadBase.txx

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: freSetupOptimizationMetricThreadBase.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 #ifndef __freSetupOptimizationMetricThreadBase_txx
00023 #define __freSetupOptimizationMetricThreadBase_txx
00024 
00025 #include "freSetupOptimizationMetricThreadBase.h"
00026 #include "freExceptions.h"
00027 #include "freControllerCentral.h"
00028 
00029 namespace FREE
00030 {
00031 
00032 template <typename TMonitor>
00033 void
00034 SetupOptimizationMetricThreadBase<TMonitor>:: 
00035 SetMonitor(MonitorType* pMonitor)
00036 {
00037   this->LockExecutionMutex();
00038     this->m_pMonitor = pMonitor;
00039   this->UnlockExecutionMutex();
00040 };
00041 
00042 template <typename TMonitor>
00043 typename SetupOptimizationMetricThreadBase<TMonitor>::ThreadIDType
00044 SetupOptimizationMetricThreadBase<TMonitor>:: 
00045 GetThreadID() const
00046 {
00047   return this->m_ThreadID;
00048 };
00049 
00050 template <typename TMonitor>
00051 void
00052 SetupOptimizationMetricThreadBase<TMonitor>:: 
00053 SetThreadID(const ThreadIDType& id)
00054 {
00055   this->LockExecutionMutex();
00056     this->m_ThreadID = id;
00057   this->UnlockExecutionMutex();
00058 };
00059 
00060 template <typename TMonitor>
00061 void
00062 SetupOptimizationMetricThreadBase<TMonitor>:: 
00063 Execute()
00064 {
00065   if (!(this->m_pMonitor)) throwExceptionMacro("Error; Cannot execute thread #"<<this->m_ThreadID<<", no monitor is defined.");
00066 
00067   this->LockExecutionMutex();
00068     //ok no start with the work
00069     Setup::Pointer smpAdaptedSetup;
00070     typename MonitorType::AdaptationIDType adaptID;
00071     
00072     while (this->m_pMonitor->GetUnevaluatedAdaptedSetup(this->m_ThreadID,adaptID,smpAdaptedSetup))
00073     { //there is work to do so go on
00074       //first reset the result
00075       this->m_Results.Reset();
00076       //now process the setup
00077       if (this->ProcessSetup(smpAdaptedSetup))
00078       { //pass results;
00079         this->m_pMonitor->EvaluationFinished(this->m_ThreadID,this->m_Results);
00080       }
00081       else
00082       { //notify failure
00083         this->m_pMonitor->NotifyFailedEvaluation(this->m_ThreadID,this->m_FailureComment);
00084       }
00085     }
00086 
00087     //ok all the work of the thread is done.
00088   this->UnlockExecutionMutex();
00089 };
00090 
00091 template <typename TMonitor>
00092 SetupOptimizationMetricThreadBase<TMonitor>:: 
00093 SetupOptimizationMetricThreadBase()
00094 {
00095   this->m_ThreadID = 0;
00096   this->m_pMonitor = 0;
00097   this->m_FailureComment = "";
00098 
00099   this->m_EvaluatedSessionProgressEvent = ProgressEventType::New(this,&Self::OnSessionProgress);
00100 };
00101 
00102 template <typename TMonitor>
00103 SetupOptimizationMetricThreadBase<TMonitor>:: 
00104 ~SetupOptimizationMetricThreadBase()
00105 {
00106   ControllerCentral::RemoveOnProgressEvent(m_EvaluatedSessionProgressEvent);
00107 };
00108 
00109 template <typename TMonitor>
00110 void
00111 SetupOptimizationMetricThreadBase<TMonitor>:: 
00112 LockExecutionMutex()
00113 {
00114   this->m_ExecutionMutex.Lock();
00115 };
00116 
00117 template <typename TMonitor>
00118 void
00119 SetupOptimizationMetricThreadBase<TMonitor>:: 
00120 UnlockExecutionMutex()
00121 {
00122   this->m_ExecutionMutex.Unlock();
00123 };
00124 
00125 template <typename TMonitor>
00126 void
00127 SetupOptimizationMetricThreadBase<TMonitor>:: 
00128 OnSessionProgress(const IDPath& senderID,
00129                   const ProgressCtrlEventBase::StatusID status,
00130                   const std::string& sComment,
00131                   SessionComponentCache* pSender,
00132                   long threadID)
00133 {
00134   this->m_pMonitor->NotifyProgress(this->m_ThreadID, status, sComment);
00135 }
00136 
00137 } // end namespace FREE
00138 
00139 #endif

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