From: Kevin M. Rosenberg Date: Fri, 29 Dec 2000 19:30:08 +0000 (+0000) Subject: r319: add complex-valued imagefile support X-Git-Tag: debian-4.5.3-3~698 X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=commitdiff_plain;h=67a6c34b5a6f38d34e8cbe66091853f453fd2d7a r319: add complex-valued imagefile support --- diff --git a/ChangeLog b/ChangeLog index 91c26bc..029264e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ TODO Read PlotFile's. - + Add to ctsim export of imagefiles to standard graphic formats. + Use FFTW library in imagefile.cpp 3.0alpha1 - Released 12/30/00 @@ -15,14 +16,19 @@ TODO files. * ctsim: Added "Process" menu to image file display with math - functions. Added 2-dimensional inverse Fourier to math functions. + functions. Added 2-dimensional inverse Fourier to math + functions. Added support for complex (real/imaginary) images. * mathfuncs.cpp: Reworked statistics algorithm to share between imagefile and plotfile classes. * imagefile.cpp: Fixed scaling bug when rasterizing Phantom with nsamples > 2. Added generic mage math functions, moved from - if1.cpp and if2.cpp to imagefile.cpp + if1.cpp and if2.cpp to imagefile.cpp. Added support complex + images. + + * array2dfile.cpp: Added code to support complex (real/imaginary) + images. * if1: Updated to handle error conditions, such as sqrt of a negative number. Converted to use new ImageFile math functions. diff --git a/include/array2dfile.h b/include/array2dfile.h index 21023dc..754ad93 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.12 2000/12/16 06:12:47 kevin Exp $ +** $Id: array2dfile.h,v 1.13 2000/12/29 19:30: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 @@ -125,12 +125,18 @@ public: PIXEL_FLOAT32 = 7, PIXEL_FLOAT64 = 8, }; - - Array2dFile (int nx, int ny, int pixelSize, int pixelFormat = PIXEL_INVALID); + + 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); @@ -158,12 +164,21 @@ public: kuint32 ny (void) const { return m_ny; } + + 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 getPixelValueRange (double& pvmin, double& pvmax) const; + void setAxisExtent (double minX, double maxX, double minY, double maxY); void doPixelOffsetScale (double offset, double scale); @@ -203,8 +218,10 @@ public: kuint32 m_ny; kuint32 m_arraySize; labelContainer m_labels; - kuint16 m_numFileLabels; + kuint16 m_numFileLabels; + kuint16 m_dataType; unsigned char** m_arrayData; + unsigned char** m_imaginaryArrayData; private: void init (void); @@ -223,9 +240,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 diff --git a/include/imagefile.h b/include/imagefile.h index 7c7daba..57d093f 100644 --- a/include/imagefile.h +++ b/include/imagefile.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: imagefile.h,v 1.24 2000/12/29 15:45:06 kevin Exp $ +** $Id: imagefile.h,v 1.25 2000/12/29 19:30: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 @@ -46,15 +46,21 @@ class F32Image : public Array2dFile { public: - F32Image (int nx, int ny); + F32Image (int nx, int ny, int dataType = Array2dFile::DATA_TYPE_REAL); F32Image (void); - kfloat32** getArray (void) - { return (kfloat32**) (m_arrayData); } - - kfloat32** const getArray (void) const - { return (kfloat32** const) (m_arrayData); } - + kfloat32** getArray (void) + { return (kfloat32**) (m_arrayData); } + + kfloat32** const getArray (void) const + { return (kfloat32** const) (m_arrayData); } + + kfloat32** getImaginaryArray (void) + { return (kfloat32**) (m_imaginaryArrayData); } + + kfloat32** const getImaginaryArray (void) const + { return (kfloat32** const) (m_imaginaryArrayData); } + #ifdef HAVE_MPI MPI::Datatype getMPIDataType (void) const { return MPI::FLOAT; } @@ -70,15 +76,21 @@ class F64Image : public Array2dFile { public: - F64Image (int nx, int ny); + F64Image (int nx, int ny, int dataType = Array2dFile::DATA_TYPE_REAL); F64Image (void); - kfloat64** getArray (void) - { return (kfloat64**) (m_arrayData); } - - kfloat64** const getArray (void) const - { return (kfloat64** const) (m_arrayData); } - + kfloat64** getArray (void) + { return (kfloat64**) (m_arrayData); } + + kfloat64** const getArray (void) const + { return (kfloat64** const) (m_arrayData); } + + kfloat64** getImaginaryArray (void) + { return (kfloat64**) (m_imaginaryArrayData); } + + kfloat64** const getImaginaryArray (void) const + { return (kfloat64** const) (m_imaginaryArrayData); } + #ifdef HAVE_MPI MPI::Datatype getMPIDataType (void) const { return MPI::DOUBLE; } @@ -116,10 +128,14 @@ class ImageFile : public ImageFileBase ImageFile (void) : ImageFileBase () {} + + bool convertRealToComplex (); + bool convertComplexToReal (); void filterResponse (const char* const domainName, double bw, const char* const filterName, double filt_param); - void statistics (double& min, double& max, double& mean, double& mode, double& median, double& stddev) const; + void statistics (double& min, double& max, double& mean, double& mode, double& median, double& stddev) const; + void statistics (ImageFileArrayConst& v, double& min, double& max, double& mean, double& mode, double& median, double& stddev) const; void getMinMax (double& min, double& max) const; void printStatistics (std::ostream& os) const; bool comparativeStatistics (const ImageFile& imComp, double& d, double& r, double& e) const; @@ -135,8 +151,10 @@ class ImageFile : public ImageFileBase bool square (ImageFile& result) const; bool log (ImageFile& result) const; bool exp (ImageFile& result) const; - bool FFTMagnitude (ImageFile& result) const; - bool FFTPhase (ImageFile& result) const; + bool fourier (ImageFile& result) const; + bool inverseFourier (ImageFile& result) const; + bool magnitude (ImageFile& result) const; + bool phase (ImageFile& result) const; int display (void) const; int displayScaling (const int scaleFactor, ImageFileValue pmin, ImageFileValue pmax) const; diff --git a/libctsim/array2dfile.cpp b/libctsim/array2dfile.cpp index 6c400ad..ca45d8b 100644 --- a/libctsim/array2dfile.cpp +++ b/libctsim/array2dfile.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: array2dfile.cpp,v 1.21 2000/12/16 06:12:47 kevin Exp $ +** $Id: array2dfile.cpp,v 1.22 2000/12/29 19:30: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 @@ -44,39 +44,39 @@ const kuint16 Array2dFile::m_signature = ('I'*256+'F'); void Array2dFileLabel::init (void) { - m_calcTime = 0; - m_labelType = L_EMPTY; - time_t t = time(0); - tm* lt = localtime(&t); - m_year = lt->tm_year; - m_month = lt->tm_mon; - m_day = lt->tm_mday; - m_hour = lt->tm_hour; - m_minute = lt->tm_min; - m_second = lt->tm_sec; + m_calcTime = 0; + m_labelType = L_EMPTY; + time_t t = time(0); + tm* lt = localtime(&t); + m_year = lt->tm_year; + m_month = lt->tm_mon; + m_day = lt->tm_mday; + m_hour = lt->tm_hour; + m_minute = lt->tm_min; + m_second = lt->tm_sec; } Array2dFileLabel::Array2dFileLabel() { - init(); + init(); } Array2dFileLabel::Array2dFileLabel(const char* const str, double ctime) - : m_strLabel (str) +: m_strLabel (str) { - init(); - - m_labelType = L_USER; - m_calcTime = ctime; + init(); + + m_labelType = L_USER; + m_calcTime = ctime; } Array2dFileLabel::Array2dFileLabel(const int type, const char* const str, double ctime) - : m_strLabel (str) +: m_strLabel (str) { - init(); - - m_labelType = type; - m_calcTime = ctime; + init(); + + m_labelType = type; + m_calcTime = ctime; } Array2dFileLabel::~Array2dFileLabel() @@ -110,7 +110,7 @@ Array2dFileLabel::getDateString (void) const { char szDate [128]; snprintf (szDate, sizeof(szDate), "%2d/%02d/%4d %02d:%02d:%02d", - m_month + 1, m_day, m_year + 1900, m_hour, m_minute, m_second); + m_month + 1, m_day, m_year + 1900, m_hour, m_minute, m_second); m_strDate = szDate; return m_strDate; } @@ -118,30 +118,30 @@ Array2dFileLabel::getDateString (void) const Array2dFileLabel::Array2dFileLabel (const Array2dFileLabel& rhs) { - m_calcTime = rhs.m_calcTime; - m_labelType = rhs.m_labelType; - m_strLabel = rhs.m_strLabel; - m_year = rhs.m_year; m_month = rhs.m_month; m_day = rhs.m_day; - m_hour = rhs.m_hour; m_minute = rhs.m_minute; m_second = rhs.m_second; + m_calcTime = rhs.m_calcTime; + m_labelType = rhs.m_labelType; + m_strLabel = rhs.m_strLabel; + m_year = rhs.m_year; m_month = rhs.m_month; m_day = rhs.m_day; + m_hour = rhs.m_hour; m_minute = rhs.m_minute; m_second = rhs.m_second; } Array2dFileLabel& Array2dFileLabel::operator= (const Array2dFileLabel& rhs) { - m_calcTime = rhs.m_calcTime; - m_labelType = rhs.m_labelType; - m_strLabel = rhs.m_strLabel; - m_year = rhs.m_year; m_month = rhs.m_month; m_day = rhs.m_day; - m_hour = rhs.m_hour; m_minute = rhs.m_minute; m_second = rhs.m_second; - - return (*this); + m_calcTime = rhs.m_calcTime; + m_labelType = rhs.m_labelType; + m_strLabel = rhs.m_strLabel; + m_year = rhs.m_year; m_month = rhs.m_month; m_day = rhs.m_day; + m_hour = rhs.m_hour; m_minute = rhs.m_minute; m_second = rhs.m_second; + + return (*this); } void Array2dFileLabel::print (std::ostream& os) const { if (m_labelType == L_HISTORY) { - os << "History: " << std::endl; + os << "History: " << std::endl; os << " " << m_strLabel << std::endl; os << " calc time = " << m_calcTime << " secs" << std::endl; os << " Timestamp = " << getDateString() << std::endl; @@ -163,22 +163,22 @@ Array2dFileLabel::print (std::ostream& os) const /////////////////////////////////////////////////////////////////////////// -Array2dFile::Array2dFile (int x, int y, int pixelSize, int pixelFormat) +Array2dFile::Array2dFile (int x, int y, int pixelSize, int pixelFormat, int dataType) { - init(); - setArraySize (x, y, pixelSize, pixelFormat); + init(); + setArraySize (x, y, pixelSize, pixelFormat, dataType); } Array2dFile::~Array2dFile (void) { - freeArray (); - for (labelIterator l = m_labels.begin(); l != m_labels.end(); l++) - delete *l; + freeArrays (); + for (labelIterator l = m_labels.begin(); l != m_labels.end(); l++) + delete *l; } Array2dFile::Array2dFile (void) { - init(); + init(); } void @@ -186,7 +186,9 @@ Array2dFile::init (void) { m_pixelSize = 0; m_pixelFormat = PIXEL_INVALID; - m_arrayData = NULL; + m_arrayData = NULL; + m_imaginaryArrayData = NULL; + m_dataType = DATA_TYPE_INVALID; m_nx = 0; m_ny = 0; m_headersize = 0; @@ -200,45 +202,92 @@ Array2dFile::init (void) void -Array2dFile::setArraySize (int x, int y, int pixelSize, int pixelFormat) +Array2dFile::setArraySize (int x, int y, int pixelSize, int pixelFormat, int dataType) { - m_pixelSize = pixelSize; - m_pixelFormat = pixelFormat; - setArraySize (x, y); + m_pixelSize = pixelSize; + m_pixelFormat = pixelFormat; + m_dataType = dataType; + setArraySize (x, y); } void Array2dFile::setArraySize (int x, int y) { - m_nx = x; - m_ny = y; - allocArray (); -} + m_nx = x; + m_ny = y; + allocArrays (); +} + +bool +Array2dFile::reallocComplexToReal () +{ + if (m_dataType != DATA_TYPE_COMPLEX) + return false; + + freeArray (m_imaginaryArrayData); + m_dataType = DATA_TYPE_REAL; + + return true; +} + + +bool +Array2dFile::reallocRealToComplex () +{ + if (m_dataType != DATA_TYPE_REAL) + return false; + + allocArray (m_imaginaryArrayData); + m_dataType = DATA_TYPE_COMPLEX; + + return true; +} + + void -Array2dFile::allocArray (void) +Array2dFile::allocArrays () { - if (m_arrayData) - freeArray(); - - m_arraySize = m_nx * m_ny * m_pixelSize; - m_arrayData = new unsigned char* [m_nx]; - - int columnBytes = m_ny * m_pixelSize; - for (unsigned int i = 0; i < m_nx; i++) - m_arrayData[i] = new unsigned char [columnBytes]; + if (m_arrayData) + freeArray (m_arrayData); + if (m_imaginaryArrayData) + freeArray (m_imaginaryArrayData); + + allocArray (m_arrayData); + if (m_dataType == DATA_TYPE_COMPLEX) + allocArray (m_imaginaryArrayData); +} + +void +Array2dFile::allocArray (unsigned char**& rppData) +{ + m_arraySize = m_nx * m_ny * m_pixelSize; + rppData = new unsigned char* [m_nx]; + int columnBytes = m_ny * m_pixelSize; + for (unsigned int i = 0; i < m_nx; i++) + rppData[i] = new unsigned char [columnBytes]; } void -Array2dFile::freeArray (void) -{ - if (m_arrayData) { - for (unsigned int i = 0; i < m_nx; i++) - delete m_arrayData[i]; - delete m_arrayData; - m_arrayData = NULL; - } -} +Array2dFile::freeArrays () +{ + if (m_arrayData) + freeArray (m_arrayData); + + if (m_imaginaryArrayData) + freeArray (m_imaginaryArrayData); + +} + +void +Array2dFile::freeArray (unsigned char**& rppData) +{ + for (unsigned int i = 0; i < m_nx; i++) + delete rppData[i]; + delete rppData; + rppData = NULL; +} + bool Array2dFile::fileWrite (const std::string& filename) @@ -249,23 +298,23 @@ Array2dFile::fileWrite (const std::string& filename) bool Array2dFile::fileWrite (const char* const filename) { - m_filename = filename; - - frnetorderstream fs (m_filename.c_str(), std::ios::out | std::ios::in | std::ios::trunc | std::ios::binary); - if (fs.fail()) { - sys_error (ERR_WARNING, "Error opening file %s for writing [fileCreate]", m_filename.c_str()); - return false; - } - if (! headerWrite(fs)) - return false; - - if (! arrayDataWrite (fs)) - return false; - - if (! labelsWrite (fs)) - return false; - - return true; + m_filename = filename; + + frnetorderstream fs (m_filename.c_str(), std::ios::out | std::ios::in | std::ios::trunc | std::ios::binary); + if (fs.fail()) { + sys_error (ERR_WARNING, "Error opening file %s for writing [fileCreate]", m_filename.c_str()); + return false; + } + if (! headerWrite(fs)) + return false; + + if (! arrayDataWrite (fs)) + return false; + + if (! labelsWrite (fs)) + return false; + + return true; } bool @@ -277,30 +326,30 @@ Array2dFile::fileRead (const std::string& filename) bool Array2dFile::fileRead (const char* const filename) { - m_filename = filename; - + m_filename = filename; + #ifdef MSVC - frnetorderstream fs (m_filename.c_str(), std::ios::out | std::ios::in | std::ios::binary); + frnetorderstream fs (m_filename.c_str(), std::ios::out | std::ios::in | std::ios::binary); #else - frnetorderstream fs (m_filename.c_str(), std::ios::out | std::ios::in | std::ios::binary | std::ios::nocreate); + frnetorderstream fs (m_filename.c_str(), std::ios::out | std::ios::in | std::ios::binary | std::ios::nocreate); #endif - if (fs.fail()) { - sys_error (ERR_WARNING, "Unable to open file %s [fileRead]", m_filename.c_str()); - return false; - } - - if (! headerRead(fs)) - return false; - - allocArray (); - - if (! arrayDataRead(fs)) - return false;; - - if (! labelsRead (fs)) - return false; - - return true; + if (fs.fail()) { + sys_error (ERR_WARNING, "Unable to open file %s [fileRead]", m_filename.c_str()); + return false; + } + + if (! headerRead(fs)) + return false; + + allocArrays (); + + if (! arrayDataRead(fs)) + return false;; + + if (! labelsRead (fs)) + return false; + + return true; } void @@ -314,11 +363,11 @@ Array2dFile::setAxisIncrement (double incX, double incY) void Array2dFile::setAxisExtent (double minX, double maxX, double minY, double maxY) { - m_axisExtentKnown = true; - m_minX = minX; - m_maxY = maxX; - m_minX = minX; - m_maxY = maxY; + m_axisExtentKnown = true; + m_minX = minX; + m_maxY = maxX; + m_minX = minX; + m_maxY = maxY; } bool @@ -328,17 +377,18 @@ Array2dFile::headerRead (frnetorderstream& fs) sys_error (ERR_WARNING, "Tried to read header with file closed [headerRead]"); return false; } - + fs.seekg (0); kuint16 file_signature; - + fs.readInt16 (m_headersize); fs.readInt16 (file_signature); fs.readInt16 (m_pixelFormat); fs.readInt16 (m_pixelSize); fs.readInt16 (m_numFileLabels); fs.readInt32 (m_nx); - fs.readInt32 (m_ny); + fs.readInt32 (m_ny); + fs.readInt16 (m_dataType); fs.readInt16 (m_axisIncrementKnown); fs.readFloat64 (m_axisIncrementX); fs.readFloat64 (m_axisIncrementY); @@ -349,7 +399,7 @@ Array2dFile::headerRead (frnetorderstream& fs) fs.readFloat64 (m_maxY); fs.readFloat64 (m_offsetPV); fs.readFloat64 (m_scalePV); - + int read_m_headersize = fs.tellg(); if (read_m_headersize != m_headersize) { sys_error (ERR_WARNING, "Read m_headersize %d != file m_headersize %d", read_m_headersize, m_headersize); @@ -359,7 +409,7 @@ Array2dFile::headerRead (frnetorderstream& fs) sys_error (ERR_WARNING, "File signature %d != true signature %d", file_signature, m_signature); return false; } - + return true; } @@ -371,9 +421,9 @@ Array2dFile::headerWrite (frnetorderstream& fs) sys_error (ERR_WARNING, "Tried to write header with ! fs"); return false; } - + m_numFileLabels = m_labels.size(); - + fs.seekp (0); fs.writeInt16 (m_headersize); fs.writeInt16 (m_signature); @@ -381,7 +431,8 @@ Array2dFile::headerWrite (frnetorderstream& fs) fs.writeInt16 (m_pixelSize); fs.writeInt16 (m_numFileLabels); fs.writeInt32 (m_nx); - fs.writeInt32 (m_ny); + fs.writeInt32 (m_ny); + fs.writeInt16 (m_dataType); fs.writeInt16 (m_axisIncrementKnown); fs.writeFloat64 (m_axisIncrementX); fs.writeFloat64 (m_axisIncrementY); @@ -392,7 +443,7 @@ Array2dFile::headerWrite (frnetorderstream& fs) fs.writeFloat64 (m_maxY); fs.writeFloat64 (m_offsetPV); fs.writeFloat64 (m_scalePV); - + m_headersize = static_cast(fs.tellp()); fs.seekp (0); fs.writeInt16 (m_headersize); @@ -408,24 +459,37 @@ Array2dFile::arrayDataWrite (frnetorderstream& fs) sys_error (ERR_WARNING, "Tried to arrayDataWrite with !fs"); return false; } - + if (! m_arrayData) - return false; - + return false; + fs.seekp (m_headersize); int columnSize = m_ny * m_pixelSize; - for (unsigned int ix = 0; ix < m_nx; ix++) { - unsigned char* ptrColumn = m_arrayData[ix]; - if (NativeBigEndian()) { - for (unsigned int iy = 0; iy < m_ny; iy++) { - ConvertReverseNetworkOrder (ptrColumn, m_pixelSize); - fs.write (reinterpret_cast(ptrColumn), m_pixelSize); - ptrColumn += m_pixelSize; - } - } else - fs.write (reinterpret_cast(ptrColumn), columnSize); - } - + for (unsigned int ix = 0; ix < m_nx; ix++) { + unsigned char* ptrColumn = m_arrayData[ix]; + if (NativeBigEndian()) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + ConvertReverseNetworkOrder (ptrColumn, m_pixelSize); + fs.write (reinterpret_cast(ptrColumn), m_pixelSize); + ptrColumn += m_pixelSize; + } + } else + fs.write (reinterpret_cast(ptrColumn), columnSize); + } + if (m_dataType == DATA_TYPE_COMPLEX) { + for (unsigned int ix = 0; ix < m_nx; ix++) { + unsigned char* ptrColumn = m_imaginaryArrayData[ix]; + if (NativeBigEndian()) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + ConvertReverseNetworkOrder (ptrColumn, m_pixelSize); + fs.write (reinterpret_cast(ptrColumn), m_pixelSize); + ptrColumn += m_pixelSize; + } + } else + fs.write (reinterpret_cast(ptrColumn), columnSize); + } + } + return true; } @@ -437,96 +501,109 @@ Array2dFile::arrayDataRead (frnetorderstream& fs) sys_error (ERR_WARNING, "Tried to arrayDataRead with ! fs"); return false; } - + if (! m_arrayData) - return false; - + return false; + fs.seekg (m_headersize); int columnSize = m_ny * m_pixelSize; - for (unsigned int ix = 0; ix < m_nx; ix++) { - unsigned char* ptrColumn = m_arrayData[ix]; - if (NativeBigEndian()) { - for (unsigned int iy = 0; iy < m_ny; iy++) { - fs.read (reinterpret_cast(ptrColumn), m_pixelSize); - ConvertReverseNetworkOrder (ptrColumn, m_pixelSize); - ptrColumn += m_pixelSize; - } - } else - fs.read (reinterpret_cast(ptrColumn), columnSize); - } - + for (unsigned int ix = 0; ix < m_nx; ix++) { + unsigned char* ptrColumn = m_arrayData[ix]; + if (NativeBigEndian()) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + fs.read (reinterpret_cast(ptrColumn), m_pixelSize); + ConvertReverseNetworkOrder (ptrColumn, m_pixelSize); + ptrColumn += m_pixelSize; + } + } else + fs.read (reinterpret_cast(ptrColumn), columnSize); + } + if (m_dataType == DATA_TYPE_COMPLEX) { + for (unsigned int ix = 0; ix < m_nx; ix++) { + unsigned char* ptrColumn = m_imaginaryArrayData[ix]; + if (NativeBigEndian()) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + fs.read (reinterpret_cast(ptrColumn), m_pixelSize); + ConvertReverseNetworkOrder (ptrColumn, m_pixelSize); + ptrColumn += m_pixelSize; + } + } else + fs.read (reinterpret_cast(ptrColumn), columnSize); + } + } + return true; } bool Array2dFile::labelsRead (frnetorderstream& fs) { - off_t pos = m_headersize + m_arraySize; - fs.seekg (pos); - if (fs.fail()) - return false; - - for (int i = 0; i < m_numFileLabels; i++) { - kuint16 labelType, year, month, day, hour, minute, second; - kfloat64 calcTime; - - fs.readInt16 (labelType); - fs.readInt16 (year); - fs.readInt16 (month); - fs.readInt16 (day); - fs.readInt16 (hour); - fs.readInt16 (minute); - fs.readInt16 (second); - fs.readFloat64 (calcTime); - - kuint16 strLength; - fs.readInt16 (strLength); - char* pszLabelStr = new char [strLength+1]; - fs.read (pszLabelStr, strLength); - pszLabelStr[strLength] = 0; - - Array2dFileLabel* pLabel = new Array2dFileLabel (labelType, pszLabelStr, calcTime); - delete pszLabelStr; - - pLabel->setDateTime (year, month, day, hour, minute, second); - m_labels.push_back (pLabel); - } - - return true; + off_t pos = m_headersize + m_arraySize; + fs.seekg (pos); + if (fs.fail()) + return false; + + for (int i = 0; i < m_numFileLabels; i++) { + kuint16 labelType, year, month, day, hour, minute, second; + kfloat64 calcTime; + + fs.readInt16 (labelType); + fs.readInt16 (year); + fs.readInt16 (month); + fs.readInt16 (day); + fs.readInt16 (hour); + fs.readInt16 (minute); + fs.readInt16 (second); + fs.readFloat64 (calcTime); + + kuint16 strLength; + fs.readInt16 (strLength); + char* pszLabelStr = new char [strLength+1]; + fs.read (pszLabelStr, strLength); + pszLabelStr[strLength] = 0; + + Array2dFileLabel* pLabel = new Array2dFileLabel (labelType, pszLabelStr, calcTime); + delete pszLabelStr; + + pLabel->setDateTime (year, month, day, hour, minute, second); + m_labels.push_back (pLabel); + } + + return true; } bool Array2dFile::labelsWrite (frnetorderstream& fs) { - off_t pos = m_headersize + m_arraySize; - fs.seekp (pos); - - for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) { - const Array2dFileLabel& label = **l; - kuint16 labelType = label.getLabelType(); - kfloat64 calcTime = label.getCalcTime(); - const char* const labelString = label.getLabelString().c_str(); - int year, month, day, hour, minute, second; - kuint16 yearBuf, monthBuf, dayBuf, hourBuf, minuteBuf, secondBuf; - - label.getDateTime (year, month, day, hour, minute, second); - yearBuf = year; monthBuf = month; dayBuf = day; - hourBuf = hour; minuteBuf = minute; secondBuf = second; - - fs.writeInt16 (labelType); - fs.writeInt16 (yearBuf); - fs.writeInt16 (monthBuf); - fs.writeInt16 (dayBuf); - fs.writeInt16 (hourBuf); - fs.writeInt16 (minuteBuf); - fs.writeInt16 (secondBuf); - fs.writeFloat64 (calcTime); - kuint16 strlength = strlen (labelString); - fs.writeInt16 (strlength); - fs.write (labelString, strlength); - } - - return true; + off_t pos = m_headersize + m_arraySize; + fs.seekp (pos); + + for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) { + const Array2dFileLabel& label = **l; + kuint16 labelType = label.getLabelType(); + kfloat64 calcTime = label.getCalcTime(); + const char* const labelString = label.getLabelString().c_str(); + int year, month, day, hour, minute, second; + kuint16 yearBuf, monthBuf, dayBuf, hourBuf, minuteBuf, secondBuf; + + label.getDateTime (year, month, day, hour, minute, second); + yearBuf = year; monthBuf = month; dayBuf = day; + hourBuf = hour; minuteBuf = minute; secondBuf = second; + + fs.writeInt16 (labelType); + fs.writeInt16 (yearBuf); + fs.writeInt16 (monthBuf); + fs.writeInt16 (dayBuf); + fs.writeInt16 (hourBuf); + fs.writeInt16 (minuteBuf); + fs.writeInt16 (secondBuf); + fs.writeFloat64 (calcTime); + kuint16 strlength = strlen (labelString); + fs.writeInt16 (strlength); + fs.write (labelString, strlength); + } + + return true; } void @@ -540,7 +617,7 @@ void Array2dFile::labelAdd (int type, const char* const lstr, double calc_time) { Array2dFileLabel label (type, lstr, calc_time); - + labelAdd (label); } @@ -548,45 +625,50 @@ Array2dFile::labelAdd (int type, const char* const lstr, double calc_time) void Array2dFile::labelAdd (const Array2dFileLabel& label) { - Array2dFileLabel* pLabel = new Array2dFileLabel(label); - - m_labels.push_back (pLabel); + Array2dFileLabel* pLabel = new Array2dFileLabel(label); + + m_labels.push_back (pLabel); } void Array2dFile::labelsCopy (Array2dFile& copyFile, const char* const pszId) { - std::string id; - if (pszId) - id = pszId; - for (unsigned int i = 0; i < copyFile.getNumLabels(); i++) { - Array2dFileLabel l (copyFile.labelGet (i)); - std::string lstr = l.getLabelString(); - lstr = id + lstr; - l.setLabelString (lstr); - labelAdd (l); - } + std::string id; + if (pszId) + id = pszId; + for (unsigned int i = 0; i < copyFile.getNumLabels(); i++) { + Array2dFileLabel l (copyFile.labelGet (i)); + std::string lstr = l.getLabelString(); + lstr = id + lstr; + l.setLabelString (lstr); + labelAdd (l); + } } void Array2dFile::arrayDataClear (void) { - if (m_arrayData) { - int columnSize = m_ny * m_pixelSize; - for (unsigned int ix = 0; ix < m_nx; ix++) - memset (m_arrayData[ix], 0, columnSize); - } + if (m_arrayData) { + int columnSize = m_ny * m_pixelSize; + for (unsigned int ix = 0; ix < m_nx; ix++) + memset (m_arrayData[ix], 0, columnSize); + } + if (m_imaginaryArrayData) { + int columnSize = m_ny * m_pixelSize; + for (unsigned int ix = 0; ix < m_nx; ix++) + memset (m_arrayData[ix], 0, columnSize); + } } void Array2dFile::printLabels (std::ostream& os) const { - for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) { - const Array2dFileLabel& label = **l; - - label.print (os); - os << std::endl; - } + for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) { + const Array2dFileLabel& label = **l; + + label.print (os); + os << std::endl; + } } diff --git a/libctsim/imagefile.cpp b/libctsim/imagefile.cpp index 54f38a1..84c6674 100644 --- a/libctsim/imagefile.cpp +++ b/libctsim/imagefile.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: imagefile.cpp,v 1.25 2000/12/29 15:45:06 kevin Exp $ +** $Id: imagefile.cpp,v 1.26 2000/12/29 19:30: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 @@ -28,8 +28,8 @@ #include "ct.h" -F32Image::F32Image (int nx, int ny) -: Array2dFile (nx, ny, sizeof(kfloat32), Array2dFile::PIXEL_FLOAT32) +F32Image::F32Image (int nx, int ny, int dataType) +: Array2dFile (nx, ny, sizeof(kfloat32), Array2dFile::PIXEL_FLOAT32, dataType) { } @@ -38,10 +38,11 @@ F32Image::F32Image (void) { setPixelFormat (Array2dFile::PIXEL_FLOAT32); setPixelSize (sizeof(kfloat32)); + setDataType (Array2dFile::DATA_TYPE_REAL); } -F64Image::F64Image (int nx, int ny) -: Array2dFile (nx, ny, sizeof(kfloat64), Array2dFile::PIXEL_FLOAT64) +F64Image::F64Image (int nx, int ny, int dataType) +: Array2dFile (nx, ny, sizeof(kfloat64), Array2dFile::PIXEL_FLOAT64, dataType) { } @@ -50,6 +51,7 @@ F64Image::F64Image (void) { setPixelFormat (PIXEL_FLOAT64); setPixelSize (sizeof(kfloat64)); + setDataType (Array2dFile::DATA_TYPE_REAL); } void @@ -212,26 +214,46 @@ ImageFile::printStatistics (std::ostream& os) const { double min, max, mean, mode, median, stddev; - statistics (min, max, mean, mode, median, stddev); - + statistics (min, max, mean, mode, median, stddev); + if (dataType() == Array2dFile::DATA_TYPE_COMPLEX) + os << "Real Component Statistics" << std::endl; + os << " min: " << min << std::endl; os << " max: " << max << std::endl; os << " mean: " << mean << std::endl; os << " mode: " << mode << std::endl; os << "median: " << median << std::endl; - os << "stddev: " << stddev << std::endl; + os << "stddev: " << stddev << std::endl; + + if (dataType() == Array2dFile::DATA_TYPE_COMPLEX) { + statistics (getImaginaryArray(), min, max, mean, mode, median, stddev); + os << std::endl << "Imaginary Component Statistics" << std::endl; + os << " min: " << min << std::endl; + os << " max: " << max << std::endl; + os << " mean: " << mean << std::endl; + os << " mode: " << mode << std::endl; + os << "median: " << median << std::endl; + os << "stddev: " << stddev << std::endl; + } } void ImageFile::statistics (double& min, double& max, double& mean, double& mode, double& median, double& stddev) const -{ - int nx = m_nx; - int ny = m_ny; - ImageFileArrayConst v = getArray(); - - if (v == NULL || nx == 0 || ny == 0) - return; +{ + ImageFileArrayConst v = getArray(); + statistics (v, min, max, mean, mode, median, stddev); +} + + +void +ImageFile::statistics (ImageFileArrayConst& v, double& min, double& max, double& mean, double& mode, double& median, double& stddev) const +{ + int nx = m_nx; + int ny = m_ny; + + if (v == NULL || nx == 0 || ny == 0) + return; std::vector vecImage; int iVec = 0; @@ -242,9 +264,8 @@ ImageFile::statistics (double& min, double& max, double& mean, double& mode, dou } vectorNumericStatistics (vecImage, nx * ny, min, max, mean, mode, median, stddev); -} - - +} + void ImageFile::getMinMax (double& min, double& max) const { @@ -267,6 +288,46 @@ ImageFile::getMinMax (double& min, double& max) const } } +bool +ImageFile::convertRealToComplex () +{ + if (dataType() != Array2dFile::DATA_TYPE_REAL) + return false; + + if (! reallocRealToComplex()) + return false; + + ImageFileArray vImag = getImaginaryArray(); + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumn vCol = vImag[ix]; + for (int iy = 0; iy < m_ny; iy++) + *vCol++ = 0; + } + + return true; +} + +bool +ImageFile::convertComplexToReal () +{ + if (dataType() != Array2dFile::DATA_TYPE_COMPLEX) + return false; + + ImageFileArray vReal = getArray(); + ImageFileArray vImag = getImaginaryArray(); + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumn vRealCol = vReal[ix]; + ImageFileColumn vImagCol = vImag[ix]; + for (int iy = 0; iy < m_ny; iy++) { + std::complex c (*vRealCol, *vImagCol); + *vRealCol++ = std::abs (c); + vImagCol++; + } + } + + return reallocComplexToReal(); +} + bool ImageFile::subtractImages (const ImageFile& rRHS, ImageFile& result) const { @@ -455,15 +516,32 @@ ImageFile::exp (ImageFile& result) const } bool -ImageFile::FFTMagnitude (ImageFile& result) const +ImageFile::inverseFourier (ImageFile& result) const +{ + if (m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]"); + return false; + } + + return true; +} + +bool +ImageFile::fourier (ImageFile& result) const { if (m_nx != result.nx() || m_ny != result.ny()) { sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]"); return false; } + if (result.dataType() == Array2dFile::DATA_TYPE_REAL) { + if (! result.reallocRealToComplex ()) + return false; + } + ImageFileArrayConst vLHS = getArray(); - ImageFileArray vResult = result.getArray(); + ImageFileArray vRealResult = result.getArray(); + ImageFileArray vImagResult = result.getImaginaryArray(); int ix, iy; double* pY = new double [m_ny]; @@ -504,8 +582,10 @@ ImageFile::FFTMagnitude (ImageFile& result) const delete [] complexOutCol; for (ix = 0; ix < m_nx; ix++) - for (iy = 0; iy < m_ny; iy++) - vResult[ix][iy] = std::abs (complexOut[ix][iy]); + for (iy = 0; iy < m_ny; iy++) { + vRealResult[ix][iy] = complexOut[ix][iy].real(); + vImagResult[ix][iy] = complexOut[ix][iy].imag(); + } for (ix = 0; ix < m_nx; ix++) delete [] complexOut[ix]; @@ -516,62 +596,65 @@ ImageFile::FFTMagnitude (ImageFile& result) const } bool -ImageFile::FFTPhase (ImageFile& result) const +ImageFile::magnitude (ImageFile& result) const { if (m_nx != result.nx() || m_ny != result.ny()) { sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]"); return false; } - ImageFileArrayConst vLHS = getArray(); - ImageFileArray vResult = result.getArray(); - - int ix, iy; - double* pY = new double [m_ny]; - std::complex** complexOut = new std::complex* [m_nx]; - for (ix = 0; ix < m_nx; ix++) - complexOut[ix] = new std::complex [m_ny]; - - for (ix = 0; ix < m_nx; ix++) { - for (iy = 0; iy < m_ny; iy++) - pY[iy] = vLHS[ix][iy]; - ProcessSignal::finiteFourierTransform (pY, complexOut[ix], m_ny, ProcessSignal::FORWARD); + ImageFileArray vReal = getArray(); + ImageFileArray vImag = NULL; + if (dataType() == Array2dFile::DATA_TYPE_COMPLEX) + vImag = getImaginaryArray(); + + ImageFileArray vRealResult = result.getArray(); + if (result.dataType() == Array2dFile::DATA_TYPE_COMPLEX) { + ImageFileArray vImagResult = result.getImaginaryArray(); + for (int ix = 0; ix < m_nx; ix++) + for (int iy = 0; iy < m_ny; iy++) + vImagResult[ix][iy] = 0; } - delete pY; - - std::complex* pX = new std::complex [m_nx]; - std::complex* complexOutCol = new std::complex [m_nx]; - for (iy = 0; iy < m_ny; iy++) { - for (ix = 0; ix < m_nx; ix++) - pX[ix] = complexOut[ix][iy]; - ProcessSignal::finiteFourierTransform (pX, complexOutCol, m_nx, ProcessSignal::FORWARD); - for (ix = 0; ix < m_nx; ix++) - complexOut[ix][iy] = complexOutCol[ix]; - } - delete [] pX; - for (ix = 0; ix < m_nx; ix++) - ProcessSignal::shuffleFourierToNaturalOrder (complexOut[ix], m_ny); + for (int ix = 0; ix < m_nx; ix++) + for (int iy = 0; iy < m_ny; iy++) { + if (dataType() == Array2dFile::DATA_TYPE_COMPLEX) + vRealResult[ix][iy] = ::sqrt (vReal[ix][iy] * vReal[ix][iy] + vImag[ix][iy] * vImag[ix][iy]); + else + vRealResult[ix][iy] = vReal[ix][iy]; + } - - for (iy = 0; iy < m_ny; iy++) { - for (ix = 0; ix < m_nx; ix++) - complexOutCol[ix] = complexOut[ix][iy]; - ProcessSignal::shuffleFourierToNaturalOrder (complexOutCol, m_nx);; - for (ix = 0; ix < m_nx; ix++) - complexOut[ix][iy] = complexOutCol[ix]; + return true; +} +bool +ImageFile::phase (ImageFile& result) const +{ + if (m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]"); + return false; } - delete [] complexOutCol; - - for (ix = 0; ix < m_nx; ix++) - for (iy = 0; iy < m_ny; iy++) - vResult[ix][iy] = atan (complexOut[ix][iy].imag / complexOut[ix][iy].real); - for (ix = 0; ix < m_nx; ix++) - delete [] complexOut[ix]; + ImageFileArray vReal = getArray(); + ImageFileArray vImag = NULL; + if (dataType() == Array2dFile::DATA_TYPE_COMPLEX) + vImag = getImaginaryArray(); + + ImageFileArray vRealResult = result.getArray(); + if (result.dataType() == Array2dFile::DATA_TYPE_COMPLEX) { + ImageFileArray vImagResult = result.getImaginaryArray(); + for (int ix = 0; ix < m_nx; ix++) + for (int iy = 0; iy < m_ny; iy++) + vImagResult[ix][iy] = 0; + } - delete [] complexOut; + for (int ix = 0; ix < m_nx; ix++) + for (int iy = 0; iy < m_ny; iy++) { + if (dataType() == Array2dFile::DATA_TYPE_COMPLEX) + vRealResult[ix][iy] = ::atan (vImag[ix][iy] / vReal[ix][iy]); + else + vRealResult[ix][iy] = vReal[ix][iy]; + } return true; } diff --git a/msvc/ctsim/ctsim.dsp b/msvc/ctsim/ctsim.dsp index 6c6220f..d393449 100644 --- a/msvc/ctsim/ctsim.dsp +++ b/msvc/ctsim/ctsim.dsp @@ -158,6 +158,7 @@ SOURCE=..\..\..\wx2\include\wx\msw\wx.rc # ADD BASE RSC /l 0x409 /i "\wx2\include\wx\msw" # SUBTRACT BASE RSC /i "\wx2\include\wx\msw" /i "\wx2\include" # ADD RSC /l 0x409 /i "\wx2\include\wx\msw" +# SUBTRACT RSC /i "\wx2\include\wx\msw" /i "\wx2\include" !ENDIF diff --git a/msvc/ctsim/ctsim.plg b/msvc/ctsim/ctsim.plg index 1487b05..7a190d2 100644 --- a/msvc/ctsim/ctsim.plg +++ b/msvc/ctsim/ctsim.plg @@ -6,13 +6,13 @@ --------------------Configuration: libctsim - Win32 Debug--------------------

