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