+0.6.0-b2 - 6/8/2000
+ Converted MPI data structures to C++ object
+
0.6.0-b1 - 6/6/2000
First C++ conversions
Portable IF (image file) format implemented with objects (SDF removed)
dnl CDPATH=
AC_INIT(src/ctrec.cpp)
-AM_INIT_AUTOMAKE(ctsim,0.6.0-b1)
+AM_INIT_AUTOMAKE(ctsim,0.6.0-b2)
AM_CONFIG_HEADER(config.h)
dnl Checks for programs.
** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: array2d.h,v 1.3 2000/06/09 01:35:33 kevin Exp $
+** $Id: array2d.h,v 1.4 2000/06/09 11:03:08 kevin Exp $
** $Log: array2d.h,v $
+** Revision 1.4 2000/06/09 11:03:08 kevin
+** Made ImageFile inherit from Array2dFile
+**
** Revision 1.3 2000/06/09 01:35:33 kevin
** Convert MPI structure to C++ class
**
template<class T>
class Array2d {
- private:
- unsigned int nx;
- unsigned int ny;
-
public:
-
- T** array_data;
-
Array2d (unsigned int x, unsigned int y)
+ : nx(x), ny(y), array_data(0)
{
- nx = x;
- ny = y;
- array_data = new T*[nx];
-
- for (unsigned int i = 0; i < nx; i++)
- array_data[i] = new T[ny];
+ allocArray();
}
+ Array2d (void)
+ : array_data(0), nx(0), ny(0)
+ {}
~Array2d ()
{
- for (int i = 0; i < nx; i++)
- delete array_data[i];
- delete array_data;
+ deleteArray();
}
+ void initSetSize (unsigned int x, unsigned int y)
+ {
+ nx = x;
+ ny = y;
+ deleteArray();
+ allocArray();
+ }
+
T** getArray (void) const
{ return array_data; }
T* getColumn (unsigned int x) const
- { return array_data[x]; }
+ { return (array_data ? array_data[x] : NULL); }
T getPoint (unsigned int x, unsigned int y) const
- { return (array_data[x][y]); }
+ { return (array_data ? array_data[x][y] : NULL); }
unsigned int sizeofPixel (void) const
{ return sizeof(T); }
unsigned int sizeofArray (void) const
{ return (sizeof(T) * nx * ny); }
+
+
+ private:
+ unsigned int nx;
+ unsigned int ny;
+ T** array_data;
+
+ void allocArray (void)
+ {
+ array_data = new T*[nx];
+
+ for (unsigned int i = 0; i < nx; i++)
+ array_data[i] = new T[ny];
+ }
+
+ void deleteArray (void)
+ {
+ if (array_data) {
+ for (int i = 0; i < nx; i++)
+ delete array_data[i];
+ delete array_data;
+ }
+ }
+
+
+ Array2d& operator= (const Array2d& rhs);
+ Array2d (const Array2d& rhs); // copy constructor
};
public:
- Array2d<T> *array;
+ Array2d<T> array;
static const int INT8 = 1;
static const int UINT8 = 2;
void doPixelOffsetScale (double offset, double scale);
T** getArray (void) const
- { return (array == NULL ? NULL : array->getArray()); }
+ { return (array.getArray()); }
bool arrayDataWrite (void);
init();
mNX = x;
mNY = y;
- array = new Array2d<T> (mNX, mNY);
+ array.initSetSize(mNX, mNY);
}
template<class T>
init();
mNX = x;
mNY = y;
- array = new Array2d<T> (mNX, mNY);
+ array.initSetSize(mNX, mNY);
}
template<class T>
mMinX = mMaxX = mMinY = mMaxY = 0;
mOffsetPV = 0;
mScalePV = 1;
- array = NULL;
io = NULL;
#if 0
Array2dFile<T>::~Array2dFile (void)
{
fileClose ();
- delete array;
}
}
headerRead();
- if (array != NULL)
- delete array;
- array = new Array2d<T> (mNX, mNY);
+ array.initSetSize(mNX, mNY);
arrayDataRead();
void
Array2dFile<T>::getPixelValueRange (T& pvmin, T& pvmax) const
{
- if (array != NULL) {
- T** da = array->getArray();
+ T** da = array.getArray();
+ if (da) {
pvmax = pvmin = da[0][0];
for (int ix = 0; ix < mNX; ix++)
for (int iy = 0; iy < mNY; iy++)
void
Array2dFile<T>::doPixelOffsetScale (double offset, double scale)
{
- if (adf != NULL) {
- mOffsetPV = offset;
- mScalePV = scale;
-
- T** ad = adf->getArray();
- for (unsigned int ix = 0; ix < mNX; ix++)
- for (unsigned int iy = 0; iy < mNY; iy++)
- ad[ix][iy] = (ad[ix][iy] - offset) * scale;
+ T** ad = array.getArray();
+ if (ad) {
+ mOffsetPV = offset;
+ mScalePV = scale;
+
+ for (unsigned int ix = 0; ix < mNX; ix++)
+ for (unsigned int iy = 0; iy < mNY; iy++)
+ ad[ix][iy] = (ad[ix][iy] - offset) * scale;
}
}
return (false);
}
+ T** da = array.getArray();
+ if (! da)
+ return (false);
+
lseek (file_id, headersize, SEEK_SET);
for (unsigned int ix = 0; ix < mNX; ix++)
for (unsigned int iy = 0; iy < mNY; iy++) {
- T value = array->array_data[ix][iy];
+ T value = da[ix][iy];
ConvertReverseNetworkOrder (&value, sizeof(T));
- write (file_id, &value, mPixelSize);
+ write (file_id, &value, mPixelSize);
}
return (true);
return (false);
}
+ T** da = array.getArray();
+ if (! da)
+ return (false);
+
lseek (file_id, headersize, SEEK_SET);
T pixelBuffer;
for (int ix = 0; ix < mNX; ix++)
for (unsigned int iy = 0; iy < mNY; iy++) {
read (file_id, &pixelBuffer, mPixelSize);
ConvertReverseNetworkOrder (&pixelBuffer, sizeof(T));
- array->array_data[ix][iy] = pixelBuffer;
+ da[ix][iy] = pixelBuffer;
}
return (true);
return (false);
}
- if (array == NULL) { // Could not have written data if array not allocated
+ if (array.getArray() == NULL) { // Could not have written data if array not allocated
sys_error (ERR_WARNING, "array == NULL [labelSeek]");
return (false);
}
- off_t pos = headersize + array->sizeofArray();
+ off_t pos = headersize + array.sizeofArray();
if (lseek (file_id, pos, SEEK_SET) != pos) {
sys_error (ERR_WARNING, "Can't seek to end of data array");
return (false);
void
Array2dFile<T>::arrayDataClear (void)
{
- if (array != NULL) {
- T** v = array->getArray();
+ T** v = array.getArray();
+ if (v) {
for (unsigned int ix = 0; ix < mNX; ix++)
for (unsigned int iy = 0; iy < mNY; iy++)
v[ix][iy] = 0;
}
-#ifdef MPI_CT
-#include <mpi.h>
+#ifdef HAVE_MPI
+#include <mpi++.h>
#endif
-class F32Image
+class F32Image : public Array2dFile<kfloat32>
{
public:
- Array2dFile<kfloat32> adf;
-
- F32Image (const char* const fname, unsigned int nx, unsigned int ny) : adf (fname, nx, ny)
+ F32Image (const char* const fname, unsigned int nx, unsigned int ny)
+ : Array2dFile<kfloat32>::Array2dFile (fname, nx, ny)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT32);
+ setPixelType (FLOAT32);
}
- F32Image (unsigned int nx, unsigned int ny) : adf (nx, ny)
+ F32Image (unsigned int nx, unsigned int ny)
+ : Array2dFile<kfloat32>::Array2dFile (nx, ny)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT32);
+ setPixelType (FLOAT32);
}
- F32Image (const char* const fname) : adf (fname)
+ F32Image (const char* const fname)
+ : Array2dFile<kfloat32>::Array2dFile (fname)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT32);
+ setPixelType (FLOAT32);
}
- kfloat32** getArray(void) const
- { return adf.getArray(); }
-
- kuint32 nx(void) const
- { return adf.nx(); }
-
- kuint32 ny(void) const
- { return adf.ny(); }
-
#ifdef HAVE_MPI
MPI::Datatype getMPIDataType (void) const
{ return MPI::FLOAT; }
};
-class F64Image
+class F64Image : public Array2dFile<kfloat64>
{
-public:
- Array2dFile<kfloat64> adf;
-
-#ifdef HAVE_MPI
- MPI::Datatype getMPIDataType (void) const
- { return MPI::DOUBLE; }
-#endif
+ public:
- F64Image (const char* const fname, unsigned int nx, unsigned int ny) : adf (fname, nx, ny)
+ F64Image (const char* const fname, unsigned int nx, unsigned int ny)
+ : Array2dFile<kfloat64>::Array2dFile (fname, nx, ny)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT64);
+ setPixelType (FLOAT64);
}
- F64Image (unsigned int nx, unsigned int ny) : adf (nx, ny)
+ F64Image (unsigned int nx, unsigned int ny)
+ : Array2dFile<kfloat64>::Array2dFile (nx, ny)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT64);
+ setPixelType (FLOAT64);
}
- F64Image (const char* const fname) : adf (fname)
+ F64Image (const char* const fname)
+ : Array2dFile<kfloat64>::Array2dFile (fname)
{
- adf.setPixelType (Array2dFile<kfloat64>::FLOAT64);
+ setPixelType (FLOAT64);
}
- kfloat64** getArray(void) const
- { return adf.getArray(); }
-
- kuint32 nx(void) const
- { return adf.nx(); }
-
- kuint32 ny(void) const
- { return adf.ny(); }
+#ifdef HAVE_MPI
+ MPI::Datatype getMPIDataType (void) const
+ { return MPI::DOUBLE; }
+#endif
};
+#define IMAGEFILE_64_BITS 1
+#ifdef IMAGEFILE_64_BITS
typedef F64Image ImageFile;
typedef kfloat64 ImageFileValue;
typedef kfloat64* ImageFileColumn;
typedef kfloat64** ImageFileArray;
+#else
+typedef F32Image ImageFile;
+typedef kfloat32 ImageFileValue;
+typedef kfloat32* ImageFileColumn;
+typedef kfloat32** ImageFileArray;
+#endif
#endif
** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: ctrec.cpp,v 1.5 2000/06/09 01:35:33 kevin Exp $
+** $Id: ctrec.cpp,v 1.6 2000/06/09 11:03:08 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
if (mpiWorld.getRank() == 0) {
im_global = new ImageFile (im_filename, nx, ny);
- im_global->adf.fileCreate();
+ im_global->fileCreate();
}
im_local = new ImageFile (nx, ny);
print_raysum_info(rs_global);
im_global = new ImageFile (im_filename, nx, ny);
- im_global->adf.fileCreate();
+ im_global->fileCreate();
#endif
#ifdef HAVE_MPI
if (opt_verbose)
mpi_t1 = MPI::Wtime();
- int nxLocal = im_local->adf.nx();
- int nyLocal = im_local->adf.ny();
+ int nxLocal = im_local->nx();
+ int nyLocal = im_local->ny();
ImageFileArray vLocal = im_local->getArray();
ImageFileArray vGlobal = NULL;
if (mpiWorld.getRank() == 0)
{
raysum_close (rs_global);
double calctime = time_end - time_start;
- im_global->adf.arrayDataWrite ();
- im_global->adf.labelAdd (Array2dFileLabel::L_HISTORY, rs_global->remark, rs_global->calctime);
- im_global->adf.labelAdd (Array2dFileLabel::L_HISTORY, remark, calctime);
- im_global->adf.fileClose ();
+ im_global->arrayDataWrite ();
+ im_global->labelAdd (Array2dFileLabel::L_HISTORY, rs_global->remark, rs_global->calctime);
+ im_global->labelAdd (Array2dFileLabel::L_HISTORY, remark, calctime);
+ im_global->fileClose ();
if (opt_verbose)
cout << "Time active = " << calctime << " sec" << endl;
}
** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: if-1.cpp,v 1.4 2000/06/08 16:43:10 kevin Exp $
+** $Id: if-1.cpp,v 1.5 2000/06/09 11:03:08 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
int ix, iy;
im_in = new ImageFile (in_file);
- im_in->adf.fileRead ();
+ im_in->fileRead ();
int nx = im_in->nx();
int ny = im_in->ny();
im_out = new ImageFile (out_file, nx, ny);
- im_out->adf.fileCreate ();
+ im_out->fileCreate ();
ImageFileArray vIn = im_in->getArray();
ImageFileArray vOut = im_out->getArray();
histString = "Sqrt transformation";
}
- im_out->adf.arrayDataWrite ();
- im_out->adf.labelsCopy (im_in->adf);
- im_out->adf.labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
- im_out->adf.fileClose ();
+ im_out->arrayDataWrite ();
+ im_out->labelsCopy (*im_in);
+ im_out->labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
+ im_out->fileClose ();
}
return (0);
** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: if-2.cpp,v 1.2 2000/06/08 16:43:10 kevin Exp $
+** $Id: if-2.cpp,v 1.3 2000/06/09 11:03:08 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
ImageFile& im_in1 = *pim_in1;
ImageFile& im_in2 = *pim_in2;
- if (! im_in1.adf.fileRead() || ! im_in2.adf.fileRead()) {
+ if (! im_in1.fileRead() || ! im_in2.fileRead()) {
sys_error (ERR_WARNING, "Error reading an image");
return (1);
}
pim_out = new ImageFile (out_file, im_in1.nx(), im_in1.ny());
ImageFile& im_out = *pim_out;
- if (! im_out.adf.fileCreate()) {
+ if (! im_out.fileCreate()) {
sys_error (ERR_WARNING, "Could not open output file %s", out_file);
return (1);
}
fprintf(stdout, "Average Error = %f\n", abs_error);
}
- im_out.adf.arrayDataWrite();
- im_out.adf.labelsCopy (im_in1.adf, "if-2 file 1: ");
- im_out.adf.labelsCopy (im_in2.adf, "if-2 file 2: ");
- im_out.adf.labelAdd (Array2dFileLabel::L_HISTORY, strOperation.c_str());
+ im_out.arrayDataWrite();
+ im_out.labelsCopy (im_in1, "if-2 file 1: ");
+ im_out.labelsCopy (im_in2, "if-2 file 2: ");
+ im_out.labelAdd (Array2dFileLabel::L_HISTORY, strOperation.c_str());
- im_out.adf.fileClose();
+ im_out.fileClose();
return (0);
}
** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: if2img.cpp,v 1.2 2000/06/08 16:43:10 kevin Exp $
+** $Id: if2img.cpp,v 1.3 2000/06/09 11:03:08 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
pim = new ImageFile (in_file);
ImageFile& im = *pim;
- if (! im.adf.fileRead()) {
+ if (! im.fileRead()) {
fprintf(stderr, "File %s does not exist\n", in_file);
return (1);
}
if (opt_labels) {
- int nlabels = im.adf.getNumLabels();
+ int nlabels = im.getNumLabels();
for (int i = 0; i < nlabels; i++) {
Array2dFileLabel label;
- im.adf.labelRead (label, i);
+ im.labelRead (label, i);
string str;
label.getDateString (str);
** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: ifinfo.cpp,v 1.4 2000/06/08 16:43:10 kevin Exp $
+** $Id: ifinfo.cpp,v 1.5 2000/06/09 11:03:08 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
in_file = argv[optind];
im = new ImageFile (in_file);
- if (! im->adf.fileRead ()) {
+ if (! im->fileRead ()) {
sys_error (ERR_WARNING, "Unable to read file %s", in_file);
return (1);
}
if (opt_labels)
{
- int nlabels = im->adf.getNumLabels();
+ int nlabels = im->getNumLabels();
int i;
for (i = 0; i < nlabels; i++)
{
Array2dFileLabel label;
- im->adf.labelRead (label, i);
+ im->labelRead (label, i);
string str;
label.getDateString (str);
** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: phm2if.cpp,v 1.6 2000/06/09 01:35:33 kevin Exp $
+** $Id: phm2if.cpp,v 1.7 2000/06/09 11:03:08 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
if (mpiWorld.getRank() == 0) {
im_global = new ImageFile (opt_outfile, opt_nx, opt_ny);
- im_global->adf.fileCreate();
+ im_global->fileCreate();
}
im_local = new ImageFile (opt_nx, opt_ny);
#else
im_global = new ImageFile (opt_outfile, opt_nx, opt_ny);
- im_global->adf.fileCreate ();
+ im_global->fileCreate ();
#endif
if (opt_phmnum >= 0)
if (mpiWorld.getRank() == 0)
#endif
{
- im_global->adf.arrayDataWrite ();
+ im_global->arrayDataWrite ();
calctime = time_end - time_start;
- im_global->adf.labelAdd (Array2dFileLabel::L_HISTORY, opt_desc, calctime);
- im_global->adf.fileClose ();
+ im_global->labelAdd (Array2dFileLabel::L_HISTORY, opt_desc, calctime);
+ im_global->fileClose ();
if (opt_verbose)
fprintf (stdout, "Time to compile image = %.2f sec\n\n", calctime);
** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: rs2if.cpp,v 1.3 2000/06/08 16:43:10 kevin Exp $
+** $Id: rs2if.cpp,v 1.4 2000/06/09 11:03:08 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
detarray_free (detarray);
raysum_close (rs);
- im->adf.fileCreate ();
- im->adf.arrayDataWrite ();
- im->adf.labelAdd (Array2dFileLabel::L_HISTORY, rs->remark, rs->calctime);
- im->adf.labelAdd (Array2dFileLabel::L_HISTORY, "Conversion from .rs to .idf");
- im->adf.fileClose ();
+ im->fileCreate ();
+ im->arrayDataWrite ();
+ im->labelAdd (Array2dFileLabel::L_HISTORY, rs->remark, rs->calctime);
+ im->labelAdd (Array2dFileLabel::L_HISTORY, "Conversion from .rs to .idf");
+ im->fileClose ();
return(0);
}