e3418dfe192d783c165d4db6be4b8ec2c20a8939
[ctsim.git] / include / backprojectors.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **      Name:         backproject.h
5 **      Purpose:      Backprojection classes
6 **      Programmer:   Kevin Rosenberg
7 **      Date Started: June 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: backprojectors.h,v 1.16 2000/12/03 15:16:17 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
29 #ifndef __BACKPROJECTORS_H
30 #define __BACKPROJECTORS_H
31
32 #undef HAVE_BSPLINE_INTERP
33
34 #include "imagefile.h"
35
36
37 class Backproject;
38 class ImageFile;
39 class Projections;
40
41 class Backprojector
42 {
43  public:
44   static const int BPROJ_INVALID;
45   static const int BPROJ_TRIG;
46   static const int BPROJ_TABLE;
47   static const int BPROJ_DIFF;
48   static const int BPROJ_DIFF2;
49   static const int BPROJ_IDIFF2;
50   static const int BPROJ_IDIFF3;
51
52   static const int INTERP_INVALID;
53   static const int INTERP_NEAREST;
54   static const int INTERP_LINEAR;
55   static const int INTERP_FREQ_PREINTERPOLATION;
56 #if HAVE_BSPLINE_INTERP
57   static const int INTERP_BSPLINE;
58   static const int INTERP_1BSPLINE;
59   static const int INTERP_2BSPLINE;
60   static const int INTERP_3BSPLINE;
61 #endif
62
63   Backprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor);
64
65   ~Backprojector ();
66                  
67   void BackprojectView (const double* const viewData, const double viewAngle);
68
69   bool fail() const {return m_fail;}
70   const string& failMessage() const {return m_failMessage;}
71
72   static const int getBackprojectCount() {return s_iBackprojectCount;}
73   static const char** getBackprojectNameArray() {return s_aszBackprojectName;}
74   static const char** getBackprojectTitleArray() {return s_aszBackprojectTitle;}
75   static int convertBackprojectNameToID (const char* const bprojName);
76   static const char* convertBackprojectIDToName (const int bprojID);
77   static const char* convertBackprojectIDToTitle (const int bprojID);
78
79   static const int getInterpCount() {return s_iInterpCount;}
80   static const char** getInterpNameArray() {return s_aszInterpName;}
81   static const char** getInterpTitleArray() {return s_aszInterpTitle;}
82   static int convertInterpNameToID (const char* const interpName);
83   static const char* convertInterpIDToName (const int interpID);
84   static const char* convertInterpIDToTitle (const int interpID);
85
86
87  private:
88   string m_nameBackproject;
89   string m_nameInterpolation;
90   int m_idBackproject;
91   int m_idInterpolation;
92   Backproject* m_pBackprojectImplem;
93   bool m_fail;
94   string m_failMessage;
95
96   static const char* s_aszBackprojectName[];
97   static const char* s_aszBackprojectTitle[];
98   static const int s_iBackprojectCount;
99
100   static const char* s_aszInterpName[];
101   static const char* s_aszInterpTitle[];
102   static const int s_iInterpCount;
103
104   bool initBackprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor);
105 };
106
107
108 class Backproject
109 {
110  public:
111     Backproject (const Projections& proj, ImageFile& im, int interpID, const int interpFactor);
112
113     virtual ~Backproject ();
114
115     virtual void BackprojectView (const double* const viewData, const double viewAngle) {};
116
117  protected:
118     void ScaleImageByRotIncrement ();
119     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double r, double phi, double L, int ni);
120     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double L, int ni);
121
122     const Projections& proj;
123     ImageFile& im;
124     int interpType;
125     ImageFileArray v;
126     kint32 nx;
127     kint32 ny;
128     double detInc;
129     double rotScale;
130     int iDetCenter;             // index refering to L=0 projection 
131     int nDet;
132     double xMin, xMax, yMin, yMax;     // Retangular coords of phantom
133     double xInc, yInc;  // size of cells
134     int m_interpFactor;
135     double m_dFocalLength;
136
137  private:
138     Backproject (const Backproject& rhs);
139     Backproject& operator= (const Backproject& rhs);
140 };
141
142
143 class BackprojectTrig : public Backproject
144 {
145  public:
146   BackprojectTrig (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
147       : Backproject::Backproject (proj, im, interpID, interpFactor)
148       {}
149
150   void BackprojectView (const double* const t, double view_angle);
151 };
152
153
154 class BackprojectTable : public Backproject
155 {
156  public:
157   BackprojectTable (const Projections& proj, ImageFile& im, int interpID, const int interpFactor);
158   virtual ~BackprojectTable ();
159
160   void BackprojectView (const double* const t, double view_angle);
161
162  protected:
163   Array2d<kfloat64> arrayR;
164   Array2d<kfloat64> arrayPhi;
165   kfloat64** r;
166   kfloat64** phi;
167 };
168
169
170 class BackprojectDiff : public Backproject
171 {
172  public:
173   BackprojectDiff (const Projections& proj, ImageFile& im, int interpID, const int interpFactor);
174   ~BackprojectDiff ();
175
176   void BackprojectView (const double* const t, double view_angle);
177
178  protected:
179   double start_r;
180   double start_phi;
181   double im_xinc, im_yinc;
182 };
183
184 class BackprojectDiff2 : public BackprojectDiff
185 {
186  public:
187   BackprojectDiff2 (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
188     :  BackprojectDiff::BackprojectDiff (proj, im, interpID, interpFactor)
189     {}
190
191   void BackprojectView (const double* const t, double view_angle);
192 };
193
194 class BackprojectIntDiff2 : public BackprojectDiff
195 {
196  public:
197   BackprojectIntDiff2 (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
198     :  BackprojectDiff::BackprojectDiff (proj, im, interpID, interpFactor)
199     {}
200   
201   void BackprojectView (const double* const t, double view_angle);
202 };
203
204
205 class BackprojectIntDiff3 : public BackprojectDiff
206 {
207  public:
208   BackprojectIntDiff3 (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
209     :  BackprojectDiff::BackprojectDiff (proj, im, interpID, interpFactor)
210     {}
211   
212   void BackprojectView (const double* const t, double view_angle);
213 };
214
215 class BackprojectEquilinear : public BackprojectTable
216 {
217  public:
218   BackprojectEquilinear (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
219       : BackprojectTable::BackprojectTable (proj, im, interpID, interpFactor)
220       {}
221
222   void BackprojectView (const double* const t, double view_angle);
223
224   virtual ~BackprojectEquilinear()
225       {}
226 };
227
228 class BackprojectEquiangular : public BackprojectTable
229 {
230  public:
231   BackprojectEquiangular (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
232       : BackprojectTable::BackprojectTable (proj, im, interpID, interpFactor)
233       {}
234
235   void BackprojectView (const double* const t, double view_angle);
236
237   virtual ~BackprojectEquiangular()
238       {}
239 };
240
241
242 #endif