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.28 2001/03/10 23:14:15 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"
41 //used for rebinning divergent beam projections to parallel
42 class ParallelRaysumCoordinate {
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
49 bool lessThanT (ParallelRaysumCoordinate& rCompare)
50 {return m_dT < rCompare.m_dT; }
51 bool lessThanTheta (ParallelRaysumCoordinate& rCompare)
52 {return m_dTheta < rCompare.m_dTheta; }
55 class ParallelRaysums {
57 ParallelRaysumCoordinate** m_ppCoordinates;
58 int m_iNumCoordinates;
61 ParallelRaysums (Projections* pProjections);
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;
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;
81 Projections (const int nView, const int nDet);
82 Projections (const Scanner& scanner);
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);
93 void initFromScanner (const Scanner& scanner);
94 bool initFromSomatomAR_STAR (int iNViews, int iNDets, unsigned char* pData, unsigned long lDataLength);
96 void printProjectionData (int startView, int endView);
97 void printProjectionData ();
98 void printScanInfo (std::ostringstream& os) const;
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);
107 bool interpolateToParallel();
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);
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;
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());}
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;}
137 double phmLen() const { return m_dViewDiameter / SQRT2; }
138 void setPhmLen(double phmLen) { m_dViewDiameter = phmLen * SQRT2; }
140 const std::string& getFilename() const {return m_filename;}
141 Array2dFileLabel& getLabel() {return m_label;}
142 const Array2dFileLabel& getLabel() const {return m_label;}
144 DetectorArray& getDetectorArray (const int iview)
145 { return (*m_projData[iview]); }
147 const DetectorArray& getDetectorArray (const int iview) const
148 { return (*m_projData[iview]); }
150 static bool copyHeader (const char* const filename, std::ostream& os);
151 static bool copyHeader (const std::string& filename, std::ostream& os);
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);
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
178 std::string m_filename;
179 Array2dFileLabel m_label;
181 const static kuint16 m_signature;
183 static const char* const s_aszInterpName[];
184 static const char* const s_aszInterpTitle[];
185 static const int s_iInterpCount;
187 bool headerWrite (fnetorderstream& fs);
188 bool headerRead (fnetorderstream& fs);
190 void deleteProjData ();
192 void init (const int nView, const int nDet);
194 // prevent default methods
195 Projections& operator= (const Projections& rhs); // assignment
196 Projections(const Projections& rhs); // copy