r5231: Auto commit for Debian build
[ctsim.git] / include / scanner.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          scanner.h
5 **   Purpose:       Scanner header file
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  July 1, 1984
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: scanner.h,v 1.24 2003/07/04 21:39:39 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 SCANNER_H
30 #define SCANNER_H
31
32 #include "trace.h"
33
34 class Projections;
35 class Phantom;
36 class PhantomElement;
37 class SGP;
38
39 // Projections are collected along an array of ndet detectors.  The data
40 // for these detectors is stored in the class DetectorArray
41
42 typedef float DetectorValue;
43
44 class DetectorArray
45 {
46  public:
47   DetectorArray (const int ndet);
48   ~DetectorArray ();
49
50   const int nDet() const {return m_nDet;}
51   const double viewAngle() const {return m_viewAngle;}
52   DetectorValue* detValues() {return m_detValues;}
53   const DetectorValue* detValues() const {return m_detValues;}
54
55   void setViewAngle (double viewAngle)
56       { m_viewAngle = viewAngle; }
57
58  private:
59   DetectorValue* m_detValues;   // Pointer to array of values recorded by detector 
60   int m_nDet;                   // Number of detectors in array */
61   double m_viewAngle;           // View angle in radians 
62
63   DetectorArray& operator=(const DetectorArray& rhs);   // assignment
64   DetectorArray (const DetectorArray& rhs);             // copy constructor
65 };
66
67
68 class Scanner
69 {
70  public:
71   static const int Scanner::GEOMETRY_INVALID;
72   static const int Scanner::GEOMETRY_PARALLEL;
73   static const int Scanner::GEOMETRY_EQUILINEAR;
74   static const int Scanner::GEOMETRY_EQUIANGULAR;
75   static const int Scanner::GEOMETRY_LINOGRAM;
76
77   
78   Scanner (const Phantom& phm, const char* const geometryName, int nDet, 
79     int nView, int iOffsetView, int nSample, const double rot_anglen, 
80     double dFocalLengthRatio, double dCenterDetectorRatio, double dViewRatio, double dScanRatio);
81   ~Scanner();
82   
83   void collectProjections (Projections& proj, const Phantom& phm, const int trace = Trace::TRACE_NONE,
84     SGP* pSGP = NULL);
85
86   void collectProjections (Projections& proj, const Phantom& phm, const int iStartView, const int iNumViews, const int iOffsetView, bool bStoreAtViewPosition, const int trace = Trace::TRACE_NONE, SGP* pSGP = NULL);
87
88   void collectProjections (Projections& proj, const Phantom& phm, const int iStartView, const int iNumViews, const int iOffsetView, int iStorageOffset, const int trace = Trace::TRACE_NONE, SGP* pSGP = NULL);
89
90   void setNView (int nView);
91   void setOffsetView (int iOffsetView);
92
93   bool fail() const {return m_fail;}
94   const std::string& failMessage() const {return m_failMessage;}
95   unsigned int nDet() const {return m_nDet;}
96   unsigned int nView() const {return m_nView;}
97   unsigned int offsetView() const {return m_iOffsetView;}
98   unsigned int startView() const {return m_startView;} 
99   double rotInc() const {return m_rotInc;}
100   double detInc() const {return m_detInc;}
101   double detLen() const {return m_detLen;}
102   double detStart() const {return m_detStart;}
103   double focalLength() const {return m_dFocalLength;}
104   double sourceDetectorLength() const {return m_dSourceDetectorLength;}
105   double centerDetectorLength() const {return m_dCenterDetectorLength;}
106
107   double viewDiameter() const {return m_dViewDiameter;}
108   double scanDiameter() const {return m_dScanDiameter;}
109   double fanBeamAngle() const {return m_dFanBeamAngle;}
110
111   int geometry() const {return m_idGeometry;}
112
113   static int getGeometryCount() {return s_iGeometryCount;}
114   static const char* const* getGeometryNameArray() {return s_aszGeometryName;}
115   static const char* const* getGeometryTitleArray() {return s_aszGeometryTitle;}
116   static int convertGeometryNameToID (const char* const geometryName);
117   static const char* convertGeometryIDToName (const int idGeometry);
118   static const char* convertGeometryIDToTitle (const int idGeometry);
119   
120  private:
121   bool m_fail;
122   std::string m_failMessage;
123   int m_idGeometry;
124   unsigned int m_nDet;          /* Number of detectors in array */
125   unsigned int m_nView;         /* Number of rotated views */
126   unsigned int m_iOffsetView; 
127   unsigned int m_startView; 
128   unsigned int m_nSample;       /* Number of rays per detector */
129   double m_dFocalLength;        // Focal Length, distance from source to center
130   double m_dSourceDetectorLength; // Distance from source to detectors
131   double m_dCenterDetectorLength; // Distance from center to detectors
132   double m_dViewDiameter; // Diameter of area being processed
133   double m_dScanDiameter; // Diamer of area being scanned
134   double m_dViewRatio;   // View Ratio to diameter phantom
135   double m_dFocalLengthRatio;   // Source to Center Length as ratio to viewDiameter radius 
136   double m_dCenterDetectorRatio; // Center to Detector Length as ratio of viewDiameter radius
137   double m_dScanRatio;       // Scan length to view length ratio
138   double m_dFanBeamAngle;
139   double m_detLen;              // Total length of detector array 
140   double m_rotLen;              // Rotation angle length in radians (norm 2PI)
141   double m_detInc;              // Increment between centers of detectors 
142   double m_rotInc;              // Increment in rotation angle between views 
143   double m_detStart;
144   double m_dXCenter;            // Center of Phantom
145   double m_dYCenter;            
146   double m_dAngularDetIncrement;
147   double m_dAngularDetLen;
148
149   int m_trace;
150   struct {
151     double xd1,yd1,xd2,yd2;     /* Coordinates of detector endpoints */
152     double xs1,ys1,xs2,ys2;     /* Coordinates of source endpoints */
153     double angle;               /* Starting angle */
154     double dAngularDet;
155   } m_initPos;
156
157   GRFMTX_2D m_rotmtxIncrement;
158
159 #ifdef HAVE_SGP
160   SGP* m_pSGP;                  // Pointer to graphics device
161   double m_dXMinWin;            // Extent of graphics window
162   double m_dXMaxWin;
163   double m_dYMinWin;
164   double m_dYMaxWin;
165   double m_dTextHeight;
166 #endif
167
168   static const char* const s_aszGeometryName[];
169   static const char* const s_aszGeometryTitle[];
170   static const int s_iGeometryCount;
171
172   void projectSingleView (const Phantom& phm, DetectorArray& darray, const double xd1, const double yd1, const double xd2, const double yd2, const double xs1, const double ys1, const double xs2, const double ys2, const double dDetAngle);
173
174   double projectSingleLine (const Phantom& phm, const double x1, const double y1, const double x2, const double y2);
175
176   double projectLineAgainstPElem (const PhantomElement& pelem, const double x1, const double y1, const double x2, const double y2);
177
178   void traceShowParam (const char* szLabel, const char *fmt, int row, int color, ...);
179   void traceShowParamXOR (const char* szLabel, const char *fmt, int row, int color, ...);
180   void traceShowParamRasterOp (int iRasterOp, const char* szLabel, const char* fmt, int row, int color, va_list va);
181
182
183 };
184
185 const static int PROJECTION_TRACE_ROW_PHANT_ID=0;
186 const static int PROJECTION_TRACE_ROW_GEOMETRY=1;
187 const static int PROJECTION_TRACE_ROW_FOCAL_LENGTH=2;
188 const static int PROJECTION_TRACE_ROW_FIELD_OF_VIEW=3;
189 const static int PROJECTION_TRACE_ROW_NDET=4;
190 const static int PROJECTION_TRACE_ROW_NVIEW=5;
191 const static int PROJECTION_TRACE_ROW_SAMPLES=6;
192 const static int PROJECTION_TRACE_ROW_CURR_VIEW=7;
193 const static int PROJECTION_TRACE_ROW_ATTEN=8;
194
195
196
197 #endif