Revert "Update package dependency from libwxgtk3.0-dev to libwxgtk3.0-gtk3-dev for...
[ctsim.git] / include / projections.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          projections.h
5 **   Purpose:       Header file for Projections class
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  July 1, 1984
8 **
9 **  This is part of the CTSim program
10 **  Copyright (c) 1983-2009 Kevin Rosenberg
11 **
12 **  This program is free software; you can redistribute it and/or modify
13 **  it under the terms of the GNU General Public License (version 2) as
14 **  published by the Free Software Foundation.
15 **
16 **  This program is distributed in the hope that it will be useful,
17 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 **  GNU General Public License for more details.
20 **
21 **  You should have received a copy of the GNU General Public License
22 **  along with this program; if not, write to the Free Software
23 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24 ******************************************************************************/
25
26 #ifndef PROJECTIONS_H
27 #define PROJECTIONS_H
28
29 class Scanner;
30 class DetectorArray;
31 class Array2dFileLabel;
32 class fnetorderstream;
33
34 #include "array2dfile.h"
35 #include "imagefile.h"
36 #include <complex>
37 #include <vector>
38
39
40 //used for rebinning divergent beam projections to parallel
41 class ParallelRaysumCoordinate {
42 public:
43   double m_dT;      // Distance from center of origin
44   double m_dTheta;  // perpendicular angle to origin
45   double m_dRaysum;
46
47   static bool compareByTheta (ParallelRaysumCoordinate* a, ParallelRaysumCoordinate* b)
48   { return a->m_dTheta == b->m_dTheta ? b->m_dT > a->m_dT : b->m_dTheta > a->m_dTheta; }
49
50   // sort first by T, then Theta
51   static bool compareByT (ParallelRaysumCoordinate* a, ParallelRaysumCoordinate* b)
52   { return a->m_dT == b->m_dT ? b->m_dTheta > a->m_dTheta : b->m_dT > a->m_dT; }
53
54 };
55
56 class ParallelRaysums {
57 public:
58
59   enum {
60     THETA_RANGE_UNCONSTRAINED = 0,
61     THETA_RANGE_NORMALIZE_TO_TWOPI,
62     THETA_RANGE_FOLD_TO_PI,
63   };
64
65   ParallelRaysums (const Projections* pProjections, int iThetaRange);
66   ~ParallelRaysums ();
67
68   typedef std::vector<ParallelRaysumCoordinate*> CoordinateContainer;
69   typedef CoordinateContainer::iterator CoordinateIterator;
70
71   CoordinateContainer& getCoordinates() {return m_vecpCoordinates;}
72   int getNumCoordinates() const {return m_iNumCoordinates;}
73   void getLimits (double* dMinT, double* dMaxT, double* dMinTheta, double* dMaxTheta) const;
74   CoordinateContainer& getSortedByT();
75   CoordinateContainer& getSortedByTheta();
76   double interpolate (double* pdX, double* pdY, int n, double dXValue, int* iLastFloor = NULL);
77   void getThetaAndRaysumsForT (int iT, double* pdTheta, double* pdRaysum);
78   void getDetPositions (double* pdDetPos);
79
80 private:
81   CoordinateContainer m_vecpCoordinates;
82   CoordinateContainer m_vecpSortedByT;
83   CoordinateContainer m_vecpSortedByTheta;
84   ParallelRaysumCoordinate* m_pCoordinates;
85   int m_iNumCoordinates;
86   int m_iNumView;
87   int m_iNumDet;
88   int m_iThetaRange;
89 };
90
91
92
93 // Projections
94 class Projections
95 {
96  public:
97
98   static const int POLAR_INTERP_INVALID;
99   static const int POLAR_INTERP_NEAREST;
100   static const int POLAR_INTERP_BILINEAR;
101   static const int POLAR_INTERP_BICUBIC;
102
103   Projections (const int nView, const int nDet);
104   Projections (const Scanner& scanner);
105   Projections ();
106   ~Projections ();
107
108   static const int getInterpCount() {return s_iInterpCount;}
109   static const char* const* getInterpNameArray() {return s_aszInterpName;}
110   static const char* const* getInterpTitleArray() {return s_aszInterpTitle;}
111   static int convertInterpNameToID (const char* const interpName);
112   static const char* convertInterpIDToName (const int interpID);
113   static const char* convertInterpIDToTitle (const int interpID);
114
115   void initFromScanner (const Scanner& scanner);
116   bool initFromSomatomAR_STAR (int iNViews, int iNDets, unsigned char* pData, unsigned long lDataLength);
117
118   void printProjectionData (int startView, int endView);
119   void printProjectionData ();
120   void printScanInfo (std::ostringstream& os) const;
121
122   int Helical180LI(int interpView);
123   int Helical180LI_Equiangular(int interpView);
124   int HalfScanFeather(void);
125
126   bool read (const std::string& fname);
127   bool read (const char* fname);
128   bool write (const char* fname);
129   bool write (const std::string& fname);
130   bool detarrayRead (fnetorderstream& fs, DetectorArray& darray, const int view_num);
131   bool detarrayWrite (fnetorderstream& fs, const DetectorArray& darray, const int view_num);
132
133   Projections* interpolateToParallel() const;
134
135   bool convertPolar (ImageFile& rIF, int iInterpolation);
136   bool convertFFTPolar (ImageFile& rIF, int iInterpolation, int iZeropad);
137   void calcArrayPolarCoordinates (unsigned int nx, unsigned int ny, double** ppdView, double** ppdDet,
138     int iNumDetWithZeros, double dZeropadRatio, double dDetInc);
139   void interpolatePolar (ImageFileArray& v, ImageFileArray& vImag, unsigned int nx, unsigned int ny, std::complex<double>** ppcDetValue,
140     double** ppdDet, double** ppdView, unsigned int nView, unsigned int nDet, unsigned int nDetWithZeros,
141     int iInterpolate);
142
143   bool reconstruct (ImageFile& im, const char* const filterName, double filt_param, const char* const filterMethodName, const int zeropad, const char* frequencyFilterName, const char* const interpName, int interp_param, const char* const backprojName, const int trace) const;
144
145   void setNView (int nView);  // used in MPI to restrict # of views
146   void setRotInc (double rotInc) { m_rotInc = rotInc;}
147   void setDetInc (double detInc) { m_detInc = detInc;}
148   void setCalcTime (double calcTime) {m_calcTime = calcTime;}
149   void setRemark (const char* remark) {m_remark = remark; m_label.setLabelString(remark);}
150   void setRemark (const std::string& remark) {setRemark(remark.c_str());}
151
152   double detStart() const {return m_detStart;}
153   double rotStart() const {return m_rotStart;}
154   double calcTime() const {return m_calcTime;}
155   double viewLen() const {return m_dViewDiameter / SQRT2;}
156   const char*  remark() const {return m_remark.c_str();}
157   double detInc() const {return m_detInc;}
158   double rotInc() const {return m_rotInc;}
159   int nDet() const {return m_nDet;}
160   int nView() const {return m_nView;}
161   int geometry() const {return m_geometry;}
162   double focalLength() const {return m_dFocalLength;}
163   double sourceDetectorLength() const { return m_dSourceDetectorLength;}
164   double viewDiameter() const {return m_dViewDiameter; }
165   double phmLen() const { return m_dViewDiameter / SQRT2; }
166   void setPhmLen(double phmLen) { m_dViewDiameter = phmLen * SQRT2; }
167
168   const std::string& getFilename() const {return m_filename;}
169   Array2dFileLabel& getLabel() {return m_label;}
170   const Array2dFileLabel& getLabel() const {return m_label;}
171
172   DetectorArray& getDetectorArray (const int iview)
173       { return (*m_projData[iview]); }
174
175   const DetectorArray& getDetectorArray (const int iview) const
176       { return (*m_projData[iview]); }
177
178   static bool copyHeader (const char* const filename, std::ostream& os);
179   static bool copyHeader (const std::string& filename, std::ostream& os);
180
181   static bool copyViewData (const char* const filename, std::ostream& os, int startView, int endView);
182   static bool copyViewData (const std::string& filename, std::ostream& os, int startView, int endView);
183
184  private:
185   int m_headerSize;             // Size of disk file header
186   int m_geometry;               // Geometry of scanner
187   class DetectorArray **m_projData;     // Pointer to array of detarray_st pointers
188   std::string m_remark;         // description of raysum data
189   int m_nDet;                   // number of detectors in array
190   int m_nView;                  // number of rotated views
191   double m_calcTime;            // time required to calculate raysums
192   double m_rotStart;            // starting view rotation
193   double m_rotInc;              // angle between rotations
194   double m_detStart;            // distance of beginning detector to center phantom
195   double m_detInc;              // increment between detectors
196   double m_dFocalLength;
197   double m_dSourceDetectorLength;
198   double m_dViewDiameter;
199   double m_dFanBeamAngle;
200   kuint32 m_year;                   // Creation date & time
201   kuint32 m_month;
202   kuint32 m_day;
203   kuint32 m_hour;
204   kuint32 m_minute;
205   kuint32 m_second;
206   std::string m_filename;
207   Array2dFileLabel m_label;
208
209   const static kuint16 m_signature;
210
211   static const char* const s_aszInterpName[];
212   static const char* const s_aszInterpTitle[];
213   static const int s_iInterpCount;
214
215   bool headerWrite (fnetorderstream& fs);
216   bool headerRead (fnetorderstream& fs);
217   void newProjData ();
218   void deleteProjData ();
219
220   void init (const int nView, const int nDet);
221
222   // prevent default methods
223   Projections& operator= (const Projections& rhs);   // assignment
224   Projections(const Projections& rhs);               // copy
225 };
226
227
228 #endif