r573: no 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-2001 Kevin Rosenberg
11 **
12 **  $Id: backprojectors.h,v 1.22 2001/02/22 18:22:40 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 class ImageFile;
39 class Projections;
40
41 class Backprojector
42 {
43  public:
44   static const int BPROJ_INVALID;
45   static const int BPROJ_TRIG;
46   static const int BPROJ_TABLE;
47   static const int BPROJ_DIFF;
48   static const int BPROJ_IDIFF;
49
50   static const int INTERP_INVALID;
51   static const int INTERP_NEAREST;
52   static const int INTERP_LINEAR;
53   static const int INTERP_CUBIC;
54   static const int INTERP_FREQ_PREINTERPOLATION;
55 #if HAVE_BSPLINE_INTERP
56   static const int INTERP_BSPLINE;
57   static const int INTERP_1BSPLINE;
58   static const int INTERP_2BSPLINE;
59   static const int INTERP_3BSPLINE;
60 #endif
61
62   Backprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor);
63
64   ~Backprojector ();
65                  
66   void BackprojectView (const double* const viewData, const double viewAngle);
67
68   bool fail() const {return m_fail;}
69   const std::string& failMessage() const {return m_failMessage;}
70
71   static const int getBackprojectCount() {return s_iBackprojectCount;}
72   static const char* const* getBackprojectNameArray() {return s_aszBackprojectName;}
73   static const char* const* getBackprojectTitleArray() {return s_aszBackprojectTitle;}
74   static int convertBackprojectNameToID (const char* const bprojName);
75   static const char* convertBackprojectIDToName (const int bprojID);
76   static const char* convertBackprojectIDToTitle (const int bprojID);
77
78   static const int getInterpCount() {return s_iInterpCount;}
79   static const char* const * getInterpNameArray() {return s_aszInterpName;}
80   static const char* const * getInterpTitleArray() {return s_aszInterpTitle;}
81   static int convertInterpNameToID (const char* const interpName);
82   static const char* convertInterpIDToName (const int interpID);
83   static const char* convertInterpIDToTitle (const int interpID);
84
85
86  private:
87   std::string m_nameBackproject;
88   std::string m_nameInterpolation;
89   int m_idBackproject;
90   int m_idInterpolation;
91   Backproject* m_pBackprojectImplem;
92   bool m_fail;
93   std::string m_failMessage;
94
95   static const char* const s_aszBackprojectName[];
96   static const char* const s_aszBackprojectTitle[];
97   static const int s_iBackprojectCount;
98
99   static const char* const s_aszInterpName[];
100   static const char* const s_aszInterpTitle[];
101   static const int s_iInterpCount;
102
103   bool initBackprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor);
104 };
105
106
107 class Backproject
108 {
109  public:
110     Backproject (const Projections& proj, ImageFile& im, int interpID, const int interpFactor);
111
112     virtual ~Backproject ();
113
114     virtual void BackprojectView (const double* const viewData, const double viewAngle) {};
115
116  protected:
117     void ScaleImageByRotIncrement ();
118     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double r, double phi, double L, int ni);
119     void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double L, int ni);
120
121     const Projections& proj;
122     ImageFile& im;
123     int interpType;
124     ImageFileArray v;
125     kint32 nx;
126     kint32 ny;
127     double detInc;
128     double rotScale;
129     int iDetCenter;             // index refering to L=0 projection 
130     int nDet;
131     double xMin, xMax, yMin, yMax;     // Retangular coords of phantom
132     double xInc, yInc;  // size of cells
133     int m_interpFactor;
134     double m_dFocalLength;
135
136  private:
137     Backproject (const Backproject& rhs);
138     Backproject& operator= (const Backproject& rhs);
139 };
140
141
142 class BackprojectTrig : public Backproject
143 {
144  public:
145   BackprojectTrig (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
146       : Backproject (proj, im, interpID, interpFactor)
147       {}
148
149   void BackprojectView (const double* const t, const double view_angle);
150 };
151
152
153 class BackprojectTable : public Backproject
154 {
155  public:
156   BackprojectTable (const Projections& proj, ImageFile& im, int interpID, const int interpFactor);
157   virtual ~BackprojectTable ();
158
159   void BackprojectView (const double* const t, const double view_angle);
160
161  protected:
162   Array2d<kfloat64> arrayR;
163   Array2d<kfloat64> arrayPhi;
164   kfloat64** r;
165   kfloat64** phi;
166 };
167
168
169 class BackprojectDiff : public Backproject
170 {
171  public:
172   BackprojectDiff (const Projections& proj, ImageFile& im, int interpID, const int interpFactor);
173   ~BackprojectDiff ();
174
175   void BackprojectView (const double* const t, const double view_angle);
176
177  protected:
178   double start_r;
179   double start_phi;
180   double im_xinc, im_yinc;
181 };
182
183
184 class BackprojectIntDiff : public BackprojectDiff
185 {
186  public:
187   BackprojectIntDiff (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
188     :  BackprojectDiff (proj, im, interpID, interpFactor)
189     {}
190   
191   void BackprojectView (const double* const t, const double view_angle);
192 };
193
194 class BackprojectEquilinear : public BackprojectTable
195 {
196  public:
197   BackprojectEquilinear (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
198       : BackprojectTable (proj, im, interpID, interpFactor)
199       {}
200
201   void BackprojectView (const double* const t, const double view_angle);
202
203   virtual ~BackprojectEquilinear()
204       {}
205 };
206
207 class BackprojectEquiangular : public BackprojectTable
208 {
209  public:
210   BackprojectEquiangular (const Projections& proj, ImageFile& im, int interpID, const int interpFactor)
211       : BackprojectTable (proj, im, interpID, interpFactor)
212       {}
213
214   void BackprojectView (const double* const t, const double view_angle);
215
216   virtual ~BackprojectEquiangular()
217       {}
218 };
219
220
221 #endif