Ignore:
Timestamp:
Mar 11, 2008, 10:40:37 AM (17 years ago)
Author:
gah
Message:

Axis.cpp cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/vizservers/nanovis/Axis.h

    r933 r936  
    33
    44#include "Chain.h"
     5
     6class Axis;
    57
    68class NaN {
     
    5658 * ----------------------------------------------------------------------
    5759 *
    58  * TickSweep --
    59  *
    60  *      Structure containing information where step intervalthe ticks (major or
     60 * Ticks --
     61 *
     62 *      Structure containing information where the ticks (major or
    6163 *      minor) will be displayed on the graph.
    6264 *
    6365 * ----------------------------------------------------------------------
    6466 */
    65 class TickSweep {
    66 private:
     67class Ticks {
     68    bool _autoscale;            /* Indicates if the ticks are autoscaled. */
     69    /*
     70     * Tick locations may be generated in two fashions
     71     */
     72    /*   1. an array of values provided by the user. */
     73    int _nTicks;                /* # of ticks on axis */
     74    float *_ticks;              /* Array of tick values (alloc-ed).  Right now
     75                                 * it's a float so we don't have to allocate
     76                                 * store for the list of ticks generated.  In
     77                                 * the future when we store both the tick
     78                                 * label and the value in the list, we may
     79                                 * extend this to a double.
     80                                 */
     81    /*
     82     *   2. a defined sweep of initial, step, and nsteps.  This in turn
     83     *      will generate the an array of values.
     84     */
    6785    double _initial;            /* Initial value */
    6886    double _step;               /* Size of interval */
    6987    unsigned int _nSteps;       /* Number of intervals. */
     88
     89    /*
     90     *This finally generates a list of ticks values that exclude duplicate
     91     * minor ticks (that are always represented by major ticks).  In the
     92     * future, the string representing the tick label will be stored in
     93     * the chain.
     94     */
     95    Chain _chain;               
     96
     97    void SetTicks(void);        /* Routine used internally to create the array
     98                                 * of ticks as defined by a given sweep. */
     99    void *GetClientData(float x) {
     100        union {
     101            float x;
     102            void *clientData;
     103        } value;
     104        value.x = x;
     105        return value.clientData;
     106    }
     107
    70108public:
    71     void SetValues(double initial, double step, unsigned int nSteps) {
    72         _initial = initial, _step = step, _nSteps = nSteps;
    73     }
    74     double Initial(void) {
    75         return _initial;
    76     }
    77     double Step(void) {
    78         return _step;
    79     }
    80     unsigned int NumSteps(void) {
    81         return _nSteps;
    82     }
    83 };
    84 
    85 /*
    86  * ----------------------------------------------------------------------
    87  *
    88  * Ticks --
    89  *
    90  *      Structure containing information where the ticks (major or
    91  *      minor) will be displayed on the graph.
    92  *
    93  * ----------------------------------------------------------------------
    94  */
    95 class Ticks {
    96 private:
    97     int _nTicks;                /* # of ticks on axis */
    98     float *_ticks;              /* Array of tick values (malloc-ed). */
    99 public:
    100     Ticks(TickSweep &sweep);
    101     Ticks(float *ticks, int nTicks) {
    102         _ticks = ticks, _nTicks = nTicks;
     109    int reqNumTicks;            /* Default number of ticks to be displayed. */
     110
     111    Ticks(int numTicks) {
     112        reqNumTicks = numTicks;
     113        _ticks = NULL;
     114        _nTicks = 0;
     115        _autoscale = true;
    103116    }
    104117    ~Ticks(void) {
     
    106119            delete [] _ticks;
    107120        }
     121        _chain.Reset();
     122       
     123    }
     124    void SetTicks(float *ticks, int nTicks) {
     125        _ticks = ticks, _nTicks = nTicks;
    108126    }
    109127    int NumTicks(void) {
     
    116134        return _ticks[i];
    117135    }
     136    void Reset(void) {
     137        _chain.Reset();
     138    }
     139    float Step() {
     140        return _step;
     141    }
     142    void Append (float x) {
     143        _chain.Append(GetClientData(x));
     144    }   
     145    void SetValues(double initial, double step, unsigned int nSteps) {
     146        _initial = initial, _step = step, _nSteps = nSteps;
     147    }
     148    bool IsAutoScale(void) {
     149        return _autoscale;
     150    }
     151    void SweepTicks(void) {
     152        if (_flags & AUTOSCALE) {
     153            if (_ticks != NULL) {
     154                delete [] _ticks;
     155            }
     156            SetTicks();
     157        }
     158    }
     159    bool FirstTick(TickIter &iter) {
     160        ChainLink *linkPtr;
     161
     162        linkPtr = _chain.FirstLink();
     163        iter.SetStartingLink(linkPtr);
     164        return (linkPtr != NULL);
     165    }
    118166};
     167
    119168
    120169/*
     
    131180    /* Flags associated with the axis. */
    132181    enum AxisFlags {
    133         AUTOSCALE_MAJOR=(1<<0),
    134         AUTOSCALE_MINOR=(1<<1),
    135         DESCENDING=(1<<2),
    136         LOGSCALE=(1<<3),
    137         TIGHT_MIN=(1<<4),
    138         TIGHT_MAX=(1<<5)
     182        AUTOSCALE=(1<<0),
     183        DESCENDING=(1<<1),
     184        LOGSCALE=(1<<2),
     185        TIGHT_MIN=(1<<3),
     186        TIGHT_MAX=(1<<4)
    139187    };
    140188
     
    164212    double _scale;              /* Scale factor for axis (1.0/_range) */
    165213
    166     double _reqStep;            /* If > 0.0, overrides the computed major
    167                                  * tick interval.  Otherwise a stepsize
    168                                  * is automatically calculated, based
    169                                  * upon the range of elements mapped to the
    170                                  * axis. The default value is 0.0. */
    171 
    172     Ticks *_t1Ptr;              /* Array of major tick positions. May be
    173                                  * set by the user or generated from the
    174                                  * major sweep below. */
    175 
    176     Ticks *_t2Ptr;              /* Array of minor tick positions. May be
    177                                  * set by the user or generated from the
    178                                  * minor sweep below. */
    179 
    180     TickSweep _minorSweep, _majorSweep;
    181    
    182     Chain _minorTicks, _majorTicks;
    183 
    184     int _reqNumMajorTicks;      /* Default number of ticks to be displayed. */
    185     int _reqNumMinorTicks;      /* If non-zero, represents the
    186                                  * requested the number of minor ticks
    187                                  * to be uniformally displayed along
    188                                  * each major tick. */
     214    double _reqStep;            /* If > 0.0, overrides the computed major tick
     215                                 * interval.  Otherwise a stepsize is
     216                                 * automatically calculated, based upon the
     217                                 * range of elements mapped to the axis. The
     218                                 * default value is 0.0. */
     219
     220    Ticks _major, _minor;
    189221
    190222    void LogScale(void);
     
    194226
    195227public:
     228    Axis(const char *name);
     229
    196230    void ResetRange(void);
    197231    void FixRange(double min, double max);
    198     Axis(const char *name);
    199     ~Axis(void);
    200     void SweepTicks(void);
    201232    void SetScale(double min, double max);
    202233    double Scale(void) {
     
    206237        return _range;
    207238    }
    208     bool FirstMinor(TickIter &iter);
    209     bool FirstMajor(TickIter &iter);
     239    bool FirstMajor(TickIter &iter) {
     240        return _major.FirstTick(iter);
     241    }
     242    bool FirstMinor(TickIter &iter) {
     243        return _minor.FirstTick(iter);
     244    }
    210245    void GetDataLimits(double min, double max);
    211246    double Map(double x);
     
    262297    }
    263298    void SetNumMinorTicksOption(int n) {
    264         _reqNumMinorTicks = n;
     299        _minor.reqNumTicks = n;
    265300    }
    266301    void SetNumMajorTicksOption(int n) {
    267         _reqNumMajorTicks = n;
     302        _major.reqNumTicks = n;
    268303    }
    269304};
    270305
    271 
    272 
    273306#endif /*_AXIS_H*/
Note: See TracChangeset for help on using the changeset viewer.