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-2001 Kevin Rosenberg
12 ** $Id: projections.h,v 1.36 2001/09/24 09:40:42 kevin Exp $
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.
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.
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 ******************************************************************************/
34 class Array2dFileLabel;
35 class fnetorderstream;
37 #include "array2dfile.h"
38 #include "imagefile.h"
43 //used for rebinning divergent beam projections to parallel
44 class ParallelRaysumCoordinate {
46 double m_dT; // Distance from center of origin
47 double m_dTheta; // perpendicular angle to origin
50 static bool compareByTheta (ParallelRaysumCoordinate* a, ParallelRaysumCoordinate* b)
51 { return a->m_dTheta == b->m_dTheta ? b->m_dT > a->m_dT : b->m_dTheta > a->m_dTheta; }
53 // sort first by T, then Theta
54 static bool compareByT (ParallelRaysumCoordinate* a, ParallelRaysumCoordinate* b)
55 { return a->m_dT == b->m_dT ? b->m_dTheta > a->m_dTheta : b->m_dT > a->m_dT; }
59 class ParallelRaysums {
63 THETA_RANGE_UNCONSTRAINED = 0,
64 THETA_RANGE_NORMALIZE_TO_TWOPI,
65 THETA_RANGE_FOLD_TO_PI,
68 ParallelRaysums (const Projections* pProjections, int iThetaRange);
71 typedef std::vector<ParallelRaysumCoordinate*> CoordinateContainer;
72 typedef CoordinateContainer::iterator CoordinateIterator;
74 CoordinateContainer& getCoordinates() {return m_vecpCoordinates;}
75 int getNumCoordinates() const {return m_iNumCoordinates;}
76 void getLimits (double* dMinT, double* dMaxT, double* dMinTheta, double* dMaxTheta) const;
77 CoordinateContainer& getSortedByT();
78 CoordinateContainer& getSortedByTheta();
79 double interpolate (double* pdX, double* pdY, int n, double dXValue, int* iLastFloor = NULL);
80 void getThetaAndRaysumsForT (int iT, double* pdTheta, double* pdRaysum);
81 void getDetPositions (double* pdDetPos);
84 CoordinateContainer m_vecpCoordinates;
85 CoordinateContainer m_vecpSortedByT;
86 CoordinateContainer m_vecpSortedByTheta;
87 ParallelRaysumCoordinate* m_pCoordinates;
88 int m_iNumCoordinates;
101 static const int POLAR_INTERP_INVALID;
102 static const int POLAR_INTERP_NEAREST;
103 static const int POLAR_INTERP_BILINEAR;
104 static const int POLAR_INTERP_BICUBIC;
106 Projections (const int nView, const int nDet);
107 Projections (const Scanner& scanner);
111 static const int getInterpCount() {return s_iInterpCount;}
112 static const char* const* getInterpNameArray() {return s_aszInterpName;}
113 static const char* const* getInterpTitleArray() {return s_aszInterpTitle;}
114 static int convertInterpNameToID (const char* const interpName);
115 static const char* convertInterpIDToName (const int interpID);
116 static const char* convertInterpIDToTitle (const int interpID);
118 void initFromScanner (const Scanner& scanner);
119 bool initFromSomatomAR_STAR (int iNViews, int iNDets, unsigned char* pData, unsigned long lDataLength);
121 void printProjectionData (int startView, int endView);
122 void printProjectionData ();
123 void printScanInfo (std::ostringstream& os) const;
125 int Helical180LI(int interpView);
126 int Helical180LI_Equiangular(int interpView);
127 int HalfScanFeather(void);
129 bool read (const std::string& fname);
130 bool read (const char* fname);
131 bool write (const char* fname);
132 bool write (const std::string& fname);
133 bool detarrayRead (fnetorderstream& fs, DetectorArray& darray, const int view_num);
134 bool detarrayWrite (fnetorderstream& fs, const DetectorArray& darray, const int view_num);
136 Projections* interpolateToParallel() const;
138 bool convertPolar (ImageFile& rIF, int iInterpolation);
139 bool convertFFTPolar (ImageFile& rIF, int iInterpolation, int iZeropad);
140 void calcArrayPolarCoordinates (unsigned int nx, unsigned int ny, double** ppdView, double** ppdDet,
141 int iNumDetWithZeros, double dZeropadRatio, double dDetInc);
142 void interpolatePolar (ImageFileArray& v, ImageFileArray& vImag, unsigned int nx, unsigned int ny, std::complex<double>** ppcDetValue,
143 double** ppdDet, double** ppdView, unsigned int nView, unsigned int nDet, unsigned int nDetWithZeros,
146 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;
148 void setNView (int nView); // used in MPI to restrict # of views
149 void setRotInc (double rotInc) { m_rotInc = rotInc;}
150 void setDetInc (double detInc) { m_detInc = detInc;}
151 void setCalcTime (double calcTime) {m_calcTime = calcTime;}
152 void setRemark (const char* remark) {m_remark = remark; m_label.setLabelString(remark);}
153 void setRemark (const std::string& remark) {setRemark(remark.c_str());}
155 double detStart() const {return m_detStart;}
156 double rotStart() const {return m_rotStart;}
157 double calcTime() const {return m_calcTime;}
158 double viewLen() const {return m_dViewDiameter / SQRT2;}
159 const char* remark() const {return m_remark.c_str();}
160 double detInc() const {return m_detInc;}
161 double rotInc() const {return m_rotInc;}
162 int nDet() const {return m_nDet;}
163 int nView() const {return m_nView;}
164 int geometry() const {return m_geometry;}
165 double focalLength() const {return m_dFocalLength;}
166 double sourceDetectorLength() const { return m_dSourceDetectorLength;}
167 double viewDiameter() const {return m_dViewDiameter; }
168 double phmLen() const { return m_dViewDiameter / SQRT2; }
169 void setPhmLen(double phmLen) { m_dViewDiameter = phmLen * SQRT2; }
171 const std::string& getFilename() const {return m_filename;}
172 Array2dFileLabel& getLabel() {return m_label;}
173 const Array2dFileLabel& getLabel() const {return m_label;}
175 DetectorArray& getDetectorArray (const int iview)
176 { return (*m_projData[iview]); }
178 const DetectorArray& getDetectorArray (const int iview) const
179 { return (*m_projData[iview]); }
181 static bool copyHeader (const char* const filename, std::ostream& os);
182 static bool copyHeader (const std::string& filename, std::ostream& os);
184 static bool copyViewData (const char* const filename, std::ostream& os, int startView, int endView);
185 static bool copyViewData (const std::string& filename, std::ostream& os, int startView, int endView);
188 int m_headerSize; // Size of disk file header
189 int m_geometry; // Geometry of scanner
190 class DetectorArray **m_projData; // Pointer to array of detarray_st pointers
191 std::string m_remark; // description of raysum data
192 int m_nDet; // number of detectors in array
193 int m_nView; // number of rotated views
194 double m_calcTime; // time required to calculate raysums
195 double m_rotStart; // starting view rotation
196 double m_rotInc; // angle between rotations
197 double m_detStart; // distance of beginning detector to center phantom
198 double m_detInc; // increment between detectors
199 double m_dFocalLength;
200 double m_dSourceDetectorLength;
201 double m_dViewDiameter;
202 double m_dFanBeamAngle;
203 kuint32 m_year; // Creation date & time
209 std::string m_filename;
210 Array2dFileLabel m_label;
212 const static kuint16 m_signature;
214 static const char* const s_aszInterpName[];
215 static const char* const s_aszInterpTitle[];
216 static const int s_iInterpCount;
218 bool headerWrite (fnetorderstream& fs);
219 bool headerRead (fnetorderstream& fs);
221 void deleteProjData ();
223 void init (const int nView, const int nDet);
225 // prevent default methods
226 Projections& operator= (const Projections& rhs); // assignment
227 Projections(const Projections& rhs); // copy