d9144deb6144504b91d5cb14f8241cc8602c2347
[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-2001 Kevin Rosenberg
11 **
12 **  $Id: backprojectors.h,v 1.20 2001/02/09 01:54: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
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_CUBIC;
56   static const int INTERP_FREQ_PREINTERPOLATION;
57 #if HAVE_BSPLINE_INTERP
58   static const int INTERP_BSPLINE;
59   static const int INTERP_1BSPLINE;
60   static const int INTERP_2BSPLINE;
61   static const int INTERP_3BSPLINE;
62 #endif
63
64   Backprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor);
65
66   ~Backprojector ();
67                  
68   void BackprojectView (const double* const viewData, const double viewAngle);
69
70   bool fail() const {return m_fail;}
71   const std::string& failMessage() const {return m_failMessage;}
72
73   static const int getBackprojectCount() {return s_iBackprojectCount;}
74   static const char** getBackprojectNameArray() {return s_aszBackprojectName;}
75   static const char** getBackprojectTitleArray() {return s_aszBackprojectTitle;}
76   static int convertBackprojectNameToID (const char* const bprojName);
77   static const char* convertBackprojectIDToName (const int bprojID);
78   static const char* convertBackprojectIDToTitle (const int bprojID);
79
80   static const int getInterpCount() {return s_iInterpCount;}
81   static const char** getInterpNameArray() {return s_aszInterpName;}
82   static const char** getInterpTitleArray() {return s_aszInterpTitle;}
83   static int convertInterpNameToID (const char* const interpName);
84   static const char* convertInterpIDToName (const int interpID);
85   static const char* convertInterpIDToTitle (const int interpID);
86
87
88  private:
89   std::string m_nameBackproject;
90   std::string m_nameInterpolation;
91   int m_idBackproject;
92   int m_idInterpolation;
93   Backproject* m_pBackprojectImplem;
94   bool m_fail;
95   std::string m_failMessage;
96
97   static const char* s_aszBackprojectName[];
98   static const char* s_aszBackprojectTitle[];
99   static const int s_iBackprojectCount;
100
101   static const char* s_aszInterpName[];
102   static const char* s_aszInterpTitle[];
103   static const int s_iInterpCount;
104
105   bool initBackprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor);
106 };
107
108
109 class Backproject
110 {
111  public:
112     Backproject (const Projections& proj, ImageFile& im, int interpID, const int interpFactor);
113
114     virtual ~Backproject ();
115
116     virtual void BackprojectView (const double* const viewData, const double viewAngle) {};
117
118  protected:
119     void ScaleImageByRotIncrement ();
120     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double r, double phi, double L, int ni);
121     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double L, int ni);
122
123     const Projections& proj;
124     ImageFile& im;
125     int interpType;
126     ImageFileArray v;
127     kint32 nx;
128     kint32 ny;
129     double detInc;
130     double rotScale;
131     int iDetCenter;             // index refering to L=0 projection 
132     int nDet;
133     double xMin, xMax, yMin, yMax;     // Retangular coords of phantom
134     double xInc, yInc;  // size of cells
135     int m_interpFactor;
136     double m_dFocalLength;
137
138  private:
139     Backproject (const Backproject& rhs);
140     Backproject& operator= (const Backproject& rhs);
141 };
142
143
144 class BackprojectTrig : public Backproject
145 {
146  public:
147   BackprojectTrig (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
148       : Backproject (proj, im, interpID, interpFactor)
149       {}
150
151   void BackprojectView (const double* const t, const double view_angle);
152 };
153
154
155 class BackprojectTable : public Backproject
156 {
157  public:
158   BackprojectTable (const Projections& proj, ImageFile& im, int interpID, const int interpFactor);
159   virtual ~BackprojectTable ();
160
161   void BackprojectView (const double* const t, const double view_angle);
162
163  protected:
164   Array2d<kfloat64> arrayR;
165   Array2d<kfloat64> arrayPhi;
166   kfloat64** r;
167   kfloat64** phi;
168 };
169
170
171 class BackprojectDiff : public Backproject
172 {
173  public:
174   BackprojectDiff (const Projections& proj, ImageFile& im, int interpID, const int interpFactor);
175   ~BackprojectDiff ();
176
177   void BackprojectView (const double* const t, const double view_angle);
178
179  protected:
180   double start_r;
181   double start_phi;
182   double im_xinc, im_yinc;
183 };
184
185 class BackprojectDiff2 : public BackprojectDiff
186 {
187  public:
188   BackprojectDiff2 (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
189     :  BackprojectDiff (proj, im, interpID, interpFactor)
190     {}
191
192   void BackprojectView (const double* const t, const double view_angle);
193 };
194
195 class BackprojectIntDiff2 : public BackprojectDiff
196 {
197  public:
198   BackprojectIntDiff2 (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
199     :  BackprojectDiff (proj, im, interpID, interpFactor)
200     {}
201   
202   void BackprojectView (const double* const t, const double view_angle);
203 };
204
205
206 class BackprojectIntDiff3 : public BackprojectDiff
207 {
208  public:
209   BackprojectIntDiff3 (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
210     :  BackprojectDiff (proj, im, interpID, interpFactor)
211     {}
212   
213   void BackprojectView (const double* const t, const double view_angle);
214 };
215
216 class BackprojectEquilinear : public BackprojectTable
217 {
218  public:
219   BackprojectEquilinear (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
220       : BackprojectTable (proj, im, interpID, interpFactor)
221       {}
222
223   void BackprojectView (const double* const t, const double view_angle);
224
225   virtual ~BackprojectEquilinear()
226       {}
227 };
228
229 class BackprojectEquiangular : public BackprojectTable
230 {
231  public:
232   BackprojectEquiangular (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
233       : BackprojectTable (proj, im, interpID, interpFactor)
234       {}
235
236   void BackprojectView (const double* const t, const double view_angle);
237
238   virtual ~BackprojectEquiangular()
239       {}
240 };
241
242
243 #endif