X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=include%2Farray2dfile.h;h=b49e04a25ed80c89d5d9b90d459d6a0087dde9ca;hp=8104129d5c1129328919adae7583ef02561fb733;hb=c00c639073653fac7463a88f2b000f263236550d;hpb=3e346e67f7f7a331919a32439b0f54a4d53d3029 diff --git a/include/array2dfile.h b/include/array2dfile.h index 8104129..b49e04a 100644 --- a/include/array2dfile.h +++ b/include/array2dfile.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: array2dfile.h,v 1.3 2000/06/28 15:25:34 kevin Exp $ +** $Id: array2dfile.h,v 1.18 2001/01/02 16:02:12 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 @@ -28,10 +28,15 @@ #ifndef ARRAY2DFILE_H #define ARRAY2DFILE_H -#include -#include +#ifndef MSVC #include +#endif + +#include +#include #include +#include +#include #include #include #include @@ -39,14 +44,14 @@ #include "fnetorderstream.h" #include "array2d.h" -using namespace std; - class Array2dFileLabel { public: - static const int L_EMPTY = 0; - static const int L_HISTORY = 1; - static const int L_USER = 2; + enum { + L_EMPTY = 0, + L_HISTORY = 1, + L_USER = 2, + }; Array2dFileLabel(); @@ -56,7 +61,7 @@ public: ~Array2dFileLabel(); - const string& getLabelString (void) const + const std::string& getLabelString (void) const { return m_strLabel; } kfloat64 getCalcTime (void) const @@ -71,19 +76,21 @@ public: int getLabelType (void) const { return m_labelType; } - string& setLabelString (const char* const str) + std::string& setLabelString (const char* const str) { m_strLabel = str; return (m_strLabel); } - string& setLabelString (const string& str) + std::string& setLabelString (const std::string& str) { m_strLabel = str; return (m_strLabel); } void setDateTime (int year, int month, int day, int hour, int minute, int second); void getDateTime (int& year, int& month, int& day, int& hour, int& minute, int& second) const; - const string& getDateString () const; + const std::string& getDateString () const; - void print (ostream& os) const; + void print (std::ostream& os) const; + void printBrief (std::ostream& os) const; + void printBrief (std::ostringstream& os) const; Array2dFileLabel (const Array2dFileLabel& rhs); @@ -99,31 +106,39 @@ private: kuint16 m_hour; kuint16 m_minute; kuint16 m_second; - string m_strLabel; + std::string m_strLabel; kfloat64 m_calcTime; - mutable string m_strDate; + mutable std::string m_strDate; }; class Array2dFile { public: - static const int PIXEL_INVALID = 0; - static const int PIXEL_INT8 = 1; - static const int PIXEL_UINT8 = 2; - static const int PIXEL_INT16 = 3; - static const int PIXEL_UINT16 = 4; - static const int PIXEL_INT32 = 5; - static const int PIXEL_UINT32 = 6; - static const int PIXEL_FLOAT32 = 7; - static const int PIXEL_FLOAT64 = 8; - - Array2dFile (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID); + enum { + PIXEL_INVALID = 0, + PIXEL_INT8 = 1, + PIXEL_UINT8 = 2, + PIXEL_INT16 = 3, + PIXEL_UINT16 = 4, + PIXEL_INT32 = 5, + PIXEL_UINT32 = 6, + PIXEL_FLOAT32 = 7, + PIXEL_FLOAT64 = 8, + }; + + enum { + DATA_TYPE_INVALID = 0, + DATA_TYPE_REAL, + DATA_TYPE_COMPLEX, + }; + + Array2dFile (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID, int dataType = DATA_TYPE_REAL); Array2dFile (void); ~Array2dFile (); - void setArraySize (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID); + void setArraySize (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID, int dataType = DATA_TYPE_REAL); void setArraySize (int nx, int ny); @@ -138,7 +153,7 @@ public: void labelAdd (int type, const char* const m_strLabel, double calc_time=0.); - void labelsCopy (Array2dFile& file, const char* const idStr = NULL); + void labelsCopy (const Array2dFile& file, const char* const idStr = NULL); void setPixelFormat (int type) { m_pixelFormat = type; } @@ -152,11 +167,26 @@ public: kuint32 ny (void) const { return m_ny; } + bool isComplex() const + { return m_dataType == DATA_TYPE_COMPLEX; } + + bool isReal() const + { return m_dataType == DATA_TYPE_REAL; } + + int dataType () const + { return static_cast(m_dataType); } + + void setDataType (int dataType) + { m_dataType = dataType; } + void setAxisIncrement (double axisIncX, double axisIncY); - void setAxisExtent (double minX, double maxX, double minY, double maxY); + bool reallocRealToComplex (); + + bool reallocComplexToReal (); void getPixelValueRange (double& pvmin, double& pvmax) const; + void setAxisExtent (double minX, double maxX, double minY, double maxY); void doPixelOffsetScale (double offset, double scale); @@ -164,22 +194,31 @@ public: bool fileRead (const char* const filename); + bool fileRead (const std::string& filename); + bool fileWrite (const char* const filename); - const string& getFilename (void) const + bool fileWrite (const std::string& filename); + + const std::string& getFilename (void) const { return m_filename; } - void printLabels (ostream& os) const; + void printLabels (std::ostream& os) const; + void printLabelsBrief (std::ostream& os) const; + void printLabelsBrief (std::ostringstream& os) const; - typedef vector::iterator labelIterator; - typedef vector::const_iterator constLabelIterator; + unsigned int nLabels() const + { return m_labels.size(); } + + typedef std::vector::iterator labelIterator; + typedef std::vector::const_iterator constLabelIterator; protected: - typedef vector labelContainer; + typedef std::vector labelContainer; - static const kuint16 m_signature = ('I'*256+'F'); + static const kuint16 m_signature; kuint16 m_headersize; - string m_filename; + std::string m_filename; kuint16 m_pixelSize; kuint16 m_pixelFormat; @@ -193,7 +232,9 @@ public: kuint32 m_arraySize; labelContainer m_labels; kuint16 m_numFileLabels; + kuint16 m_dataType; unsigned char** m_arrayData; + unsigned char** m_imaginaryArrayData; private: void init (void); @@ -212,9 +253,11 @@ private: bool labelSeek (int label_num); - void allocArray (void); - - void freeArray (void); + void allocArrays (); + void freeArrays (); + + void allocArray (unsigned char**& rppData); + void freeArray (unsigned char**& rppData); Array2dFile (const Array2dFile& rhs); // copy constructor Array2dFile& operator= (const Array2dFile&); // assignment operator