- Timestamp:
- Mar 11, 2008, 10:40:37 AM (16 years ago)
- Location:
- trunk/vizservers/nanovis
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vizservers/nanovis/Axis.cpp
r933 r936 80 80 } 81 81 82 Ticks::Ticks(TickSweep &sweep) 82 void 83 Ticks::SetTicks(void) 83 84 { 84 85 _nTicks = 0; 85 fprintf(stderr, "Ticks nsteps=%d, step=%g, initial=%g\n", 86 sweep.NumSteps(), sweep.Step(), sweep.Initial()); 87 _ticks = new float[sweep.NumSteps()]; 88 if (sweep.Step() == 0.0) { 86 _ticks = new float[_nSteps]; 87 if (_step == 0.0) { 89 88 /* Hack: A zero step indicates to use log values. */ 90 89 unsigned int i; … … 102 101 1.0 103 102 }; 104 for (i = 0; i < sweep.NumSteps(); i++) {103 for (i = 0; i < _nSteps; i++) { 105 104 _ticks[i] = logTable[i]; 106 105 } … … 109 108 unsigned int i; 110 109 111 value = sweep.Initial(); /* Start from smallest axis tick */ 112 for (i = 0; i < sweep.NumSteps(); i++) { 113 value = sweep.Initial() + (sweep.Step() * i); 114 _ticks[i] = UROUND(value, sweep.Step()); 115 fprintf(stderr, "ticks[%d] = %g (value=%g)\n", 116 i, _ticks[i], value); 117 } 118 } 119 _nTicks = sweep.NumSteps(); 120 } 121 122 Axis::Axis(const char *name) 110 value = _initial; /* Start from smallest axis tick */ 111 for (i = 0; i < _nSteps; i++) { 112 value = _initial + (_step * i); 113 _ticks[i] = UROUND(value, _step); 114 } 115 } 116 _nTicks = _nSteps; 117 } 118 119 Axis::Axis(const char *name) : 120 _major(5), _minor(2) 123 121 { 124 122 _name = NULL; 125 123 SetName(name); 126 _flags = AUTOSCALE_MAJOR | AUTOSCALE_MINOR;127 124 _title = NULL; 128 125 _valueMin = DBL_MAX, _valueMax = -DBL_MAX; … … 131 128 _range = 0.0, _scale = 0.0; 132 129 _reqStep = 0.0; 133 _reqNumMinorTicks = 2;134 _reqNumMajorTicks = 5;135 _reqStep = 0.0;136 _t1Ptr = _t2Ptr = NULL;137 }138 139 Axis::~Axis(void)140 {141 if (_t1Ptr != NULL) {142 delete _t1Ptr;143 }144 if (_t2Ptr != NULL) {145 delete _t2Ptr;146 }147 _minorTicks.Reset();148 _majorTicks.Reset();149 130 } 150 131 … … 331 312 * decade. Instead, treat the axis as a linear scale. */ 332 313 range = NiceNum(range, 0); 333 majorStep = NiceNum(range / _ reqNumMajorTicks, 1);314 majorStep = NiceNum(range / _major.reqNumTicks, 1); 334 315 tickMin = UFLOOR(tickMin, majorStep); 335 316 tickMax = UCEIL(tickMax, majorStep); … … 364 345 } 365 346 } 366 _major Sweep.SetValues(majorStep, nMajor, floor(tickMin));367 _minor Sweep.SetValues(minorStep, nMinor, minorStep);347 _major.SetValues(majorStep, nMajor, floor(tickMin)); 348 _minor.SetValues(minorStep, nMinor, minorStep); 368 349 _min = tickMin; 369 350 _max = tickMax; … … 460 441 } else { 461 442 range = NiceNum(range, 0); 462 step = NiceNum(range / _ reqNumMajorTicks, 1);443 step = NiceNum(range / _major.reqNumTicks, 1); 463 444 } 464 445 … … 471 452 fprintf(stderr, "LinearScale %s (nTicks=%d, step=%g)\n", _name, 472 453 nTicks, step); 473 _major Sweep.SetValues(tickMin, step, nTicks);454 _major.SetValues(tickMin, step, nTicks); 474 455 475 456 /* … … 488 469 /* Now calculate the minor tick step and number. */ 489 470 490 if ((_ reqNumMinorTicks > 0) && (_flags & AUTOSCALE_MAJOR)) {491 nTicks = _ reqNumMinorTicks - 1;471 if ((_minor.reqNumTicks > 0) && (_minor.IsAutoScale())) { 472 nTicks = _minor.reqNumTicks - 1; 492 473 step = 1.0 / (nTicks + 1); 493 474 } else { … … 497 478 * create minor log-scale tick marks. */ 498 479 } 499 _minor Sweep.SetValues(step, step, nTicks);480 _minor.SetValues(step, step, nTicks); 500 481 fprintf(stderr, "leaving LinearScale %s (min=%g, max=%g)\n", 501 482 _name, _min, _max); 502 483 } 503 484 504 505 void506 Axis::SweepTicks()507 {508 if (_flags & AUTOSCALE_MAJOR) {509 if (_t1Ptr != NULL) {510 delete _t1Ptr;511 }512 _t1Ptr = new Ticks(_majorSweep);513 }514 if (_flags & AUTOSCALE_MINOR) {515 if (_t2Ptr != NULL) {516 delete _t2Ptr;517 }518 _t2Ptr = new Ticks(_minorSweep);519 }520 }521 485 522 486 void … … 529 493 LinearScale(); 530 494 } 531 SweepTicks(); 495 _major.SweepTicks(); 496 _minor.SweepTicks(); 532 497 MakeTicks(); 533 498 } … … 537 502 Axis::MakeTicks(void) 538 503 { 504 _major.Reset(); 505 _minor.Reset(); 539 506 int i; 540 541 _majorTicks.Reset(); 542 _minorTicks.Reset(); 543 for (i = 0; i < _t1Ptr->NumTicks(); i++) { 544 union { 545 float x; 546 void *clientData; 547 } value; 507 for (i = 0; i < _major.NumTicks(); i++) { 548 508 double t1, t2; 549 509 int j; 550 510 551 t1 = _ t1Ptr->GetTick(i);511 t1 = _major.GetTick(i); 552 512 /* Minor ticks */ 553 for (j = 0; j < _ t2Ptr->NumTicks(); j++) {554 t2 = t1 + (_major Sweep.Step() * _t2Ptr->GetTick(j));513 for (j = 0; j < _minor.NumTicks(); j++) { 514 t2 = t1 + (_major.Step() * _minor.GetTick(j)); 555 515 if (!InRange(t2)) { 556 516 continue; 557 517 } 558 518 if (t1 == t2) { 559 continue; 519 continue; // Don't add duplicate minor ticks. 560 520 } 561 value.x = t2; 562 _minorTicks.Append(value.clientData); 521 _minor.Append(t2); 563 522 } 564 523 if (!InRange(t1)) { 565 524 continue; 566 525 } 567 value.x = t1; 568 _majorTicks.Append(value.clientData); 569 } 570 } 571 572 bool 573 Axis::FirstMajor(TickIter &iter) 574 { 575 ChainLink *linkPtr; 576 577 linkPtr = _majorTicks.FirstLink(); 578 iter.SetStartingLink(linkPtr); 579 return (linkPtr != NULL); 580 } 581 582 bool 583 Axis::FirstMinor(TickIter &iter) 584 { 585 ChainLink *linkPtr; 586 587 linkPtr = _minorTicks.FirstLink(); 588 iter.SetStartingLink(linkPtr); 589 return (linkPtr != NULL); 526 _major.Append(t1); 527 } 590 528 } 591 529 -
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*/ -
trunk/vizservers/nanovis/Chain.h
r934 r936 30 30 * A ChainLink is the container structure for the Chain. 31 31 */ 32 33 34 32 class ChainLink { 35 33 friend class Chain;
Note: See TracChangeset
for help on using the changeset viewer.