Command Lines

-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP34.tmp" with contents +Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP8B.tmp" with contents [ /nologo /G6 /MTd /W3 /Gm /GR /GX /ZI /Od /I "..\..\..\zlib" /I "..\..\INCLUDE" /I "..\..\getopt" /I "..\..\..\lpng108" /I "..\..\..\fftw-2.1.3\fftw" /I "..\..\..\fftw-2.1.3\rfftw" /I "..\..\..\wx2\include" /D "_DEBUG" /D "HAVE_WXWIN" /D "HAVE_STRING_H" /D "HAVE_GETOPT_H" /D "WIN32" /D "_MBCS" /D "_LIB" /D "MSVC" /D "HAVE_FFTW" /D "HAVE_PNG" /D "HAVE_SGP" /D "HAVE_WXWINDOWS" /D "__WXMSW__" /FR"Debug/" /Fp"Debug/libctsim.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c "C:\ctsim-2.0.6\libctsim\imagefile.cpp" ] -Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP34.tmp" -Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP35.tmp" with contents +Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP8B.tmp" +Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP8C.tmp" with contents [ /nologo /out:"Debug\libctsim.lib" ".\Debug\array2dfile.obj" @@ -43,7 +43,7 @@ Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP35.tmp" with content ".\Debug\transformmatrix.obj" ".\Debug\xform.obj" ] -Creating command line "link.exe -lib @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP35.tmp" +Creating command line "link.exe -lib @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP8C.tmp"

