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