1 /*****************************************************************************
5 ** Purpose: Header file for Projections class
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: July 1, 1984
9 ** This is part of the CTSim program
10 ** Copyright (c) 1983-2009 Kevin Rosenberg
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.
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.
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 ******************************************************************************/
31 class Array2dFileLabel;
32 class fnetorderstream;
34 #include "array2dfile.h"
35 #include "imagefile.h"
40 //used for rebinning divergent beam projections to parallel
41 class ParallelRaysumCoordinate {
43 double m_dT; // Distance from center of origin
44 double m_dTheta; // perpendicular angle to origin
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; }
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; }
56 class ParallelRaysums {
60 THETA_RANGE_UNCONSTRAINED = 0,
61 THETA_RANGE_NORMALIZE_TO_TWOPI,
62 THETA_RANGE_FOLD_TO_PI,
65 ParallelRaysums (const Projections* pProjections, int iThetaRange);
68 typedef std::vector<ParallelRaysumCoordinate*> CoordinateContainer;
69 typedef CoordinateContainer::iterator CoordinateIterator;
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);
81 CoordinateContainer m_vecpCoordinates;
82 CoordinateContainer m_vecpSortedByT;
83 CoordinateContainer m_vecpSortedByTheta;
84 ParallelRaysumCoordinate* m_pCoordinates;
85 int m_iNumCoordinates;
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;
103 Projections (const int nView, const int nDet);
104 Projections (const Scanner& scanner);
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);
115 void initFromScanner (const Scanner& scanner);
116 bool initFromSomatomAR_STAR (int iNViews, int iNDets, unsigned char* pData, unsigned long lDataLength);
118 void printProjectionData (int startView, int endView);
119 void printProjectionData ();
120 void printScanInfo (std::ostringstream& os) const;
122 int Helical180LI(int interpView);
123 int Helical180LI_Equiangular(int interpView);
124 int HalfScanFeather(void);
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);
133 Projections* interpolateToParallel() const;
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,
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;
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());}
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; }
168 const std::string& getFilename() const {return m_filename;}
169 Array2dFileLabel& getLabel() {return m_label;}
170 const Array2dFileLabel& getLabel() const {return m_label;}
172 DetectorArray& getDetectorArray (const int iview)
173 { return (*m_projData[iview]); }
175 const DetectorArray& getDetectorArray (const int iview) const
176 { return (*m_projData[iview]); }
178 static bool copyHeader (const char* const filename, std::ostream& os);
179 static bool copyHeader (const std::string& filename, std::ostream& os);
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);
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
206 std::string m_filename;
207 Array2dFileLabel m_label;
209 const static kuint16 m_signature;
211 static const char* const s_aszInterpName[];
212 static const char* const s_aszInterpTitle[];
213 static const int s_iInterpCount;
215 bool headerWrite (fnetorderstream& fs);
216 bool headerRead (fnetorderstream& fs);
218 void deleteProjData ();
220 void init (const int nView, const int nDet);
222 // prevent default methods
223 Projections& operator= (const Projections& rhs); // assignment
224 Projections(const Projections& rhs); // copy