r156: *** empty log message ***
[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.11 2000/07/20 11:17:31 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
39 class Backprojector
40 {
41  public:
42   typedef  enum {
43     BPROJ_INVALID,
44     BPROJ_TRIG,
45     BPROJ_TABLE,
46     BPROJ_DIFF,
47     BPROJ_DIFF2,
48     BPROJ_IDIFF2,
49     BPROJ_IDIFF3
50 } BackprojectID;
51
52   typedef enum {
53     INTERP_INVALID,
54     INTERP_NEAREST,      // Nearest neighbor
55 #if HAVE_BSPLINE_INTERP
56     I_BSPLINE,
57     I_1BSPLINE,      // 1st order B-Spline 
58     I_2BSPLINE,
59     I_3BSPLINE,
60 #endif
61     INTERP_LINEAR,        // Linear interpolation 
62     INTERP_FREQ_PREINTERPOLATION,
63   } InterpolationID;
64
65   static const char BPROJ_TRIG_STR[];
66   static const char BPROJ_TABLE_STR[];
67   static const char BPROJ_DIFF_STR[];
68   static const char BPROJ_DIFF2_STR[];
69   static const char BPROJ_IDIFF2_STR[];
70   static const char BPROJ_IDIFF3_STR[];
71
72   static const char BPROJ_TRIG_TITLE_STR[];
73   static const char BPROJ_TABLE_TITLE_STR[];
74   static const char BPROJ_DIFF_TITLE_STR[];
75   static const char BPROJ_DIFF2_TITLE_STR[];
76   static const char BPROJ_IDIFF2_TITLE_STR[];
77   static const char BPROJ_IDIFF3_TITLE_STR[];
78  
79   static const char INTERP_NEAREST_STR[];
80   static const char INTERP_LINEAR_STR[];
81   static const char INTERP_BSPLINE_STR[];
82   static const char INTERP_FREQ_PREINTERPOLATION_STR[];
83
84   static const char INTERP_NEAREST_TITLE_STR[];
85   static const char INTERP_LINEAR_TITLE_STR[];
86   static const char INTERP_BSPLINE_TITLE_STR[];
87   static const char INTERP_FREQ_PREINTERPOLATION_TITLE_STR[];
88
89   Backprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor);
90
91   ~Backprojector (void);
92                  
93   void BackprojectView (const double* const viewData, const double viewAngle);
94
95   bool fail(void) const {return m_fail;}
96   const string& failMessage(void) const {return m_failMessage;}
97
98  private:
99   string m_nameBackproject;
100   string m_nameInterpolation;
101   BackprojectID m_idBackproject;
102   InterpolationID m_idInterpolation;
103   Backproject* m_pBackprojectImplem;
104   bool m_fail;
105   string m_failMessage;
106
107   static const InterpolationID convertInterpolationNameToID (const char* const interpName);
108   static const char* convertInterpolationIDToName (const InterpolationID interpID);
109   static const BackprojectID convertBackprojectNameToID (const char* const bprojName);
110   static const char* convertBackprojectIDToName (const BackprojectID bprojID);
111
112   bool initBackprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor);
113 };
114
115
116 class Backproject
117 {
118  public:
119     Backproject (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType, const int interpFactor);
120
121     virtual ~Backproject ();
122
123     virtual void BackprojectView (const double* const viewData, const double viewAngle) {};
124
125  protected:
126     void ScaleImageByRotIncrement (void);
127     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double r, double phi, double L, int ni);
128     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double L, int ni);
129
130     const Projections& proj;
131     ImageFile& im;
132     Backprojector::InterpolationID interpType;
133     ImageFileArray v;
134     kint32 nx;
135     kint32 ny;
136     double detInc;
137     double rotInc;
138     int iDetCenter;             // index refering to L=0 projection 
139     int nDet;
140     double xMin, xMax, yMin, yMax;     // Retangular coords of phantom
141     double xInc, yInc;  // size of cells
142     int m_interpFactor;
143
144  private:
145     Backproject (const Backproject& rhs);
146     Backproject& operator= (const Backproject& rhs);
147 };
148
149
150 class BackprojectTrig : public Backproject
151 {
152  public:
153   BackprojectTrig (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType, const int interpFactor)
154       : Backproject::Backproject (proj, im, interpType, interpFactor)
155       {}
156
157   void BackprojectView (const double* const t, double view_angle);
158 };
159
160
161 class BackprojectTable : public Backproject
162 {
163  public:
164   BackprojectTable (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType, const int interpFactor);
165   ~BackprojectTable ();
166
167   void BackprojectView (const double* const t, double view_angle);
168
169  private:
170   Array2d<kfloat64> arrayR;
171   Array2d<kfloat64> arrayPhi;
172   kfloat64** r;
173   kfloat64** phi;
174 };
175
176
177 class BackprojectDiff : public Backproject
178 {
179  public:
180   BackprojectDiff (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType, const int interpFactor);
181   ~BackprojectDiff ();
182
183   void BackprojectView (const double* const t, double view_angle);
184
185  protected:
186   double start_r;
187   double start_phi;
188   double im_xinc, im_yinc;
189 };
190
191 class BackprojectDiff2 : public BackprojectDiff
192 {
193  public:
194   BackprojectDiff2 (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType, const int interpFactor)
195     :  BackprojectDiff::BackprojectDiff (proj, im, interpType, interpFactor)
196     {}
197
198   void BackprojectView (const double* const t, double view_angle);
199 };
200
201 class BackprojectIntDiff2 : public BackprojectDiff
202 {
203  public:
204   BackprojectIntDiff2 (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType, const int interpFactor)
205     :  BackprojectDiff::BackprojectDiff (proj, im, interpType, interpFactor)
206     {}
207   
208   void BackprojectView (const double* const t, double view_angle);
209 };
210
211
212 class BackprojectIntDiff3 : public BackprojectDiff
213 {
214  public:
215   BackprojectIntDiff3 (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType, const int interpFactor)
216     :  BackprojectDiff::BackprojectDiff (proj, im, interpType, interpFactor)
217     {}
218   
219   void BackprojectView (const double* const t, double view_angle);
220 };
221
222
223 #endif