r120: *** 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.5 2000/06/25 17:32:24 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 #undef HAVE_BSPLINE_INTERP
30
31 class Backproject;
32
33 class Backprojector
34 {
35  public:
36   typedef  enum {
37     BPROJ_INVALID,
38     BPROJ_TRIG,
39     BPROJ_TABLE,
40     BPROJ_DIFF,
41     BPROJ_DIFF2,
42     BPROJ_IDIFF2
43 } BackprojectID;
44
45   typedef enum {
46     INTERP_INVALID,
47     INTERP_NEAREST,      // Nearest neighbor
48 #if HAVE_BSPLINE_INTERP
49     I_BSPLINE,
50     I_1BSPLINE,      // 1st order B-Spline 
51     I_2BSPLINE,
52     I_3BSPLINE,
53 #endif
54     INTERP_LINEAR        // Linear interpolation 
55   } InterpolationID;
56
57   static const char BPROJ_TRIG_STR[]=     "trig";
58   static const char BPROJ_TABLE_STR[]=    "table";
59   static const char BPROJ_DIFF_STR[]=     "diff";
60   static const char BPROJ_DIFF2_STR[]=    "diff2";
61   static const char BPROJ_IDIFF2_STR[]=   "idiff2";
62  
63   static const char INTERP_NEAREST_STR[]=  "nearest";
64   static const char INTERP_LINEAR_STR[]=   "linear";
65   static const char INTERP_BSPLINE_STR[]=  "bspline";
66
67
68   Backprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName);
69
70   ~Backprojector (void);
71                  
72   void BackprojectView (const double* const viewData, const double viewAngle);
73
74   bool fail(void) const {return m_fail;}
75   const string& failMessage(void) const {return m_failMessage;}
76
77  private:
78   string m_nameBackproject;
79   string m_nameInterpolation;
80   BackprojectID m_idBackproject;
81   InterpolationID m_idInterpolation;
82   Backproject* m_pBackprojectImplem;
83   bool m_fail;
84   string m_failMessage;
85
86   static const InterpolationID convertInterpolationNameToID (const char* const interpName);
87   static const char* convertInterpolationIDToName (const InterpolationID interpID);
88   static const BackprojectID convertBackprojectNameToID (const char* const bprojName);
89   static const char* convertBackprojectIDToName (const BackprojectID bprojID);
90
91   bool initBackprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName);
92 };
93
94
95 class Backproject
96 {
97  public:
98     Backproject (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType);
99
100     virtual ~Backproject ();
101
102     virtual void BackprojectView (const double* const viewData, const double viewAngle) {};
103
104  protected:
105     void ScaleImageByRotIncrement (void);
106     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double r, double phi, double L, int ni);
107     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double L, int ni);
108
109     Backprojector::InterpolationID interpType;
110     const Projections& proj;
111     ImageFile& im;
112     ImageFileArray v;
113     kuint32 nx;
114     kuint32 ny;
115     double detInc;
116     double rotInc;
117     int iDetCenter;             // index refering to L=0 projection 
118     int nDet;
119     double xMin, xMax, yMin, yMax;     // Retangular coords of phantom
120     double xInc, yInc;  // size of cells
121
122  private:
123     Backproject (const Backproject& rhs);
124     Backproject& operator= (const Backproject& rhs);
125 };
126
127
128 class BackprojectTrig : public Backproject
129 {
130  public:
131   BackprojectTrig (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType)
132       : Backproject::Backproject (proj, im, interpType)
133       {}
134
135   void BackprojectView (const double* const t, double view_angle);
136 };
137
138
139 class BackprojectTable : public Backproject
140 {
141  public:
142   BackprojectTable (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType);
143   ~BackprojectTable ();
144
145   void BackprojectView (const double* const t, double view_angle);
146
147  private:
148   Array2d<kfloat64> arrayR;
149   Array2d<kfloat64> arrayPhi;
150   kfloat64** r;
151   kfloat64** phi;
152 };
153
154
155 class BackprojectDiff : public Backproject
156 {
157  public:
158   BackprojectDiff (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType);
159   ~BackprojectDiff ();
160
161   void BackprojectView (const double* const t, double view_angle);
162
163  protected:
164   double start_r;
165   double start_phi;
166   double im_xinc, im_yinc;
167 };
168
169 class BackprojectDiff2 : public BackprojectDiff
170 {
171  public:
172   BackprojectDiff2 (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType)
173     :  BackprojectDiff::BackprojectDiff (proj, im, interpType)
174     {}
175
176   void BackprojectView (const double* const t, double view_angle);
177 };
178
179 class BackprojectIntDiff2 : public BackprojectDiff
180 {
181  public:
182   BackprojectIntDiff2 (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType)
183     :  BackprojectDiff::BackprojectDiff (proj, im, interpType)
184     {}
185   
186   void BackprojectView (const double* const t, double view_angle);
187 };
188
189