r626: no message
[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.28 2001/03/10 23:14:15 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
41 //used for rebinning divergent beam projections to parallel
42 class ParallelRaysumCoordinate {  
43 public:
44   double m_dT;      // Distance from center of origin
45   double m_dTheta;  // perpendicular angle to origin
46   int m_iViewNum;   // View number for this raysum
47   int m_iDetNum;    // Detector number for this raysum
48
49   bool lessThanT (ParallelRaysumCoordinate& rCompare)
50   {return m_dT < rCompare.m_dT; }
51   bool lessThanTheta (ParallelRaysumCoordinate& rCompare)
52   {return m_dTheta < rCompare.m_dTheta; }
53 };
54
55 class ParallelRaysums {
56 private:
57   ParallelRaysumCoordinate** m_ppCoordinates;
58   int m_iNumCoordinates;
59
60 public:
61   ParallelRaysums (Projections* pProjections);
62   ~ParallelRaysums ();
63
64   ParallelRaysumCoordinate** getCoordinates() {return m_ppCoordinates;}
65   int getNumCoordinates() const {return m_iNumCoordinates;}
66   void getLimits (double* dMinT, double* dMaxT, double* dMinTheta, double* dMaxTheta) const;
67 };
68
69
70
71 // Projections
72 class Projections
73 {
74  public:
75
76   static const int POLAR_INTERP_INVALID;
77   static const int POLAR_INTERP_NEAREST;
78   static const int POLAR_INTERP_BILINEAR;
79   static const int POLAR_INTERP_BICUBIC;
80
81   Projections (const int nView, const int nDet);
82   Projections (const Scanner& scanner);
83   Projections ();
84   ~Projections ();
85
86   static const int getInterpCount() {return s_iInterpCount;}
87   static const char* const* getInterpNameArray() {return s_aszInterpName;}
88   static const char* const* getInterpTitleArray() {return s_aszInterpTitle;}
89   static int convertInterpNameToID (const char* const interpName);
90   static const char* convertInterpIDToName (const int interpID);
91   static const char* convertInterpIDToTitle (const int interpID);
92
93   void initFromScanner (const Scanner& scanner);
94   bool initFromSomatomAR_STAR (int iNViews, int iNDets, unsigned char* pData, unsigned long lDataLength);
95
96   void printProjectionData (int startView, int endView);
97   void printProjectionData ();
98   void printScanInfo (std::ostringstream& os) const;
99
100   bool read (const std::string& fname);
101   bool read (const char* fname);
102   bool write (const char* fname);
103   bool write (const std::string& fname);
104   bool detarrayRead (fnetorderstream& fs, DetectorArray& darray, const int view_num);
105   bool detarrayWrite (fnetorderstream& fs, const DetectorArray& darray, const int view_num);
106
107   bool interpolateToParallel();
108
109   bool convertPolar (ImageFile& rIF, int iInterpolation);
110   bool convertFFTPolar (ImageFile& rIF, int iInterpolation, int iZeropad);
111   bool calcArrayPolarCoordinates (unsigned int nx, unsigned int ny, double** ppdView, double** ppdDet);
112   void interpolatePolar (ImageFileArray& v, ImageFileArray& vImag, unsigned int nx, unsigned int ny, std::complex<double>** ppcDetValue,
113     double** ppdDet, double** ppdView, unsigned int nView, unsigned int nDet, int iInterpolate);
114
115   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;
116
117   void setNView (int nView);  // used in MPI to restrict # of views
118   void setRotInc (double rotInc) { m_rotInc = rotInc;}
119   void setDetInc (double detInc) { m_detInc = detInc;}
120   void setCalcTime (double calcTime) {m_calcTime = calcTime;}
121   void setRemark (const char* remark) {m_remark = remark; m_label.setLabelString(remark);}
122   void setRemark (const std::string& remark) {setRemark(remark.c_str());}
123
124   double detStart() const {return m_detStart;}
125   double rotStart() const {return m_rotStart;}
126   double calcTime() const {return m_calcTime;}
127   double viewLen() const {return m_dViewDiameter / SQRT2;}
128   const char*  remark() const {return m_remark.c_str();}
129   double detInc() const {return m_detInc;}
130   double rotInc() const {return m_rotInc;}
131   int nDet() const {return m_nDet;}
132   int nView() const {return m_nView;}
133   int geometry() const {return m_geometry;}
134   double focalLength() const {return m_dFocalLength;}
135   double sourceDetectorLength() const { return m_dSourceDetectorLength;}
136
137   double phmLen() const { return m_dViewDiameter / SQRT2; }
138   void setPhmLen(double phmLen) { m_dViewDiameter = phmLen * SQRT2; }
139
140   const std::string& getFilename() const {return m_filename;}
141   Array2dFileLabel& getLabel() {return m_label;}
142   const Array2dFileLabel& getLabel() const {return m_label;}
143
144   DetectorArray& getDetectorArray (const int iview)
145       { return (*m_projData[iview]); }
146   
147   const DetectorArray& getDetectorArray (const int iview) const
148       { return (*m_projData[iview]); }
149
150   static bool copyHeader (const char* const filename, std::ostream& os);
151   static bool copyHeader (const std::string& filename, std::ostream& os);
152
153   static bool copyViewData (const char* const filename, std::ostream& os, int startView, int endView);
154   static bool copyViewData (const std::string& filename, std::ostream& os, int startView, int endView);
155   
156  private:
157   int m_headerSize;             // Size of disk file header 
158   int m_geometry;               // Geometry of scanner 
159   class DetectorArray **m_projData;     // Pointer to array of detarray_st pointers 
160   std::string m_remark;         // description of raysum data 
161   int m_nDet;                   // number of detectors in array 
162   int m_nView;                  // number of rotated views 
163   double m_calcTime;            // time required to calculate raysums 
164   double m_rotStart;            // starting view rotation
165   double m_rotInc;              // angle between rotations 
166   double m_detStart;            // distance of beginning detector to center phantom
167   double m_detInc;              // increment between detectors 
168   double m_dFocalLength;
169   double m_dSourceDetectorLength;
170   double m_dViewDiameter;
171   double m_dFanBeamAngle;
172   kuint32 m_year;                   // Creation date & time
173   kuint32 m_month;
174   kuint32 m_day;
175   kuint32 m_hour;
176   kuint32 m_minute;
177   kuint32 m_second;
178   std::string m_filename;
179   Array2dFileLabel m_label;
180
181   const static kuint16 m_signature;
182
183   static const char* const s_aszInterpName[];
184   static const char* const s_aszInterpTitle[];
185   static const int s_iInterpCount;
186
187   bool headerWrite (fnetorderstream& fs);
188   bool headerRead (fnetorderstream& fs);
189   void newProjData ();
190   void deleteProjData ();
191
192   void init (const int nView, const int nDet);
193
194   // prevent default methods
195   Projections& operator= (const Projections& rhs);   // assignment
196   Projections(const Projections& rhs);               // copy
197 };
198
199
200 #endif