-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
-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
fnetorderstream (const char* filename, int mode)
: fstream (filename, mode) {}
+ fnetorderstream (const int fd)
+ : fstream (fd) {}
+
~fnetorderstream (void)
{}
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);
** 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
class Scanner;
class DetectorArray;
class Array2dFileLabel;
-\r
-#include <sstream>\r
// Projections
void initFromScanner (const Scanner& scanner);
+ void printProjectionData (int startView, int endView);
void printProjectionData ();
void printScanInfo (ostringstream& os) const;
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
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 ();
** 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
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);
}
** 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
for (int iy = 0; iy < ny; iy++) {
int b = static_cast<int>((((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;
}
}
** 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
}
+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)
{
*/
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());
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");
+ }
}
}
** 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
#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);
/*****************************************************************************
** 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
** 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
******************************************************************************/
/* FILE
- * pjfinfo.c Convert Raysum to image
+ * pjinfo.c Convert Raysum to image
*
* DATE
* August 2000
#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;
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;
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);
int retval = 1;
try {
- retval = pjfinfo_main(argc, argv);
+ retval = pjinfo_main(argc, argv);
} catch (exception e) {
cerr << "Exception: " << e.what() << endl;
} catch (...) {