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