r186: *** empty log message ***
[ctsim.git] / libctsim / scanner.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          scanner.cpp
5 **   Purpose:       Classes for CT scanner
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  1984
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: scanner.cpp,v 1.13 2000/08/31 08:38:58 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 #include "ct.h"
29
30
31 const int Scanner::GEOMETRY_INVALID = -1;
32 const int Scanner::GEOMETRY_PARALLEL = 0;
33 const int Scanner::GEOMETRY_EQUIANGULAR = 1;
34 const int Scanner::GEOMETRY_EQUILINEAR = 2;
35
36 const char* Scanner::s_aszGeometryName[] = 
37 {
38   {"parallel"},
39   {"equiangular"},
40   {"equilinear"},
41 };
42
43 const char* Scanner::s_aszGeometryTitle[] = 
44 {
45   {"Parallel"},
46   {"Equiangular"},
47   {"Equilinear"},
48 };
49
50 const int Scanner::s_iGeometryCount = sizeof(s_aszGeometryName) / sizeof(const char*);
51
52
53 // NAME
54 //   DetectorArray       Construct a DetectorArray
55
56 DetectorArray::DetectorArray (const int nDet)
57 {
58   m_nDet = nDet;
59   m_detValues = new DetectorValue [m_nDet];
60 }
61
62
63 // NAME
64 //   ~DetectorArray             Free memory allocated to a detector array
65
66 DetectorArray::~DetectorArray (void)
67 {
68   delete [] m_detValues;
69 }
70
71
72
73 /* NAME
74  *   Scanner::Scanner           Construct a user specified detector structure
75  *
76  * SYNOPSIS
77  *   Scanner (phm, nDet, nView, nSample)
78  *   Phantom& phm               PHANTOM that we are making detector for
79  *   int geomety                Geometry of detector
80  *   int nDet                   Number of detector along detector array
81  *   int nView                  Number of rotated views
82  *   int nSample                Number of rays per detector
83  */
84
85 Scanner::Scanner (const Phantom& phm, const char* const geometryName, int nDet, int nView, int nSample, const double rot_anglen, const double dFocalLengthRatio, const double dFieldOfViewRatio)
86 {
87   m_phmLen = phm.maxAxisLength();      // maximal length along an axis
88
89   m_fail = false;
90   m_idGeometry = convertGeometryNameToID (geometryName);
91   if (m_idGeometry == GEOMETRY_INVALID) {
92     m_fail = true;
93     m_failMessage = "Invalid geometry name ";
94     m_failMessage += geometryName;
95     return;
96   }
97
98   if (nView < 1)
99     nView = 1;
100   if (nSample < 1)
101     m_nSample = 1;
102   if (nDet < 1)
103     nDet = 1;
104
105   m_nDet     = nDet;
106   m_nView    = nView;
107   m_nSample  = nSample;
108   m_dFocalLengthRatio = dFocalLengthRatio;
109   m_dFieldOfViewRatio = dFieldOfViewRatio;
110   m_dFocalLength = (m_phmLen * SQRT2 / 2) * dFocalLengthRatio;
111   m_dFieldOfView = m_phmLen * SQRT2 * dFieldOfViewRatio;
112
113   m_dXCenter = phm.xmin() + (phm.xmax() - phm.xmin()) / 2;
114   m_dYCenter = phm.ymin() + (phm.ymax() - phm.ymin()) / 2;
115   m_rotLen  = rot_anglen;
116   m_rotInc  = m_rotLen / m_nView;
117   if (m_idGeometry == GEOMETRY_PARALLEL) {
118     m_detLen   = m_dFieldOfView;
119     m_detInc  = m_detLen / m_nDet;
120     
121     double dHalfDetLen = m_detLen / 2;
122     m_initPos.xs1 = m_dXCenter - m_dFocalLength;
123     m_initPos.ys1 = m_dYCenter + dHalfDetLen;
124     m_initPos.xs2 = m_dXCenter + m_dFocalLength;
125     m_initPos.ys2 = m_dYCenter + dHalfDetLen;
126     m_initPos.xd1 = m_dXCenter - m_dFocalLength;
127     m_initPos.yd1 = m_dYCenter - dHalfDetLen;
128     m_initPos.xd2 = m_dXCenter + m_dFocalLength;
129     m_initPos.yd2 = m_dYCenter - dHalfDetLen;
130     m_initPos.angle = 0.0;
131   } else if (m_idGeometry == GEOMETRY_EQUILINEAR) {
132 #if 0
133     double dAngle = (m_dFieldOfView / 2) / cos (asin (m_dFieldOfView / 2 / m_dFocalLength));
134 #else
135     double dHalfSquare = m_dFieldOfView / SQRT2 / 2;
136     double dFocalPastPhm = m_dFocalLength - dHalfSquare;
137     if (dFocalPastPhm <= 0.) {
138       m_fail = true;
139       m_failMessage = "Focal Point inside of phantom";
140       return;
141     }
142     double dAngle = atan( dHalfSquare / dFocalPastPhm );
143 #endif
144     double dHalfDetLen = 2 * m_dFocalLength * tan (dAngle);
145
146     m_detLen = dHalfDetLen * 2;
147     m_detInc  = m_detLen / m_nDet;
148     
149     m_initPos.angle = 0.0;
150     m_initPos.xs1 = m_dXCenter;
151     m_initPos.ys1 = m_dYCenter + m_dFocalLength;
152     m_initPos.xs2 = m_dXCenter;
153     m_initPos.ys2 = m_dYCenter + m_dFocalLength;
154     m_initPos.xd1 = m_dXCenter - dHalfDetLen;
155     m_initPos.yd1 = m_dYCenter - m_dFocalLength;
156     m_initPos.xd2 = m_dXCenter + dHalfDetLen;
157     m_initPos.yd2 = m_dYCenter - m_dFocalLength;
158     m_initPos.angle = 0.0;
159   } else if (m_idGeometry == GEOMETRY_EQUIANGULAR) {
160 #if 0
161     double dAngle = atan ((m_dFieldOfView / 2) / m_dFocalLength);
162 #else
163     double dHalfSquare = m_dFieldOfView / SQRT2 / 2;
164     double dFocalPastPhm = m_dFocalLength - dHalfSquare;
165     if (dFocalPastPhm <= 0.) {
166       m_fail = true;
167       m_failMessage = "Focal Point inside of phantom";
168       return;
169     }
170     double dAngle =  atan ( dHalfSquare / dFocalPastPhm ); 
171 #endif
172     m_detLen = 2 * dAngle;
173     m_detInc = m_detLen / m_nDet;
174
175     m_dAngularDetIncrement = m_detInc * 2; // Angular Position 2x gamma angle
176     m_dAngularDetLen = m_detLen * 2;
177     m_initPos.dAngularDet = -m_dAngularDetLen / 2;
178
179     m_initPos.angle = 0;
180     m_initPos.xs1 = m_dXCenter;
181     m_initPos.ys1 = m_dYCenter + m_dFocalLength;;
182     m_initPos.xs2 = m_dXCenter;
183     m_initPos.ys2 = m_dYCenter + m_dFocalLength;
184   }
185
186   // Calculate incrementatal rotation matrix 
187   GRFMTX_2D temp;
188   xlat_mtx2 (m_rotmtxIncrement, -m_dXCenter, -m_dYCenter);
189   rot_mtx2 (temp, m_rotInc);
190   mult_mtx2 (m_rotmtxIncrement, temp, m_rotmtxIncrement);
191   xlat_mtx2 (temp, m_dXCenter, m_dYCenter);
192   mult_mtx2 (m_rotmtxIncrement, temp, m_rotmtxIncrement);
193   
194 }
195
196 Scanner::~Scanner (void)
197 {
198 }
199
200
201 const char*
202 Scanner::convertGeometryIDToName (const int geomID)
203 {
204   const char *name = "";
205
206   if (geomID >= 0 && geomID < s_iGeometryCount)
207       return (s_aszGeometryName[geomID]);
208
209   return (name);
210 }
211
212 const char*
213 Scanner::convertGeometryIDToTitle (const int geomID)
214 {
215   const char *title = "";
216
217   if (geomID >= 0 && geomID < s_iGeometryCount)
218       return (s_aszGeometryName[geomID]);
219
220   return (title);
221 }
222       
223 int
224 Scanner::convertGeometryNameToID (const char* const geomName) 
225 {
226   int id = GEOMETRY_INVALID;
227
228   for (int i = 0; i < s_iGeometryCount; i++)
229       if (strcasecmp (geomName, s_aszGeometryName[i]) == 0) {
230           id = i;
231           break;
232       }
233
234   return (id);
235 }
236   
237
238 /* NAME
239  *   collectProjections         Calculate projections for a Phantom
240  *
241  * SYNOPSIS
242  *   collectProjections (proj, phm, start_view, nView, bStoreViewPos, trace)
243  *   Projectrions& proj      Projection storage
244  *   Phantom& phm            Phantom for which we collect projections
245  *   bool bStoreViewPos      TRUE then storage proj at normal view position
246  *   int trace               Trace level
247 */
248
249
250 void
251 Scanner::collectProjections (Projections& proj, const Phantom& phm, const int trace, SGP* pSGP)
252 {
253   collectProjections (proj, phm, 0, proj.nView(), true, trace, pSGP);
254 }
255
256 void
257 Scanner::collectProjections (Projections& proj, const Phantom& phm, const int iStartView, const int iNumViews, bool bStoreAtViewPosition, const int trace, SGP* pSGP)
258 {
259   m_trace = trace;
260   double start_angle = iStartView * proj.rotInc();
261
262   // Calculate initial rotation matrix 
263   GRFMTX_2D rotmtx_initial, temp;
264   xlat_mtx2 (rotmtx_initial, -m_dXCenter, -m_dYCenter);
265   rot_mtx2 (temp, start_angle);
266   mult_mtx2 (rotmtx_initial, temp, rotmtx_initial);
267   xlat_mtx2 (temp, m_dXCenter, m_dYCenter);
268   mult_mtx2 (rotmtx_initial, temp, rotmtx_initial);
269
270   double xd1=0, yd1=0, xd2=0, yd2=0;
271   if (m_idGeometry != GEOMETRY_EQUIANGULAR) {
272       xd1 = m_initPos.xd1;
273       yd1 = m_initPos.yd1;
274       xd2 = m_initPos.xd2;
275       yd2 = m_initPos.yd2;
276       xform_mtx2 (rotmtx_initial, xd1, yd1);      // rotate detector endpoints 
277       xform_mtx2 (rotmtx_initial, xd2, yd2);      // to initial view_angle 
278   }
279   
280   double xs1 = m_initPos.xs1;
281   double ys1 = m_initPos.ys1;
282   double xs2 = m_initPos.xs2;
283   double ys2 = m_initPos.ys2;
284   xform_mtx2 (rotmtx_initial, xs1, ys1);      // rotate source endpoints to
285   xform_mtx2 (rotmtx_initial, xs2, ys2);      // initial view angle
286
287   int iView;
288   double viewAngle;
289   for (iView = 0, viewAngle = start_angle;  iView < iNumViews; iView++, viewAngle += proj.rotInc()) {
290     int iStoragePosition = iView;
291     if (bStoreAtViewPosition)
292       iStoragePosition += iStartView;
293
294     DetectorArray& detArray = proj.getDetectorArray( iStoragePosition );
295
296 #ifdef HAVE_SGP 
297   if (pSGP && m_trace >= Trace::TRACE_PHANTOM) {
298       m_pSGP = pSGP;
299       m_pSGP->eraseWindow();
300       double dWindowSize = max(m_detLen, m_dFocalLength * 2) * SQRT2;
301       double dHalfWindowSize = dWindowSize / 2;
302       m_dXMinWin = m_dXCenter - dHalfWindowSize;
303       m_dXMaxWin = m_dXCenter + dHalfWindowSize;
304       m_dYMinWin = m_dYCenter - dHalfWindowSize;
305       m_dYMaxWin = m_dYCenter + dHalfWindowSize;
306       double dHalfPhmLen = m_phmLen /  2;
307
308     m_pSGP->eraseWindow ();
309     m_pSGP->setWindow (m_dXMinWin, m_dYMinWin, m_dXMaxWin, m_dYMaxWin);
310     m_pSGP->setRasterOp (RO_COPY);
311     m_pSGP->setColor (C_RED);
312     m_pSGP->moveAbs (0., 0.);
313     m_pSGP->drawRect (m_dXCenter - dHalfPhmLen, m_dYCenter - dHalfPhmLen, m_dXCenter + dHalfPhmLen, m_dYCenter + dHalfPhmLen);
314     m_pSGP->moveAbs (0., 0.);
315     m_pSGP->drawCircle (m_dFocalLength);
316     m_pSGP->setColor (C_BLUE);
317     phm.draw (*m_pSGP);
318     m_dTextHeight = m_pSGP->getCharHeight ();
319
320     traceShowParam ("Projection Collector", "%s", PROJECTION_TRACE_ROW_TITLE, C_BLACK, " ");
321     traceShowParam ("________________", "%s", PROJECTION_TRACE_ROW_TITLE2, C_LTGRAY, " ");
322     traceShowParam ("Phantom:",       "%s", PROJECTION_TRACE_ROW_PHANT_ID, C_BLACK, phm.name().c_str());
323     traceShowParam ("Geometry:", "%s", PROJECTION_TRACE_ROW_GEOMETRY, C_BLUE, convertGeometryIDToName(m_idGeometry));
324     traceShowParam ("Focal Length Ratio:", "%.2f", PROJECTION_TRACE_ROW_FOCAL_LENGTH, C_BLUE, m_dFocalLengthRatio);
325     traceShowParam ("Field Of View Ratio:", "%.2f", PROJECTION_TRACE_ROW_FIELD_OF_VIEW, C_BLUE, m_dFieldOfViewRatio);
326     traceShowParam ("Num Detectors:", "%d", PROJECTION_TRACE_ROW_NDET, C_BLUE, proj.nDet());
327     traceShowParam ("Num Views:", "%d", PROJECTION_TRACE_ROW_NVIEW, C_BLUE, proj.nView());
328     traceShowParam ("Samples / Ray:", "%d", PROJECTION_TRACE_ROW_SAMPLES, C_BLUE, m_nSample);
329     
330     m_pSGP->setMarker (SGP::MARK_BDIAMOND, C_LTGREEN);
331   }
332 #endif
333
334 #ifdef HAVE_SGP
335     if (m_pSGP && m_trace >= Trace::TRACE_PHANTOM) {
336       m_pSGP->setColor (C_BLACK);
337       m_pSGP->setPenWidth (2);
338       if (m_idGeometry == GEOMETRY_PARALLEL) {
339         m_pSGP->moveAbs (xs1, ys1);
340         m_pSGP->lineAbs (xs2, ys2);
341         m_pSGP->moveAbs (xd1, yd1);
342         m_pSGP->lineAbs (xd2, yd2);
343       } else if (m_idGeometry == GEOMETRY_EQUILINEAR) { 
344         m_pSGP->setPenWidth (4);
345         m_pSGP->moveAbs (xs1, ys1);
346         m_pSGP->lineAbs (xs2, ys2);
347         m_pSGP->setPenWidth (2);
348         m_pSGP->moveAbs (xd1, yd1);
349         m_pSGP->lineAbs (xd2, yd2);
350       } else if (m_idGeometry == GEOMETRY_EQUIANGULAR) {
351         m_pSGP->setPenWidth (4);
352         m_pSGP->moveAbs (xs1, ys1);
353         m_pSGP->lineAbs (xs2, ys2);
354         m_pSGP->setPenWidth (2);
355         m_pSGP->moveAbs (0., 0.);
356         m_pSGP->drawArc (m_dFocalLength, viewAngle + 3 * HALFPI - (m_dAngularDetLen/2), viewAngle + 3 * HALFPI + (m_dAngularDetLen/2));
357       }
358       m_pSGP->setPenWidth (1);
359     }
360     if (m_trace >= Trace::TRACE_CONSOLE)
361       traceShowParam ("Current View:", "%d (%.0f%%)", PROJECTION_TRACE_ROW_CURR_VIEW, C_RED, iView + iStartView, (iView + iStartView) / static_cast<double>(m_nView) * 100.);
362 #endif
363             
364     projectSingleView (phm, detArray, xd1, yd1, xd2, yd2, xs1, ys1, xs2, ys2, viewAngle + 3 * HALFPI);
365     detArray.setViewAngle (viewAngle);
366       
367 #ifdef HAVE_SGP
368     if (m_pSGP && m_trace >= Trace::TRACE_PHANTOM) {
369       //        rs_plot (detArray, xd1, yd1, dXCenter, dYCenter, theta);
370     }
371 #endif
372     xform_mtx2 (m_rotmtxIncrement, xs1, ys1);
373     xform_mtx2 (m_rotmtxIncrement, xs2, ys2);
374     if (m_idGeometry != GEOMETRY_EQUIANGULAR) {
375         xform_mtx2 (m_rotmtxIncrement, xd1, yd1);  // rotate detector endpoints 
376         xform_mtx2 (m_rotmtxIncrement, xd2, yd2);
377     }
378   } /* for each iView */
379 }
380
381
382 /* NAME
383  *    rayview                   Calculate raysums for a view at any angle
384  *
385  * SYNOPSIS
386  *    rayview (phm, detArray, xd1, nSample, yd1, xd2, yd2, xs1, ys1, xs2, ys2)
387  *    Phantom& phm              Phantom to scan
388  *    DETARRAY *detArray                Storage of values for detector array
389  *    Scanner& det              Scanner parameters
390  *    double xd1, yd1, xd2, yd2 Beginning & ending detector positions
391  *    double xs1, ys1, xs2, ys2 Beginning & ending source positions
392  *
393  * RAY POSITIONING
394  *         For each detector, have there are a variable number of rays traced.
395  *     The source of each ray is the center of the source x-ray cell. The
396  *     detector positions are equally spaced within the cell
397  *
398  *         The increments between rays are calculated so that the cells start
399  *     at the beginning of a detector cell and they end on the endpoint
400  *     of the cell.  Thus, the last cell starts at (xd2-ddx),(yd2-ddy).
401  *         The exception to this is if there is only one ray per detector.
402  *     In that case, the detector position is the center of the detector cell.
403  */
404
405 void 
406 Scanner::projectSingleView (const Phantom& phm, DetectorArray& detArray, 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)
407 {
408
409   double sdx = (xs2 - xs1) / detArray.nDet();  // change in coords 
410   double sdy = (ys2 - ys1) / detArray.nDet();  // between source
411   double xs_maj = xs1 + (sdx / 2);      // put ray source in center of cell 
412   double ys_maj = ys1 + (sdy / 2);
413
414   double ddx=0, ddy=0, ddx2=0, ddy2=0, ddx2_ofs=0, ddy2_ofs=0, xd_maj=0, yd_maj=0;
415   double dAngleInc=0, dAngleSampleInc=0, dAngleSampleOffset=0, dAngleMajor=0;
416   if (m_idGeometry == GEOMETRY_EQUIANGULAR) {
417       dAngleInc = m_dAngularDetIncrement;
418       dAngleSampleInc = dAngleInc / m_nSample;
419       dAngleSampleOffset = dAngleSampleInc / 2;
420       dAngleMajor = dDetAngle - (m_dAngularDetLen/2) + dAngleSampleOffset;
421   } else {
422       ddx = (xd2 - xd1) / detArray.nDet();  // change in coords 
423       ddy = (yd2 - yd1) / detArray.nDet();  // between detectors
424       ddx2 = ddx / m_nSample;   // Incr. between rays with detector cell
425       ddy2 = ddy / m_nSample;  // Doesn't include detector endpoints 
426       ddx2_ofs = ddx2 / 2;    // offset of 1st ray from start of detector cell
427       ddy2_ofs = ddy2 / 2;
428       
429       xd_maj = xd1 + ddx2_ofs;       // Incr. between detector cells
430       yd_maj = yd1 + ddy2_ofs;
431   }
432
433   DetectorValue* detval = detArray.detValues();
434
435   if (phm.getComposition() == P_UNIT_PULSE) {  // put unit pulse in center of view
436     for (int d = 0; d < detArray.nDet(); d++)
437       if (detArray.nDet() / 2 == d && (d % 2) == 1)
438         detval[d] = 1;
439       else
440         detval[d] = 0;
441   } else {
442       for (int d = 0; d < detArray.nDet(); d++) {
443       double xs = xs_maj;
444       double ys = ys_maj;
445       double xd=0, yd=0, dAngle=0;
446       if (m_idGeometry == GEOMETRY_EQUIANGULAR) {
447           dAngle = dAngleMajor;
448       } else {
449           xd = xd_maj;
450           yd = yd_maj;
451       }
452       double sum = 0.0;
453       for (unsigned int i = 0; i < m_nSample; i++) {
454         if (m_idGeometry == GEOMETRY_EQUIANGULAR) {
455             xd = m_dFocalLength * cos (dAngle);
456             yd = m_dFocalLength * sin (dAngle);
457         }
458
459 #ifdef HAVE_SGP
460         if (m_pSGP && m_trace >= Trace::TRACE_PROJECTIONS) {
461           m_pSGP->setColor (C_YELLOW);
462           m_pSGP->setRasterOp (RO_AND);
463           m_pSGP->moveAbs (xs, ys);
464           m_pSGP->lineAbs (xd, yd);
465         }
466 #endif
467
468         sum += projectSingleLine (phm, xd, yd, xs, ys);
469               
470 #ifdef HAVE_SGP
471         if (m_trace >= Trace::TRACE_CLIPPING) {
472           traceShowParam ("Attenuation:", "%s", PROJECTION_TRACE_ROW_ATTEN, C_LTMAGENTA, "        ");
473           traceShowParam ("Attenuation:", "%.3f", PROJECTION_TRACE_ROW_ATTEN, C_LTMAGENTA, sum);
474         }
475 #endif
476         if (m_idGeometry == GEOMETRY_EQUIANGULAR)
477             dAngle += dAngleSampleInc;
478         else {
479             xd += ddx2;
480             yd += ddy2;
481         }
482       } // for each sample in detector
483
484       detval[d] = sum / m_nSample;
485       xs_maj += sdx;
486       ys_maj += sdy;
487       if (m_idGeometry == GEOMETRY_EQUIANGULAR)
488           dAngleMajor += dAngleInc;
489         else {
490             xd_maj += ddx;
491             yd_maj += ddy;
492         }
493     } /* for each detector */
494   } /* if not unit pulse */
495 }
496
497
498 void 
499 Scanner::traceShowParam (const char *szLabel, const char *fmt, int row, int color, ...)
500 {  
501   va_list arg;
502   va_start(arg, color);
503   traceShowParamRasterOp (RO_COPY, szLabel, fmt, row, color, arg);
504   va_end(arg);
505 }
506
507 void 
508 Scanner::traceShowParamXOR (const char *szLabel, const char *fmt, int row, int color, ...)
509 {  
510   va_list arg;
511   va_start(arg, color);
512   traceShowParamRasterOp (RO_XOR, szLabel, fmt, row, color, arg);
513   va_end(arg);
514 }
515
516 void 
517 Scanner::traceShowParamRasterOp (int iRasterOp, const char *szLabel, const char *fmt, int row, int color, va_list args)
518 {  
519   char szValue[256];
520
521   vsnprintf (szValue, sizeof(szValue), fmt, args);
522
523   //  cio_set_cpos (raysum_trace_menu_column, row);
524   //  cio_set_text_clr (color - 8, 0);
525   //  cio_set_text_clr (color, 0);
526
527   if (m_pSGP) {
528     m_pSGP->setRasterOp (iRasterOp);
529     double dYPos = m_dYMaxWin - (row * m_dTextHeight);
530     m_pSGP->moveAbs (m_dXMinWin, dYPos);
531     m_pSGP->setTextColor (color, -1);
532     m_pSGP->drawText (szLabel);
533     double dValueOffset = (m_dXMaxWin - m_dXMinWin) / 5;
534     m_pSGP->moveAbs (m_dXMinWin + dValueOffset, dYPos);
535     m_pSGP->drawText (szValue);
536   } else {
537     cio_put_str (szLabel);
538     cio_put_str (szValue);
539     cio_put_str ("\n");
540   }
541 }
542
543
544
545 /* NAME
546  *    projectSingleLine                 INTERNAL: Calculates raysum along a line for a Phantom
547  *
548  * SYNOPSIS
549  *    rsum = phm_ray_attenuation (phm, x1, y1, x2, y2)
550  *    double rsum               Ray sum of Phantom along given line
551  *    Phantom& phm;             Phantom from which to calculate raysum
552  *    double *x1, *y1, *x2, y2  Endpoints of ray path (in Phantom coords)
553  */
554
555 double 
556 Scanner::projectSingleLine (const Phantom& phm, const double x1, const double y1, const double x2, const double y2)
557 {
558   // check ray against each pelem in Phantom 
559   double rsum = 0.0;
560   for (PElemConstIterator i = phm.listPElem().begin(); i != phm.listPElem().end(); i++)
561     rsum += projectLineAgainstPElem (**i, x1, y1, x2, y2);
562
563   return (rsum);
564 }
565
566
567 /* NAME
568  *   pelem_ray_attenuation              Calculate raysum of an pelem along one line
569  *
570  * SYNOPSIS
571  *   rsum = pelem_ray_attenuation (pelem, x1, y1, x2, y2)
572  *   double rsum                Computed raysum
573  *   PhantomElement& pelem              Pelem to scan
574  *   double x1, y1, x2, y2      Endpoints of raysum line
575  */
576
577 double 
578 Scanner::projectLineAgainstPElem (const PhantomElement& pelem, double x1, double y1, double x2, double y2)
579 {
580   if (! pelem.clipLineWorldCoords (x1, y1, x2, y2)) {
581     if (m_trace == Trace::TRACE_CLIPPING)
582       cio_tone (1000., 0.05);
583     return (0.0);
584   }
585
586 #ifdef HAVE_SGP
587   if (m_pSGP && m_trace == Trace::TRACE_CLIPPING) {
588     m_pSGP->setRasterOp (RO_XOR);
589     m_pSGP->moveAbs (x1, y1);
590     m_pSGP->lineAbs (x2, y2);
591     cio_tone (8000., 0.05);
592     m_pSGP->moveAbs (x1, y1);
593     m_pSGP->lineAbs (x2, y2);
594     m_pSGP->setRasterOp (RO_SET);
595   }
596 #endif
597
598   double len = lineLength (x1, y1, x2, y2);
599   return (len * pelem.atten());
600 }
601