1 /*****************************************************************************
5 ** Purpose: Header file for Phantom objects
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: July 1, 1984
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: phantom.h,v 1.18 2001/01/02 05:33:37 kevin Exp $
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.
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.
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 ******************************************************************************/
32 #include "ctsupport.h"
43 /* Codes for Coordinate Types */
44 /* Defines coords for isPointInside() */
47 PELEM_COORD, /* Normalized PElem Coordinates */
48 PHM_COORD /* World phantom Coordinates */
55 PhantomElement (const char* const type, const double cx, const double cy, const double u, const double v, const double rot, const double atten);
59 bool isPointInside (double x, double y, const CoordType coord_type) const;
61 bool clipLineNormalizedCoords (double& x1, double& y1, double& x2, double& y2) const;
63 bool clipLineWorldCoords (double& x1, double& y1, double& x2, double& y2) const;
65 const int nOutlinePoints() const {return m_nPoints;}
66 double* rectLimits() {return m_rectLimits;}
67 double* xOutline() {return m_xOutline;}
\r
68 double* yOutline() {return m_yOutline;}
\r
69 double* const xOutline() const {return m_xOutline;}
\r
70 double* const yOutline() const {return m_yOutline;}
\r
71 const double atten() const {return m_atten;}
72 const double diameter() const {return m_diameter;}
73 const double xmin() const {return m_xmin;}
74 const double xmax() const {return m_xmax;}
75 const double ymin() const {return m_ymin;}
76 const double ymax() const {return m_ymax;}
77 const double rot() const {return m_rot;}
78 const double cx() const {return m_cx;}
79 const double cy() const {return m_cy;}
80 const double u() const {return m_u;}
81 const double v() const {return m_v;}
\r
83 void printDefinition (std::ostream& os) const;
86 PhmElemType m_type; // pelem type (box, ellipse, etc)
87 double m_cx, m_cy; // center of pelem
88 double m_u, m_v; // size of pelem
89 double m_atten; // X-ray attenuation coefficient
90 double m_rot; // pelem rotation angle (in radians)
91 double *m_x, *m_y; // ptr to array of points in obj world coord
92 int m_nPoints; // number of points in outline arrays
93 double m_xmin, m_xmax, m_ymin, m_ymax; // pelem limits
95 GRFMTX_2D m_xformPhmToObj; // map from phantom to normalized pelem coords
96 GRFMTX_2D m_xformObjToPhm; // map from normalized pelem coords to phantom coords
99 double m_rectLimits[4];
101 static const int POINTS_PER_CIRCLE;
102 static const double SCALE_PELEM_EXTENT; // increase pelem limits by 0.5%
104 static PhmElemType convertNameToType (const char* const typeName);
105 static const char* const convertTypeToName (PhmElemType iType);
\r
107 void makeTransformMatrices ();
109 void makeVectorOutline ();
111 void calcArcPoints (double x[], double y[], const int pts, const double xcent, const double ycent, const double r, const double start, const double stop);
113 void calcEllipsePoints (double x[], double y[], const int pts, const double u, const double v);
115 static int numCirclePoints (double theta);
117 PhantomElement (const PhantomElement& rhs); // copy constructor
118 PhantomElement& operator= (const PhantomElement&); // assignment operator
123 P_PELEMS, // Phantom made of PElems
124 P_UNIT_PULSE, // Special phantom, not made of pelems
125 P_FILTER // defined only by this type
126 } PhantomComposition;
129 //////////////////////////////////////////////////////
130 // Phantom Class Declaration
131 //////////////////////////////////////////////////////
138 static const int PHM_INVALID;
139 static const int PHM_HERMAN;
140 static const int PHM_B_HERMAN;
141 static const int PHM_SHEPP_LOGAN;
142 static const int PHM_B_SHEPP_LOGAN;
143 static const int PHM_UNITPULSE;
146 Phantom (const char* const phmName);
150 void setComposition (PhantomComposition composition)
151 { m_composition = composition; }
153 const PhantomComposition getComposition () const
154 { return m_composition; }
156 bool createFromPhantom (const char* const phmName);
158 bool createFromPhantom (const int phmid);
160 bool createFromFile (const char* const fname);
162 bool fileWrite (const char* const fname);
\r
164 void addPElem (const PhantomElement& pelem);
166 void addPElem (const char* const composition, const double cx, const double cy, const double u, const double v, const double rot, const double atten);
168 void convertToImagefile (ImageFile& im, const int in_nsample, const int trace, const int colStart, const int colCount, bool bStoreAtColumnPos) const;
170 void convertToImagefile (ImageFile& im, const int in_nsample, const int trace) const;
172 void printDefinitions (std::ostream& os) const;
\r
174 bool fail() const {return m_fail;}
175 const std::string& failMessage() const {return m_failMessage;}
176 const std::string& name() const {return m_name;}
177 const int id() const {return m_id;}
181 void show (SGP& sgp) const;
182 void draw (SGP& sgp) const;
185 void addStdHerman ();
186 void addStdHermanBordered ();
187 void addStdSheppLogan ();
188 void addStdSheppLoganBordered ();
190 void print (std::ostream& os) const;
192 const double maxAxisLength () const {return (((m_xmax - m_xmin) > (m_ymax - m_ymin)) ? (m_xmax - m_xmin) : (m_ymax - m_ymin));}
194 const double diameter() const {return m_diameter;}
195 const double xmin() const {return m_xmin;}
196 const double xmax() const {return m_xmax;}
197 const double ymin() const {return m_ymin;}
198 const double ymax() const {return m_ymax;}
199 std::list<PhantomElement*>& listPElem() {return m_listPElem;}
200 const std::list<PhantomElement*>& listPElem() const {return m_listPElem;}
201 const int nPElem() const {return m_nPElem;}
203 static const int getPhantomCount() {return s_iPhantomCount;}
204 static const char** getPhantomNameArray() {return s_aszPhantomName;}
205 static const char** getPhantomTitleArray() {return s_aszPhantomTitle;}
206 static int convertNameToPhantomID (const char* const phmName);
207 static const char* convertPhantomIDToName (const int phmID);
208 static const char* convertPhantomIDToTitle (const int phmID);
211 PhantomComposition m_composition;
212 int m_nPElem; // number of pelems in phantom
213 double m_xmin, m_xmax, m_ymin, m_ymax; // extent of pelems in pelem coordinates
214 double m_diameter; // diameter of object
215 mutable std::list<PhantomElement*> m_listPElem; // pelem lists
219 std::string m_failMessage;
221 static const char* s_aszPhantomName[];
222 static const char* s_aszPhantomTitle[];
223 static const int s_iPhantomCount;
227 Phantom (const Phantom& rhs); // copy constructor
228 Phantom& operator= (const Phantom&); // assignment operator
231 typedef std::list<PhantomElement*>::iterator PElemIterator;
232 typedef std::list<PhantomElement*>::const_iterator PElemConstIterator;