From c00c639073653fac7463a88f2b000f263236550d Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Tue, 2 Jan 2001 16:02:13 +0000 Subject: [PATCH] r348: fix linefeed problem --- configure | 2 +- include/array2dfile.h | 80 +- include/ct.h | 20 +- include/ctsupport.h | 60 +- include/ezplot.h | 106 +- include/fnetorderstream.h | 56 +- include/fourier.h | 90 +- include/hashtable.h | 174 +-- include/imagefile.h | 166 +-- include/msvc_compat.h | 2 +- include/phantom.h | 26 +- include/plotfile.h | 52 +- include/pol.h | 324 ++--- include/procsignal.h | 20 +- include/sgp.h | 6 +- libctgraphics/ezset.cpp | 106 +- libctgraphics/pol.cpp | 80 +- libctgraphics/sgp.cpp | 140 +-- libctgraphics/transformmatrix.cpp | 10 +- libctsim/array2dfile.cpp | 424 +++---- libctsim/backprojectors.cpp | 22 +- libctsim/filter.cpp | 4 +- libctsim/fourier.cpp | 558 ++++----- libctsim/imagefile.cpp | 1832 ++++++++++++++--------------- libctsim/phantom.cpp | 154 +-- libctsim/procsignal.cpp | 50 +- libctsim/projections.cpp | 38 +- libctsim/reconstruct.cpp | 10 +- libctsupport/clip.cpp | 4 +- libctsupport/fnetorderstream.cpp | 32 +- libctsupport/hashtable.cpp | 282 ++--- libctsupport/mathfuncs.cpp | 110 +- libctsupport/msvc.cpp | 2 +- libctsupport/plotfile.cpp | 310 ++--- libctsupport/syserror.cpp | 40 +- libctsupport/xform.cpp | 8 +- src/ctsim.cpp | 266 ++--- src/dialogs.cpp | 926 +++++++-------- src/dlgprojections.cpp | 42 +- src/dlgreconstruct.cpp | 100 +- src/docs.cpp | 62 +- 41 files changed, 3398 insertions(+), 3398 deletions(-) diff --git a/configure b/configure index fc93465..663e7f5 100755 --- a/configure +++ b/configure @@ -715,7 +715,7 @@ fi PACKAGE=ctsim -VERSION=3.0.0alpha1 +VERSION=3.0.0alpha3 if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then { echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; } diff --git a/include/array2dfile.h b/include/array2dfile.h index 79ae2f2..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.17 2001/01/02 07:47:36 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 @@ -34,11 +34,11 @@ #include #include -#include +#include #include -#include -#include -#include +#include +#include +#include #include #include "ctsupport.h" #include "fnetorderstream.h" @@ -89,8 +89,8 @@ public: const std::string& getDateString () const; void print (std::ostream& os) const; - void printBrief (std::ostream& os) const; - void printBrief (std::ostringstream& os) const; + void printBrief (std::ostream& os) const; + void printBrief (std::ostringstream& os) const; Array2dFileLabel (const Array2dFileLabel& rhs); @@ -127,12 +127,12 @@ public: PIXEL_FLOAT32 = 7, PIXEL_FLOAT64 = 8, }; - - enum { - DATA_TYPE_INVALID = 0, - DATA_TYPE_REAL, - DATA_TYPE_COMPLEX, - }; + + 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); @@ -166,26 +166,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; } + + 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); - bool reallocRealToComplex (); - - bool reallocComplexToReal (); + 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,12 +203,12 @@ public: const std::string& getFilename (void) const { return m_filename; } - void printLabels (std::ostream& os) const; - void printLabelsBrief (std::ostream& os) const; - void printLabelsBrief (std::ostringstream& os) const; - - unsigned int nLabels() const - { return m_labels.size(); } + void printLabels (std::ostream& os) const; + void printLabelsBrief (std::ostream& os) const; + void printLabelsBrief (std::ostringstream& os) const; + + unsigned int nLabels() const + { return m_labels.size(); } typedef std::vector::iterator labelIterator; typedef std::vector::const_iterator constLabelIterator; @@ -231,10 +231,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; + unsigned char** m_imaginaryArrayData; private: void init (void); @@ -255,9 +255,9 @@ private: void allocArrays (); void freeArrays (); - - void allocArray (unsigned char**& rppData); - void freeArray (unsigned char**& rppData); + + 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/ct.h b/include/ct.h index b618130..98425a1 100644 --- a/include/ct.h +++ b/include/ct.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ct.h,v 1.48 2001/01/02 05:34:57 kevin Exp $ +** $Id: ct.h,v 1.49 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 @@ -35,7 +35,7 @@ #ifdef HAVE_CONFIG_H #include #endif - + #define HAVE_ANSI_CPP 1 #ifdef HAVE_ANSI_CPP #include @@ -46,16 +46,16 @@ #include #include #include - -#if defined(MSVC) || HAVE_SSTREAM + +#if defined(MSVC) || HAVE_SSTREAM #include -#else +#else #include -#endif - +#endif + #include #include -#include +#include #include #include #include @@ -170,12 +170,12 @@ extern "C" { #include "phantom.h" #include "scanner.h" #include "backprojectors.h" -#include "filter.h" +#include "filter.h" #include "fourier.h" #include "procsignal.h" #include "projections.h" #include "reconstruct.h" -#include "plotfile.h" +#include "plotfile.h" #include "trace.h" diff --git a/include/ctsupport.h b/include/ctsupport.h index b4063e3..d843a08 100644 --- a/include/ctsupport.h +++ b/include/ctsupport.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ctsupport.h,v 1.21 2001/01/02 07:47:36 kevin Exp $ +** $Id: ctsupport.h,v 1.22 2001/01/02 16:02:12 kevin Exp $ ** ** ** This program is free software; you can redistribute it and/or modify @@ -43,16 +43,16 @@ #include #include #include -#include +#include #include -#include -#include +#include +#include -#if defined(MSVC) || HAVE_SSTREAM +#if defined(MSVC) || HAVE_SSTREAM #include -#else +#else #include -#endif +#endif #define TRUE 1 #define FALSE 0 @@ -71,7 +71,7 @@ /*----------------------------------------------------------------------*/ -#define ERR_TRACE -1 +#define ERR_TRACE -1 #define ERR_WARNING 0 #define ERR_SEVERE 1 #define ERR_FATAL 2 @@ -190,27 +190,27 @@ convertRadiansToDegrees (double x) template inline T nearest (double x) { return (x > 0 ? static_cast(x+0.5) : static_cast(x-0.5)); } - -inline bool isEven (int n) -{ return (n % 2) == 0; } - -inline bool isOdd (int n) -{ return (n % 2) != 0; } - -#if 0 -inline bool isEven (long n) -{ return (n % 2) == 0; } - -inline bool isOdd (long n) -{ return (n % 2) != 0; } -#endif - -inline int imax (int a, int b) -{ return (a >= b ? a : b); } - -inline double dmax (double a, double b) -{ return (a >= b ? a : b); } - + +inline bool isEven (int n) +{ return (n % 2) == 0; } + +inline bool isOdd (int n) +{ return (n % 2) != 0; } + +#if 0 +inline bool isEven (long n) +{ return (n % 2) == 0; } + +inline bool isOdd (long n) +{ return (n % 2) != 0; } +#endif + +inline int imax (int a, int b) +{ return (a >= b ? a : b); } + +inline double dmax (double a, double b) +{ return (a >= b ? a : b); } + template inline T clamp (T value, T lowerBounds, T upperBounds) { return (value >= upperBounds ? upperBounds : (value <= lowerBounds ? lowerBounds : value )); } @@ -258,7 +258,7 @@ void scale2d (double x[], double y[], int pts, double xfact, double yfact); // mathfuncs.cpp double normalizeAngle (double theta); double integrateSimpson (const double xmin, const double xmax, const double *y, const int np); -void vectorNumericStatistics (std::vector vec, const int nPoints, double& min, double& max, double& mean, double& mode, double& median, double& stddev); +void vectorNumericStatistics (std::vector vec, const int nPoints, double& min, double& max, double& mean, double& mode, double& median, double& stddev); /*----------------------------------------------------------------------*/ diff --git a/include/ezplot.h b/include/ezplot.h index f6dbf77..6a8de84 100644 --- a/include/ezplot.h +++ b/include/ezplot.h @@ -7,7 +7,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ezplot.h,v 1.23 2000/12/29 15:45:06 kevin Exp $ +** $Id: ezplot.h,v 1.24 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 @@ -32,7 +32,7 @@ #include #include #include "ctsupport.h" -#include "sgp.h" +#include "sgp.h" #include "pol.h" @@ -52,21 +52,21 @@ public: //---------------------------------------------------------------------- // axis definitions -enum { +enum { LINEAR = 1, // linear axis LOG, // logrithmic axis - NOAXIS, // don't plot axis + NOAXIS, // don't plot axis }; // tick definitions -enum { +enum { ABOVE = 1, BELOW, RIGHT, - LEFT, + LEFT, }; -// line types +// line types enum { NOLINE = 0, SOLID, @@ -74,31 +74,31 @@ enum { DASH1, DASH2, DASH3, - DASH4, -}; + DASH4, +}; // symbol definitions -enum { +enum { SB_CROSS = 1, SB_PLUS, SB_BOX, SB_CIRCLE, SB_ERRORBAR, - MAXSYMBOL, + MAXSYMBOL, }; -enum { +enum { INSIDE = 1, // values of o_legendbox OUTSIDE, - NOLEGEND, -}; - + NOLEGEND, +}; + + +struct KeywordCodeTable { + char* keyword; + int code; +}; -struct KeywordCodeTable { - char* keyword; - int code; -}; - /*----------------------------------------------------------------------------- * GLOBAL VARIABLES * @@ -137,7 +137,7 @@ private: enum { S_DATA = 2, S_HELP, - S_EXIT, + S_EXIT, S_CURVE, S_SOLID, S_DASH, @@ -145,7 +145,7 @@ private: S_BLACK, S_RED, S_GREEN, - S_BLUE, + S_BLUE, S_SYMBOL, S_PEN, S_EVERY, @@ -207,36 +207,36 @@ private: S_TAG, S_TEXTSIZE, }; - - static const struct KeywordCodeTable m_sKeywords[]; - static const int NKEYS; + + static const struct KeywordCodeTable m_sKeywords[]; + static const int NKEYS; std::vector m_vecCurves; - std::vector m_veciColor; - std::vector m_vecbColorSet; - std::vector m_veciSymbol; - std::vector m_vecbSymbolSet; - std::vector m_veciSymbolFreq; - std::vector m_vecbSymbolFreqSet; - std::vector m_veciLinestyle; - std::vector m_vecbLinestyleSet; - std::vector m_vecsLegend; - std::vector m_vecbLegendSet; - - int getColor (unsigned int iCurve) const; - int getSymbol (unsigned int iCurve) const; - const std::string* getLegend (unsigned int iCurve) const; - int getSymbolFreq (unsigned int iCurve) const; - int getLinestyle (unsigned int iCurve) const; - - void setColor (unsigned int iCurve, int iColor); - void setSymbol (unsigned int iCurve, int iSymbol); - void setSymbolFreq (unsigned int iCurve, int iSymbolFreq); - void setLinestyle (unsigned int iCurve, int iLinestyle); - void setLegend (unsigned int iCurve, const std::string& strLegend); - void setLegend (unsigned int iCurve, const char* const pszLegend); - - int m_iCurrentCurve; + std::vector m_veciColor; + std::vector m_vecbColorSet; + std::vector m_veciSymbol; + std::vector m_vecbSymbolSet; + std::vector m_veciSymbolFreq; + std::vector m_vecbSymbolFreqSet; + std::vector m_veciLinestyle; + std::vector m_vecbLinestyleSet; + std::vector m_vecsLegend; + std::vector m_vecbLegendSet; + + int getColor (unsigned int iCurve) const; + int getSymbol (unsigned int iCurve) const; + const std::string* getLegend (unsigned int iCurve) const; + int getSymbolFreq (unsigned int iCurve) const; + int getLinestyle (unsigned int iCurve) const; + + void setColor (unsigned int iCurve, int iColor); + void setSymbol (unsigned int iCurve, int iSymbol); + void setSymbolFreq (unsigned int iCurve, int iSymbolFreq); + void setLinestyle (unsigned int iCurve, int iLinestyle); + void setLegend (unsigned int iCurve, const std::string& strLegend); + void setLegend (unsigned int iCurve, const char* const pszLegend); + + int m_iCurrentCurve; // Colors int clr_axis; // color of all axis lines @@ -320,11 +320,11 @@ private: int axis_scale (double min, double max, int nint, double *minp, double *maxp, int *nintp); SGP* m_pSGP; - POL m_pol; + POL m_pol; void clearCurves (); - bool ezcmd (const char* const comm); + bool ezcmd (const char* const comm); bool do_cmd(int lx); void bad_option(char *opt); void initPlotSettings(); @@ -341,7 +341,7 @@ private: EZPlot (); ~EZPlot (); - bool ezset (const std::string& command); + bool ezset (const std::string& command); bool ezset (const char* const command); void addCurve (const float* x, const double* y, int num); diff --git a/include/fnetorderstream.h b/include/fnetorderstream.h index a855939..9528004 100644 --- a/include/fnetorderstream.h +++ b/include/fnetorderstream.h @@ -1,31 +1,31 @@ -/***************************************************************************** -** FILE IDENTIFICATION -** -** Name: fnetorderstream.h -** Purpose: Network-order file stream header -** Programmer: Kevin Rosenberg -** Date Started: Sep 2000 -** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: fnetorderstream.h,v 1.6 2000/12/16 06:12:47 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 -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - - +/***************************************************************************** +** FILE IDENTIFICATION +** +** Name: fnetorderstream.h +** Purpose: Network-order file stream header +** Programmer: Kevin Rosenberg +** Date Started: Sep 2000 +** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: fnetorderstream.h,v 1.7 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + + #ifndef NETORDER_H #define NETORDER_H diff --git a/include/fourier.h b/include/fourier.h index 95aaeb0..5145cae 100644 --- a/include/fourier.h +++ b/include/fourier.h @@ -1,45 +1,45 @@ -/***************************************************************************** -** FILE IDENTIFICATION -** -** Name: fourier.h -** Purpose: Header for Fourier transform functions -** Programmer: Kevin Rosenberg -** Date Started: Dec 2000 -** -** This is part of the CTSim program -** Copyright (C) 1983-2001 Kevin Rosenberg -** -** $Id: fourier.h,v 1.1 2001/01/02 06:33:04 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 -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -#include - -class ImageFile; - -class Fourier { -public: - static void shuffleFourierToNaturalOrder (ImageFile& im); - static void shuffleNaturalToFourierOrder (ImageFile& im); - - static void shuffleNaturalToFourierOrder (float* pdVector, const int n); - static void shuffleNaturalToFourierOrder (double* pdVector, const int n); - static void shuffleNaturalToFourierOrder (std::complex* pdVector, const int n); - static void shuffleFourierToNaturalOrder (float* pdVector, const int n); - static void shuffleFourierToNaturalOrder (double* pdVector, const int n); - static void shuffleFourierToNaturalOrder (std::complex* pdVector, const int n); - -}; // namespace Fourier - +/***************************************************************************** +** FILE IDENTIFICATION +** +** Name: fourier.h +** Purpose: Header for Fourier transform functions +** Programmer: Kevin Rosenberg +** Date Started: Dec 2000 +** +** This is part of the CTSim program +** Copyright (C) 1983-2001 Kevin Rosenberg +** +** $Id: fourier.h,v 1.2 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +#include + +class ImageFile; + +class Fourier { +public: + static void shuffleFourierToNaturalOrder (ImageFile& im); + static void shuffleNaturalToFourierOrder (ImageFile& im); + + static void shuffleNaturalToFourierOrder (float* pdVector, const int n); + static void shuffleNaturalToFourierOrder (double* pdVector, const int n); + static void shuffleNaturalToFourierOrder (std::complex* pdVector, const int n); + static void shuffleFourierToNaturalOrder (float* pdVector, const int n); + static void shuffleFourierToNaturalOrder (double* pdVector, const int n); + static void shuffleFourierToNaturalOrder (std::complex* pdVector, const int n); + +}; // namespace Fourier + diff --git a/include/hashtable.h b/include/hashtable.h index 0f97edf..ea5dc43 100644 --- a/include/hashtable.h +++ b/include/hashtable.h @@ -1,87 +1,87 @@ -/* FILE IDENTIFICATION -** -** File Name: hashtable.h -** Author: Kevin Rosenberg -** Purpose: Header file for hash table library -** Date Started: Dec. 2000 -** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: hashtable.h,v 1.1 2000/12/27 20:09:19 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 -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -#ifndef HASHTABLE_H -#define HASHTABLE_H - - -class KeywordCodeEntry -{ -private: - std::string m_strKeyword; - int m_iCode; - class KeywordCodeEntry *m_pNext; - - public: - - KeywordCodeEntry (const char* const pszKeyword, int iCode); - - const char* const getKeyword() const - { return m_strKeyword.c_str(); } - - bool matchesKeyword (const char* const pszMatch) const; - - int getCode () const - { return m_iCode; } - - void setCode (int iCode) - { m_iCode = iCode; } - - void setNext (KeywordCodeEntry* pNext) - { m_pNext = pNext; } - - KeywordCodeEntry* getNext () - { return m_pNext; } -}; - - -class KeywordCodeHashTable { -public: - enum { - HASHSIZE = 100, - }; - - KeywordCodeHashTable() - { initTable(); } - - ~KeywordCodeHashTable() - { freeTable(); } - - void installKeywordCode (const char* const pszKeyword, int iCode); - KeywordCodeEntry* lookup (const char* const pszKeyword); - -private: - KeywordCodeEntry* m_hashTable[HASHSIZE]; - - int hash (const char* s); - void initTable (); - void freeTable (); -}; - -#endif - - +/* FILE IDENTIFICATION +** +** File Name: hashtable.h +** Author: Kevin Rosenberg +** Purpose: Header file for hash table library +** Date Started: Dec. 2000 +** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: hashtable.h,v 1.2 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +#ifndef HASHTABLE_H +#define HASHTABLE_H + + +class KeywordCodeEntry +{ +private: + std::string m_strKeyword; + int m_iCode; + class KeywordCodeEntry *m_pNext; + + public: + + KeywordCodeEntry (const char* const pszKeyword, int iCode); + + const char* const getKeyword() const + { return m_strKeyword.c_str(); } + + bool matchesKeyword (const char* const pszMatch) const; + + int getCode () const + { return m_iCode; } + + void setCode (int iCode) + { m_iCode = iCode; } + + void setNext (KeywordCodeEntry* pNext) + { m_pNext = pNext; } + + KeywordCodeEntry* getNext () + { return m_pNext; } +}; + + +class KeywordCodeHashTable { +public: + enum { + HASHSIZE = 100, + }; + + KeywordCodeHashTable() + { initTable(); } + + ~KeywordCodeHashTable() + { freeTable(); } + + void installKeywordCode (const char* const pszKeyword, int iCode); + KeywordCodeEntry* lookup (const char* const pszKeyword); + +private: + KeywordCodeEntry* m_hashTable[HASHSIZE]; + + int hash (const char* s); + void initTable (); + void freeTable (); +}; + +#endif + + diff --git a/include/imagefile.h b/include/imagefile.h index 3587f1c..eaa69af 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.27 2001/01/02 05:34:57 kevin Exp $ +** $Id: imagefile.h,v 1.28 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,9 +28,9 @@ #ifndef IMAGEFILE_H #define IMAGEFILE_H -#ifndef MSVC -#include -#endif +#ifndef MSVC +#include +#endif #include #include #include @@ -47,20 +47,20 @@ class F32Image : public Array2dFile { public: 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** getImaginaryArray (void) - { return (kfloat32**) (m_imaginaryArrayData); } - - kfloat32** const getImaginaryArray (void) const - { return (kfloat32** const) (m_imaginaryArrayData); } - + F32Image (void); + + 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; } @@ -79,18 +79,18 @@ class F64Image : public Array2dFile 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** getImaginaryArray (void) - { return (kfloat64**) (m_imaginaryArrayData); } - - kfloat64** const getImaginaryArray (void) const - { return (kfloat64** const) (m_imaginaryArrayData); } - + 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; } @@ -106,7 +106,7 @@ typedef F64Image ImageFileBase; typedef kfloat64 ImageFileValue; typedef kfloat64* ImageFileColumn; typedef kfloat64** ImageFileArray; -typedef kfloat64** const ImageFileArrayConst; +typedef kfloat64** const ImageFileArrayConst; typedef const kfloat64* ImageFileColumnConst; #else typedef F32Image ImageFileBase; @@ -114,34 +114,34 @@ typedef kfloat32 ImageFileValue; typedef kfloat32* ImageFileColumn; typedef kfloat32** ImageFileArray; typedef kfloat32** const ImageFileArrayConst; -typedef const kfloat32* ImageFileColumnConst; +typedef const kfloat32* ImageFileColumnConst; #endif class ImageFile : public ImageFileBase -{ -private: - - static const char* s_aszFormatName[]; - static const char* s_aszFormatTitle[]; - static const int s_iFormatCount; - -public: - - static const int FORMAT_INVALID; - static const int FORMAT_PGM; - static const int FORMAT_PGMASCII; -#if HAVE_PNG - static const int FORMAT_PNG; - static const int FORMAT_PNG16; -#endif - - static const int getFormatCount() {return s_iFormatCount;} - static const char** getFormatNameArray() {return s_aszFormatName;} - static const char** getFormatTitleArray() {return s_aszFormatTitle;} - static int convertFormatNameToID (const char* const formatName); - static const char* convertFormatIDToName (const int formatID); - static const char* convertFormatIDToTitle (const int formatID); +{ +private: + + static const char* s_aszFormatName[]; + static const char* s_aszFormatTitle[]; + static const int s_iFormatCount; + +public: + + static const int FORMAT_INVALID; + static const int FORMAT_PGM; + static const int FORMAT_PGMASCII; +#if HAVE_PNG + static const int FORMAT_PNG; + static const int FORMAT_PNG16; +#endif + + static const int getFormatCount() {return s_iFormatCount;} + static const char** getFormatNameArray() {return s_aszFormatName;} + static const char** getFormatTitleArray() {return s_aszFormatTitle;} + static int convertFormatNameToID (const char* const formatName); + static const char* convertFormatIDToName (const int formatID); + static const char* convertFormatIDToTitle (const int formatID); ImageFile (int nx, int ny) : ImageFileBase (nx, ny) @@ -150,44 +150,44 @@ public: ImageFile (void) : ImageFileBase () {} - - bool convertRealToComplex (); - bool convertComplexToReal (); + + bool convertRealToComplex (); + bool convertComplexToReal (); void filterResponse (const char* const domainName, double bw, const char* const filterName, double filt_param, double dInputScale = 1., double dOutputScale = 1.); - 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 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; bool printComparativeStatistics (const ImageFile& imComp, std::ostream& os) const; - + bool subtractImages (const ImageFile& rRHS, ImageFile& result) const; - bool addImages (const ImageFile& rRHS, ImageFile& result) const; - bool multiplyImages (const ImageFile& rRHS, ImageFile& result) const; - bool divideImages (const ImageFile& rRHS, ImageFile& result) const; - - bool scaleImage (ImageFile& result) const; - - bool invertPixelValues (ImageFile& result) const; - bool sqrt (ImageFile& result) const; - bool square (ImageFile& result) const; - bool log (ImageFile& result) const; - bool exp (ImageFile& result) const; - bool fourier (ImageFile& result) const; - bool inverseFourier (ImageFile& result) const; -#ifdef HAVE_FFTW - bool fft (ImageFile& result) const; - bool ifft (ImageFile& result) const; -#endif - bool magnitude (ImageFile& result) const; - bool phase (ImageFile& result) const; - + bool addImages (const ImageFile& rRHS, ImageFile& result) const; + bool multiplyImages (const ImageFile& rRHS, ImageFile& result) const; + bool divideImages (const ImageFile& rRHS, ImageFile& result) const; + + bool scaleImage (ImageFile& result) const; + + bool invertPixelValues (ImageFile& result) const; + bool sqrt (ImageFile& result) const; + bool square (ImageFile& result) const; + bool log (ImageFile& result) const; + bool exp (ImageFile& result) const; + bool fourier (ImageFile& result) const; + bool inverseFourier (ImageFile& result) const; +#ifdef HAVE_FFTW + bool fft (ImageFile& result) const; + bool ifft (ImageFile& result) const; +#endif + bool magnitude (ImageFile& result) const; + bool phase (ImageFile& result) const; + int display (void) const; int displayScaling (const int scaleFactor, ImageFileValue pmin, ImageFileValue pmax) const; - - bool exportImage (const char* const pszFormat, const char* const pszFilename, int nxcell, int nycell, double densmin, double densmax); + + bool exportImage (const char* const pszFormat, const char* const pszFilename, int nxcell, int nycell, double densmin, double densmax); #if HAVE_PNG bool writeImagePNG (const char* const outfile, int bitdepth, int nxcell, int nycell, double densmin, double densmax); diff --git a/include/msvc_compat.h b/include/msvc_compat.h index 188d849..494e362 100644 --- a/include/msvc_compat.h +++ b/include/msvc_compat.h @@ -10,7 +10,7 @@ #define strcasecmp _stricmp #define strncasecmp _strnicmp #define snprintf _snprintf - #define vsnprintf _vsnprintf + #define vsnprintf _vsnprintf #pragma warning(disable:4786) #endif #endif diff --git a/include/phantom.h b/include/phantom.h index f8187c2..286f3ed 100644 --- a/include/phantom.h +++ b/include/phantom.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: phantom.h,v 1.19 2001/01/02 07:47:36 kevin Exp $ +** $Id: phantom.h,v 1.20 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 @@ -64,10 +64,10 @@ class PhantomElement const int nOutlinePoints() const {return m_nPoints;} double* rectLimits() {return m_rectLimits;} - double* xOutline() {return m_xOutline;} - double* yOutline() {return m_yOutline;} - double* const xOutline() const {return m_xOutline;} - double* const yOutline() const {return m_yOutline;} + double* xOutline() {return m_xOutline;} + double* yOutline() {return m_yOutline;} + double* const xOutline() const {return m_xOutline;} + double* const yOutline() const {return m_yOutline;} const double atten() const {return m_atten;} const double diameter() const {return m_diameter;} const double xmin() const {return m_xmin;} @@ -78,8 +78,8 @@ class PhantomElement const double cx() const {return m_cx;} const double cy() const {return m_cy;} const double u() const {return m_u;} - const double v() const {return m_v;} - + const double v() const {return m_v;} + void printDefinition (std::ostream& os) const; void printDefinition (std::ostringstream& os) const; @@ -103,7 +103,7 @@ class PhantomElement static const double SCALE_PELEM_EXTENT; // increase pelem limits by 0.5% static PhmElemType convertNameToType (const char* const typeName); - static const char* const convertTypeToName (PhmElemType iType); + static const char* const convertTypeToName (PhmElemType iType); void makeTransformMatrices (); @@ -159,8 +159,8 @@ class Phantom bool createFromPhantom (const int phmid); bool createFromFile (const char* const fname); - - bool fileWrite (const char* const fname); + + bool fileWrite (const char* const fname); void addPElem (const PhantomElement& pelem); @@ -169,9 +169,9 @@ class Phantom void convertToImagefile (ImageFile& im, const int in_nsample, const int trace, const int colStart, const int colCount, bool bStoreAtColumnPos) const; void convertToImagefile (ImageFile& im, const int in_nsample, const int trace) const; - - void printDefinitions (std::ostream& os) const; - void printDefinitions (std::ostringstream& os) const; + + void printDefinitions (std::ostream& os) const; + void printDefinitions (std::ostringstream& os) const; bool fail() const {return m_fail;} const std::string& failMessage() const {return m_failMessage;} diff --git a/include/plotfile.h b/include/plotfile.h index b88793f..4097469 100644 --- a/include/plotfile.h +++ b/include/plotfile.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: plotfile.h,v 1.5 2001/01/02 07:47:36 kevin Exp $ +** $Id: plotfile.h,v 1.6 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 @@ -41,21 +41,21 @@ #include #include #include "ctsupport.h" -#include "plotfile.h" +#include "plotfile.h" // Plotfile structure: // 1. Lines that begin with # are comments // 2. ASCII file format // 3. Header lines begin with and end with -// 4. Valid headers +// 4. Valid headers // (signifies beginning of plotfile) -// (beginning of description lines) -// (signifies beginning of ezset commands) +// (beginning of description lines) +// (signifies beginning of ezset commands) // Beginning of data columns // 5. Data is ASCII file format, one record per line // Number of columns is variable and is set by ncolumns header - + class PlotFile @@ -63,7 +63,7 @@ class PlotFile private: std::string m_strFilename; std::string m_strDate; - std::vector m_vecStrDescriptions; + std::vector m_vecStrDescriptions; std::vector m_vecStrEzsetCommands; std::vector m_vecCurves; int m_iNumColumns; @@ -86,18 +86,18 @@ public: void setCurveSize (int iNCurves, int iNRecords); - void addDescription (const char* const pszDesc) - { m_vecStrDescriptions.push_back (pszDesc); } - - void addEzsetCommand (const char* const pszCmd) - { m_vecStrEzsetCommands.push_back (pszCmd); } + void addDescription (const char* const pszDesc) + { m_vecStrDescriptions.push_back (pszDesc); } + + void addEzsetCommand (const char* const pszCmd) + { m_vecStrEzsetCommands.push_back (pszCmd); } bool addColumn (int iCol, const double* const pdColumn); - bool addColumn (int iCol, const float* const pdColumn); - - void getColumn (int iCol, double *pdColumnData) const; - + bool addColumn (int iCol, const float* const pdColumn); + + void getColumn (int iCol, double *pdColumnData) const; + const std::string& getDate () const { return m_strDate; } @@ -106,10 +106,10 @@ public: int getNumRecords () const { return m_iNumRecords; } - - bool getMinMax (int startingCol, double& min, double& max) const; - - bool statistics (int startingCol, double& min, double& max, double& mean, double& mode, double& median, double &stddev) const; + + bool getMinMax (int startingCol, double& min, double& max) const; + + bool statistics (int startingCol, double& min, double& max, double& mean, double& mode, double& median, double &stddev) const; unsigned int getNumDescriptions (void) const { return m_vecStrDescriptions.size(); } @@ -117,12 +117,12 @@ public: const std::string& getDescription (int iDescIndex) const { return m_vecStrDescriptions[iDescIndex]; } - unsigned int getNumEzsetCommands (void) const - { return m_vecStrEzsetCommands.size(); } - - const std::string& getEzsetCommand (int iIndex) const - { return m_vecStrEzsetCommands[iIndex]; } - + unsigned int getNumEzsetCommands (void) const + { return m_vecStrEzsetCommands.size(); } + + const std::string& getEzsetCommand (int iIndex) const + { return m_vecStrEzsetCommands[iIndex]; } + bool fileRead (const char* const filename); bool fileWrite (const char* const filename); diff --git a/include/pol.h b/include/pol.h index 1d14989..f8f44e5 100644 --- a/include/pol.h +++ b/include/pol.h @@ -2,7 +2,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: pol.h,v 1.10 2000/12/29 20:11:42 kevin Exp $ +** $Id: pol.h,v 1.11 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 @@ -19,21 +19,21 @@ ******************************************************************************/ #ifndef __H_POL #define __H_POL - -#include "hashtable.h" -#include + +#include "hashtable.h" +#include class POL { public: - // codes for pol_usefile - enum { - P_USE_STR = 1, // use string as input source - P_USE_FILE, // use file as input source - }; - - + // codes for pol_usefile + enum { + P_USE_STR = 1, // use string as input source + P_USE_FILE, // use file as input source + }; + + POL(); ~POL(); @@ -57,157 +57,157 @@ class POL { int get_inputline (FILE *fp); void set_inputline (const char* const line); - - enum { - MAXTOK = 200, // maximum length of a token - MAXLINE = 1024, // maximum line length - MAXIDENT = 20, - MAXSKIPWORD = 20, - MAXSKIPCHAR = 20, - MIN_INT = -2000000000, - MAX_INT = 2000000000, - }; - - // token types - enum { - TT_STRING = 1, // string token - TT_INT, // integer token - TT_REAL, // floating point token - TT_ALPHA, // alphabetic token - TT_ALPNUM, // alphanumeric token - TT_NUMALPHA, - TT_SPECLCHAR, - TT_EOF, // end of file reached - TT_ERROR, // error in token, caused by call to wrong type of token reader - TT_BLANK, // white space token. pol_tok() skips these - TT_USERTOK, // user defined token - }; - - -private: - - // codes for pol_int and pol_float - // if in reject catagory, get new number from terminal - enum { - P_FLTINT = 1, // get a real or integer number - P_BFLTINT, // get a real or integer number, clip against bounds - P_CBFLTINT, // get real or int, reject if outside bounds - P_FLT, // get a real number - P_BFLT, // get a real, clip against bounds - P_CBFLT, // get a floating, reject if outside bounds - P_INT, // get a integer number - P_BINT, // get a integer, clip against bounds - P_CBINT, // get a integer, reject if outside bounds - }; - -#define LETTER 'a' -#define DIGIT '0' - - -// typedef std::map KeywordCodeList; - - struct token_st { - int ready; // TRUE if token is ready - // std::string tokstr; // token string - char tokstr[MAXTOK+1]; - int type; // type of token 'TT_' - int code; // holds code for user defined tokens - double fnum; // real value of token - int inum; // integer value of token - }; - typedef struct token_st TOKEN; - struct token_st token; // current token - - // Tables words stored with install() & found with lookup() - KeywordCodeHashTable skiptable; // words to ignore and skip - KeywordCodeHashTable cmdtable; // pol parameter commands - KeywordCodeHashTable usertable; // user defined symbols - - struct metachar { - char eoc; /* end of command character */ - char str; /* string delimiter */ - char com; /* comment character */ - char cmd; /* pol parameter command character */ - char prg; /* program load character */ - char con; /* continuation across newline character */ - char out; /* character that delimits output to terminal */ - char ter; /* character indicates insertion of input from terminal */ - char inb; /* input from graphics device */ - } meta; - - - char m_szSkipChars [MAXSKIPCHAR]; // characters to skip - bool m_bTrace; - bool m_bNewlineIsEOC; - - struct KeywordCodeList { - char *keyword; - int code; - }; - - static const struct KeywordCodeList cmdlist[]; - static const unsigned int NUMCMD; - - // Internal codes for pol commands - enum { - PC_EOC = 1, - PC_STR, - PC_COM, - PC_CMD, - PC_PRG, - PC_CON, - PC_OUT, - PC_TER, - PC_INB, - PC_NL_EOC, - PC_NL_NEOC, - PC_TRON, - PC_TROFF, - PC_FILE, - PC_DUMP, - }; - - enum { - INPUT_STREAM = 1, - INPUT_FILE, - INPUT_STRING, - }; - - int m_iInputType; - std::istream* m_pInputStream; - FILE* m_pInputFile; - char* m_pszInputString; - - enum { - MAXFILE = 8, - }; - - int currentf; /* pointer to current fp */ - FILE *filep[MAXFILE]; /* == NULL for string input */ - char *fname[MAXFILE]; /* pointer to filename */ - - char inputline[MAXLINE]; /* current input line */ - int lineptr; /* current position in inputline */ - - std::stack m_stackPushBackInput; - - bool skipSingleToken (char term[]); - int tok (struct token_st *token); - void dumptok (struct token_st *token); - - - int getpol_tok (struct token_st *token); - int getcmd (); - int gettok (TOKEN *tok); - void getblank (char *s, int toksiz); - int getalpha (char *s, int toksiz); - void getquote (char *qs, int toksiz); - void getescape (char *s, int delim, int toksiz); - int getnumber (char str[], int strsize, double *fnum, int *inum); - void eatline (); - int type (int c); - int getch (FILE *fp); - + + enum { + MAXTOK = 200, // maximum length of a token + MAXLINE = 1024, // maximum line length + MAXIDENT = 20, + MAXSKIPWORD = 20, + MAXSKIPCHAR = 20, + MIN_INT = -2000000000, + MAX_INT = 2000000000, + }; + + // token types + enum { + TT_STRING = 1, // string token + TT_INT, // integer token + TT_REAL, // floating point token + TT_ALPHA, // alphabetic token + TT_ALPNUM, // alphanumeric token + TT_NUMALPHA, + TT_SPECLCHAR, + TT_EOF, // end of file reached + TT_ERROR, // error in token, caused by call to wrong type of token reader + TT_BLANK, // white space token. pol_tok() skips these + TT_USERTOK, // user defined token + }; + + +private: + + // codes for pol_int and pol_float + // if in reject catagory, get new number from terminal + enum { + P_FLTINT = 1, // get a real or integer number + P_BFLTINT, // get a real or integer number, clip against bounds + P_CBFLTINT, // get real or int, reject if outside bounds + P_FLT, // get a real number + P_BFLT, // get a real, clip against bounds + P_CBFLT, // get a floating, reject if outside bounds + P_INT, // get a integer number + P_BINT, // get a integer, clip against bounds + P_CBINT, // get a integer, reject if outside bounds + }; + +#define LETTER 'a' +#define DIGIT '0' + + +// typedef std::map KeywordCodeList; + + struct token_st { + int ready; // TRUE if token is ready + // std::string tokstr; // token string + char tokstr[MAXTOK+1]; + int type; // type of token 'TT_' + int code; // holds code for user defined tokens + double fnum; // real value of token + int inum; // integer value of token + }; + typedef struct token_st TOKEN; + struct token_st token; // current token + + // Tables words stored with install() & found with lookup() + KeywordCodeHashTable skiptable; // words to ignore and skip + KeywordCodeHashTable cmdtable; // pol parameter commands + KeywordCodeHashTable usertable; // user defined symbols + + struct metachar { + char eoc; /* end of command character */ + char str; /* string delimiter */ + char com; /* comment character */ + char cmd; /* pol parameter command character */ + char prg; /* program load character */ + char con; /* continuation across newline character */ + char out; /* character that delimits output to terminal */ + char ter; /* character indicates insertion of input from terminal */ + char inb; /* input from graphics device */ + } meta; + + + char m_szSkipChars [MAXSKIPCHAR]; // characters to skip + bool m_bTrace; + bool m_bNewlineIsEOC; + + struct KeywordCodeList { + char *keyword; + int code; + }; + + static const struct KeywordCodeList cmdlist[]; + static const unsigned int NUMCMD; + + // Internal codes for pol commands + enum { + PC_EOC = 1, + PC_STR, + PC_COM, + PC_CMD, + PC_PRG, + PC_CON, + PC_OUT, + PC_TER, + PC_INB, + PC_NL_EOC, + PC_NL_NEOC, + PC_TRON, + PC_TROFF, + PC_FILE, + PC_DUMP, + }; + + enum { + INPUT_STREAM = 1, + INPUT_FILE, + INPUT_STRING, + }; + + int m_iInputType; + std::istream* m_pInputStream; + FILE* m_pInputFile; + char* m_pszInputString; + + enum { + MAXFILE = 8, + }; + + int currentf; /* pointer to current fp */ + FILE *filep[MAXFILE]; /* == NULL for string input */ + char *fname[MAXFILE]; /* pointer to filename */ + + char inputline[MAXLINE]; /* current input line */ + int lineptr; /* current position in inputline */ + + std::stack m_stackPushBackInput; + + bool skipSingleToken (char term[]); + int tok (struct token_st *token); + void dumptok (struct token_st *token); + + + int getpol_tok (struct token_st *token); + int getcmd (); + int gettok (TOKEN *tok); + void getblank (char *s, int toksiz); + int getalpha (char *s, int toksiz); + void getquote (char *qs, int toksiz); + void getescape (char *s, int delim, int toksiz); + int getnumber (char str[], int strsize, double *fnum, int *inum); + void eatline (); + int type (int c); + int getch (FILE *fp); + }; #endif diff --git a/include/procsignal.h b/include/procsignal.h index 2be3b7c..a3b7440 100644 --- a/include/procsignal.h +++ b/include/procsignal.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: procsignal.h,v 1.11 2001/01/02 05:34:57 kevin Exp $ +** $Id: procsignal.h,v 1.12 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 @@ -41,9 +41,9 @@ class SignalFilter; class SGP; - -typedef std::complex CTSimComplex; - + +typedef std::complex CTSimComplex; + class ProcessSignal { public: @@ -60,11 +60,11 @@ class ProcessSignal { static const int FILTER_GENERATION_INVALID; static const int FILTER_GENERATION_DIRECT; static const int FILTER_GENERATION_INVERSE_FOURIER; - - enum { - FORWARD = -1, - BACKWARD = 1, - }; + + enum { + FORWARD = -1, + BACKWARD = 1, + }; ProcessSignal (const char* szFilterName, const char* szFilterMethodName,double bw, double signalIncrement, int n, double param, const char* szDomainName, const char* szFilterGenerationName, const int zeropad = 0, const int preinterpolationFactor = 1, const int iTraceLevel = Trace::TRACE_NONE, int iGeometry = Scanner::GEOMETRY_PARALLEL, double dFocalLength = 1., SGP* pSGP = NULL); @@ -105,7 +105,7 @@ class ProcessSignal { static void finiteFourierTransform (const double input[], std::complex output[], const int n, const int direction); static void finiteFourierTransform (const std::complex input[], std::complex output[], const int n, const int direction); static void finiteFourierTransform (const std::complex input[], double output[], const int n, const int direction); - + private: std::string m_nameFilterMethod; diff --git a/include/sgp.h b/include/sgp.h index 2a1472b..2d83b2e 100644 --- a/include/sgp.h +++ b/include/sgp.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: sgp.h,v 1.23 2000/12/25 21:54:26 kevin Exp $ +** $Id: sgp.h,v 1.24 2001/01/02 16:02:13 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 @@ -127,7 +127,7 @@ private: double m_dTextAngle; bool m_bRecalcTransform; double m_dPointsPerPixel; // points (72pt/in) per screen pixel; - int m_iLinestyle; + int m_iLinestyle; // Master coordinates are coordinates before CTM transformation // World coordinates are coordinates defined by setWindow() @@ -175,7 +175,7 @@ public: static const unsigned char MARKER_BITMAP[MARK_COUNT][5]; SGP (const SGPDriver& driver); - ~SGP(); + ~SGP(); void drawCircle (const double r); void drawArc (const double r, double start, double stop); diff --git a/libctgraphics/ezset.cpp b/libctgraphics/ezset.cpp index 222b3cd..e70620f 100644 --- a/libctgraphics/ezset.cpp +++ b/libctgraphics/ezset.cpp @@ -6,7 +6,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ezset.cpp,v 1.15 2000/12/29 15:45:06 kevin Exp $ +** $Id: ezset.cpp,v 1.16 2001/01/02 16:02:13 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 @@ -26,17 +26,17 @@ #include "ezplot.h" #include "pol.h" - -bool -EZPlot::ezset (const std::string& command) -{ - return ezset (command.c_str()); -} + +bool +EZPlot::ezset (const std::string& command) +{ + return ezset (command.c_str()); +} bool EZPlot::ezset (const char* const command) { - + return ezcmd (command); } @@ -91,8 +91,8 @@ EZPlot::do_cmd (int lx) c_title = strIn; break; case S_LEGEND: - m_pol.readText (strIn, sizeof(strIn)); - if (m_iCurrentCurve >= 0) + m_pol.readText (strIn, sizeof(strIn)); + if (m_iCurrentCurve >= 0) setLegend (m_iCurrentCurve, strIn); break; case S_XLABEL: @@ -171,24 +171,24 @@ EZPlot::do_cmd (int lx) o_linestyle = SGP::LS_SOLID; break; case S_DASH: - int ls; - ls = SGP::LS_DASH1; - if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { + int ls; + ls = SGP::LS_DASH1; + if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { if (n == 1) ls = SGP::LS_DASH1; else if (n == 2) ls = SGP::LS_DASH2; else if (n == 3) ls = SGP::LS_DASH3; - else if (n == 4) - ls = SGP::LS_DASH4; - else if (n == 5) - ls = SGP::LS_DOTTED; - } - if (m_iCurrentCurve < 0) - o_linestyle = ls; - else - setLinestyle (m_iCurrentCurve, ls); + else if (n == 4) + ls = SGP::LS_DASH4; + else if (n == 5) + ls = SGP::LS_DOTTED; + } + if (m_iCurrentCurve < 0) + o_linestyle = ls; + else + setLinestyle (m_iCurrentCurve, ls); break; case S_NOLINE: o_linestyle = SGP::LS_NOLINE; @@ -197,11 +197,11 @@ EZPlot::do_cmd (int lx) case S_COLOR: if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { - if (n >= 0) { + if (n >= 0) { if (m_iCurrentCurve < 0) - o_color = n; - else - setColor (m_iCurrentCurve, n); + o_color = n; + else + setColor (m_iCurrentCurve, n); } else bad_option("The color you picked"); } @@ -283,36 +283,36 @@ EZPlot::do_cmd (int lx) case S_SYMBOL: if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { if (n > 0 && n <= MAXSYMBOL) { - if (m_iCurrentCurve < 0) - o_symbol = n; - else - setSymbol (m_iCurrentCurve, n); - } + if (m_iCurrentCurve < 0) + o_symbol = n; + else + setSymbol (m_iCurrentCurve, n); + } } else { if (m_pol.readWord("every",5) == TRUE) { - if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { + if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { int sym = 1; - if (n > 0) - sym = n; - if (m_iCurrentCurve < 0) - o_symfreq = sym; - else - setSymbolFreq (m_iCurrentCurve, sym); + if (n > 0) + sym = n; + if (m_iCurrentCurve < 0) + o_symfreq = sym; + else + setSymbolFreq (m_iCurrentCurve, sym); } } else if (m_pol.readWord ("none",4) == TRUE) { o_symbol = -1; } } break; - case S_CURVE: - if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { - if (n > 0) - m_iCurrentCurve = n - 1; - } else { - if (m_pol.readWord ("all",3) == TRUE) - m_iCurrentCurve = -1; - } - break; + case S_CURVE: + if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { + if (n > 0) + m_iCurrentCurve = n - 1; + } else { + if (m_pol.readWord ("all",3) == TRUE) + m_iCurrentCurve = -1; + } + break; case S_XTICKS: if (m_pol.readUserToken(str,&lx) == FALSE) break; @@ -382,21 +382,21 @@ EZPlot::do_cmd (int lx) } - + void EZPlot::bad_option (char *opt) { sys_error (ERR_WARNING, "INVALID option: %s", opt); } - + //---------------------------------------------------------------------- // KEYWORDS / CODES TABLE //---------------------------------------------------------------------- -const struct KeywordCodeTable EZPlot::m_sKeywords[] = -{ +const struct KeywordCodeTable EZPlot::m_sKeywords[] = +{ {"solid", S_SOLID}, - {"dash", S_DASH}, + {"dash", S_DASH}, {"curve", S_CURVE}, {"noline", S_NOLINE}, {"black", S_BLACK}, @@ -473,7 +473,7 @@ const struct KeywordCodeTable EZPlot::m_sKeywords[] = {"textsize", S_TEXTSIZE}, }; - + const int EZPlot::NKEYS = (sizeof(EZPlot::m_sKeywords) / sizeof (struct KeywordCodeTable)); void diff --git a/libctgraphics/pol.cpp b/libctgraphics/pol.cpp index 9c0e427..22741e3 100644 --- a/libctgraphics/pol.cpp +++ b/libctgraphics/pol.cpp @@ -6,7 +6,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: pol.cpp,v 1.8 2000/12/29 15:45:06 kevin Exp $ +** $Id: pol.cpp,v 1.9 2001/01/02 16:02:13 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 @@ -22,7 +22,7 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -#include "ct.h" +#include "ct.h" #include #include #include @@ -50,11 +50,11 @@ const struct POL::KeywordCodeList POL::cmdlist[] = { }; const unsigned int POL::NUMCMD = (sizeof(POL::cmdlist) / sizeof (struct POL::KeywordCodeList)); - + POL::POL() { - currentf = -1; + currentf = -1; m_bTrace = false; init(); } @@ -76,7 +76,7 @@ POL::init () meta.ter = PERCENT; meta.inb = LBRACK; - m_bNewlineIsEOC = true; + m_bNewlineIsEOC = true; m_szSkipChars[0] = EOS; @@ -85,7 +85,7 @@ POL::init () token.ready = false; // no token read yet } - + /* addSkipWord (w) * @@ -107,11 +107,11 @@ POL::addSkipWord (const char* const w) */ void POL::addSkipChar (int c) -{ - int n = strlen (m_szSkipChars); - if (n < MAXSKIPCHAR) { - m_szSkipChars[n] = c; - m_szSkipChars[n+1] = 0; +{ + int n = strlen (m_szSkipChars); + if (n < MAXSKIPCHAR) { + m_szSkipChars[n] = c; + m_szSkipChars[n+1] = 0; } } @@ -122,7 +122,7 @@ POL::addSkipChar (int c) // // tok() looks for these user defined tokens. If it finds one, // it stores the tokens code in the token structure and returns TT_USERTOK -void +void POL::addKeyword (const char* const str, int code) { usertable.installKeywordCode (str, code); @@ -228,7 +228,7 @@ POL::readInteger (int *n, int typecode, bool boundcode, int bb1, int bb2) return (false); } -bool +bool POL::readFloat (double *n, double typecode, bool boundcode, double bb1, double bb2) { tok (&token); @@ -275,7 +275,7 @@ POL::skipTokens() return (skipSingleToken (term)); } -void +void POL::reader() { while (skipTokens()) @@ -621,7 +621,7 @@ POL::getescape ( /* reads up to delim */ } s[i] = EOS; } - + bool POL::readText (char *str, int lim) @@ -630,17 +630,17 @@ POL::readText (char *str, int lim) while ((c = inchar()) == BLANK || c == TAB) ; ungetch (c); - if (c == EOF) { - str[0] = 0; - return false; - } - + if (c == EOF) { + str[0] = 0; + return false; + } + int i; for (i = 0; i < lim && (c = inchar()) != EOF && c != NEWLINE; i++) str[i] = c; ungetch (c); - str[i] = 0; - + str[i] = 0; + return true; } @@ -831,9 +831,9 @@ POL::usefile (int source, char *fn) sys_error (ERR_SEVERE, "files nested too deeply"); return; } - - while (! m_stackPushBackInput.empty()) - m_stackPushBackInput.pop(); + + while (! m_stackPushBackInput.empty()) + m_stackPushBackInput.pop(); if (source == P_USE_STR) { filep[currentf] = NULL; @@ -898,12 +898,12 @@ POL::inchar() int POL::getch (FILE *fp) { - int c; - if (m_stackPushBackInput.size() > 0) { - c = m_stackPushBackInput.top(); - m_stackPushBackInput.pop(); - return c; - } + int c; + if (m_stackPushBackInput.size() > 0) { + c = m_stackPushBackInput.top(); + m_stackPushBackInput.pop(); + return c; + } if (fp == NULL) { if ((c = inputline[lineptr]) == EOS) @@ -922,17 +922,17 @@ POL::getch (FILE *fp) void POL::ungetch (int c) { - m_stackPushBackInput.push (c); + m_stackPushBackInput.push (c); } int POL::get_inputline (FILE *fp) { - while (! m_stackPushBackInput.empty()) - m_stackPushBackInput.pop(); - - lineptr = 0; + while (! m_stackPushBackInput.empty()) + m_stackPushBackInput.pop(); + + lineptr = 0; if (fgets (inputline, MAXLINE, fp) == NULL) return (EOF); else @@ -942,9 +942,9 @@ POL::get_inputline (FILE *fp) void POL::set_inputline (const char* const line) { - while (! m_stackPushBackInput.empty()) - m_stackPushBackInput.pop(); - + while (! m_stackPushBackInput.empty()) + m_stackPushBackInput.pop(); + strncpy (inputline, line, MAXLINE); - lineptr = 0; + lineptr = 0; } diff --git a/libctgraphics/sgp.cpp b/libctgraphics/sgp.cpp index a745093..ec129d2 100644 --- a/libctgraphics/sgp.cpp +++ b/libctgraphics/sgp.cpp @@ -7,7 +7,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: sgp.cpp,v 1.24 2000/12/26 21:13:15 kevin Exp $ +** $Id: sgp.cpp,v 1.25 2001/01/02 16:02:13 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 @@ -98,18 +98,18 @@ SGP::SGP (const SGPDriver& driver) static const double dScreenDPI = 82; static const double dPointsPerInch = 72.; m_dPointsPerPixel = dPointsPerInch / dScreenDPI; - const int iTestPointSize = 12; + const int iTestPointSize = 12; m_pFont = new wxFont (wxROMAN, wxNORMAL, wxNORMAL, wxNORMAL); - m_pFont->SetPointSize (iTestPointSize); - m_pFont->SetWeight (wxNORMAL); + m_pFont->SetPointSize (iTestPointSize); + m_pFont->SetWeight (wxNORMAL); m_pFont->SetStyle (wxNORMAL); - m_pFont->SetFamily (wxROMAN); -#ifdef MSVC - m_pFont->SetFaceName(wxString("times new roman")); -#endif + m_pFont->SetFamily (wxROMAN); +#ifdef MSVC + m_pFont->SetFaceName(wxString("times new roman")); +#endif m_driver.idWX()->SetFont (*m_pFont); double dTestCharHeight = m_driver.idWX()->GetCharHeight(); - m_dPointsPerPixel = iTestPointSize / dTestCharHeight; + m_dPointsPerPixel = iTestPointSize / dTestCharHeight; m_driver.idWX()->SetBackground (*wxWHITE_BRUSH); } #endif @@ -121,19 +121,19 @@ SGP::SGP (const SGPDriver& driver) setTextAngle (0.); setTextPointSize (12); - setColor (C_BLACK); + setColor (C_BLACK); setLineStyle (LS_SOLID); } -SGP::~SGP() -{ -#if HAVE_WXWINDOWS - if (m_driver.isWX()) { - m_driver.idWX()->SetFont (wxNullFont); - delete m_pFont; - } -#endif -} +SGP::~SGP() +{ +#if HAVE_WXWINDOWS + if (m_driver.isWX()) { + m_driver.idWX()->SetFont (wxNullFont); + delete m_pFont; + } +#endif +} void SGP::stylusNDC (double x, double y, bool beam) @@ -179,19 +179,19 @@ SGP::eraseWindow () g2_clear (m_driver.idG2()); #endif #if HAVE_WXWINDOWS - if (m_driver.isWX()) { - wxBrush brushWhite; - brushWhite.SetColour(255,255,255); - m_driver.idWX()->SetBackground(brushWhite); - m_driver.idWX()->Clear(); - m_driver.idWX()->SetBackground(wxNullBrush); -#if 1 - wxPen pen; - pen.SetColour(255,255,255); - m_driver.idWX()->SetBrush (brushWhite); - m_driver.idWX()->DrawRectangle (0, 0, m_iPhysicalXSize, m_iPhysicalYSize); - m_driver.idWX()->SetBrush (wxNullBrush); -#endif + if (m_driver.isWX()) { + wxBrush brushWhite; + brushWhite.SetColour(255,255,255); + m_driver.idWX()->SetBackground(brushWhite); + m_driver.idWX()->Clear(); + m_driver.idWX()->SetBackground(wxNullBrush); +#if 1 + wxPen pen; + pen.SetColour(255,255,255); + m_driver.idWX()->SetBrush (brushWhite); + m_driver.idWX()->DrawRectangle (0, 0, m_iPhysicalXSize, m_iPhysicalYSize); + m_driver.idWX()->SetBrush (wxNullBrush); +#endif } #endif } @@ -394,37 +394,37 @@ SGP::setMarker (int idMarke, int iColor) //============================================================== void SGP::setLineStyle (int style) -{ - m_iLinestyle = style; - -#if HAVE_WXWINDOWS - if (m_driver.isWX()) { - switch (m_iLinestyle) { - case LS_SOLID: - m_pen.SetStyle (wxSOLID); - break; - case LS_DASH1: - m_pen.SetStyle (wxLONG_DASH); - break; - case LS_DASH2: - m_pen.SetStyle (wxSHORT_DASH); - break; - case LS_DASH3: - m_pen.SetStyle (wxDOT_DASH); - break; - case LS_DASH4: - m_pen.SetStyle (wxCROSS_HATCH); - break; - case LS_DOTTED: - m_pen.SetStyle (wxDOT); - break; - default: - m_pen.SetStyle (wxSOLID); - break; - } - m_driver.idWX()->SetPen (m_pen); - } -#endif +{ + m_iLinestyle = style; + +#if HAVE_WXWINDOWS + if (m_driver.isWX()) { + switch (m_iLinestyle) { + case LS_SOLID: + m_pen.SetStyle (wxSOLID); + break; + case LS_DASH1: + m_pen.SetStyle (wxLONG_DASH); + break; + case LS_DASH2: + m_pen.SetStyle (wxSHORT_DASH); + break; + case LS_DASH3: + m_pen.SetStyle (wxDOT_DASH); + break; + case LS_DASH4: + m_pen.SetStyle (wxCROSS_HATCH); + break; + case LS_DOTTED: + m_pen.SetStyle (wxDOT); + break; + default: + m_pen.SetStyle (wxSOLID); + break; + } + m_driver.idWX()->SetPen (m_pen); + } +#endif } //============================================================== @@ -532,11 +532,11 @@ SGP::getTextExtent (const char* szText, double* worldW, double* worldH) if (m_driver.isWX()) { wxString sText (szText); wxCoord deviceW, deviceH; - m_driver.idWX()->GetTextExtent (sText, &deviceW, &deviceH); - if (m_dTextAngle == 90 || m_dTextAngle == -90) { - wxCoord temp = deviceW; - deviceW = deviceH; - deviceH = temp; + m_driver.idWX()->GetTextExtent (sText, &deviceW, &deviceH); + if (m_dTextAngle == 90 || m_dTextAngle == -90) { + wxCoord temp = deviceW; + deviceW = deviceH; + deviceH = temp; } *worldW = (xw_max - xw_min) * deviceW / static_cast(m_iPhysicalXSize);; *worldH = (yw_max - yw_min) * deviceH / static_cast(m_iPhysicalYSize); @@ -552,7 +552,7 @@ SGP::getCharHeight () #if HAVE_WXWINDOWS if (m_driver.isWX()) { dHeight = m_driver.idWX()->GetCharHeight(); - dHeight /= static_cast(m_iPhysicalYSize); + dHeight /= static_cast(m_iPhysicalYSize); dHeight /= (yv_max - yv_min); // scale to viewport; } #endif @@ -568,7 +568,7 @@ SGP::getCharWidth () #if HAVE_WXWINDOWS if (m_driver.isWX()) { dWidth = m_driver.idWX()->GetCharWidth(); - dWidth /= static_cast(m_iPhysicalXSize); + dWidth /= static_cast(m_iPhysicalXSize); dWidth /= (xv_max - xv_min); // scale to viewport } #endif diff --git a/libctgraphics/transformmatrix.cpp b/libctgraphics/transformmatrix.cpp index 9edf3aa..ce27a3e 100644 --- a/libctgraphics/transformmatrix.cpp +++ b/libctgraphics/transformmatrix.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: transformmatrix.cpp,v 1.3 2000/12/06 01:46:43 kevin Exp $ +** $Id: transformmatrix.cpp,v 1.4 2001/01/02 16:02:13 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 @@ -25,10 +25,10 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -#include +#include #include "ctsupport.h" #include "transformmatrix.h" - + TransformationMatrix2D::TransformationMatrix2D (double m[3][3]) { @@ -92,8 +92,8 @@ TransformationMatrix2D::invert () const double determ = determinant (); if (fabs(determ) < 1E-6) { - sys_error (ERR_WARNING, "Determinant = %g [TransformationMatrix2D::invert]", determ); - print (std::cout); + sys_error (ERR_WARNING, "Determinant = %g [TransformationMatrix2D::invert]", determ); + print (std::cout); std::cout << std::endl; } diff --git a/libctsim/array2dfile.cpp b/libctsim/array2dfile.cpp index 49f90f4..555d22e 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.26 2001/01/02 07:47:36 kevin Exp $ +** $Id: array2dfile.cpp,v 1.27 2001/01/02 16:02:13 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 @@ -26,9 +26,9 @@ ******************************************************************************/ #include "array2dfile.h" -#include -#ifdef MSVC -typedef long off_t; +#include +#ifdef MSVC +typedef long off_t; #endif @@ -108,8 +108,8 @@ Array2dFileLabel::getDateTime (int& year, int& month, int& day, int& hour, int& const std::string& Array2dFileLabel::getDateString (void) const { - char szDate [128]; - snprintf (szDate, sizeof(szDate), "%2d/%02d/%4d %02d:%02d:%02d", + 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_strDate = szDate; return m_strDate; @@ -137,53 +137,53 @@ Array2dFileLabel::operator= (const Array2dFileLabel& rhs) return (*this); } -void -Array2dFileLabel::print (std::ostream& os) const -{ - if (m_labelType == L_HISTORY) { - os << "History: " << std::endl; - os << " " << m_strLabel << std::endl; - os << " calc time = " << m_calcTime << " secs" << std::endl; - os << " Timestamp = " << getDateString() << std::endl; - } else if (m_labelType == L_USER) { - os << "Note: " << m_strLabel << std::endl; - os << " Timestamp = %s" << getDateString() << std::endl; - } else { - os << "Unknown (" << m_labelType << "): " << m_strLabel << std::endl; - os << " Timestamp = %s" << getDateString() << std::endl; - } -} - -void -Array2dFileLabel::printBrief (std::ostream& os) const -{ - if (m_labelType == L_HISTORY) { - os << "History ("; - if (m_calcTime > 0) - os << m_calcTime << " secs, "; - os << getDateString() << "): " << m_strLabel << std::endl; - } else if (m_labelType == L_USER) { - os << "Note (" << getDateString() << "): " << m_strLabel << std::endl; - } else { - os << "Unknown (" << getDateString() << "): " << m_strLabel << std::endl; - } -} - -void -Array2dFileLabel::printBrief (std::ostringstream& os) const -{ - if (m_labelType == L_HISTORY) { - os << "History ("; - if (m_calcTime > 0) - os << m_calcTime << " secs, "; +void +Array2dFileLabel::print (std::ostream& os) const +{ + if (m_labelType == L_HISTORY) { + os << "History: " << std::endl; + os << " " << m_strLabel << std::endl; + os << " calc time = " << m_calcTime << " secs" << std::endl; + os << " Timestamp = " << getDateString() << std::endl; + } else if (m_labelType == L_USER) { + os << "Note: " << m_strLabel << std::endl; + os << " Timestamp = %s" << getDateString() << std::endl; + } else { + os << "Unknown (" << m_labelType << "): " << m_strLabel << std::endl; + os << " Timestamp = %s" << getDateString() << std::endl; + } +} + +void +Array2dFileLabel::printBrief (std::ostream& os) const +{ + if (m_labelType == L_HISTORY) { + os << "History ("; + if (m_calcTime > 0) + os << m_calcTime << " secs, "; + os << getDateString() << "): " << m_strLabel << std::endl; + } else if (m_labelType == L_USER) { + os << "Note (" << getDateString() << "): " << m_strLabel << std::endl; + } else { + os << "Unknown (" << getDateString() << "): " << m_strLabel << std::endl; + } +} + +void +Array2dFileLabel::printBrief (std::ostringstream& os) const +{ + if (m_labelType == L_HISTORY) { + os << "History ("; + if (m_calcTime > 0) + os << m_calcTime << " secs, "; os << getDateString().c_str() << "): " << m_strLabel.c_str() << "\n"; - } else if (m_labelType == L_USER) { + } else if (m_labelType == L_USER) { os << "Note (" << getDateString() << "): " << m_strLabel << "\n"; - } else { + } else { os << "Unknown (" << getDateString() << "): " << m_strLabel << "\n"; - } -} - + } +} + /////////////////////////////////////////////////////////////////////////// // CLASS IMPLEMENTATION @@ -216,8 +216,8 @@ Array2dFile::init (void) { m_pixelSize = 0; m_pixelFormat = PIXEL_INVALID; - m_arrayData = NULL; - m_imaginaryArrayData = NULL; + m_arrayData = NULL; + m_imaginaryArrayData = NULL; m_dataType = DATA_TYPE_INVALID; m_nx = 0; m_ny = 0; @@ -235,7 +235,7 @@ void Array2dFile::setArraySize (int x, int y, int pixelSize, int pixelFormat, int dataType) { m_pixelSize = pixelSize; - m_pixelFormat = pixelFormat; + m_pixelFormat = pixelFormat; m_dataType = dataType; setArraySize (x, y); } @@ -246,78 +246,78 @@ Array2dFile::setArraySize (int x, int y) 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; -} - +} + +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::allocArrays () { - 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) -{ + 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]; + 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]; + rppData[i] = new unsigned char [columnBytes]; } void 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; -} - + 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) @@ -358,11 +358,11 @@ Array2dFile::fileRead (const char* const filename) { m_filename = filename; -#ifdef MSVC - 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); -#endif +#ifdef MSVC + 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); +#endif if (fs.fail()) { sys_error (ERR_WARNING, "Unable to open file %s [fileRead]", m_filename.c_str()); return false; @@ -417,7 +417,7 @@ Array2dFile::headerRead (frnetorderstream& fs) 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); @@ -461,7 +461,7 @@ 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); @@ -495,30 +495,30 @@ Array2dFile::arrayDataWrite (frnetorderstream& fs) 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); - } - 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); - } - } + 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; } @@ -537,30 +537,30 @@ Array2dFile::arrayDataRead (frnetorderstream& fs) 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); - } - 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); - } - } + 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; } @@ -593,10 +593,10 @@ Array2dFile::labelsRead (frnetorderstream& fs) pszLabelStr[strLength] = 0; Array2dFileLabel* pLabel = new Array2dFileLabel (labelType, pszLabelStr, calcTime); - delete pszLabelStr; - + delete pszLabelStr; + pLabel->setDateTime (year, month, day, hour, minute, second); - m_labels.push_back (pLabel); + m_labels.push_back (pLabel); } return true; @@ -678,49 +678,49 @@ Array2dFile::labelsCopy (const Array2dFile& copyFile, const char* const pszId) 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_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; - } -} - -void -Array2dFile::printLabelsBrief (std::ostream& os) const -{ - for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) { - const Array2dFileLabel& label = **l; - - label.printBrief (os); - } -} - + 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::printLabelsBrief (std::ostringstream& os) const -{ - for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) { - const Array2dFileLabel& label = **l; - - label.printBrief (os); - } -} - +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; + } +} + +void +Array2dFile::printLabelsBrief (std::ostream& os) const +{ + for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) { + const Array2dFileLabel& label = **l; + + label.printBrief (os); + } +} + +void +Array2dFile::printLabelsBrief (std::ostringstream& os) const +{ + for (constLabelIterator l = m_labels.begin(); l != m_labels.end(); l++) { + const Array2dFileLabel& label = **l; + + label.printBrief (os); + } +} + const Array2dFileLabel& Array2dFile::labelGet (int i) const diff --git a/libctsim/backprojectors.cpp b/libctsim/backprojectors.cpp index 726e5b8..1f8a1d2 100644 --- a/libctsim/backprojectors.cpp +++ b/libctsim/backprojectors.cpp @@ -8,7 +8,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: backprojectors.cpp,v 1.21 2001/01/01 10:14:34 kevin Exp $ +** $Id: backprojectors.cpp,v 1.22 2001/01/02 16:02:13 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 @@ -264,12 +264,12 @@ Backproject::Backproject (const Projections& proj, ImageFile& im, int interpType iDetCenter = (nDet - 1) / 2; // index refering to L=0 projection rotScale = proj.rotInc(); - if (proj.geometry() == Scanner::GEOMETRY_PARALLEL) - rotScale /= (proj.nView() * proj.rotInc() / PI); // scale by number of PI rotations - else if (proj.geometry() == Scanner::GEOMETRY_EQUIANGULAR || proj.geometry() == Scanner::GEOMETRY_EQUILINEAR) - rotScale /= (proj.nView() * proj.rotInc() / (2 * PI)); // scale by number of 2PI rotations - else - sys_error (ERR_SEVERE, "Invalid geometry type %d [Backproject::Backproject]", proj.geometry()); + if (proj.geometry() == Scanner::GEOMETRY_PARALLEL) + rotScale /= (proj.nView() * proj.rotInc() / PI); // scale by number of PI rotations + else if (proj.geometry() == Scanner::GEOMETRY_EQUIANGULAR || proj.geometry() == Scanner::GEOMETRY_EQUILINEAR) + rotScale /= (proj.nView() * proj.rotInc() / (2 * PI)); // scale by number of 2PI rotations + else + sys_error (ERR_SEVERE, "Invalid geometry type %d [Backproject::Backproject]", proj.geometry()); v = im.getArray(); nx = im.nx(); @@ -305,7 +305,7 @@ void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, doubl } void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double L, int iDetPos) -{ +{ #if 1 std::ostringstream os; os << "ix=" << ix << ", iy=" << iy << ", theta=" << theta << ", L=" << L << ", detinc=" << detInc << "\n"; @@ -314,7 +314,7 @@ void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, doubl os << "yMin=" << yMin << ", yMax=" << yMax << ", yInc=" << yInc << "\n"; os << "iDetPos index outside bounds: " << iDetPos << " [backprojector]";; - sys_error (ERR_WARNING, os.str().c_str()); + sys_error (ERR_WARNING, os.str().c_str()); #endif } @@ -639,8 +639,8 @@ BackprojectIntDiff3::BackprojectView (const double* const filteredProj, const do *pImCol++ += filteredProj[iDetPos] + (detRemainder * deltaFilteredProj[iDetPos]); } // end for iy } //end linear - } // end for ix - + } // end for ix + delete deltaFilteredProj; } diff --git a/libctsim/filter.cpp b/libctsim/filter.cpp index 5a4b0ef..60f97c8 100644 --- a/libctsim/filter.cpp +++ b/libctsim/filter.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: filter.cpp,v 1.32 2000/12/04 19:50:57 kevin Exp $ +** $Id: filter.cpp,v 1.33 2001/01/02 16:02:13 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 @@ -369,7 +369,7 @@ SignalFilter::spatialResponseCalc (int filterID, double bw, double x, double par q[i] = frequencyResponse (filterID, bw, z, param) * cos (TWOPI * z * x); double y = 2 * integrateSimpson (zmin, zmax, q, n); - delete q; + delete q; return (y); } diff --git a/libctsim/fourier.cpp b/libctsim/fourier.cpp index 09033ac..08940d4 100644 --- a/libctsim/fourier.cpp +++ b/libctsim/fourier.cpp @@ -1,279 +1,279 @@ -/***************************************************************************** -** FILE IDENTIFICATION -** -** Name: fourier.cpp -** Purpose: Fourier transform functions -** Programmer: Kevin Rosenberg -** Date Started: Dec 2000 -** -** This is part of the CTSim program -** Copyright (C) 1983-2001 Kevin Rosenberg -** -** $Id: fourier.cpp,v 1.1 2001/01/02 06:33:04 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 -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -#include "ct.h" - - - -void -Fourier::shuffleFourierToNaturalOrder (ImageFile& im) -{ - ImageFileArray vReal = im.getArray(); - ImageFileArray vImag = im.getImaginaryArray(); - unsigned int ix, iy; - unsigned int nx = im.nx(); - unsigned int ny = im.ny(); - - // shuffle each column - for (ix = 0; ix < nx; ix++) { - Fourier::shuffleFourierToNaturalOrder (vReal[ix], ny); - if (im.isComplex()) - Fourier::shuffleFourierToNaturalOrder (vImag[ix], ny); - } - - // shuffle each row - float* pRow = new float [nx]; - for (iy = 0; iy < ny; iy++) { - for (ix = 0; ix < nx; ix++) - pRow[ix] = vReal[ix][iy]; - Fourier::shuffleFourierToNaturalOrder (pRow, nx); - for (ix = 0; ix < nx; ix++) - vReal[ix][iy] = pRow[ix]; - if (im.isComplex()) { - for (ix = 0; ix < nx; ix++) - pRow[ix] = vImag[ix][iy]; - Fourier::shuffleFourierToNaturalOrder (pRow, nx);; - for (ix = 0; ix < nx; ix++) - vImag[ix][iy] = pRow[ix]; - } - } - delete pRow; -} - -void -Fourier::shuffleNaturalToFourierOrder (ImageFile& im) -{ - ImageFileArray vReal = im.getArray(); - ImageFileArray vImag = im.getImaginaryArray(); - unsigned int ix, iy; - unsigned int nx = im.nx(); - unsigned int ny = im.ny(); - - // shuffle each x column - for (ix = 0; ix < nx; ix++) { - Fourier::shuffleNaturalToFourierOrder (vReal[ix], ny); - if (im.isComplex()) - Fourier::shuffleNaturalToFourierOrder (vImag[ix], ny); - } - - // shuffle each y row - float* pRow = new float [nx]; - for (iy = 0; iy < ny; iy++) { - for (ix = 0; ix < nx; ix++) - pRow[ix] = vReal[ix][iy]; - Fourier::shuffleNaturalToFourierOrder (pRow, nx); - for (ix = 0; ix < nx; ix++) - vReal[ix][iy] = pRow[ix]; - if (im.isComplex()) { - for (ix = 0; ix < nx; ix++) - pRow[ix] = vImag[ix][iy]; - Fourier::shuffleNaturalToFourierOrder (pRow, nx); - for (ix = 0; ix < nx; ix++) - vImag[ix][iy] = pRow[ix]; - } - } - delete [] pRow; -} - - -// Odd Number of Points -// Natural Frequency Order: -(n-1)/2...-1,0,1...(n-1)/2 -// Fourier Frequency Order: 0, 1..(n-1)/2,-(n-1)/2...-1 -// Even Number of Points -// Natural Frequency Order: -n/2...-1,0,1...((n/2)-1) -// Fourier Frequency Order: 0,1...((n/2)-1),-n/2...-1 - -void -Fourier::shuffleNaturalToFourierOrder (double* pdVector, const int n) -{ - double* pdTemp = new double [n]; - int i; - if (n % 2) { // Odd - int iHalfN = (n - 1) / 2; - - pdTemp[0] = pdVector[iHalfN]; - for (i = 0; i < iHalfN; i++) - pdTemp[i + 1] = pdVector[i + 1 + iHalfN]; - for (i = 0; i < iHalfN; i++) - pdTemp[i + iHalfN + 1] = pdVector[i]; - } else { // Even - int iHalfN = n / 2; - pdTemp[0] = pdVector[iHalfN]; - for (i = 0; i < iHalfN - 1; i++) - pdTemp[i + 1] = pdVector[i + iHalfN + 1]; - for (i = 0; i < iHalfN; i++) - pdTemp[i + iHalfN] = pdVector[i]; - } - - for (i = 0; i < n; i++) - pdVector[i] = pdTemp[i]; - delete pdTemp; -} - -void -Fourier::shuffleNaturalToFourierOrder (std::complex* pdVector, const int n) -{ - std::complex* pdTemp = new std::complex [n]; - int i; - if (n % 2) { // Odd - int iHalfN = (n - 1) / 2; - - pdTemp[0] = pdVector[iHalfN]; - for (i = 0; i < iHalfN; i++) - pdTemp[i + 1] = pdVector[i + 1 + iHalfN]; - for (i = 0; i < iHalfN; i++) - pdTemp[i + iHalfN + 1] = pdVector[i]; - } else { // Even - int iHalfN = n / 2; - pdTemp[0] = pdVector[iHalfN]; - for (i = 0; i < iHalfN - 1; i++) - pdTemp[i + 1] = pdVector[i + iHalfN + 1]; - for (i = 0; i < iHalfN; i++) - pdTemp[i + iHalfN] = pdVector[i]; - } - - for (i = 0; i < n; i++) - pdVector[i] = pdTemp[i]; - delete [] pdTemp; -} - - -void -Fourier::shuffleNaturalToFourierOrder (float* pdVector, const int n) -{ - float* pdTemp = new float [n]; - int i; - if (n % 2) { // Odd - int iHalfN = (n - 1) / 2; - - pdTemp[0] = pdVector[iHalfN]; - for (i = 0; i < iHalfN; i++) - pdTemp[i + 1] = pdVector[i + 1 + iHalfN]; - for (i = 0; i < iHalfN; i++) - pdTemp[i + iHalfN + 1] = pdVector[i]; - } else { // Even - int iHalfN = n / 2; - pdTemp[0] = pdVector[iHalfN]; - for (i = 0; i < iHalfN - 1; i++) - pdTemp[i + 1] = pdVector[i + iHalfN + 1]; - for (i = 0; i < iHalfN; i++) - pdTemp[i + iHalfN] = pdVector[i]; - } - - for (i = 0; i < n; i++) - pdVector[i] = pdTemp[i]; - delete pdTemp; -} - - - -void -Fourier::shuffleFourierToNaturalOrder (double* pdVector, const int n) -{ - double* pdTemp = new double [n]; - int i; - if (n % 2) { // Odd - int iHalfN = (n - 1) / 2; - - pdTemp[iHalfN] = pdVector[0]; - for (i = 0; i < iHalfN; i++) - pdTemp[i + 1 + iHalfN] = pdVector[i + 1]; - for (i = 0; i < iHalfN; i++) - pdTemp[i] = pdVector[i + iHalfN + 1]; - } else { // Even - int iHalfN = n / 2; - pdTemp[iHalfN] = pdVector[0]; - for (i = 0; i < iHalfN; i++) - pdTemp[i] = pdVector[i + iHalfN]; - for (i = 0; i < iHalfN - 1; i++) - pdTemp[i + iHalfN + 1] = pdVector[i+1]; - } - - for (i = 0; i < n; i++) - pdVector[i] = pdTemp[i]; - delete pdTemp; -} - - -void -Fourier::shuffleFourierToNaturalOrder (std::complex* pdVector, const int n) -{ - std::complex* pdTemp = new std::complex [n]; - int i; - if (n % 2) { // Odd - int iHalfN = (n - 1) / 2; - - pdTemp[iHalfN] = pdVector[0]; - for (i = 0; i < iHalfN; i++) - pdTemp[i + 1 + iHalfN] = pdVector[i + 1]; - for (i = 0; i < iHalfN; i++) - pdTemp[i] = pdVector[i + iHalfN + 1]; - } else { // Even - int iHalfN = n / 2; - pdTemp[iHalfN] = pdVector[0]; - for (i = 0; i < iHalfN; i++) - pdTemp[i] = pdVector[i + iHalfN]; - for (i = 0; i < iHalfN - 1; i++) - pdTemp[i + iHalfN + 1] = pdVector[i+1]; - } - - for (i = 0; i < n; i++) - pdVector[i] = pdTemp[i]; - delete [] pdTemp; -} - - - - -void -Fourier::shuffleFourierToNaturalOrder (float* pVector, const int n) -{ - float* pTemp = new float [n]; - int i; - if (n % 2) { // Odd - int iHalfN = (n - 1) / 2; - - pTemp[iHalfN] = pVector[0]; - for (i = 0; i < iHalfN; i++) - pTemp[i + 1 + iHalfN] = pVector[i + 1]; - for (i = 0; i < iHalfN; i++) - pTemp[i] = pVector[i + iHalfN + 1]; - } else { // Even - int iHalfN = n / 2; - pTemp[iHalfN] = pVector[0]; - for (i = 0; i < iHalfN; i++) - pTemp[i] = pVector[i + iHalfN]; - for (i = 0; i < iHalfN - 1; i++) - pTemp[i + iHalfN + 1] = pVector[i+1]; - } - - for (i = 0; i < n; i++) - pVector[i] = pTemp[i]; - delete [] pTemp; -} - - +/***************************************************************************** +** FILE IDENTIFICATION +** +** Name: fourier.cpp +** Purpose: Fourier transform functions +** Programmer: Kevin Rosenberg +** Date Started: Dec 2000 +** +** This is part of the CTSim program +** Copyright (C) 1983-2001 Kevin Rosenberg +** +** $Id: fourier.cpp,v 1.2 2001/01/02 16:02:13 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +#include "ct.h" + + + +void +Fourier::shuffleFourierToNaturalOrder (ImageFile& im) +{ + ImageFileArray vReal = im.getArray(); + ImageFileArray vImag = im.getImaginaryArray(); + unsigned int ix, iy; + unsigned int nx = im.nx(); + unsigned int ny = im.ny(); + + // shuffle each column + for (ix = 0; ix < nx; ix++) { + Fourier::shuffleFourierToNaturalOrder (vReal[ix], ny); + if (im.isComplex()) + Fourier::shuffleFourierToNaturalOrder (vImag[ix], ny); + } + + // shuffle each row + float* pRow = new float [nx]; + for (iy = 0; iy < ny; iy++) { + for (ix = 0; ix < nx; ix++) + pRow[ix] = vReal[ix][iy]; + Fourier::shuffleFourierToNaturalOrder (pRow, nx); + for (ix = 0; ix < nx; ix++) + vReal[ix][iy] = pRow[ix]; + if (im.isComplex()) { + for (ix = 0; ix < nx; ix++) + pRow[ix] = vImag[ix][iy]; + Fourier::shuffleFourierToNaturalOrder (pRow, nx);; + for (ix = 0; ix < nx; ix++) + vImag[ix][iy] = pRow[ix]; + } + } + delete pRow; +} + +void +Fourier::shuffleNaturalToFourierOrder (ImageFile& im) +{ + ImageFileArray vReal = im.getArray(); + ImageFileArray vImag = im.getImaginaryArray(); + unsigned int ix, iy; + unsigned int nx = im.nx(); + unsigned int ny = im.ny(); + + // shuffle each x column + for (ix = 0; ix < nx; ix++) { + Fourier::shuffleNaturalToFourierOrder (vReal[ix], ny); + if (im.isComplex()) + Fourier::shuffleNaturalToFourierOrder (vImag[ix], ny); + } + + // shuffle each y row + float* pRow = new float [nx]; + for (iy = 0; iy < ny; iy++) { + for (ix = 0; ix < nx; ix++) + pRow[ix] = vReal[ix][iy]; + Fourier::shuffleNaturalToFourierOrder (pRow, nx); + for (ix = 0; ix < nx; ix++) + vReal[ix][iy] = pRow[ix]; + if (im.isComplex()) { + for (ix = 0; ix < nx; ix++) + pRow[ix] = vImag[ix][iy]; + Fourier::shuffleNaturalToFourierOrder (pRow, nx); + for (ix = 0; ix < nx; ix++) + vImag[ix][iy] = pRow[ix]; + } + } + delete [] pRow; +} + + +// Odd Number of Points +// Natural Frequency Order: -(n-1)/2...-1,0,1...(n-1)/2 +// Fourier Frequency Order: 0, 1..(n-1)/2,-(n-1)/2...-1 +// Even Number of Points +// Natural Frequency Order: -n/2...-1,0,1...((n/2)-1) +// Fourier Frequency Order: 0,1...((n/2)-1),-n/2...-1 + +void +Fourier::shuffleNaturalToFourierOrder (double* pdVector, const int n) +{ + double* pdTemp = new double [n]; + int i; + if (n % 2) { // Odd + int iHalfN = (n - 1) / 2; + + pdTemp[0] = pdVector[iHalfN]; + for (i = 0; i < iHalfN; i++) + pdTemp[i + 1] = pdVector[i + 1 + iHalfN]; + for (i = 0; i < iHalfN; i++) + pdTemp[i + iHalfN + 1] = pdVector[i]; + } else { // Even + int iHalfN = n / 2; + pdTemp[0] = pdVector[iHalfN]; + for (i = 0; i < iHalfN - 1; i++) + pdTemp[i + 1] = pdVector[i + iHalfN + 1]; + for (i = 0; i < iHalfN; i++) + pdTemp[i + iHalfN] = pdVector[i]; + } + + for (i = 0; i < n; i++) + pdVector[i] = pdTemp[i]; + delete pdTemp; +} + +void +Fourier::shuffleNaturalToFourierOrder (std::complex* pdVector, const int n) +{ + std::complex* pdTemp = new std::complex [n]; + int i; + if (n % 2) { // Odd + int iHalfN = (n - 1) / 2; + + pdTemp[0] = pdVector[iHalfN]; + for (i = 0; i < iHalfN; i++) + pdTemp[i + 1] = pdVector[i + 1 + iHalfN]; + for (i = 0; i < iHalfN; i++) + pdTemp[i + iHalfN + 1] = pdVector[i]; + } else { // Even + int iHalfN = n / 2; + pdTemp[0] = pdVector[iHalfN]; + for (i = 0; i < iHalfN - 1; i++) + pdTemp[i + 1] = pdVector[i + iHalfN + 1]; + for (i = 0; i < iHalfN; i++) + pdTemp[i + iHalfN] = pdVector[i]; + } + + for (i = 0; i < n; i++) + pdVector[i] = pdTemp[i]; + delete [] pdTemp; +} + + +void +Fourier::shuffleNaturalToFourierOrder (float* pdVector, const int n) +{ + float* pdTemp = new float [n]; + int i; + if (n % 2) { // Odd + int iHalfN = (n - 1) / 2; + + pdTemp[0] = pdVector[iHalfN]; + for (i = 0; i < iHalfN; i++) + pdTemp[i + 1] = pdVector[i + 1 + iHalfN]; + for (i = 0; i < iHalfN; i++) + pdTemp[i + iHalfN + 1] = pdVector[i]; + } else { // Even + int iHalfN = n / 2; + pdTemp[0] = pdVector[iHalfN]; + for (i = 0; i < iHalfN - 1; i++) + pdTemp[i + 1] = pdVector[i + iHalfN + 1]; + for (i = 0; i < iHalfN; i++) + pdTemp[i + iHalfN] = pdVector[i]; + } + + for (i = 0; i < n; i++) + pdVector[i] = pdTemp[i]; + delete pdTemp; +} + + + +void +Fourier::shuffleFourierToNaturalOrder (double* pdVector, const int n) +{ + double* pdTemp = new double [n]; + int i; + if (n % 2) { // Odd + int iHalfN = (n - 1) / 2; + + pdTemp[iHalfN] = pdVector[0]; + for (i = 0; i < iHalfN; i++) + pdTemp[i + 1 + iHalfN] = pdVector[i + 1]; + for (i = 0; i < iHalfN; i++) + pdTemp[i] = pdVector[i + iHalfN + 1]; + } else { // Even + int iHalfN = n / 2; + pdTemp[iHalfN] = pdVector[0]; + for (i = 0; i < iHalfN; i++) + pdTemp[i] = pdVector[i + iHalfN]; + for (i = 0; i < iHalfN - 1; i++) + pdTemp[i + iHalfN + 1] = pdVector[i+1]; + } + + for (i = 0; i < n; i++) + pdVector[i] = pdTemp[i]; + delete pdTemp; +} + + +void +Fourier::shuffleFourierToNaturalOrder (std::complex* pdVector, const int n) +{ + std::complex* pdTemp = new std::complex [n]; + int i; + if (n % 2) { // Odd + int iHalfN = (n - 1) / 2; + + pdTemp[iHalfN] = pdVector[0]; + for (i = 0; i < iHalfN; i++) + pdTemp[i + 1 + iHalfN] = pdVector[i + 1]; + for (i = 0; i < iHalfN; i++) + pdTemp[i] = pdVector[i + iHalfN + 1]; + } else { // Even + int iHalfN = n / 2; + pdTemp[iHalfN] = pdVector[0]; + for (i = 0; i < iHalfN; i++) + pdTemp[i] = pdVector[i + iHalfN]; + for (i = 0; i < iHalfN - 1; i++) + pdTemp[i + iHalfN + 1] = pdVector[i+1]; + } + + for (i = 0; i < n; i++) + pdVector[i] = pdTemp[i]; + delete [] pdTemp; +} + + + + +void +Fourier::shuffleFourierToNaturalOrder (float* pVector, const int n) +{ + float* pTemp = new float [n]; + int i; + if (n % 2) { // Odd + int iHalfN = (n - 1) / 2; + + pTemp[iHalfN] = pVector[0]; + for (i = 0; i < iHalfN; i++) + pTemp[i + 1 + iHalfN] = pVector[i + 1]; + for (i = 0; i < iHalfN; i++) + pTemp[i] = pVector[i + iHalfN + 1]; + } else { // Even + int iHalfN = n / 2; + pTemp[iHalfN] = pVector[0]; + for (i = 0; i < iHalfN; i++) + pTemp[i] = pVector[i + iHalfN]; + for (i = 0; i < iHalfN - 1; i++) + pTemp[i + iHalfN + 1] = pVector[i+1]; + } + + for (i = 0; i < n; i++) + pVector[i] = pTemp[i]; + delete [] pTemp; +} + + diff --git a/libctsim/imagefile.cpp b/libctsim/imagefile.cpp index cc7e234..df0e51e 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.32 2001/01/02 10:23:46 kevin Exp $ +** $Id: imagefile.cpp,v 1.33 2001/01/02 16:02:13 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 @@ -27,84 +27,84 @@ #include "ct.h" -const int ImageFile::FORMAT_INVALID = -1; -const int ImageFile::FORMAT_PGM = 0; -const int ImageFile::FORMAT_PGMASCII = 1; -#ifdef HAVE_PNG -const int ImageFile::FORMAT_PNG = 2; -const int ImageFile::FORMAT_PNG16 = 3; -#endif - -const char* ImageFile::s_aszFormatName[] = -{ - {"pgm"}, - {"pgmascii"}, -#ifdef HAVE_PNG - {"png"}, - {"png16"}, -#endif -}; - -const char* ImageFile::s_aszFormatTitle[] = -{ - {"PGM"}, - {"PGM ASCII"}, - {"PNG"}, - {"PNG 16-bit"}, -}; - -const int ImageFile::s_iFormatCount = sizeof(s_aszFormatName) / sizeof(const char*); - - +const int ImageFile::FORMAT_INVALID = -1; +const int ImageFile::FORMAT_PGM = 0; +const int ImageFile::FORMAT_PGMASCII = 1; +#ifdef HAVE_PNG +const int ImageFile::FORMAT_PNG = 2; +const int ImageFile::FORMAT_PNG16 = 3; +#endif + +const char* ImageFile::s_aszFormatName[] = +{ + {"pgm"}, + {"pgmascii"}, +#ifdef HAVE_PNG + {"png"}, + {"png16"}, +#endif +}; + +const char* ImageFile::s_aszFormatTitle[] = +{ + {"PGM"}, + {"PGM ASCII"}, + {"PNG"}, + {"PNG 16-bit"}, +}; + +const int ImageFile::s_iFormatCount = sizeof(s_aszFormatName) / sizeof(const char*); -F32Image::F32Image (int nx, int ny, int dataType) -: Array2dFile (nx, ny, sizeof(kfloat32), Array2dFile::PIXEL_FLOAT32, dataType) -{ -} - -F32Image::F32Image (void) -: Array2dFile() -{ - setPixelFormat (Array2dFile::PIXEL_FLOAT32); - setPixelSize (sizeof(kfloat32)); - setDataType (Array2dFile::DATA_TYPE_REAL); -} - -F64Image::F64Image (int nx, int ny, int dataType) -: Array2dFile (nx, ny, sizeof(kfloat64), Array2dFile::PIXEL_FLOAT64, dataType) -{ -} - -F64Image::F64Image (void) -: Array2dFile () -{ - setPixelFormat (PIXEL_FLOAT64); - setPixelSize (sizeof(kfloat64)); - setDataType (Array2dFile::DATA_TYPE_REAL); -} + + +F32Image::F32Image (int nx, int ny, int dataType) +: Array2dFile (nx, ny, sizeof(kfloat32), Array2dFile::PIXEL_FLOAT32, dataType) +{ +} + +F32Image::F32Image (void) +: Array2dFile() +{ + setPixelFormat (Array2dFile::PIXEL_FLOAT32); + setPixelSize (sizeof(kfloat32)); + setDataType (Array2dFile::DATA_TYPE_REAL); +} + +F64Image::F64Image (int nx, int ny, int dataType) +: Array2dFile (nx, ny, sizeof(kfloat64), Array2dFile::PIXEL_FLOAT64, dataType) +{ +} + +F64Image::F64Image (void) +: Array2dFile () +{ + setPixelFormat (PIXEL_FLOAT64); + setPixelSize (sizeof(kfloat64)); + setDataType (Array2dFile::DATA_TYPE_REAL); +} void ImageFile::filterResponse (const char* const domainName, double bw, const char* const filterName, double filt_param, double dInputScale, double dOutputScale) -{ - ImageFileArray v = getArray(); - SignalFilter filter (filterName, domainName, bw, filt_param); - - int iXCenter, iYCenter; - if (isEven (m_nx)) - iXCenter = m_nx / 2; - else - iXCenter = (m_nx - 1) / 2; - if (isEven (m_ny)) - iYCenter = m_ny / 2; - else - iYCenter = (m_ny - 1) / 2; - - for (unsigned int ix = 0; ix < m_nx; ix++) - for (unsigned int iy = 0; iy < m_ny; iy++) { - long lD2 = ((ix - iXCenter) * (ix - iXCenter)) + ((iy - iYCenter) * (iy - iYCenter)); - double r = ::sqrt (static_cast(lD2)) * dInputScale; - v[ix][iy] = filter.response (r) * dOutputScale; - } +{ + ImageFileArray v = getArray(); + SignalFilter filter (filterName, domainName, bw, filt_param); + + int iXCenter, iYCenter; + if (isEven (m_nx)) + iXCenter = m_nx / 2; + else + iXCenter = (m_nx - 1) / 2; + if (isEven (m_ny)) + iYCenter = m_ny / 2; + else + iYCenter = (m_ny - 1) / 2; + + for (unsigned int ix = 0; ix < m_nx; ix++) + for (unsigned int iy = 0; iy < m_ny; iy++) { + long lD2 = ((ix - iXCenter) * (ix - iXCenter)) + ((iy - iYCenter) * (iy - iYCenter)); + double r = ::sqrt (static_cast(lD2)) * dInputScale; + v[ix][iy] = filter.response (r) * dOutputScale; + } } int @@ -250,58 +250,58 @@ ImageFile::printStatistics (std::ostream& os) const { double min, max, mean, mode, median, stddev; - statistics (min, max, mean, mode, median, stddev); - if (isComplex()) - os << "Real Component Statistics" << std::endl; + statistics (min, max, mean, mode, median, stddev); + if (isComplex()) + 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; - - if (isComplex()) { - statistics (getImaginaryArray(), min, max, mean, mode, median, stddev); + os << "stddev: " << stddev << std::endl; + + if (isComplex()) { + 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; - } + 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 -{ - ImageFileArrayConst v = getArray(); - statistics (v, min, max, mean, mode, median, stddev); +{ + 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; - vecImage.resize (nx * ny); - for (int ix = 0; ix < nx; ix++) { - for (int iy = 0; iy < ny; iy++) - vecImage[iVec++] = v[ix][iy]; - } - - vectorNumericStatistics (vecImage, nx * ny, 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; + vecImage.resize (nx * ny); + for (int ix = 0; ix < nx; ix++) { + for (int iy = 0; iy < ny; iy++) + vecImage[iVec++] = v[ix][iy]; + } + + vectorNumericStatistics (vecImage, nx * ny, min, max, mean, mode, median, stddev); +} + void ImageFile::getMinMax (double& min, double& max) const { @@ -323,796 +323,796 @@ 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 (unsigned int ix = 0; ix < m_nx; ix++) { - ImageFileColumn vCol = vImag[ix]; - for (unsigned 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 (unsigned int ix = 0; ix < m_nx; ix++) { - ImageFileColumn vRealCol = vReal[ix]; - ImageFileColumn vImagCol = vImag[ix]; - for (unsigned int iy = 0; iy < m_ny; iy++) { - CTSimComplex c (*vRealCol, *vImagCol); - *vRealCol++ = std::abs (c); - vImagCol++; - } - } - - return reallocComplexToReal(); -} - -bool -ImageFile::subtractImages (const ImageFile& rRHS, ImageFile& result) const -{ - if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { - sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); - return false; - } - - if (isComplex() || rRHS.isComplex() && ! result.isComplex()) - result.convertRealToComplex(); - - ImageFileArrayConst vLHS = getArray(); - ImageFileArrayConst vLHSImag = getImaginaryArray(); - ImageFileArrayConst vRHS = rRHS.getArray(); - ImageFileArrayConst vRHSImag = rRHS.getImaginaryArray(); - ImageFileArray vResult = result.getArray(); - ImageFileArray vResultImag = result.getImaginaryArray(); - - for (unsigned int ix = 0; ix < m_nx; ix++) { - for (unsigned int iy = 0; iy < m_ny; iy++) { - vResult[ix][iy] = vLHS[ix][iy] - vRHS[ix][iy]; - if (result.isComplex()) { - vResultImag[ix][iy] = 0; - if (isComplex()) - vResultImag[ix][iy] += vLHSImag[ix][iy]; - if (rRHS.isComplex()) - vResultImag[ix][iy] -= vRHSImag[ix][iy]; - } - } - } - - return true; -} -bool -ImageFile::addImages (const ImageFile& rRHS, ImageFile& result) const -{ - if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { - sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); - return false; - } - - if (isComplex() || rRHS.isComplex() && ! result.isComplex()) - result.convertRealToComplex(); - - ImageFileArrayConst vLHS = getArray(); - ImageFileArrayConst vLHSImag = getImaginaryArray(); - ImageFileArrayConst vRHS = rRHS.getArray(); - ImageFileArrayConst vRHSImag = rRHS.getImaginaryArray(); - ImageFileArray vResult = result.getArray(); - ImageFileArray vResultImag = result.getImaginaryArray(); - - for (unsigned int ix = 0; ix < m_nx; ix++) { - for (unsigned int iy = 0; iy < m_ny; iy++) { - vResult[ix][iy] = vLHS[ix][iy] + vRHS[ix][iy]; - if (result.isComplex()) { - vResultImag[ix][iy] = 0; - if (isComplex()) - vResultImag[ix][iy] += vLHSImag[ix][iy]; - if (rRHS.isComplex()) - vResultImag[ix][iy] += vRHSImag[ix][iy]; - } - } - } - - return true; -} - -bool -ImageFile::multiplyImages (const ImageFile& rRHS, ImageFile& result) const -{ - if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { - sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); - return false; - } - - if (isComplex() || rRHS.isComplex() && ! result.isComplex()) - result.convertRealToComplex(); - - ImageFileArrayConst vLHS = getArray(); - ImageFileArrayConst vLHSImag = getImaginaryArray(); - ImageFileArrayConst vRHS = rRHS.getArray(); - ImageFileArrayConst vRHSImag = rRHS.getImaginaryArray(); - ImageFileArray vResult = result.getArray(); - ImageFileArray vResultImag = result.getImaginaryArray(); - - for (unsigned int ix = 0; ix < m_nx; ix++) { - for (unsigned int iy = 0; iy < m_ny; iy++) { - if (result.isComplex()) { - double dImag = 0; - if (isComplex()) - dImag = vLHSImag[ix][iy]; - std::complex cLHS (vLHS[ix][iy], dImag); - dImag = 0; - if (rRHS.isComplex()) - dImag = vRHSImag[ix][iy]; - std::complex cRHS (vRHS[ix][iy], dImag); - std::complex cResult = cLHS * cRHS; - vResult[ix][iy] = cResult.real(); - vResultImag[ix][iy] = cResult.imag(); - } else - vResult[ix][iy] = vLHS[ix][iy] * vRHS[ix][iy]; - } - } - - - return true; -} - -bool -ImageFile::divideImages (const ImageFile& rRHS, ImageFile& result) const -{ - if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { - sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); - return false; - } - - if (isComplex() || rRHS.isComplex() && ! result.isComplex()) - result.convertRealToComplex(); - - ImageFileArrayConst vLHS = getArray(); - ImageFileArrayConst vLHSImag = getImaginaryArray(); - ImageFileArrayConst vRHS = rRHS.getArray(); - ImageFileArrayConst vRHSImag = rRHS.getImaginaryArray(); - ImageFileArray vResult = result.getArray(); - ImageFileArray vResultImag = result.getImaginaryArray(); - - for (unsigned int ix = 0; ix < m_nx; ix++) { - for (unsigned int iy = 0; iy < m_ny; iy++) { - if (result.isComplex()) { - double dImag = 0; - if (isComplex()) - dImag = vLHSImag[ix][iy]; - std::complex cLHS (vLHS[ix][iy], dImag); - dImag = 0; - if (rRHS.isComplex()) - dImag = vRHSImag[ix][iy]; - std::complex cRHS (vRHS[ix][iy], dImag); - std::complex cResult = cLHS / cRHS; - vResult[ix][iy] = cResult.real(); - vResultImag[ix][iy] = cResult.imag(); - } else { - if (vRHS != 0) - vResult[ix][iy] = vLHS[ix][iy] / vRHS[ix][iy]; - else - vResult[ix][iy] = 0; - } - } - } - - return true; -} - - -bool -ImageFile::invertPixelValues (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 (isComplex() && ! result.isComplex()) - result.convertRealToComplex(); - - ImageFileArrayConst vLHS = getArray(); - ImageFileArray vResult = result.getArray(); - - for (unsigned int ix = 0; ix < m_nx; ix++) { - ImageFileColumnConst in = vLHS[ix]; - ImageFileColumn out = vResult[ix]; - for (unsigned int iy = 0; iy < m_ny; iy++) - *out++ = - *in++; - } - - return true; -} - -bool -ImageFile::sqrt (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 (isComplex() && ! result.isComplex()) - result.convertRealToComplex(); - - bool bComplexOutput = result.isComplex(); - ImageFileArrayConst vLHS = getArray(); - if (! bComplexOutput) // check if should convert to complex output - for (unsigned int ix = 0; ix < m_nx; ix++) - for (unsigned int iy = 0; iy < m_ny; iy++) - if (! bComplexOutput && vLHS[ix][iy] < 0) { - result.convertRealToComplex(); - bComplexOutput = true; - break; - } - - ImageFileArrayConst vLHSImag = getImaginaryArray(); - ImageFileArray vResult = result.getArray(); - ImageFileArray vResultImag = result.getImaginaryArray(); - - for (unsigned int ix = 0; ix < m_nx; ix++) { - for (unsigned int iy = 0; iy < m_ny; iy++) { - if (result.isComplex()) { - double dImag = 0; - if (isComplex()) - dImag = vLHSImag[ix][iy]; - std::complex cLHS (vLHS[ix][iy], dImag); - std::complex cResult = std::sqrt(cLHS); - vResult[ix][iy] = cResult.real(); - vResultImag[ix][iy] = cResult.imag(); - } else - vResult[ix][iy] = ::sqrt (vLHS[ix][iy]); - } - } - - - return true; -} - -bool -ImageFile::log (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 (isComplex() && ! result.isComplex()) - result.convertRealToComplex(); - - ImageFileArrayConst vLHS = getArray(); - ImageFileArrayConst vLHSImag = getImaginaryArray(); - ImageFileArray vResult = result.getArray(); - ImageFileArray vResultImag = result.getImaginaryArray(); - - for (unsigned int ix = 0; ix < m_nx; ix++) { - for (unsigned int iy = 0; iy < m_ny; iy++) { - if (result.isComplex()) { - double dImag = 0; - if (isComplex()) - dImag = vLHSImag[ix][iy]; - std::complex cLHS (vLHS[ix][iy], dImag); - std::complex cResult = std::log (cLHS); - vResult[ix][iy] = cResult.real(); - vResultImag[ix][iy] = cResult.imag(); - } else - vResult[ix][iy] = ::log (vLHS[ix][iy]); - } - } - - - return true; -} - -bool -ImageFile::exp (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 (isComplex() && ! result.isComplex()) - result.convertRealToComplex(); - - ImageFileArrayConst vLHS = getArray(); - ImageFileArrayConst vLHSImag = getImaginaryArray(); - ImageFileArray vResult = result.getArray(); - ImageFileArray vResultImag = result.getImaginaryArray(); - - for (unsigned int ix = 0; ix < m_nx; ix++) { - for (unsigned int iy = 0; iy < m_ny; iy++) { - if (result.isComplex()) { - double dImag = 0; - if (isComplex()) - dImag = vLHSImag[ix][iy]; - std::complex cLHS (vLHS[ix][iy], dImag); - std::complex cResult = std::exp (cLHS); - vResult[ix][iy] = cResult.real(); - vResultImag[ix][iy] = cResult.imag(); - } else - vResult[ix][iy] = ::exp (vLHS[ix][iy]); - } - } - - - return true; -} - -bool -ImageFile::scaleImage (ImageFile& result) const -{ - unsigned int nx = m_nx; - unsigned int ny = m_ny; - unsigned int newNX = result.nx(); - unsigned int newNY = result.ny(); - - double dXScale = static_cast(newNX) / static_cast(nx); - double dYScale = static_cast(newNY) / static_cast(ny); - - if (isComplex() && ! result.isComplex()) - result.convertRealToComplex(); - - ImageFileArrayConst vReal = getArray(); - ImageFileArrayConst vImag = getImaginaryArray(); - ImageFileArray vResult = result.getArray(); - ImageFileArray vResultImag = result.getImaginaryArray(); - - for (unsigned int ix = 0; ix < newNX; ix++) { - for (unsigned int iy = 0; iy < newNY; iy++) { - double dXPos = ix / dXScale; - double dYPos = iy / dYScale; - unsigned int scaleNX = static_cast (dXPos); - unsigned int scaleNY = static_cast (dYPos); - double dXFrac = dXPos - scaleNX; - double dYFrac = dYPos - scaleNY; - if (scaleNX >= nx - 1 || scaleNY >= ny - 1) { - vResult[ix][iy] = vReal[scaleNX][scaleNY]; - if (result.isComplex()) { - if (isComplex()) - vResultImag[ix][iy] = vImag[scaleNX][scaleNY]; - else - vResultImag[ix][iy] = 0; - } - } else { - vResult[ix][iy] = vReal[scaleNX][scaleNY] + - dXFrac * (vReal[scaleNX+1][scaleNY] - vReal[scaleNX][scaleNY]) + - dYFrac * (vReal[scaleNX][scaleNY+1] - vReal[scaleNX][scaleNY]); - if (result.isComplex()) { - if (isComplex()) - vResultImag[ix][iy] = vImag[scaleNX][scaleNY] + - dXFrac * (vImag[scaleNX+1][scaleNY] - vImag[scaleNX][scaleNY]) + - dYFrac * (vImag[scaleNX][scaleNY+1] - vImag[scaleNX][scaleNY]); - else - vResultImag[ix][iy] = 0; - } - } - } - } - - return true; -} - -#ifdef HAVE_FFTW -bool -ImageFile::fft (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.convertRealToComplex ()) - return false; - } - - fftw_complex* in = new fftw_complex [m_nx * m_ny]; - - ImageFileArrayConst vReal = getArray(); - ImageFileArrayConst vImag = getImaginaryArray(); - - unsigned int ix, iy; - unsigned int iArray = 0; - for (ix = 0; ix < m_nx; ix++) - for (iy = 0; iy < m_ny; iy++) { - in[iArray].re = vReal[ix][iy]; - if (isComplex()) - in[iArray].im = vImag[ix][iy]; - else - in[iArray].im = 0; - iArray++; - } - - fftwnd_plan plan = fftw2d_create_plan (m_nx, m_ny, FFTW_FORWARD, FFTW_IN_PLACE); - - fftwnd_one (plan, in, NULL); - - ImageFileArray vRealResult = result.getArray(); - ImageFileArray vImagResult = result.getImaginaryArray(); - iArray = 0; - unsigned int iScale = m_nx * m_ny; - for (ix = 0; ix < m_nx; ix++) - for (iy = 0; iy < m_ny; iy++) { - vRealResult[ix][iy] = in[iArray].re / iScale; - vImagResult[ix][iy] = in[iArray].im / iScale; - iArray++; - } - - fftwnd_destroy_plan (plan); - delete in; - - - Fourier::shuffleFourierToNaturalOrder (result); - - return true; -} - - -bool -ImageFile::ifft (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.convertRealToComplex ()) - return false; - } - - ImageFileArrayConst vReal = getArray(); - ImageFileArrayConst vImag = getImaginaryArray(); - ImageFileArray vRealResult = result.getArray(); - ImageFileArray vImagResult = result.getImaginaryArray(); - unsigned int ix, iy; - for (ix = 0; ix < m_nx; ix++) - for (iy = 0; iy < m_ny; iy++) { - vRealResult[ix][iy] = vReal[ix][iy]; - if (isComplex()) - vImagResult[ix][iy] = vImag[ix][iy]; - else - vImagResult[ix][iy] = 0; - } - - Fourier::shuffleNaturalToFourierOrder (result); - - fftw_complex* in = new fftw_complex [m_nx * m_ny]; - - unsigned int iArray = 0; - for (ix = 0; ix < m_nx; ix++) - for (iy = 0; iy < m_ny; iy++) { - in[iArray].re = vRealResult[ix][iy]; - in[iArray].im = vImagResult[ix][iy]; - iArray++; - } - - fftwnd_plan plan = fftw2d_create_plan (m_nx, m_ny, FFTW_BACKWARD, FFTW_IN_PLACE); - - fftwnd_one (plan, in, NULL); - - iArray = 0; - for (ix = 0; ix < m_nx; ix++) - for (iy = 0; iy < m_ny; iy++) { - vRealResult[ix][iy] = in[iArray].re; - vImagResult[ix][iy] = in[iArray].im; - iArray++; - } - - fftwnd_destroy_plan (plan); - - delete in; - - return true; -} -#endif // HAVE_FFTW - - - -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.isComplex()) - if (! result.convertRealToComplex ()) - return false; - - ImageFileArrayConst vLHS = getArray(); - ImageFileArrayConst vLHSImag = getImaginaryArray(); - ImageFileArray vRealResult = result.getArray(); - ImageFileArray vImagResult = result.getImaginaryArray(); - - unsigned int ix, iy; - - // alloc output matrix - CTSimComplex** complexOut = new CTSimComplex* [m_nx]; - for (ix = 0; ix < m_nx; ix++) - complexOut[ix] = new CTSimComplex [m_ny]; - - // fourier each x column - CTSimComplex* pY = new CTSimComplex [m_ny]; - for (ix = 0; ix < m_nx; ix++) { - for (iy = 0; iy < m_ny; iy++) { - double dImag = 0; - if (isComplex()) - dImag = vLHSImag[ix][iy]; - pY[iy] = std::complex(vLHS[ix][iy], dImag); - } - ProcessSignal::finiteFourierTransform (pY, complexOut[ix], m_ny, ProcessSignal::FORWARD); - } - delete [] pY; - - // fourier each y row - CTSimComplex* pX = new CTSimComplex [m_nx]; - CTSimComplex* complexOutRow = new CTSimComplex [m_nx]; - for (iy = 0; iy < m_ny; iy++) { - for (ix = 0; ix < m_nx; ix++) - pX[ix] = complexOut[ix][iy]; - ProcessSignal::finiteFourierTransform (pX, complexOutRow, m_nx, ProcessSignal::FORWARD); - for (ix = 0; ix < m_nx; ix++) - complexOut[ix][iy] = complexOutRow[ix]; - } - delete [] pX; - delete [] complexOutRow; - - for (ix = 0; ix < m_nx; ix++) - for (iy = 0; iy < m_ny; iy++) { - vRealResult[ix][iy] = complexOut[ix][iy].real(); - vImagResult[ix][iy] = complexOut[ix][iy].imag(); - } - - Fourier::shuffleFourierToNaturalOrder (result); - - // delete complexOut matrix - for (ix = 0; ix < m_nx; ix++) - delete [] complexOut[ix]; - delete [] complexOut; - - return true; -} - -bool -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; - } - - if (result.dataType() == Array2dFile::DATA_TYPE_REAL) { - if (! result.convertRealToComplex ()) - return false; - } - - ImageFileArrayConst vLHSReal = getArray(); - ImageFileArrayConst vLHSImag = getImaginaryArray(); - ImageFileArray vRealResult = result.getArray(); - ImageFileArray vImagResult = result.getImaginaryArray(); - - unsigned int ix, iy; - // alloc 2d complex output matrix - CTSimComplex** complexOut = new CTSimComplex* [m_nx]; - for (ix = 0; ix < m_nx; ix++) - complexOut[ix] = new CTSimComplex [m_ny]; - - // put input image into result - for (ix = 0; ix < m_nx; ix++) - for (iy = 0; iy < m_ny; iy++) { - vRealResult[ix][iy] = vLHSReal[ix][iy]; - if (isComplex()) - vImagResult[ix][iy] = vLHSImag[ix][iy]; - else - vImagResult[ix][iy] = 0; - } - - Fourier::shuffleNaturalToFourierOrder (result); - - // ifourier each x column - CTSimComplex* pCol = new CTSimComplex [m_ny]; - for (ix = 0; ix < m_nx; ix++) { - for (iy = 0; iy < m_ny; iy++) { - pCol[iy] = std::complex (vRealResult[ix][iy], vImagResult[ix][iy]); - } - ProcessSignal::finiteFourierTransform (pCol, complexOut[ix], m_ny, ProcessSignal::BACKWARD); - } - delete [] pCol; - - // ifourier each y row - CTSimComplex* complexInRow = new CTSimComplex [m_nx]; - CTSimComplex* complexOutRow = new CTSimComplex [m_nx]; - for (iy = 0; iy < m_ny; iy++) { - for (ix = 0; ix < m_nx; ix++) - complexInRow[ix] = complexOut[ix][iy]; - ProcessSignal::finiteFourierTransform (complexInRow, complexOutRow, m_nx, ProcessSignal::BACKWARD); - for (ix = 0; ix < m_nx; ix++) - complexOut[ix][iy] = complexOutRow[ix]; - } - delete [] complexInRow; - delete [] complexOutRow; - - for (ix = 0; ix < m_nx; ix++) - for (iy = 0; iy < m_ny; iy++) { - vRealResult[ix][iy] = complexOut[ix][iy].real(); - vImagResult[ix][iy] = complexOut[ix][iy].imag(); - } - - // delete complexOut matrix - for (ix = 0; ix < m_nx; ix++) - delete [] complexOut[ix]; - delete [] complexOut; - - return true; -} - - -bool -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; - } - - ImageFileArray vReal = getArray(); - ImageFileArray vImag = getImaginaryArray(); - ImageFileArray vRealResult = result.getArray(); - - for (unsigned int ix = 0; ix < m_nx; ix++) - for (unsigned int iy = 0; iy < m_ny; iy++) { - if (isComplex()) - vRealResult[ix][iy] = ::sqrt (vReal[ix][iy] * vReal[ix][iy] + vImag[ix][iy] * vImag[ix][iy]); - else - vRealResult[ix][iy] = vReal[ix][iy]; - } - - if (result.isComplex()) - result.convertComplexToReal(); - - 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; - } - - ImageFileArray vReal = getArray(); - ImageFileArray vImag = getImaginaryArray(); - ImageFileArray vRealResult = result.getArray(); - - for (unsigned int ix = 0; ix < m_nx; ix++) - for (unsigned int iy = 0; iy < m_ny; iy++) { - if (isComplex()) - vRealResult[ix][iy] = ::atan2 (vImag[ix][iy], vReal[ix][iy]); - else - vRealResult[ix][iy] = 0; - } - - if (result.isComplex()) - result.convertComplexToReal(); - - return true; -} - -bool -ImageFile::square (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 (isComplex() && ! result.isComplex()) - result.convertRealToComplex(); - - ImageFileArrayConst vLHS = getArray(); - ImageFileArrayConst vLHSImag = getImaginaryArray(); - ImageFileArray vResult = result.getArray(); - ImageFileArray vResultImag = result.getImaginaryArray(); - - for (unsigned int ix = 0; ix < m_nx; ix++) { - for (unsigned int iy = 0; iy < m_ny; iy++) { - if (result.isComplex()) { - double dImag = 0; - if (isComplex()) - dImag = vLHSImag[ix][iy]; - std::complex cLHS (vLHS[ix][iy], dImag); - std::complex cResult = cLHS * cLHS; - vResult[ix][iy] = cResult.real(); - vResultImag[ix][iy] = cResult.imag(); - } else - vResult[ix][iy] = vLHS[ix][iy] * vLHS[ix][iy]; - } - } - - - return true; -} - -int -ImageFile::convertFormatNameToID (const char* const formatName) -{ - int formatID = FORMAT_INVALID; - - for (int i = 0; i < s_iFormatCount; i++) - if (strcasecmp (formatName, s_aszFormatName[i]) == 0) { - formatID = i; - break; - } - - return (formatID); -} - -const char* -ImageFile::convertFormatIDToName (int formatID) -{ - static const char *formatName = ""; - - if (formatID >= 0 && formatID < s_iFormatCount) - return (s_aszFormatName[formatID]); - - return (formatName); -} - -const char* -ImageFile::convertFormatIDToTitle (const int formatID) -{ - static const char *formatTitle = ""; - - if (formatID >= 0 && formatID < s_iFormatCount) - return (s_aszFormatTitle[formatID]); - - return (formatTitle); -} - -bool -ImageFile::exportImage (const char* const pszFormat, const char* const pszFilename, int nxcell, int nycell, double densmin, double densmax) -{ - int iFormatID = convertFormatNameToID (pszFormat); - if (iFormatID == FORMAT_INVALID) { - sys_error (ERR_SEVERE, "Invalid format %s [ImageFile::exportImage]", pszFormat); - return false; - } - - if (iFormatID == FORMAT_PGM) - return writeImagePGM (pszFilename, nxcell, nycell, densmin, densmax); - else if (iFormatID == FORMAT_PGMASCII) - return writeImagePGMASCII (pszFilename, nxcell, nycell, densmin, densmax); - else if (iFormatID == FORMAT_PNG) - return writeImagePNG (pszFilename, 8, nxcell, nycell, densmin, densmax); - else if (iFormatID == FORMAT_PNG16) - return writeImagePNG (pszFilename, 16, nxcell, nycell, densmin, densmax); - - sys_error (ERR_SEVERE, "Invalid format %s [ImageFile::exportImage]", pszFormat); - return false; -} - +bool +ImageFile::convertRealToComplex () +{ + if (dataType() != Array2dFile::DATA_TYPE_REAL) + return false; + + if (! reallocRealToComplex()) + return false; + + ImageFileArray vImag = getImaginaryArray(); + for (unsigned int ix = 0; ix < m_nx; ix++) { + ImageFileColumn vCol = vImag[ix]; + for (unsigned 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 (unsigned int ix = 0; ix < m_nx; ix++) { + ImageFileColumn vRealCol = vReal[ix]; + ImageFileColumn vImagCol = vImag[ix]; + for (unsigned int iy = 0; iy < m_ny; iy++) { + CTSimComplex c (*vRealCol, *vImagCol); + *vRealCol++ = std::abs (c); + vImagCol++; + } + } + + return reallocComplexToReal(); +} + +bool +ImageFile::subtractImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + if (isComplex() || rRHS.isComplex() && ! result.isComplex()) + result.convertRealToComplex(); + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vLHSImag = getImaginaryArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArrayConst vRHSImag = rRHS.getImaginaryArray(); + ImageFileArray vResult = result.getArray(); + ImageFileArray vResultImag = result.getImaginaryArray(); + + for (unsigned int ix = 0; ix < m_nx; ix++) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + vResult[ix][iy] = vLHS[ix][iy] - vRHS[ix][iy]; + if (result.isComplex()) { + vResultImag[ix][iy] = 0; + if (isComplex()) + vResultImag[ix][iy] += vLHSImag[ix][iy]; + if (rRHS.isComplex()) + vResultImag[ix][iy] -= vRHSImag[ix][iy]; + } + } + } + + return true; +} + +bool +ImageFile::addImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + if (isComplex() || rRHS.isComplex() && ! result.isComplex()) + result.convertRealToComplex(); + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vLHSImag = getImaginaryArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArrayConst vRHSImag = rRHS.getImaginaryArray(); + ImageFileArray vResult = result.getArray(); + ImageFileArray vResultImag = result.getImaginaryArray(); + + for (unsigned int ix = 0; ix < m_nx; ix++) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + vResult[ix][iy] = vLHS[ix][iy] + vRHS[ix][iy]; + if (result.isComplex()) { + vResultImag[ix][iy] = 0; + if (isComplex()) + vResultImag[ix][iy] += vLHSImag[ix][iy]; + if (rRHS.isComplex()) + vResultImag[ix][iy] += vRHSImag[ix][iy]; + } + } + } + + return true; +} + +bool +ImageFile::multiplyImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + if (isComplex() || rRHS.isComplex() && ! result.isComplex()) + result.convertRealToComplex(); + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vLHSImag = getImaginaryArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArrayConst vRHSImag = rRHS.getImaginaryArray(); + ImageFileArray vResult = result.getArray(); + ImageFileArray vResultImag = result.getImaginaryArray(); + + for (unsigned int ix = 0; ix < m_nx; ix++) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + if (result.isComplex()) { + double dImag = 0; + if (isComplex()) + dImag = vLHSImag[ix][iy]; + std::complex cLHS (vLHS[ix][iy], dImag); + dImag = 0; + if (rRHS.isComplex()) + dImag = vRHSImag[ix][iy]; + std::complex cRHS (vRHS[ix][iy], dImag); + std::complex cResult = cLHS * cRHS; + vResult[ix][iy] = cResult.real(); + vResultImag[ix][iy] = cResult.imag(); + } else + vResult[ix][iy] = vLHS[ix][iy] * vRHS[ix][iy]; + } + } + + + return true; +} + +bool +ImageFile::divideImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + if (isComplex() || rRHS.isComplex() && ! result.isComplex()) + result.convertRealToComplex(); + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vLHSImag = getImaginaryArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArrayConst vRHSImag = rRHS.getImaginaryArray(); + ImageFileArray vResult = result.getArray(); + ImageFileArray vResultImag = result.getImaginaryArray(); + + for (unsigned int ix = 0; ix < m_nx; ix++) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + if (result.isComplex()) { + double dImag = 0; + if (isComplex()) + dImag = vLHSImag[ix][iy]; + std::complex cLHS (vLHS[ix][iy], dImag); + dImag = 0; + if (rRHS.isComplex()) + dImag = vRHSImag[ix][iy]; + std::complex cRHS (vRHS[ix][iy], dImag); + std::complex cResult = cLHS / cRHS; + vResult[ix][iy] = cResult.real(); + vResultImag[ix][iy] = cResult.imag(); + } else { + if (vRHS != 0) + vResult[ix][iy] = vLHS[ix][iy] / vRHS[ix][iy]; + else + vResult[ix][iy] = 0; + } + } + } + + return true; +} + + +bool +ImageFile::invertPixelValues (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 (isComplex() && ! result.isComplex()) + result.convertRealToComplex(); + + ImageFileArrayConst vLHS = getArray(); + ImageFileArray vResult = result.getArray(); + + for (unsigned int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in = vLHS[ix]; + ImageFileColumn out = vResult[ix]; + for (unsigned int iy = 0; iy < m_ny; iy++) + *out++ = - *in++; + } + + return true; +} + +bool +ImageFile::sqrt (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 (isComplex() && ! result.isComplex()) + result.convertRealToComplex(); + + bool bComplexOutput = result.isComplex(); + ImageFileArrayConst vLHS = getArray(); + if (! bComplexOutput) // check if should convert to complex output + for (unsigned int ix = 0; ix < m_nx; ix++) + for (unsigned int iy = 0; iy < m_ny; iy++) + if (! bComplexOutput && vLHS[ix][iy] < 0) { + result.convertRealToComplex(); + bComplexOutput = true; + break; + } + + ImageFileArrayConst vLHSImag = getImaginaryArray(); + ImageFileArray vResult = result.getArray(); + ImageFileArray vResultImag = result.getImaginaryArray(); + + for (unsigned int ix = 0; ix < m_nx; ix++) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + if (result.isComplex()) { + double dImag = 0; + if (isComplex()) + dImag = vLHSImag[ix][iy]; + std::complex cLHS (vLHS[ix][iy], dImag); + std::complex cResult = std::sqrt(cLHS); + vResult[ix][iy] = cResult.real(); + vResultImag[ix][iy] = cResult.imag(); + } else + vResult[ix][iy] = ::sqrt (vLHS[ix][iy]); + } + } + + + return true; +} + +bool +ImageFile::log (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 (isComplex() && ! result.isComplex()) + result.convertRealToComplex(); + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vLHSImag = getImaginaryArray(); + ImageFileArray vResult = result.getArray(); + ImageFileArray vResultImag = result.getImaginaryArray(); + + for (unsigned int ix = 0; ix < m_nx; ix++) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + if (result.isComplex()) { + double dImag = 0; + if (isComplex()) + dImag = vLHSImag[ix][iy]; + std::complex cLHS (vLHS[ix][iy], dImag); + std::complex cResult = std::log (cLHS); + vResult[ix][iy] = cResult.real(); + vResultImag[ix][iy] = cResult.imag(); + } else + vResult[ix][iy] = ::log (vLHS[ix][iy]); + } + } + + + return true; +} + +bool +ImageFile::exp (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 (isComplex() && ! result.isComplex()) + result.convertRealToComplex(); + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vLHSImag = getImaginaryArray(); + ImageFileArray vResult = result.getArray(); + ImageFileArray vResultImag = result.getImaginaryArray(); + + for (unsigned int ix = 0; ix < m_nx; ix++) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + if (result.isComplex()) { + double dImag = 0; + if (isComplex()) + dImag = vLHSImag[ix][iy]; + std::complex cLHS (vLHS[ix][iy], dImag); + std::complex cResult = std::exp (cLHS); + vResult[ix][iy] = cResult.real(); + vResultImag[ix][iy] = cResult.imag(); + } else + vResult[ix][iy] = ::exp (vLHS[ix][iy]); + } + } + + + return true; +} + +bool +ImageFile::scaleImage (ImageFile& result) const +{ + unsigned int nx = m_nx; + unsigned int ny = m_ny; + unsigned int newNX = result.nx(); + unsigned int newNY = result.ny(); + + double dXScale = static_cast(newNX) / static_cast(nx); + double dYScale = static_cast(newNY) / static_cast(ny); + + if (isComplex() && ! result.isComplex()) + result.convertRealToComplex(); + + ImageFileArrayConst vReal = getArray(); + ImageFileArrayConst vImag = getImaginaryArray(); + ImageFileArray vResult = result.getArray(); + ImageFileArray vResultImag = result.getImaginaryArray(); + + for (unsigned int ix = 0; ix < newNX; ix++) { + for (unsigned int iy = 0; iy < newNY; iy++) { + double dXPos = ix / dXScale; + double dYPos = iy / dYScale; + unsigned int scaleNX = static_cast (dXPos); + unsigned int scaleNY = static_cast (dYPos); + double dXFrac = dXPos - scaleNX; + double dYFrac = dYPos - scaleNY; + if (scaleNX >= nx - 1 || scaleNY >= ny - 1) { + vResult[ix][iy] = vReal[scaleNX][scaleNY]; + if (result.isComplex()) { + if (isComplex()) + vResultImag[ix][iy] = vImag[scaleNX][scaleNY]; + else + vResultImag[ix][iy] = 0; + } + } else { + vResult[ix][iy] = vReal[scaleNX][scaleNY] + + dXFrac * (vReal[scaleNX+1][scaleNY] - vReal[scaleNX][scaleNY]) + + dYFrac * (vReal[scaleNX][scaleNY+1] - vReal[scaleNX][scaleNY]); + if (result.isComplex()) { + if (isComplex()) + vResultImag[ix][iy] = vImag[scaleNX][scaleNY] + + dXFrac * (vImag[scaleNX+1][scaleNY] - vImag[scaleNX][scaleNY]) + + dYFrac * (vImag[scaleNX][scaleNY+1] - vImag[scaleNX][scaleNY]); + else + vResultImag[ix][iy] = 0; + } + } + } + } + + return true; +} + +#ifdef HAVE_FFTW +bool +ImageFile::fft (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.convertRealToComplex ()) + return false; + } + + fftw_complex* in = new fftw_complex [m_nx * m_ny]; + + ImageFileArrayConst vReal = getArray(); + ImageFileArrayConst vImag = getImaginaryArray(); + + unsigned int ix, iy; + unsigned int iArray = 0; + for (ix = 0; ix < m_nx; ix++) + for (iy = 0; iy < m_ny; iy++) { + in[iArray].re = vReal[ix][iy]; + if (isComplex()) + in[iArray].im = vImag[ix][iy]; + else + in[iArray].im = 0; + iArray++; + } + + fftwnd_plan plan = fftw2d_create_plan (m_nx, m_ny, FFTW_FORWARD, FFTW_IN_PLACE); + + fftwnd_one (plan, in, NULL); + + ImageFileArray vRealResult = result.getArray(); + ImageFileArray vImagResult = result.getImaginaryArray(); + iArray = 0; + unsigned int iScale = m_nx * m_ny; + for (ix = 0; ix < m_nx; ix++) + for (iy = 0; iy < m_ny; iy++) { + vRealResult[ix][iy] = in[iArray].re / iScale; + vImagResult[ix][iy] = in[iArray].im / iScale; + iArray++; + } + + fftwnd_destroy_plan (plan); + delete in; + + + Fourier::shuffleFourierToNaturalOrder (result); + + return true; +} + + +bool +ImageFile::ifft (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.convertRealToComplex ()) + return false; + } + + ImageFileArrayConst vReal = getArray(); + ImageFileArrayConst vImag = getImaginaryArray(); + ImageFileArray vRealResult = result.getArray(); + ImageFileArray vImagResult = result.getImaginaryArray(); + unsigned int ix, iy; + for (ix = 0; ix < m_nx; ix++) + for (iy = 0; iy < m_ny; iy++) { + vRealResult[ix][iy] = vReal[ix][iy]; + if (isComplex()) + vImagResult[ix][iy] = vImag[ix][iy]; + else + vImagResult[ix][iy] = 0; + } + + Fourier::shuffleNaturalToFourierOrder (result); + + fftw_complex* in = new fftw_complex [m_nx * m_ny]; + + unsigned int iArray = 0; + for (ix = 0; ix < m_nx; ix++) + for (iy = 0; iy < m_ny; iy++) { + in[iArray].re = vRealResult[ix][iy]; + in[iArray].im = vImagResult[ix][iy]; + iArray++; + } + + fftwnd_plan plan = fftw2d_create_plan (m_nx, m_ny, FFTW_BACKWARD, FFTW_IN_PLACE); + + fftwnd_one (plan, in, NULL); + + iArray = 0; + for (ix = 0; ix < m_nx; ix++) + for (iy = 0; iy < m_ny; iy++) { + vRealResult[ix][iy] = in[iArray].re; + vImagResult[ix][iy] = in[iArray].im; + iArray++; + } + + fftwnd_destroy_plan (plan); + + delete in; + + return true; +} +#endif // HAVE_FFTW + + + +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.isComplex()) + if (! result.convertRealToComplex ()) + return false; + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vLHSImag = getImaginaryArray(); + ImageFileArray vRealResult = result.getArray(); + ImageFileArray vImagResult = result.getImaginaryArray(); + + unsigned int ix, iy; + + // alloc output matrix + CTSimComplex** complexOut = new CTSimComplex* [m_nx]; + for (ix = 0; ix < m_nx; ix++) + complexOut[ix] = new CTSimComplex [m_ny]; + + // fourier each x column + CTSimComplex* pY = new CTSimComplex [m_ny]; + for (ix = 0; ix < m_nx; ix++) { + for (iy = 0; iy < m_ny; iy++) { + double dImag = 0; + if (isComplex()) + dImag = vLHSImag[ix][iy]; + pY[iy] = std::complex(vLHS[ix][iy], dImag); + } + ProcessSignal::finiteFourierTransform (pY, complexOut[ix], m_ny, ProcessSignal::FORWARD); + } + delete [] pY; + + // fourier each y row + CTSimComplex* pX = new CTSimComplex [m_nx]; + CTSimComplex* complexOutRow = new CTSimComplex [m_nx]; + for (iy = 0; iy < m_ny; iy++) { + for (ix = 0; ix < m_nx; ix++) + pX[ix] = complexOut[ix][iy]; + ProcessSignal::finiteFourierTransform (pX, complexOutRow, m_nx, ProcessSignal::FORWARD); + for (ix = 0; ix < m_nx; ix++) + complexOut[ix][iy] = complexOutRow[ix]; + } + delete [] pX; + delete [] complexOutRow; + + for (ix = 0; ix < m_nx; ix++) + for (iy = 0; iy < m_ny; iy++) { + vRealResult[ix][iy] = complexOut[ix][iy].real(); + vImagResult[ix][iy] = complexOut[ix][iy].imag(); + } + + Fourier::shuffleFourierToNaturalOrder (result); + + // delete complexOut matrix + for (ix = 0; ix < m_nx; ix++) + delete [] complexOut[ix]; + delete [] complexOut; + + return true; +} + +bool +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; + } + + if (result.dataType() == Array2dFile::DATA_TYPE_REAL) { + if (! result.convertRealToComplex ()) + return false; + } + + ImageFileArrayConst vLHSReal = getArray(); + ImageFileArrayConst vLHSImag = getImaginaryArray(); + ImageFileArray vRealResult = result.getArray(); + ImageFileArray vImagResult = result.getImaginaryArray(); + + unsigned int ix, iy; + // alloc 2d complex output matrix + CTSimComplex** complexOut = new CTSimComplex* [m_nx]; + for (ix = 0; ix < m_nx; ix++) + complexOut[ix] = new CTSimComplex [m_ny]; + + // put input image into result + for (ix = 0; ix < m_nx; ix++) + for (iy = 0; iy < m_ny; iy++) { + vRealResult[ix][iy] = vLHSReal[ix][iy]; + if (isComplex()) + vImagResult[ix][iy] = vLHSImag[ix][iy]; + else + vImagResult[ix][iy] = 0; + } + + Fourier::shuffleNaturalToFourierOrder (result); + + // ifourier each x column + CTSimComplex* pCol = new CTSimComplex [m_ny]; + for (ix = 0; ix < m_nx; ix++) { + for (iy = 0; iy < m_ny; iy++) { + pCol[iy] = std::complex (vRealResult[ix][iy], vImagResult[ix][iy]); + } + ProcessSignal::finiteFourierTransform (pCol, complexOut[ix], m_ny, ProcessSignal::BACKWARD); + } + delete [] pCol; + + // ifourier each y row + CTSimComplex* complexInRow = new CTSimComplex [m_nx]; + CTSimComplex* complexOutRow = new CTSimComplex [m_nx]; + for (iy = 0; iy < m_ny; iy++) { + for (ix = 0; ix < m_nx; ix++) + complexInRow[ix] = complexOut[ix][iy]; + ProcessSignal::finiteFourierTransform (complexInRow, complexOutRow, m_nx, ProcessSignal::BACKWARD); + for (ix = 0; ix < m_nx; ix++) + complexOut[ix][iy] = complexOutRow[ix]; + } + delete [] complexInRow; + delete [] complexOutRow; + + for (ix = 0; ix < m_nx; ix++) + for (iy = 0; iy < m_ny; iy++) { + vRealResult[ix][iy] = complexOut[ix][iy].real(); + vImagResult[ix][iy] = complexOut[ix][iy].imag(); + } + + // delete complexOut matrix + for (ix = 0; ix < m_nx; ix++) + delete [] complexOut[ix]; + delete [] complexOut; + + return true; +} + + +bool +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; + } + + ImageFileArray vReal = getArray(); + ImageFileArray vImag = getImaginaryArray(); + ImageFileArray vRealResult = result.getArray(); + + for (unsigned int ix = 0; ix < m_nx; ix++) + for (unsigned int iy = 0; iy < m_ny; iy++) { + if (isComplex()) + vRealResult[ix][iy] = ::sqrt (vReal[ix][iy] * vReal[ix][iy] + vImag[ix][iy] * vImag[ix][iy]); + else + vRealResult[ix][iy] = vReal[ix][iy]; + } + + if (result.isComplex()) + result.convertComplexToReal(); + + 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; + } + + ImageFileArray vReal = getArray(); + ImageFileArray vImag = getImaginaryArray(); + ImageFileArray vRealResult = result.getArray(); + + for (unsigned int ix = 0; ix < m_nx; ix++) + for (unsigned int iy = 0; iy < m_ny; iy++) { + if (isComplex()) + vRealResult[ix][iy] = ::atan2 (vImag[ix][iy], vReal[ix][iy]); + else + vRealResult[ix][iy] = 0; + } + + if (result.isComplex()) + result.convertComplexToReal(); + + return true; +} + +bool +ImageFile::square (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 (isComplex() && ! result.isComplex()) + result.convertRealToComplex(); + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vLHSImag = getImaginaryArray(); + ImageFileArray vResult = result.getArray(); + ImageFileArray vResultImag = result.getImaginaryArray(); + + for (unsigned int ix = 0; ix < m_nx; ix++) { + for (unsigned int iy = 0; iy < m_ny; iy++) { + if (result.isComplex()) { + double dImag = 0; + if (isComplex()) + dImag = vLHSImag[ix][iy]; + std::complex cLHS (vLHS[ix][iy], dImag); + std::complex cResult = cLHS * cLHS; + vResult[ix][iy] = cResult.real(); + vResultImag[ix][iy] = cResult.imag(); + } else + vResult[ix][iy] = vLHS[ix][iy] * vLHS[ix][iy]; + } + } + + + return true; +} + +int +ImageFile::convertFormatNameToID (const char* const formatName) +{ + int formatID = FORMAT_INVALID; + + for (int i = 0; i < s_iFormatCount; i++) + if (strcasecmp (formatName, s_aszFormatName[i]) == 0) { + formatID = i; + break; + } + + return (formatID); +} + +const char* +ImageFile::convertFormatIDToName (int formatID) +{ + static const char *formatName = ""; + + if (formatID >= 0 && formatID < s_iFormatCount) + return (s_aszFormatName[formatID]); + + return (formatName); +} + +const char* +ImageFile::convertFormatIDToTitle (const int formatID) +{ + static const char *formatTitle = ""; + + if (formatID >= 0 && formatID < s_iFormatCount) + return (s_aszFormatTitle[formatID]); + + return (formatTitle); +} + +bool +ImageFile::exportImage (const char* const pszFormat, const char* const pszFilename, int nxcell, int nycell, double densmin, double densmax) +{ + int iFormatID = convertFormatNameToID (pszFormat); + if (iFormatID == FORMAT_INVALID) { + sys_error (ERR_SEVERE, "Invalid format %s [ImageFile::exportImage]", pszFormat); + return false; + } + + if (iFormatID == FORMAT_PGM) + return writeImagePGM (pszFilename, nxcell, nycell, densmin, densmax); + else if (iFormatID == FORMAT_PGMASCII) + return writeImagePGMASCII (pszFilename, nxcell, nycell, densmin, densmax); + else if (iFormatID == FORMAT_PNG) + return writeImagePNG (pszFilename, 8, nxcell, nycell, densmin, densmax); + else if (iFormatID == FORMAT_PNG16) + return writeImagePNG (pszFilename, 16, nxcell, nycell, densmin, densmax); + + sys_error (ERR_SEVERE, "Invalid format %s [ImageFile::exportImage]", pszFormat); + return false; +} + bool ImageFile::writeImagePGM (const char* const outfile, int nxcell, int nycell, double densmin, double densmax) { @@ -1144,10 +1144,10 @@ ImageFile::writeImagePGM (const char* const outfile, int nxcell, int nycell, dou fputc( rowp[ic], fp ); } } - + delete rowp; - fclose(fp); - + fclose(fp); + return true; } @@ -1183,10 +1183,10 @@ ImageFile::writeImagePGMASCII (const char* const outfile, int nxcell, int nycell fprintf(fp, "\n"); } } - + delete rowp; - fclose(fp); - + fclose(fp); + return true; } @@ -1202,7 +1202,7 @@ ImageFile::writeImagePNG (const char* const outfile, int bitdepth, int nxcell, i unsigned char* rowp = new unsigned char [nx * nxcell * (bitdepth / 8)]; - FILE *fp = fopen (outfile, "wb"); + FILE *fp = fopen (outfile, "wb"); if (! fp) return false; @@ -1253,10 +1253,10 @@ ImageFile::writeImagePNG (const char* const outfile, int bitdepth, int nxcell, i png_write_end (png_ptr, info_ptr); png_destroy_write_struct (&png_ptr, &info_ptr); - delete rowp; + delete rowp; + + fclose(fp); - fclose(fp); - return true; } #endif @@ -1295,17 +1295,17 @@ ImageFile::writeImageGIF (const char* const outfile, int nxcell, int nycell, dou } } - FILE *out; + FILE *out; if ((out = fopen (outfile,"w")) == NULL) { sys_error(ERR_FATAL, "Error opening output file %s for writing", outfile); return false; } gdImageGif(gif,out); fclose(out); - gdImageDestroy(gif); - - delete rowp; - + gdImageDestroy(gif); + + delete rowp; + return true; } #endif diff --git a/libctsim/phantom.cpp b/libctsim/phantom.cpp index b74e531..467c8e9 100644 --- a/libctsim/phantom.cpp +++ b/libctsim/phantom.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: phantom.cpp,v 1.25 2001/01/02 07:47:36 kevin Exp $ +** $Id: phantom.cpp,v 1.26 2001/01/02 16:02:13 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 @@ -27,8 +27,8 @@ #include "ct.h" -const int PhantomElement::POINTS_PER_CIRCLE = 360; -const double PhantomElement::SCALE_PELEM_EXTENT=0.005; // increase pelem limits by 0.5% +const int PhantomElement::POINTS_PER_CIRCLE = 360; +const double PhantomElement::SCALE_PELEM_EXTENT=0.005; // increase pelem limits by 0.5% const int Phantom::PHM_INVALID = -1; const int Phantom::PHM_HERMAN = 0; @@ -226,15 +226,15 @@ Phantom::createFromFile (const char* const fname) return (bGoodFile); } -bool -Phantom::fileWrite (const char* const fname) -{ - fstream file (fname, ios::out); - - if (! file.fail()) - printDefinitions (file); - return ! file.fail(); -} +bool +Phantom::fileWrite (const char* const fname) +{ + fstream file (fname, ios::out); + + if (! file.fail()) + printDefinitions (file); + return ! file.fail(); +} /* NAME * addPElem Add pelem @@ -288,12 +288,12 @@ Phantom::print (std::ostream& os) const os << "Number of PElements: " << m_nPElem << "\n"; os << "Limits: xmin=" << m_xmin << ", ymin=" << m_ymin << ", xmax=" << m_xmax << ", ymax=" << m_ymax << "\n"; - for (PElemConstIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) { + for (PElemConstIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) { const PhantomElement& rPE = **i; - os << "PhantomElement: nPoints=" << rPE.nOutlinePoints(); + os << "PhantomElement: nPoints=" << rPE.nOutlinePoints(); os << ", atten=" << rPE.atten() << " rot=" << convertRadiansToDegrees (rPE.rot()) << "\n"; os << "xmin=" << rPE.xmin() << ", ymin=" << rPE.ymin() << ", xmax=" << rPE.xmax() << ", ymax=" << rPE.ymax() << "\n"; - + if (false) for (int i = 0; i < rPE.nOutlinePoints(); i++) os << rPE.xOutline()[i] << "," << rPE.yOutline()[i] << "\n"; @@ -305,36 +305,36 @@ Phantom::print (std::ostringstream& os) const os << "Number of PElements: " << m_nPElem << "\n"; os << "Limits: xmin=" << m_xmin << ", ymin=" << m_ymin << ", xmax=" << m_xmax << ", ymax=" << m_ymax << "\n"; - for (PElemConstIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) { + for (PElemConstIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) { const PhantomElement& rPE = **i; - os << "PhantomElement: nPoints=" << rPE.nOutlinePoints(); + os << "PhantomElement: nPoints=" << rPE.nOutlinePoints(); os << ", atten=" << rPE.atten() << " rot=" << convertRadiansToDegrees (rPE.rot()) << "\n"; os << "xmin=" << rPE.xmin() << ", ymin=" << rPE.ymin() << ", xmax=" << rPE.xmax() << ", ymax=" << rPE.ymax() << "\n"; - + if (false) for (int i = 0; i < rPE.nOutlinePoints(); i++) os << rPE.xOutline()[i] << "," << rPE.yOutline()[i] << "\n"; } } - -void -Phantom::printDefinitions (std::ostream& os) const -{ - for (PElemConstIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) { - const PhantomElement& rPE = **i; - rPE.printDefinition (os); - } -} - -void -Phantom::printDefinitions (std::ostringstream& os) const -{ - for (PElemConstIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) { - const PhantomElement& rPE = **i; - rPE.printDefinition (os); - } -} - + +void +Phantom::printDefinitions (std::ostream& os) const +{ + for (PElemConstIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) { + const PhantomElement& rPE = **i; + rPE.printDefinition (os); + } +} + +void +Phantom::printDefinitions (std::ostringstream& os) const +{ + for (PElemConstIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) { + const PhantomElement& rPE = **i; + rPE.printDefinition (os); + } +} + /* NAME * show Show vector outline of Phantom to user @@ -550,13 +550,13 @@ Phantom::convertToImagefile (ImageFile& im, const int in_nsample, const int trac if (nsample > 1) { double factor = 1.0 / static_cast(nsample * nsample); - + for (int ix = 0; ix < colCount; ix++) { - int iColStore = ix; - if (bStoreAtColumnPos) - iColStore += colStart; + int iColStore = ix; + if (bStoreAtColumnPos) + iColStore += colStart; for (int iy = 0; iy < ny; iy++) - v[iColStore][iy] *= factor; + v[iColStore][iy] *= factor; } } } @@ -594,27 +594,27 @@ PhantomElement::PhantomElement (const char *type, const double cx, const double m_rectLimits[2] = m_xmax; m_rectLimits[3] = m_ymax; } - + PhantomElement::~PhantomElement () { delete m_xOutline; delete m_yOutline; } - -void -PhantomElement::printDefinition (std::ostream& os) const -{ - os << convertTypeToName (m_type) << " " << m_cx << " " << m_cy << " " << m_u << " " - << m_v << " " << convertRadiansToDegrees (m_rot) << " " << m_atten << "\n"; -} - -void -PhantomElement::printDefinition (std::ostringstream& os) const -{ - os << convertTypeToName (m_type) << " " << m_cx << " " << m_cy << " " << m_u << " " - << m_v << " " << convertRadiansToDegrees (m_rot) << " " << m_atten << "\n"; -} + +void +PhantomElement::printDefinition (std::ostream& os) const +{ + os << convertTypeToName (m_type) << " " << m_cx << " " << m_cy << " " << m_u << " " + << m_v << " " << convertRadiansToDegrees (m_rot) << " " << m_atten << "\n"; +} + +void +PhantomElement::printDefinition (std::ostringstream& os) const +{ + os << convertTypeToName (m_type) << " " << m_cx << " " << m_cy << " " << m_u << " " + << m_v << " " << convertRadiansToDegrees (m_rot) << " " << m_atten << "\n"; +} PhmElemType PhantomElement::convertNameToType (const char* const typeName) @@ -636,26 +636,26 @@ PhantomElement::convertNameToType (const char* const typeName) return (type); } - -const char* const -PhantomElement::convertTypeToName (PhmElemType iType) -{ - static char* pszType = "Unknown"; - - if (iType == PELEM_RECTANGLE) - pszType = "rectangle"; - else if (iType == PELEM_TRIANGLE) - pszType = "triangle"; - else if (iType == PELEM_ELLIPSE) - pszType = "ellipse"; - else if (iType == PELEM_SECTOR) - pszType = "sector"; - else if (iType == PELEM_SEGMENT) - pszType = "segment"; - - return pszType; -} - + +const char* const +PhantomElement::convertTypeToName (PhmElemType iType) +{ + static char* pszType = "Unknown"; + + if (iType == PELEM_RECTANGLE) + pszType = "rectangle"; + else if (iType == PELEM_TRIANGLE) + pszType = "triangle"; + else if (iType == PELEM_ELLIPSE) + pszType = "ellipse"; + else if (iType == PELEM_SECTOR) + pszType = "sector"; + else if (iType == PELEM_SEGMENT) + pszType = "segment"; + + return pszType; +} + void PhantomElement::makeTransformMatrices () diff --git a/libctsim/procsignal.cpp b/libctsim/procsignal.cpp index 41895ac..71a0e67 100644 --- a/libctsim/procsignal.cpp +++ b/libctsim/procsignal.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: procsignal.cpp,v 1.13 2001/01/02 05:34:57 kevin Exp $ +** $Id: procsignal.cpp,v 1.14 2001/01/02 16:02:13 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 @@ -115,7 +115,7 @@ ProcessSignal::ProcessSignal (const char* szFilterName, const char* szFilterMeth void ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandwidth, double dSignalIncrement, int nSignalPoints, double dFilterParam, const int idDomain, const int idFilterGeneration, const int iZeropad, const int iPreinterpolationFactor, int iTraceLevel, int iGeometry, double dFocalLength, SGP* pSGP) -{ +{ int i; m_idFilter = idFilter; m_idDomain = idDomain; @@ -200,7 +200,7 @@ ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandw } #endif ProcessSignal::finiteFourierTransform (adFrequencyFilter, m_adFilter, m_nFilterPoints, FORWARD); - delete adFrequencyFilter; + delete adFrequencyFilter; #ifdef HAVE_SGP if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) { pEZPlot->ezset ("title Inverse Fourier Frequency: Fourier Order"); @@ -335,7 +335,7 @@ ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandw if (m_traceLevel >= Trace::TRACE_CONSOLE) std::cout << "nFilterPoints = " << m_nFilterPoints << endl; #endif - double* adSpatialFilter = new double [m_nFilterPoints]; + double* adSpatialFilter = new double [m_nFilterPoints]; SignalFilter filter (m_idFilter, m_dFilterMin, m_dFilterMax, nSpatialPoints, m_dBandwidth, m_dFilterParam, SignalFilter::DOMAIN_SPATIAL); filter.copyFilterData (adSpatialFilter, 0, nSpatialPoints); #ifdef HAVE_SGP @@ -364,17 +364,17 @@ ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandw double dScale = 0.5 * sinScale * sinScale; adSpatialFilter[i] *= dScale; } - } + } for (i = nSpatialPoints; i < m_nFilterPoints; i++) adSpatialFilter[i] = 0; m_adFilter = new double [m_nFilterPoints]; - std::complex* acInverseFilter = new std::complex [m_nFilterPoints]; + std::complex* acInverseFilter = new std::complex [m_nFilterPoints]; finiteFourierTransform (adSpatialFilter, acInverseFilter, m_nFilterPoints, BACKWARD); - delete adSpatialFilter; + delete adSpatialFilter; for (i = 0; i < m_nFilterPoints; i++) m_adFilter[i] = std::abs (acInverseFilter[i]) * m_dSignalInc; - delete acInverseFilter; + delete acInverseFilter; #ifdef HAVE_SGP if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) { pEZPlot->ezset ("title Spatial Filter: Inverse"); @@ -382,7 +382,7 @@ ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandw pEZPlot->ezset ("yporigin 0.50"); pEZPlot->addCurve (m_adFilter, m_nFilterPoints); pEZPlot->plot (pSGP); - delete pEZPlot; + delete pEZPlot; } #endif } @@ -528,7 +528,7 @@ void ProcessSignal::filterSignal (const float constInput[], double output[]) const { double* input = new double [m_nSignalPoints]; - int i; + int i; for (i = 0; i < m_nSignalPoints; i++) input[i] = constInput[i]; @@ -542,7 +542,7 @@ ProcessSignal::filterSignal (const float constInput[], double output[]) const int iDetFromCenter = i - (m_nSignalPoints / 2); input[i] *= m_dFocalLength * cos (iDetFromCenter * m_dSignalInc); } - } + } if (m_idFilterMethod == FILTER_METHOD_CONVOLUTION) { for (i = 0; i < m_nSignalPoints; i++) output[i] = convolve (input, m_dSignalInc, i, m_nSignalPoints); @@ -553,15 +553,15 @@ ProcessSignal::filterSignal (const float constInput[], double output[]) const for (i = m_nSignalPoints; i < m_nFilterPoints; i++) inputSignal[i] = 0; // zeropad std::complex* fftSignal = new std::complex [m_nFilterPoints]; - finiteFourierTransform (inputSignal, fftSignal, m_nFilterPoints, FORWARD); + finiteFourierTransform (inputSignal, fftSignal, m_nFilterPoints, FORWARD); delete inputSignal; for (i = 0; i < m_nFilterPoints; i++) fftSignal[i] *= m_adFilter[i]; double* inverseFourier = new double [m_nFilterPoints]; - finiteFourierTransform (fftSignal, inverseFourier, m_nFilterPoints, BACKWARD); + finiteFourierTransform (fftSignal, inverseFourier, m_nFilterPoints, BACKWARD); delete fftSignal; for (i = 0; i < m_nSignalPoints; i++) - output[i] = inverseFourier[i]; + output[i] = inverseFourier[i]; delete inverseFourier; } else if (m_idFilterMethod == FILTER_METHOD_FOURIER_TABLE) { double* inputSignal = new double [m_nFilterPoints]; @@ -570,15 +570,15 @@ ProcessSignal::filterSignal (const float constInput[], double output[]) const for (i = m_nSignalPoints; i < m_nFilterPoints; i++) inputSignal[i] = 0; // zeropad std::complex* fftSignal = new std::complex [m_nFilterPoints]; - finiteFourierTransform (inputSignal, fftSignal, FORWARD); + finiteFourierTransform (inputSignal, fftSignal, FORWARD); delete inputSignal; for (i = 0; i < m_nFilterPoints; i++) fftSignal[i] *= m_adFilter[i]; double* inverseFourier = new double [m_nFilterPoints]; - finiteFourierTransform (fftSignal, inverseFourier, BACKWARD); + finiteFourierTransform (fftSignal, inverseFourier, BACKWARD); delete fftSignal; for (i = 0; i < m_nSignalPoints; i++) - output[i] = inverseFourier[i]; + output[i] = inverseFourier[i]; delete inverseFourier; } #if HAVE_FFTW @@ -589,7 +589,7 @@ ProcessSignal::filterSignal (const float constInput[], double output[]) const fftw_real* fftOutput = new fftw_real [ m_nFilterPoints ]; rfftw_one (m_realPlanForward, m_adRealFftInput, fftOutput); for (i = 0; i < m_nFilterPoints; i++) - m_adRealFftSignal[i] = m_adFilter[i] * fftOutput[i]; + m_adRealFftSignal[i] = m_adFilter[i] * fftOutput[i]; delete [] fftOutput; for (i = m_nFilterPoints; i < m_nOutputPoints; i++) m_adRealFftSignal[i] = 0; @@ -597,7 +597,7 @@ ProcessSignal::filterSignal (const float constInput[], double output[]) const fftw_real* ifftOutput = new fftw_real [ m_nOutputPoints ]; rfftw_one (m_realPlanBackward, m_adRealFftSignal, ifftOutput); for (i = 0; i < m_nSignalPoints * m_iPreinterpolationFactor; i++) - output[i] = ifftOutput[i]; + output[i] = ifftOutput[i]; delete [] ifftOutput; } else if (m_idFilterMethod == FILTER_METHOD_FFTW) { for (i = 0; i < m_nSignalPoints; i++) @@ -608,15 +608,15 @@ ProcessSignal::filterSignal (const float constInput[], double output[]) const for (i = 0; i < m_nFilterPoints; i++) { m_adComplexFftSignal[i].re = m_adFilter[i] * fftOutput[i].re; m_adComplexFftSignal[i].im = m_adFilter[i] * fftOutput[i].im; - } + } delete [] fftOutput; fftw_complex* ifftOutput = new fftw_complex [ m_nOutputPoints ]; fftw_one (m_complexPlanBackward, m_adComplexFftSignal, ifftOutput); for (i = 0; i < m_nSignalPoints * m_iPreinterpolationFactor; i++) - output[i] = ifftOutput[i].re; + output[i] = ifftOutput[i].re; delete [] ifftOutput; } -#endif +#endif delete input; } @@ -690,7 +690,7 @@ ProcessSignal::finiteFourierTransform (const double input[], double output[], co finiteFourierTransform (input, complexOutput, n, direction); for (int i = 0; i < n; i++) - output[i] = complexOutput[i].real(); + output[i] = complexOutput[i].real(); delete [] complexOutput; } @@ -733,8 +733,8 @@ ProcessSignal::finiteFourierTransform (const std::complex input[], std:: std::complex sum (0,0); for (int j = 0; j < n; j++) { double angle = i * j * angleIncrement; - std::complex exponentTerm (cos(angle), sin(angle)); - sum += input[j] * exponentTerm; + std::complex exponentTerm (cos(angle), sin(angle)); + sum += input[j] * exponentTerm; } if (direction < 0) { sum /= n; diff --git a/libctsim/projections.cpp b/libctsim/projections.cpp index 4c31b38..f6fff53 100644 --- a/libctsim/projections.cpp +++ b/libctsim/projections.cpp @@ -8,7 +8,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: projections.cpp,v 1.34 2001/01/02 06:29:23 kevin Exp $ +** $Id: projections.cpp,v 1.35 2001/01/02 16:02:13 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 @@ -25,8 +25,8 @@ ******************************************************************************/ #include "ct.h" - -const kuint16 Projections::m_signature = ('P'*256 + 'J'); + +const kuint16 Projections::m_signature = ('P'*256 + 'J'); /* NAME * Projections Constructor for projections matrix storage @@ -71,15 +71,15 @@ Projections::init (const int nView, const int nDet) m_nView = nView; m_nDet = nDet; newProjData (); - - time_t t = time (NULL); - 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; + + time_t t = time (NULL); + 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; } void @@ -271,7 +271,7 @@ Projections::headerRead (fnetorderstream& fs) } pszRemarkStorage[_remarksize] = 0; m_remark = pszRemarkStorage; - delete pszRemarkStorage; + delete pszRemarkStorage; off_t _hsizeread = fs.tellg(); if (!fs || _hsizeread != _hsize) { @@ -316,12 +316,12 @@ Projections::read (const std::string& filename) bool Projections::read (const char* filename) { - m_filename = filename; -#ifdef MSVC - frnetorderstream fileRead (m_filename.c_str(), std::ios::in | std::ios::binary); -#else - frnetorderstream fileRead (m_filename.c_str(), std::ios::in | std::ios::binary | std::ios::nocreate); -#endif + m_filename = filename; +#ifdef MSVC + frnetorderstream fileRead (m_filename.c_str(), std::ios::in | std::ios::binary); +#else + frnetorderstream fileRead (m_filename.c_str(), std::ios::in | std::ios::binary | std::ios::nocreate); +#endif if (fileRead.fail()) return false; diff --git a/libctsim/reconstruct.cpp b/libctsim/reconstruct.cpp index df45621..c858027 100644 --- a/libctsim/reconstruct.cpp +++ b/libctsim/reconstruct.cpp @@ -8,7 +8,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: reconstruct.cpp,v 1.6 2000/12/29 15:45:06 kevin Exp $ +** $Id: reconstruct.cpp,v 1.7 2001/01/02 16:02:13 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 @@ -123,7 +123,7 @@ Reconstructor::plotFilter (SGP* pSGP) ezplot.addCurve (adPlotXAxis, m_pProcessSignal->getFilter(), nVecFilter); ezplot.plot (pSGP); } - } + } delete adPlotXAxis; #endif } @@ -165,7 +165,7 @@ Reconstructor::reconstructView (int iStartView, int iViewCount, SGP* pSGP, bool } #endif #endif - + if (bBackprojectView) m_pBackprojector->BackprojectView (adFilteredProj, rDetArray.viewAngle()); @@ -197,7 +197,7 @@ Reconstructor::reconstructView (int iStartView, int iViewCount, SGP* pSGP, bool } #endif //HAVE_SGP } - - delete adFilteredProj; + + delete adFilteredProj; } diff --git a/libctsupport/clip.cpp b/libctsupport/clip.cpp index 3ff8b08..e11e334 100644 --- a/libctsupport/clip.cpp +++ b/libctsupport/clip.cpp @@ -14,7 +14,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: clip.cpp,v 1.6 2000/12/06 15:17:51 kevin Exp $ +** $Id: clip.cpp,v 1.7 2001/01/02 16:02:13 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 @@ -331,7 +331,7 @@ tcode (const double x, const double y, const double m, const double b, const int static int rectcode (double x, double y, const double rect[4]); -bool +bool clip_rect (double& x1, double& y1, double& x2, double& y2, const double rect[4]) { double x = 0, y = 0; diff --git a/libctsupport/fnetorderstream.cpp b/libctsupport/fnetorderstream.cpp index ffa26f0..41d1ead 100644 --- a/libctsupport/fnetorderstream.cpp +++ b/libctsupport/fnetorderstream.cpp @@ -48,7 +48,7 @@ ConvertReverseNetworkOrder (void* buffer, size_t bytes) #endif } -void +void fnetorderstream::writeInt16 (kuint16 n) { #ifndef WORDS_BIGENDIAN SwapBytes2 (&n); @@ -56,7 +56,7 @@ fnetorderstream::writeInt16 (kuint16 n) { write (reinterpret_cast(&n), 2); } -void +void fnetorderstream::writeInt32 (kuint32 n) { #ifndef WORDS_BIGENDIAN SwapBytes4(&n); @@ -64,7 +64,7 @@ fnetorderstream::writeInt32 (kuint32 n) { write (reinterpret_cast(&n), 4); } -void +void fnetorderstream::writeFloat32 (kfloat32 n) { #ifndef WORDS_BIGENDIAN SwapBytes4 (&n); @@ -72,7 +72,7 @@ fnetorderstream::writeFloat32 (kfloat32 n) { write (reinterpret_cast(&n), 4); } -void +void fnetorderstream::writeFloat64 (kfloat64 n) { #ifndef WORDS_BIGENDIAN SwapBytes8 (&n); @@ -80,7 +80,7 @@ fnetorderstream::writeFloat64 (kfloat64 n) { write (reinterpret_cast(&n), 8); } -void +void fnetorderstream::readInt16 (kuint16& n) { read (reinterpret_cast(&n), 2); #ifndef WORDS_BIGENDIAN @@ -88,7 +88,7 @@ fnetorderstream::readInt16 (kuint16& n) { #endif } -void +void fnetorderstream::readInt32 (kuint32& n) { read (reinterpret_cast(&n), 4); #ifndef WORDS_BIGENDIAN @@ -96,7 +96,7 @@ fnetorderstream::readInt32 (kuint32& n) { #endif } -void +void fnetorderstream::readFloat32 (kfloat32& n) { read (reinterpret_cast(&n), 4); #ifndef WORDS_BIGENDIAN @@ -104,7 +104,7 @@ fnetorderstream::readFloat32 (kfloat32& n) { #endif } -void +void fnetorderstream::readFloat64 (kfloat64& n) { read (reinterpret_cast(&n), 8); #ifndef WORDS_BIGENDIAN @@ -114,7 +114,7 @@ fnetorderstream::readFloat64 (kfloat64& n) { -void +void frnetorderstream::writeInt16 (kuint16 n) { #ifdef WORDS_BIGENDIAN SwapBytes2 (&n); @@ -122,7 +122,7 @@ frnetorderstream::writeInt16 (kuint16 n) { write (reinterpret_cast(&n), 2); } -void +void frnetorderstream::writeInt32 (kuint32 n) { #ifdef WORDS_BIGENDIAN SwapBytes4(&n); @@ -130,7 +130,7 @@ frnetorderstream::writeInt32 (kuint32 n) { write (reinterpret_cast(&n), 4); } -void +void frnetorderstream::writeFloat32 (kfloat32 n) { #ifdef WORDS_BIGENDIAN SwapBytes4 (&n); @@ -138,7 +138,7 @@ frnetorderstream::writeFloat32 (kfloat32 n) { write (reinterpret_cast(&n), 4); } -void +void frnetorderstream::writeFloat64 (kfloat64 n) { #ifdef WORDS_BIGENDIAN SwapBytes8 (&n); @@ -146,7 +146,7 @@ frnetorderstream::writeFloat64 (kfloat64 n) { write (reinterpret_cast(&n), 8); } -void +void frnetorderstream::readInt16 (kuint16& n) { read (reinterpret_cast(&n), 2); #ifdef WORDS_BIGENDIAN @@ -154,7 +154,7 @@ frnetorderstream::readInt16 (kuint16& n) { #endif } -void +void frnetorderstream::readInt32 (kuint32& n) { read (reinterpret_cast(&n), 4); #ifdef WORDS_BIGENDIAN @@ -162,7 +162,7 @@ frnetorderstream::readInt32 (kuint32& n) { #endif } -void +void frnetorderstream::readFloat32 (kfloat32& n) { read (reinterpret_cast(&n), 4); #ifdef WORDS_BIGENDIAN @@ -170,7 +170,7 @@ frnetorderstream::readFloat32 (kfloat32& n) { #endif } -void +void frnetorderstream::readFloat64 (kfloat64& n) { read (reinterpret_cast(&n), 8); #ifdef WORDS_BIGENDIAN diff --git a/libctsupport/hashtable.cpp b/libctsupport/hashtable.cpp index a4dd283..d5e1e11 100644 --- a/libctsupport/hashtable.cpp +++ b/libctsupport/hashtable.cpp @@ -1,141 +1,141 @@ -/***************************************************************************** -** FILE IDENTIFICATION -** -** Hash Table Class -** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: hashtable.cpp,v 1.1 2000/12/27 20:09:19 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 -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -#include "ct.h" -#include -#include -#include -#include "ctsupport.h" -#include "pol.h" - - -KeywordCodeEntry::KeywordCodeEntry (const char* const pszKeyword, int iCode) - : m_iCode (iCode), m_pNext(NULL) -{ - int nLength = strlen (pszKeyword); - char* pszCopy = new char [ nLength + 1]; - for (int i = 0; i < nLength; i++) - pszCopy[i] = tolower (pszKeyword[i]); - pszCopy[nLength] = 0; - - m_strKeyword = pszCopy; - - delete pszCopy; -} - - -bool -KeywordCodeEntry::matchesKeyword (const char* const pszCompare) const -{ - int nLength = strlen (pszCompare); - char* pszCopy = new char [ nLength + 1]; - for (int i = 0; i < nLength; i++) - pszCopy[i] = tolower (pszCompare[i]); - pszCopy[nLength] = 0; - - bool bMatch = false; - if (m_strKeyword.compare (pszCompare) == 0) - bMatch = true; - - delete pszCopy; - - return bMatch; -} - - -// inittable (table) -// clear symbol table - -void -KeywordCodeHashTable::initTable () -{ - int i; - - for (i = 0; i < HASHSIZE; i++) - m_hashTable[i] = NULL; -} - -// freetable (table) -// free all memory allocated to table, then clear table - -void -KeywordCodeHashTable::freeTable () -{ - int i; - KeywordCodeEntry *p, *np; - - for (i = 0; i < HASHSIZE; i++) { - np = m_hashTable [i]; - while (np != NULL) { - p = np->getNext(); - delete np; - np = p; - } - } - initTable (); -} - - -// form hash value of string s -int -KeywordCodeHashTable::hash (const char* s) -{ - int hashval = 0; - - while (*s != EOS) { - hashval += tolower(*s); - s++; - } - - return (hashval % HASHSIZE); -} - - -/* Look for s in hash table */ -KeywordCodeEntry * -KeywordCodeHashTable::lookup (const char* const pszLookup) -{ - KeywordCodeEntry *found = NULL; - for (KeywordCodeEntry* np = m_hashTable[ hash( pszLookup ) ]; np != NULL; np = np->getNext()) - if (np->matchesKeyword (pszLookup)) { - found = np; // found it - break; - } - - return (found); -} - -void -KeywordCodeHashTable::installKeywordCode (const char* const pszKeyword, int iCode) -{ - KeywordCodeEntry *np = lookup (pszKeyword); - - if (np == NULL) { // not found - np = new KeywordCodeEntry (pszKeyword, iCode); - int hashval = hash (np->getKeyword()); - np->setNext (m_hashTable[ hashval ]); - m_hashTable[hashval] = np; - } else // already defined - np->setCode (iCode); -} +/***************************************************************************** +** FILE IDENTIFICATION +** +** Hash Table Class +** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: hashtable.cpp,v 1.2 2001/01/02 16:02:13 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +#include "ct.h" +#include +#include +#include +#include "ctsupport.h" +#include "pol.h" + + +KeywordCodeEntry::KeywordCodeEntry (const char* const pszKeyword, int iCode) + : m_iCode (iCode), m_pNext(NULL) +{ + int nLength = strlen (pszKeyword); + char* pszCopy = new char [ nLength + 1]; + for (int i = 0; i < nLength; i++) + pszCopy[i] = tolower (pszKeyword[i]); + pszCopy[nLength] = 0; + + m_strKeyword = pszCopy; + + delete pszCopy; +} + + +bool +KeywordCodeEntry::matchesKeyword (const char* const pszCompare) const +{ + int nLength = strlen (pszCompare); + char* pszCopy = new char [ nLength + 1]; + for (int i = 0; i < nLength; i++) + pszCopy[i] = tolower (pszCompare[i]); + pszCopy[nLength] = 0; + + bool bMatch = false; + if (m_strKeyword.compare (pszCompare) == 0) + bMatch = true; + + delete pszCopy; + + return bMatch; +} + + +// inittable (table) +// clear symbol table + +void +KeywordCodeHashTable::initTable () +{ + int i; + + for (i = 0; i < HASHSIZE; i++) + m_hashTable[i] = NULL; +} + +// freetable (table) +// free all memory allocated to table, then clear table + +void +KeywordCodeHashTable::freeTable () +{ + int i; + KeywordCodeEntry *p, *np; + + for (i = 0; i < HASHSIZE; i++) { + np = m_hashTable [i]; + while (np != NULL) { + p = np->getNext(); + delete np; + np = p; + } + } + initTable (); +} + + +// form hash value of string s +int +KeywordCodeHashTable::hash (const char* s) +{ + int hashval = 0; + + while (*s != EOS) { + hashval += tolower(*s); + s++; + } + + return (hashval % HASHSIZE); +} + + +/* Look for s in hash table */ +KeywordCodeEntry * +KeywordCodeHashTable::lookup (const char* const pszLookup) +{ + KeywordCodeEntry *found = NULL; + for (KeywordCodeEntry* np = m_hashTable[ hash( pszLookup ) ]; np != NULL; np = np->getNext()) + if (np->matchesKeyword (pszLookup)) { + found = np; // found it + break; + } + + return (found); +} + +void +KeywordCodeHashTable::installKeywordCode (const char* const pszKeyword, int iCode) +{ + KeywordCodeEntry *np = lookup (pszKeyword); + + if (np == NULL) { // not found + np = new KeywordCodeEntry (pszKeyword, iCode); + int hashval = hash (np->getKeyword()); + np->setNext (m_hashTable[ hashval ]); + m_hashTable[hashval] = np; + } else // already defined + np->setCode (iCode); +} diff --git a/libctsupport/mathfuncs.cpp b/libctsupport/mathfuncs.cpp index c9b18ac..c6dd98d 100644 --- a/libctsupport/mathfuncs.cpp +++ b/libctsupport/mathfuncs.cpp @@ -2,7 +2,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: mathfuncs.cpp,v 1.6 2001/01/02 05:34:57 kevin Exp $ +** $Id: mathfuncs.cpp,v 1.7 2001/01/02 16:02:13 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 @@ -81,57 +81,57 @@ normalizeAngle (double theta) return (theta); } - - -void -vectorNumericStatistics (std::vector vec, const int nPoints, double& min, double& max, double& mean, double& mode, double& median, double& stddev) -{ - if (nPoints <= 0) - return; - - mean = 0; - min = vec[0]; - max = vec[0]; - int i; - for (i = 0; i < nPoints; i++) { - double v = vec[i]; - if (v > max) - max = v; - if (v < min) - min = v; - mean += v; - } - mean /= nPoints; - - static const int nbin = 1024; - int hist[ nbin ] = {0}; - double spread = max - min; - mode = 0; - stddev = 0; - for (i = 0; i < nPoints; i++) { - double v = vec[i]; - int b = static_cast((((v - min) / spread) * (nbin - 1)) + 0.5); - hist[b]++; - double diff = (v - mean); - stddev += diff * diff; - } - stddev = sqrt (stddev / nPoints); - - int max_binindex = 0; - int max_bin = -1; - for (int ibin = 0; ibin < nbin; ibin++) { - if (hist[ibin] > max_bin) { - max_bin = hist[ibin]; - max_binindex = ibin; - } - } - - mode = (max_binindex * spread / (nbin - 1)) + min; - - std::sort(vec.begin(), vec.end()); - - if (nPoints % 2) // Odd - median = vec[((nPoints - 1) / 2)]; - else // Even - median = (vec[ (nPoints / 2) - 1 ] + vec[ nPoints / 2 ]) / 2; -} + + +void +vectorNumericStatistics (std::vector vec, const int nPoints, double& min, double& max, double& mean, double& mode, double& median, double& stddev) +{ + if (nPoints <= 0) + return; + + mean = 0; + min = vec[0]; + max = vec[0]; + int i; + for (i = 0; i < nPoints; i++) { + double v = vec[i]; + if (v > max) + max = v; + if (v < min) + min = v; + mean += v; + } + mean /= nPoints; + + static const int nbin = 1024; + int hist[ nbin ] = {0}; + double spread = max - min; + mode = 0; + stddev = 0; + for (i = 0; i < nPoints; i++) { + double v = vec[i]; + int b = static_cast((((v - min) / spread) * (nbin - 1)) + 0.5); + hist[b]++; + double diff = (v - mean); + stddev += diff * diff; + } + stddev = sqrt (stddev / nPoints); + + int max_binindex = 0; + int max_bin = -1; + for (int ibin = 0; ibin < nbin; ibin++) { + if (hist[ibin] > max_bin) { + max_bin = hist[ibin]; + max_binindex = ibin; + } + } + + mode = (max_binindex * spread / (nbin - 1)) + min; + + std::sort(vec.begin(), vec.end()); + + if (nPoints % 2) // Odd + median = vec[((nPoints - 1) / 2)]; + else // Even + median = (vec[ (nPoints / 2) - 1 ] + vec[ nPoints / 2 ]) / 2; +} diff --git a/libctsupport/msvc.cpp b/libctsupport/msvc.cpp index 99e1caa..3cdfabd 100644 --- a/libctsupport/msvc.cpp +++ b/libctsupport/msvc.cpp @@ -5,4 +5,4 @@ const fpos_t std::_Fpz = 0; #endif - + diff --git a/libctsupport/plotfile.cpp b/libctsupport/plotfile.cpp index be54e56..b7e1d57 100644 --- a/libctsupport/plotfile.cpp +++ b/libctsupport/plotfile.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: plotfile.cpp,v 1.9 2001/01/02 07:47:36 kevin Exp $ +** $Id: plotfile.cpp,v 1.10 2001/01/02 16:02:13 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 @@ -40,7 +40,7 @@ PlotFile::PlotFile (int nCurves, int nRecords) { initHeaders (); - setCurveSize (nCurves, nRecords); + setCurveSize (nCurves, nRecords); } PlotFile::PlotFile () @@ -57,9 +57,9 @@ PlotFile::initHeaders () { m_iNumColumns = 0; m_iNumRecords = 0; - time_t currentTime = time (NULL); - m_strDate = ctime (¤tTime); - m_vecStrDescriptions.clear(); + time_t currentTime = time (NULL); + m_strDate = ctime (¤tTime); + m_vecStrDescriptions.clear(); m_vecStrEzsetCommands.clear(); } @@ -71,9 +71,9 @@ PlotFile::setCurveSize (int nCols, int nRecords) m_vecCurves.clear(); m_vecCurves.reserve (m_iNumColumns * m_iNumRecords); } - -// Storage format -// a Column's records are stored sequentially. It begins at iCol * m_iNumRecords + +// Storage format +// a Column's records are stored sequentially. It begins at iCol * m_iNumRecords bool PlotFile::addColumn (int iCol, const double* const pdColData) @@ -89,83 +89,83 @@ PlotFile::addColumn (int iCol, const double* const pdColData) return true; } -bool -PlotFile::addColumn (int iCol, const float* const pdColData) -{ - if (iCol < 0 || iCol >= m_iNumColumns) { - sys_error (ERR_SEVERE, "Illegal column number %d [PlotFile::addColumn]", iCol); - return (false); - } - - for (int iRec = 0; iRec < m_iNumRecords; iRec++) - m_vecCurves[ iRec + (iCol * m_iNumRecords) ] = pdColData [iRec]; - - return true; -} - -void -PlotFile::getColumn (int iCol, double* pdColData) const -{ - if (iCol < 0 || iCol >= m_iNumColumns) { - sys_error (ERR_SEVERE, "Illegal column number %d [PlotFile::addColumn]", iCol); - return; - } - - for (int iRec = 0; iRec < m_iNumRecords; iRec++) - pdColData[iRec] = m_vecCurves[ iRec + (iCol * m_iNumRecords) ]; - -} - -bool -PlotFile::getMinMax (int iStartingCol, double& dMin, double& dMax) const -{ - if (iStartingCol >= m_iNumColumns) { - sys_error (ERR_WARNING, "iStartingCol >= iNumColumns"); - return false; - } - - int iOffset = iStartingCol * m_iNumRecords; - dMin = m_vecCurves[ 0 + iOffset ]; - dMax = dMin; - - for (int iCol = iStartingCol; iCol < m_iNumColumns; iCol++) { - int iOffset = iCol * m_iNumRecords; - for (int iRec = 0; iRec < m_iNumRecords; iRec++) { - double dVal = m_vecCurves[ iRec + iOffset ]; - if (dVal < dMin) - dMin = dVal; - else if (dVal > dMax) - dMax = dVal; - } - } - - return true; -} - -bool -PlotFile::statistics (int iStartingCol, double& min, double& max, double& mean, double& mode, double& median, double &stddev) const -{ - if (iStartingCol >= m_iNumColumns) { - sys_error (ERR_WARNING, "iStartingCol >= iNumColumns"); - return false; - } - - int iNPoints = (m_iNumColumns - iStartingCol) * m_iNumRecords; - std::vector vec; - vec.resize (iNPoints); - - int iVec = 0; - for (int iCol = iStartingCol; iCol < m_iNumColumns; iCol++) { - int iOffset = iCol * m_iNumRecords; - for (int iRec = 0; iRec < m_iNumRecords; iRec++) - vec[iVec++] = m_vecCurves[ iRec + iOffset ]; - } - - vectorNumericStatistics (vec, iNPoints, min, max, mean, mode, median, stddev); - - return true; -} - +bool +PlotFile::addColumn (int iCol, const float* const pdColData) +{ + if (iCol < 0 || iCol >= m_iNumColumns) { + sys_error (ERR_SEVERE, "Illegal column number %d [PlotFile::addColumn]", iCol); + return (false); + } + + for (int iRec = 0; iRec < m_iNumRecords; iRec++) + m_vecCurves[ iRec + (iCol * m_iNumRecords) ] = pdColData [iRec]; + + return true; +} + +void +PlotFile::getColumn (int iCol, double* pdColData) const +{ + if (iCol < 0 || iCol >= m_iNumColumns) { + sys_error (ERR_SEVERE, "Illegal column number %d [PlotFile::addColumn]", iCol); + return; + } + + for (int iRec = 0; iRec < m_iNumRecords; iRec++) + pdColData[iRec] = m_vecCurves[ iRec + (iCol * m_iNumRecords) ]; + +} + +bool +PlotFile::getMinMax (int iStartingCol, double& dMin, double& dMax) const +{ + if (iStartingCol >= m_iNumColumns) { + sys_error (ERR_WARNING, "iStartingCol >= iNumColumns"); + return false; + } + + int iOffset = iStartingCol * m_iNumRecords; + dMin = m_vecCurves[ 0 + iOffset ]; + dMax = dMin; + + for (int iCol = iStartingCol; iCol < m_iNumColumns; iCol++) { + int iOffset = iCol * m_iNumRecords; + for (int iRec = 0; iRec < m_iNumRecords; iRec++) { + double dVal = m_vecCurves[ iRec + iOffset ]; + if (dVal < dMin) + dMin = dVal; + else if (dVal > dMax) + dMax = dVal; + } + } + + return true; +} + +bool +PlotFile::statistics (int iStartingCol, double& min, double& max, double& mean, double& mode, double& median, double &stddev) const +{ + if (iStartingCol >= m_iNumColumns) { + sys_error (ERR_WARNING, "iStartingCol >= iNumColumns"); + return false; + } + + int iNPoints = (m_iNumColumns - iStartingCol) * m_iNumRecords; + std::vector vec; + vec.resize (iNPoints); + + int iVec = 0; + for (int iCol = iStartingCol; iCol < m_iNumColumns; iCol++) { + int iOffset = iCol * m_iNumRecords; + for (int iRec = 0; iRec < m_iNumRecords; iRec++) + vec[iVec++] = m_vecCurves[ iRec + iOffset ]; + } + + vectorNumericStatistics (vec, iNPoints, min, max, mean, mode, median, stddev); + + return true; +} + bool PlotFile::fileWrite (const char* const filename) { @@ -218,37 +218,37 @@ PlotFile::headerRead (std::iostream& fs) return false; } - initHeaders(); - fs.seekg (0); - bool bFinishedHeaders = false; - - fs >> m_iNumColumns; - fs >> m_iNumRecords; - - if (fs.fail() || m_iNumColumns == 0 || m_iNumRecords == 0) - return false; - - while (! bFinishedHeaders && ! fs.eof() && ! fs.fail()) { - char line[1024]; - fs.getline (line, sizeof(line)); - int iSP = 0; - while (line[iSP] == ' ') - iSP++; - if (line[iSP] == '\n' || ! line[iSP]) - ; - else if (line[iSP] == '#') { - iSP++; - while (line[iSP] == ' ') - iSP++; - if (line[iSP] == '\n' || ! line[iSP]) - ; - else - addDescription (&line[iSP]); - } else if (strstr (&line[iSP], "") != NULL) { - bFinishedHeaders = true; - } else - addEzsetCommand (&line[iSP]); - } + initHeaders(); + fs.seekg (0); + bool bFinishedHeaders = false; + + fs >> m_iNumColumns; + fs >> m_iNumRecords; + + if (fs.fail() || m_iNumColumns == 0 || m_iNumRecords == 0) + return false; + + while (! bFinishedHeaders && ! fs.eof() && ! fs.fail()) { + char line[1024]; + fs.getline (line, sizeof(line)); + int iSP = 0; + while (line[iSP] == ' ') + iSP++; + if (line[iSP] == '\n' || ! line[iSP]) + ; + else if (line[iSP] == '#') { + iSP++; + while (line[iSP] == ' ') + iSP++; + if (line[iSP] == '\n' || ! line[iSP]) + ; + else + addDescription (&line[iSP]); + } else if (strstr (&line[iSP], "") != NULL) { + bFinishedHeaders = true; + } else + addEzsetCommand (&line[iSP]); + } return ! fs.fail(); } @@ -263,15 +263,15 @@ PlotFile::headerWrite (std::iostream& fs) } fs.seekp (0); - fs << m_iNumColumns << " " << m_iNumRecords << "\n"; - + fs << m_iNumColumns << " " << m_iNumRecords << "\n"; + unsigned int i; - for (i = 0; i < m_vecStrEzsetCommands.size(); i++) - fs << m_vecStrEzsetCommands[i] << "\n"; - - for (i = 0; i < m_vecStrDescriptions.size(); i++) - fs << "# " << m_vecStrDescriptions[i] << "\n"; - + for (i = 0; i < m_vecStrEzsetCommands.size(); i++) + fs << m_vecStrEzsetCommands[i] << "\n"; + + for (i = 0; i < m_vecStrDescriptions.size(); i++) + fs << "# " << m_vecStrDescriptions[i] << "\n"; + if (! m_strDate.empty()) fs << "# Date: " << m_strDate << "\n"; @@ -297,8 +297,8 @@ PlotFile::columnsWrite (std::iostream& fs) } fs << "\n"; - - fs << "\n"; + + fs << "\n"; return ! fs.fail(); } @@ -316,21 +316,21 @@ PlotFile::columnsRead (std::iostream& fs) sys_error (ERR_WARNING, "Called PlotFile::columnsRead with 0 columns or records"); return false; } - - bool bTerminateEarly = false; - for (int iRec = 0; iRec < m_iNumRecords; iRec++) { - for (int iCol = 0; iCol < m_iNumColumns; iCol++) { - if (fs.eof()) { - bTerminateEarly = true; - break; - } - if (fs.fail()) - break; - double d; - fs >> d; - m_vecCurves[ iRec + (iCol * m_iNumRecords) ] = d; - } - } + + bool bTerminateEarly = false; + for (int iRec = 0; iRec < m_iNumRecords; iRec++) { + for (int iCol = 0; iCol < m_iNumColumns; iCol++) { + if (fs.eof()) { + bTerminateEarly = true; + break; + } + if (fs.fail()) + break; + double d; + fs >> d; + m_vecCurves[ iRec + (iCol * m_iNumRecords) ] = d; + } + } return ! (bTerminateEarly || fs.fail()); } @@ -338,24 +338,24 @@ PlotFile::columnsRead (std::iostream& fs) void PlotFile::printHeaders (std::ostream& os) const -{ - os << "EZSet Commands\n"; - for (unsigned int iEZ = 0; iEZ < m_vecStrEzsetCommands.size(); iEZ++) - os << m_vecStrEzsetCommands[iEZ] << "\n"; - - os << "Descriptions\n"; - for (unsigned int iDesc = 0; iDesc < m_vecStrDescriptions.size(); iDesc++) +{ + os << "EZSet Commands\n"; + for (unsigned int iEZ = 0; iEZ < m_vecStrEzsetCommands.size(); iEZ++) + os << m_vecStrEzsetCommands[iEZ] << "\n"; + + os << "Descriptions\n"; + for (unsigned int iDesc = 0; iDesc < m_vecStrDescriptions.size(); iDesc++) os << m_vecStrDescriptions[iDesc] << "\n"; } void PlotFile::printHeaders (std::ostringstream& os) const -{ - os << "EZSet Commands\n"; - for (unsigned int iEZ = 0; iEZ < m_vecStrEzsetCommands.size(); iEZ++) - os << m_vecStrEzsetCommands[iEZ] << "\n"; - - os << "Descriptions\n"; - for (unsigned int iDesc = 0; iDesc < m_vecStrDescriptions.size(); iDesc++) +{ + os << "EZSet Commands\n"; + for (unsigned int iEZ = 0; iEZ < m_vecStrEzsetCommands.size(); iEZ++) + os << m_vecStrEzsetCommands[iEZ] << "\n"; + + os << "Descriptions\n"; + for (unsigned int iDesc = 0; iDesc < m_vecStrDescriptions.size(); iDesc++) os << m_vecStrDescriptions[iDesc] << "\n"; } diff --git a/libctsupport/syserror.cpp b/libctsupport/syserror.cpp index 679ecb4..f87b82e 100644 --- a/libctsupport/syserror.cpp +++ b/libctsupport/syserror.cpp @@ -2,7 +2,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: syserror.cpp,v 1.11 2000/12/29 20:11:42 kevin Exp $ +** $Id: syserror.cpp,v 1.12 2001/01/02 16:02:13 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 @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include "ct.h" @@ -39,7 +39,7 @@ */ static int s_reportErrorLevel = ERR_WARNING; // Set error reporting level - + bool g_bRunningWXWindows = false; void sys_error (int severity, const char *msg, ...) @@ -47,14 +47,14 @@ void sys_error (int severity, const char *msg, ...) va_list arg; va_start(arg, msg); - + std::string strOutput; sys_verror (strOutput, severity, msg, arg); - -// if (g_bRunningWXWindows) -// theApp->getLog() << strOutput.c_str(); -// else - std::cout << strOutput; + +// if (g_bRunningWXWindows) +// theApp->getLog() << strOutput.c_str(); +// else + std::cout << strOutput; va_end(arg); } @@ -68,9 +68,9 @@ void sys_verror (std::string& strOutput, int severity, const char *msg, va_list if (severity < s_reportErrorLevel) return; // ignore error if less than reporting level - std::ostringstream os; + std::ostringstream os; - s_nErrorCount++; + s_nErrorCount++; if (severity != ERR_FATAL) { if (s_nErrorCount > MAX_ERROR_COUNT) return; @@ -79,7 +79,7 @@ void sys_verror (std::string& strOutput, int severity, const char *msg, va_list os << "*** M A X I M U M E R R O R C O U N T R E A C H E D ***\n"; os << "*** ***\n"; os << "*** No further errors will be reported ***\n"; - os << "*****************************************************************\n"; + os << "*****************************************************************\n"; strOutput = os.str(); return; } @@ -94,26 +94,26 @@ void sys_verror (std::string& strOutput, int severity, const char *msg, va_list break; case ERR_WARNING: os << "WARNING ERROR: "; - break; - case ERR_TRACE: - os << "Trace: "; + break; + case ERR_TRACE: + os << "Trace: "; break; default: os << "Illegal error severity #" << severity << ": "; } - char errStr[2000]; + char errStr[2000]; #if HAVE_VSNPRINTF vsnprintf (errStr, sizeof(errStr), msg, arg); #elif HAVE_VSPRINTF - vsprintf (errStr, msg, arg); -#else + vsprintf (errStr, msg, arg); +#else strncpy (errStr, sizeof(errStr), "Error message not available on this platform."); #endif os << errStr << "\n"; - strOutput = os.str(); + strOutput = os.str(); if (severity == ERR_FATAL) throw std::runtime_error (errStr); @@ -160,7 +160,7 @@ sys_error_level (int severity) { if (severity == ERR_FATAL || severity == ERR_SEVERE || - severity == ERR_WARNING || + severity == ERR_WARNING || severity == ERR_TRACE) s_reportErrorLevel = severity; else diff --git a/libctsupport/xform.cpp b/libctsupport/xform.cpp index 219eb9b..f50832e 100644 --- a/libctsupport/xform.cpp +++ b/libctsupport/xform.cpp @@ -2,7 +2,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: xform.cpp,v 1.4 2000/12/04 04:44:03 kevin Exp $ +** $Id: xform.cpp,v 1.5 2001/01/02 16:02:13 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 @@ -131,9 +131,9 @@ mult_mtx2 (const GRFMTX_2D m1, const GRFMTX_2D m2, GRFMTX_2D result) temp[row][col] = 0; for (int calc = 0; calc < 3; calc++) temp[row][col] += m1[row][calc] * m2[calc][col]; - } - } - + } + } + for (int r = 0; r < 3; r++) for (int col = 0; col < 3; col++) result[r][col] = temp[r][col]; diff --git a/src/ctsim.cpp b/src/ctsim.cpp index 439ae4f..fb835ad 100644 --- a/src/ctsim.cpp +++ b/src/ctsim.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ctsim.cpp,v 1.24 2001/01/02 05:34:57 kevin Exp $ +** $Id: ctsim.cpp,v 1.25 2001/01/02 16:02:13 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 @@ -24,44 +24,44 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ - - -// For compilers that support precompilation, includes "wx/wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WX_PRECOMP -#include "wx/wx.h" -#endif - -#if !wxUSE_DOC_VIEW_ARCHITECTURE -#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h! -#endif - -#include "ct.h" + + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +#if !wxUSE_DOC_VIEW_ARCHITECTURE +#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h! +#endif + +#include "ct.h" #include "ctsim.h" #include "docs.h" #include "views.h" #include "dialogs.h" - + #if defined(HAVE_CONFIG_H) #include "config.h" -#endif - +#endif + #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG) -#ifdef MSVC -#define __STDC__ 1 -#endif -#include "getopt.h" -#ifdef MSVC -#undef __STDC__ +#ifdef MSVC +#define __STDC__ 1 +#endif +#include "getopt.h" +#ifdef MSVC +#undef __STDC__ #endif #endif - -static const char* rcsindent = "$Id: ctsim.cpp,v 1.24 2001/01/02 05:34:57 kevin Exp $"; + +static const char* rcsindent = "$Id: ctsim.cpp,v 1.25 2001/01/02 16:02:13 kevin Exp $"; class CTSimApp* theApp = NULL; @@ -103,11 +103,11 @@ CTSimApp::OnInit() switch (c) { case O_VERSION: - std::cout << rcsindent << std::endl; -#ifdef CTSIMVERSION - std::cout << "Version: CTSIMVERSION" << std::endl; -#elif defined(VERSION) - std::cout << "Version: VERSION" << std::endl; + std::cout << rcsindent << std::endl; +#ifdef CTSIMVERSION + std::cout << "Version: CTSIMVERSION" << std::endl; +#elif defined(VERSION) + std::cout << "Version: VERSION" << std::endl; #endif exit(0); case O_HELP: @@ -185,8 +185,8 @@ IMPLEMENT_CLASS(MainFrame, wxDocParentFrame) BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame) EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout) EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents) -EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom) -EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter) +EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom) +EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter) EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit) EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0) EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1) @@ -224,8 +224,8 @@ MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const //// Make a menubar wxMenu *file_menu = new wxMenu; - file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom..."); - file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter..."); + file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom..."); + file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter..."); file_menu->Append(wxID_OPEN, "&Open..."); file_menu->AppendSeparator(); @@ -255,107 +255,107 @@ MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const m_pWindowMenu->Append (m_apWindowMenuItems[i]); m_pWindowMenu->Enable (MAINMENU_WINDOW_BASE+i, false); } - - m_iDefaultPhantomID = Phantom::PHM_HERMAN; - m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT; - m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY; - m_iDefaultFilterXSize = 256; - m_iDefaultFilterYSize = 256; - m_dDefaultFilterParam = 1.; - m_dDefaultFilterBandwidth = 1.; - m_dDefaultFilterInputScale = 1.; - m_dDefaultFilterOutputScale = 1.; - + + m_iDefaultPhantomID = Phantom::PHM_HERMAN; + m_iDefaultFilterID = SignalFilter::FILTER_BANDLIMIT; + m_iDefaultFilterDomainID = SignalFilter::DOMAIN_FREQUENCY; + m_iDefaultFilterXSize = 256; + m_iDefaultFilterYSize = 256; + m_dDefaultFilterParam = 1.; + m_dDefaultFilterBandwidth = 1.; + m_dDefaultFilterInputScale = 1.; + m_dDefaultFilterOutputScale = 1.; + } void MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) -{ - wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n"; -#ifdef CTSIMVERSION - msg += "Version "; - msg += CTSIMVERSION; - msg += "\n\n"; -#elif defined(VERSION) - msg << "Version: " << VERSION << "\n\n"; -#endif - msg += "Author: Kevin Rosenberg \nUsage: ctsim [files-to-open..] [--help]"; +{ + wxString msg = "CTSim\nThe Open Source Computed Tomography Simulator\n"; +#ifdef CTSIMVERSION + msg += "Version "; + msg += CTSIMVERSION; + msg += "\n\n"; +#elif defined(VERSION) + msg << "Version: " << VERSION << "\n\n"; +#endif + msg += "Author: Kevin Rosenberg \nUsage: ctsim [files-to-open..] [--help]"; wxMessageBox(msg, "About CTSim", wxOK | wxICON_INFORMATION, this); } - -void -MainFrame::OnCreatePhantom(wxCommandEvent& WXUNUSED(event)) -{ - DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID); - int dialogReturn = dialogPhantom.ShowModal(); - if (dialogReturn == wxID_OK) { - wxString selection (dialogPhantom.getPhantom()); - *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n"; - wxString filename = selection + ".phm"; - m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str()); - theApp->getDocManager()->CreateDocument(filename, wxDOC_SILENT); - } - -} - -void -MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event)) -{ - DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale); - int dialogReturn = dialogFilter.ShowModal(); - if (dialogReturn == wxID_OK) { - wxString strFilter (dialogFilter.getFilterName()); - wxString strDomain (dialogFilter.getDomainName()); - m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str()); - m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str()); - m_iDefaultFilterXSize = dialogFilter.getXSize(); - m_iDefaultFilterYSize = dialogFilter.getYSize(); - m_dDefaultFilterBandwidth = dialogFilter.getBandwidth(); - m_dDefaultFilterParam= dialogFilter.getFilterParam(); - m_dDefaultFilterInputScale = dialogFilter.getInputScale(); - m_dDefaultFilterOutputScale = dialogFilter.getOutputScale(); - std::ostringstream os; - os << "Generate Filter=" << strFilter.c_str() - << ", size=(" << static_cast(m_iDefaultFilterXSize) << "," << static_cast(m_iDefaultFilterYSize) - << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth - << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale; - *theApp->getLog() << os.str().c_str() << "\n"; - wxString filename = "untitled.if"; - ImageFileDocument* pFilterDoc = dynamic_cast(theApp->getDocManager()->CreateDocument ("untitled.if", wxDOC_SILENT)); - if (! pFilterDoc) { - sys_error (ERR_SEVERE, "Unable to create filter image"); - return; - } - ImageFile& rIF = pFilterDoc->getImageFile(); - rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize); - rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale); - rIF.labelAdd (os.str().c_str()); - if (theApp->getSetModifyNewDocs()) - pFilterDoc->Modify (true); - pFilterDoc->UpdateAllViews(); - pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL); - } -} - -void -CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector& vecIF) -{ - const ImageFile& rIF = pIFDoc->getImageFile(); - unsigned int nx = rIF.nx(); - unsigned int ny = rIF.ny(); - wxList& rListDocs = m_docManager->GetDocuments(); - for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) { - wxDocument* pDoc = reinterpret_cast(pNode->GetData()); - ImageFileDocument* pIFCompareDoc = dynamic_cast(pDoc); - if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) { - const ImageFile& rCompareIF = pIFCompareDoc->getImageFile(); - if (rCompareIF.nx() == nx && rCompareIF.ny() == ny) - vecIF.push_back (pIFCompareDoc); - } - } -} - + +void +MainFrame::OnCreatePhantom(wxCommandEvent& WXUNUSED(event)) +{ + DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID); + int dialogReturn = dialogPhantom.ShowModal(); + if (dialogReturn == wxID_OK) { + wxString selection (dialogPhantom.getPhantom()); + *theApp->getLog() << "Selected phantom " << selection.c_str() << "\n"; + wxString filename = selection + ".phm"; + m_iDefaultPhantomID = Phantom::convertNameToPhantomID (selection.c_str()); + theApp->getDocManager()->CreateDocument(filename, wxDOC_SILENT); + } + +} + +void +MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event)) +{ + DialogGetFilterParameters dialogFilter (this, m_iDefaultFilterXSize, m_iDefaultFilterYSize, m_iDefaultFilterID, m_dDefaultFilterParam, m_dDefaultFilterBandwidth, m_iDefaultFilterDomainID, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale); + int dialogReturn = dialogFilter.ShowModal(); + if (dialogReturn == wxID_OK) { + wxString strFilter (dialogFilter.getFilterName()); + wxString strDomain (dialogFilter.getDomainName()); + m_iDefaultFilterID = SignalFilter::convertFilterNameToID (strFilter.c_str()); + m_iDefaultFilterDomainID = SignalFilter::convertDomainNameToID (strDomain.c_str()); + m_iDefaultFilterXSize = dialogFilter.getXSize(); + m_iDefaultFilterYSize = dialogFilter.getYSize(); + m_dDefaultFilterBandwidth = dialogFilter.getBandwidth(); + m_dDefaultFilterParam= dialogFilter.getFilterParam(); + m_dDefaultFilterInputScale = dialogFilter.getInputScale(); + m_dDefaultFilterOutputScale = dialogFilter.getOutputScale(); + std::ostringstream os; + os << "Generate Filter=" << strFilter.c_str() + << ", size=(" << static_cast(m_iDefaultFilterXSize) << "," << static_cast(m_iDefaultFilterYSize) + << "), domain=" << strDomain.c_str() << ", filterParam=" << m_dDefaultFilterParam << ", bandwidth=" << m_dDefaultFilterBandwidth + << ", inputScale=" << m_dDefaultFilterInputScale << ", outputScale=" << m_dDefaultFilterOutputScale; + *theApp->getLog() << os.str().c_str() << "\n"; + wxString filename = "untitled.if"; + ImageFileDocument* pFilterDoc = dynamic_cast(theApp->getDocManager()->CreateDocument ("untitled.if", wxDOC_SILENT)); + if (! pFilterDoc) { + sys_error (ERR_SEVERE, "Unable to create filter image"); + return; + } + ImageFile& rIF = pFilterDoc->getImageFile(); + rIF.setArraySize (m_iDefaultFilterXSize, m_iDefaultFilterYSize); + rIF.filterResponse (strDomain.c_str(), m_dDefaultFilterBandwidth, strFilter.c_str(), m_dDefaultFilterParam, m_dDefaultFilterInputScale, m_dDefaultFilterOutputScale); + rIF.labelAdd (os.str().c_str()); + if (theApp->getSetModifyNewDocs()) + pFilterDoc->Modify (true); + pFilterDoc->UpdateAllViews(); + pFilterDoc->GetFirstView()->OnUpdate (NULL, NULL); + } +} + +void +CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector& vecIF) +{ + const ImageFile& rIF = pIFDoc->getImageFile(); + unsigned int nx = rIF.nx(); + unsigned int ny = rIF.ny(); + wxList& rListDocs = m_docManager->GetDocuments(); + for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) { + wxDocument* pDoc = reinterpret_cast(pNode->GetData()); + ImageFileDocument* pIFCompareDoc = dynamic_cast(pDoc); + if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) { + const ImageFile& rCompareIF = pIFCompareDoc->getImageFile(); + if (rCompareIF.nx() == nx && rCompareIF.ny() == ny) + vecIF.push_back (pIFCompareDoc); + } + } +} + void MainFrame::OnHelpContents(wxCommandEvent& WXUNUSED(event) ) { diff --git a/src/dialogs.cpp b/src/dialogs.cpp index 4802162..f0ece54 100644 --- a/src/dialogs.cpp +++ b/src/dialogs.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: dialogs.cpp,v 1.23 2001/01/02 05:34:57 kevin Exp $ +** $Id: dialogs.cpp,v 1.24 2001/01/02 16:02:13 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 @@ -48,28 +48,28 @@ #include "wx/sizer.h" #include "dialogs.h" #include "ctsim.h" -#include "ct.h" -//#include "ctsupport.h" +#include "ct.h" +//#include "ctsupport.h" //#include "scanner.h" //#include "phantom.h" //#include "filter.h" //#include "backprojectors.h" -#include "docs.h" -#include "views.h" -#include "imagefile.h" - -#if defined(MSVC) || HAVE_SSTREAM -#include -#else -#include -#endif - - -/////////////////////////////////////////////////////////////////////// -// CLASS IMPLEMENTATION -// StringValueAndTitleListBox -/////////////////////////////////////////////////////////////////////// - +#include "docs.h" +#include "views.h" +#include "imagefile.h" + +#if defined(MSVC) || HAVE_SSTREAM +#include +#else +#include +#endif + + +/////////////////////////////////////////////////////////////////////// +// CLASS IMPLEMENTATION +// StringValueAndTitleListBox +/////////////////////////////////////////////////////////////////////// + StringValueAndTitleListBox::StringValueAndTitleListBox (wxDialog* pParent, int nChoices, const char* aszTitle[], const char* aszValue[]) : wxListBox () { @@ -79,7 +79,7 @@ StringValueAndTitleListBox::StringValueAndTitleListBox (wxDialog* pParent, int n Create (pParent, -1, wxDefaultPosition, wxSize(200,-1), nChoices, psTitle, wxLB_SINGLE | wxLB_NEEDED_SB); - m_ppszValues = aszValue; + m_ppszValues = aszValue; delete [] psTitle; }; @@ -90,10 +90,10 @@ StringValueAndTitleListBox::getSelectionStringValue (void) const } -/////////////////////////////////////////////////////////////////////// -// CLASS IMPLEMENTATION -// DialogGetPhantom -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// +// CLASS IMPLEMENTATION +// DialogGetPhantom +/////////////////////////////////////////////////////////////////////// DialogGetPhantom::DialogGetPhantom (wxFrame* pParent, int iDefaultPhantom) : wxDialog (pParent, -1, "Select Phantom", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) @@ -130,77 +130,77 @@ DialogGetPhantom::getPhantom(void) return m_pListBoxPhantom->getSelectionStringValue(); } - -/////////////////////////////////////////////////////////////////////// -// CLASS IMPLEMENTATION -// DialogGetComparisonImage -/////////////////////////////////////////////////////////////////////// - -DialogGetComparisonImage::DialogGetComparisonImage (wxFrame* pParent, const char* const pszTitle, const std::vector& rVecIF, bool bShowMakeDifference) -: wxDialog (pParent, -1, pszTitle, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION), m_rVecIF(rVecIF) -{ - wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); - - pTopSizer->Add (new wxStaticText (this, -1, pszTitle), 0, wxALIGN_CENTER | wxALL, 5); - - pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxALL, 5); - - int iNImages = m_rVecIF.size(); - wxString* pstrImages = new wxString [iNImages]; - for (int i = 0; i < iNImages; i++) { - ImageFileView* pView = dynamic_cast(m_rVecIF[i]->GetFirstView()); - if (pView) - pstrImages[i] = pView->getFrame()->GetTitle(); - } - - m_pListBoxImageChoices = new wxListBox (this, -1, wxDefaultPosition, wxDefaultSize, iNImages, pstrImages, wxLB_SINGLE); - delete [] pstrImages; - - m_pListBoxImageChoices->SetSelection (0); - pTopSizer->Add (m_pListBoxImageChoices, 0, wxALL | wxALIGN_CENTER | wxEXPAND); - - if (bShowMakeDifference) { - m_pMakeDifferenceImage = new wxCheckBox (this, -1, "Make Difference Image"); - m_pMakeDifferenceImage->SetValue (FALSE); - pTopSizer->Add (m_pMakeDifferenceImage, 0, wxALL | wxALIGN_CENTER | wxEXPAND); - } else - m_pMakeDifferenceImage = NULL; - - pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); - - wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); - wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay"); - wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel"); - pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10); - pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10); - - pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER); - - SetAutoLayout (true); - SetSizer (pTopSizer); - pTopSizer->Fit (this); - pTopSizer->SetSizeHints (this); -} - -ImageFileDocument* -DialogGetComparisonImage::getImageFileDocument(void) -{ - return m_rVecIF[ m_pListBoxImageChoices->GetSelection() ]; -} - -bool -DialogGetComparisonImage::getMakeDifferenceImage() -{ - if (m_pMakeDifferenceImage) - return m_pMakeDifferenceImage->GetValue(); - else - return false; -} - - -///////////////////////////////////////////////////////////////////// -// CLASS DiaglogGetMinMax Implementation -///////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////// +// CLASS IMPLEMENTATION +// DialogGetComparisonImage +/////////////////////////////////////////////////////////////////////// + +DialogGetComparisonImage::DialogGetComparisonImage (wxFrame* pParent, const char* const pszTitle, const std::vector& rVecIF, bool bShowMakeDifference) +: wxDialog (pParent, -1, pszTitle, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION), m_rVecIF(rVecIF) +{ + wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); + + pTopSizer->Add (new wxStaticText (this, -1, pszTitle), 0, wxALIGN_CENTER | wxALL, 5); + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxALL, 5); + + int iNImages = m_rVecIF.size(); + wxString* pstrImages = new wxString [iNImages]; + for (int i = 0; i < iNImages; i++) { + ImageFileView* pView = dynamic_cast(m_rVecIF[i]->GetFirstView()); + if (pView) + pstrImages[i] = pView->getFrame()->GetTitle(); + } + + m_pListBoxImageChoices = new wxListBox (this, -1, wxDefaultPosition, wxDefaultSize, iNImages, pstrImages, wxLB_SINGLE); + delete [] pstrImages; + + m_pListBoxImageChoices->SetSelection (0); + pTopSizer->Add (m_pListBoxImageChoices, 0, wxALL | wxALIGN_CENTER | wxEXPAND); + + if (bShowMakeDifference) { + m_pMakeDifferenceImage = new wxCheckBox (this, -1, "Make Difference Image"); + m_pMakeDifferenceImage->SetValue (FALSE); + pTopSizer->Add (m_pMakeDifferenceImage, 0, wxALL | wxALIGN_CENTER | wxEXPAND); + } else + m_pMakeDifferenceImage = NULL; + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); + + wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); + wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay"); + wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel"); + pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10); + pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10); + + pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER); + + SetAutoLayout (true); + SetSizer (pTopSizer); + pTopSizer->Fit (this); + pTopSizer->SetSizeHints (this); +} + +ImageFileDocument* +DialogGetComparisonImage::getImageFileDocument(void) +{ + return m_rVecIF[ m_pListBoxImageChoices->GetSelection() ]; +} + +bool +DialogGetComparisonImage::getMakeDifferenceImage() +{ + if (m_pMakeDifferenceImage) + return m_pMakeDifferenceImage->GetValue(); + else + return false; +} + + +///////////////////////////////////////////////////////////////////// +// CLASS DiaglogGetMinMax Implementation +///////////////////////////////////////////////////////////////////// DialogGetMinMax::DialogGetMinMax (wxFrame* pParent, const char* const pszTitle, double dDefaultMin, double dDefaultMax) : wxDialog (pParent, -1, pszTitle, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) @@ -268,89 +268,89 @@ DialogGetMinMax::getMaximum (void) } -///////////////////////////////////////////////////////////////////// -// CLASS DialogAutoScaleParameters IMPLEMENTATION -///////////////////////////////////////////////////////////////////// - -DialogAutoScaleParameters::DialogAutoScaleParameters (wxFrame *pParent, double mean, double mode, double median, double stddev, double dDefaultScaleFactor) -: wxDialog (pParent, -1, "Auto Scale Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION), m_dMean(mean), m_dMode(mode), m_dMedian(median), m_dStdDev(stddev) -{ - wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); - - pTopSizer->Add (new wxStaticText (this, -1, "Auto Scale Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5); - - pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); - - wxString asTitle[3]; - asTitle[0] = "Median"; - asTitle[1] = "Mode"; - asTitle[2] = "Mean"; - - m_pListBoxCenter = new wxListBox (this, -1, wxDefaultPosition, wxDefaultSize, 3, asTitle, wxLB_SINGLE | wxLB_NEEDED_SB); - m_pListBoxCenter->SetSelection (0); - pTopSizer->Add (m_pListBoxCenter, 0, wxALL | wxALIGN_CENTER | wxEXPAND); - - wxGridSizer *pGridSizer = new wxGridSizer (2); - pGridSizer->Add (new wxStaticText (this, -1, "Standard Deviation Factor"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - std::ostringstream osDefaultFactor; - osDefaultFactor << dDefaultScaleFactor; - m_pTextCtrlStdDevFactor = new wxTextCtrl (this, -1, osDefaultFactor.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); - pGridSizer->Add (m_pTextCtrlStdDevFactor, 0, wxALIGN_CENTER_VERTICAL); - pTopSizer->Add (pGridSizer, 1, wxALL, 10); - - pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); - - wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); - wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay"); - wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel"); - pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10); - pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10); - - pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER); - - SetAutoLayout (true); - SetSizer (pTopSizer); - pTopSizer->Fit (this); - pTopSizer->SetSizeHints (this); -} - -bool -DialogAutoScaleParameters::getMinMax (double* pMin, double* pMax) -{ - int iCenter = m_pListBoxCenter->GetSelection(); - double dCenter = m_dMedian; - if (iCenter == 1) - dCenter = m_dMode; - else if (iCenter == 2) - dCenter = m_dMode; - - wxString sStddevFactor = m_pTextCtrlStdDevFactor->GetValue(); - double dValue; - if (! sStddevFactor.ToDouble (&dValue)) { - *theApp->getLog() << "Error: Non-numeric Standard Deviation Factor of " << sStddevFactor << "\n"; - return false; - } - double dHalfWidth = dValue * m_dStdDev / 2; - *pMin = dCenter - dHalfWidth; - *pMax = dCenter + dHalfWidth; - *theApp->getLog() << "Setting minimum to " << *pMin << " and maximum to " << *pMax << "\n"; - - return true; -} - -double -DialogAutoScaleParameters::getAutoScaleFactor () -{ - wxString sStddevFactor = m_pTextCtrlStdDevFactor->GetValue(); - double dValue = 1.; - if (! sStddevFactor.ToDouble (&dValue)) { - *theApp->getLog() << "Error: Non-numeric Standard Deviation Factor of " << sStddevFactor << "\n"; - } - - return dValue; -} - - +///////////////////////////////////////////////////////////////////// +// CLASS DialogAutoScaleParameters IMPLEMENTATION +///////////////////////////////////////////////////////////////////// + +DialogAutoScaleParameters::DialogAutoScaleParameters (wxFrame *pParent, double mean, double mode, double median, double stddev, double dDefaultScaleFactor) +: wxDialog (pParent, -1, "Auto Scale Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION), m_dMean(mean), m_dMode(mode), m_dMedian(median), m_dStdDev(stddev) +{ + wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); + + pTopSizer->Add (new wxStaticText (this, -1, "Auto Scale Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5); + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); + + wxString asTitle[3]; + asTitle[0] = "Median"; + asTitle[1] = "Mode"; + asTitle[2] = "Mean"; + + m_pListBoxCenter = new wxListBox (this, -1, wxDefaultPosition, wxDefaultSize, 3, asTitle, wxLB_SINGLE | wxLB_NEEDED_SB); + m_pListBoxCenter->SetSelection (0); + pTopSizer->Add (m_pListBoxCenter, 0, wxALL | wxALIGN_CENTER | wxEXPAND); + + wxGridSizer *pGridSizer = new wxGridSizer (2); + pGridSizer->Add (new wxStaticText (this, -1, "Standard Deviation Factor"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + std::ostringstream osDefaultFactor; + osDefaultFactor << dDefaultScaleFactor; + m_pTextCtrlStdDevFactor = new wxTextCtrl (this, -1, osDefaultFactor.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); + pGridSizer->Add (m_pTextCtrlStdDevFactor, 0, wxALIGN_CENTER_VERTICAL); + pTopSizer->Add (pGridSizer, 1, wxALL, 10); + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); + + wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); + wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay"); + wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel"); + pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10); + pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10); + + pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER); + + SetAutoLayout (true); + SetSizer (pTopSizer); + pTopSizer->Fit (this); + pTopSizer->SetSizeHints (this); +} + +bool +DialogAutoScaleParameters::getMinMax (double* pMin, double* pMax) +{ + int iCenter = m_pListBoxCenter->GetSelection(); + double dCenter = m_dMedian; + if (iCenter == 1) + dCenter = m_dMode; + else if (iCenter == 2) + dCenter = m_dMode; + + wxString sStddevFactor = m_pTextCtrlStdDevFactor->GetValue(); + double dValue; + if (! sStddevFactor.ToDouble (&dValue)) { + *theApp->getLog() << "Error: Non-numeric Standard Deviation Factor of " << sStddevFactor << "\n"; + return false; + } + double dHalfWidth = dValue * m_dStdDev / 2; + *pMin = dCenter - dHalfWidth; + *pMax = dCenter + dHalfWidth; + *theApp->getLog() << "Setting minimum to " << *pMin << " and maximum to " << *pMax << "\n"; + + return true; +} + +double +DialogAutoScaleParameters::getAutoScaleFactor () +{ + wxString sStddevFactor = m_pTextCtrlStdDevFactor->GetValue(); + double dValue = 1.; + if (! sStddevFactor.ToDouble (&dValue)) { + *theApp->getLog() << "Error: Non-numeric Standard Deviation Factor of " << sStddevFactor << "\n"; + } + + return dValue; +} + + ///////////////////////////////////////////////////////////////////// // CLASS IDENTIFICATION // @@ -662,7 +662,7 @@ DialogGetReconstructionParameters::DialogGetReconstructionParameters (wxFrame* p m_pListBoxFilterGeneration->SetSelection (iDefaultFilterGenerationID); pGridSizer->Add (new wxStaticText (this, -1, "Filter Generation"), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); pGridSizer->Add (m_pListBoxFilterGeneration, 0, wxALL | wxALIGN_LEFT | wxEXPAND); - + m_pListBoxBackproject = new StringValueAndTitleListBox (this, Backprojector::getBackprojectCount(), Backprojector::getBackprojectTitleArray(), Backprojector::getBackprojectNameArray()); m_pListBoxBackproject->SetSelection (iDefaultBackprojectID); @@ -675,14 +675,14 @@ DialogGetReconstructionParameters::DialogGetReconstructionParameters (wxFrame* p pGridSizer->Add (m_pListBoxInterp, 0, wxALL | wxALIGN_RIGHT | wxEXPAND); - pGridSizer->Add (new wxStaticText (this, -1, "Trace Level"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - static const char* aszTraceTitle[] = {"None", "Full"}; - static const char* aszTraceName[] = {"none", "full"}; - m_pListBoxTrace = new StringValueAndTitleListBox (this, 2, aszTraceTitle, aszTraceName); - iTrace = clamp(iTrace, 0, 1); - m_pListBoxTrace->SetSelection (iTrace); - pGridSizer->Add (m_pListBoxTrace); - + pGridSizer->Add (new wxStaticText (this, -1, "Trace Level"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + static const char* aszTraceTitle[] = {"None", "Full"}; + static const char* aszTraceName[] = {"none", "full"}; + m_pListBoxTrace = new StringValueAndTitleListBox (this, 2, aszTraceTitle, aszTraceName); + iTrace = clamp(iTrace, 0, 1); + m_pListBoxTrace->SetSelection (iTrace); + pGridSizer->Add (m_pListBoxTrace); + pGridSizer->Add (new wxStaticText (this, -1, "X Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); pGridSizer->Add (m_pTextCtrlXSize, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); pGridSizer->Add (new wxStaticText (this, -1, "Y Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); @@ -813,279 +813,279 @@ DialogGetReconstructionParameters::getFilterGenerationName (void) return m_pListBoxFilterGeneration->getSelectionStringValue(); } - -///////////////////////////////////////////////////////////////////// -// CLASS IDENTIFICATION -// -// DialogGetFilterParameters -///////////////////////////////////////////////////////////////////// - - -DialogGetFilterParameters::DialogGetFilterParameters (wxFrame* pParent, int iDefaultXSize, int iDefaultYSize, int iDefaultFilterID, double dDefaultFilterParam, double dDefaultBandwidth, int iDefaultDomainID, double dDefaultInputScale, double dDefaultOutputScale) -: wxDialog (pParent, -1, "Set Filter Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) -{ - wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); - - pTopSizer->Add (new wxStaticText (this, -1, "Set Filter Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5); - - pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); - - std::ostringstream os; - os << iDefaultXSize; - m_pTextCtrlXSize = new wxTextCtrl (this, -1, os.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); - std::ostringstream osYSize; - osYSize << iDefaultYSize; - m_pTextCtrlYSize = new wxTextCtrl (this, -1, osYSize.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); - std::ostringstream osFilterParam; - osFilterParam << dDefaultFilterParam; - m_pTextCtrlFilterParam = new wxTextCtrl (this, -1, osFilterParam.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); - std::ostringstream osBandwidth; - osBandwidth << dDefaultBandwidth; - m_pTextCtrlBandwidth = new wxTextCtrl (this, -1, osBandwidth.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); - std::ostringstream osInputScale; - osInputScale << dDefaultInputScale; - m_pTextCtrlInputScale = new wxTextCtrl (this, -1, osInputScale.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); - std::ostringstream osOutputScale; - osOutputScale << dDefaultOutputScale; - m_pTextCtrlOutputScale = new wxTextCtrl (this, -1, osOutputScale.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); - - wxFlexGridSizer* pGridSizer = new wxFlexGridSizer (2); - pGridSizer->Add (new wxStaticText (this, -1, "Filter"), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); - m_pListBoxFilter = new StringValueAndTitleListBox (this, SignalFilter::getFilterCount(), SignalFilter::getFilterTitleArray(), SignalFilter::getFilterNameArray()); - m_pListBoxFilter->SetSelection (iDefaultFilterID); - pGridSizer->Add (m_pListBoxFilter, 0, wxALL | wxALIGN_LEFT | wxEXPAND); - - m_pListBoxDomain = new StringValueAndTitleListBox (this, SignalFilter::getDomainCount(), SignalFilter::getDomainTitleArray(), SignalFilter::getDomainNameArray()); - m_pListBoxDomain->SetSelection (iDefaultDomainID); - pGridSizer->Add (new wxStaticText (this, -1, "Domain"), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); - pGridSizer->Add (m_pListBoxDomain, 0, wxALL | wxALIGN_LEFT | wxEXPAND); - - pGridSizer->Add (new wxStaticText (this, -1, "X Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (m_pTextCtrlXSize, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (new wxStaticText (this, -1, "Y Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (m_pTextCtrlYSize, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (new wxStaticText (this, -1, "Filter Parameter"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (m_pTextCtrlFilterParam, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (new wxStaticText (this, -1, "Bandwidth"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (m_pTextCtrlBandwidth, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (new wxStaticText (this, -1, "Axis (input) Scale"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (m_pTextCtrlInputScale, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (new wxStaticText (this, -1, "Filter Output Scale"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (m_pTextCtrlOutputScale, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); - - pTopSizer->Add (pGridSizer, 1, wxALL, 3); - - pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); - - wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); - wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay"); - wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel"); - pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10); - pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10); - - pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER); - - SetAutoLayout (true); - SetSizer (pTopSizer); - pTopSizer->Layout(); - pTopSizer->Fit (this); - pTopSizer->SetSizeHints (this); -} - -DialogGetFilterParameters::~DialogGetFilterParameters (void) -{ -} - - -unsigned int -DialogGetFilterParameters::getXSize (void) -{ - wxString strCtrl = m_pTextCtrlXSize->GetValue(); - unsigned long lValue; - if (strCtrl.ToULong (&lValue)) - return lValue; - else - return (m_iDefaultXSize); -} - -unsigned int -DialogGetFilterParameters::getYSize (void) -{ - wxString strCtrl = m_pTextCtrlYSize->GetValue(); - unsigned long lValue; - if (strCtrl.ToULong (&lValue)) - return lValue; - else - return (m_iDefaultYSize); -} - -double -DialogGetFilterParameters::getBandwidth (void) -{ - wxString strCtrl = m_pTextCtrlBandwidth->GetValue(); - double dValue; - if (strCtrl.ToDouble (&dValue)) - return dValue; - else - return (m_dDefaultBandwidth); -} - -double -DialogGetFilterParameters::getFilterParam (void) -{ - wxString strCtrl = m_pTextCtrlFilterParam->GetValue(); - double dValue; - if (strCtrl.ToDouble (&dValue)) - return (dValue); - else - return (m_dDefaultFilterParam); -} - -double -DialogGetFilterParameters::getInputScale (void) -{ - wxString strCtrl = m_pTextCtrlInputScale->GetValue(); - double dValue; - if (strCtrl.ToDouble (&dValue)) - return dValue; - else - return (m_dDefaultInputScale); -} - -double -DialogGetFilterParameters::getOutputScale (void) -{ - wxString strCtrl = m_pTextCtrlOutputScale->GetValue(); - double dValue; - if (strCtrl.ToDouble (&dValue)) - return dValue; - else - return (m_dDefaultOutputScale); -} - -const char* -DialogGetFilterParameters::getFilterName (void) -{ - return m_pListBoxFilter->getSelectionStringValue(); -} - -const char* -DialogGetFilterParameters::getDomainName (void) -{ - return m_pListBoxDomain->getSelectionStringValue(); -} - - -/////////////////////////////////////////////////////////////////////// -// CLASS IMPLEMENTATION -// DialogExportParameters -/////////////////////////////////////////////////////////////////////// - -DialogExportParameters::DialogExportParameters (wxFrame* pParent, int iDefaultFormatID) -: wxDialog (pParent, -1, "Select ExportParameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) -{ - wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); - - pTopSizer->Add (new wxStaticText (this, -1, "Select Export Format"), 0, wxALIGN_CENTER | wxALL, 5); - - pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxALL, 5); - - m_pListBoxFormat = new StringValueAndTitleListBox (this, ImageFile::getFormatCount(), ImageFile::getFormatTitleArray(), ImageFile::getFormatNameArray()); - m_pListBoxFormat->SetSelection (iDefaultFormatID); - pTopSizer->Add (m_pListBoxFormat, 0, wxALL | wxALIGN_CENTER | wxEXPAND); - - pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); - - wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); - wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay"); - wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel"); - pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10); - pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10); - - pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER); - - SetAutoLayout (true); - SetSizer (pTopSizer); - pTopSizer->Fit (this); - pTopSizer->SetSizeHints (this); -} - -const char* -DialogExportParameters::getFormatName(void) -{ - return m_pListBoxFormat->getSelectionStringValue(); -} - - -///////////////////////////////////////////////////////////////////// -// CLASS DiaglogGetXYSize Implementation -///////////////////////////////////////////////////////////////////// - -DialogGetXYSize::DialogGetXYSize (wxFrame* pParent, const char* const pszTitle, int iDefaultXSize, int iDefaultYSize) -: wxDialog (pParent, -1, pszTitle, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) -{ - m_iDefaultXSize = iDefaultXSize; - m_iDefaultYSize = iDefaultYSize; - - wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); - - pTopSizer->Add (new wxStaticText (this, -1, pszTitle), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5); - - pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); - - std::ostringstream os; - os << iDefaultXSize; - m_pTextCtrlXSize = new wxTextCtrl (this, -1, os.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); - std::ostringstream osYSize; - osYSize << iDefaultYSize; - m_pTextCtrlYSize = new wxTextCtrl (this, -1, osYSize.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); - - wxFlexGridSizer *pGridSizer = new wxFlexGridSizer (2); - pGridSizer->Add (new wxStaticText (this, -1, "X Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (m_pTextCtrlXSize, 0, wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (new wxStaticText (this, -1, "Y Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - pGridSizer->Add (m_pTextCtrlYSize, 0, wxALIGN_CENTER_VERTICAL); - pTopSizer->Add (pGridSizer, 1, wxALL, 10); - - pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); - - wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); - wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay"); - wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel"); - pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10); - pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10); - - pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER); - - SetAutoLayout (true); - SetSizer (pTopSizer); - pTopSizer->Fit (this); - pTopSizer->SetSizeHints (this); -} - -DialogGetXYSize::~DialogGetXYSize (void) -{ -} - -unsigned int -DialogGetXYSize::getXSize (void) -{ - wxString strCtrl = m_pTextCtrlXSize->GetValue(); - long lValue; - if (strCtrl.ToLong (&lValue)) - return lValue; - else - return (m_iDefaultXSize); -} - -unsigned int -DialogGetXYSize::getYSize (void) -{ - wxString strCtrl = m_pTextCtrlYSize->GetValue(); - long lValue; - if (strCtrl.ToLong (&lValue)) - return lValue; - else - return (m_iDefaultYSize); -} - + +///////////////////////////////////////////////////////////////////// +// CLASS IDENTIFICATION +// +// DialogGetFilterParameters +///////////////////////////////////////////////////////////////////// + + +DialogGetFilterParameters::DialogGetFilterParameters (wxFrame* pParent, int iDefaultXSize, int iDefaultYSize, int iDefaultFilterID, double dDefaultFilterParam, double dDefaultBandwidth, int iDefaultDomainID, double dDefaultInputScale, double dDefaultOutputScale) +: wxDialog (pParent, -1, "Set Filter Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) +{ + wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); + + pTopSizer->Add (new wxStaticText (this, -1, "Set Filter Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5); + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); + + std::ostringstream os; + os << iDefaultXSize; + m_pTextCtrlXSize = new wxTextCtrl (this, -1, os.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); + std::ostringstream osYSize; + osYSize << iDefaultYSize; + m_pTextCtrlYSize = new wxTextCtrl (this, -1, osYSize.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); + std::ostringstream osFilterParam; + osFilterParam << dDefaultFilterParam; + m_pTextCtrlFilterParam = new wxTextCtrl (this, -1, osFilterParam.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); + std::ostringstream osBandwidth; + osBandwidth << dDefaultBandwidth; + m_pTextCtrlBandwidth = new wxTextCtrl (this, -1, osBandwidth.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); + std::ostringstream osInputScale; + osInputScale << dDefaultInputScale; + m_pTextCtrlInputScale = new wxTextCtrl (this, -1, osInputScale.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); + std::ostringstream osOutputScale; + osOutputScale << dDefaultOutputScale; + m_pTextCtrlOutputScale = new wxTextCtrl (this, -1, osOutputScale.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); + + wxFlexGridSizer* pGridSizer = new wxFlexGridSizer (2); + pGridSizer->Add (new wxStaticText (this, -1, "Filter"), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); + m_pListBoxFilter = new StringValueAndTitleListBox (this, SignalFilter::getFilterCount(), SignalFilter::getFilterTitleArray(), SignalFilter::getFilterNameArray()); + m_pListBoxFilter->SetSelection (iDefaultFilterID); + pGridSizer->Add (m_pListBoxFilter, 0, wxALL | wxALIGN_LEFT | wxEXPAND); + + m_pListBoxDomain = new StringValueAndTitleListBox (this, SignalFilter::getDomainCount(), SignalFilter::getDomainTitleArray(), SignalFilter::getDomainNameArray()); + m_pListBoxDomain->SetSelection (iDefaultDomainID); + pGridSizer->Add (new wxStaticText (this, -1, "Domain"), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); + pGridSizer->Add (m_pListBoxDomain, 0, wxALL | wxALIGN_LEFT | wxEXPAND); + + pGridSizer->Add (new wxStaticText (this, -1, "X Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (m_pTextCtrlXSize, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (new wxStaticText (this, -1, "Y Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (m_pTextCtrlYSize, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (new wxStaticText (this, -1, "Filter Parameter"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (m_pTextCtrlFilterParam, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (new wxStaticText (this, -1, "Bandwidth"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (m_pTextCtrlBandwidth, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (new wxStaticText (this, -1, "Axis (input) Scale"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (m_pTextCtrlInputScale, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (new wxStaticText (this, -1, "Filter Output Scale"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (m_pTextCtrlOutputScale, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + + pTopSizer->Add (pGridSizer, 1, wxALL, 3); + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); + + wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); + wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay"); + wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel"); + pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10); + pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10); + + pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER); + + SetAutoLayout (true); + SetSizer (pTopSizer); + pTopSizer->Layout(); + pTopSizer->Fit (this); + pTopSizer->SetSizeHints (this); +} + +DialogGetFilterParameters::~DialogGetFilterParameters (void) +{ +} + + +unsigned int +DialogGetFilterParameters::getXSize (void) +{ + wxString strCtrl = m_pTextCtrlXSize->GetValue(); + unsigned long lValue; + if (strCtrl.ToULong (&lValue)) + return lValue; + else + return (m_iDefaultXSize); +} + +unsigned int +DialogGetFilterParameters::getYSize (void) +{ + wxString strCtrl = m_pTextCtrlYSize->GetValue(); + unsigned long lValue; + if (strCtrl.ToULong (&lValue)) + return lValue; + else + return (m_iDefaultYSize); +} + +double +DialogGetFilterParameters::getBandwidth (void) +{ + wxString strCtrl = m_pTextCtrlBandwidth->GetValue(); + double dValue; + if (strCtrl.ToDouble (&dValue)) + return dValue; + else + return (m_dDefaultBandwidth); +} + +double +DialogGetFilterParameters::getFilterParam (void) +{ + wxString strCtrl = m_pTextCtrlFilterParam->GetValue(); + double dValue; + if (strCtrl.ToDouble (&dValue)) + return (dValue); + else + return (m_dDefaultFilterParam); +} + +double +DialogGetFilterParameters::getInputScale (void) +{ + wxString strCtrl = m_pTextCtrlInputScale->GetValue(); + double dValue; + if (strCtrl.ToDouble (&dValue)) + return dValue; + else + return (m_dDefaultInputScale); +} + +double +DialogGetFilterParameters::getOutputScale (void) +{ + wxString strCtrl = m_pTextCtrlOutputScale->GetValue(); + double dValue; + if (strCtrl.ToDouble (&dValue)) + return dValue; + else + return (m_dDefaultOutputScale); +} + +const char* +DialogGetFilterParameters::getFilterName (void) +{ + return m_pListBoxFilter->getSelectionStringValue(); +} + +const char* +DialogGetFilterParameters::getDomainName (void) +{ + return m_pListBoxDomain->getSelectionStringValue(); +} + + +/////////////////////////////////////////////////////////////////////// +// CLASS IMPLEMENTATION +// DialogExportParameters +/////////////////////////////////////////////////////////////////////// + +DialogExportParameters::DialogExportParameters (wxFrame* pParent, int iDefaultFormatID) +: wxDialog (pParent, -1, "Select ExportParameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) +{ + wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); + + pTopSizer->Add (new wxStaticText (this, -1, "Select Export Format"), 0, wxALIGN_CENTER | wxALL, 5); + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxALL, 5); + + m_pListBoxFormat = new StringValueAndTitleListBox (this, ImageFile::getFormatCount(), ImageFile::getFormatTitleArray(), ImageFile::getFormatNameArray()); + m_pListBoxFormat->SetSelection (iDefaultFormatID); + pTopSizer->Add (m_pListBoxFormat, 0, wxALL | wxALIGN_CENTER | wxEXPAND); + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); + + wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); + wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay"); + wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel"); + pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10); + pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10); + + pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER); + + SetAutoLayout (true); + SetSizer (pTopSizer); + pTopSizer->Fit (this); + pTopSizer->SetSizeHints (this); +} + +const char* +DialogExportParameters::getFormatName(void) +{ + return m_pListBoxFormat->getSelectionStringValue(); +} + + +///////////////////////////////////////////////////////////////////// +// CLASS DiaglogGetXYSize Implementation +///////////////////////////////////////////////////////////////////// + +DialogGetXYSize::DialogGetXYSize (wxFrame* pParent, const char* const pszTitle, int iDefaultXSize, int iDefaultYSize) +: wxDialog (pParent, -1, pszTitle, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) +{ + m_iDefaultXSize = iDefaultXSize; + m_iDefaultYSize = iDefaultYSize; + + wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); + + pTopSizer->Add (new wxStaticText (this, -1, pszTitle), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5); + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); + + std::ostringstream os; + os << iDefaultXSize; + m_pTextCtrlXSize = new wxTextCtrl (this, -1, os.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); + std::ostringstream osYSize; + osYSize << iDefaultYSize; + m_pTextCtrlYSize = new wxTextCtrl (this, -1, osYSize.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); + + wxFlexGridSizer *pGridSizer = new wxFlexGridSizer (2); + pGridSizer->Add (new wxStaticText (this, -1, "X Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (m_pTextCtrlXSize, 0, wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (new wxStaticText (this, -1, "Y Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (m_pTextCtrlYSize, 0, wxALIGN_CENTER_VERTICAL); + pTopSizer->Add (pGridSizer, 1, wxALL, 10); + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); + + wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); + wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay"); + wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel"); + pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10); + pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10); + + pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER); + + SetAutoLayout (true); + SetSizer (pTopSizer); + pTopSizer->Fit (this); + pTopSizer->SetSizeHints (this); +} + +DialogGetXYSize::~DialogGetXYSize (void) +{ +} + +unsigned int +DialogGetXYSize::getXSize (void) +{ + wxString strCtrl = m_pTextCtrlXSize->GetValue(); + long lValue; + if (strCtrl.ToLong (&lValue)) + return lValue; + else + return (m_iDefaultXSize); +} + +unsigned int +DialogGetXYSize::getYSize (void) +{ + wxString strCtrl = m_pTextCtrlYSize->GetValue(); + long lValue; + if (strCtrl.ToLong (&lValue)) + return lValue; + else + return (m_iDefaultYSize); +} + diff --git a/src/dlgprojections.cpp b/src/dlgprojections.cpp index 489d912..fb2f8cd 100644 --- a/src/dlgprojections.cpp +++ b/src/dlgprojections.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: dlgprojections.cpp,v 1.14 2000/12/29 15:45:06 kevin Exp $ +** $Id: dlgprojections.cpp,v 1.15 2001/01/02 16:02:13 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 @@ -126,7 +126,7 @@ ProjectionsDialog::ProjectionsDialog (Scanner& rScanner, Projections& rProj, con Show(TRUE); Enable(TRUE); // enable this window - m_bitmap.Create (m_iClientX, m_iClientY); // save a copy of screen + m_bitmap.Create (m_iClientX, m_iClientY); // save a copy of screen m_pDC = dynamic_cast (new wxClientDC (this)); int x, y; this->GetClientSize(&x, &y); @@ -145,8 +145,8 @@ void ProjectionsDialog::showView (int iViewNumber) { if ( iViewNumber < m_rProjections.nView() ) { - m_iLastView = iViewNumber; - ::wxYield(); // update the display + m_iLastView = iViewNumber; + ::wxYield(); // update the display m_pSGP->eraseWindow(); m_btnPause->Refresh(); m_btnStep->Refresh(); @@ -154,7 +154,7 @@ ProjectionsDialog::showView (int iViewNumber) if (m_iTrace >= Trace::TRACE_PLOT) m_pSGP->setViewport (0, 0, 0.66, 1); - ::wxYield(); // update the display + ::wxYield(); // update the display m_rScanner.collectProjections (m_rProjections, m_rPhantom, iViewNumber, 1, true, m_iTrace, m_pSGP); ::wxYield(); // update the display if (m_iTrace >= Trace::TRACE_PLOT) { @@ -165,11 +165,11 @@ ProjectionsDialog::showView (int iViewNumber) detPos[i] = i; EZPlot ezplot; ezplot.ezset ("grid"); - ezplot.ezset ("box"); + ezplot.ezset ("box"); ezplot.ezset ("yticks left"); - ezplot.addCurve (detValues, detPos, detArray.nDet()); + ezplot.addCurve (detValues, detPos, detArray.nDet()); m_pSGP->setViewport (0.67, 0.1, 1., 1.); - ezplot.plot (m_pSGP); + ezplot.plot (m_pSGP); delete detPos; } } @@ -232,8 +232,8 @@ ProjectionsDialog::OnPause (wxCommandEvent& event) showView (m_iLastView); m_state = Paused; m_btnPause->SetLabel (wxString("Resume")); - m_pSGP->setDC (m_pDC); - m_memoryDC.SelectObject(wxNullBitmap); + m_pSGP->setDC (m_pDC); + m_memoryDC.SelectObject(wxNullBitmap); } else if (m_state == Paused) { m_state = Continue; m_btnPause->SetLabel (wxString("Pause")); @@ -248,22 +248,22 @@ ProjectionsDialog::OnStep (wxCommandEvent& event) } else if (m_state == Continue) { m_memoryDC.SelectObject (m_bitmap); // in memoryDC m_pSGP->setDC (&m_memoryDC); - m_memoryDC.SetFont (*wxSWISS_FONT); + m_memoryDC.SetFont (*wxSWISS_FONT); showView (m_iLastView); // m_rScanner.collectProjections (m_rProjections, m_rPhantom, m_iLastView, 1, true, m_iTrace, m_pSGP); m_state = Paused; m_btnPause->SetLabel (wxString("Resume")); - m_pSGP->setDC (m_pDC); - m_memoryDC.SelectObject(wxNullBitmap); - Refresh(); + m_pSGP->setDC (m_pDC); + m_memoryDC.SelectObject(wxNullBitmap); + Refresh(); } else if (m_state == Paused) { - m_memoryDC.SelectObject (m_bitmap); // in memoryDC - m_pSGP->setDC (&m_memoryDC); - m_memoryDC.SetFont (*wxSWISS_FONT); + m_memoryDC.SelectObject (m_bitmap); // in memoryDC + m_pSGP->setDC (&m_memoryDC); + m_memoryDC.SetFont (*wxSWISS_FONT); projectView (m_iLastView + 1); - m_pSGP->setDC (m_pDC); - m_memoryDC.SelectObject(wxNullBitmap); - Refresh(); + m_pSGP->setDC (m_pDC); + m_memoryDC.SelectObject(wxNullBitmap); + Refresh(); } } @@ -280,7 +280,7 @@ void ProjectionsDialog::OnClose(wxCloseEvent& event) void ProjectionsDialog::OnPaint (wxPaintEvent& event) { - wxPaintDC paintDC (this); + wxPaintDC paintDC (this); if (m_state == Paused) { paintDC.DrawBitmap (m_bitmap, 0, 0, false); } diff --git a/src/dlgreconstruct.cpp b/src/dlgreconstruct.cpp index 3dcd74a..4fd7b1a 100644 --- a/src/dlgreconstruct.cpp +++ b/src/dlgreconstruct.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: dlgreconstruct.cpp,v 1.12 2000/12/18 12:29:41 kevin Exp $ +** $Id: dlgreconstruct.cpp,v 1.13 2001/01/02 16:02:13 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 @@ -55,13 +55,13 @@ static const int LAYOUT_X_MARGIN = 4; static const int LAYOUT_Y_MARGIN = 4; - - -const int ReconstructDialog::ID_BTN_PAUSE = 19998; -const int ReconstructDialog::ID_BTN_STEP = 19999; -const int ReconstructDialog::MAX_IMAGE_X = 400; -const int ReconstructDialog::MAX_IMAGE_Y = 400; - + + +const int ReconstructDialog::ID_BTN_PAUSE = 19998; +const int ReconstructDialog::ID_BTN_STEP = 19999; +const int ReconstructDialog::MAX_IMAGE_X = 400; +const int ReconstructDialog::MAX_IMAGE_Y = 400; + BEGIN_EVENT_TABLE(ReconstructDialog, wxDialog) EVT_BUTTON(wxID_CANCEL, ReconstructDialog::OnCancel) @@ -130,20 +130,20 @@ ReconstructDialog::ReconstructDialog (Reconstructor& rReconstruct, const Project m_iClientY = sizeDlg.y; SetClientSize (sizeDlg); - Centre(wxCENTER_FRAME | wxBOTH); - - if ( m_parentTop ) - m_parentTop->Enable(FALSE); - - Show(TRUE); - Enable(TRUE); // enable this window - + Centre(wxCENTER_FRAME | wxBOTH); + + if ( m_parentTop ) + m_parentTop->Enable(FALSE); + + Show(TRUE); + Enable(TRUE); // enable this window + m_bitmap.Create (m_iClientX, m_iClientY); // save a copy of screen - m_pDC = dynamic_cast (new wxClientDC (this)); - int x, y; - this->GetClientSize(&x, &y); - m_pSGPDriver = new SGPDriver (m_pDC, x, y); - m_pSGP = new SGP (*m_pSGPDriver); + m_pDC = dynamic_cast (new wxClientDC (this)); + int x, y; + this->GetClientSize(&x, &y); + m_pSGPDriver = new SGPDriver (m_pDC, x, y); + m_pSGP = new SGP (*m_pSGPDriver); wxYield(); // Update the display @@ -152,11 +152,11 @@ ReconstructDialog::ReconstructDialog (Reconstructor& rReconstruct, const Project void ReconstructDialog::showView (int iViewNumber, bool bBackprojectView) -{ +{ if ( iViewNumber < m_rProjections.nView() ) { m_iLastView = iViewNumber; - ::wxYield(); // update the display - m_pSGP->eraseWindow(); + ::wxYield(); // update the display + m_pSGP->eraseWindow(); m_btnPause->Refresh(); m_btnStep->Refresh(); m_btnAbort->Refresh(); @@ -202,7 +202,7 @@ ReconstructDialog::showView (int iViewNumber, bool bBackprojectView) int baseAddr = ((m_nyImage - 1 - iy) * m_nxImage + ix2) * 3; imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity; } - } + } wxImage image (m_nxImage, m_nyImage, imageData, true); wxBitmap bitmap = image.ConvertToBitmap(); m_pSGP->getDriver().idWX()->DrawBitmap(bitmap, xBase, yBase, false); @@ -259,15 +259,15 @@ ReconstructDialog::OnPause (wxCommandEvent& event) // this means that the count down is already finished and we're being // shown as a modal dialog - so just let the default handler do the job event.Skip(); - } else if (m_state == Continue) { - m_memoryDC.SelectObject (m_bitmap); // in memoryDC - m_pSGP->setDC (&m_memoryDC); - m_memoryDC.SetFont (*wxSWISS_FONT); - showView (m_iLastView, false); + } else if (m_state == Continue) { + m_memoryDC.SelectObject (m_bitmap); // in memoryDC + m_pSGP->setDC (&m_memoryDC); + m_memoryDC.SetFont (*wxSWISS_FONT); + showView (m_iLastView, false); m_state = Paused; m_btnPause->SetLabel (wxString("Resume")); - m_pSGP->setDC (m_pDC); - m_memoryDC.SelectObject(wxNullBitmap); + m_pSGP->setDC (m_pDC); + m_memoryDC.SelectObject(wxNullBitmap); } else if (m_state == Paused) { m_state = Continue; m_btnPause->SetLabel (wxString("Pause")); @@ -280,24 +280,24 @@ ReconstructDialog::OnStep (wxCommandEvent& event) { if ( m_state == Finished ) { event.Skip(); - } else if (m_state == Continue) { - m_memoryDC.SelectObject (m_bitmap); // in memoryDC - m_pSGP->setDC (&m_memoryDC); - m_memoryDC.SetFont (*wxSWISS_FONT); - showView (m_iLastView, false); + } else if (m_state == Continue) { + m_memoryDC.SelectObject (m_bitmap); // in memoryDC + m_pSGP->setDC (&m_memoryDC); + m_memoryDC.SetFont (*wxSWISS_FONT); + showView (m_iLastView, false); m_state = Paused; m_btnPause->SetLabel (wxString("Resume")); - m_pSGP->setDC (m_pDC); - m_memoryDC.SelectObject(wxNullBitmap); - Refresh(); + m_pSGP->setDC (m_pDC); + m_memoryDC.SelectObject(wxNullBitmap); + Refresh(); } else if (m_state == Paused) { - m_memoryDC.SelectObject (m_bitmap); // in memoryDC - m_pSGP->setDC (&m_memoryDC); - m_memoryDC.SetFont (*wxSWISS_FONT); + m_memoryDC.SelectObject (m_bitmap); // in memoryDC + m_pSGP->setDC (&m_memoryDC); + m_memoryDC.SetFont (*wxSWISS_FONT); reconstructView (m_iLastView + 1); - m_pSGP->setDC (m_pDC); - m_memoryDC.SelectObject(wxNullBitmap); - Refresh(); + m_pSGP->setDC (m_pDC); + m_memoryDC.SelectObject(wxNullBitmap); + Refresh(); } } @@ -313,11 +313,11 @@ void ReconstructDialog::OnClose(wxCloseEvent& event) void ReconstructDialog::OnPaint (wxPaintEvent& event) -{ - wxPaintDC paintDC (this); +{ + wxPaintDC paintDC (this); if (m_state == Paused) { - paintDC.DrawBitmap (m_bitmap, 0, 0, false); - } + paintDC.DrawBitmap (m_bitmap, 0, 0, false); + } } diff --git a/src/docs.cpp b/src/docs.cpp index 69b5954..d9b3d10 100644 --- a/src/docs.cpp +++ b/src/docs.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: docs.cpp,v 1.10 2001/01/02 05:34:57 kevin Exp $ +** $Id: docs.cpp,v 1.11 2001/01/02 16:02:13 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 @@ -80,8 +80,8 @@ bool ImageFileDocument::OnOpenDocument(const wxString& filename) SetFilename(filename, true); } Modify(false); - UpdateAllViews(); - GetFirstView()->OnUpdate (GetFirstView(), NULL); + UpdateAllViews(); + GetFirstView()->OnUpdate (GetFirstView(), NULL); return true; } @@ -131,7 +131,7 @@ bool ProjectionFileDocument::OnOpenDocument(const wxString& filename) SetFilename(filename, true); } Modify(false); - UpdateAllViews(); + UpdateAllViews(); return true; } @@ -175,22 +175,22 @@ bool PhantomDocument::OnOpenDocument(const wxString& filename) } m_idPhantom = m_phantom.id(); Modify(false); - UpdateAllViews(); + UpdateAllViews(); return true; } -bool PhantomDocument::OnSaveDocument(const wxString& filename) -{ - if (! m_phantom.fileWrite (filename.c_str())) { - *theApp->getLog() << "Unable to write phantom file " << filename << "\n"; - return false; - } - *theApp->getLog() << "Wrote phantom file " << filename << "\n"; - Modify(false); - return true; -} - +bool PhantomDocument::OnSaveDocument(const wxString& filename) +{ + if (! m_phantom.fileWrite (filename.c_str())) { + *theApp->getLog() << "Unable to write phantom file " << filename << "\n"; + return false; + } + *theApp->getLog() << "Wrote phantom file " << filename << "\n"; + Modify(false); + return true; +} + bool PhantomDocument::OnCloseDocument () { bool bReturn = wxDocument::OnCloseDocument(); @@ -212,18 +212,18 @@ void PhantomDocument::Modify(bool mod) IMPLEMENT_DYNAMIC_CLASS(PlotFileDocument, wxDocument) -bool PlotFileDocument::OnSaveDocument(const wxString& filename) -{ - m_namePlot = filename.c_str(); - if (! m_plot.fileWrite (filename)) { - *theApp->getLog() << "Unable to write plot file " << filename << "\n"; - return false; - } - *theApp->getLog() << "Wrote plot file " << filename << "\n"; - Modify(false); - return true; -} - +bool PlotFileDocument::OnSaveDocument(const wxString& filename) +{ + m_namePlot = filename.c_str(); + if (! m_plot.fileWrite (filename)) { + *theApp->getLog() << "Unable to write plot file " << filename << "\n"; + return false; + } + *theApp->getLog() << "Wrote plot file " << filename << "\n"; + Modify(false); + return true; +} + bool PlotFileDocument::OnOpenDocument(const wxString& filename) { if (filename == "untitled.plt") { @@ -235,12 +235,12 @@ bool PlotFileDocument::OnOpenDocument(const wxString& filename) return false; } *theApp->getLog() << "Read plot file " << filename << "\n"; - SetFilename (filename, true); + SetFilename (filename, true); m_namePlot = filename.c_str(); } Modify (false); - UpdateAllViews(); - GetFirstView()->OnUpdate (NULL, NULL); + UpdateAllViews(); + GetFirstView()->OnUpdate (NULL, NULL); return true; } -- 2.34.1