From 2a3686d3bd1f690d318b81766c261da785cf9b57 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Sat, 23 Dec 2000 18:12:35 +0000 Subject: [PATCH] r312: *** empty log message *** --- ChangeLog | 29 ++- include/ezplot.h | 529 ++++++++++++++++++++------------------ include/plotfile.h | 71 ++--- libctgraphics/ezplot.cpp | 481 +++++++++++++++++----------------- libctgraphics/ezset.cpp | 24 +- libctsupport/plotfile.cpp | 271 ++++++++++--------- msvc/ctsim/ctsim.plg | 61 ++++- src/views.cpp | 91 ++++--- tools/if1.cpp | 26 +- tools/if2.cpp | 34 ++- 10 files changed, 867 insertions(+), 750 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3788ecd..89179db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,23 @@ +TODO + Read PlotFile's. + + Fix display of ylabel. + + Review old ezset.c and add in concept of curve number. Add to ezset + std::vector for individual curve parameters such as color, linestyle, + symbol. Read these vectors during plot generation + + Add help button onto dialog's for reconstruction & projections. + Consider use of wxWindows help file classes. + + Consider changing POL into a Class. Consider making it read tag tokens. + + Consider being able to write Phantom files as text + 3.0alpha1 - Released 12/30/00 - * Added PlotFile class to system, used by if2 and ctsim + * Added PlotFile class to system, used by if2 and ctsim for row + and column plots and comparison plots * ctsim: Added image comparison statistics and image subtraction @@ -13,10 +30,18 @@ plotfile classes. * imagefile.cpp: Fixed scaling bug when rasterizing Phantom with - nsamples > 2. Added image math functions. + nsamples > 2. Added generic mage math functions, moved from + if1.cpp and if2.cpp to imagefile.cpp + * if1: Updated to handle error conditions, such as sqrt of a + negative number. + * if2: Updated to output plot files and use new ImageFile class math functions + + * if1: Updated to use new ImageFile class math functions + + * ezplot.h: Updated to more C++ conventions 2.5.0 - 12/18/00 First Microsoft Windows GUI version diff --git a/include/ezplot.h b/include/ezplot.h index 67c6e31..6ad4b5b 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.19 2000/12/20 14:39:09 kevin Exp $ +** $Id: ezplot.h,v 1.20 2000/12/23 18:12:35 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 @@ -36,19 +36,19 @@ class EZPlotCurve { - public: - double *x; - double *y; - int m_iPointCount; - int m_iLineStyle; - int m_iSymbol; - int m_iSymbolFreq; - int m_iColor; - std::string m_sLegend; - - EZPlotCurve (const double* x, const double* y, int n, int color, int linestyle, int symbol, int sumbolFreq, const std::string& legend); - - ~EZPlotCurve(); +public: + double *x; + double *y; + int m_iPointCount; + int m_iLineStyle; + int m_iSymbol; + int m_iSymbolFreq; + int m_iColor; + std::string m_sLegend; + + EZPlotCurve (const double* x, const double* y, int n, int color, int linestyle, int symbol, int sumbolFreq, const std::string& legend); + + ~EZPlotCurve(); }; //---------------------------------------------------------------------- @@ -56,59 +56,75 @@ class EZPlotCurve { //---------------------------------------------------------------------- // axis definitions -#define LINEAR 1 // linear axis -#define LOG 2 // logrithmic axis -#define NOAXIS 3 // don't plot axis +enum { + LINEAR = 1, // linear axis + LOG, // logrithmic axis + NOAXIS, // don't plot axis +}; // tick definitions -#define ABOVE 1 -#define BELOW 2 -#define RIGHT 4 -#define LEFT 8 +enum { + ABOVE = 1, + BELOW, + RIGHT, + LEFT, +}; -// line types -#define NOLINE 0 -#define SOLID 1 -#define DASH 2 -#define DASH1 10 -#define DASH2 11 -#define DASH3 12 -#define DASH4 13 +// line types +enum { + NOLINE = 0, + SOLID, + DASH, + DASH1, + DASH2, + DASH3, + DASH4, +}; // symbol definitions -#define SB_CROSS 1 -#define SB_PLUS 2 -#define SB_BOX 3 -#define SB_CIRCLE 4 -#define SB_ERRORBAR 5 -#define MAXSYMBOL 5 - -#define INSIDE 1 // values of o_legendbox -#define OUTSIDE 2 -#define NOLEGEND 3 +enum { + SB_CROSS = 1, + SB_PLUS, + SB_BOX, + SB_CIRCLE, + SB_ERRORBAR, + MAXSYMBOL, +}; +enum { + INSIDE = 1, // values of o_legendbox + OUTSIDE, + NOLEGEND, +}; + + +struct KeywordCodeTable { + char* keyword; + int code; +}; + /*----------------------------------------------------------------------------- - * GLOBAL VARIABLES - * - * Naming Convention: - * i_ Internal variable - * Not user changable - * o_ Option variable - * Normal variable that is user modifiable - * These variables must always have a valid value - * d_ Device variable - * Variables controlling devices - * clr_ Color variable - * Holds a color value - * c_ Character string variable - * Contains a character string - * v_ Value variable - * User modifiable variable associated with the set variable (s_) - * These variables do not always have a valid value - * These variables change assumption EZPLOT makes about the plot - * s_ Set variable. - * TRUE if associated value variable (v_) has been set by the user - *---------------------------------------------------------------------------*/ +* GLOBAL VARIABLES +* +* Naming Convention: +* i_ Internal variable +* Not user changable +* o_ Option variable +* Normal variable that is user modifiable +* These variables must always have a valid value +* d_ Device variable +* Variables controlling devices +* clr_ Color variable +* Holds a color value +* c_ Character string variable +* Contains a character string +* v_ Value variable +* User modifiable variable associated with the set variable (s_) +* These variables do not always have a valid value +* These variables change assumption EZPLOT makes about the plot +* s_ Set variable. +* TRUE if associated value variable (v_) has been set by the user +*---------------------------------------------------------------------------*/ #include @@ -117,203 +133,204 @@ typedef std::vector::const_iterator EZPlotCurveConstIterator; class SGP; class EZPlot { - private: - std::vector m_vecCurves; - - // Colors - int clr_axis; // color of all axis lines - int clr_title; // color of main title - int clr_label; // color of axis labels - int clr_legend; // color of legend box - int clr_grid; // color of grid lines - int clr_number; // color of axis number labels - - // Options - double o_xporigin, o_yporigin; // origin of plot frame in NDC - double o_xlength, o_ylength; // length of plot frame in NDC - - std::string c_xlabel; // label for x axis - std::string c_ylabel; // label for y axis - std::string c_title; // title to print above graph - std::string c_legend;; // current legend specified - - int o_linestyle, o_color; // style to use for curves all subsequent curves to EZPLOT - int o_xaxis, o_yaxis; // Specifies where axis & labels are drawn - bool o_grid; // Flag to draw a grid at major ticks - bool o_box; // Flag to draw a box around the graph - - int o_xticks, o_yticks; // direction to draw tick marks - bool o_xtlabel, o_ytlabel; // TRUE if label tick marks - - int o_xmajortick, o_ymajortick; // number of major ticks to draw - int o_xminortick, o_yminortick; // number of minor ticks between major ticks - - int o_symbol; // Symbol type, (0 = no symbol) - int o_symfreq; // frequency to draw symbols at curve points - - int o_legendbox; // controls whether legend is inside or outside of the axis extents - int o_tag; // controls whether to draw tag at end of axes - - // VALUE & SET variables - double v_xmin, v_xmax, v_ymin, v_ymax; // user supplied axis endpoints - bool s_xmin, s_xmax, s_ymin, s_ymax; // TRUE is endpoint has been set - double v_xtitle, v_ytitle; // NDC position to plot title - bool s_xtitle, s_ytitle; // TRUE if set position for title - double v_xcross, v_ycross; // position that axes cross - bool s_xcross, s_ycross; // TRUE if set axes cross position - double v_xlegend, v_ylegend; // upper-left position of legend box in NDC - bool s_xlegend, s_ylegend; // TRUE if set position of legend box - int v_lxfrac, v_lyfrac; // number of digits to right of decimal place - bool s_lxfrac, s_lyfrac; // TRUE if set number of fractional digits - double v_textsize; // size of text in NDC - bool s_textsize; // TRUE if user set size of text - - // Global variables - double charheight; // Height of characters in NDC - double charwidth; // Height of characters in NDC - double xp_min, xp_max, yp_min, yp_max; // boundry of plot frame in NDC - double xa_min, xa_max, ya_min, ya_max; // extent of axes in NDC - double xgw_min, xgw_max, ygw_min, ygw_max; // boundary of graph in input coords - double xgn_min, xgn_max, ygn_min, ygn_max; // boundy of graph in NDC - double xt_min, xt_max, yt_min, yt_max; // boundary of axis ticks - double xl_min, xl_max, yl_min, yl_max; // boundary of legend box - double title_row; // y-coord of title row - double xtl_ofs; // Offset y-coord of x tick labels from axis - double ytl_ofs; // Offset x-coord of y tick labels from axis - double xlbl_row; // row of x label in world coord - double ylbl_col; // column of y label in world coord - double xw_tickinc, yw_tickinc; // increment between major ticks in WC - double xn_tickinc, yn_tickinc; // increment between major ticks in NDC - int x_nint, y_nint; // number of intervals along x & y axes - int x_fldwid, x_frac; // numeric field sizes & number of digits - int y_fldwid, y_frac; // in fraction of number, used for printf() - double xtl_wid, ytl_wid; // length of ticks labels in NDC - double tl_height; // height of tick labels in NDC - char x_numfmt[20]; // format to print x tick labels - char y_numfmt[20]; // format to print y tick labels - - double m_dVP_xmin, m_dVP_ymin; - double m_dVP_xmax, m_dVP_ymax; - double m_dVP_xscale, m_dVP_yscale; - double m_xWorldScale, m_yWorldScale; - - void drawAxes(void); - void symbol (int sym, double symwidth, double symheight); - void make_numfmt(char *fmtstr, int *fldwid, int *nfrac, double min, double max, int nint); - int axis_scale (double min, double max, int nint, double *minp, double *maxp, int *nintp); - - SGP& rSGP; - - void clearCurves (); - - bool ezcmd (const char const *comm); - bool do_cmd(int lx); - void bad_option(char *opt); - void initPlotSettings(); - - static void initkw(void); - - static bool ezset_initialized; - - double convertWorldToNDC_X (double x) - { return xgn_min + (x - xgw_min) * m_xWorldScale; } - - double convertWorldToNDC_Y (double y) - { return ygn_min + (y - ygw_min) * m_yWorldScale; } - +private: + //---------------------------------------------------------------------- + // POL Codes + //---------------------------------------------------------------------- + + enum { + S_DATA = 2, + S_HELP, + S_EXIT, + S_SOLID, + S_DASH, + S_NOLINE, + S_BLACK, + S_RED, + S_GREEN, + S_BLUE, + S_SYMBOL, + S_PEN, + S_EVERY, + S_NONE, + S_LEGEND, + S_XLEGEND, + S_YLEGEND, + S_XLIN, + S_YLIN, + S_XLOG, + S_YLOG, + S_XLABEL, + S_YLABEL, + S_XLENGTH, + S_YLENGTH, + S_XTICKS, + S_YTICKS, + S_ABOVE, + S_LABEL, + S_BELOW, + S_NOLABEL, + S_RIGHT, + S_LEFT, + S_XAUTOSCALE, + S_YAUTOSCALE, + S_XMIN, + S_YMIN, + S_XMAX, + S_YMAX, + S_LXFRAC, + S_LYFRAC, + S_XCROSS, + S_YCROSS, + S_NOXAXIS, + S_NOYAXIS, + S_XPORIGIN, + S_YPORIGIN, + S_TITLE, + S_XTITLE, + S_YTITLE, + S_REPLOT, + S_CLEAR, + S_STORE, + S_RESTORE, + S_AMARK, + S_NO, + S_INTERACTIVE, + S_UNITS, + S_INCHES, + S_USER, + S_BOX, + S_NOBOX, + S_GRID, + S_NOGRID, + S_MAJOR, + S_MINOR, + S_COLOR, + S_LEGENDBOX, + S_TAG, + S_TEXTSIZE, + }; + + static const struct KeywordCodeTable m_sKeywords[]; + static const int NKEYS; + + std::vector m_vecCurves; + + // Colors + int clr_axis; // color of all axis lines + int clr_title; // color of main title + int clr_label; // color of axis labels + int clr_legend; // color of legend box + int clr_grid; // color of grid lines + int clr_number; // color of axis number labels + + // Options + double o_xporigin, o_yporigin; // origin of plot frame in NDC + double o_xlength, o_ylength; // length of plot frame in NDC + + std::string c_xlabel; // label for x axis + std::string c_ylabel; // label for y axis + std::string c_title; // title to print above graph + std::string c_legend;; // current legend specified + + int o_linestyle, o_color; // style to use for curves all subsequent curves to EZPLOT + int o_xaxis, o_yaxis; // Specifies where axis & labels are drawn + bool o_grid; // Flag to draw a grid at major ticks + bool o_box; // Flag to draw a box around the graph + + int o_xticks, o_yticks; // direction to draw tick marks + bool o_xtlabel, o_ytlabel; // TRUE if label tick marks + + int o_xmajortick, o_ymajortick; // number of major ticks to draw + int o_xminortick, o_yminortick; // number of minor ticks between major ticks + + int o_symbol; // Symbol type, (0 = no symbol) + int o_symfreq; // frequency to draw symbols at curve points + + int o_legendbox; // controls whether legend is inside or outside of the axis extents + int o_tag; // controls whether to draw tag at end of axes + + // VALUE & SET variables + double v_xmin, v_xmax, v_ymin, v_ymax; // user supplied axis endpoints + bool s_xmin, s_xmax, s_ymin, s_ymax; // TRUE is endpoint has been set + double v_xtitle, v_ytitle; // NDC position to plot title + bool s_xtitle, s_ytitle; // TRUE if set position for title + double v_xcross, v_ycross; // position that axes cross + bool s_xcross, s_ycross; // TRUE if set axes cross position + double v_xlegend, v_ylegend; // upper-left position of legend box in NDC + bool s_xlegend, s_ylegend; // TRUE if set position of legend box + int v_lxfrac, v_lyfrac; // number of digits to right of decimal place + bool s_lxfrac, s_lyfrac; // TRUE if set number of fractional digits + double v_textsize; // size of text in NDC + bool s_textsize; // TRUE if user set size of text + + // Global variables + double charheight; // Height of characters in NDC + double charwidth; // Height of characters in NDC + double xp_min, xp_max, yp_min, yp_max; // boundry of plot frame in NDC + double xa_min, xa_max, ya_min, ya_max; // extent of axes in NDC + double xgw_min, xgw_max, ygw_min, ygw_max; // boundary of graph in input coords + double xgn_min, xgn_max, ygn_min, ygn_max; // boundy of graph in NDC + double xt_min, xt_max, yt_min, yt_max; // boundary of axis ticks + double xl_min, xl_max, yl_min, yl_max; // boundary of legend box + double title_row; // y-coord of title row + double xtl_ofs; // Offset y-coord of x tick labels from axis + double ytl_ofs; // Offset x-coord of y tick labels from axis + double xlbl_row; // row of x label in world coord + double ylbl_col; // column of y label in world coord + double xw_tickinc, yw_tickinc; // increment between major ticks in WC + double xn_tickinc, yn_tickinc; // increment between major ticks in NDC + int x_nint, y_nint; // number of intervals along x & y axes + int x_fldwid, x_frac; // numeric field sizes & number of digits + int y_fldwid, y_frac; // in fraction of number, used for printf() + double xtl_wid, ytl_wid; // length of ticks labels in NDC + double tl_height; // height of tick labels in NDC + char x_numfmt[20]; // format to print x tick labels + char y_numfmt[20]; // format to print y tick labels + + double m_dVP_xmin, m_dVP_ymin; + double m_dVP_xmax, m_dVP_ymax; + double m_dVP_xscale, m_dVP_yscale; + double m_xWorldScale, m_yWorldScale; + + void drawAxes(void); + void symbol (int sym, double symwidth, double symheight); + void make_numfmt(char *fmtstr, int *fldwid, int *nfrac, double min, double max, int nint); + int axis_scale (double min, double max, int nint, double *minp, double *maxp, int *nintp); + + SGP& rSGP; + + void clearCurves (); + + bool ezcmd (const char const *comm); + bool do_cmd(int lx); + void bad_option(char *opt); + void initPlotSettings(); + + static void initkw(void); + + static bool ezset_initialized; + + double convertWorldToNDC_X (double x) + { return xgn_min + (x - xgw_min) * m_xWorldScale; } + + double convertWorldToNDC_Y (double y) + { return ygn_min + (y - ygw_min) * m_yWorldScale; } + public: - EZPlot (SGP& sgp); - ~EZPlot (); - - bool ezset (const std::string& command); - bool ezset (const char const *command); - - void addCurve (const float* x, const double* y, int num); - void addCurve (const double* x, const float* y, int num); - void addCurve (const double* x, const double* y, int num); - void addCurve (const double* y, int n); - void addCurve (const float* y, int n); - - void plot (); + EZPlot (SGP& sgp); + ~EZPlot (); + + bool ezset (const std::string& command); + bool ezset (const char const *command); + + void addCurve (const float* x, const double* y, int num); + void addCurve (const double* x, const float* y, int num); + void addCurve (const double* x, const double* y, int num); + void addCurve (const double* y, int n); + void addCurve (const float* y, int n); + + void plot (); }; -//---------------------------------------------------------------------- -// Codes from LEX -//---------------------------------------------------------------------- - -#define S_DATA 2 -#define S_HELP 3 -#define S_EXIT 4 - -#define S_SOLID -10 -#define S_DASH -11 -#define S_NOLINE -12 -#define S_BLACK -13 -#define S_RED -14 -#define S_BLUE -15 -#define S_GREEN -16 -#define S_PEN -17 -#define S_SYMBOL -18 -#define S_EVERY -19 -#define S_NONE -20 -#define S_LEGEND -24 -#define S_XLEGEND -25 -#define S_YLEGEND -26 -#define S_XLIN -27 -#define S_YLIN -28 -#define S_XLOG -29 -#define S_YLOG -30 -#define S_XLABEL -31 -#define S_YLABEL -32 -#define S_XLENGTH -33 -#define S_YLENGTH -34 -#define S_XTICKS -35 -#define S_YTICKS -36 -#define S_ABOVE -37 -#define S_LABEL -38 -#define S_BELOW -39 -#define S_NOLABEL -40 -#define S_RIGHT -41 -#define S_LEFT -42 -#define S_XAUTOSCALE -43 -#define S_YAUTOSCALE -44 -#define S_XMIN -45 -#define S_YMIN -46 -#define S_XMAX -47 -#define S_YMAX -48 -#define S_LXFRAC -49 -#define S_LYFRAC -50 -#define S_XCROSS -51 -#define S_YCROSS -52 -#define S_NOXAXIS -53 -#define S_NOYAXIS -54 -#define S_XPORIGIN -55 -#define S_YPORIGIN -56 -#define S_TITLE -57 -#define S_XTITLE -58 -#define S_YTITLE -59 -#define S_REPLOT -60 -#define S_CLEAR -61 -#define S_STORE -62 -#define S_RESTORE -63 -#define S_AMARK -66 -#define S_NO -67 -#define S_INTERACTIVE -68 -#define S_UNITS -69 -#define S_INCHES -70 -#define S_USER -71 - -#define S_BOX -100 -#define S_NOBOX -101 -#define S_GRID -102 -#define S_NOGRID -103 -#define S_MAJOR -104 -#define S_MINOR -105 -#define S_COLOR -106 -#define S_LEGENDBOX -107 -#define S_TAG -108 - -#define S_TEXTSIZE -120 - - #endif diff --git a/include/plotfile.h b/include/plotfile.h index c60e579..da40ed3 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.3 2000/12/20 20:08:48 kevin Exp $ +** $Id: plotfile.h,v 1.4 2000/12/23 18:12:35 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,37 +41,30 @@ #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 -//
(signifies beginning of headers) -// (multiple instances may be present) -// -// -// <xlabel> -// <ylabel> -// <filetype>plotfile</filetype> (required) -// <ncolumns> (required) -// <nrecords> (required) -// </header> (required, signifies end of headers) +// 4. Valid headers +// <plotfile ncolumns nrecords> (signifies beginning of plotfile) +// <description> (beginning of description lines) +// <ezset> (signifies beginning of ezset commands) +// <columns> 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 -// 6. Data begins with <plotdata> and ends with </plotdata> + class PlotFile { private: std::string m_strFilename; - std::string m_strTitle; - std::string m_strXLabel; - std::string m_strYLabel; std::string m_strDate; - std::vector<std::string> m_vecStrDescriptions; + std::vector<std::string> m_vecStrDescriptions; + std::vector<std::string> m_vecStrEzsetCommands; std::vector<double> m_vecCurves; int m_iNumColumns; int m_iNumRecords; @@ -91,44 +84,20 @@ public: PlotFile (void); ~PlotFile (); - void setTitle (const std::string& title) - { m_strTitle = title; } - - void setTitle (const char* const title) - { m_strTitle = title; } - - void setXLabel (const std::string& label) - { m_strXLabel = label; } - - void setXLabel (const char* const label) - { m_strXLabel = label; } - - void setYLabel (const std::string& label) - { m_strYLabel = label; } - - void setYLabel (const char* const label) - { m_strYLabel = label; } - void setCurveSize (int iNCurves, int iNRecords); - void addDescription (const char* const pszDesc) - { m_vecStrDescriptions.push_back (pszDesc); } - + 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; - const std::string& getTitle () const - { return m_strTitle; } - - const std::string& getXLabel () const - { return m_strXLabel; } - - const std::string& getYLabel () const - { return m_strXLabel; } - const std::string& getDate () const { return m_strDate; } @@ -148,6 +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]; } + bool fileRead (const char* const filename); bool fileWrite (const char* const filename); diff --git a/libctgraphics/ezplot.cpp b/libctgraphics/ezplot.cpp index 5a2ec69..c009535 100644 --- a/libctgraphics/ezplot.cpp +++ b/libctgraphics/ezplot.cpp @@ -6,7 +6,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ezplot.cpp,v 1.20 2000/12/20 20:08:48 kevin Exp $ +** $Id: ezplot.cpp,v 1.21 2000/12/23 18:12:35 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 @@ -36,15 +36,15 @@ static const int DEF_CURVE_CLR = C_RED; EZPlotCurve::EZPlotCurve (const double* xData, const double* yData, int n, int color, int linestyle, int symbol, int symfreq, const std::string& legend) - : x(NULL), y(NULL), m_sLegend (legend) +: x(NULL), y(NULL), m_sLegend (legend) { x = new double [n]; y = new double [n]; - + int copyCount = n * sizeof(double); memcpy (x, xData, copyCount); memcpy (y, yData, copyCount); - + m_iPointCount = n; m_iColor = color; m_iLineStyle = linestyle; @@ -63,10 +63,10 @@ void EZPlot::addCurve (const double *y, int n) { double* x = new double [n]; - + for (int i = 0; i < n; i++) x[i] = i; - + addCurve (x, y, n); delete x; } @@ -76,10 +76,10 @@ void EZPlot::addCurve (const float *y, int n) { double* yDouble = new double [n]; - + for (int i = 0; i < n; i++) yDouble[i] = y[i]; - + addCurve (yDouble, n); delete yDouble; } @@ -89,10 +89,10 @@ void EZPlot::addCurve (const float x[], const double y[], int num) { double* dx = new double [num]; - + for (int i = 0; i < num; i++) dx[i] = x[i]; - + addCurve (dx, y, num); delete dx; } @@ -101,12 +101,12 @@ void EZPlot::addCurve (const double x[], const float y[], int num) { double* dy = new double [num]; - + for (int i = 0; i < num; i++) dy[i] = y[i]; - + addCurve (x, dy, num); - + delete dy; } @@ -116,7 +116,7 @@ EZPlot::addCurve (const double x[], const double y[], int num) { if (num < 1) return; - + EZPlotCurve* pCurve = new EZPlotCurve (x, y, num, o_color, o_linestyle, o_symbol, o_symfreq, c_legend); m_vecCurves.push_back (pCurve); } @@ -139,9 +139,9 @@ EZPlot::clearCurves () EZPlot::EZPlot (SGP& sgp) - : rSGP (sgp) +: rSGP (sgp) { - initPlotSettings(); + initPlotSettings(); } void @@ -149,7 +149,7 @@ EZPlot::initPlotSettings () { charheight = rSGP.getCharHeight(); charwidth = rSGP.getCharWidth(); - + c_xlabel = ""; c_ylabel = ""; c_title = ""; @@ -204,26 +204,30 @@ EZPlot::initPlotSettings () /* NAME - * plot Plots all curves collected by addCurves () - * - * SYNOPSIS - * plot() - * - * DESCRIPTION - * This routine plots the curves that have stored by addCurves(). - * - * CALLS - * drawAxes() & make_numfmt() - */ +* plot Plots all curves collected by addCurves () +* +* SYNOPSIS +* plot() +* +* DESCRIPTION +* This routine plots the curves that have stored by addCurves(). +* +* CALLS +* drawAxes() & make_numfmt() +*/ void EZPlot::plot () -{ +{ +#if 0 + wxFont* myFont = new wxFont (12, wxMODERN, wxNORMAL, wxNORMAL); + rSGP.getDriver().idWX()->SetFont (*myFont); +#endif if (m_vecCurves.size() <= 0) return; - + rSGP.setWindow (0., 0., 1., 1.); - + if (s_textsize == TRUE) { charheight = v_textsize; charwidth = rSGP.getCharWidth(); @@ -243,13 +247,13 @@ EZPlot::plot () for (int ip = 0; ip < curve.m_iPointCount; ip++) { if (curve.x[ip] > xmax) - xmax = curve.x[ip]; + xmax = curve.x[ip]; else if (curve.x[ip] < xmin) - xmin = curve.x[ip]; + xmin = curve.x[ip]; if (curve.y[ip] > ymax) - ymax = curve.y[ip]; + ymax = curve.y[ip]; else if (curve.y[ip] < ymin) - ymin = curve.y[ip]; + ymin = curve.y[ip]; } } @@ -260,18 +264,18 @@ EZPlot::plot () else if (v_xcross > xmax) xmax = v_xcross; } - + if (s_ycross == TRUE) { if (v_ycross < ymin) ymin = v_ycross; else if (v_ycross > ymax) ymax = v_ycross; } - + // find nice endpoints for axes if (! axis_scale (xmin, xmax, o_xmajortick - 1, &xgw_min, &xgw_max, &x_nint) || ! axis_scale (ymin, ymax, o_ymajortick - 1, &ygw_min, &ygw_max, &y_nint)) return; - + // check if user set x-axis extents if (s_xmin == TRUE) { xgw_min = v_xmin; @@ -291,11 +295,11 @@ EZPlot::plot () ygw_max = v_ymax; y_nint = o_ymajortick - 1; } - + // calculate increment between major axis in world coordinates xw_tickinc = (xgw_max - xgw_min) / x_nint; yw_tickinc = (ygw_max - ygw_min) / y_nint; - + // we have now calcuated xgw_min, xyw_max, ygw_min, & ygw_max // set the number of decimal point to users' setting or default @@ -304,25 +308,25 @@ EZPlot::plot () x_frac = v_lxfrac; else x_frac = -1; - + if (s_lyfrac == TRUE) y_frac = v_lyfrac; else y_frac = -1; - + make_numfmt (x_numfmt, &x_fldwid, &x_frac, xgw_min, xgw_max, x_nint); make_numfmt (y_numfmt, &y_fldwid, &y_frac, ygw_min, ygw_max, y_nint); - + xtl_wid = x_fldwid * charwidth; // calc size of tick labels ytl_wid = y_fldwid * charwidth; tl_height = charheight; - + // calculate the extent of the plot frame xp_min = o_xporigin; yp_min = o_yporigin; xp_max = xp_min + o_xlength; yp_max = yp_min + o_ylength; - + xp_min = clamp (xp_min, 0., 1.); xp_max = clamp (xp_max, 0., 1.); yp_min = clamp (yp_min, 0., 1.); @@ -332,12 +336,12 @@ EZPlot::plot () xa_max = xp_max; ya_min = yp_min; ya_max = yp_max; - + // adjust frame for title if (c_title.length() > 0) ya_max -= 2 * charheight; title_row = ya_max + 2 * charheight; - + // calculate legend box boundaries int max_leg = 0; // longest legend in characters int num_leg = 0; // number of legend titles @@ -347,10 +351,10 @@ EZPlot::plot () if (nLegend > 0) { ++num_leg; if (nLegend > max_leg) - nLegend = max_leg; + nLegend = max_leg; } } - + if (num_leg > 0 && o_legendbox != NOLEGEND) { double leg_width = (max_leg + 2) * charwidth; // size of legend box double leg_height = num_leg * 3 * charheight; @@ -360,7 +364,7 @@ EZPlot::plot () else { xl_max = xa_max; if (o_legendbox == OUTSIDE) - xa_max -= (leg_width + 0.5 * charwidth); + xa_max -= (leg_width + 0.5 * charwidth); } xl_min = xl_max - leg_width; @@ -370,43 +374,43 @@ EZPlot::plot () yl_max = ya_max; yl_min = yl_max - leg_height; - + rSGP.setColor (clr_legend); rSGP.drawRect (xl_min, yl_min, xl_max, yl_max); - + int iLegend = 0; // current legend position for (EZPlotCurveIterator iterCurve = m_vecCurves.begin(); iterCurve != m_vecCurves.end(); iterCurve++) { - const EZPlotCurve& curve = **iterCurve; - - if (curve.m_sLegend.length() == 0) - continue; - - double xmin = xl_min + 1.0 * charwidth; - double xmax = xl_max - 1.0 * charwidth; - double y = yl_max - (2.0 + iLegend * 3) * charheight; - - rSGP.moveAbs (xmin, y + 0.5 * charheight); - rSGP.drawText (curve.m_sLegend); - rSGP.setColor (curve.m_iColor); - if (curve.m_iLineStyle != SGP::LS_NOLINE) { - rSGP.setLineStyle (curve.m_iLineStyle); - rSGP.moveAbs (xmin, y); - rSGP.lineAbs (xmax, y); - } - if (curve.m_iSymbol > 0) { - double xinc = (xmax - xmin) / (5 - 1); - rSGP.setLineStyle (SGP::LS_SOLID); - for (int j = 0; j < 5; j++) { - rSGP.moveAbs (xmin + j * xinc, y); - symbol(curve.m_iSymbol, 0.5 * charwidth, 0.5 * charheight); - } - } - ++iLegend; // move to next legend position + const EZPlotCurve& curve = **iterCurve; + + if (curve.m_sLegend.length() == 0) + continue; + + double xmin = xl_min + 1.0 * charwidth; + double xmax = xl_max - 1.0 * charwidth; + double y = yl_max - (2.0 + iLegend * 3) * charheight; + + rSGP.moveAbs (xmin, y + 0.5 * charheight); + rSGP.drawText (curve.m_sLegend); + rSGP.setColor (curve.m_iColor); + if (curve.m_iLineStyle != SGP::LS_NOLINE) { + rSGP.setLineStyle (curve.m_iLineStyle); + rSGP.moveAbs (xmin, y); + rSGP.lineAbs (xmax, y); + } + if (curve.m_iSymbol > 0) { + double xinc = (xmax - xmin) / (5 - 1); + rSGP.setLineStyle (SGP::LS_SOLID); + for (int j = 0; j < 5; j++) { + rSGP.moveAbs (xmin + j * xinc, y); + symbol(curve.m_iSymbol, 0.5 * charwidth, 0.5 * charheight); + } + } + ++iLegend; // move to next legend position } } // end legend printing - + // calculate the extent of the axes - + /*-------------------------*/ /* adjust frame for labels */ /*-------------------------*/ @@ -415,16 +419,16 @@ EZPlot::plot () if (c_xlabel.length() > 0) ya_min += 3.0 * charheight; xlbl_row = xp_min; // put x-label on bottom of plot frame - + // Y-Label if (c_ylabel.length() > 0) xa_min += 3.0 * charwidth; // reverse rSGP.setTextSize because writing text sideways ylbl_col = xp_min + 2 * charwidth; - + /*------------------------------*/ /* adjust frame for tick labels */ /*------------------------------*/ - + // Calc offset of tick labels from axes if (o_xaxis == NOAXIS || o_xtlabel == FALSE) xtl_ofs = 0.0; @@ -439,12 +443,12 @@ EZPlot::plot () ytl_ofs = -(1 + y_fldwid) * charwidth; else if (o_yticks == RIGHT) ytl_ofs = 1.5 * charwidth; - + xt_min = xa_min; yt_min = ya_min; xt_max = xa_max; yt_max = ya_max; - + // see if need to shrink axis extents and/or tick extents if (xtl_ofs != 0.0 && s_ycross == FALSE) { if (o_xticks == BELOW) { @@ -467,11 +471,11 @@ EZPlot::plot () } } else xt_min = xa_min; - + // decrease size of graph, if necessary, to accommadate space // between axis boundary and boundary of ticks - double x_added_ticks = -1; // number of tick spaces added to axis - double y_added_ticks = -1; + double x_added_ticks = 0; // number of tick spaces added to axis + double y_added_ticks = 0; if (o_xaxis == NOAXIS || o_xtlabel == FALSE) x_added_ticks = 0; if (o_yaxis == NOAXIS || o_ytlabel == FALSE) @@ -510,62 +514,74 @@ EZPlot::plot () xgn_max = xt_max; ygn_min = yt_min; ygn_max = yt_max; - + //------------------------------------------------------------------------ m_xWorldScale = (xgn_max - xgn_min) / (xgw_max - xgw_min); m_yWorldScale = (ygn_max - ygn_min) / (ygw_max - ygw_min); - + // PLOT CURVES rSGP.setLineStyle (SGP::LS_SOLID); drawAxes(); - + // size of symbol in NDC double symwidth = charwidth; double symheight = charheight; - - for (EZPlotCurveIterator iterCurve3 = m_vecCurves.begin(); iterCurve3 != m_vecCurves.end(); iterCurve3++) { - const EZPlotCurve& curve = **iterCurve3; - - rSGP.setColor (curve.m_iColor); + + double clipRect[4]; + clipRect[0] = xgn_min; clipRect[1] = ygn_min; clipRect[2] = xgn_max; clipRect[3] = ygn_max; - if (curve.m_iLineStyle != SGP::LS_NOLINE) { - rSGP.setLineStyle (curve.m_iLineStyle); - double x = convertWorldToNDC_X (curve.x[0]); - double y = convertWorldToNDC_Y (curve.y[0]); - rSGP.moveAbs (x, y); - for (int i = 1; i < curve.m_iPointCount; i++) { - x = convertWorldToNDC_X (curve.x[i]); - y = convertWorldToNDC_Y (curve.y[i]); - rSGP.lineAbs (x, y); - } - } - if (curve.m_iSymbol > 0) { - rSGP.setLineStyle (SGP::LS_SOLID); - double x = convertWorldToNDC_X (curve.x[0]); - double y = convertWorldToNDC_Y (curve.y[0]); - rSGP.moveAbs (x, y); - symbol (curve.m_iSymbol, symwidth, symheight); - for (int i = 1; i < curve.m_iPointCount; i++) - if (i % curve.m_iSymbolFreq == 0 || i == curve.m_iPointCount - 1) { - x = convertWorldToNDC_X (curve.x[i]); - y = convertWorldToNDC_Y (curve.y[i]); - rSGP.moveAbs (x, y); - symbol (curve.m_iSymbol, symwidth, symheight); - } - } + for (EZPlotCurveIterator iterCurve3 = m_vecCurves.begin(); iterCurve3 != m_vecCurves.end(); iterCurve3++) { + const EZPlotCurve& curve = **iterCurve3; + + rSGP.setColor (curve.m_iColor); + + bool bOutside = false; + if (curve.m_iLineStyle != SGP::LS_NOLINE) { + rSGP.setLineStyle (curve.m_iLineStyle); + double x1 = convertWorldToNDC_X (curve.x[0]); + double y1 = convertWorldToNDC_Y (curve.y[0]); + for (int i = 1; i < curve.m_iPointCount; i++) { + double x2 = convertWorldToNDC_X (curve.x[i]); + double y2 = convertWorldToNDC_Y (curve.y[i]); + double x2Clip = x2; + double y2Clip = y2; + if (clip_rect (x1, y1, x2Clip, y2Clip, clipRect)) { + rSGP.moveAbs (x1, y1); + rSGP.lineAbs (x2Clip, y2Clip); + } + x1 = x2; + y1 = y2; + } + } + if (curve.m_iSymbol > 0) { + rSGP.setLineStyle (SGP::LS_SOLID); + double x = convertWorldToNDC_X (curve.x[0]); + double y = convertWorldToNDC_Y (curve.y[0]); + rSGP.moveAbs (x, y); + symbol (curve.m_iSymbol, symwidth, symheight); + for (int i = 1; i < curve.m_iPointCount; i++) + if (i % curve.m_iSymbolFreq == 0 || i == curve.m_iPointCount - 1) { + x = convertWorldToNDC_X (curve.x[i]); + y = convertWorldToNDC_Y (curve.y[i]); + if (y >= ygn_min && y <= ygn_max) { + rSGP.moveAbs (x, y); + symbol (curve.m_iSymbol, symwidth, symheight); + } + } + } } - + } /* NAME - * drawAxes INTERNAL routine to draw axis & label them - * - * SYNOPSIS - * drawAxes() - */ +* drawAxes INTERNAL routine to draw axis & label them +* +* SYNOPSIS +* drawAxes() +*/ void @@ -650,46 +666,46 @@ EZPlot::drawAxes() if (o_grid == TRUE) { rSGP.setColor (clr_grid); for (i = 0; i <= x_nint; i++) { - rSGP.moveAbs (xt_min + xn_tickinc * i, ya_max); - rSGP.lineAbs (xt_min + xn_tickinc * i, ya_min); + rSGP.moveAbs (xt_min + xn_tickinc * i, ya_max); + rSGP.lineAbs (xt_min + xn_tickinc * i, ya_min); } } - rSGP.moveAbs (xa_min + (xa_max-xa_min)/2 - c_xlabel.length()*charwidth, xlbl_row); - rSGP.setTextSize (charheight * 2.0); + rSGP.moveAbs (xa_min + (xa_max-xa_min)/2 - c_xlabel.length()*charwidth * 1.5, xlbl_row + charheight * 1.5); + rSGP.setTextSize (charheight * 1.5); rSGP.setTextColor (clr_label, -1); rSGP.drawText (c_xlabel); rSGP.setTextSize (charheight); minorinc = xn_tickinc / (o_xminortick + 1); - + for (i = 0; i <= x_nint; i++) { x = xt_min + xn_tickinc * i; rSGP.setColor (clr_axis); rSGP.moveAbs (x, xaxispos); rSGP.lineAbs (x, xaxispos + xticklen); if (i != x_nint) - for (j = 1; j <= o_xminortick; j++) { - x2 = x + minorinc * j; - rSGP.moveAbs (x2, xaxispos); - rSGP.lineAbs (x2, xaxispos + TICKRATIO * xticklen); - } - axis_near = FALSE; - if (xaxispos + xtl_ofs > ya_min && o_yaxis != NOAXIS) { - double xw = xgw_min + i * xw_tickinc; - double x = convertWorldToNDC_X (xw); - double d = x - yaxispos; - if (o_yticks == RIGHT && d >= 0 && d < 0.9 * xn_tickinc) - axis_near = TRUE; - if (o_yticks == LEFT && d <= 0 && d > -0.9 * xn_tickinc) - axis_near = TRUE; - } - - if (o_xtlabel == TRUE && axis_near == FALSE) { - snprintf (str, sizeof(str), x_numfmt, xgw_min + xw_tickinc * i); - numstr = str_skip_head (str, " "); - rSGP.moveAbs (x-strlen(numstr)*charwidth/2, xaxispos + xtl_ofs); - rSGP.setTextColor (clr_number, -1); - rSGP.drawText (numstr); - } + for (j = 1; j <= o_xminortick; j++) { + x2 = x + minorinc * j; + rSGP.moveAbs (x2, xaxispos); + rSGP.lineAbs (x2, xaxispos + TICKRATIO * xticklen); + } + axis_near = FALSE; + if (xaxispos + xtl_ofs > ya_min && o_yaxis != NOAXIS) { + double xw = xgw_min + i * xw_tickinc; + double x = convertWorldToNDC_X (xw); + double d = x - yaxispos; + if (o_yticks == RIGHT && d >= 0 && d < 0.9 * xn_tickinc) + axis_near = TRUE; + if (o_yticks == LEFT && d <= 0 && d > -0.9 * xn_tickinc) + axis_near = TRUE; + } + + if (o_xtlabel == TRUE && axis_near == FALSE) { + snprintf (str, sizeof(str), x_numfmt, xgw_min + xw_tickinc * i); + numstr = str_skip_head (str, " "); + rSGP.moveAbs (x-strlen(numstr)*charwidth/2, xaxispos + xtl_ofs); + rSGP.setTextColor (clr_number, -1); + rSGP.drawText (numstr); + } } } // X - Axis @@ -715,16 +731,16 @@ EZPlot::drawAxes() if (o_grid == TRUE) { rSGP.setColor (clr_grid); for (i = 0; i <= y_nint; i++) { - y = yt_min + yn_tickinc * i; - rSGP.moveAbs (xa_max, y); - rSGP.lineAbs (xa_min, y); + y = yt_min + yn_tickinc * i; + rSGP.moveAbs (xa_max, y); + rSGP.lineAbs (xa_min, y); } } - rSGP.moveAbs (ylbl_col, ya_min + (ya_max-ya_min)/2 - c_ylabel.length()*charheight); + rSGP.moveAbs (ylbl_col, ya_min + (ya_max-ya_min)/2 - c_ylabel.length()*charheight*1.5); + rSGP.getDriver().idWX()->SetFont(*wxSWISS_FONT); rSGP.setTextAngle (HALFPI); - rSGP.setTextSize (2 * charheight); + rSGP.setTextSize (1.5 * charheight); rSGP.setTextColor (clr_label, -1); - rSGP.drawText (c_ylabel); rSGP.setTextAngle (0.0); rSGP.setTextSize (charheight); minorinc = yn_tickinc / (o_yminortick + 1); @@ -735,27 +751,27 @@ EZPlot::drawAxes() rSGP.moveAbs (yaxispos, y); rSGP.lineAbs (yaxispos + yticklen, y); if (i != y_nint) - for (j = 1; j <= o_yminortick; j++) { - y2 = y + minorinc * j; - rSGP.moveAbs (yaxispos, y2); - rSGP.lineAbs (yaxispos + TICKRATIO * yticklen, y2); - } - axis_near = FALSE; - if (yaxispos + ytl_ofs > xa_min && o_xaxis != NOAXIS) { - double yw = ygw_min + i * yw_tickinc; - double y = convertWorldToNDC_Y (yw); - double d = y - xaxispos; - if (o_xticks == ABOVE && d >= 0 && d < 0.9 * yn_tickinc) - axis_near = TRUE; - if (o_xticks == BELOW && d <= 0 && d > -0.9 * yn_tickinc) - axis_near = TRUE; - } - if (o_ytlabel == TRUE && axis_near == FALSE) { - snprintf (str, sizeof(str), y_numfmt, ygw_min + yw_tickinc * i); - rSGP.moveAbs (yaxispos + ytl_ofs, y + 0.5 * charheight); - rSGP.setTextColor (clr_number, -1); - rSGP.drawText (str); - } + for (j = 1; j <= o_yminortick; j++) { + y2 = y + minorinc * j; + rSGP.moveAbs (yaxispos, y2); + rSGP.lineAbs (yaxispos + TICKRATIO * yticklen, y2); + } + axis_near = FALSE; + if (yaxispos + ytl_ofs > xa_min && o_xaxis != NOAXIS) { + double yw = ygw_min + i * yw_tickinc; + double y = convertWorldToNDC_Y (yw); + double d = y - xaxispos; + if (o_xticks == ABOVE && d >= 0 && d < 0.9 * yn_tickinc) + axis_near = TRUE; + if (o_xticks == BELOW && d <= 0 && d > -0.9 * yn_tickinc) + axis_near = TRUE; + } + if (o_ytlabel == TRUE && axis_near == FALSE) { + snprintf (str, sizeof(str), y_numfmt, ygw_min + yw_tickinc * i); + rSGP.moveAbs (yaxispos + ytl_ofs, y + 0.5 * charheight); + rSGP.setTextColor (clr_number, -1); + rSGP.drawText (str); + } } } // Y - Axis } @@ -802,25 +818,25 @@ EZPlot::symbol (int sym, double symwidth, double symheight) /* NAME - * axis_scale calculates graph axis scaling - * - * SYNOPSIS: - * retval = axis_scale (min, max, nint, minp, maxp, nintp, - * rec_total, rec_frac) - * - * INPUT: - * double min Smallest value to plot - * double max Largest value to plot - * int nint Number of intervals desired - * - * OUTPUT: - * int retval FALSE if illegal parameters, else TRUE - * double *minp Minimum graph value - * double *maxp Maximum graph value - * int *nintp Number of intervals for graph - * int *rec_total Recommended field width for printing out the number - * int *rec_frac Recommended number of digits for print fraction - */ +* axis_scale calculates graph axis scaling +* +* SYNOPSIS: +* retval = axis_scale (min, max, nint, minp, maxp, nintp, +* rec_total, rec_frac) +* +* INPUT: +* double min Smallest value to plot +* double max Largest value to plot +* int nint Number of intervals desired +* +* OUTPUT: +* int retval FALSE if illegal parameters, else TRUE +* double *minp Minimum graph value +* double *maxp Maximum graph value +* int *nintp Number of intervals for graph +* int *rec_total Recommended field width for printing out the number +* int *rec_frac Recommended number of digits for print fraction +*/ int EZPlot::axis_scale (double min, double max, int nint, double *minp, double *maxp, int *nintp) @@ -835,7 +851,7 @@ EZPlot::axis_scale (double min, double max, int nint, double *minp, double *maxp if (fabs(min) < fabs(max)) a = fabs(max); double scale = pow (10.0, floor(log10(a))); - loop: +loop: double mina = min / scale; double maxa = max / scale; double d = (maxa - mina) / nint; @@ -851,17 +867,18 @@ EZPlot::axis_scale (double min, double max, int nint, double *minp, double *maxp v = 5.0; double wdt = v * pow (10.0, e); double g = floor (mina / wdt); - if (fabs(g + 1 - mina / wdt) < j) - g = g + 1; -#if 1 - g++; + if (fabs(g + 1 - mina / wdt) < j) + g = g + 1; +#undef TEST1 +#ifdef TEST1 + g++; #endif *minp = wdt * g; double h = floor (maxa / wdt) + 1.0; if (fabs(maxa / wdt + 1 - h) < j) - h = h - 1; -#if 1 - h--; + h = h - 1; +#ifdef TEST1 + h--; #endif *maxp = wdt * h; *nintp = static_cast<int>(h - g); @@ -878,22 +895,22 @@ EZPlot::axis_scale (double min, double max, int nint, double *minp, double *maxp /* NAME - * make_numfmt Make a numeric format string - * - * SYNOPSIS - * make_numfmt (fmtstr, fldwid, nfrac, min, max, nint) - * char *fmtstr Returned format string for printf() - * int *fldwid Returned field width - * int *nfrac If < 0, then calculate best number of - * fraction places & return that value - * If >= 0, then use that number of places - * double min Minimum value - * double max Maximum value - * int nint Number of intervals between min & max - * - * DESCRIPTION - * This routine is written as an INTERNAL routine for EZPLOT - */ +* make_numfmt Make a numeric format string +* +* SYNOPSIS +* make_numfmt (fmtstr, fldwid, nfrac, min, max, nint) +* char *fmtstr Returned format string for printf() +* int *fldwid Returned field width +* int *nfrac If < 0, then calculate best number of +* fraction places & return that value +* If >= 0, then use that number of places +* double min Minimum value +* double max Maximum value +* int nint Number of intervals between min & max +* +* DESCRIPTION +* This routine is written as an INTERNAL routine for EZPLOT +*/ static inline double trunc (double x) @@ -909,14 +926,14 @@ void EZPlot::make_numfmt (char *fmtstr, int *fldwid, int *nfrac, double minval, double maxval, int nint) { int wid, frac, expon; - + double delta = (maxval - minval) / nint; double absmin = fabs(minval); double absmax = fabs(maxval); if (absmin > absmax) - absmax = absmin; + absmax = absmin; double logt = log10( absmax ); - + if (fabs(logt) >= 6) { // use exponential format if (fabs(logt) > 99) expon = 5; // E+102 @@ -927,7 +944,7 @@ EZPlot::make_numfmt (char *fmtstr, int *fldwid, int *nfrac, double minval, doubl delta /= pow (10., floor(logt)); // scale delta frac = static_cast<int>(fabs(trunc(log10(delta)))) + 1; if (frac < 1) - frac = 1; // to be safe, add decimal pt + frac = 1; // to be safe, add decimal pt } else // use users' frac frac = *nfrac; @@ -944,16 +961,16 @@ EZPlot::make_numfmt (char *fmtstr, int *fldwid, int *nfrac, double minval, doubl if (*nfrac < 0) { // calculate frac if (delta >= 0.999999) - frac = 1; // add a decimal pt to be safe + frac = 1; // add a decimal pt to be safe else - frac = static_cast<int>(fabs(trunc(log10(delta)))) + 1; + frac = static_cast<int>(fabs(trunc(log10(delta)))) + 1; } else // use users' frac frac = *nfrac; wid += 1 + frac; sprintf (fmtstr, "%s%d%s%d%s", "%", wid, ".", frac, "f"); } - + *fldwid = wid; *nfrac = frac; } diff --git a/libctgraphics/ezset.cpp b/libctgraphics/ezset.cpp index ed396aa..1b8741d 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.10 2000/12/20 14:39:09 kevin Exp $ +** $Id: ezset.cpp,v 1.11 2000/12/23 18:12:35 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 @@ -386,15 +386,13 @@ EZPlot::bad_option (char *opt) sys_error (ERR_WARNING, "INVALID option: %s", opt); } -/*----------------------------------------------------------------------*/ -/* LEXIGRAPHICAL CODES */ -/*----------------------------------------------------------------------*/ -static struct key { - char *keyword; - int code; -} keytab[] = { - {"solid", S_SOLID}, +//---------------------------------------------------------------------- +// KEYWORDS / CODES TABLE +//---------------------------------------------------------------------- +const struct KeywordCodeTable EZPlot::m_sKeywords[] = +{ + {"solid", S_SOLID}, {"dash", S_DASH}, {"noline", S_NOLINE}, {"black", S_BLACK}, @@ -471,13 +469,13 @@ static struct key { {"textsize", S_TEXTSIZE}, }; - -static const unsigned int NKEYS=(sizeof(keytab) / sizeof(struct key)); + +const int EZPlot::NKEYS = (sizeof(EZPlot::m_sKeywords) / sizeof (struct KeywordCodeTable)); void EZPlot::initkw(void) { for (unsigned int i = 0; i < NKEYS; i++) - if (! pol_install(keytab[i].keyword, keytab[i].code)) - sys_error(ERR_SEVERE, "error installing ezset keywords [initkw]"); + if (! pol_install (m_sKeywords[i].keyword, m_sKeywords [i].code)) + sys_error(ERR_SEVERE, "error installing ezset keywords [EZPlot::initkw]"); } diff --git a/libctsupport/plotfile.cpp b/libctsupport/plotfile.cpp index b9e8ac6..b05705a 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.4 2000/12/21 03:40:58 kevin Exp $ +** $Id: plotfile.cpp,v 1.5 2000/12/23 18:12:35 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 @@ -39,8 +39,8 @@ PlotFile::PlotFile (int nCurves, int nRecords) { - initHeaders (); - setCurveSize (nCurves, nRecords); + initHeaders (); + setCurveSize (nCurves, nRecords); } PlotFile::PlotFile () @@ -55,22 +55,20 @@ PlotFile::~PlotFile () void PlotFile::initHeaders () { - m_iNumColumns = 0; - m_iNumRecords = 0; - m_strTitle = ""; - m_strXLabel = ""; - m_strYLabel = ""; - m_strDate = ""; - m_vecStrDescriptions.clear(); + m_iNumColumns = 0; + m_iNumRecords = 0; + m_strDate = ""; + m_vecStrDescriptions.clear(); + m_vecStrEzsetCommands.clear(); } void PlotFile::setCurveSize (int nCols, int nRecords) { - m_iNumColumns = nCols; - m_iNumRecords = nRecords; - m_vecCurves.clear(); - m_vecCurves.reserve (m_iNumColumns * m_iNumRecords); + m_iNumColumns = nCols; + m_iNumRecords = nRecords; + m_vecCurves.clear(); + m_vecCurves.reserve (m_iNumColumns * m_iNumRecords); } // Storage format @@ -83,10 +81,10 @@ PlotFile::addColumn (int iCol, const double* const pdColData) 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; } @@ -97,10 +95,10 @@ PlotFile::addColumn (int iCol, const float* const pdColData) 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; } @@ -111,105 +109,105 @@ PlotFile::getColumn (int iCol, double* pdColData) const 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; + 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 iOffset = iStartingCol * m_iNumRecords; - int iNPoints = (m_iNumColumns - iStartingCol) * m_iNumRecords; - std::vector<double> 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; + if (iStartingCol >= m_iNumColumns) { + sys_error (ERR_WARNING, "iStartingCol >= iNumColumns"); + return false; + } + + int iOffset = iStartingCol * m_iNumRecords; + int iNPoints = (m_iNumColumns - iStartingCol) * m_iNumRecords; + std::vector<double> 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) { - m_strFilename = filename; - - fstream fs (m_strFilename.c_str(), std::ios::out | std::ios::trunc); - if (fs.fail()) { - sys_error (ERR_WARNING, "Error opening file %s for writing [fileCreate]", m_strFilename.c_str()); - return false; - } - - if (! headerWrite(fs) || ! columnsWrite (fs)) - return false; - - return true; + m_strFilename = filename; + + fstream fs (m_strFilename.c_str(), std::ios::out | std::ios::trunc); + if (fs.fail()) { + sys_error (ERR_WARNING, "Error opening file %s for writing [fileCreate]", m_strFilename.c_str()); + return false; + } + + if (! headerWrite(fs) || ! columnsWrite (fs)) + return false; + + return true; } bool PlotFile::fileRead (const char* const filename) { - m_strFilename = filename; - + m_strFilename = filename; + #ifdef MSVC - fstream fs (m_strFilename.c_str(), std::ios::in); + fstream fs (m_strFilename.c_str(), std::ios::in); #else - fstream fs (m_strFilename.c_str(), std::ios::in | std::ios::nocreate); + fstream fs (m_strFilename.c_str(), std::ios::in | std::ios::nocreate); #endif - - if (fs.fail()) { - sys_error (ERR_WARNING, "Unable to open file %s [fileRead]", m_strFilename.c_str()); - return false; - } - - if (! headerRead(fs)) - return false; - - setCurveSize (m_iNumColumns, m_iNumRecords); - - if (! columnsRead(fs)) - return false;; - - return true; + + if (fs.fail()) { + sys_error (ERR_WARNING, "Unable to open file %s [fileRead]", m_strFilename.c_str()); + return false; + } + + if (! headerRead(fs)) + return false; + + setCurveSize (m_iNumColumns, m_iNumRecords); + + if (! columnsRead(fs)) + return false;; + + return true; } bool @@ -219,13 +217,17 @@ PlotFile::headerRead (std::iostream& fs) sys_error (ERR_WARNING, "Tried to read header with file closed [headerRead]"); return false; } - - fs.seekg (0); - - initHeaders(); - bool bInHeaders = true; -// while (bInHeaders) { - //} + + initHeaders(); + fs.seekg (0); + bool bFinishedHeaders = false; + + while (! bFinishedHeaders && ! fs.eof() && ! fs.fail()) { + char line[1024]; + fs.getline (line, sizeof(line)); + if (strstr (line, "<datapoints>") != NULL) + bFinishedHeaders = true; + } return ! fs.fail(); } @@ -238,29 +240,31 @@ PlotFile::headerWrite (std::iostream& fs) sys_error (ERR_WARNING, "Tried to write header with ! fs"); return false; } - + fs.seekp (0); fs << "<plotfile>\n"; - fs << "<header>\n"; + fs << "<ncolumns>" << m_iNumColumns << "</ncolumns>\n"; + fs << "<nrecords>" << m_iNumRecords << "</nrecords>\n"; + int iNEzset = m_vecStrEzsetCommands.size(); + if (iNEzset > 0) { + fs << "<ezset>\n"; + for (int i = 0; i < iNEzset; i++) + fs << m_vecStrEzsetCommands[i] << "\n"; + fs << "</ezset>\n"; + } + if (! m_strDate.empty()) fs << "<date>" << m_strDate << "</date>\n"; - - if (! m_strTitle.empty()) - fs << "<title>" << m_strTitle << "\n"; - - if (! m_strXLabel.empty()) - fs << "" << m_strXLabel << "\n"; - - if (! m_strYLabel.empty()) - fs << "" << m_strYLabel << "\n"; - - int iNDesc = m_vecStrDescriptions.size(); - for (int i = 0; i < iNDesc; i++) - fs << "" << m_vecStrDescriptions[i] << "\n"; - - fs << "
\n"; - + + int iNDesc = m_vecStrDescriptions.size(); + if (iNDesc > 0) { + fs << "\n"; + for (int i = 0; i < iNDesc; i++) + fs << m_vecStrDescriptions[i] << "\n"; + fs << "\n"; + } + return ! fs.fail(); } @@ -272,20 +276,20 @@ PlotFile::columnsWrite (std::iostream& fs) sys_error (ERR_WARNING, "Tried to columnWrite with !fs"); return false; } - + fs << "\n"; - + int iStride = m_iNumRecords; for (int iRec = 0; iRec < m_iNumRecords; iRec++) { for (int iCol = 0; iCol < m_iNumColumns; iCol++) fs << m_vecCurves [iRec + (iCol * iStride)] << " "; fs << "\n"; } - + fs << "\n"; - + fs << "\n"; - + return ! fs.fail(); } @@ -297,15 +301,30 @@ PlotFile::columnsRead (std::iostream& fs) sys_error (ERR_WARNING, "Tried to arrayDataRead with ! fs"); return false; } - + return ! fs.fail(); - + if (m_iNumColumns == 0 || m_iNumRecords == 0) { sys_error (ERR_WARNING, "Called PlotFile::columnsRead with 0 columns or records"); return false; } - - return true; + + 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()); } diff --git a/msvc/ctsim/ctsim.plg b/msvc/ctsim/ctsim.plg index ec7bd1a..89fc5c6 100644 --- a/msvc/ctsim/ctsim.plg +++ b/msvc/ctsim/ctsim.plg @@ -3,16 +3,55 @@
 

