X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=include%2Fimagefile.h;h=70c3fe40b4f914b1364fd33c235a81f7cc1b83c1;hp=19f5db07354362fba69b22bf48c313f93981af0c;hb=a62ba7c54d39fcf1e469c8df169018fa60ae7c3b;hpb=2451ac413848718a1dd666ce6f6464e974680f47 diff --git a/include/imagefile.h b/include/imagefile.h index 19f5db0..70c3fe4 100644 --- a/include/imagefile.h +++ b/include/imagefile.h @@ -13,6 +13,8 @@ class Array2dFileLabel { private: void init (void); + Array2dFileLabel (const Array2dFileLabel&); + Array2dFileLabel& operator= (const Array2dFileLabel&); public: kfloat64 calc_time; @@ -88,9 +90,12 @@ private: kuint32 mNX; kuint32 mNY; + Array2dFile (const Array2dFile&); + Array2dFile& operator= (const Array2dFile&); + public: - Array2d *array; + Array2d array; static const int INT8 = 1; static const int UINT8 = 2; @@ -139,7 +144,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 +165,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 +175,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 +202,6 @@ Array2dFile::init (void) mMinX = mMaxX = mMinY = mMaxY = 0; mOffsetPV = 0; mScalePV = 1; - array = NULL; io = NULL; #if 0 @@ -233,7 +237,6 @@ template Array2dFile::~Array2dFile (void) { fileClose (); - delete array; } @@ -272,10 +275,8 @@ Array2dFile::fileRead (void) } headerRead(); - if (array != NULL) - delete array; - array = new Array2d (mNX, mNY); + array.initSetSize(mNX, mNY); arrayDataRead(); @@ -306,8 +307,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 +323,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 +431,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 +455,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 +480,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 +602,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 +611,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 +643,46 @@ public: }; -class F64Image +class F64Image : public Array2dFile { -public: - Array2dFile adf; + public: -#ifdef HAVE_MPI - MPI::Datatype getMPIDataType (void) const - { return MPI::DOUBLE; } -#endif - - 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