X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;ds=sidebyside;f=include%2Fimagefile.h;h=19f5db07354362fba69b22bf48c313f93981af0c;hb=2451ac413848718a1dd666ce6f6464e974680f47;hp=a6988d8e76b909c77f395909894203901f257a5b;hpb=dc41bc610efe1cfb7b29f715dcc036b879db1f44;p=ctsim.git diff --git a/include/imagefile.h b/include/imagefile.h index a6988d8..19f5db0 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; }; @@ -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,7 +134,7 @@ 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); @@ -133,6 +143,8 @@ public: bool arrayDataWrite (void); + void arrayDataClear (void); + bool fileRead (void); bool fileCreate (void); @@ -221,6 +233,7 @@ template Array2dFile::~Array2dFile (void) { fileClose (); + delete array; } @@ -228,11 +241,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; } } @@ -292,18 +304,18 @@ 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(); + if (array != NULL) { + T** da = array->getArray(); 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 @@ -422,7 +434,7 @@ Array2dFile::arrayDataWrite (void) 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)); + ConvertReverseNetworkOrder (&value, sizeof(T)); write (file_id, &value, mPixelSize); } @@ -443,7 +455,7 @@ Array2dFile::arrayDataRead (void) for (int ix = 0; ix < mNX; ix++) for (unsigned int iy = 0; iy < mNY; iy++) { read (file_id, &pixelBuffer, mPixelSize); - ConvertNetworkOrder (&pixelBuffer, sizeof(T)); + ConvertReverseNetworkOrder (&pixelBuffer, sizeof(T)); array->array_data[ix][iy] = pixelBuffer; } @@ -562,8 +574,33 @@ 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); + } +} + +template +void +Array2dFile::arrayDataClear (void) +{ + if (array != NULL) { + T** v = array->getArray(); + for (unsigned int ix = 0; ix < mNX; ix++) + for (unsigned int iy = 0; iy < mNY; iy++) + v[ix][iy] = 0; + } +} -#endif #ifdef MPI_CT #include @@ -589,20 +626,30 @@ public: adf.setPixelType (Array2dFile::FLOAT32); } -#ifdef MPI_CT - MPI_Datatype getMPIDataType (void) const - { return MPI_FLOAT; } + 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; } #endif }; + class F64Image { public: Array2dFile adf; -#ifdef MPI_CT - MPI_Datatype getMPIDataType (void) const - { return MPI_DOUBLE; } +#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) @@ -619,6 +666,15 @@ public: { adf.setPixelType (Array2dFile::FLOAT64); } + + kfloat64** getArray(void) const + { return adf.getArray(); } + + kuint32 nx(void) const + { return adf.nx(); } + + kuint32 ny(void) const + { return adf.ny(); } }; typedef F64Image ImageFile; @@ -626,5 +682,7 @@ typedef kfloat64 ImageFileValue; typedef kfloat64* ImageFileColumn; typedef kfloat64** ImageFileArray; +#endif +