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