comparison base/RangeMapper.cpp @ 1206:659372323b45 tony-2.0-integration

Merge latest SV 3.0 branch code
author Chris Cannam
date Fri, 19 Aug 2016 15:58:57 +0100
parents 932487fe515a
children 48e9f538e6e9
comparison
equal deleted inserted replaced
1136:e94719f941ba 1206:659372323b45
21 21
22 #include <iostream> 22 #include <iostream>
23 23
24 LinearRangeMapper::LinearRangeMapper(int minpos, int maxpos, 24 LinearRangeMapper::LinearRangeMapper(int minpos, int maxpos,
25 double minval, double maxval, 25 double minval, double maxval,
26 QString unit, bool inverted) : 26 QString unit, bool inverted,
27 std::map<int, QString> labels) :
27 m_minpos(minpos), 28 m_minpos(minpos),
28 m_maxpos(maxpos), 29 m_maxpos(maxpos),
29 m_minval(minval), 30 m_minval(minval),
30 m_maxval(maxval), 31 m_maxval(maxval),
31 m_unit(unit), 32 m_unit(unit),
32 m_inverted(inverted) 33 m_inverted(inverted),
34 m_labels(labels)
33 { 35 {
34 assert(m_maxval != m_minval); 36 assert(m_maxval != m_minval);
35 assert(m_maxpos != m_minpos); 37 assert(m_maxpos != m_minpos);
36 } 38 }
37 39
68 { 70 {
69 if (m_inverted) position = m_maxpos - (position - m_minpos); 71 if (m_inverted) position = m_maxpos - (position - m_minpos);
70 double value = m_minval + 72 double value = m_minval +
71 ((double(position - m_minpos) / double(m_maxpos - m_minpos)) 73 ((double(position - m_minpos) / double(m_maxpos - m_minpos))
72 * (m_maxval - m_minval)); 74 * (m_maxval - m_minval));
75 // cerr << "getValueForPositionUnclamped(" << position << "): minval " << m_minval << ", maxval " << m_maxval << ", value " << value << endl;
73 return value; 76 return value;
77 }
78
79 QString
80 LinearRangeMapper::getLabel(int position) const
81 {
82 if (m_labels.find(position) != m_labels.end()) {
83 return m_labels.at(position);
84 } else {
85 return "";
86 }
74 } 87 }
75 88
76 LogRangeMapper::LogRangeMapper(int minpos, int maxpos, 89 LogRangeMapper::LogRangeMapper(int minpos, int maxpos,
77 double minval, double maxval, 90 double minval, double maxval,
78 QString unit, bool inverted) : 91 QString unit, bool inverted) :