X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsim%2Fphantom.cpp;h=2b969e87e25128808cc399a2cd23bd95aa5d709a;hp=48123fabb0ce2b2b21e212c7e337358105a5f80f;hb=747a2ec9e0f3c49723b36da0cc77270fbecc9dfe;hpb=1a050c98763fbbc0662731b0b76953acede6f5d7 diff --git a/libctsim/phantom.cpp b/libctsim/phantom.cpp index 48123fa..2b969e8 100644 --- a/libctsim/phantom.cpp +++ b/libctsim/phantom.cpp @@ -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 @@ -80,6 +78,7 @@ Phantom::init () m_composition = P_PELEMS; m_fail = false; m_id = PHM_INVALID; + m_im = NULL; } Phantom::~Phantom () @@ -87,9 +86,10 @@ Phantom::~Phantom () for (PElemIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) { delete *i; } + if (m_im) + delete m_im; } - const char* Phantom::convertPhantomIDToName (int phmID) { @@ -117,13 +117,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); } @@ -173,10 +173,10 @@ Phantom::createFromPhantom (const int phmid) /* METHOD IDENTIFICATION -* createFromFile Add PhantomElements from file +* createFromPhmFile Add PhantomElements from file * * SYNOPSIS -* createFromFile (filename) +* createFromPhmFile (filename) * * RETURNS * true if pelem were added @@ -184,7 +184,7 @@ Phantom::createFromPhantom (const int phmid) */ bool -Phantom::createFromFile (const char* const fname) +Phantom::createFromPhmFile (const char* const fname) { bool bGoodFile = true; FILE *fp; @@ -203,7 +203,7 @@ Phantom::createFromFile (const char* const fname) if (status == static_cast(EOF)) break; else if (status != 7) { - sys_error (ERR_WARNING, "Insufficient fields reading phantom file %s [Phantom::createFromFile]", fname); + sys_error (ERR_WARNING, "Insufficient fields reading phantom file %s [Phantom::createFromPhmFile]", fname); bGoodFile = false; } addPElem (pelemtype, cx, cy, u, v, rot, dens); @@ -214,6 +214,32 @@ Phantom::createFromFile (const char* const fname) return (bGoodFile); } +bool +Phantom::createFromImageFile (const char* const fname) +{ + bool bGoodFile = true; + + m_im = new ImageFile (); + if (! m_im || ! m_im->fileRead (fname)) { + sys_error (ERR_SEVERE, "Unable to read image file %s", fname); + bGoodFile = false; + delete m_im; + m_im = NULL; + m_fail = true; + } else { + m_name = fname; + m_id = -1; + m_fail = false; + + if (! m_im->getAxisExtent(m_xmin, m_xmax, m_ymin, m_ymax)) { + m_xmax = m_im->nx() / 2.; m_xmin = -m_xmax; + m_ymax = m_im->ny() / 2.; m_ymin = -m_ymax; + } + } + + return (bGoodFile); +} + bool Phantom::fileWrite (const char* const fname) { @@ -509,6 +535,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 +582,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(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 +666,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";