X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=include%2Fimagefile.h;h=7c0952c2acc568e8b96897a011637ac77074baa5;hp=2c145e0ba6b9de2998222a47b0c6cea3fdd75bdc;hb=4b16507e92bb80b09575b28bed66810e33d2681f;hpb=92a7e95f339442d5d87f0febcae338306e1c6edd diff --git a/include/imagefile.h b/include/imagefile.h index 2c145e0..7c0952c 100644 --- a/include/imagefile.h +++ b/include/imagefile.h @@ -3,6 +3,8 @@ #include #include "kstddef.h" +#include +#include #include using namespace std; @@ -35,7 +37,7 @@ public: ~Array2dFileLabel(); - const string& getLabelString (void) const + string getLabelString (void) const { return label_str; } kfloat64 getCalcTime (void) const @@ -44,6 +46,12 @@ public: kfloat64 getLabelType (void) const { return label_type; } + string& setLabelString (const char* const str) + { label_str = str; return (label_str); } + + string& setLabelString (const string& str) + { label_str = str; return (label_str); } + void getDateString (string& str) const; }; @@ -82,7 +90,7 @@ private: public: - Array2d *array; + Array2d array; static const int INT8 = 1; static const int UINT8 = 2; @@ -109,6 +117,8 @@ public: void labelAdd (int type, const char* const label_str, double calc_time=0.); + void labelsCopy (Array2dFile& file, const char* const idStr = NULL); + void fileClose (void); void setPixelType (int type) @@ -124,15 +134,17 @@ public: void setAxisExtent (double mMinX, double mMaxX, double mMinY, double mMaxY); - void getPixelValueRange (T& pvmin, T& pvmax); + void getPixelValueRange (T& pvmin, T& pvmax) const; void doPixelOffsetScale (double offset, double scale); T** getArray (void) const - { return (array == NULL ? NULL : array->getArray()); } + { return (array.getArray()); } bool arrayDataWrite (void); + void arrayDataClear (void); + bool fileRead (void); bool fileCreate (void); @@ -148,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 @@ -158,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 @@ -185,7 +197,6 @@ Array2dFile::init (void) mMinX = mMaxX = mMinY = mMaxY = 0; mOffsetPV = 0; mScalePV = 1; - array = NULL; io = NULL; #if 0 @@ -228,11 +239,10 @@ template void Array2dFile::fileClose (void) { - headerWrite (); - if (file_id >= 0 && array != NULL) { - arrayDataWrite (); - close (file_id); - file_id = -1; + if (file_id >= 0) { + headerWrite (); + close (file_id); + file_id = -1; } } @@ -260,10 +270,8 @@ Array2dFile::fileRead (void) } headerRead(); - if (array != NULL) - delete array; - array = new Array2d (mNX, mNY); + array.initSetSize(mNX, mNY); arrayDataRead(); @@ -292,32 +300,32 @@ Array2dFile::setAxisExtent (double minX, double maxX, double minY, double max template void -Array2dFile::getPixelValueRange (T& pvmin, T& pvmax) +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++) - if (pvmax < da[ix][iy]) - pvmax = da[ix][iy]; - else if (pvmin > da[ix][iy]) + for (int ix = 0; ix < mNX; ix++) + for (int iy = 0; iy < mNY; iy++) + if (pvmax < da[ix][iy]) + pvmax = da[ix][iy]; + else if (pvmin > da[ix][iy]) pvmin = da[ix][iy]; - } + } } 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; } } @@ -418,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]; - ConvertNetworkOrder (&value, sizeof(T)); - write (file_id, &array->array_data[ix][iy], mPixelSize); + T value = da[ix][iy]; + ConvertReverseNetworkOrder (&value, sizeof(T)); + write (file_id, &value, mPixelSize); } return (true); @@ -438,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); - ConvertNetworkOrder (&pixelBuffer, sizeof(T)); - array->array_data[ix][iy] = pixelBuffer; + ConvertReverseNetworkOrder (&pixelBuffer, sizeof(T)); + da[ix][iy] = pixelBuffer; } return (true); @@ -459,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); @@ -562,69 +578,108 @@ Array2dFile::labelAdd (const Array2dFileLabel& label) fsync(file_id); } +template +void +Array2dFile::labelsCopy (Array2dFile& copyFile, const char* const idStr) +{ + string id = idStr; + for (int i = 0; i < copyFile.getNumLabels(); i++) { + Array2dFileLabel l; + copyFile.labelRead (l, i); + string lstr = l.getLabelString(); + lstr = idStr + lstr; + l.setLabelString (lstr); + labelAdd (l); + } +} -#endif +template +void +Array2dFile::arrayDataClear (void) +{ + 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 + +#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); } -#ifdef MPI_CT - MPI_Datatype getMPIDataType (void) const - { return MPI_FLOAT; } +#ifdef HAVE_MPI + MPI::Datatype getMPIDataType (void) const + { return MPI::FLOAT; } #endif }; -class F64Image -{ -public: - Array2dFile adf; -#ifdef MPI_CT - MPI_Datatype getMPIDataType (void) const - { return MPI_DOUBLE; } -#endif +class F64Image : public Array2dFile +{ + 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); } + +#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