Output Window

Compiling... imagefile.cpp @@ -52,7 +52,7 @@ Creating library... --------------------Configuration: ctsim - Win32 Debug--------------------

Command Lines

-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP36.tmp" with contents +Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP8D.tmp" with contents [ comctl32.lib winmm.lib rpcrt4.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ../libctsim/Debug/libctsim.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ..\..\..\lpng108\msvc\win32\libpng\lib_dbg\libpng.lib ..\..\..\lpng108\msvc\win32\zlib\lib_dbg\zlib.lib libcmtd.lib ..\..\..\fftw-2.1.3\Win32\FFTW2st\Debug\FFTW2st.lib ..\..\..\fftw-2.1.3\Win32\RFFTW2st\Debug\RFFTW2st.lib ../../../wx2/lib/wxd.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/ctsim.pdb" /debug /machine:I386 /nodefaultlib:"libcd.lib" /nodefaultlib:"libcid.lib" /nodefaultlib:"msvcrtd.lib" /out:"Debug/ctsim.exe" /pdbtype:sept /libpath:"..\..\..\lpng108\msvc\win32\libpng\lib" /libpath:"..\..\..\lpng108\msvc\win32\zlib\lib" ".\Debug\ctsim.obj" @@ -67,7 +67,7 @@ comctl32.lib winmm.lib rpcrt4.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib w "\fftw-2.1.3\Win32\RFFTW2st\Debug\RFFTW2st.lib" "\wx2\lib\wxd.lib" ] -Creating command line "link.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP36.tmp" +Creating command line "link.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP8D.tmp"

Output Window

Linking... diff --git a/src/ctsim.h b/src/ctsim.h index bbd7f83..b944560 100644 --- a/src/ctsim.h +++ b/src/ctsim.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ctsim.h,v 1.14 2000/12/29 15:45:06 kevin Exp $ +** $Id: ctsim.h,v 1.15 2000/12/29 19:30: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 @@ -152,8 +152,10 @@ enum { IFMENU_PROCESS_SQUARE, IFMENU_PROCESS_LOG, IFMENU_PROCESS_EXP, - IFMENU_PROCESS_FFT_MAGNITUDE, - IFMENU_PROCESS_FFT_PHASE, + IFMENU_PROCESS_FOURIER, + IFMENU_PROCESS_INVERSE_FOURIER, + IFMENU_PROCESS_MAGNITUDE, + IFMENU_PROCESS_PHASE, PHMMENU_PROCESS_RASTERIZE, PHMMENU_PROCESS_PROJECTIONS, PLOTMENU_VIEW_SCALE_MINMAX, diff --git a/src/views.cpp b/src/views.cpp index 8c53e4c..307d6c0 100644 --- a/src/views.cpp +++ b/src/views.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: views.cpp,v 1.40 2000/12/29 15:45:06 kevin Exp $ +** $Id: views.cpp,v 1.41 2000/12/29 19:30: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 @@ -169,8 +169,10 @@ EVT_MENU(IFMENU_PROCESS_SQUARE, ImageFileView::OnSquare) EVT_MENU(IFMENU_PROCESS_SQRT, ImageFileView::OnSquareRoot) EVT_MENU(IFMENU_PROCESS_LOG, ImageFileView::OnLog) EVT_MENU(IFMENU_PROCESS_EXP, ImageFileView::OnExp) -EVT_MENU(IFMENU_PROCESS_FFT_MAGNITUDE, ImageFileView::OnFFTMagnitude) -EVT_MENU(IFMENU_PROCESS_FFT_PHASE, ImageFileView::OnFFTPhase) +EVT_MENU(IFMENU_PROCESS_FOURIER, ImageFileView::OnFourier) +EVT_MENU(IFMENU_PROCESS_INVERSE_FOURIER, ImageFileView::OnInverseFourier) +EVT_MENU(IFMENU_PROCESS_MAGNITUDE, ImageFileView::OnMagnitude) +EVT_MENU(IFMENU_PROCESS_PHASE, ImageFileView::OnPhase) EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow) EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol) END_EVENT_TABLE() @@ -187,15 +189,26 @@ ImageFileView::~ImageFileView(void) void ImageFileView::OnProperties (wxCommandEvent& event) { - double min, max, mean, mode, median, stddev; const ImageFile& rIF = GetDocument()->getImageFile(); if (rIF.nx() == 0 || rIF.ny() == 0) *theApp->getLog() << "Properties: empty imagefile\n"; else { const std::string& rFilename = rIF.getFilename(); - rIF.statistics (min, max, mean, mode, median, stddev); std::ostringstream os; - os << "file: " << rFilename << "\nmin: "<getLog() << os.str().c_str(); wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION); dialogMsg.ShowModal(); @@ -348,20 +361,48 @@ ImageFileView::OnExp (wxCommandEvent& event) } void -ImageFileView::OnFFTMagnitude (wxCommandEvent& event) +ImageFileView::OnFourier (wxCommandEvent& event) { ImageFile& rIF = GetDocument()->getImageFile(); - rIF.FFTMagnitude (rIF); + rIF.fourier (rIF); + m_bMinSpecified = false; + m_bMaxSpecified = false; + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + +void +ImageFileView::OnInverseFourier (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.inverseFourier (rIF); + m_bMinSpecified = false; + m_bMaxSpecified = false; if (theApp->getSetModifyNewDocs()) GetDocument()->Modify(TRUE); GetDocument()->UpdateAllViews(this); } void -ImageFileView::OnFFTPhase (wxCommandEvent& event) +ImageFileView::OnMagnitude (wxCommandEvent& event) { ImageFile& rIF = GetDocument()->getImageFile(); - rIF.FFTPhase (rIF); + rIF.magnitude (rIF); + m_bMinSpecified = false; + m_bMaxSpecified = false; + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + +void +ImageFileView::OnPhase (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.phase (rIF); + m_bMinSpecified = false; + m_bMaxSpecified = false; if (theApp->getSetModifyNewDocs()) GetDocument()->Modify(TRUE); GetDocument()->UpdateAllViews(this); @@ -415,8 +456,11 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) process_menu->Append (IFMENU_PROCESS_SQRT, "Square &Root"); process_menu->Append (IFMENU_PROCESS_LOG, "&Log"); process_menu->Append (IFMENU_PROCESS_EXP, "&Exp"); - process_menu->Append (IFMENU_PROCESS_FFT_MAGNITUDE, "&FFT Magnitude"); - process_menu->Append (IFMENU_PROCESS_FFT_PHASE, "FFT &Phase"); + process_menu->AppendSeparator(); + process_menu->Append (IFMENU_PROCESS_FOURIER, "&Fourier"); + process_menu->Append (IFMENU_PROCESS_INVERSE_FOURIER, "&Inverse Fourier"); + process_menu->Append (IFMENU_PROCESS_MAGNITUDE, "&Magnitude"); + process_menu->Append (IFMENU_PROCESS_PHASE, "&Phase"); wxMenu *plot_menu = new wxMenu; plot_menu->Append (IFMENU_PLOT_ROW, "Plot &Row"); diff --git a/src/views.h b/src/views.h index 8bb5e6d..79b154c 100644 --- a/src/views.h +++ b/src/views.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: views.h,v 1.17 2000/12/29 15:45:06 kevin Exp $ +** $Id: views.h,v 1.18 2000/12/29 19:30: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 @@ -71,8 +71,10 @@ public: void OnSquareRoot (wxCommandEvent& event); void OnLog (wxCommandEvent& event); void OnExp (wxCommandEvent& event); - void OnFFTMagnitude (wxCommandEvent& event); - void OnFFTPhase (wxCommandEvent& event); + void OnFourier (wxCommandEvent& event); + void OnInverseFourier (wxCommandEvent& event); + void OnMagnitude (wxCommandEvent& event); + void OnPhase (wxCommandEvent& event); void OnScaleAuto (wxCommandEvent& event); void OnScaleMinMax (wxCommandEvent& event); void OnPlotRow (wxCommandEvent& event); diff --git a/tools/if1.cpp b/tools/if1.cpp index 9e4c169..cac6df3 100644 --- a/tools/if1.cpp +++ b/tools/if1.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if1.cpp,v 1.3 2000/12/29 15:45:06 kevin Exp $ +** $Id: if1.cpp,v 1.4 2000/12/29 19:30: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 @@ -46,7 +46,7 @@ static struct option my_options[] = {0, 0, 0, 0} }; -static const char* g_szIdStr = "$Id: if1.cpp,v 1.3 2000/12/29 15:45:06 kevin Exp $"; +static const char* g_szIdStr = "$Id: if1.cpp,v 1.4 2000/12/29 19:30:08 kevin Exp $"; void if1_usage (const char *program) @@ -59,7 +59,7 @@ if1_usage (const char *program) std::cout << " --exp Natural exponential of image" << std::endl; std::cout << " --sqr Square of image" << std::endl; std::cout << " --sqrt Square root of image" << std::endl; - std::cout << " --verbose Verbose modem" << std::endl; + std::cout << " --verbose Verbose mode" << std::endl; std::cout << " --version Print version" << std::endl; std::cout << " --help Print this help message" << std::endl; } diff --git a/tools/ifinfo.cpp b/tools/ifinfo.cpp index f423460..1e98db0 100644 --- a/tools/ifinfo.cpp +++ b/tools/ifinfo.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ifinfo.cpp,v 1.5 2000/12/17 23:30:48 kevin Exp $ +** $Id: ifinfo.cpp,v 1.6 2000/12/29 19:30: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 @@ -46,7 +46,7 @@ static struct option my_options[] = {0, 0, 0, 0} }; -static const char* g_szIdStr = "$Id: ifinfo.cpp,v 1.5 2000/12/17 23:30:48 kevin Exp $"; +static const char* g_szIdStr = "$Id: ifinfo.cpp,v 1.6 2000/12/29 19:30:08 kevin Exp $"; void @@ -138,7 +138,13 @@ ifinfo_main (int argc, char *const argv[]) im->printLabels (std::cout); if (opt_stats) { - std::cout << "Size: (" << im->nx() << "," << im->ny() << ")\n"; + std::cout << "Size: (" << im->nx() << "," << im->ny() << ")\n"; + std::cout << "Data type: "; + if (im->dataType() == Array2dFile::DATA_TYPE_COMPLEX) + std::cout << "Complex\n"; + else + std::cout << "Real\n"; + im->printStatistics (std::cout); }