X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fthreadrecon.h;h=9c1e5e26783b274ca43eabfe13cf579049555c41;hp=0daa6219587c2571de2cd729d15b134ff4d732c1;hb=1ef49f39828474ed05fe69aff68d400e3b7d4044;hpb=b0df0a0f3008d0fee67f388cfa1c37af6383b38f diff --git a/src/threadrecon.h b/src/threadrecon.h index 0daa621..9c1e5e2 100644 --- a/src/threadrecon.h +++ b/src/threadrecon.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2001 Kevin Rosenberg ** -** $Id: threadrecon.h,v 1.5 2001/02/23 03:28:26 kevin Exp $ +** $Id: threadrecon.h,v 1.6 2001/02/23 18:56:56 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -33,39 +33,60 @@ #include #include "timer.h" -// This thread creates a BackgroundTask event handler object -// The thread is detached and terminates when BackgroundTask terminates -class BackgroundTaskThread : public wxThread { +// This thread creates a SupervisorTask event handler object +// The thread is detached and terminates when SupervisorTask terminates +class SupervisorTaskThread : public wxThread { private: public: - BackgroundTaskThread(); + SupervisorTaskThread(); - virtual wxThread::ExitCode Entry(); + virtual wxThread::ExitCode Entry() = 0; // called when the thread exits - whether it terminates normally or is stopped with Delete() virtual void OnExit(); }; -// Pure virtual class for BackgroundTasks that can communication -// with BackgroundManager +class ReconstructorSupervisorThread : public SupervisorTaskThread { +private: +public: +}; -class BackgroundTask : public wxEvtHandler { + +// Pure virtual class for BackgroundSupervisor that can communication +// with BackgroundManager via messages + +class BackgroundSupervisor : public wxEvtHandler { private: bool m_bDone; public: - BackgroundTask() + + enum { + MSG_BACKGROUND_SUPERVISOR_ADD = 7500, // sends to BackgroundManager and Document + MSG_BACKGROUND_SUPERVISOR_REMOVE = 7501, // sends to BackgroundManager and Document + MSG_BACKGROUND_SUPERVISOR_UNIT_TICK = 7502, // sends to BackgroundManager for progress bars + MSG_BACKGROUND_SUPERVISOR_CANCEL = 7503, // *sent* to Supervisor to cancel process + + MSG_WORKER_THREAD_UNIT_TICK = 7504, + MSG_WORKER_THREAD_DONE = 7505, + MSG_WORKER_THREAD_FAIL = 7506, // sent by workers when they fail + }; + + BackgroundSupervisor() : m_bDone(false), wxEvtHandler() {} - virtual ~BackgroundTask() + virtual ~BackgroundSupervisor() {} virtual void cancel() = 0; virtual bool start() = 0; virtual bool testDone() = 0; + virtual void OnWorkerFail(wxCommandEvent& event) = 0; + virtual void OnWorkerUnitTick(wxCommandEvent& event) = 0; + virtual void OnWorkerDone(wxCommandEvent& event) = 0; bool isDone() const {return m_bDone;} void setDone() { m_bDone = true; } @@ -74,20 +95,22 @@ public: class Reconstructor; class ImageFile; class ProjectionFileDocument; -class ReconstructionThread; +class ReconstructorWorker; class ProjectionFileView; -class ThreadedReconstructor : public BackgroundTask { +class ReconstructorSupervisor : public BackgroundSupervisor { private: - DECLARE_DYNAMIC_CLASS(ThreadedReconstructor) + DECLARE_DYNAMIC_CLASS(ReconstructorSupervisor) + wxCriticalSection m_critsectThreadContainer; std::vector m_vecpChildImageFile; - std::vector m_vecpThread; + typedef std::vector ThreadContainer; + ThreadContainer m_vecpThread; ProjectionFileView* m_pProjView; wxProgressDialog* m_pDialogProgress; wxGauge* m_pGauge; - + volatile bool m_bFail; int m_iNumThreads; const int m_iImageNX; @@ -95,23 +118,23 @@ private: volatile int m_iRunning; volatile unsigned int m_iViewsDone; volatile unsigned int m_iTotalViews; - //wxCriticalSection m_criticalSection; wxString m_strLabel; Timer* m_pTimer; bool m_bCancelled; bool m_bCancelling; public: - ThreadedReconstructor (ProjectionFileView* pProjView, + ReconstructorSupervisor (ProjectionFileView* pProjView, int iNX, int iNY, const char* pszFilterName, double dFilterParam, const char* pszFilterMethod, int iZeropad, const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam, const char* pszBackprojectName, const char* const pszLabel); - ThreadedReconstructor () - : m_bFail(true), m_iNumThreads(0), m_iImageNX(0), m_iImageNY(0), m_iTotalViews(0), BackgroundTask() + ReconstructorSupervisor () + : m_bFail(true), m_iNumThreads(0), m_iImageNX(0), m_iImageNY(0), m_iTotalViews(0), + BackgroundSupervisor() {} - ~ThreadedReconstructor (); + ~ReconstructorSupervisor (); void OnThreadEvent (wxCommandEvent& event); void cancel(); @@ -121,6 +144,9 @@ public: bool fail() const {return m_bFail;} bool testDone(); void cleanUp(); + virtual void OnWorkerFail(wxCommandEvent& event); + virtual void OnWorkerUnitTick(wxCommandEvent& event); + virtual void OnWorkerDone(wxCommandEvent& event); ImageFile* getImageFile(); @@ -129,20 +155,29 @@ public: -class ReconstructionThread : public wxThread { +class ReconstructorWorker : public wxThread { private: - ThreadedReconstructor* m_pSupervisor; - Reconstructor* m_pReconstructor; + ReconstructorSupervisor* m_pSupervisor; int m_iStartView; int m_iNumViews; int m_iThread; + ProjectionFileView* m_pProjView; + ImageFile* m_pImageFile; + const std::string m_strFilterName; + const double m_dFilterParam; + const std::string m_strFilterMethod; + const int m_iZeropad; + const std::string m_strFilterGenerationName; + const std::string m_strInterpName; + const int m_iInterpParam; + const std::string m_strBackprojectName; public: - ReconstructionThread (ThreadedReconstructor* pSupervisor, + ReconstructorWorker (ReconstructorSupervisor* pSupervisor, ProjectionFileView* pProjFile, ImageFile* pImageFile, int iThread, int iStartView, int iNumViews, - const char* pszFilterName, double dFilterParam, const char* pszFilterMethod, - int iZeropad, const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam, + const char* const pszFilterName, double dFilterParam, const char* const pszFilterMethod, + int iZeropad, const char* const pszFilterGenerationName, const char* const pszInterpName, int iInterpParam, const char* pszBackprojectName); virtual wxThread::ExitCode Entry(); // thread execution starts here @@ -153,4 +188,4 @@ public: #endif - \ No newline at end of file +