Interim work on creating projections from an imagefile
[ctsim.git] / libctsim / phantom.cpp
index bf1165499445375848e475861060d00a8762c443..2b969e87e25128808cc399a2cd23bd95aa5d709a 100644 (file)
@@ -78,6 +78,7 @@ Phantom::init ()
   m_composition = P_PELEMS;
   m_fail = false;
   m_id = PHM_INVALID;
   m_composition = P_PELEMS;
   m_fail = false;
   m_id = PHM_INVALID;
+  m_im = NULL;
 }
 
 Phantom::~Phantom ()
 }
 
 Phantom::~Phantom ()
@@ -85,9 +86,10 @@ Phantom::~Phantom ()
   for (PElemIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) {
     delete *i;
   }
   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)
 {
 const char*
 Phantom::convertPhantomIDToName (int phmID)
 {
@@ -171,10 +173,10 @@ Phantom::createFromPhantom (const int phmid)
 
 
 /* METHOD IDENTIFICATION
 
 
 /* METHOD IDENTIFICATION
-*   createFromFile          Add PhantomElements from file
+*   createFromPhmFile          Add PhantomElements from file
 *
 * SYNOPSIS
 *
 * SYNOPSIS
-*   createFromFile (filename)
+*   createFromPhmFile (filename)
 *
 * RETURNS
 *   true if pelem were added
 *
 * RETURNS
 *   true if pelem were added
@@ -182,7 +184,7 @@ Phantom::createFromPhantom (const int phmid)
 */
 
 bool
 */
 
 bool
-Phantom::createFromFile (const char* const fname)
+Phantom::createFromPhmFile (const char* const fname)
 {
   bool bGoodFile = true;
   FILE *fp;
 {
   bool bGoodFile = true;
   FILE *fp;
@@ -201,7 +203,7 @@ Phantom::createFromFile (const char* const fname)
     if (status == static_cast<int>(EOF))
       break;
     else if (status != 7) {
     if (status == static_cast<int>(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);
       bGoodFile = false;
     }
     addPElem (pelemtype, cx, cy, u, v, rot, dens);
@@ -212,6 +214,32 @@ Phantom::createFromFile (const char* const fname)
   return (bGoodFile);
 }
 
   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)
 {
 bool
 Phantom::fileWrite (const char* const fname)
 {