r575: 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.5 2001/02/23 03:28:26 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 BackgroundTask event handler object
37 // The thread is detached and terminates when BackgroundTask terminates
38 class BackgroundTaskThread : public wxThread {
39 private:
40
41 public:
42   BackgroundTaskThread();
43
44   virtual wxThread::ExitCode Entry();
45
46   // called when the thread exits - whether it terminates normally or is stopped with Delete()
47   virtual void OnExit();
48 };
49
50
51 // Pure virtual class for BackgroundTasks that can communication
52 // with BackgroundManager
53
54 class BackgroundTask : public wxEvtHandler {
55 private:
56   bool m_bDone;
57
58 public:
59   BackgroundTask()
60     : m_bDone(false), wxEvtHandler()
61   {}
62
63   virtual ~BackgroundTask()
64   {}
65
66   virtual void cancel() = 0;
67   virtual bool start() = 0;
68   virtual bool testDone() = 0;
69
70   bool isDone() const {return m_bDone;}
71   void setDone() { m_bDone = true; }
72 };
73
74 class Reconstructor;
75 class ImageFile;
76 class ProjectionFileDocument;
77 class ReconstructionThread;
78 class ProjectionFileView;
79
80
81 class ThreadedReconstructor : public BackgroundTask {
82 private:
83   DECLARE_DYNAMIC_CLASS(ThreadedReconstructor)
84
85   std::vector<ImageFile*> m_vecpChildImageFile;
86   std::vector<ReconstructionThread*> m_vecpThread;
87   ProjectionFileView* m_pProjView;
88   wxProgressDialog* m_pDialogProgress;
89   wxGauge* m_pGauge;
90   
91   volatile bool m_bFail;
92   int m_iNumThreads;
93   const int m_iImageNX;
94   const int m_iImageNY;
95   volatile int m_iRunning;
96   volatile unsigned int m_iViewsDone;
97   volatile unsigned int m_iTotalViews;
98   //wxCriticalSection m_criticalSection;
99   wxString m_strLabel;
100   Timer* m_pTimer;
101   bool m_bCancelled;
102   bool m_bCancelling;
103
104 public:
105    ThreadedReconstructor (ProjectionFileView* pProjView, 
106    int iNX, int iNY, const char* pszFilterName, double dFilterParam, const char* pszFilterMethod, 
107    int iZeropad, const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam,
108    const char* pszBackprojectName, const char* const pszLabel);
109
110    ThreadedReconstructor ()
111      : m_bFail(true), m_iNumThreads(0), m_iImageNX(0), m_iImageNY(0), m_iTotalViews(0), BackgroundTask()
112    {}
113
114    ~ThreadedReconstructor ();
115
116   void OnThreadEvent (wxCommandEvent& event);
117   void cancel();
118
119   void onDone();
120   bool start();
121   bool fail() const {return m_bFail;}
122   bool testDone();
123   void cleanUp();
124
125   ImageFile* getImageFile();
126
127   DECLARE_EVENT_TABLE()
128 };
129
130
131
132 class ReconstructionThread : public wxThread {
133 private:
134   ThreadedReconstructor* m_pSupervisor;
135   Reconstructor* m_pReconstructor;
136   int m_iStartView;
137   int m_iNumViews;
138   int m_iThread;
139
140 public:
141   ReconstructionThread (ThreadedReconstructor* pSupervisor, 
142     ProjectionFileView* pProjFile, ImageFile* pImageFile, 
143     int iThread, int iStartView, int iNumViews,
144    const char* pszFilterName, double dFilterParam, const char* pszFilterMethod, 
145    int iZeropad, const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam,
146    const char* pszBackprojectName);
147
148   virtual wxThread::ExitCode Entry();      // thread execution starts here
149
150   // called when the thread exits - whether it terminates normally or is stopped with Delete()
151   virtual void OnExit();
152 };
153
154
155 #endif
156