From: Kevin M. Rosenberg Date: Fri, 9 Jun 2000 11:03:08 +0000 (+0000) Subject: r91: Made ImageFile inherit from Array2dFile X-Git-Tag: debian-4.5.3-3~926 X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=commitdiff_plain;h=4b16507e92bb80b09575b28bed66810e33d2681f r91: Made ImageFile inherit from Array2dFile --- diff --git a/ChangeLog b/ChangeLog index 6b72c05..e4606bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +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) diff --git a/configure.in b/configure.in index 3a7ab6c..dcf7aee 100644 --- a/configure.in +++ b/configure.in @@ -4,7 +4,7 @@ dnl Must reset CDPATH so that bash's cd does not print to stdout 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. diff --git a/include/array2d.h b/include/array2d.h index 30b92d4..c4d4200 100644 --- a/include/array2d.h +++ b/include/array2d.h @@ -9,8 +9,11 @@ ** 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 ** @@ -36,40 +39,38 @@ template 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); } @@ -79,6 +80,33 @@ class Array2d { 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 }; diff --git a/include/imagefile.h b/include/imagefile.h index 19f5db0..7c0952c 100644 --- a/include/imagefile.h +++ b/include/imagefile.h @@ -90,7 +90,7 @@ private: public: - Array2d *array; + Array2d array; static const int INT8 = 1; static const int UINT8 = 2; @@ -139,7 +139,7 @@ public: void doPixelOffsetScale (double offset, double scale); T** getArray (void) const - { return (array == NULL ? NULL : array->getArray()); } + { return (array.getArray()); } bool arrayDataWrite (void); @@ -160,7 +160,7 @@ Array2dFile::Array2dFile (unsigned int x, unsigned int y) init(); mNX = x; mNY = y; - array = new Array2d (mNX, mNY); + array.initSetSize(mNX, mNY); } template @@ -170,7 +170,7 @@ Array2dFile::Array2dFile (const char * const str, unsigned int x, unsigned in init(); mNX = x; mNY = y; - array = new Array2d (mNX, mNY); + array.initSetSize(mNX, mNY); } template @@ -197,7 +197,6 @@ Array2dFile::init (void) mMinX = mMaxX = mMinY = mMaxY = 0; mOffsetPV = 0; mScalePV = 1; - array = NULL; io = NULL; #if 0 @@ -233,7 +232,6 @@ template Array2dFile::~Array2dFile (void) { fileClose (); - delete array; } @@ -272,10 +270,8 @@ Array2dFile::fileRead (void) } headerRead(); - if (array != NULL) - delete array; - array = new Array2d (mNX, mNY); + array.initSetSize(mNX, mNY); arrayDataRead(); @@ -306,8 +302,8 @@ template void Array2dFile::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++) @@ -322,14 +318,14 @@ template void Array2dFile::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; } } @@ -430,12 +426,16 @@ Array2dFile::arrayDataWrite (void) 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); @@ -450,13 +450,17 @@ Array2dFile::arrayDataRead (void) 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); @@ -471,12 +475,12 @@ Array2dFile::labelSeek (unsigned int label_num) 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); @@ -593,8 +597,8 @@ template void Array2dFile::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; @@ -602,39 +606,31 @@ Array2dFile::arrayDataClear (void) } -#ifdef MPI_CT -#include +#ifdef HAVE_MPI +#include #endif -class F32Image +class F32Image : public Array2dFile { public: - Array2dFile 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::Array2dFile (fname, nx, ny) { - adf.setPixelType (Array2dFile::FLOAT32); + setPixelType (FLOAT32); } - F32Image (unsigned int nx, unsigned int ny) : adf (nx, ny) + F32Image (unsigned int nx, unsigned int ny) + : Array2dFile::Array2dFile (nx, ny) { - adf.setPixelType (Array2dFile::FLOAT32); + setPixelType (FLOAT32); } - F32Image (const char* const fname) : adf (fname) + F32Image (const char* const fname) + : Array2dFile::Array2dFile (fname) { - adf.setPixelType (Array2dFile::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; } @@ -642,45 +638,46 @@ public: }; -class F64Image +class F64Image : public Array2dFile { -public: - Array2dFile 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::Array2dFile (fname, nx, ny) { - adf.setPixelType (Array2dFile::FLOAT64); + setPixelType (FLOAT64); } - F64Image (unsigned int nx, unsigned int ny) : adf (nx, ny) + F64Image (unsigned int nx, unsigned int ny) + : Array2dFile::Array2dFile (nx, ny) { - adf.setPixelType (Array2dFile::FLOAT64); + setPixelType (FLOAT64); } - F64Image (const char* const fname) : adf (fname) + F64Image (const char* const fname) + : Array2dFile::Array2dFile (fname) { - adf.setPixelType (Array2dFile::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 diff --git a/src/ctrec.cpp b/src/ctrec.cpp index 68b9ff6..ada1c10 100644 --- a/src/ctrec.cpp +++ b/src/ctrec.cpp @@ -9,7 +9,7 @@ ** 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 @@ -284,7 +284,7 @@ ctrec_main (int argc, char * argv[]) 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); @@ -295,7 +295,7 @@ ctrec_main (int argc, char * argv[]) print_raysum_info(rs_global); im_global = new ImageFile (im_filename, nx, ny); - im_global->adf.fileCreate(); + im_global->fileCreate(); #endif #ifdef HAVE_MPI @@ -317,8 +317,8 @@ ctrec_main (int argc, char * argv[]) 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) @@ -353,10 +353,10 @@ ctrec_main (int argc, char * argv[]) { 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; } diff --git a/src/if-1.cpp b/src/if-1.cpp index bfdd9dd..e2993a5 100644 --- a/src/if-1.cpp +++ b/src/if-1.cpp @@ -9,7 +9,7 @@ ** 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 @@ -136,11 +136,11 @@ if1_main (int argc, char *const argv[]) 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(); @@ -176,10 +176,10 @@ if1_main (int argc, char *const argv[]) 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); diff --git a/src/if-2.cpp b/src/if-2.cpp index 4368c17..51fc23d 100644 --- a/src/if-2.cpp +++ b/src/if-2.cpp @@ -9,7 +9,7 @@ ** 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 @@ -131,7 +131,7 @@ sdf2_main (int argc, char *const argv[]) 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); } @@ -148,7 +148,7 @@ sdf2_main (int argc, char *const argv[]) 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); } @@ -202,12 +202,12 @@ sdf2_main (int argc, char *const argv[]) 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); } diff --git a/src/if2img.cpp b/src/if2img.cpp index d25c394..a99b801 100644 --- a/src/if2img.cpp +++ b/src/if2img.cpp @@ -9,7 +9,7 @@ ** 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 @@ -281,17 +281,17 @@ if2img_main (int argc, char *const argv[]) 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); diff --git a/src/ifinfo.cpp b/src/ifinfo.cpp index bc55c1e..a78a085 100644 --- a/src/ifinfo.cpp +++ b/src/ifinfo.cpp @@ -9,7 +9,7 @@ ** 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 @@ -127,20 +127,20 @@ ifinfo_main (int argc, char *const argv[]) 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); diff --git a/src/phm2if.cpp b/src/phm2if.cpp index 66ceb47..63d5a49 100644 --- a/src/phm2if.cpp +++ b/src/phm2if.cpp @@ -9,7 +9,7 @@ ** 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 @@ -317,12 +317,12 @@ phm2sdf_main (int argc, char* argv[]) 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) @@ -395,10 +395,10 @@ phm2sdf_main (int argc, char* argv[]) 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); diff --git a/src/rs2if.cpp b/src/rs2if.cpp index 42a8220..82ed201 100644 --- a/src/rs2if.cpp +++ b/src/rs2if.cpp @@ -9,7 +9,7 @@ ** 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 @@ -136,11 +136,11 @@ rs2if_main (const int argc, char *const argv[]) 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); }