r156: *** empty log message ***
[ctsim.git] / include / phantom.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          phantom.h
5 **   Purpose:       Header file for Phantom objects
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: phantom.h,v 1.9 2000/07/20 11:17:31 kevin Exp $
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 #ifndef PHANTOM_H
29 #define PHANTOM_H
30
31 #include <slist>
32 using namespace std;
33
34 typedef enum {
35     PELEM_INVALID,
36     PELEM_RECTANGLE,
37     PELEM_TRIANGLE,
38     PELEM_ELLIPSE,
39     PELEM_SECTOR,
40     PELEM_SEGMENT
41 } PhmElemType;
42
43 /* Codes for Coordinate Types      */
44 /* Defines coords for isPointInside() */
45
46 typedef enum {
47   PELEM_COORD,         /* Normalized PElem Coordinates */
48   PHM_COORD           /* World phantom Coordinates */
49 } CoordType;
50
51
52 class PhantomElement
53 {
54  public:
55     PhantomElement (const char* const type, const double cx, const double cy, const double u, const double v, const double rot, const double atten);
56
57     ~PhantomElement (void);
58
59     bool isPointInside (double x, double y, const CoordType coord_type) const;
60
61     bool clipLineNormalizedCoords (double& x1, double& y1, double& x2, double& y2) const;
62  
63     bool clipLineWorldCoords (double& x1, double& y1, double& x2, double& y2) const;
64
65     const int nOutlinePoints(void) const {return m_nPoints;}
66     double* rectLimits(void) {return m_rectLimits;}
67     double* xOutline() {return m_xOutline;}
68     double* yOutline() {return m_yOutline;}
69     const double atten(void) const {return m_atten;}
70     const double diameter(void) const {return m_diameter;}
71     const double xmin(void) const {return m_xmin;}
72     const double xmax(void) const {return m_xmax;}
73     const double ymin(void) const {return m_ymin;}
74     const double ymax(void) const {return m_ymax;}
75     const double rot(void) const {return m_rot;}
76     const double cx(void) const {return m_cx;}
77     const double cy(void) const {return m_cy;}
78     const double u(void) const {return m_u;}
79     const double v(void) const {return m_v;}
80
81  private:
82     PhmElemType m_type;      // pelem type (box, ellipse, etc)
83     double m_cx, m_cy;       // center of pelem 
84     double m_u, m_v;                 // size of pelem 
85     double m_atten;          // X-ray attenuation coefficient
86     double m_rot;                    // pelem rotation angle (in radians) 
87     double *m_x, *m_y;       // ptr to array of points in obj world coord 
88     int m_nPoints;                   // number of points in outline arrays 
89     double m_xmin, m_xmax, m_ymin, m_ymax;  // pelem limits 
90     double m_diameter;       
91     GRFMTX_2D m_xformPhmToObj;        // map from phantom to normalized pelem coords
92     GRFMTX_2D m_xformObjToPhm;        // map from normalized pelem coords to phantom coords 
93     double* m_xOutline;
94     double* m_yOutline;
95     double  m_rectLimits[4];
96
97     static const int POINTS_PER_CIRCLE = 360;
98     static const double SCALE_PELEM_EXTENT=0.005;  // increase pelem limits by 0.5% 
99
100     static PhmElemType PhantomElement::convertNameToType (const char* const typeName);
101
102     void makeTransformMatrices (void);
103
104     void makeVectorOutline (void);
105
106     void calcArcPoints (double x[], double y[], const int pts, const double xcent, const double ycent, const double r, const double start, const double stop);
107
108     void calcEllipsePoints (double x[], double y[], const int pts, const double u, const double v);
109
110     static int numCirclePoints (double theta);
111
112     PhantomElement (const PhantomElement& rhs);        // copy constructor
113     PhantomElement& operator= (const PhantomElement&); // assignment operator
114 };
115
116
117 typedef enum {
118     P_PELEMS,        // Phantom made of PElems
119     P_UNIT_PULSE,   // Special phantom, not made of pelems 
120     P_FILTER      // defined only by this type
121 } PhantomComposition;
122
123 // Phantom class 
124
125 class Phantom
126 {
127  public:
128     typedef enum {
129       PHM_INVALID,
130       PHM_HERMAN,               /* Herman head phantom */
131       PHM_BHERMAN,              /* Bordered Herman head phantom */
132       PHM_ROWLAND,              /* Rowland head phantom */
133       PHM_BROWLAND,             /* Bordered Rowland head phantom */
134       PHM_UNITPULSE             /* Unit pulse phantom */
135     } PhantomID;
136
137     static const char PHM_HERMAN_STR[];
138     static const char PHM_BHERMAN_STR[];
139     static const char PHM_ROWLAND_STR[];
140     static const char PHM_BROWLAND_STR[];
141     static const char PHM_UNITPULSE_STR[];
142
143     static const char PHM_HERMAN_TITLE_STR[];
144     static const char PHM_BHERMAN_TITLE_STR[];
145     static const char PHM_ROWLAND_TITLE_STR[];
146     static const char PHM_BROWLAND_TITLE_STR[];
147     static const char PHM_UNITPULSE_TITLE_STR[];
148
149     Phantom (void);
150     Phantom (const char* const phmName);
151
152     ~Phantom (void);
153
154     void setComposition (PhantomComposition composition)
155         { m_composition = composition; }
156
157     const PhantomComposition getComposition (void) const
158         { return m_composition; }
159
160     bool createFromPhantom (const char* const phmName);
161
162     bool createFromPhantom (const PhantomID phmid);
163
164     bool createFromFile (const char* const fname);
165
166     void addPElem (const PhantomElement& pelem);
167
168     void addPElem (const char* const composition, const double cx, const double cy, const double u, const double v, const double rot, const double atten);
169
170     void convertToImagefile (ImageFile& im, const int in_nsample, const int trace, const int colStart, const int colCount) const;
171
172     void convertToImagefile (ImageFile& im, const int in_nsample, const int trace) const;
173
174     bool fail(void) const             {return m_fail;}
175     const string& failMessage(void) const {return m_failMessage;}
176     const string& name(void) const     {return m_name;}
177     const PhantomID id(void) const     {return m_id;}
178
179 #if HAVE_SGP
180     void show (void) const;
181     void draw (void) const;
182 #endif
183     
184     void addStdHerman (void);
185     void addStdHermanBordered (void);
186     void addStdRowland (void);
187     void addStdRowlandBordered (void);
188
189     void print (void) const;
190
191     const double maxAxisLength (void) const {return (((m_xmax - m_xmin) > (m_ymax - m_ymin)) ? (m_xmax - m_xmin) : (m_ymax - m_ymin));}
192
193     const double diameter(void) const {return m_diameter;}
194     const double xmin(void) const {return m_xmin;}
195     const double xmax(void) const {return m_xmax;}
196     const double ymin(void) const {return m_ymin;}
197     const double ymax(void) const {return m_ymax;}
198     slist<PhantomElement*>& listPElem(void) {return m_listPElem;}
199     const slist<PhantomElement*>& listPElem(void) const {return m_listPElem;}
200     const int nPElem(void) const {return m_nPElem;}
201
202  private:
203     PhantomComposition m_composition;
204     int m_nPElem;                           // number of pelems in phantom 
205     double m_xmin, m_xmax, m_ymin, m_ymax;  // extent of pelems in pelem coordinates
206     double m_diameter;                        // diameter of object
207     mutable slist<PhantomElement*> m_listPElem;      // pelem lists
208     string m_name;
209     PhantomID m_id;
210     bool m_fail;
211     string m_failMessage;
212
213     // Standard phantomsa
214     static PhantomID convertNameToPhantomID (const char* const phmName);
215     static const char* convertPhantomIDToName (const PhantomID phmID);
216
217     void init(void);
218
219     Phantom (const Phantom& rhs);        // copy constructor
220     Phantom& operator= (const Phantom&); // assignment operator
221 };
222
223 typedef slist<PhantomElement*>::iterator PElemIterator;
224 typedef slist<PhantomElement*>::const_iterator PElemConstIterator;
225
226 #endif