r628: 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.30 2001/03/11 06:34:37 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   double m_dRaysum;
49
50   bool lessThanT (ParallelRaysumCoordinate& rCompare)
51   {return m_dT < rCompare.m_dT; }
52   bool lessThanTheta (ParallelRaysumCoordinate& rCompare)
53   {return m_dTheta < rCompare.m_dTheta; }
54
55   static bool compareByTheta (ParallelRaysumCoordinate* a, ParallelRaysumCoordinate* b)
56   { return a->m_dTheta == b->m_dTheta ? b->m_dT > a->m_dT : b->m_dTheta > a->m_dTheta; }
57
58   // sort first by T, then Theta
59   static bool compareByT (ParallelRaysumCoordinate* a, ParallelRaysumCoordinate* b)
60   { return a->m_dT == b->m_dT ? b->m_dTheta > a->m_dTheta : b->m_dT > a->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   double interpolate (double* pdX, double* pdY, int n, double dXValue);
78   void getThetaAndRaysumsForT (int iT, double* pdTheta, double* pdRaysum);
79   void getDetPositions (double* pdDetPos);
80
81 private:
82   CoordinateContainer m_vecpCoordinates;
83   CoordinateContainer m_vecpSortedByT;
84   CoordinateContainer m_vecpSortedByTheta;
85   int m_iNumCoordinates;
86   int m_iNumView;
87   int m_iNumDet;
88 };
89
90
91
92 // Projections
93 class Projections
94 {
95  public:
96
97   static const int POLAR_INTERP_INVALID;
98   static const int POLAR_INTERP_NEAREST;
99   static const int POLAR_INTERP_BILINEAR;
100   static const int POLAR_INTERP_BICUBIC;
101
102   Projections (const int nView, const int nDet);
103   Projections (const Scanner& scanner);
104   Projections ();
105   ~Projections ();
106
107   static const int getInterpCount() {return s_iInterpCount;}
108   static const char* const* getInterpNameArray() {return s_aszInterpName;}
109   static const char* const* getInterpTitleArray() {return s_aszInterpTitle;}
110   static int convertInterpNameToID (const char* const interpName);
111   static const char* convertInterpIDToName (const int interpID);
112   static const char* convertInterpIDToTitle (const int interpID);
113
114   void initFromScanner (const Scanner& scanner);
115   bool initFromSomatomAR_STAR (int iNViews, int iNDets, unsigned char* pData, unsigned long lDataLength);
116
117   void printProjectionData (int startView, int endView);
118   void printProjectionData ();
119   void printScanInfo (std::ostringstream& os) const;
120
121   bool read (const std::string& fname);
122   bool read (const char* fname);
123   bool write (const char* fname);
124   bool write (const std::string& fname);
125   bool detarrayRead (fnetorderstream& fs, DetectorArray& darray, const int view_num);
126   bool detarrayWrite (fnetorderstream& fs, const DetectorArray& darray, const int view_num);
127
128   Projections* interpolateToParallel();
129
130   bool convertPolar (ImageFile& rIF, int iInterpolation);
131   bool convertFFTPolar (ImageFile& rIF, int iInterpolation, int iZeropad);
132   bool calcArrayPolarCoordinates (unsigned int nx, unsigned int ny, double** ppdView, double** ppdDet);
133   void interpolatePolar (ImageFileArray& v, ImageFileArray& vImag, unsigned int nx, unsigned int ny, std::complex<double>** ppcDetValue,
134     double** ppdDet, double** ppdView, unsigned int nView, unsigned int nDet, int iInterpolate);
135
136   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;
137
138   void setNView (int nView);  // used in MPI to restrict # of views
139   void setRotInc (double rotInc) { m_rotInc = rotInc;}
140   void setDetInc (double detInc) { m_detInc = detInc;}
141   void setCalcTime (double calcTime) {m_calcTime = calcTime;}
142   void setRemark (const char* remark) {m_remark = remark; m_label.setLabelString(remark);}
143   void setRemark (const std::string& remark) {setRemark(remark.c_str());}
144
145   double detStart() const {return m_detStart;}
146   double rotStart() const {return m_rotStart;}
147   double calcTime() const {return m_calcTime;}
148   double viewLen() const {return m_dViewDiameter / SQRT2;}
149   const char*  remark() const {return m_remark.c_str();}
150   double detInc() const {return m_detInc;}
151   double rotInc() const {return m_rotInc;}
152   int nDet() const {return m_nDet;}
153   int nView() const {return m_nView;}
154   int geometry() const {return m_geometry;}
155   double focalLength() const {return m_dFocalLength;}
156   double sourceDetectorLength() const { return m_dSourceDetectorLength;}
157
158   double phmLen() const { return m_dViewDiameter / SQRT2; }
159   void setPhmLen(double phmLen) { m_dViewDiameter = phmLen * SQRT2; }
160
161   const std::string& getFilename() const {return m_filename;}
162   Array2dFileLabel& getLabel() {return m_label;}
163   const Array2dFileLabel& getLabel() const {return m_label;}
164
165   DetectorArray& getDetectorArray (const int iview)
166       { return (*m_projData[iview]); }
167   
168   const DetectorArray& getDetectorArray (const int iview) const
169       { return (*m_projData[iview]); }
170
171   static bool copyHeader (const char* const filename, std::ostream& os);
172   static bool copyHeader (const std::string& filename, std::ostream& os);
173
174   static bool copyViewData (const char* const filename, std::ostream& os, int startView, int endView);
175   static bool copyViewData (const std::string& filename, std::ostream& os, int startView, int endView);
176   
177  private:
178   int m_headerSize;             // Size of disk file header 
179   int m_geometry;               // Geometry of scanner 
180   class DetectorArray **m_projData;     // Pointer to array of detarray_st pointers 
181   std::string m_remark;         // description of raysum data 
182   int m_nDet;                   // number of detectors in array 
183   int m_nView;                  // number of rotated views 
184   double m_calcTime;            // time required to calculate raysums 
185   double m_rotStart;            // starting view rotation
186   double m_rotInc;              // angle between rotations 
187   double m_detStart;            // distance of beginning detector to center phantom
188   double m_detInc;              // increment between detectors 
189   double m_dFocalLength;
190   double m_dSourceDetectorLength;
191   double m_dViewDiameter;
192   double m_dFanBeamAngle;
193   kuint32 m_year;                   // Creation date & time
194   kuint32 m_month;
195   kuint32 m_day;
196   kuint32 m_hour;
197   kuint32 m_minute;
198   kuint32 m_second;
199   std::string m_filename;
200   Array2dFileLabel m_label;
201
202   const static kuint16 m_signature;
203
204   static const char* const s_aszInterpName[];
205   static const char* const s_aszInterpTitle[];
206   static const int s_iInterpCount;
207
208   bool headerWrite (fnetorderstream& fs);
209   bool headerRead (fnetorderstream& fs);
210   void newProjData ();
211   void deleteProjData ();
212
213   void init (const int nView, const int nDet);
214
215   // prevent default methods
216   Projections& operator= (const Projections& rhs);   // assignment
217   Projections(const Projections& rhs);               // copy
218 };
219
220
221 #endif