Changeset 936 for trunk/vizservers/nanovis/Axis.h
- Timestamp:
- Mar 11, 2008, 10:40:37 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vizservers/nanovis/Axis.h
r933 r936 3 3 4 4 #include "Chain.h" 5 6 class Axis; 5 7 6 8 class NaN { … … 56 58 * ---------------------------------------------------------------------- 57 59 * 58 * Tick Sweep--59 * 60 * Structure containing information where step intervalthe ticks (major or60 * Ticks -- 61 * 62 * Structure containing information where the ticks (major or 61 63 * minor) will be displayed on the graph. 62 64 * 63 65 * ---------------------------------------------------------------------- 64 66 */ 65 class TickSweep { 66 private: 67 class 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 */ 67 85 double _initial; /* Initial value */ 68 86 double _step; /* Size of interval */ 69 87 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 70 108 public: 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; 103 116 } 104 117 ~Ticks(void) { … … 106 119 delete [] _ticks; 107 120 } 121 _chain.Reset(); 122 123 } 124 void SetTicks(float *ticks, int nTicks) { 125 _ticks = ticks, _nTicks = nTicks; 108 126 } 109 127 int NumTicks(void) { … … 116 134 return _ticks[i]; 117 135 } 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 } 118 166 }; 167 119 168 120 169 /* … … 131 180 /* Flags associated with the axis. */ 132 181 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) 139 187 }; 140 188 … … 164 212 double _scale; /* Scale factor for axis (1.0/_range) */ 165 213 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; 189 221 190 222 void LogScale(void); … … 194 226 195 227 public: 228 Axis(const char *name); 229 196 230 void ResetRange(void); 197 231 void FixRange(double min, double max); 198 Axis(const char *name);199 ~Axis(void);200 void SweepTicks(void);201 232 void SetScale(double min, double max); 202 233 double Scale(void) { … … 206 237 return _range; 207 238 } 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 } 210 245 void GetDataLimits(double min, double max); 211 246 double Map(double x); … … 262 297 } 263 298 void SetNumMinorTicksOption(int n) { 264 _ reqNumMinorTicks = n;299 _minor.reqNumTicks = n; 265 300 } 266 301 void SetNumMajorTicksOption(int n) { 267 _ reqNumMajorTicks = n;302 _major.reqNumTicks = n; 268 303 } 269 304 }; 270 305 271 272 273 306 #endif /*_AXIS_H*/
Note: See TracChangeset
for help on using the changeset viewer.