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