From: Kevin M. Rosenberg Date: Sat, 16 Dec 2000 02:31:00 +0000 (+0000) Subject: r254: Added binary output of projection file elements X-Git-Tag: debian-4.5.3-3~763 X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=commitdiff_plain;h=9703ace3c451ce079967284bf191783736dbc77f r254: Added binary output of projection file elements --- diff --git a/ChangeLog b/ChangeLog index 6703e41..388af49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ -2.0.7 - 12/04/00 +2.0.7 - 12/16/00 Modifications for Microsoft Visual C++ compilation - Fix core-dump bug in Array2dFile::labelsCopy() function [Thanks Ian Kay!] + Fixed core-dump bug in Array2dFile::labelsCopy() function (Ian Kay) + Improved pjinfo to output binary headers and view data, useful when + manually compiling changing phantoms during projection process. Thanks to + Ian Kay for idea and initial code submission. 2.0.6 - 12/03/00 Fixed minor compilation problem with procsignal.h diff --git a/include/Makefile.am b/include/Makefile.am index bf978a6..63726ae 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,4 +1,4 @@ -noinst_HEADERS=ct.h ezplot.h pol.h sgp.h array2d.h imagefile.h backprojectors.h mpiworld.h fnetorderstream.h phantom.h timer.h sstream scanner.h projections.h ctsupport.h filter.h array2dfile.h trace.h transformmatrix.h procsignal.h reconstruct.h +noinst_HEADERS=ct.h ezplot.h pol.h sgp.h array2d.h imagefile.h backprojectors.h mpiworld.h fnetorderstream.h phantom.h timer.h sstream_subst scanner.h projections.h ctsupport.h filter.h array2dfile.h trace.h transformmatrix.h procsignal.h reconstruct.h diff --git a/include/fnetorderstream.h b/include/fnetorderstream.h index b682105..41be6cb 100644 --- a/include/fnetorderstream.h +++ b/include/fnetorderstream.h @@ -71,6 +71,9 @@ class fnetorderstream : public fstream { fnetorderstream (const char* filename, int mode) : fstream (filename, mode) {} + fnetorderstream (const int fd) + : fstream (fd) {} + ~fnetorderstream (void) {} @@ -91,6 +94,9 @@ class frnetorderstream : public fnetorderstream { frnetorderstream (const char* filename, int mode) : fnetorderstream (filename, mode) {} + frnetorderstream (const int fd) + : fnetorderstream (fd) {} + virtual void writeInt16 (kuint16 n); virtual void writeInt32 (kuint32 n); virtual void writeFloat32 (kfloat32 n); diff --git a/include/projections.h b/include/projections.h index 4bad1e4..03cb2da 100644 --- a/include/projections.h +++ b/include/projections.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: projections.h,v 1.15 2000/12/04 05:36:57 kevin Exp $ +** $Id: projections.h,v 1.16 2000/12/16 02:31:00 kevin Exp $ ** ** ** This program is free software; you can redistribute it and/or modify @@ -32,8 +32,6 @@ class Scanner; class DetectorArray; class Array2dFileLabel; - -#include // Projections @@ -47,6 +45,7 @@ class Projections void initFromScanner (const Scanner& scanner); + void printProjectionData (int startView, int endView); void printProjectionData (); void printScanInfo (ostringstream& os) const; @@ -89,6 +88,12 @@ class Projections const DetectorArray& getDetectorArray (const int iview) const { return (*m_projData[iview]); } + + static bool copyHeader (const char* const filename, ostream& os); + static bool copyHeader (const string& filename, ostream& os); + + static bool copyViewData (const char* const filename, ostream& os, int startView, int endView); + static bool copyViewData (const string& filename, ostream& os, int startView, int endView); private: int m_headerSize; // Size of disk file header @@ -116,10 +121,8 @@ class Projections const static kuint16 m_signature; - bool headerRead (); - bool headerWrite (); - bool headerRead (fnetorderstream& fs); bool headerWrite (fnetorderstream& fs); + bool headerRead (fnetorderstream& fs); void newProjData (); void deleteProjData (); diff --git a/libctsim/array2dfile.cpp b/libctsim/array2dfile.cpp index 40be226..b3538da 100644 --- a/libctsim/array2dfile.cpp +++ b/libctsim/array2dfile.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: array2dfile.cpp,v 1.18 2000/12/15 22:07:35 kevin Exp $ +** $Id: array2dfile.cpp,v 1.19 2000/12/16 02:31:00 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 @@ -563,7 +563,7 @@ Array2dFile::labelsCopy (Array2dFile& copyFile, const char* const pszId) for (unsigned int i = 0; i < copyFile.getNumLabels(); i++) { Array2dFileLabel l (copyFile.labelGet (i)); string lstr = l.getLabelString(); - lstr = idStr + lstr; + lstr = id + lstr; l.setLabelString (lstr); labelAdd (l); } diff --git a/libctsim/imagefile.cpp b/libctsim/imagefile.cpp index 803347f..851b4fd 100644 --- a/libctsim/imagefile.cpp +++ b/libctsim/imagefile.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: imagefile.cpp,v 1.17 2000/12/06 01:46:43 kevin Exp $ +** $Id: imagefile.cpp,v 1.18 2000/12/16 02:31:00 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 @@ -256,7 +256,7 @@ ImageFile::statistics (double& min, double& max, double& mean, double& mode, dou for (int iy = 0; iy < ny; iy++) { int b = static_cast((((v[ix4][iy] - min) / spread) * (nbin - 1)) + 0.5); hist[b]++; - double diff = (v[ix][iy] - mean); + double diff = (v[ix4][iy] - mean); stddev += diff * diff; } } diff --git a/libctsim/projections.cpp b/libctsim/projections.cpp index 7de8203..49aaa99 100644 --- a/libctsim/projections.cpp +++ b/libctsim/projections.cpp @@ -8,7 +8,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: projections.cpp,v 1.28 2000/12/06 01:46:43 kevin Exp $ +** $Id: projections.cpp,v 1.29 2000/12/16 02:31:00 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 @@ -329,6 +329,99 @@ Projections::read (const char* filename) } +bool +Projections::copyViewData (const string& filename, ostream& os, int startView, int endView) +{ + return copyViewData (filename.c_str(), os, startView, endView); +} + +bool +Projections::copyViewData (const char* const filename, ostream& os, int startView, int endView) +{ + frnetorderstream is (filename, ios::in | ios::binary); + kuint16 sizeHeader, signature; + kuint32 _nView, _nDet; + + is.readInt16 (sizeHeader); + is.readInt16 (signature); + is.readInt32 (_nView); + is.readInt32 (_nDet); + int nView = _nView; + int nDet = _nDet; + + if (signature != m_signature) { + sys_error (ERR_FATAL, "Illegal signature in projection file %s", filename); + return false; + } + + if (startView < 0) + startView = 0; + if (startView > nView - 1) + startView = nView; + if (endView < 0 || endView > nView - 1) + endView = nView - 1; + + if (startView > endView) { // swap if start > end + int tempView = endView; + endView = startView; + startView = tempView; + } + + int sizeView = 8 /* view_angle */ + 4 /* nDet */ + (4 * nDet); + unsigned char* pViewData = new unsigned char [sizeView]; + + for (int i = startView; i <= endView; i++) { + is.seekg (sizeHeader + i * sizeView); + is.read (pViewData, sizeView); + os.write (pViewData, sizeView); + if (is.fail() || os.fail()) + break; + } + + delete pViewData; + if (is.fail()) + sys_error (ERR_FATAL, "Error reading projection file"); + if (os.fail()) + sys_error (ERR_FATAL, "Error writing projection file"); + + return (! (is.fail() | os.fail())); +} + +bool +Projections::copyHeader (const string& filename, ostream& os) +{ + return copyHeader (filename.c_str(), os); +} + +bool +Projections::copyHeader (const char* const filename, ostream& os) +{ + frnetorderstream is (filename, ios::in | ios::binary); + kuint16 sizeHeader, signature; + is.readInt16 (sizeHeader); + is.readInt16 (signature); + is.seekg (0); + if (signature != m_signature) { + sys_error (ERR_FATAL, "Illegal signature in projection file %s", filename); + return false; + } + + unsigned char* pHdrData = new unsigned char [sizeHeader]; + is.read (pHdrData, sizeHeader); + if (is.fail()) { + sys_error (ERR_FATAL, "Error reading header"); + return false; + } + + os.write (pHdrData, sizeHeader); + if (os.fail()) { + sys_error (ERR_FATAL, "Error writing header"); + return false; + } + + return true; +} + bool Projections::write (const string& filename) { @@ -465,7 +558,13 @@ Projections::detarrayWrite (fnetorderstream& fs, const DetectorArray& darray, co */ void -Projections::printProjectionData (void) +Projections::printProjectionData () +{ + printProjectionData (0, nView() - 1); +} + +void +Projections::printProjectionData (int startView, int endView) { printf("Projections Data\n\n"); printf("Description: %s\n", m_remark.c_str()); @@ -475,13 +574,19 @@ Projections::printProjectionData (void) printf("rotStart = %8.4f rotInc = %8.4f\n", m_rotStart, m_rotInc); printf("detStart = %8.4f detInc = %8.4f\n", m_detStart, m_detInc); if (m_projData != NULL) { - for (int ir = 0; ir < m_nView; ir++) { - printf("View %d: angle %f\n", ir, m_projData[ir]->viewAngle()); - DetectorValue* detval = m_projData[ir]->detValues(); - for (int id = 0; id < m_projData[ir]->nDet(); id++) - printf("%8.4f ", detval[id]); - printf("\n"); - } + if (startView < 0) + startView = 0; + if (startView > m_nView - 1) + startView = m_nView - 1; + if (endView > m_nView - 1) + endView = m_nView - 1; + for (int ir = startView; ir <= endView - 1; ir++) { + printf("View %d: angle %f\n", ir, m_projData[ir]->viewAngle()); + DetectorValue* detval = m_projData[ir]->detValues(); + for (int id = 0; id < m_projData[ir]->nDet(); id++) + printf("%8.4f ", detval[id]); + printf("\n"); + } } } diff --git a/libctsim/scanner.cpp b/libctsim/scanner.cpp index c8c8663..48f2394 100644 --- a/libctsim/scanner.cpp +++ b/libctsim/scanner.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: scanner.cpp,v 1.17 2000/12/06 01:46:43 kevin Exp $ +** $Id: scanner.cpp,v 1.18 2000/12/16 02:31:00 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 @@ -535,7 +535,7 @@ Scanner::traceShowParamRasterOp (int iRasterOp, const char *szLabel, const char #ifdef MSVC vsprintf (szValue, fmt, args); #else - vnsprintf (szValue, sizeof(szValue), fmt, args); + vsnprintf (szValue, sizeof(szValue), fmt, args); #endif // cio_set_cpos (raysum_trace_menu_column, row); diff --git a/tools/pjinfo.cpp b/tools/pjinfo.cpp index 0ca578c..8a4d0e2 100644 --- a/tools/pjinfo.cpp +++ b/tools/pjinfo.cpp @@ -1,7 +1,7 @@ /***************************************************************************** ** FILE IDENTIFICATION ** -** Name: pjfinfo.cpp +** Name: pjinfo.cpp ** Purpose: Convert an projection data file to an image file ** Programmer: Kevin Rosenberg ** Date Started: April 2000 @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: pjinfo.cpp,v 1.1 2000/09/02 05:17:29 kevin Exp $ +** $Id: pjinfo.cpp,v 1.2 2000/12/16 02:31:00 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 @@ -26,7 +26,7 @@ ******************************************************************************/ /* FILE - * pjfinfo.c Convert Raysum to image + * pjinfo.c Convert Raysum to image * * DATE * August 2000 @@ -36,41 +36,53 @@ #include "timer.h" -enum { O_DUMP, O_HELP, O_VERSION }; +enum { O_BINARYHEADER, O_BINARYVIEWS, O_STARTVIEW, O_ENDVIEW, O_DUMP, O_HELP, O_VERSION }; static struct option my_options[] = { + {"binaryheader", 0, 0, O_BINARYHEADER}, + {"binaryviews", 0, 0, O_BINARYVIEWS}, + {"startview", 1, 0, O_STARTVIEW}, + {"endview", 1, 0, O_ENDVIEW}, {"dump", 0, 0, O_DUMP}, {"help", 0, 0, O_HELP}, {"version", 0, 0, O_VERSION}, {0, 0, 0, 0} }; -static const char* g_szIdStr = "$Id: pjinfo.cpp,v 1.1 2000/09/02 05:17:29 kevin Exp $"; +static const char* g_szIdStr = "$Id: pjinfo.cpp,v 1.2 2000/12/16 02:31:00 kevin Exp $"; void -pjfinfo_usage (const char *program) +pjinfo_usage (const char *program) { cout << "usage: " << fileBasename(program) << " proj-file [OPTIONS]" << endl; cout << "Display projection file information" << endl; - cout << endl; - cout << " --dump Dump all scan data" << endl; - cout << " --version Print version" << endl; - cout << " --help Print this help message" << endl; + cout << "\n"; + cout << " --binaryheader Dump binary header data\n"; + cout << " --binaryviews Dump binary view data\n"; + cout << " --startview n Beginning view number to display (default=0)\n"; + cout << " --endview n Ending view number to display (default=last view)\n"; + cout << " --dump Print all scan data ASCII format\n"; + cout << " --version Print version" << endl; + cout << " --help Print this help message" << endl; } int -pjfinfo_main (const int argc, char *const argv[]) +pjinfo_main (const int argc, char *const argv[]) { string pj_name; bool optDump = false; + bool optBinaryHeader = false; + bool optBinaryViews = false; + int optStartView = 0; + int optEndView = -1; // tells copyViewData to use default last view extern int optind; - Timer timerProgram; while (1) { + char *endptr, *endstr; int c = getopt_long (argc, argv, "", my_options, NULL); if (c == -1) break; @@ -80,6 +92,30 @@ pjfinfo_main (const int argc, char *const argv[]) case O_DUMP: optDump = true; break; + case O_BINARYHEADER: + optBinaryHeader = true; + break; + case O_BINARYVIEWS: + optBinaryViews = true; + break; + case O_STARTVIEW: + optStartView = strtol(optarg, &endptr, 10); + endstr = optarg + strlen(optarg); + if (endptr != endstr) { + cerr << "Error setting --startview to %s" << optarg << endl; + pjinfo_usage(argv[0]); + return (1); + } + break; + case O_ENDVIEW: + optEndView = strtol(optarg, &endptr, 10); + endstr = optarg + strlen(optarg); + if (endptr != endstr) { + cerr << "Error setting --endview to %s" << optarg << endl; + pjinfo_usage(argv[0]); + return (1); + } + break; case O_VERSION: #ifdef VERSION cout << "Version " << VERSION << endl << g_szIdStr << endl; @@ -89,33 +125,39 @@ pjfinfo_main (const int argc, char *const argv[]) return (0); case O_HELP: case '?': - pjfinfo_usage(argv[0]); + pjinfo_usage(argv[0]); return (0); default: - pjfinfo_usage(argv[0]); + pjinfo_usage(argv[0]); return (1); } } if (argc - optind != 1) { - pjfinfo_usage(argv[0]); + pjinfo_usage(argv[0]); return (1); } pj_name = argv[optind]; - Projections pj; - if (! pj.read (pj_name)) { - sys_error (ERR_SEVERE, "Can not open projection file %s", pj_name.c_str()); - return (1); - } - - if (optDump) - pj.printProjectionData(); + if (optBinaryHeader) + Projections::copyHeader (pj_name, cout); + else if (optBinaryViews) + Projections::copyViewData (pj_name, cout, optStartView, optEndView); else { - ostringstream os; - pj.printScanInfo (os); - cout << os.str(); + Projections pj; + if (! pj.read (pj_name)) { + sys_error (ERR_SEVERE, "Can not open projection file %s", pj_name.c_str()); + return (1); + } + + if (optDump) { + pj.printProjectionData (optStartView, optEndView); + } else { + ostringstream os; + pj.printScanInfo (os); + cout << os.str(); + } } return(0); @@ -129,7 +171,7 @@ main (const int argc, char *const argv[]) int retval = 1; try { - retval = pjfinfo_main(argc, argv); + retval = pjinfo_main(argc, argv); } catch (exception e) { cerr << "Exception: " << e.what() << endl; } catch (...) {