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