comparison layer/TimeValueLayer.cpp @ 678:26c5f7fd4807 imaf_enc

Merge from the default branch
author Chris Cannam
date Mon, 04 Nov 2013 17:12:32 +0000
parents d52751e2728b
children 1a0dfcbffaf1
comparison
equal deleted inserted replaced
677:5e5ab4e8d64b 678:26c5f7fd4807
318 bool 318 bool
319 TimeValueLayer::getValueExtents(float &min, float &max, 319 TimeValueLayer::getValueExtents(float &min, float &max,
320 bool &logarithmic, QString &unit) const 320 bool &logarithmic, QString &unit) const
321 { 321 {
322 if (!m_model) return false; 322 if (!m_model) return false;
323
323 min = m_model->getValueMinimum(); 324 min = m_model->getValueMinimum();
324 max = m_model->getValueMaximum(); 325 max = m_model->getValueMaximum();
326
325 logarithmic = (m_verticalScale == LogScale); 327 logarithmic = (m_verticalScale == LogScale);
328
326 unit = m_model->getScaleUnits(); 329 unit = m_model->getScaleUnits();
330
327 if (m_derivative) { 331 if (m_derivative) {
328 max = std::max(fabsf(min), fabsf(max)); 332 max = std::max(fabsf(min), fabsf(max));
329 min = -max; 333 min = -max;
330 } 334 }
331 335
332 #ifdef DEBUG_TIME_VALUE_LAYER 336 #ifdef DEBUG_TIME_VALUE_LAYER
333 std::cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << std::endl; 337 std::cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << std::endl;
334 #endif 338 #endif
335 339
340 if (!shouldAutoAlign() && !logarithmic && !m_derivative) {
341
342 if (max == min) {
343 max = max + 0.5;
344 min = min - 0.5;
345 } else {
346 float margin = (max - min) / 10.0;
347 max = max + margin;
348 min = min - margin;
349 }
350
351 #ifdef DEBUG_TIME_VALUE_LAYER
352 std::cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl;
353 #endif
354 }
355
336 return true; 356 return true;
337 } 357 }
338 358
339 bool 359 bool
340 TimeValueLayer::getDisplayExtents(float &min, float &max) const 360 TimeValueLayer::getDisplayExtents(float &min, float &max) const
341 { 361 {
342 if (!m_model || shouldAutoAlign()) return false; 362 if (!m_model || shouldAutoAlign()) return false;
343 363
344 if (m_scaleMinimum == m_scaleMaximum) { 364 if (m_scaleMinimum == m_scaleMaximum) {
345 min = m_model->getValueMinimum(); 365 bool log;
346 max = m_model->getValueMaximum(); 366 QString unit;
367 getValueExtents(min, max, log, unit);
347 } else { 368 } else {
348 min = m_scaleMinimum; 369 min = m_scaleMinimum;
349 max = m_scaleMaximum; 370 max = m_scaleMaximum;
350 } 371 }
351 372
770 } 791 }
771 } 792 }
772 793
773 #ifdef DEBUG_TIME_VALUE_LAYER 794 #ifdef DEBUG_TIME_VALUE_LAYER
774 std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << std::endl; 795 std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << std::endl;
775 #endif
776
777 if (max == min) {
778 max = max + 0.5;
779 min = min - 0.5;
780 } else {
781 float margin = (max - min) / 10.0;
782 max = max + margin;
783 min = min - margin;
784 }
785
786 #ifdef DEBUG_TIME_VALUE_LAYER
787 std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl;
788 #endif 796 #endif
789 } 797 }
790 798
791 int 799 int
792 TimeValueLayer::getYForValue(View *v, float val) const 800 TimeValueLayer::getYForValue(View *v, float val) const
1253 int prec = trunc(log10f(inc)); 1261 int prec = trunc(log10f(inc));
1254 prec -= 1; 1262 prec -= 1;
1255 if (prec < 0) dp = -prec; 1263 if (prec < 0) dp = -prec;
1256 round = powf(10.f, prec); 1264 round = powf(10.f, prec);
1257 #ifdef DEBUG_TIME_VALUE_LAYER 1265 #ifdef DEBUG_TIME_VALUE_LAYER
1258 std::cerr << "inc = " << inc << ", round = " << round << std::endl; 1266 std::cerr << "inc = " << inc << ", round = " << round << ", dp = " << dp << std::endl;
1259 #endif 1267 #endif
1260 } 1268 }
1261 1269
1262 int prevy = -1; 1270 int prevy = -1;
1263 1271
1293 continue; 1301 continue;
1294 } 1302 }
1295 } 1303 }
1296 1304
1297 if (logarithmic) { 1305 if (logarithmic) {
1298 sprintf(buffer, "%.*g", dp < 2 ? 2 : dp, LogRange::unmap(dispval)); 1306 double dv = LogRange::unmap(dispval);
1307 int digits = trunc(log10f(dv));
1308 int sf = dp + (digits > 0 ? digits : 0);
1309 if (sf < 2) sf = 2;
1310 sprintf(buffer, "%.*g", sf, dv);
1299 } else { 1311 } else {
1300 sprintf(buffer, "%.*f", dp, dispval); 1312 sprintf(buffer, "%.*f", dp, dispval);
1301 } 1313 }
1302 QString label = QString(buffer); 1314 QString label = QString(buffer);
1303 1315