r164: *** empty log message ***
[ctsim.git] / libctsim / scanner.cpp
index ae665f207894f1e43e790c577969029a446b7443..e39fca5d7ff0a8625c3d335893b0c641c1051bd6 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: scanner.cpp,v 1.5 2000/07/22 15:45:33 kevin Exp $
+**  $Id: scanner.cpp,v 1.7 2000/07/29 19:50:08 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -180,7 +180,7 @@ Scanner::convertGeometryNameToID (const char* const geomName)
 */
 
 void
-Scanner::collectProjections (Projections& proj, const Phantom& phm, const int start_view, const int trace)
+Scanner::collectProjections (Projections& proj, const Phantom& phm, const int start_view, const int trace = TRACE_NONE, SGP* pSGP = NULL)
 {
   GRFMTX_2D rotmtx_initial, temp;
   GRFMTX_2D rotmtx_incr;
@@ -201,26 +201,24 @@ Scanner::collectProjections (Projections& proj, const Phantom& phm, const int st
   m_trace = trace;
 
 #ifdef HAVE_SGP 
-  SGP_ID gid;
-  if (m_trace >= TRACE_PHM) {
+  if (pSGP && m_trace >= TRACE_PHM) {
     double wsize = 1.42 * m_phmLen / 2;        /* sqrt(2) * radius */
-      
-    gid = sgp2_init (512, 512, "RayCollect");
-    sgp2_color (C_LTBLUE);
-    sgp2_window (xcent - wsize, ycent - wsize, xcent + wsize, ycent + wsize);
-    sgp2_color (C_BROWN);
+
+    pSGP->setColor (C_LTBLUE);
+    pSGP->setWindow (xcent - wsize, ycent - wsize, xcent + wsize, ycent + wsize);
+    pSGP->setColor (C_BROWN);
 #if RADIUS
-    sgp2_draw_circle (m_phmLen / 2);
+    pSGP->drawCircle (m_phmLen / 2);
 #else
-    sgp2_draw_rect (xcent - m_phmLen / 2, ycent - m_phmLen / 2,
+    pSGP->drawRect (xcent - m_phmLen / 2, ycent - m_phmLen / 2,
                    xcent + m_phmLen / 2, ycent + m_phmLen / 2);
 #endif
-    sgp2_color (C_BROWN);
-    sgp2_move_abs (0., 0.);
-    sgp2_draw_circle (wsize);
+    pSGP->setColor (C_BROWN);
+    pSGP->moveAbs (0., 0.);
+    pSGP->drawCircle (wsize);
     //      raysum_trace_menu_column = (crt->xsize * crt->asp) / 8 + 3;
-    traceShowParam ("X-Ray Simulator", "%s", RAYSUM_TRACE_ROW_TITLE, 8+C_LTWHITE, " ");
-    traceShowParam ("---------------", "%s", RAYSUM_TRACE_ROW_TITLE2, 8+C_LTWHITE, " ");
+    traceShowParam ("X-Ray Simulator", "%s", RAYSUM_TRACE_ROW_TITLE, C_BLACK, " ");
+    traceShowParam ("---------------", "%s", RAYSUM_TRACE_ROW_TITLE2, C_BLACK, " ");
     traceShowParam ("Phantom:",       "%s", RAYSUM_TRACE_ROW_PHANT_ID, C_YELLOW, " Herman");
     traceShowParam ("Chomaticity  :", "%s", RAYSUM_TRACE_ROW_CHROMATIC, C_LTGREEN, "Mono");
     traceShowParam ("Scatter      :", "%5.1f", RAYSUM_TRACE_ROW_SCATTER, C_LTGREEN, 0.);
@@ -229,10 +227,10 @@ Scanner::collectProjections (Projections& proj, const Phantom& phm, const int st
     traceShowParam ("Num Views    :", "%5d", RAYSUM_TRACE_ROW_NVIEW, C_LTRED, proj.nView());
     traceShowParam ("Samples / Ray:", "%5d", RAYSUM_TRACE_ROW_SAMPLES, C_LTRED, m_nSample);
     
-    sgp2_color (C_LTGREEN);
-    phm.draw();
+    pSGP->setColor (C_LTGREEN);
+    phm.draw (*pSGP);
     
-    initmarker (BDIAMOND, 129);
+    pSGP->setMarker (SGP::MARK_BDIAMOND, C_LTGREEN);
   }
 #endif
 
@@ -261,26 +259,26 @@ Scanner::collectProjections (Projections& proj, const Phantom& phm, const int st
       DetectorArray& detArray = proj.getDetectorArray( iview );
 
 #ifdef HAVE_SGP
-    if (m_trace >= TRACE_PHM) {
-      sgp2_move_abs (xd1, yd1);
-      sgp2_line_abs (xd2, yd2);
-      sgp2_move_abs (xs1, ys1);
-      sgp2_line_abs (xs2, ys2);
+    if (pSGP && m_trace >= TRACE_PHM) {
+      pSGP->moveAbs (xd1, yd1);
+      pSGP->lineAbs (xd2, yd2);
+      pSGP->moveAbs (xs1, ys1);
+      pSGP->lineAbs (xs2, ys2);
     }
 #endif
     if (m_trace)
       traceShowParam ("Current View :", "%5d", RAYSUM_TRACE_ROW_CURR_VIEW, C_LTMAGENTA, iview);
            
-    projectSingleView (phm, detArray, xd1, yd1, xd2, yd2, xs1, ys1, xs2, ys2);
+    projectSingleView (phm, detArray, xd1, yd1, xd2, yd2, xs1, ys1, xs2, ys2, pSGP);
     detArray.setViewAngle (viewAngle);
       
 #ifdef HAVE_SGP
-    if (m_trace >= TRACE_PHM) {
+    if (pSGP && m_trace >= TRACE_PHM) {
       //       rs_plot (detArray, xd1, yd1, xcent, ycent, theta);
-      sgp2_move_abs (xd1, yd1);
-      sgp2_line_abs (xd2, yd2);
-      sgp2_move_abs (xs1, ys1);
-      sgp2_line_abs (xs2, ys2);
+      pSGP->moveAbs (xd1, yd1);
+      pSGP->lineAbs (xd2, yd2);
+      pSGP->moveAbs (xs1, ys1);
+      pSGP->lineAbs (xs2, ys2);
     }
 #endif
     xform_mtx2 (rotmtx_incr, xd1, yd1);         // rotate detector endpoints 
@@ -315,7 +313,7 @@ Scanner::collectProjections (Projections& proj, const Phantom& phm, const int st
  */
 
 void 
-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)
+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, SGP* pSGP)
 {
   double ddx = (xd2 - xd1) / detArray.nDet();  // change in coords between detectors
   double ddy = (yd2 - yd1) / detArray.nDet();
@@ -349,20 +347,20 @@ Scanner::projectSingleView (const Phantom& phm, DetectorArray& detArray, const d
       double sum = 0.0;
       for (unsigned int i = 0; i < m_nSample; i++) {
 #ifdef HAVE_SGP
-       if (m_trace >= TRACE_RAYS) {
-         sgp2_move_abs (xs, ys);
-         sgp2_line_abs (xd, yd);
+       if (pSGP && m_trace >= TRACE_RAYS) {
+         pSGP->moveAbs (xs, ys);
+         pSGP->lineAbs (xd, yd);
        }
 #endif
-       sum += projectSingleLine (phm, xd, yd, xs, ys);
+       sum += projectSingleLine (phm, xd, yd, xs, ys, pSGP);
              
        if (m_trace >= TRACE_RAYS)
          traceShowParam ("Attenuation  :", "%5.2f", RAYSUM_TRACE_ROW_ATTEN, C_LTMAGENTA, "sum");
 
 #ifdef HAVE_SGP
-       if (m_trace >= TRACE_RAYS) {
-         sgp2_move_abs (xs, ys);
-         sgp2_line_abs (xd, yd);
+       if (pSGP && m_trace >= TRACE_RAYS) {
+         pSGP->moveAbs (xs, ys);
+         pSGP->lineAbs (xd, yd);
        }
 #endif
        xd += ddx2;
@@ -393,7 +391,7 @@ Scanner::traceShowParam (const char *label, const char *fmt, int row, int color,
   vsnprintf (s, sizeof(s), fmt, arg);
   //  cio_set_text_clr (color, 0);
   cio_put_str (s);
-
+  cout << "\n";
   va_end(arg);
 }
 
@@ -409,12 +407,12 @@ Scanner::traceShowParam (const char *label, const char *fmt, int row, int color,
  */
 
 double 
-Scanner::projectSingleLine (const Phantom& phm, const double x1, const double y1, const double x2, const double y2)
+Scanner::projectSingleLine (const Phantom& phm, const double x1, const double y1, const double x2, const double y2, SGP* pSGP)
 {
   // check ray against each pelem in Phantom 
   double rsum = 0.0;
   for (PElemConstIterator i = phm.listPElem().begin(); i != phm.listPElem().end(); i++)
-    rsum += projectLineAgainstPElem (**i, x1, y1, x2, y2);
+    rsum += projectLineAgainstPElem (**i, x1, y1, x2, y2, pSGP);
 
   return (rsum);
 }
@@ -431,7 +429,7 @@ Scanner::projectSingleLine (const Phantom& phm, const double x1, const double y1
  */
 
 double 
-Scanner::projectLineAgainstPElem (const PhantomElement& pelem, double x1, double y1, double x2, double y2)
+Scanner::projectLineAgainstPElem (const PhantomElement& pelem, double x1, double y1, double x2, double y2, SGP* pSGP)
 {
   if (! pelem.clipLineWorldCoords (x1, y1, x2, y2)) {
     if (m_trace == TRACE_CLIPPING)
@@ -440,12 +438,12 @@ Scanner::projectLineAgainstPElem (const PhantomElement& pelem, double x1, double
   }
 
 #ifdef HAVE_SGP
-  if (m_trace == TRACE_CLIPPING) {
-    sgp2_move_abs (x1, y1);
-    sgp2_line_abs (x2, y2);
+  if (pSGP && m_trace == TRACE_CLIPPING) {
+    pSGP->moveAbs (x1, y1);
+    pSGP->lineAbs (x2, y2);
     cio_tone (8000., 0.05);
-    sgp2_move_abs (x1, y1);
-    sgp2_line_abs (x2, y2);
+    pSGP->moveAbs (x1, y1);
+    pSGP->lineAbs (x2, y2);
   }
 #endif