r117: *** 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.4 2000/06/22 10:17:28 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   Backprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName);
58
59   ~Backprojector (void);
60                  
61   void BackprojectView (const double* const viewData, const double viewAngle);
62
63   bool fail(void) const {return m_fail;}
64
65  private:
66   string m_nameBackproject;
67   string m_nameInterpolation;
68   BackprojectID m_idBackproject;
69   InterpolationID m_idInterpolation;
70   bool m_fail;
71   Backproject* m_pBackprojectImplem;
72
73   static const char BPROJ_TRIG_STR[]=     "trig";
74   static const char BPROJ_TABLE_STR[]=    "table";
75   static const char BPROJ_DIFF_STR[]=     "diff";
76   static const char BPROJ_DIFF2_STR[]=    "diff2";
77   static const char BPROJ_IDIFF2_STR[]=   "idiff2";
78  
79   static const char INTERP_NEAREST_STR[]=  "nearest";
80   static const char INTERP_LINEAR_STR[]=   "linear";
81   static const char INTERP_BSPLINE_STR[]=  "bspline";
82
83   static const InterpolationID convertInterpolationNameToID (const char* const interpName);
84   static const char* convertInterpolationIDToName (const InterpolationID interpID);
85   static const BackprojectID convertBackprojectNameToID (const char* const bprojName);
86   static const char* convertBackprojectIDToName (const BackprojectID bprojID);
87
88   bool initBackprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName);
89 };
90
91
92 class Backproject
93 {
94  public:
95     Backproject (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType);
96
97     virtual ~Backproject ();
98
99     virtual void BackprojectView (const double* const viewData, const double viewAngle) {};
100
101  protected:
102     void ScaleImageByRotIncrement (void);
103     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double r, double phi, double L, int ni);
104     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double L, int ni);
105
106     Backprojector::InterpolationID interpType;
107     const Projections& proj;
108     ImageFile& im;
109     ImageFileArray v;
110     kuint32 nx;
111     kuint32 ny;
112     double detInc;
113     double rotInc;
114     int iDetCenter;             // index refering to L=0 projection 
115     int nDet;
116     double xMin, xMax, yMin, yMax;     // Retangular coords of phantom
117     double xInc, yInc;  // size of cells
118
119  private:
120     Backproject (const Backproject& rhs);
121     Backproject& operator= (const Backproject& rhs);
122 };
123
124
125 class BackprojectTrig : public Backproject
126 {
127  public:
128   BackprojectTrig (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType)
129       : Backproject::Backproject (proj, im, interpType)
130       {}
131
132   void BackprojectView (const double* const t, double view_angle);
133 };
134
135
136 class BackprojectTable : public Backproject
137 {
138  public:
139   BackprojectTable (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType);
140   ~BackprojectTable ();
141
142   void BackprojectView (const double* const t, double view_angle);
143
144  private:
145   Array2d<kfloat64> arrayR;
146   Array2d<kfloat64> arrayPhi;
147   kfloat64** r;
148   kfloat64** phi;
149 };
150
151
152 class BackprojectDiff : public Backproject
153 {
154  public:
155   BackprojectDiff (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType);
156   ~BackprojectDiff ();
157
158   void BackprojectView (const double* const t, double view_angle);
159
160  protected:
161   double start_r;
162   double start_phi;
163   double im_xinc, im_yinc;
164 };
165
166 class BackprojectDiff2 : public BackprojectDiff
167 {
168  public:
169   BackprojectDiff2 (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType)
170     :  BackprojectDiff::BackprojectDiff (proj, im, interpType)
171     {}
172
173   void BackprojectView (const double* const t, double view_angle);
174 };
175
176 class BackprojectIntDiff2 : public BackprojectDiff
177 {
178  public:
179   BackprojectIntDiff2 (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType)
180     :  BackprojectDiff::BackprojectDiff (proj, im, interpType)
181     {}
182   
183   void BackprojectView (const double* const t, double view_angle);
184 };
185
186