Build Log

---------------------Configuration: ctsim - Win32 Debug-------------------- +--------------------Configuration: libctsim - Win32 Debug--------------------

Command Lines

-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP432.tmp" with contents +Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSPFC.tmp" with contents [ -/nologo /G6 /MTd /W3 /Gm /GR /GX /ZI /Od /I "\wx2\include" /I "." /I "..\..\include" /I "..\..\getopt" /I "..\..\..\lpng108" /I "..\..\..\zlib" /I "..\..\..\fftw-2.1.3\fftw" /I "..\..\..\fftw-2.1.3\rfftw" /D VERSION=\"2.5.0\" /D "_DEBUG" /D "__WXMSW__" /D "HAVE_SGP" /D "HAVE_PNG" /D "HAVE_WXWINDOWS" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "HAVE_STRING_H" /D "HAVE_FFTW" /D "HAVE_RFFTW" /D "HAVE_GETOPT_H" /D "MSVC" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /D CTSIMVERSION=\"2.5.0\" /FR"Debug/" /Fp"Debug/ctsim.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c -"C:\ctsim-2.0.6\src\ctsim.cpp" +/nologo /G6 /MTd /W3 /Gm /GR /GX /ZI /Od /I "..\..\..\zlib" /I "..\..\INCLUDE" /I "..\..\getopt" /I "..\..\..\lpng108" /I "..\..\..\fftw-2.1.3\fftw" /I "..\..\..\fftw-2.1.3\rfftw" /I "..\..\..\wx2\include" /D "_DEBUG" /D "HAVE_WXWIN" /D "HAVE_STRING_H" /D "HAVE_GETOPT_H" /D "WIN32" /D "_MBCS" /D "_LIB" /D "MSVC" /D "HAVE_FFTW" /D "HAVE_PNG" /D "HAVE_SGP" /D "HAVE_WXWINDOWS" /D "__WXMSW__" /FR"Debug/" /Fp"Debug/libctsim.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c +"C:\ctsim-2.0.6\libctgraphics\ezplot.cpp" ] -Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP432.tmp" -Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP433.tmp" with contents +Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSPFC.tmp" +Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSPFD.tmp" with contents +[ +/nologo /out:"Debug\libctsim.lib" +".\Debug\array2dfile.obj" +".\Debug\backprojectors.obj" +".\Debug\clip.obj" +".\Debug\consoleio.obj" +".\Debug\ezplot.obj" +".\Debug\ezset.obj" +".\Debug\ezsupport.obj" +".\Debug\filter.obj" +".\Debug\fnetorderstream.obj" +".\Debug\getopt.obj" +".\Debug\getopt1.obj" +".\Debug\imagefile.obj" +".\Debug\mathfuncs.obj" +".\Debug\phantom.obj" +".\Debug\plotfile.obj" +".\Debug\pol.obj" +".\Debug\procsignal.obj" +".\Debug\projections.obj" +".\Debug\reconstruct.obj" +".\Debug\scanner.obj" +".\Debug\sgp.obj" +".\Debug\strfuncs.obj" +".\Debug\syserror.obj" +".\Debug\trace.obj" +".\Debug\transformmatrix.obj" +".\Debug\xform.obj" +] +Creating command line "link.exe -lib @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSPFD.tmp" +

Output Window

+Compiling... +ezplot.cpp +Creating library... +

+--------------------Configuration: ctsim - Win32 Debug-------------------- +

+

Command Lines

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

Output Window

-Compiling... -ctsim.cpp Linking... -Creating command line "bscmake.exe /nologo /o"Debug/ctsim.bsc" ".\Debug\ctsim.sbr" ".\Debug\dialogs.sbr" ".\Debug\dlgprojections.sbr" ".\Debug\dlgreconstruct.sbr" ".\Debug\docs.sbr" ".\Debug\views.sbr"" -Creating browse info file... -BSCMAKE: warning BK4503 : minor error in .SBR file '.\Debug\ctsim.sbr' ignored -

Output Window

Results

-ctsim.exe - 0 error(s), 1 warning(s) +ctsim.exe - 0 error(s), 0 warning(s)
diff --git a/src/views.cpp b/src/views.cpp index 740c81c..8b1abce 100644 --- a/src/views.cpp +++ b/src/views.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: views.cpp,v 1.36 2000/12/22 04:18:00 kevin Exp $ +** $Id: views.cpp,v 1.37 2000/12/23 18:12:35 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 @@ -493,11 +493,15 @@ ImageFileView::OnPlotRow (wxCommandEvent& event) sys_error (ERR_SEVERE, "Internal error: unable to create Plot file"); } else { PlotFile& rPlotFile = pPlotDoc->getPlotFile(); - std::ostringstream title; - title << "Row " << yCursor; - rPlotFile.setTitle(title.str()); - rPlotFile.setXLabel("Column"); - rPlotFile.setYLabel("Pixel Value"); + std::ostringstream os; + os << "Row " << yCursor; + std::string title("title "); + title += os.str(); + rPlotFile.addEzsetCommand (title.c_str()); + rPlotFile.addEzsetCommand ("xlabel Column"); + rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("box"); + rPlotFile.addEzsetCommand ("grid"); rPlotFile.setCurveSize (2, nx); rPlotFile.addColumn (0, pX); rPlotFile.addColumn (1, pY); @@ -535,11 +539,15 @@ ImageFileView::OnPlotCol (wxCommandEvent& event) sys_error (ERR_SEVERE, "Internal error: unable to create Plot file"); } else { PlotFile& rPlotFile = pPlotDoc->getPlotFile(); - std::ostringstream title; - title << "Column " << xCursor; - rPlotFile.setTitle(title.str()); - rPlotFile.setXLabel("Row"); - rPlotFile.setYLabel("Pixel Value"); + std::ostringstream os; + os << "Column " << xCursor; + std::string title("title "); + title += os.str(); + rPlotFile.addEzsetCommand (title.c_str()); + rPlotFile.addEzsetCommand ("xlabel Row"); + rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("box"); + rPlotFile.addEzsetCommand ("grid"); rPlotFile.setCurveSize (2, nx); rPlotFile.addColumn (0, pX); rPlotFile.addColumn (1, pY); @@ -561,7 +569,10 @@ ImageFileView::OnCompareCol (wxCommandEvent& event) std::vector vecIFDoc; theApp->getCompatibleImages (GetDocument(), vecIFDoc); - + if (vecIFDoc.size() == 0) { + wxMessageBox ("No compatible images for Column Comparison", "Error"); + return; + } DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false); if (dialogGetCompare.ShowModal() == wxID_OK) { @@ -588,11 +599,15 @@ ImageFileView::OnCompareCol (wxCommandEvent& event) sys_error (ERR_SEVERE, "Internal error: unable to create Plot file"); } else { PlotFile& rPlotFile = pPlotDoc->getPlotFile(); - std::ostringstream title; - title << "Comparison of Column " << xCursor; - rPlotFile.setTitle(title.str()); - rPlotFile.setXLabel("Row"); - rPlotFile.setYLabel("Pixel Value"); + std::ostringstream os; + os << "Column " << xCursor << " Comparison"; + std::string title("title "); + title += os.str(); + rPlotFile.addEzsetCommand (title.c_str()); + rPlotFile.addEzsetCommand ("xlabel Row"); + rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("box"); + rPlotFile.addEzsetCommand ("grid"); rPlotFile.setCurveSize (3, nx); rPlotFile.addColumn (0, pX); rPlotFile.addColumn (1, pY1); @@ -618,6 +633,11 @@ ImageFileView::OnCompareRow (wxCommandEvent& event) std::vector vecIFDoc; theApp->getCompatibleImages (GetDocument(), vecIFDoc); + if (vecIFDoc.size() == 0) { + wxMessageBox ("No compatible images for Row Comparison", "Error"); + return; + } + DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false); if (dialogGetCompare.ShowModal() == wxID_OK) { @@ -644,11 +664,15 @@ ImageFileView::OnCompareRow (wxCommandEvent& event) sys_error (ERR_SEVERE, "Internal error: unable to create Plot file"); } else { PlotFile& rPlotFile = pPlotDoc->getPlotFile(); - std::ostringstream title; - title << "Comparison of Row " << yCursor; - rPlotFile.setTitle(title.str()); - rPlotFile.setXLabel("Column"); - rPlotFile.setYLabel("Pixel Value"); + std::ostringstream os; + os << "Row " << yCursor << " Comparison"; + std::string title("title "); + title += os.str(); + rPlotFile.addEzsetCommand (title.c_str()); + rPlotFile.addEzsetCommand ("xlabel Column"); + rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("box"); + rPlotFile.addEzsetCommand ("grid"); rPlotFile.setCurveSize (3, ny); rPlotFile.addColumn (0, pX); rPlotFile.addColumn (1, pY1); @@ -1060,7 +1084,7 @@ ProjectionFileView::OnReconstruct (wxCommandEvent& event) m_iDefaultTrace = dialogReconstruction.getTrace(); if (m_iDefaultNX > 0 && m_iDefaultNY > 0) { ImageFileDocument* pReconDoc = dynamic_cast(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT)); - if (pReconDoc) { + if (! pReconDoc) { sys_error (ERR_SEVERE, "Unable to create image file"); return; } @@ -1500,23 +1524,10 @@ PlotFileView::OnDraw (wxDC* dc) SGP sgp (driver); const PlotFile& rPhantom = GetDocument()->getPlotFile(); EZPlot plot (sgp); - - if (! rPlotFile.getTitle().empty()) { - std::string s("title "); - s += rPlotFile.getTitle(); - plot.ezset (s); - } - if (! rPlotFile.getXLabel().empty()) { - std::string s("xlabel "); - s += rPlotFile.getXLabel(); - plot.ezset (s); - } - if (! rPlotFile.getYLabel().empty()) { - std::string s("ylabel "); - s += rPlotFile.getYLabel(); - plot.ezset (s); - } - + + for (int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++) + plot.ezset (rPlotFile.getEzsetCommand (iEzset)); + if (m_bMinSpecified) { std::ostringstream os; os << "ymin " << m_dMinPixel; diff --git a/tools/if1.cpp b/tools/if1.cpp index b961c0e..dcd1dc1 100644 --- a/tools/if1.cpp +++ b/tools/if1.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if1.cpp,v 1.1 2000/12/18 00:24:28 kevin Exp $ +** $Id: if1.cpp,v 1.2 2000/12/23 18:12:35 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -46,7 +46,7 @@ static struct option my_options[] = {0, 0, 0, 0} }; -static const char* g_szIdStr = "$Id: if1.cpp,v 1.1 2000/12/18 00:24:28 kevin Exp $"; +static const char* g_szIdStr = "$Id: if1.cpp,v 1.2 2000/12/23 18:12:35 kevin Exp $"; void if1_usage (const char *program) @@ -154,27 +154,33 @@ if1_main (int argc, char *const argv[]) } if (opt_log) { for (ix = 0; ix < nx; ix++) - for (iy = 0; iy < ny; iy++) - vOut[ix][iy] = log (vIn[ix][iy]); - histString = "Log transformation"; + for (iy = 0; iy < ny; iy++) + if (vIn[ix][iy] < 0) + vOut[ix][iy] = 0; + else + vOut[ix][iy] = log (vIn[ix][iy]); + histString = "Logrithmic transformation"; } if (opt_exp) { for (ix = 0; ix < nx; ix++) for (iy = 0; iy < ny; iy++) vOut[ix][iy] = exp (vIn[ix][iy]); - histString = "Exp transformation"; + histString = "Exponential transformation"; } if (opt_sqr) { for (ix = 0; ix < nx; ix++) for (iy = 0; iy < ny; iy++) vOut[ix][iy] = vIn[ix][iy] * vIn[ix][iy]; - histString = "Sqr transformation"; + histString = "Square transformation"; } if (opt_sqrt) { for (ix = 0; ix < nx; ix++) - for (iy = 0; iy < ny; iy++) - vOut[ix][iy] = sqrt (vIn[ix][iy]); - histString = "Sqrt transformation"; + for (iy = 0; iy < ny; iy++) + if (vIn[ix][iy] < 0) + vOut[ix][iy] = sqrt (-vIn[ix][iy]); + else + vOut[ix][iy] = sqrt (vIn[ix][iy]); + histString = "Square root transformation"; } im_out->labelsCopy (*im_in); diff --git a/tools/if2.cpp b/tools/if2.cpp index c49b5a4..571e8d6 100644 --- a/tools/if2.cpp +++ b/tools/if2.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if2.cpp,v 1.4 2000/12/22 04:18:00 kevin Exp $ +** $Id: if2.cpp,v 1.5 2000/12/23 18:12:35 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -46,7 +46,7 @@ static struct option my_options[] = {0, 0, 0, 0} }; -static const char* g_szIdStr = "$Id: if2.cpp,v 1.4 2000/12/22 04:18:00 kevin Exp $"; +static const char* g_szIdStr = "$Id: if2.cpp,v 1.5 2000/12/23 18:12:35 kevin Exp $"; void if2_usage (const char *program) @@ -237,10 +237,18 @@ if2_main (int argc, char *const argv[]) plotFile.addColumn (0, plot_xaxis); plotFile.addColumn (1, v1[opt_columnPlot]); plotFile.addColumn (2, v2[opt_columnPlot]); - plotFile.setTitle ("Column Plot"); - plotFile.setXLabel ("Column"); - plotFile.setYLabel ("Pixel Value"); - + std::ostringstream os; + os << "Column " << opt_columnPlot << " Comparison"; + plotFile.addDescription (os.str().c_str()); + std::string title("title "); + title += os.str(); + plotFile.addEzsetCommand (title.c_str()); + plotFile.addEzsetCommand ("xlabel Column"); + plotFile.addEzsetCommand ("ylabel Pixel Value"); + plotFile.addEzsetCommand ("box"); + plotFile.addEzsetCommand ("grid"); + plotFile.addEzsetCommand ("xticks major 5"); + plotFile.fileWrite (strOutFile.c_str()); #if HAVE_SGP @@ -284,9 +292,17 @@ if2_main (int argc, char *const argv[]) plotFile.addColumn (0, plot_xaxis); plotFile.addColumn (1, v1Row); plotFile.addColumn (2, v2Row); - plotFile.setTitle ("Row Plot"); - plotFile.setXLabel ("Row"); - plotFile.setYLabel ("Pixel Value"); + std::ostringstream os; + os << "Row " << opt_rowPlot << " Comparison"; + plotFile.addDescription (os.str().c_str()); + std::string title("title "); + title += os.str(); + plotFile.addEzsetCommand (title.c_str()); + plotFile.addEzsetCommand ("xlabel Row"); + plotFile.addEzsetCommand ("ylabel Pixel Value"); + plotFile.addEzsetCommand ("box"); + plotFile.addEzsetCommand ("grid"); + plotFile.addEzsetCommand ("xticks major 5"); plotFile.fileWrite (strOutFile.c_str()); -- 2.34.1