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-2009 Kevin Rosenberg
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License (version 2) as
14 ** published by the Free Software Foundation.
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ******************************************************************************/
30 #include "ctsupport.h"
41 /* Codes for Coordinate Types */
42 /* Defines coords for isPointInside() */
45 PELEM_COORD, /* Normalized PElem Coordinates */
46 PHM_COORD /* World phantom Coordinates */
53 PhantomElement (const char* const type, const double cx, const double cy, const double u, const double v, const double rot, const double atten);
57 bool isPointInside (double x, double y, const CoordType coord_type) const;
59 bool clipLineNormalizedCoords (double& x1, double& y1, double& x2, double& y2) const;
61 bool clipLineWorldCoords (double& x1, double& y1, double& x2, double& y2) const;
63 const int nOutlinePoints() const {return m_nPoints;}
64 double* rectLimits() {return m_rectLimits;}
65 double* xOutline() {return m_xOutline;}
66 double* yOutline() {return m_yOutline;}
67 double* const xOutline() const {return m_xOutline;}
68 double* const yOutline() const {return m_yOutline;}
69 const double atten() const {return m_atten;}
70 const double xmin() const {return m_xmin;}
71 const double xmax() const {return m_xmax;}
72 const double ymin() const {return m_ymin;}
73 const double ymax() const {return m_ymax;}
74 const double rot() const {return m_rot;}
75 const double cx() const {return m_cx;}
76 const double cy() const {return m_cy;}
77 const double u() const {return m_u;}
78 const double v() const {return m_v;}
80 static PhmElemType convertNameToType (const char* const typeName);
82 void printDefinition (std::ostream& os) const;
83 void printDefinition (std::ostringstream& 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
94 GRFMTX_2D m_xformPhmToObj; // map from phantom to normalized pelem coords
95 GRFMTX_2D m_xformObjToPhm; // map from normalized pelem coords to phantom coords
98 double m_rectLimits[4];
100 static const int POINTS_PER_CIRCLE;
101 static const double SCALE_PELEM_EXTENT; // increase pelem limits by 0.5%
103 static const char* const convertTypeToName (PhmElemType iType);
105 void makeTransformMatrices ();
106 void makeVectorOutline ();
107 void calcArcPoints (double x[], double y[], const int pts, const double xcent, const double ycent, const double r, const double start, const double stop);
108 void calcEllipsePoints (double x[], double y[], const int pts, const double u, const double v);
110 static int numCirclePoints (double theta);
112 PhantomElement (const PhantomElement& rhs); // copy constructor
113 PhantomElement& operator= (const PhantomElement&); // assignment operator
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;
124 //////////////////////////////////////////////////////
125 // Phantom Class Declaration
126 //////////////////////////////////////////////////////
133 static const int PHM_INVALID;
134 static const int PHM_HERMAN;
135 static const int PHM_SHEPP_LOGAN;
136 static const int PHM_UNITPULSE;
139 Phantom (const char* const phmName);
143 void setComposition (PhantomComposition composition)
144 { m_composition = composition; }
146 const PhantomComposition getComposition () const
147 { return m_composition; }
149 bool createFromPhantom (const char* const phmName);
150 bool createFromPhantom (const int phmid);
151 bool createFromPhmFile (const char* const fname);
152 bool createFromImageFile (const char* const fname);
153 bool fileWrite (const char* const fname);
155 void addPElem (const PhantomElement& pelem);
156 void addPElem (const char* const composition, const double cx, const double cy, const double u, const double v, const double rot, const double atten);
158 void convertToImagefile (ImageFile& im, double dViewRatio, const int in_nsample, const int trace) const;
159 void convertToImagefile (ImageFile& im, double dViewRatio, const int in_nsample, const int trace,
160 const int colStart, const int colCount, bool bStoreAtColumnPos) const;
161 void convertToImagefile (ImageFile& im, int iNX, double dViewRatio, const int in_nsample, const int trace,
162 const int colStart, const int colCount, int iStorageOffset) const;
164 void printDefinitions (std::ostream& os) const;
165 void printDefinitions (std::ostringstream& os) const;
167 bool fail() const {return m_fail;}
168 const std::string& failMessage() const {return m_failMessage;}
169 const std::string& name() const {return m_name;}
170 const int id() const {return m_id;}
174 void show (SGP& sgp) const;
175 void draw (SGP& sgp) const;
178 void addStdHerman ();
179 void addStdSheppLogan ();
181 void print (std::ostream& os) const;
182 void print (std::ostringstream& os) const;
184 double maxAxisLength () const
185 { return maxValue<double> (m_xmax - m_xmin, m_ymax - m_ymin); }
187 double getDiameterBoundaryCircle() const
188 { return SQRT2 * maxAxisLength(); }
190 const double xmin() const {return m_xmin;}
191 const double xmax() const {return m_xmax;}
192 const double ymin() const {return m_ymin;}
193 const double ymax() const {return m_ymax;}
194 std::list<PhantomElement*>& listPElem() {return m_listPElem;}
195 const std::list<PhantomElement*>& listPElem() const {return m_listPElem;}
196 const int nPElem() const {return m_nPElem;}
197 const bool isImagefile(void) const { return m_im != NULL; }
198 const ImageFile* getImagefile() const { return m_im; }
200 static const int getPhantomCount() {return s_iPhantomCount;}
201 static const char** getPhantomNameArray() {return s_aszPhantomName;}
202 static const char** getPhantomTitleArray() {return s_aszPhantomTitle;}
203 static int convertNameToPhantomID (const char* const phmName);
204 static const char* convertPhantomIDToName (const int phmID);
205 static const char* convertPhantomIDToTitle (const int phmID);
208 PhantomComposition m_composition;
209 int m_nPElem; // number of pelems in phantom
210 double m_xmin, m_xmax, m_ymin, m_ymax; // extent of pelems in pelem coordinates
211 mutable std::list<PhantomElement*> m_listPElem; // pelem lists
215 std::string m_failMessage;
216 static const char* s_aszPhantomName[];
217 static const char* s_aszPhantomTitle[];
218 static const int s_iPhantomCount;
219 ImageFile* m_im; // If defining a phantom from an ImageFile
223 Phantom (const Phantom& rhs); // copy constructor
224 Phantom& operator= (const Phantom&); // assignment operator
227 typedef std::list<PhantomElement*>::iterator PElemIterator;
228 typedef std::list<PhantomElement*>::const_iterator PElemConstIterator;