X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fthreadrecon.h;h=e96bb2d8f85c76d4adea9ebb2295ec594c138e11;hb=6480e936da257519dd36840862ac995ca8c374da;hp=0cb8c9a3c584c7070f82d64d84d84049912d71db;hpb=e081109a4a541c8780aaa253b874acada5957200;p=ctsim.git diff --git a/src/threadrecon.h b/src/threadrecon.h index 0cb8c9a..e96bb2d 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.2 2001/02/22 15:00:20 kevin Exp $ +** $Id: threadrecon.h,v 1.7 2001/02/23 21:58:32 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,37 +33,86 @@ #include #include "timer.h" +// This thread creates a SupervisorTask event handler object +// The thread is detached and terminates when SupervisorTask terminates +class SupervisorTaskThread : public wxThread { +private: + +public: + SupervisorTaskThread(); + + virtual wxThread::ExitCode Entry() = 0; -class BackgroundTask : public wxEvtHandler { + // called when the thread exits - whether it terminates normally or is stopped with Delete() + virtual void OnExit(); +}; + + +class ReconstructorSupervisorThread : public SupervisorTaskThread { +private: public: - BackgroundTask() - : wxEvtHandler() +}; + + +// Pure virtual class for BackgroundSupervisor that can communication +// with BackgroundManager via messages + +class BackgroundSupervisor : public wxEvtHandler { +private: + bool m_bDone; + +public: + + 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; + virtual void OnCancel(wxCommandEvent& event) = 0; + + bool isDone() const {return m_bDone;} + void setDone() { m_bDone = true; } + + static void cancelSupervisor (BackgroundSupervisor* pSupervisor); }; 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_vecpReconstructor; std::vector m_vecpChildImageFile; - std::vector m_vecpThread; + typedef std::vector ThreadContainer; + ThreadContainer m_vecpThread; + ProjectionFileDocument* m_pProjDoc; ProjectionFileView* m_pProjView; wxProgressDialog* m_pDialogProgress; - wxGauge* m_pGauge; - + volatile bool m_bFail; int m_iNumThreads; const int m_iImageNX; @@ -71,59 +120,72 @@ 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; - bool m_bDone; 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 (); - - void OnThreadEvent (wxCommandEvent& event); - bool testDone(); - void cancel(); + ~ReconstructorSupervisor (); void onDone(); bool start(); bool fail() const {return m_bFail;} - bool getDone() const {return m_bDone;} + bool testDone(); + void cleanUp(); + virtual void OnWorkerFail(wxCommandEvent& event); + virtual void OnWorkerUnitTick(wxCommandEvent& event); + virtual void OnWorkerDone(wxCommandEvent& event); + virtual void OnCancel(wxCommandEvent& event); - ImageFile* getImageFile() const; + ImageFile* getImageFile(); DECLARE_EVENT_TABLE() }; -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, Reconstructor* pReconstructor, - int iThread, int iStartView, int iNumViews); + ReconstructorWorker (ReconstructorSupervisor* pSupervisor, + ProjectionFileView* pProjFile, ImageFile* pImageFile, + int iThread, int iStartView, int iNumViews, + 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 - // called when the thread exits - whether it terminates normally or is - // stopped with Delete() (but not when it is Kill()ed!) - virtual void OnExit(); + // called when the thread exits - whether it terminates normally or is stopped with Delete() + virtual void OnExit(); }; #endif +