1 /*****************************************************************************
5 ** Purpose: Header file for thread reconstructions
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: February 2001
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2001 Kevin Rosenberg
12 ** $Id: threadrecon.h,v 1.7 2001/02/23 21:58:32 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 #ifndef _THREADRECON_H
29 #define _THREADRECON_H
32 #include <wx/thread.h>
33 #include <wx/progdlg.h>
36 // This thread creates a SupervisorTask event handler object
37 // The thread is detached and terminates when SupervisorTask terminates
38 class SupervisorTaskThread : public wxThread {
42 SupervisorTaskThread();
44 virtual wxThread::ExitCode Entry() = 0;
46 // called when the thread exits - whether it terminates normally or is stopped with Delete()
47 virtual void OnExit();
51 class ReconstructorSupervisorThread : public SupervisorTaskThread {
57 // Pure virtual class for BackgroundSupervisor that can communication
58 // with BackgroundManager via messages
60 class BackgroundSupervisor : public wxEvtHandler {
67 MSG_BACKGROUND_SUPERVISOR_ADD = 7500, // sends to BackgroundManager and Document
68 MSG_BACKGROUND_SUPERVISOR_REMOVE = 7501, // sends to BackgroundManager and Document
69 MSG_BACKGROUND_SUPERVISOR_UNIT_TICK = 7502, // sends to BackgroundManager for progress bars
70 MSG_BACKGROUND_SUPERVISOR_CANCEL = 7503, // *sent* to Supervisor to cancel process
72 MSG_WORKER_THREAD_UNIT_TICK = 7504,
73 MSG_WORKER_THREAD_DONE = 7505,
74 MSG_WORKER_THREAD_FAIL = 7506, // sent by workers when they fail
77 BackgroundSupervisor()
78 : m_bDone(false), wxEvtHandler()
81 virtual ~BackgroundSupervisor()
84 virtual bool start() = 0;
85 virtual bool testDone() = 0;
86 virtual void OnWorkerFail(wxCommandEvent& event) = 0;
87 virtual void OnWorkerUnitTick(wxCommandEvent& event) = 0;
88 virtual void OnWorkerDone(wxCommandEvent& event) = 0;
89 virtual void OnCancel(wxCommandEvent& event) = 0;
91 bool isDone() const {return m_bDone;}
92 void setDone() { m_bDone = true; }
94 static void cancelSupervisor (BackgroundSupervisor* pSupervisor);
99 class ProjectionFileDocument;
100 class ReconstructorWorker;
101 class ProjectionFileView;
104 class ReconstructorSupervisor : public BackgroundSupervisor {
106 DECLARE_DYNAMIC_CLASS(ReconstructorSupervisor)
107 wxCriticalSection m_critsectThreadContainer;
109 std::vector<ImageFile*> m_vecpChildImageFile;
110 typedef std::vector<ReconstructorWorker*> ThreadContainer;
111 ThreadContainer m_vecpThread;
112 ProjectionFileDocument* m_pProjDoc;
113 ProjectionFileView* m_pProjView;
114 wxProgressDialog* m_pDialogProgress;
116 volatile bool m_bFail;
118 const int m_iImageNX;
119 const int m_iImageNY;
120 volatile int m_iRunning;
121 volatile unsigned int m_iViewsDone;
122 volatile unsigned int m_iTotalViews;
129 ReconstructorSupervisor (ProjectionFileView* pProjView,
130 int iNX, int iNY, const char* pszFilterName, double dFilterParam, const char* pszFilterMethod,
131 int iZeropad, const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam,
132 const char* pszBackprojectName, const char* const pszLabel);
134 ReconstructorSupervisor ()
135 : m_bFail(true), m_iNumThreads(0), m_iImageNX(0), m_iImageNY(0), m_iTotalViews(0),
136 BackgroundSupervisor()
139 ~ReconstructorSupervisor ();
143 bool fail() const {return m_bFail;}
146 virtual void OnWorkerFail(wxCommandEvent& event);
147 virtual void OnWorkerUnitTick(wxCommandEvent& event);
148 virtual void OnWorkerDone(wxCommandEvent& event);
149 virtual void OnCancel(wxCommandEvent& event);
151 ImageFile* getImageFile();
153 DECLARE_EVENT_TABLE()
158 class ReconstructorWorker : public wxThread {
160 ReconstructorSupervisor* m_pSupervisor;
164 ProjectionFileView* m_pProjView;
165 ImageFile* m_pImageFile;
166 const std::string m_strFilterName;
167 const double m_dFilterParam;
168 const std::string m_strFilterMethod;
169 const int m_iZeropad;
170 const std::string m_strFilterGenerationName;
171 const std::string m_strInterpName;
172 const int m_iInterpParam;
173 const std::string m_strBackprojectName;
176 ReconstructorWorker (ReconstructorSupervisor* pSupervisor,
177 ProjectionFileView* pProjFile, ImageFile* pImageFile,
178 int iThread, int iStartView, int iNumViews,
179 const char* const pszFilterName, double dFilterParam, const char* const pszFilterMethod,
180 int iZeropad, const char* const pszFilterGenerationName, const char* const pszInterpName, int iInterpParam,
181 const char* pszBackprojectName);
183 virtual wxThread::ExitCode Entry(); // thread execution starts here
185 // called when the thread exits - whether it terminates normally or is stopped with Delete()
186 virtual void OnExit();