r576: no message
[ctsim.git] / src / threadrecon.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          threadrecon.h
5 **   Purpose:       Header file for thread reconstructions
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  February 2001
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2001 Kevin Rosenberg
11 **
12 **  $Id: threadrecon.h,v 1.6 2001/02/23 18:56:56 kevin Exp $
13 **
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.
17 **
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.
22 **
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 ******************************************************************************/
27
28 #ifndef _THREADRECON_H
29 #define _THREADRECON_H
30
31 #include <vector>
32 #include <wx/thread.h>
33 #include <wx/progdlg.h>
34 #include "timer.h"
35
36 // This thread creates a SupervisorTask event handler object
37 // The thread is detached and terminates when SupervisorTask terminates
38 class SupervisorTaskThread : public wxThread {
39 private:
40
41 public:
42   SupervisorTaskThread();
43
44   virtual wxThread::ExitCode Entry() = 0;
45
46   // called when the thread exits - whether it terminates normally or is stopped with Delete()
47   virtual void OnExit();
48 };
49
50
51 class ReconstructorSupervisorThread : public SupervisorTaskThread {
52 private:
53 public:
54 };
55
56
57 // Pure virtual class for BackgroundSupervisor that can communication
58 // with BackgroundManager via messages
59
60 class BackgroundSupervisor : public wxEvtHandler {
61 private:
62   bool m_bDone;
63
64 public:
65
66   enum {
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
71
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
75   };
76
77   BackgroundSupervisor()
78     : m_bDone(false), wxEvtHandler()
79   {}
80
81   virtual ~BackgroundSupervisor()
82   {}
83
84   virtual void cancel() = 0;
85   virtual bool start() = 0;
86   virtual bool testDone() = 0;
87   virtual void OnWorkerFail(wxCommandEvent& event) = 0;
88   virtual void OnWorkerUnitTick(wxCommandEvent& event) = 0;
89   virtual void OnWorkerDone(wxCommandEvent& event) = 0;
90
91   bool isDone() const {return m_bDone;}
92   void setDone() { m_bDone = true; }
93 };
94
95 class Reconstructor;
96 class ImageFile;
97 class ProjectionFileDocument;
98 class ReconstructorWorker;
99 class ProjectionFileView;
100
101
102 class ReconstructorSupervisor : public BackgroundSupervisor {
103 private:
104   DECLARE_DYNAMIC_CLASS(ReconstructorSupervisor)
105   wxCriticalSection m_critsectThreadContainer;
106
107   std::vector<ImageFile*> m_vecpChildImageFile;
108   typedef std::vector<ReconstructorWorker*> ThreadContainer;
109   ThreadContainer m_vecpThread;
110   ProjectionFileView* m_pProjView;
111   wxProgressDialog* m_pDialogProgress;
112   wxGauge* m_pGauge;
113     
114   volatile bool m_bFail;
115   int m_iNumThreads;
116   const int m_iImageNX;
117   const int m_iImageNY;
118   volatile int m_iRunning;
119   volatile unsigned int m_iViewsDone;
120   volatile unsigned int m_iTotalViews;
121   wxString m_strLabel;
122   Timer* m_pTimer;
123   bool m_bCancelled;
124   bool m_bCancelling;
125
126 public:
127    ReconstructorSupervisor (ProjectionFileView* pProjView, 
128    int iNX, int iNY, const char* pszFilterName, double dFilterParam, const char* pszFilterMethod, 
129    int iZeropad, const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam,
130    const char* pszBackprojectName, const char* const pszLabel);
131
132    ReconstructorSupervisor ()
133      : m_bFail(true), m_iNumThreads(0), m_iImageNX(0), m_iImageNY(0), m_iTotalViews(0), 
134      BackgroundSupervisor()
135    {}
136
137    ~ReconstructorSupervisor ();
138
139   void OnThreadEvent (wxCommandEvent& event);
140   void cancel();
141
142   void onDone();
143   bool start();
144   bool fail() const {return m_bFail;}
145   bool testDone();
146   void cleanUp();
147   virtual void OnWorkerFail(wxCommandEvent& event);
148   virtual void OnWorkerUnitTick(wxCommandEvent& event);
149   virtual void OnWorkerDone(wxCommandEvent& event);
150
151   ImageFile* getImageFile();
152
153   DECLARE_EVENT_TABLE()
154 };
155
156
157
158 class ReconstructorWorker : public wxThread {
159 private:
160   ReconstructorSupervisor* m_pSupervisor;
161   int m_iStartView;
162   int m_iNumViews;
163   int m_iThread;
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;
174
175 public:
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);
182
183   virtual wxThread::ExitCode Entry();      // thread execution starts here
184
185   // called when the thread exits - whether it terminates normally or is stopped with Delete()
186   virtual void OnExit();
187 };
188
189
190 #endif
191