Increment position counters - microoptimization
[ctsim.git] / libctsim / phantom.cpp
index 48123fabb0ce2b2b21e212c7e337358105a5f80f..bf1165499445375848e475861060d00a8762c443 100644 (file)
@@ -7,9 +7,7 @@
 **     Date Started:           Aug 1984
 **
 **  This is part of the CTSim program
-**  Copyright (c) 1983-2001 Kevin Rosenberg
-**
-**  $Id$
+**  Copyright (c) 1983-2009 Kevin Rosenberg
 **
 **  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
@@ -117,13 +115,13 @@ Phantom::convertNameToPhantomID (const char* const phmName)
 {
   int id = PHM_INVALID;
 
-  for (int i = 0; i < s_iPhantomCount; i++)
+  for (int i = 0; i < s_iPhantomCount; i++) {
     if (strcasecmp (phmName, s_aszPhantomName[i]) == 0) {
       id = i;
       break;
     }
-
-    return (id);
+  }
+  return (id);
 }
 
 
@@ -509,6 +507,34 @@ Phantom::convertToImagefile (ImageFile& im, const int iTotalRasterCols, const do
       *vCol++ = 0;
   }
 
+#if HAVE_OPENMP
+  double x_start = xmin + (colStart * xinc);
+  for (PElemConstIterator pelem = m_listPElem.begin(); pelem != m_listPElem.end(); pelem++) {
+    const PhantomElement& rPElem = **pelem;
+    #pragma omp parallel for
+    for (int ix = 0; ix < colCount; ix++) {
+      double x = x_start + ix * xinc;
+      int iColStore = ix + iStorageOffset;
+      ImageFileColumn vCol = v[iColStore];
+
+      double y = ymin;
+      for (int iy = 0; iy < ny; iy++, y += yinc) {
+        double dAtten = 0;
+        double xi = x + kxofs;
+        for (int kx = 0; kx < nsample; kx++, xi += kxinc) {
+          double yi = y + kyofs;
+          for (int ky = 0; ky < nsample; ky++, yi += kyinc) {
+            if (rPElem.isPointInside (xi, yi, PHM_COORD))
+              dAtten += rPElem.atten();
+          } // ky
+        } // kx
+        *vCol++ += dAtten;
+      } /* iy */
+    }  /* ix */
+  }  /* pelem */
+
+#else
+
   double x_start = xmin + (colStart * xinc);
   for (PElemConstIterator pelem = m_listPElem.begin(); pelem != m_listPElem.end(); pelem++) {
     const PhantomElement& rPElem = **pelem;
@@ -528,12 +554,13 @@ Phantom::convertToImagefile (ImageFile& im, const int iTotalRasterCols, const do
       } /* for iy */
     }  /* for ix */
   }  /* for pelem */
-
+#endif
 
   if (nsample > 1) {
     double factor = 1.0 / static_cast<double>(nsample * nsample);
-
-
+#if HAVE_OPENMP
+    #pragma omp parallel for
+#endif
     for (int ix = 0; ix < colCount; ix++) {
       int iColStore = ix + iStorageOffset;
       ImageFileColumn vCol = v[iColStore];
@@ -611,7 +638,7 @@ PhantomElement::convertNameToType (const char* const typeName)
 const char* const
 PhantomElement::convertTypeToName (PhmElemType iType)
 {
-  static char* pszType = "Unknown";
+  static const char* pszType = "Unknown";
 
   if (iType == PELEM_RECTANGLE)
     pszType = "rectangle";