comparison base/RangeMapper.cpp @ 464:9525c9d7e54d

* Add vertical zoom and pan to time-value layer. Still some defects, particularly in logarithmic mode. Now need to get this in note layer as well! * Some fixes to log colouring in segmentation mode of time-value layer.
author Chris Cannam
date Fri, 24 Oct 2008 14:52:40 +0000
parents ca3b91119482
children bdc9bb371a9f
comparison
equal deleted inserted replaced
463:93806ad9481e 464:9525c9d7e54d
20 20
21 #include <iostream> 21 #include <iostream>
22 22
23 LinearRangeMapper::LinearRangeMapper(int minpos, int maxpos, 23 LinearRangeMapper::LinearRangeMapper(int minpos, int maxpos,
24 float minval, float maxval, 24 float minval, float maxval,
25 QString unit) : 25 QString unit, bool inverted) :
26 m_minpos(minpos), 26 m_minpos(minpos),
27 m_maxpos(maxpos), 27 m_maxpos(maxpos),
28 m_minval(minval), 28 m_minval(minval),
29 m_maxval(maxval), 29 m_maxval(maxval),
30 m_unit(unit) 30 m_unit(unit),
31 m_inverted(inverted)
31 { 32 {
32 assert(m_maxval != m_minval); 33 assert(m_maxval != m_minval);
33 assert(m_maxpos != m_minpos); 34 assert(m_maxpos != m_minpos);
34 } 35 }
35 36
41 * (m_maxpos - m_minpos)); 42 * (m_maxpos - m_minpos));
42 if (position < m_minpos) position = m_minpos; 43 if (position < m_minpos) position = m_minpos;
43 if (position > m_maxpos) position = m_maxpos; 44 if (position > m_maxpos) position = m_maxpos;
44 // std::cerr << "LinearRangeMapper::getPositionForValue: " << value << " -> " 45 // std::cerr << "LinearRangeMapper::getPositionForValue: " << value << " -> "
45 // << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", minval " << m_minval << ", maxval " << m_maxval << ")" << std::endl; 46 // << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", minval " << m_minval << ", maxval " << m_maxval << ")" << std::endl;
46 return position; 47 if (m_inverted) return m_maxpos - position;
48 else return position;
47 } 49 }
48 50
49 float 51 float
50 LinearRangeMapper::getValueForPosition(int position) const 52 LinearRangeMapper::getValueForPosition(int position) const
51 { 53 {
54 if (m_inverted) position = m_maxpos - position;
52 float value = m_minval + 55 float value = m_minval +
53 ((float(position - m_minpos) / float(m_maxpos - m_minpos)) 56 ((float(position - m_minpos) / float(m_maxpos - m_minpos))
54 * (m_maxval - m_minval)); 57 * (m_maxval - m_minval));
55 if (value < m_minval) value = m_minval; 58 if (value < m_minval) value = m_minval;
56 if (value > m_maxval) value = m_maxval; 59 if (value > m_maxval) value = m_maxval;
59 return value; 62 return value;
60 } 63 }
61 64
62 LogRangeMapper::LogRangeMapper(int minpos, int maxpos, 65 LogRangeMapper::LogRangeMapper(int minpos, int maxpos,
63 float minval, float maxval, 66 float minval, float maxval,
64 QString unit) : 67 QString unit, bool inverted) :
65 m_minpos(minpos), 68 m_minpos(minpos),
66 m_maxpos(maxpos), 69 m_maxpos(maxpos),
67 m_unit(unit) 70 m_unit(unit),
71 m_inverted(inverted)
68 { 72 {
69 convertMinMax(minpos, maxpos, minval, maxval, m_minlog, m_ratio); 73 convertMinMax(minpos, maxpos, minval, maxval, m_minlog, m_ratio);
70 74
71 std::cerr << "LogRangeMapper: minpos " << minpos << ", maxpos " 75 std::cerr << "LogRangeMapper: minpos " << minpos << ", maxpos "
72 << maxpos << ", minval " << minval << ", maxval " 76 << maxpos << ", minval " << minval << ", maxval "
102 LogRangeMapper::getPositionForValue(float value) const 106 LogRangeMapper::getPositionForValue(float value) const
103 { 107 {
104 int position = (log10(value) - m_minlog) * m_ratio + m_minpos; 108 int position = (log10(value) - m_minlog) * m_ratio + m_minpos;
105 if (position < m_minpos) position = m_minpos; 109 if (position < m_minpos) position = m_minpos;
106 if (position > m_maxpos) position = m_maxpos; 110 if (position > m_maxpos) position = m_maxpos;
107 std::cerr << "LogRangeMapper::getPositionForValue: " << value << " -> " 111 // std::cerr << "LogRangeMapper::getPositionForValue: " << value << " -> "
108 << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl; 112 // << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl;
109 return position; 113 if (m_inverted) return m_maxpos - position;
114 else return position;
110 } 115 }
111 116
112 float 117 float
113 LogRangeMapper::getValueForPosition(int position) const 118 LogRangeMapper::getValueForPosition(int position) const
114 { 119 {
120 if (m_inverted) position = m_maxpos - position;
115 float value = powf(10, (position - m_minpos) / m_ratio + m_minlog); 121 float value = powf(10, (position - m_minpos) / m_ratio + m_minlog);
116 std::cerr << "LogRangeMapper::getValueForPosition: " << position << " -> " 122 // std::cerr << "LogRangeMapper::getValueForPosition: " << position << " -> "
117 << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl; 123 // << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl;
118 return value; 124 return value;
119 } 125 }
120 126